task.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. refreshTradeAnalysisTables := task.NewTask("refreshTradeAnalysisTables", "0 0 20 * * *", data.RefreshTradeAnalysisTables)
  32. task.AddTask("refreshTradeAnalysisTables", refreshTradeAnalysisTables)
  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. refreshTradeAnalysisTables := task.NewTask("refreshTradeAnalysisTables", "0 0 20 * * *", data.RefreshTradeAnalysisTables)
  121. task.AddTask("refreshTradeAnalysisTables", refreshTradeAnalysisTables)
  122. }
  123. func RefreshData(cont context.Context) (err error) {
  124. wg := sync.WaitGroup{}
  125. wg.Add(14)
  126. //hour := time.Now().Hour()
  127. //if hour != 0 {
  128. //}
  129. //彭博
  130. go data.RefreshDataFromPb(&wg)
  131. //彭博财务
  132. go data.RefreshDataFromPbFinance(&wg)
  133. //手工数据
  134. go data.RefreshDataFromManual(&wg)
  135. //隆众数据
  136. //go data.RefreshDataFromLz(&wg)
  137. //有色
  138. go data.RefreshDataFromYs(&wg)
  139. //钢联
  140. go data.RefreshDataFromGl(&wg)
  141. //路透
  142. go data.RefreshDataFromLt(&wg)
  143. //煤炭
  144. go data.RefreshDataFromCoal(&wg)
  145. //谷歌出行数据
  146. go data.RefreshDataFromGoogleTravel(&wg)
  147. //钢联化工
  148. go data.RefreshDataFromMysteelChemical(&wg)
  149. //eia steo报告指标
  150. go data.RefreshDataFromEiaSteo(&wg)
  151. //UN报告指标
  152. go data.RefreshDataFromComTrade(&wg)
  153. //卓创报告指标
  154. go data.RefreshDataFromSci(&wg)
  155. //国家统计局指标
  156. go data.RefreshDataFromNationalStatistics(&wg)
  157. //富宝指标刷新
  158. go data.RefreshDataFromFubao(&wg)
  159. // Bloomberg
  160. go func() {
  161. wg.Add(1)
  162. _ = data.RefreshDataFromBloomberg(&wg)
  163. }()
  164. // CCF化纤信息
  165. go func() {
  166. wg.Add(1)
  167. _ = data.RefreshDataFromCCF(&wg)
  168. }()
  169. // 持仓分析
  170. go func() {
  171. wg.Add(1)
  172. _ = data.RefreshDataFromTradeAnalysis(&wg)
  173. }()
  174. wg.Wait()
  175. ////计算指标
  176. data.RefreshDataFromCalculateAll()
  177. // 刷新所有的基础预测指标
  178. data.RefreshBasePredictDataAll()
  179. // 预测计算指标
  180. data.RefreshPredictDataFromCalculateAll()
  181. // 指标系列计算数据
  182. _ = data.RefreshFactorEdbCalculateData()
  183. // 指标系列图表计算数据
  184. _ = data.RefreshFactorEdbChartCalculateData()
  185. // 刷新商品利润曲线图表数据
  186. _ = data.RefreshFutureGoodProfitChart()
  187. // 刷新计算指标-依赖指标id大于当前计算指标id的计算指标
  188. data.RefreshDataFromCalculateAfter()
  189. time.Sleep(5 * time.Second)
  190. //data.RefreshNotice()
  191. fmt.Println("Refresh End")
  192. return
  193. }
  194. // 刷新所有计算指标数据
  195. func RefreshAllCalculateEdbData(cont context.Context) (err error) {
  196. ////计算指标
  197. err = data.RefreshDataFromCalculateAll()
  198. return
  199. }
  200. // SyncBaseData 刷新基础数据
  201. func SyncBaseData(cont context.Context) (err error) {
  202. now := time.Now()
  203. if now.Hour() == 0 || now.Hour() == 19 {
  204. return nil
  205. }
  206. //同步钢联基础数据
  207. if utils.BusinessCode == utils.BusinessCodeRelease {
  208. go data.SyncGlDataBase()
  209. }
  210. return
  211. }
  212. // SyncBaseDataExt 刷新基础数据
  213. func SyncBaseDataExt(cont context.Context) (err error) {
  214. now := time.Now()
  215. if now.Hour() == 0 || now.Hour() == 19 {
  216. return nil
  217. }
  218. //同步手工数据
  219. go data.SyncManualDataBase()
  220. //刷新图表中,指标的最新日期
  221. go data.SetChartEdbEndDate()
  222. return
  223. }
  224. // RefreshFutureGoodData 刷新商品数据
  225. func RefreshFutureGoodData(cont context.Context) (err error) {
  226. future_good.RefreshFutureGoodDataFromThs()
  227. fmt.Println("Refresh End")
  228. return
  229. }
  230. // RefreshTradeData 刷新交易所数据
  231. func RefreshTradeData(cont context.Context) (err error) {
  232. wg := sync.WaitGroup{}
  233. wg.Add(6)
  234. //郑商所
  235. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_ZZ)
  236. //上期所
  237. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_SH)
  238. //上期能源
  239. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_SHFE)
  240. //中金所
  241. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_CFFEX)
  242. //大商所
  243. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_DL)
  244. //广期所数据
  245. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_GFEX)
  246. wg.Wait()
  247. //计算指标
  248. data.RefreshDataFromCalculateAll()
  249. // 刷新所有的基础预测指标
  250. data.RefreshBasePredictDataAll()
  251. // 计算预测指标
  252. data.RefreshPredictDataFromCalculateAll()
  253. return
  254. }
  255. // RefreshEicData 刷新欧洲天然气数据
  256. func RefreshEicData(cont context.Context) (err error) {
  257. wg := sync.WaitGroup{}
  258. wg.Add(1)
  259. //欧洲天然气
  260. go data.RefreshDataFromEic(&wg)
  261. wg.Wait()
  262. ////计算指标
  263. //data.RefreshDataFromCalculateAll()
  264. //
  265. //// 刷新所有的基础预测指标
  266. //data.RefreshBasePredictDataAll()
  267. //
  268. //// 计算预测指标
  269. //data.RefreshPredictDataFromCalculateAll()
  270. return
  271. }
  272. // 检测数据服务
  273. func checkDataServer(cont context.Context) (err error) {
  274. //检测wind新服务器
  275. go data.CheckWindDataInterface(cont)
  276. //检测同花顺数据服务器
  277. //go data.CheckThsDataInterface(cont)
  278. //检测路透数据服务器
  279. go data.CheckLtDataInterface(cont)
  280. //检测彭博
  281. go data.CheckPbDataInterface(cont)
  282. return
  283. }
  284. func TaskInit() {
  285. fmt.Println("TaskInit start")
  286. //data.InitGuangzhouPositionTask()
  287. fmt.Println("TaskInit end")
  288. return
  289. }