task.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. package services
  2. import (
  3. "context"
  4. "eta_gn/eta_task/services/data"
  5. "eta_gn/eta_task/services/data/future_good"
  6. "eta_gn/eta_task/services/data_stat"
  7. "eta_gn/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" || utils.IsStartReleaseTask {
  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. GnTask()
  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 * * * * ", ConfigRefreshDataGn)
  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. refreshThsHfBase := task.NewTask("refreshThsHfBase", "0 0 0,6,9,12,15,18,21 * * *", data.RefreshBaseFromThsHfIndex)
  92. task.AddTask("refreshThsHfBase", refreshThsHfBase)
  93. }
  94. func RefreshData(cont context.Context) (err error) {
  95. wg := sync.WaitGroup{}
  96. //手工数据
  97. go func() {
  98. wg.Add(1)
  99. data.RefreshDataFromManual(&wg)
  100. }()
  101. // 持仓分析
  102. //go func() {
  103. // wg.Add(1)
  104. // _ = data.RefreshDataFromTradeAnalysis(&wg)
  105. //}()
  106. // 刷新未配置刷新时间点的来源(可能含未知的来源, 统一在这个时间刷新)
  107. go func() {
  108. wg.Add(1)
  109. data.NoneConfigRefreshDataGn(&wg)
  110. }()
  111. wg.Wait()
  112. ////计算指标
  113. data.RefreshDataFromCalculateAll()
  114. // 刷新所有的基础预测指标
  115. data.RefreshBasePredictDataAll()
  116. // 预测计算指标
  117. data.RefreshPredictDataFromCalculateAll()
  118. // 指标系列计算数据
  119. _ = data.RefreshFactorEdbCalculateData()
  120. // 指标系列图表计算数据
  121. _ = data.RefreshFactorEdbChartCalculateData()
  122. time.Sleep(5 * time.Second)
  123. //data.RefreshNotice()
  124. fmt.Println("Refresh End")
  125. return
  126. }
  127. // SyncBaseData 刷新基础数据
  128. func SyncBaseData(cont context.Context) (err error) {
  129. now := time.Now()
  130. if now.Hour() == 0 || now.Hour() == 19 {
  131. return nil
  132. }
  133. //同步钢联基础数据
  134. if utils.BusinessCode == utils.BusinessCodeRelease {
  135. go data.SyncGlDataBase()
  136. }
  137. return
  138. }
  139. // SyncBaseDataExt 刷新基础数据
  140. func SyncBaseDataExt(cont context.Context) (err error) {
  141. now := time.Now()
  142. if now.Hour() == 0 || now.Hour() == 19 {
  143. return nil
  144. }
  145. //同步手工数据
  146. go data.SyncManualDataBase()
  147. //刷新图表中,指标的最新日期
  148. go data.SetChartEdbEndDate()
  149. return
  150. }
  151. // RefreshFutureGoodData 刷新商品数据
  152. func RefreshFutureGoodData(cont context.Context) (err error) {
  153. future_good.RefreshFutureGoodDataFromThs()
  154. fmt.Println("Refresh End")
  155. return
  156. }
  157. // RefreshTradeData 刷新交易所数据
  158. func RefreshTradeData(cont context.Context) (err error) {
  159. wg := sync.WaitGroup{}
  160. wg.Add(6)
  161. //郑商所
  162. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_ZZ)
  163. //上期所
  164. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_SH)
  165. //上期能源
  166. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_SHFE)
  167. //中金所
  168. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_CFFEX)
  169. //大商所
  170. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_DL)
  171. //广期所数据
  172. go data.RefreshBaseDataFromSource(&wg, utils.DATA_SOURCE_GFEX)
  173. wg.Wait()
  174. //计算指标
  175. data.RefreshDataFromCalculateAll()
  176. // 刷新所有的基础预测指标
  177. data.RefreshBasePredictDataAll()
  178. // 计算预测指标
  179. data.RefreshPredictDataFromCalculateAll()
  180. return
  181. }
  182. // RefreshEicData 刷新欧洲天然气数据
  183. func RefreshEicData(cont context.Context) (err error) {
  184. wg := sync.WaitGroup{}
  185. wg.Add(1)
  186. //欧洲天然气
  187. go data.RefreshDataFromEic(&wg)
  188. wg.Wait()
  189. ////计算指标
  190. //data.RefreshDataFromCalculateAll()
  191. //
  192. //// 刷新所有的基础预测指标
  193. //data.RefreshBasePredictDataAll()
  194. //
  195. //// 计算预测指标
  196. //data.RefreshPredictDataFromCalculateAll()
  197. return
  198. }
  199. // 检测数据服务
  200. func checkDataServer(cont context.Context) (err error) {
  201. //检测wind新服务器
  202. go data.CheckWindDataInterface(cont)
  203. //检测同花顺数据服务器
  204. //go data.CheckThsDataInterface(cont)
  205. //检测路透数据服务器
  206. go data.CheckLtDataInterface(cont)
  207. //检测彭博
  208. go data.CheckPbDataInterface(cont)
  209. return
  210. }
  211. func TaskInit() {
  212. fmt.Println("TaskInit start")
  213. //data.InitGuangzhouPositionTask()
  214. fmt.Println("TaskInit end")
  215. return
  216. }