task.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package services
  2. import (
  3. "context"
  4. "eta/eta_task/services/data"
  5. "eta/eta_task/services/data/future_good"
  6. "eta/eta_task/utils"
  7. "fmt"
  8. "github.com/beego/beego/v2/task"
  9. "sync"
  10. "time"
  11. )
  12. func Task() {
  13. fmt.Println("task start")
  14. //如果是生产环境,才需要走这些任务
  15. if utils.RunMode == "release" {
  16. releaseTask()
  17. }
  18. // 定时发布智能研报
  19. publishSmartReport := task.NewTask("publishSmartReport", "0 */1 * * * *", PublishSmartReport)
  20. task.AddTask("定时发布智能研报", publishSmartReport)
  21. task.StartTask()
  22. fmt.Println("task end")
  23. }
  24. // 生产环境需要走的任务
  25. func releaseTask() {
  26. //同步指标
  27. if utils.BusinessCode != utils.BusinessCodeRelease {
  28. syncHzDataIndex := task.NewTask("syncHzDataIndex", "0 10,20,40,50 16,18 * * *", SyncHzDataIndex)
  29. task.AddTask("syncHzDataIndex", syncHzDataIndex)
  30. }
  31. // 定时统计交易所的持仓分析数据
  32. initPositionTask := task.NewTask("initPositionTask", "0 20,40 16-18 * * *", data.InitPositionTask)
  33. task.AddTask("initPositionTask", initPositionTask)
  34. //刷新指标数据
  35. refreshData := task.NewTask("refreshData", "0 30 0,19 * * *", RefreshData)
  36. task.AddTask("refreshData", refreshData)
  37. //同步弘则数据库中来自,钢联,隆众,有色,人工等基础数据--每隔五分钟,同步一次最新数据
  38. syncBaseData := task.NewTask("syncBaseData", "0 */5 * * * * ", SyncBaseData)
  39. task.AddTask("syncBaseData", syncBaseData)
  40. syncBaseDataExt := task.NewTask("syncBaseDataExt", "0 */30 * * * * ", SyncBaseDataExt)
  41. task.AddTask("syncBaseDataExt", syncBaseDataExt)
  42. //初始化指标更新状态
  43. resetEdbInfoIsUpdate := task.NewTask("resetEdbInfoIsUpdate", "0 0 0 * * *", data.ResetEdbInfoIsUpdate)
  44. task.AddTask("resetEdbInfoIsUpdate", resetEdbInfoIsUpdate)
  45. // 刷新商品数据
  46. refreshFutureGoodData := task.NewTask("refreshFutureGoodData", "0 30 0,19 * * *", RefreshFutureGoodData)
  47. task.AddTask("refreshFutureGoodData", refreshFutureGoodData)
  48. //刷新交易所指标数据
  49. refreshTradeData := task.NewTask("refreshData", "0 1 4 * * *", RefreshTradeData)
  50. task.AddTask("refreshTradeData", refreshTradeData)
  51. //刷新欧洲天然气指标数据
  52. refreshEicData := task.NewTask("refreshData", "0 1 3,7 * * *", RefreshEicData)
  53. task.AddTask("refreshEicData", refreshEicData)
  54. //检测数据服务器
  55. checkDataServer := task.NewTask("checkDataServer", "0 */2 * * * * ", checkDataServer)
  56. task.AddTask("checkDataServer", checkDataServer)
  57. //删除日志 report_save_log,ppt_v2_save_log,保留一个月的
  58. deleteLog := task.NewTask("syncSubStatus", "0 0 2 2 * *", DeleteLog)
  59. task.AddTask("deleteLog", deleteLog)
  60. // 定时发布研报
  61. publishReport := task.NewTask("publishReport", "0 */1 * * * *", PublishReport)
  62. task.AddTask("定时发布研报", publishReport)
  63. // 定时发布英文研报
  64. publishEnglishReport := task.NewTask("publishEnglishReport", "0 */1 * * * *", PublishEnglishReport)
  65. task.AddTask("定时发布英文研报", publishEnglishReport)
  66. // 每天清理两周前的报告保存日志
  67. clearReportSaveLog := task.NewTask("clearReportSaveLog", "0 15 23 * * *", ClearReportSaveLog)
  68. task.AddTask("定时清理报告保存日志", clearReportSaveLog)
  69. // 每天清理三个月前的用户操作日志
  70. clearAdminOperateLog := task.NewTask("clearAdminOperateLog", "0 20 23 * * *", ClearAdminOperateLog)
  71. task.AddTask("定时清理用户操作日志", clearAdminOperateLog)
  72. // 嘉悦物产-每分钟定时同步增量指标
  73. if utils.BusinessCode == utils.BusinessCodeJiaYue {
  74. syncJiaYueNewIndex := task.NewTask("syncJiaYueNewIndex", "0 */1 * * * *", data.SyncJiaYueNewIndex)
  75. task.AddTask("定时同步嘉悦物产增量指标", syncJiaYueNewIndex)
  76. }
  77. }
  78. func RefreshData(cont context.Context) (err error) {
  79. wg := sync.WaitGroup{}
  80. wg.Add(15)
  81. //hour := time.Now().Hour()
  82. //if hour != 0 {
  83. //}
  84. go data.RefreshDataFromWind(&wg)
  85. //同花顺
  86. go data.RefreshDataFromThs(&wg)
  87. //彭博
  88. go data.RefreshDataFromPb(&wg)
  89. //彭博财务
  90. go data.RefreshDataFromPbFinance(&wg)
  91. //手工数据
  92. go data.RefreshDataFromManual(&wg)
  93. //隆众数据
  94. //go data.RefreshDataFromLz(&wg)
  95. //有色
  96. go data.RefreshDataFromYs(&wg)
  97. //钢联
  98. go data.RefreshDataFromGl(&wg)
  99. //路透
  100. go data.RefreshDataFromLt(&wg)
  101. //煤炭
  102. go data.RefreshDataFromCoal(&wg)
  103. //谷歌出行数据
  104. go data.RefreshDataFromGoogleTravel(&wg)
  105. //钢联化工
  106. go data.RefreshDataFromMysteelChemical(&wg)
  107. //eia steo报告指标
  108. go data.RefreshDataFromEiaSteo(&wg)
  109. //UN报告指标
  110. go data.RefreshDataFromComTrade(&wg)
  111. //卓创报告指标
  112. go data.RefreshDataFromSci(&wg)
  113. //国家统计局指标
  114. go data.RefreshDataFromNationalStatistics(&wg)
  115. // 来自桥接服务的指标
  116. wg.Add(1)
  117. go data.RefreshDataFromBridge(&wg)
  118. wg.Wait()
  119. ////计算指标
  120. data.RefreshDataFromCalculateAll()
  121. // 预测计算指标
  122. data.RefreshPredictDataFromCalculateAll()
  123. time.Sleep(5 * time.Second)
  124. data.RefreshNotice()
  125. fmt.Println("Refresh End")
  126. return
  127. }
  128. // SyncBaseData 刷新基础数据
  129. func SyncBaseData(cont context.Context) (err error) {
  130. now := time.Now()
  131. if now.Hour() == 0 || now.Hour() == 19 {
  132. return nil
  133. }
  134. //同步钢联基础数据
  135. go data.SyncGlDataBase()
  136. return
  137. }
  138. // SyncBaseDataExt 刷新基础数据
  139. func SyncBaseDataExt(cont context.Context) (err error) {
  140. now := time.Now()
  141. if now.Hour() == 0 || now.Hour() == 19 {
  142. return nil
  143. }
  144. //同步手工数据
  145. go data.SyncManualDataBase()
  146. //刷新图表中,指标的最新日期
  147. go data.SetChartEdbEndDate()
  148. return
  149. }
  150. // RefreshFutureGoodData 刷新商品数据
  151. func RefreshFutureGoodData(cont context.Context) (err error) {
  152. future_good.RefreshFutureGoodDataFromThs()
  153. fmt.Println("Refresh End")
  154. return
  155. }
  156. // RefreshTradeData 刷新交易所数据
  157. func RefreshTradeData(cont context.Context) (err error) {
  158. wg := sync.WaitGroup{}
  159. wg.Add(5)
  160. //郑商所
  161. go data.RefreshDataFromZz(&wg)
  162. //上期所
  163. go data.RefreshDataFromSh(&wg)
  164. //上期能源
  165. go data.RefreshDataFromShfe(&wg)
  166. //中金所
  167. go data.RefreshDataFromCffex(&wg)
  168. //大商所
  169. go data.RefreshDataFromDl(&wg)
  170. wg.Wait()
  171. //计算指标
  172. data.RefreshDataFromCalculateAll()
  173. // 计算预测指标
  174. data.RefreshPredictDataFromCalculateAll()
  175. return
  176. }
  177. // RefreshEicData 刷新欧洲天然气数据
  178. func RefreshEicData(cont context.Context) (err error) {
  179. wg := sync.WaitGroup{}
  180. wg.Add(1)
  181. //欧洲天然气
  182. go data.RefreshDataFromEic(&wg)
  183. wg.Wait()
  184. //计算指标
  185. data.RefreshDataFromCalculateAll()
  186. // 计算预测指标
  187. data.RefreshPredictDataFromCalculateAll()
  188. return
  189. }
  190. // 检测数据服务
  191. func checkDataServer(cont context.Context) (err error) {
  192. //检测wind新服务器
  193. go data.CheckWindDataInterface(cont)
  194. //检测同花顺数据服务器
  195. //go data.CheckThsDataInterface(cont)
  196. //检测路透数据服务器
  197. go data.CheckLtDataInterface(cont)
  198. //检测彭博
  199. go data.CheckPbDataInterface(cont)
  200. return
  201. }