task.go 9.6 KB

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