task.go 10 KB

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