task.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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/services/data_stat"
  7. "eta/eta_task/utils"
  8. "fmt"
  9. "sync"
  10. "time"
  11. "github.com/beego/beego/v2/task"
  12. )
  13. func Task() {
  14. fmt.Println("task start")
  15. //如果是生产环境,才需要走这些任务
  16. if utils.RunMode == "release" {
  17. releaseTask()
  18. }
  19. // 定时发布智能研报
  20. publishSmartReport := task.NewTask("publishSmartReport", "0 */1 * * * *", PublishSmartReport)
  21. task.AddTask("定时发布智能研报", publishSmartReport)
  22. // 定时发布研报
  23. publishReport := task.NewTask("publishReport", "0 */1 * * * *", PublishReport)
  24. task.AddTask("定时发布研报", publishReport)
  25. // 定时汇总数据源终端指标更新情况
  26. setEdbSourceStatTask := task.NewTask("setEdbSourceStatTask", "0 20 19,23 * * *", data_stat.SetEdbSourceStatTask)
  27. task.AddTask("数据源统计表", setEdbSourceStatTask)
  28. XyTask()
  29. // TODO:测试-刷新同花顺高频, 上线前删除
  30. if utils.RunMode == "debug" {
  31. refreshThsHfBase := task.NewTask("refreshThsHfBase", "0 30 12 * * *", data.RefreshBaseFromThsHfIndex)
  32. task.AddTask("refreshThsHfBase", refreshThsHfBase)
  33. }
  34. task.StartTask()
  35. fmt.Println("task end")
  36. }
  37. // 生产环境需要走的任务
  38. func releaseTask() {
  39. //同步指标
  40. if utils.BusinessCode != utils.BusinessCodeRelease {
  41. syncHzDataIndex := task.NewTask("syncHzDataIndex", "0 10,20,40,50 16,18 * * *", SyncHzDataIndex)
  42. task.AddTask("syncHzDataIndex", syncHzDataIndex)
  43. syncRankingFromDalian := task.NewTask("syncRankingFromDalian", "0 30,40,50 16,18 * * *", SyncRankingFromDalian)
  44. task.AddTask("syncRankingFromDalian", syncRankingFromDalian)
  45. }
  46. // 定时统计交易所的持仓分析数据
  47. initPositionTask := task.NewTask("initPositionTask", "0 20,40 16-19 * * *", data.InitPositionTask)
  48. task.AddTask("initPositionTask", initPositionTask)
  49. //刷新指标数据
  50. refreshData := task.NewTask("refreshData", "0 30 0,19 * * *", RefreshData)
  51. task.AddTask("refreshData", refreshData)
  52. // 根据配置刷新指标数据
  53. configRefreshData := task.NewTask("syncBaseDataExt", "0 */30 * * * * ", ConfigRefreshData)
  54. task.AddTask("configRefreshData", configRefreshData)
  55. // 定时禁用钢联化工和wind指标的刷新状态
  56. disableEdbRefresh := task.NewTask("disableEdbRefresh", "0 0 10 * * *", DisableEdbRefresh)
  57. task.AddTask("disableEdbRefresh", disableEdbRefresh)
  58. //同步弘则数据库中来自,钢联,隆众,有色,人工等基础数据--每隔五分钟,同步一次最新数据
  59. syncBaseData := task.NewTask("syncBaseData", "0 */5 * * * * ", SyncBaseData)
  60. task.AddTask("syncBaseData", syncBaseData)
  61. syncBaseDataExt := task.NewTask("syncBaseDataExt", "0 */30 * * * * ", SyncBaseDataExt)
  62. task.AddTask("syncBaseDataExt", syncBaseDataExt)
  63. //初始化指标更新状态
  64. resetEdbInfoIsUpdate := task.NewTask("resetEdbInfoIsUpdate", "0 0 0 * * *", data.ResetEdbInfoIsUpdate)
  65. task.AddTask("resetEdbInfoIsUpdate", resetEdbInfoIsUpdate)
  66. // 刷新商品数据
  67. refreshFutureGoodData := task.NewTask("refreshFutureGoodData", "0 30 0,19 * * *", RefreshFutureGoodData)
  68. task.AddTask("refreshFutureGoodData", refreshFutureGoodData)
  69. //刷新交易所指标数据
  70. refreshTradeData := task.NewTask("refreshData", "0 1 4 * * *", RefreshTradeData)
  71. task.AddTask("refreshTradeData", refreshTradeData)
  72. //刷新欧洲天然气指标数据
  73. refreshEicData := task.NewTask("refreshData", "0 1 3,7 * * *", RefreshEicData)
  74. task.AddTask("refreshEicData", refreshEicData)
  75. //检测数据服务器
  76. checkDataServer := task.NewTask("checkDataServer", "0 */2 * * * * ", checkDataServer)
  77. task.AddTask("checkDataServer", checkDataServer)
  78. //删除日志 report_save_log,ppt_v2_save_log,保留一个月的
  79. deleteLog := task.NewTask("syncSubStatus", "0 0 2 2 * *", DeleteLog)
  80. task.AddTask("deleteLog", deleteLog)
  81. // 定时发布英文研报
  82. publishEnglishReport := task.NewTask("publishEnglishReport", "0 */1 * * * *", PublishEnglishReport)
  83. task.AddTask("定时发布英文研报", publishEnglishReport)
  84. // 每天清理两周前的报告保存日志
  85. clearReportSaveLog := task.NewTask("clearReportSaveLog", "0 15 23 * * *", ClearReportSaveLog)
  86. task.AddTask("定时清理报告保存日志", clearReportSaveLog)
  87. // 每天清理三个月前的用户操作日志
  88. clearAdminOperateLog := task.NewTask("clearAdminOperateLog", "0 20 23 * * *", ClearAdminOperateLog)
  89. task.AddTask("定时清理用户操作日志", clearAdminOperateLog)
  90. // 嘉悦物产
  91. if utils.BusinessCode == utils.BusinessCodeJiaYue {
  92. // 每10分钟定时同步增量指标
  93. syncJiaYueNewIndex := task.NewTask("syncJiaYueNewIndex", "0 */10 * * * *", data.SyncJiaYueNewIndex)
  94. task.AddTask("定时同步嘉悦物产增量指标", syncJiaYueNewIndex)
  95. // 每30分钟同步一次数据宝指标数据
  96. syncJiaYueDataBaby := task.NewTask("syncJiaYueDataBaby", "0 */30 * * * * ", data.RefreshJiaYueDataFromBridge)
  97. task.AddTask("syncJiaYueDataBaby", syncJiaYueDataBaby)
  98. }
  99. if utils.BusinessCode == utils.BusinessCodeZhongJi {
  100. // 每天同步一次指标列表
  101. syncZhongJiIndexList := task.NewTask("syncZhongJiIndexList", "0 0 17 * * *", data.SyncZhongJiIndexList)
  102. task.AddTask("定时同步中基宁波SMM指标列表", syncZhongJiIndexList)
  103. }
  104. // 中石油新加坡
  105. if utils.IsPCSG == "1" {
  106. refreshPCSGBloomberg := task.NewTask("refreshPCSGBloombergDaily", "0 */30 * * * *", data.RefreshPCSGBloomberg)
  107. task.AddTask("中石油新加坡-每日Bloomberg指标刷新", refreshPCSGBloomberg)
  108. }
  109. // 刷新同花顺高频
  110. refreshThsHfBase := task.NewTask("refreshThsHfBase", "0 0 0,6,9,12,15,18,21 * * *", data.RefreshBaseFromThsHfIndex)
  111. task.AddTask("refreshThsHfBase", refreshThsHfBase)
  112. }
  113. func RefreshData(cont context.Context) (err error) {
  114. wg := sync.WaitGroup{}
  115. wg.Add(14)
  116. //hour := time.Now().Hour()
  117. //if hour != 0 {
  118. //}
  119. //彭博
  120. go data.RefreshDataFromPb(&wg)
  121. //彭博财务
  122. go data.RefreshDataFromPbFinance(&wg)
  123. //手工数据
  124. go data.RefreshDataFromManual(&wg)
  125. //隆众数据
  126. //go data.RefreshDataFromLz(&wg)
  127. //有色
  128. go data.RefreshDataFromYs(&wg)
  129. //钢联
  130. go data.RefreshDataFromGl(&wg)
  131. //路透
  132. go data.RefreshDataFromLt(&wg)
  133. //煤炭
  134. go data.RefreshDataFromCoal(&wg)
  135. //谷歌出行数据
  136. go data.RefreshDataFromGoogleTravel(&wg)
  137. //钢联化工
  138. go data.RefreshDataFromMysteelChemical(&wg)
  139. //eia steo报告指标
  140. go data.RefreshDataFromEiaSteo(&wg)
  141. //UN报告指标
  142. go data.RefreshDataFromComTrade(&wg)
  143. //卓创报告指标
  144. go data.RefreshDataFromSci(&wg)
  145. //国家统计局指标
  146. go data.RefreshDataFromNationalStatistics(&wg)
  147. //富宝指标刷新
  148. go data.RefreshDataFromFubao(&wg)
  149. // Bloomberg
  150. go func() {
  151. wg.Add(1)
  152. _ = data.RefreshDataFromBloomberg(&wg)
  153. }()
  154. // CCF化纤信息
  155. go func() {
  156. wg.Add(1)
  157. _ = data.RefreshDataFromCCF(&wg)
  158. }()
  159. wg.Wait()
  160. ////计算指标
  161. data.RefreshDataFromCalculateAll()
  162. // 刷新所有的基础预测指标
  163. data.RefreshBasePredictDataAll()
  164. // 预测计算指标
  165. data.RefreshPredictDataFromCalculateAll()
  166. // 指标系列计算数据
  167. _ = data.RefreshFactorEdbCalculateData()
  168. // 指标系列图表计算数据
  169. _ = data.RefreshFactorEdbChartCalculateData()
  170. time.Sleep(5 * time.Second)
  171. //data.RefreshNotice()
  172. fmt.Println("Refresh End")
  173. return
  174. }
  175. // SyncBaseData 刷新基础数据
  176. func SyncBaseData(cont context.Context) (err error) {
  177. now := time.Now()
  178. if now.Hour() == 0 || now.Hour() == 19 {
  179. return nil
  180. }
  181. //同步钢联基础数据
  182. if utils.BusinessCode == utils.BusinessCodeRelease {
  183. go data.SyncGlDataBase()
  184. }
  185. return
  186. }
  187. // SyncBaseDataExt 刷新基础数据
  188. func SyncBaseDataExt(cont context.Context) (err error) {
  189. now := time.Now()
  190. if now.Hour() == 0 || now.Hour() == 19 {
  191. return nil
  192. }
  193. //同步手工数据
  194. go data.SyncManualDataBase()
  195. //刷新图表中,指标的最新日期
  196. go data.SetChartEdbEndDate()
  197. return
  198. }
  199. // RefreshFutureGoodData 刷新商品数据
  200. func RefreshFutureGoodData(cont context.Context) (err error) {
  201. future_good.RefreshFutureGoodDataFromThs()
  202. fmt.Println("Refresh End")
  203. return
  204. }
  205. // RefreshTradeData 刷新交易所数据
  206. func RefreshTradeData(cont context.Context) (err error) {
  207. wg := sync.WaitGroup{}
  208. wg.Add(6)
  209. //郑商所
  210. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_ZZ)
  211. //上期所
  212. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_SH)
  213. //上期能源
  214. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_SHFE)
  215. //中金所
  216. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_CFFEX)
  217. //大商所
  218. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_DL)
  219. //广期所数据
  220. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_GFEX)
  221. wg.Wait()
  222. //计算指标
  223. data.RefreshDataFromCalculateAll()
  224. // 刷新所有的基础预测指标
  225. data.RefreshBasePredictDataAll()
  226. // 计算预测指标
  227. data.RefreshPredictDataFromCalculateAll()
  228. return
  229. }
  230. // RefreshEicData 刷新欧洲天然气数据
  231. func RefreshEicData(cont context.Context) (err error) {
  232. wg := sync.WaitGroup{}
  233. wg.Add(1)
  234. //欧洲天然气
  235. go data.RefreshDataFromEic(&wg)
  236. wg.Wait()
  237. //计算指标
  238. data.RefreshDataFromCalculateAll()
  239. // 刷新所有的基础预测指标
  240. data.RefreshBasePredictDataAll()
  241. // 计算预测指标
  242. data.RefreshPredictDataFromCalculateAll()
  243. return
  244. }
  245. // 检测数据服务
  246. func checkDataServer(cont context.Context) (err error) {
  247. //检测wind新服务器
  248. go data.CheckWindDataInterface(cont)
  249. //检测同花顺数据服务器
  250. //go data.CheckThsDataInterface(cont)
  251. //检测路透数据服务器
  252. go data.CheckLtDataInterface(cont)
  253. //检测彭博
  254. go data.CheckPbDataInterface(cont)
  255. return
  256. }
  257. func TaskInit() {
  258. fmt.Println("TaskInit start")
  259. //data.InitGuangzhouPositionTask()
  260. fmt.Println("TaskInit end")
  261. return
  262. }