edb_info.go 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  1. package data
  2. import (
  3. "context"
  4. "errors"
  5. "eta/eta_task/models/data_manage"
  6. "eta/eta_task/services/alarm_msg"
  7. "eta/eta_task/utils"
  8. "fmt"
  9. "strconv"
  10. "strings"
  11. "sync"
  12. "time"
  13. )
  14. // RefreshDataFromThs 刷新同花顺数据
  15. func RefreshDataFromThs(wg *sync.WaitGroup) (err error) {
  16. errMsgList := make([]string, 0)
  17. defer func() {
  18. if err != nil {
  19. fmt.Println("RefreshDataFromThs Err:" + err.Error())
  20. go alarm_msg.SendAlarmMsg("RefreshDataFromThs ErrMsg:"+err.Error(), 3)
  21. }
  22. if len(errMsgList) > 0 {
  23. errMsg := "RefreshDataFromThs Err:" + strings.Join(errMsgList, "\n")
  24. fmt.Println(errMsg)
  25. go alarm_msg.SendAlarmMsg(errMsg, 3)
  26. }
  27. wg.Done()
  28. }()
  29. var condition string
  30. var pars []interface{}
  31. condition += " AND source=? "
  32. pars = append(pars, utils.DATA_SOURCE_THS)
  33. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  34. if err != nil {
  35. err = errors.New("GetEdbInfoByCondition:" + err.Error())
  36. return
  37. }
  38. for _, v := range items {
  39. startDate := ""
  40. if v.Frequency == "日度" {
  41. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  42. } else if v.Frequency == "周度" {
  43. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  44. } else if v.Frequency == "月度" {
  45. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  46. } else if v.Frequency == "季度" {
  47. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  48. } else if v.Frequency == "年度" {
  49. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  50. } else {
  51. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  52. }
  53. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  54. if err != nil {
  55. errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+err.Error())
  56. continue
  57. }
  58. if resp.Ret != 200 {
  59. errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  60. continue
  61. }
  62. }
  63. return err
  64. }
  65. // RefreshDataFromWind 刷新万得数据
  66. func RefreshDataFromWind(wg *sync.WaitGroup) (err error) {
  67. errMsgList := make([]string, 0)
  68. defer func() {
  69. if err != nil {
  70. fmt.Println("RefreshDataFromWind Err:" + err.Error())
  71. go alarm_msg.SendAlarmMsg("RefreshDataFromWind ErrMsg:"+err.Error(), 3)
  72. }
  73. if len(errMsgList) > 0 {
  74. errMsg := "RefreshDataFromWind Err:" + strings.Join(errMsgList, "\n")
  75. fmt.Println(errMsg)
  76. go alarm_msg.SendAlarmMsg(errMsg, 3)
  77. }
  78. wg.Done()
  79. }()
  80. var condition string
  81. var pars []interface{}
  82. condition += ` AND source=? AND no_update = 0 `
  83. pars = append(pars, utils.DATA_SOURCE_WIND)
  84. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  85. if err != nil {
  86. return err
  87. }
  88. for _, v := range items {
  89. startDate := ""
  90. if v.Frequency == "日度" {
  91. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  92. } else if v.Frequency == "周度" {
  93. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  94. } else if v.Frequency == "月度" {
  95. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  96. } else if v.Frequency == "季度" {
  97. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  98. } else if v.Frequency == "年度" {
  99. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  100. } else {
  101. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  102. }
  103. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  104. if err != nil {
  105. errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+err.Error())
  106. continue
  107. }
  108. if resp.Ret != 200 {
  109. errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  110. continue
  111. }
  112. }
  113. fmt.Println("wind刷新结束")
  114. return err
  115. }
  116. // RefreshDataFromPb 刷新彭博数据
  117. func RefreshDataFromPb(wg *sync.WaitGroup) (err error) {
  118. errMsgList := make([]string, 0)
  119. defer func() {
  120. if err != nil {
  121. fmt.Println("RefreshDataFromPb Err:" + err.Error())
  122. go alarm_msg.SendAlarmMsg("RefreshDataFromPb ErrMsg:"+err.Error(), 3)
  123. }
  124. if len(errMsgList) > 0 {
  125. errMsg := "RefreshDataFromPb Err:" + strings.Join(errMsgList, "\n")
  126. fmt.Println(errMsg)
  127. go alarm_msg.SendAlarmMsg(errMsg, 3)
  128. }
  129. wg.Done()
  130. }()
  131. if utils.PbRefreshOpen == "0" {
  132. return
  133. }
  134. var condition string
  135. var pars []interface{}
  136. var frequencyStr string
  137. if utils.PbRefreshFrequency == "" {
  138. frequencyStr = "'日度','周度'"
  139. } else {
  140. frequencyStr = utils.PbRefreshFrequency
  141. }
  142. condition += " AND source=? AND frequency in (" + frequencyStr + ") "
  143. pars = append(pars, utils.DATA_SOURCE_PB)
  144. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  145. if err != nil {
  146. return errors.New("GetEdbInfoByCondition:" + err.Error())
  147. }
  148. for _, v := range items {
  149. startDate := ""
  150. if v.Frequency == "日度" {
  151. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  152. } else if v.Frequency == "周度" {
  153. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  154. } else if v.Frequency == "月度" {
  155. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  156. } else if v.Frequency == "季度" {
  157. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  158. } else if v.Frequency == "年度" {
  159. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  160. } else {
  161. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  162. }
  163. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  164. if err != nil {
  165. errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+err.Error())
  166. continue
  167. }
  168. if resp.Ret != 200 {
  169. errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  170. continue
  171. }
  172. }
  173. return err
  174. }
  175. // RefreshDataFromPbFinance 刷新彭博财务指标数据
  176. func RefreshDataFromPbFinance(wg *sync.WaitGroup) (err error) {
  177. errMsgList := make([]string, 0)
  178. defer func() {
  179. if err != nil {
  180. fmt.Println("RefreshDataFromPb Err:" + err.Error())
  181. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromPb ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  182. go alarm_msg.SendAlarmMsg("RefreshDataFromPb ErrMsg:"+err.Error(), 3)
  183. }
  184. if len(errMsgList) > 0 {
  185. errMsg := "RefreshDataFromPbFinance Err:" + strings.Join(errMsgList, "\n")
  186. fmt.Println(errMsg)
  187. go alarm_msg.SendAlarmMsg(errMsg, 3)
  188. }
  189. wg.Done()
  190. }()
  191. var condition string
  192. var pars []interface{}
  193. condition += " AND source=? "
  194. pars = append(pars, utils.DATA_SOURCE_PB_FINANCE)
  195. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  196. if err != nil {
  197. return errors.New("GetEdbInfoByCondition:" + err.Error())
  198. }
  199. for _, v := range items {
  200. startDate := ""
  201. if v.Frequency == "日度" {
  202. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  203. } else if v.Frequency == "周度" {
  204. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  205. } else if v.Frequency == "月度" {
  206. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  207. } else if v.Frequency == "季度" {
  208. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  209. } else if v.Frequency == "年度" {
  210. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  211. } else {
  212. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  213. }
  214. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  215. if err != nil {
  216. errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+err.Error())
  217. continue
  218. }
  219. if resp.Ret != 200 {
  220. errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  221. continue
  222. }
  223. }
  224. return err
  225. }
  226. // RefreshDataFromCalculateAll 刷新所有计算指标
  227. func RefreshDataFromCalculateAll() (err error) {
  228. errMsgList := make([]string, 0)
  229. defer func() {
  230. if err != nil {
  231. errMsg := "刷新所有计算指标失败 ErrMsg:" + err.Error()
  232. utils.FileLog.Info(errMsg)
  233. go alarm_msg.SendAlarmMsg(errMsg, 3)
  234. }
  235. if len(errMsgList) > 0 {
  236. utils.FileLog.Info("刷新所有计算指标失败 ErrMsg:" + strings.Join(errMsgList, "\n"))
  237. go alarm_msg.SendAlarmMsg("刷新所有计算指标失败 ErrMsg:"+strings.Join(errMsgList, "\n"), 3)
  238. }
  239. }()
  240. var condition string
  241. var pars []interface{}
  242. // 查询 普通指标的计算指标
  243. condition += " AND edb_type=? AND edb_info_type=? AND no_update=0"
  244. pars = append(pars, 2, 0)
  245. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  246. if err != nil {
  247. return err
  248. }
  249. for _, v := range items {
  250. source := v.Source
  251. startDate := v.StartDate.Format(utils.FormatDate)
  252. if startDate == "0001-01-01" {
  253. continue
  254. }
  255. fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source)
  256. fmt.Println("RefreshEdbCalculateData", v.EdbInfoId, v.EdbCode, startDate)
  257. result, tmpErr := RefreshEdbCalculateData(v.EdbInfoId, v.EdbCode, startDate)
  258. if tmpErr != nil {
  259. errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;err:%s", v.EdbInfoId, v.EdbCode, tmpErr.Error()))
  260. continue
  261. }
  262. if result.Ret != 200 {
  263. errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;msg:%s;errMsg:%s", v.EdbInfoId, v.EdbCode, result.Msg, result.ErrMsg))
  264. //return err
  265. continue
  266. }
  267. }
  268. return err
  269. }
  270. // RefreshBasePredictDataAll 刷新所有的基础预测指标
  271. func RefreshBasePredictDataAll() (err error) {
  272. errMsgList := make([]string, 0)
  273. defer func() {
  274. if err != nil {
  275. errMsg := "刷新所有计算指标失败 ErrMsg:" + err.Error()
  276. utils.FileLog.Info(errMsg)
  277. go alarm_msg.SendAlarmMsg(errMsg, 3)
  278. }
  279. if len(errMsgList) > 0 {
  280. utils.FileLog.Info("刷新所有基础预测指标失败 ErrMsg:" + strings.Join(errMsgList, "\n"))
  281. go alarm_msg.SendAlarmMsg("刷新所有基础预测指标失败 ErrMsg:"+strings.Join(errMsgList, "\n"), 3)
  282. }
  283. }()
  284. var condition string
  285. var pars []interface{}
  286. // 查询 普通指标的计算指标
  287. condition += " AND edb_type=? AND edb_info_type=? "
  288. pars = append(pars, 1, 1)
  289. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  290. if err != nil {
  291. errMsgList = append(errMsgList, fmt.Sprintf("获取基础预测指标列表失败;err:%s", err.Error()))
  292. return err
  293. }
  294. for _, v := range items {
  295. source := v.Source
  296. startDate := v.StartDate.Format(utils.FormatDate)
  297. if startDate == "0001-01-01" {
  298. continue
  299. }
  300. fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source, "======RefreshBasePredictDataAll:", startDate)
  301. result, tmpErr := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  302. if tmpErr != nil {
  303. errMsgList = append(errMsgList, fmt.Sprintf("刷新基础预测指标失败1,指标ID:%d;指标编码:%s;err:%s", v.EdbInfoId, v.EdbCode, tmpErr.Error()))
  304. continue
  305. }
  306. if result.Ret != 200 {
  307. errMsgList = append(errMsgList, fmt.Sprintf("刷新基础预测指标失败2,指标ID:%d;指标编码:%s;报错提示信息msg:%s;报错信息err:%s", v.EdbInfoId, v.EdbCode, result.ErrMsg, result.Msg))
  308. continue
  309. }
  310. }
  311. return err
  312. }
  313. // RefreshPredictDataFromCalculateAll 刷新所有预测计算指标
  314. func RefreshPredictDataFromCalculateAll() (err error) {
  315. errMsgList := make([]string, 0)
  316. defer func() {
  317. if err != nil {
  318. errMsg := "刷新所有计算预测指标失败 ErrMsg:" + err.Error()
  319. utils.FileLog.Info(errMsg)
  320. go alarm_msg.SendAlarmMsg(errMsg, 3)
  321. }
  322. if len(errMsgList) > 0 {
  323. utils.FileLog.Info("刷新所有计算预测指标失败 Err:" + strings.Join(errMsgList, "\n"))
  324. go alarm_msg.SendAlarmMsg("刷新所有计算预测指标失败 Err:"+strings.Join(errMsgList, "\n"), 3)
  325. }
  326. }()
  327. var condition string
  328. var pars []interface{}
  329. // 查询 普通指标的计算指标
  330. condition += " AND edb_type=? AND edb_info_type=? "
  331. pars = append(pars, 2, 1)
  332. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  333. if err != nil {
  334. return err
  335. }
  336. for _, v := range items {
  337. source := v.Source
  338. startDate := v.StartDate.Format(utils.FormatDate)
  339. if startDate == "0001-01-01" {
  340. continue
  341. }
  342. fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source, "======RefreshPredictEdbCalculateData:", startDate)
  343. result, tmpErr := RefreshPredictEdbCalculateData(v.EdbInfoId, v.EdbCode, startDate)
  344. if tmpErr != nil {
  345. errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;err:%s", v.EdbInfoId, v.EdbCode, tmpErr.Error()))
  346. continue
  347. }
  348. if result.Ret != 200 {
  349. errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;msg:%s;errMsg:%s", v.EdbInfoId, v.EdbCode, result.Msg, result.ErrMsg))
  350. continue
  351. }
  352. }
  353. return err
  354. }
  355. // RefreshDataFromManual 刷新手工指标数据
  356. func RefreshDataFromManual(wg *sync.WaitGroup) (err error) {
  357. errMsgList := make([]string, 0)
  358. defer func() {
  359. if err != nil {
  360. fmt.Println("RefreshDataFromManual Err:" + err.Error())
  361. go alarm_msg.SendAlarmMsg("RefreshDataFromManual ErrMsg:"+err.Error(), 3)
  362. }
  363. if len(errMsgList) > 0 {
  364. errMsg := "RefreshDataFromManual Err:" + strings.Join(errMsgList, "\n")
  365. fmt.Println(errMsg)
  366. go alarm_msg.SendAlarmMsg(errMsg, 3)
  367. }
  368. wg.Done()
  369. }()
  370. var condition string
  371. var pars []interface{}
  372. condition += " AND source=? "
  373. pars = append(pars, utils.DATA_SOURCE_MANUAL)
  374. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  375. if err != nil {
  376. return errors.New("GetEdbInfoByCondition:" + err.Error())
  377. }
  378. for _, v := range items {
  379. startDate := v.StartDate.Format(utils.FormatDate)
  380. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  381. if err != nil {
  382. errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+err.Error())
  383. continue
  384. }
  385. if resp.Ret != 200 {
  386. errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  387. continue
  388. }
  389. }
  390. return err
  391. }
  392. func ResetEdbInfoIsUpdate(cont context.Context) (err error) {
  393. go data_manage.ResetEdbInfoIsUpdate()
  394. return nil
  395. }
  396. // RefreshDataFromGoogleTravel RefreshDataFromEic 刷新谷歌出行数据
  397. func RefreshDataFromGoogleTravel(wg *sync.WaitGroup) (err error) {
  398. errMsgList := make([]string, 0)
  399. defer func() {
  400. if err != nil {
  401. fmt.Println("RefreshDataFromGoogleTravel Err:" + err.Error())
  402. go alarm_msg.SendAlarmMsg("RefreshDataFromGoogleTravel ErrMsg:"+err.Error(), 3)
  403. }
  404. if len(errMsgList) > 0 {
  405. tips := fmt.Sprintf("RefreshDataFromGoogleTravel ErrMsg: %s", strings.Join(errMsgList, `<br/>`))
  406. fmt.Println(tips)
  407. utils.FileLog.Info(tips)
  408. go alarm_msg.SendAlarmMsg(tips, 3)
  409. }
  410. wg.Done()
  411. }()
  412. var condition string
  413. var pars []interface{}
  414. condition += " AND source=? "
  415. pars = append(pars, utils.DATA_SOURCE_GOOGLE_TRAVEL)
  416. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  417. if err != nil {
  418. return errors.New("GetEdbInfoByCondition:" + err.Error())
  419. }
  420. for _, v := range items {
  421. startDate := ""
  422. if v.Frequency == "日度" {
  423. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  424. } else if v.Frequency == "周度" {
  425. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  426. } else if v.Frequency == "月度" {
  427. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  428. } else if v.Frequency == "季度" {
  429. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  430. } else if v.Frequency == "年度" {
  431. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  432. } else {
  433. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  434. }
  435. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  436. if err != nil {
  437. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  438. continue
  439. }
  440. if resp.Ret != 200 {
  441. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  442. continue
  443. }
  444. }
  445. return err
  446. }
  447. // RefreshDataFromEiaSteo 刷新eia steo 报告数据
  448. func RefreshDataFromEiaSteo(wg *sync.WaitGroup) (err error) {
  449. errMsgList := make([]string, 0)
  450. defer func() {
  451. if err != nil {
  452. fmt.Println("RefreshDataFromEiaSteo Err:" + err.Error())
  453. go alarm_msg.SendAlarmMsg("RefreshDataFromEiaSteo ErrMsg:"+err.Error(), 3)
  454. }
  455. if len(errMsgList) > 0 {
  456. tips := fmt.Sprintf("RefreshDataFromEiaSteo ErrMsg: %s", strings.Join(errMsgList, `<br/>`))
  457. fmt.Println(tips)
  458. utils.FileLog.Info(tips)
  459. go alarm_msg.SendAlarmMsg(tips, 3)
  460. }
  461. wg.Done()
  462. }()
  463. var condition string
  464. var pars []interface{}
  465. condition += " AND source=? "
  466. pars = append(pars, utils.DATA_SOURCE_EIA_STEO)
  467. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  468. if err != nil {
  469. return errors.New("GetEdbInfoByCondition:" + err.Error())
  470. }
  471. for _, v := range items {
  472. startDate := ""
  473. if v.Frequency == "日度" {
  474. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  475. } else if v.Frequency == "周度" {
  476. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  477. } else if v.Frequency == "月度" {
  478. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  479. } else if v.Frequency == "季度" {
  480. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  481. } else if v.Frequency == "年度" {
  482. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  483. } else {
  484. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  485. }
  486. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  487. if err != nil {
  488. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  489. continue
  490. }
  491. if resp.Ret != 200 {
  492. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  493. continue
  494. }
  495. }
  496. return err
  497. }
  498. // RefreshDataFromYs 刷新有色数据
  499. func RefreshDataFromYs(wg *sync.WaitGroup) (err error) {
  500. errMsgList := make([]string, 0)
  501. defer func() {
  502. if err != nil {
  503. fmt.Println("RefreshDataFromYs Err:" + err.Error())
  504. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromYs ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  505. go alarm_msg.SendAlarmMsg("RefreshDataFromYs ErrMsg:"+err.Error(), 3)
  506. }
  507. if len(errMsgList) > 0 {
  508. errMsg := "RefreshDataFromYs Err:" + strings.Join(errMsgList, "\n")
  509. fmt.Println(errMsg)
  510. go alarm_msg.SendAlarmMsg(errMsg, 3)
  511. }
  512. wg.Done()
  513. }()
  514. var condition string
  515. var pars []interface{}
  516. condition += " AND source=? "
  517. pars = append(pars, utils.DATA_SOURCE_YS)
  518. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  519. if err != nil {
  520. return errors.New("GetEdbInfoByCondition:" + err.Error())
  521. }
  522. for _, v := range items {
  523. startDate := ""
  524. if v.Frequency == "日度" {
  525. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  526. } else if v.Frequency == "周度" {
  527. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  528. } else if v.Frequency == "月度" {
  529. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  530. } else if v.Frequency == "季度" {
  531. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  532. } else if v.Frequency == "年度" {
  533. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  534. } else {
  535. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  536. }
  537. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  538. if err != nil {
  539. errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+err.Error())
  540. continue
  541. }
  542. if resp.Ret != 200 {
  543. errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  544. continue
  545. }
  546. }
  547. return err
  548. }
  549. // 刷新钢联数据
  550. func RefreshDataFromGl(wg *sync.WaitGroup) (err error) {
  551. errMsgList := make([]string, 0)
  552. defer func() {
  553. if err != nil {
  554. fmt.Println("RefreshDataFromGl Err:" + err.Error())
  555. go alarm_msg.SendAlarmMsg("RefreshDataFromGl ErrMsg:"+err.Error(), 3)
  556. }
  557. if len(errMsgList) > 0 {
  558. tips := fmt.Sprintf("RefreshDataFromGl ErrMsg: %s", strings.Join(errMsgList, `<br/>`))
  559. fmt.Println(tips)
  560. utils.FileLog.Info(tips)
  561. go alarm_msg.SendAlarmMsg(tips, 3)
  562. }
  563. wg.Done()
  564. }()
  565. var condition string
  566. var pars []interface{}
  567. condition += " AND source=? "
  568. pars = append(pars, utils.DATA_SOURCE_GL)
  569. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  570. if err != nil {
  571. return errors.New("GetEdbInfoByCondition:" + err.Error())
  572. }
  573. for _, v := range items {
  574. startDate := ""
  575. if v.Frequency == "日度" {
  576. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  577. } else if v.Frequency == "周度" {
  578. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  579. } else if v.Frequency == "月度" {
  580. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  581. } else if v.Frequency == "季度" {
  582. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  583. } else if v.Frequency == "年度" {
  584. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  585. } else {
  586. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  587. }
  588. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  589. if err != nil {
  590. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  591. continue
  592. }
  593. if resp.Ret != 200 {
  594. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  595. continue
  596. }
  597. }
  598. return err
  599. }
  600. // RefreshDataFromLt 刷新路透数据
  601. func RefreshDataFromLt(wg *sync.WaitGroup) (err error) {
  602. errMsgList := make([]string, 0)
  603. defer func() {
  604. if len(errMsgList) > 0 {
  605. tips := fmt.Sprintf("RefreshDataFromLt ErrMsg: %s", strings.Join(errMsgList, `<br/>`))
  606. fmt.Println(tips)
  607. utils.FileLog.Info(tips)
  608. go alarm_msg.SendAlarmMsg(tips, 3)
  609. }
  610. utils.FileLog.Info("RefreshDataFromLt刷新结束")
  611. wg.Done()
  612. }()
  613. var condition string
  614. var pars []interface{}
  615. condition += " AND source=? "
  616. pars = append(pars, utils.DATA_SOURCE_LT)
  617. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  618. if err != nil {
  619. errMsgList = append(errMsgList, "GetEdbInfoByCondition:"+err.Error())
  620. return errors.New("GetEdbInfoByCondition:" + err.Error())
  621. }
  622. for _, v := range items {
  623. fmt.Println(v.EdbCode, v.Frequency, v.EndDate)
  624. startDate := v.StartDate.Format(utils.FormatDate)
  625. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  626. if err != nil {
  627. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  628. continue
  629. }
  630. if resp.Ret != 200 {
  631. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  632. continue
  633. }
  634. }
  635. return err
  636. }
  637. // RefreshDataFromCoal 刷新煤炭网数据
  638. func RefreshDataFromCoal(wg *sync.WaitGroup) (err error) {
  639. errMsgList := make([]string, 0)
  640. defer func() {
  641. if err != nil {
  642. fmt.Println("RefreshDataFromCoal Err:" + err.Error())
  643. go alarm_msg.SendAlarmMsg("RefreshDataFromCoal ErrMsg:"+err.Error(), 3)
  644. }
  645. if len(errMsgList) > 0 {
  646. tips := fmt.Sprintf("RefreshDataFromCoal ErrMsg: %s", strings.Join(errMsgList, `<br/>`))
  647. fmt.Println(tips)
  648. utils.FileLog.Info(tips)
  649. go alarm_msg.SendAlarmMsg(tips, 3)
  650. }
  651. wg.Done()
  652. }()
  653. var condition string
  654. var pars []interface{}
  655. condition += " AND source=? "
  656. pars = append(pars, utils.DATA_SOURCE_COAL)
  657. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  658. if err != nil {
  659. return errors.New("GetEdbInfoByCondition:" + err.Error())
  660. }
  661. for _, v := range items {
  662. startDate := ""
  663. if v.Frequency == "日度" {
  664. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  665. } else if v.Frequency == "周度" {
  666. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  667. } else if v.Frequency == "月度" {
  668. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  669. } else if v.Frequency == "季度" {
  670. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  671. } else if v.Frequency == "年度" {
  672. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  673. } else {
  674. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  675. }
  676. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  677. if err != nil {
  678. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  679. continue
  680. }
  681. if resp.Ret != 200 {
  682. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  683. continue
  684. }
  685. }
  686. return err
  687. }
  688. // RefreshDataFromMysteelChemical 刷新钢联化工数据
  689. func RefreshDataFromMysteelChemical(wg *sync.WaitGroup) (err error) {
  690. errMsgList := make([]string, 0)
  691. defer func() {
  692. if err != nil {
  693. fmt.Println("RefreshDataFromMysteelChemical Err:" + err.Error())
  694. go alarm_msg.SendAlarmMsg("RefreshDataFromMysteelChemical ErrMsg:"+err.Error(), 3)
  695. }
  696. if len(errMsgList) > 0 {
  697. tips := fmt.Sprintf("RefreshDataFromMysteelChemical ErrMsg: %s", strings.Join(errMsgList, `<br/>`))
  698. fmt.Println(tips)
  699. utils.FileLog.Info(tips)
  700. go alarm_msg.SendAlarmMsg(tips, 3)
  701. }
  702. wg.Done()
  703. }()
  704. var condition string
  705. var pars []interface{}
  706. condition += " AND source=? AND no_update = 0 "
  707. pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
  708. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  709. if err != nil {
  710. return errors.New("GetEdbInfoByCondition:" + err.Error())
  711. }
  712. for _, v := range items {
  713. startDate := ""
  714. if v.Frequency == "日度" {
  715. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  716. } else if v.Frequency == "周度" {
  717. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  718. } else if v.Frequency == "月度" {
  719. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  720. } else if v.Frequency == "季度" {
  721. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  722. } else if v.Frequency == "年度" {
  723. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  724. } else {
  725. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  726. }
  727. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  728. if err != nil {
  729. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  730. continue
  731. }
  732. if resp.Ret != 200 {
  733. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  734. continue
  735. }
  736. }
  737. return err
  738. }
  739. // RefreshDataFromComTrade 刷新 UN 数据
  740. func RefreshDataFromComTrade(wg *sync.WaitGroup) (err error) {
  741. errMsgList := make([]string, 0)
  742. defer func() {
  743. if err != nil {
  744. fmt.Println("RefreshDataFromComTrade Err:" + err.Error())
  745. go alarm_msg.SendAlarmMsg("RefreshDataFromComTrade ErrMsg:"+err.Error(), 3)
  746. }
  747. if len(errMsgList) > 0 {
  748. tips := fmt.Sprintf("RefreshDataFromComTrade ErrMsg: %s", strings.Join(errMsgList, `<br/>`))
  749. fmt.Println(tips)
  750. utils.FileLog.Info(tips)
  751. go alarm_msg.SendAlarmMsg(tips, 3)
  752. }
  753. wg.Done()
  754. }()
  755. var condition string
  756. var pars []interface{}
  757. condition += " AND source=? "
  758. pars = append(pars, utils.DATA_SOURCE_COM_TRADE)
  759. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  760. if err != nil {
  761. return errors.New("GetEdbInfoByCondition:" + err.Error())
  762. }
  763. for _, v := range items {
  764. startDate := ""
  765. if v.Frequency == "日度" {
  766. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  767. } else if v.Frequency == "周度" {
  768. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  769. } else if v.Frequency == "月度" {
  770. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  771. } else if v.Frequency == "季度" {
  772. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  773. } else if v.Frequency == "年度" {
  774. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  775. } else {
  776. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  777. }
  778. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  779. if err != nil {
  780. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  781. continue
  782. }
  783. if resp.Ret != 200 {
  784. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  785. continue
  786. }
  787. }
  788. return err
  789. }
  790. // RefreshDataFromSci 刷新 卓创 数据
  791. func RefreshDataFromSci(wg *sync.WaitGroup) (err error) {
  792. errMsgList := make([]string, 0)
  793. defer func() {
  794. if err != nil {
  795. fmt.Println("RefreshDataFromSci Err:" + err.Error())
  796. go alarm_msg.SendAlarmMsg("RefreshDataFromSci ErrMsg:"+err.Error(), 3)
  797. }
  798. if len(errMsgList) > 0 {
  799. tips := fmt.Sprintf("RefreshDataFromSci ErrMsg: %s", strings.Join(errMsgList, `<br/>`))
  800. fmt.Println(tips)
  801. utils.FileLog.Info(tips)
  802. go alarm_msg.SendAlarmMsg(tips, 3)
  803. }
  804. wg.Done()
  805. }()
  806. var condition string
  807. var pars []interface{}
  808. condition += " AND source=? "
  809. pars = append(pars, utils.DATA_SOURCE_SCI)
  810. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  811. if err != nil {
  812. return errors.New("GetEdbInfoByCondition:" + err.Error())
  813. }
  814. for _, v := range items {
  815. startDate := ""
  816. if v.Frequency == "日度" {
  817. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  818. } else if v.Frequency == "周度" {
  819. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  820. } else if v.Frequency == "月度" {
  821. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  822. } else if v.Frequency == "季度" {
  823. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  824. } else if v.Frequency == "年度" {
  825. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  826. } else {
  827. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  828. }
  829. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  830. if err != nil {
  831. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  832. continue
  833. }
  834. if resp.Ret != 200 {
  835. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  836. continue
  837. }
  838. }
  839. return err
  840. }
  841. // RefreshDataFromNationalStatistics 刷新统计局数据
  842. func RefreshDataFromNationalStatistics(wg *sync.WaitGroup) (err error) {
  843. errMsgList := make([]string, 0)
  844. defer func() {
  845. if err != nil {
  846. fmt.Println("RefreshDataFromNationalStatistics Err:" + err.Error())
  847. go alarm_msg.SendAlarmMsg("RefreshDataFromNationalStatistics ErrMsg:"+err.Error(), 3)
  848. }
  849. if len(errMsgList) > 0 {
  850. tips := fmt.Sprintf("RefreshDataFromNationalStatistics ErrMsg: %s", strings.Join(errMsgList, `<br/>`))
  851. fmt.Println(tips)
  852. utils.FileLog.Info(tips)
  853. go alarm_msg.SendAlarmMsg(tips, 3)
  854. }
  855. wg.Done()
  856. }()
  857. var condition string
  858. var pars []interface{}
  859. condition += ` AND source = ? `
  860. pars = append(pars, utils.DATA_SOURCE_NATIONAL_STATISTICS)
  861. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  862. if err != nil {
  863. return errors.New("GetEdbInfoByCondition:" + err.Error())
  864. }
  865. for _, v := range items {
  866. startDate := ""
  867. if v.Frequency == "日度" {
  868. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  869. } else if v.Frequency == "周度" {
  870. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  871. } else if v.Frequency == "月度" {
  872. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  873. } else if v.Frequency == "季度" {
  874. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  875. } else if v.Frequency == "年度" {
  876. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  877. } else {
  878. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  879. }
  880. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  881. if err != nil {
  882. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  883. continue
  884. }
  885. if resp.Ret != 200 {
  886. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  887. continue
  888. }
  889. }
  890. return err
  891. }
  892. // RefreshDataFromEic 刷欧洲天然气数据
  893. func RefreshDataFromEic(wg *sync.WaitGroup) (err error) {
  894. defer func() {
  895. if err != nil {
  896. fmt.Println("RefreshDataFromEic Err:" + err.Error())
  897. go alarm_msg.SendAlarmMsg("RefreshDataFromEic ErrMsg:"+err.Error(), 3)
  898. }
  899. wg.Done()
  900. }()
  901. var condition string
  902. var pars []interface{}
  903. condition += " AND source=? "
  904. pars = append(pars, utils.DATA_SOURCE_GIE)
  905. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  906. if err != nil {
  907. return errors.New("GetEdbInfoByCondition:" + err.Error())
  908. }
  909. for _, v := range items {
  910. startDate := ""
  911. if v.Frequency == "日度" {
  912. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  913. } else if v.Frequency == "周度" {
  914. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  915. } else if v.Frequency == "月度" {
  916. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  917. } else if v.Frequency == "季度" {
  918. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  919. } else if v.Frequency == "年度" {
  920. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  921. } else {
  922. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  923. }
  924. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  925. if err != nil {
  926. return errors.New("RefreshEdbData Err:" + err.Error())
  927. }
  928. if resp.Ret != 200 {
  929. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  930. }
  931. }
  932. return err
  933. }
  934. // RefreshJiaYueDataFromBridge 嘉悦物产-刷新数据宝指标
  935. func RefreshJiaYueDataFromBridge(cont context.Context) (err error) {
  936. utils.FileLog.Info(fmt.Sprintf("嘉悦-开始刷新数据宝指标: %s", time.Now().Format(utils.FormatDateTime)))
  937. defer func() {
  938. if err != nil {
  939. tips := fmt.Sprintf("RefreshJiaYueDataFromBridge ErrMsg: %s", err.Error())
  940. utils.FileLog.Info(tips)
  941. go alarm_msg.SendAlarmMsg(tips, 3)
  942. }
  943. utils.FileLog.Info(fmt.Sprintf("嘉悦-结束刷新数据宝指标: %s", time.Now().Format(utils.FormatDateTime)))
  944. }()
  945. // 获取来自桥接服务的指标来源
  946. cond := ` AND from_bridge = 1`
  947. pars := make([]interface{}, 0)
  948. sources, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  949. if e != nil {
  950. err = fmt.Errorf("获取来自桥接服务的数据源失败, err: %s", e.Error())
  951. return
  952. }
  953. sourceArr := make([]string, 0)
  954. for _, v := range sources {
  955. if v.EdbSourceId <= 0 {
  956. continue
  957. }
  958. sourceArr = append(sourceArr, strconv.Itoa(v.EdbSourceId))
  959. }
  960. if len(sourceArr) == 0 {
  961. utils.FileLog.Info("RefreshJiaYueDataFromBridge 无数据来源")
  962. return
  963. }
  964. // 获取指标
  965. edbCond := fmt.Sprintf(` AND source IN (%s)`, utils.GetOrmInReplace(len(sourceArr)))
  966. edbPars := make([]interface{}, 0)
  967. edbPars = append(edbPars, sourceArr)
  968. items, e := data_manage.GetEdbInfoByCondition(edbCond, edbPars, 0)
  969. if e != nil {
  970. err = fmt.Errorf("GetEdbInfoByCondition err: %s", e.Error())
  971. return
  972. }
  973. for _, v := range items {
  974. startDate := ""
  975. if v.Frequency == "日度" {
  976. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  977. } else if v.Frequency == "周度" {
  978. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  979. } else if v.Frequency == "月度" {
  980. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  981. } else if v.Frequency == "季度" {
  982. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  983. } else if v.Frequency == "年度" {
  984. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  985. } else {
  986. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  987. }
  988. resp, e := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  989. if e != nil {
  990. utils.FileLog.Info(fmt.Sprintf("RefreshEdbData err: %s", e.Error()))
  991. //err = fmt.Errorf("RefreshEdbData err: %s", e.Error())
  992. continue
  993. }
  994. if resp.Ret != 200 {
  995. utils.FileLog.Info(fmt.Sprintf("RefreshEdbData indexCode: %s, err: %s, errMsg: %s", v.EdbCode, resp.Msg, resp.ErrMsg))
  996. //err = fmt.Errorf("RefreshEdbData Err: %s; ErrMsg: %s", resp.Msg, resp.ErrMsg)
  997. continue
  998. }
  999. }
  1000. return
  1001. }
  1002. // RefreshDataFromFubao 刷新富宝数据
  1003. func RefreshDataFromFubao(wg *sync.WaitGroup) (err error) {
  1004. errMsgList := make([]string, 0)
  1005. defer func() {
  1006. if err != nil {
  1007. fmt.Println("RefreshDataFromFubao Err:" + err.Error())
  1008. go alarm_msg.SendAlarmMsg("RefreshDataFromFubao ErrMsg:"+err.Error(), 3)
  1009. }
  1010. if len(errMsgList) > 0 {
  1011. errMsg := "RefreshDataFromFubao Err:" + strings.Join(errMsgList, "\n")
  1012. fmt.Println(errMsg)
  1013. go alarm_msg.SendAlarmMsg(errMsg, 3)
  1014. }
  1015. wg.Done()
  1016. }()
  1017. var condition string
  1018. var pars []interface{}
  1019. condition += ` AND source=? AND no_update = 0 `
  1020. pars = append(pars, utils.DATA_SOURCE_FUBAO)
  1021. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1022. if err != nil {
  1023. return err
  1024. }
  1025. for _, v := range items {
  1026. startDate := ""
  1027. if v.Frequency == "日度" {
  1028. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1029. } else if v.Frequency == "周度" {
  1030. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1031. } else if v.Frequency == "月度" {
  1032. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1033. } else if v.Frequency == "季度" {
  1034. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1035. } else if v.Frequency == "年度" {
  1036. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1037. } else {
  1038. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1039. }
  1040. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  1041. if err != nil {
  1042. errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+err.Error())
  1043. continue
  1044. }
  1045. if resp.Ret != 200 {
  1046. errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  1047. continue
  1048. }
  1049. }
  1050. fmt.Println("Fubao刷新结束")
  1051. return err
  1052. }
  1053. // RefreshDataFromBloomberg 刷新Bloomberg
  1054. func RefreshDataFromBloomberg(wg *sync.WaitGroup) (err error) {
  1055. errMsgList := make([]string, 0)
  1056. defer func() {
  1057. if err != nil {
  1058. fmt.Println("RefreshDataFromBloomberg Err:" + err.Error())
  1059. go alarm_msg.SendAlarmMsg("RefreshDataFromBloomberg ErrMsg:"+err.Error(), 3)
  1060. }
  1061. if len(errMsgList) > 0 {
  1062. errMsg := "RefreshDataFromBloomberg Err:" + strings.Join(errMsgList, "\n")
  1063. fmt.Println(errMsg)
  1064. go alarm_msg.SendAlarmMsg(errMsg, 3)
  1065. }
  1066. wg.Done()
  1067. }()
  1068. var condition string
  1069. var pars []interface{}
  1070. condition += ` AND source = ? AND no_update = 0 `
  1071. pars = append(pars, utils.DATA_SOURCE_BLOOMBERG)
  1072. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1073. if err != nil {
  1074. return err
  1075. }
  1076. for _, v := range items {
  1077. startDate := ""
  1078. if v.Frequency == "日度" {
  1079. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1080. } else if v.Frequency == "周度" {
  1081. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1082. } else if v.Frequency == "月度" {
  1083. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1084. } else if v.Frequency == "季度" {
  1085. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1086. } else if v.Frequency == "年度" {
  1087. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1088. } else {
  1089. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1090. }
  1091. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  1092. if err != nil {
  1093. errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+err.Error())
  1094. continue
  1095. }
  1096. if resp.Ret != 200 {
  1097. errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  1098. continue
  1099. }
  1100. }
  1101. fmt.Println("Bloomberg刷新结束")
  1102. return err
  1103. }
  1104. // RefreshDataFromCCF 刷新CCF化纤信息
  1105. func RefreshDataFromCCF(wg *sync.WaitGroup) (err error) {
  1106. errMsgList := make([]string, 0)
  1107. defer func() {
  1108. if err != nil {
  1109. tips := fmt.Sprintf("RefreshDataFromCCF err: %v", err)
  1110. utils.FileLog.Info(tips)
  1111. go alarm_msg.SendAlarmMsg(tips, 3)
  1112. }
  1113. if len(errMsgList) > 0 {
  1114. tips := fmt.Sprintf("RefreshDataFromCCF ErrMsg: %s", strings.Join(errMsgList, "\n"))
  1115. utils.FileLog.Info(tips)
  1116. go alarm_msg.SendAlarmMsg(tips, 3)
  1117. }
  1118. wg.Done()
  1119. }()
  1120. var condition string
  1121. var pars []interface{}
  1122. condition += ` AND source = ? AND no_update = 0 `
  1123. pars = append(pars, utils.DATA_SOURCE_CCF)
  1124. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1125. if err != nil {
  1126. return err
  1127. }
  1128. for _, v := range items {
  1129. startDate := ""
  1130. if v.Frequency == "日度" {
  1131. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1132. } else if v.Frequency == "周度" {
  1133. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1134. } else if v.Frequency == "月度" {
  1135. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1136. } else if v.Frequency == "季度" {
  1137. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1138. } else if v.Frequency == "年度" {
  1139. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1140. } else {
  1141. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1142. }
  1143. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  1144. if err != nil {
  1145. errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+err.Error())
  1146. continue
  1147. }
  1148. if resp.Ret != 200 {
  1149. errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  1150. continue
  1151. }
  1152. }
  1153. fmt.Println("CCF化纤信息刷新结束")
  1154. return err
  1155. }
  1156. // RefreshBaseDataFromSource
  1157. // @Description: 刷新基础数据
  1158. // @author: Roc
  1159. // @datetime 2024-08-01 18:10:03
  1160. // @param wg *sync.WaitGroup
  1161. // @param source int
  1162. // @return err error
  1163. func RefreshBaseDataFromSource(wg *sync.WaitGroup, source int) (err error) {
  1164. errMsgList := make([]string, 0)
  1165. defer func() {
  1166. if err != nil {
  1167. errMsg := fmt.Sprintf("刷新基础数据失败,来源:%d,ErrMsg:%s", source, err.Error())
  1168. utils.FileLog.Info(errMsg)
  1169. go alarm_msg.SendAlarmMsg(errMsg, 3)
  1170. }
  1171. if len(errMsgList) > 0 {
  1172. errMsg := fmt.Sprintf("刷新基础数据失败,来源:%d,ErrMsg:%s", source, strings.Join(errMsgList, "\n"))
  1173. utils.FileLog.Info(errMsg)
  1174. go alarm_msg.SendAlarmMsg(errMsg, 3)
  1175. }
  1176. wg.Done()
  1177. }()
  1178. var condition string
  1179. var pars []interface{}
  1180. condition += " AND source=? "
  1181. pars = append(pars, source)
  1182. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1183. if err != nil {
  1184. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1185. }
  1186. for _, v := range items {
  1187. startDate := ""
  1188. if v.Frequency == "日度" {
  1189. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1190. } else if v.Frequency == "周度" {
  1191. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1192. } else if v.Frequency == "月度" {
  1193. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1194. } else if v.Frequency == "季度" {
  1195. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1196. } else if v.Frequency == "年度" {
  1197. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1198. } else {
  1199. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1200. }
  1201. resp, tmpErr := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  1202. if err != nil {
  1203. errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;err:%s", v.EdbInfoId, v.EdbCode, tmpErr.Error()))
  1204. continue
  1205. }
  1206. if resp.Ret != 200 {
  1207. errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;msg:%s;errMsg:%s", v.EdbInfoId, v.EdbCode, resp.Msg, resp.ErrMsg))
  1208. continue
  1209. }
  1210. }
  1211. return err
  1212. }