task.go 11 KB

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