old_refresh.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. package data
  2. import (
  3. "errors"
  4. "eta/eta_task/models/data_manage"
  5. "eta/eta_task/services/alarm_msg"
  6. "eta/eta_task/utils"
  7. "fmt"
  8. "strings"
  9. "sync"
  10. )
  11. // RefreshDataFromDl 刷新广期所数据
  12. func RefreshDataFromGz(wg *sync.WaitGroup) (err error) {
  13. errMsgList := make([]string, 0)
  14. defer func() {
  15. if err != nil {
  16. errMsg := "刷新广期所数据 ErrMsg:" + err.Error()
  17. utils.FileLog.Info(errMsg)
  18. go alarm_msg.SendAlarmMsg(errMsg, 3)
  19. }
  20. if len(errMsgList) > 0 {
  21. utils.FileLog.Info("刷新广期所数据 Err:" + strings.Join(errMsgList, "\n"))
  22. go alarm_msg.SendAlarmMsg("刷新广期所数据 Err:"+strings.Join(errMsgList, "\n"), 3)
  23. }
  24. wg.Done()
  25. }()
  26. var condition string
  27. var pars []interface{}
  28. condition += " AND source=? "
  29. pars = append(pars, utils.DATA_SOURCE_GFEX)
  30. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  31. if err != nil {
  32. return errors.New("GetEdbInfoByCondition:" + err.Error())
  33. }
  34. for _, v := range items {
  35. startDate := ""
  36. if v.Frequency == "日度" {
  37. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  38. } else if v.Frequency == "周度" {
  39. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  40. } else if v.Frequency == "月度" {
  41. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  42. } else if v.Frequency == "季度" {
  43. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  44. } else if v.Frequency == "年度" {
  45. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  46. } else {
  47. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  48. }
  49. resp, tmpErr := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  50. if err != nil {
  51. errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;err:%s", v.EdbInfoId, v.EdbCode, tmpErr.Error()))
  52. continue
  53. }
  54. if resp.Ret != 200 {
  55. errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;msg:%s;errMsg:%s", v.EdbInfoId, v.EdbCode, resp.Msg, resp.ErrMsg))
  56. continue
  57. }
  58. }
  59. return err
  60. }
  61. // RefreshDataFromDl 刷新大商所数据
  62. func RefreshDataFromDl(wg *sync.WaitGroup) (err error) {
  63. errMsgList := make([]string, 0)
  64. defer func() {
  65. if err != nil {
  66. errMsg := "刷新大商所数据 ErrMsg:" + err.Error()
  67. utils.FileLog.Info(errMsg)
  68. go alarm_msg.SendAlarmMsg(errMsg, 3)
  69. }
  70. if len(errMsgList) > 0 {
  71. utils.FileLog.Info("刷新大商所数据 Err:" + strings.Join(errMsgList, "\n"))
  72. go alarm_msg.SendAlarmMsg("刷新大商所数据 Err:"+strings.Join(errMsgList, "\n"), 3)
  73. }
  74. wg.Done()
  75. }()
  76. var condition string
  77. var pars []interface{}
  78. condition += " AND source=? "
  79. pars = append(pars, utils.DATA_SOURCE_DL)
  80. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  81. if err != nil {
  82. return errors.New("GetEdbInfoByCondition:" + err.Error())
  83. }
  84. for _, v := range items {
  85. startDate := ""
  86. if v.Frequency == "日度" {
  87. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  88. } else if v.Frequency == "周度" {
  89. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  90. } else if v.Frequency == "月度" {
  91. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  92. } else if v.Frequency == "季度" {
  93. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  94. } else if v.Frequency == "年度" {
  95. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  96. } else {
  97. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  98. }
  99. resp, tmpErr := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  100. if err != nil {
  101. errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;err:%s", v.EdbInfoId, v.EdbCode, tmpErr.Error()))
  102. continue
  103. }
  104. if resp.Ret != 200 {
  105. errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;msg:%s;errMsg:%s", v.EdbInfoId, v.EdbCode, resp.Msg, resp.ErrMsg))
  106. continue
  107. }
  108. }
  109. return err
  110. }
  111. // RefreshDataFromCffex 刷新中金所数据
  112. func RefreshDataFromCffex(wg *sync.WaitGroup) (err error) {
  113. defer func() {
  114. if err != nil {
  115. fmt.Println("RefreshDataFromCffex Err:" + err.Error())
  116. go alarm_msg.SendAlarmMsg("RefreshDataFromCffex ErrMsg:"+err.Error(), 3)
  117. }
  118. wg.Done()
  119. }()
  120. var condition string
  121. var pars []interface{}
  122. condition += " AND source=? "
  123. pars = append(pars, utils.DATA_SOURCE_CFFEX)
  124. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  125. if err != nil {
  126. return errors.New("GetEdbInfoByCondition:" + err.Error())
  127. }
  128. for _, v := range items {
  129. startDate := ""
  130. if v.Frequency == "日度" {
  131. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  132. } else if v.Frequency == "周度" {
  133. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  134. } else if v.Frequency == "月度" {
  135. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  136. } else if v.Frequency == "季度" {
  137. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  138. } else if v.Frequency == "年度" {
  139. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  140. } else {
  141. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  142. }
  143. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  144. if err != nil {
  145. return errors.New("RefreshEdbData Err:" + err.Error())
  146. }
  147. if resp.Ret != 200 {
  148. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  149. }
  150. }
  151. return err
  152. }
  153. // RefreshDataFromShfe 刷新上期能源数据
  154. func RefreshDataFromShfe(wg *sync.WaitGroup) (err error) {
  155. defer func() {
  156. if err != nil {
  157. fmt.Println("RefreshDataFromShfe Err:" + err.Error())
  158. go alarm_msg.SendAlarmMsg("RefreshDataFromShfe ErrMsg:"+err.Error(), 3)
  159. }
  160. wg.Done()
  161. }()
  162. var condition string
  163. var pars []interface{}
  164. condition += " AND source=? "
  165. pars = append(pars, utils.DATA_SOURCE_SHFE)
  166. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  167. if err != nil {
  168. return errors.New("GetEdbInfoByCondition:" + err.Error())
  169. }
  170. for _, v := range items {
  171. startDate := ""
  172. if v.Frequency == "日度" {
  173. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  174. } else if v.Frequency == "周度" {
  175. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  176. } else if v.Frequency == "月度" {
  177. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  178. } else if v.Frequency == "季度" {
  179. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  180. } else if v.Frequency == "年度" {
  181. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  182. } else {
  183. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  184. }
  185. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  186. if err != nil {
  187. return errors.New("RefreshEdbData Err:" + err.Error())
  188. }
  189. if resp.Ret != 200 {
  190. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  191. }
  192. }
  193. return err
  194. }
  195. // RefreshDataFromSh 刷新上期所数据
  196. func RefreshDataFromSh(wg *sync.WaitGroup) (err error) {
  197. defer func() {
  198. if err != nil {
  199. fmt.Println("RefreshDataFromSh Err:" + err.Error())
  200. go alarm_msg.SendAlarmMsg("RefreshDataFromSh ErrMsg:"+err.Error(), 3)
  201. }
  202. wg.Done()
  203. }()
  204. var condition string
  205. var pars []interface{}
  206. condition += " AND source=? "
  207. pars = append(pars, utils.DATA_SOURCE_SH)
  208. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  209. if err != nil {
  210. return errors.New("GetEdbInfoByCondition:" + err.Error())
  211. }
  212. for _, v := range items {
  213. startDate := ""
  214. if v.Frequency == "日度" {
  215. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  216. } else if v.Frequency == "周度" {
  217. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  218. } else if v.Frequency == "月度" {
  219. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  220. } else if v.Frequency == "季度" {
  221. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  222. } else if v.Frequency == "年度" {
  223. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  224. } else {
  225. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  226. }
  227. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  228. if err != nil {
  229. return errors.New("RefreshEdbData Err:" + err.Error())
  230. }
  231. if resp.Ret != 200 {
  232. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  233. }
  234. }
  235. return err
  236. }
  237. // RefreshDataFromZz 刷新郑商所数据
  238. func RefreshDataFromZz(wg *sync.WaitGroup) (err error) {
  239. defer func() {
  240. if err != nil {
  241. fmt.Println("RefreshDataFromZz Err:" + err.Error())
  242. go alarm_msg.SendAlarmMsg("RefreshDataFromZz ErrMsg:"+err.Error(), 3)
  243. }
  244. wg.Done()
  245. }()
  246. var condition string
  247. var pars []interface{}
  248. condition += " AND source=? "
  249. pars = append(pars, utils.DATA_SOURCE_ZZ)
  250. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  251. if err != nil {
  252. return errors.New("GetEdbInfoByCondition:" + err.Error())
  253. }
  254. for _, v := range items {
  255. startDate := ""
  256. if v.Frequency == "日度" {
  257. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  258. } else if v.Frequency == "周度" {
  259. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  260. } else if v.Frequency == "月度" {
  261. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  262. } else if v.Frequency == "季度" {
  263. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  264. } else if v.Frequency == "年度" {
  265. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  266. } else {
  267. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  268. }
  269. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  270. if err != nil {
  271. return errors.New("RefreshEdbData Err:" + err.Error())
  272. }
  273. if resp.Ret != 200 {
  274. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  275. }
  276. }
  277. return err
  278. }