edb_info.go 47 KB

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