task.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. package services
  2. import (
  3. "context"
  4. "fmt"
  5. "hongze/hongze_task/services/company_contract"
  6. "hongze/hongze_task/services/data"
  7. "hongze/hongze_task/utils"
  8. "sync"
  9. "time"
  10. "github.com/beego/beego/v2/task"
  11. )
  12. func Task() {
  13. fmt.Println("task start")
  14. //如果是生产环境,才需要走这些任务
  15. if utils.RunMode == "release" {
  16. releaseTask()
  17. }
  18. //每日定时合同处理
  19. handleCompanyContract := task.NewTask("handleCompanyContract", "0 1 0 * * *", company_contract.HandleCompanyContract)
  20. task.AddTask("每日定时合同处理", handleCompanyContract)
  21. //正式->试用
  22. companyTryOut := task.NewTask("companyTryOut", "0 5 0 * * *", CompanyTryOut)
  23. task.AddTask("正式->试用", companyTryOut)
  24. //试用->冻结
  25. companyFreeze := task.NewTask("companyFreeze", "0 10 0 * * *", CompanyFreeze)
  26. task.AddTask("试用->冻结", companyFreeze)
  27. //冻结->流失
  28. companyLoss := task.NewTask("companyLoss", "0 20 0 * * *", CompanyLoss)
  29. task.AddTask("冻结->流失", companyLoss)
  30. //用户产品权限试用-->关闭
  31. companyReportPermissionClose := task.NewTask("companyReportPermissionClose", "0 30 0 * * *", CompanyReportPermissionClose)
  32. task.AddTask("用户产品权限试用-->关闭", companyReportPermissionClose)
  33. //删除日志记录
  34. //deleteReportSaveLog := task.NewTask("deleteReportSaveLog", "0 30 08 * * *", DeleteReportSaveLog)
  35. //task.AddTask("deleteReportSaveLog", deleteReportSaveLog)
  36. // 存量客户数据统计
  37. stackCompanyStatistic := task.NewTask("stackCompanyStatistic", "0 35 0 * * *", StackCompanyStatistic)
  38. task.AddTask("存量客户数据统计", stackCompanyStatistic)
  39. // 定时往同花顺推送报告
  40. sendWaitReport := task.NewTask("sendWaitReport", "0 */1 * * * * ", SendWaitReport)
  41. task.AddTask("定时往同花顺推送报告", sendWaitReport)
  42. task.StartTask()
  43. //GetHistoryLzProductDetail()
  44. //GetLzPrice()
  45. //GetLzProductDetail()
  46. //LzExportExcel()
  47. //GetLzProductList()GetLzProductDetail
  48. fmt.Println("task end")
  49. }
  50. //生产环境需要走的任务
  51. func releaseTask() {
  52. //隆众指标获取
  53. //getLzProductList := task.NewTask("getLzProductList", "0 0 11-19/1 * * * ", GetLzProductList)
  54. //task.AddTask("getLzProductList", getLzProductList)
  55. //隆众指标数据获取
  56. //getLzProductDetail := task.NewTask("getLzProductDetail", "0 5 11-19/1 * * * ", GetLzProductDetail)
  57. //task.AddTask("getLzProductDetail", getLzProductDetail)
  58. //隆众价格指标获取
  59. //getLzProductPriceProduct := task.NewTask("getLzProductPriceProduct", "0 5 11-19/1 * * * ", GetLzProductPriceProduct)
  60. //task.AddTask("getLzProductPriceProduct", getLzProductPriceProduct)
  61. //隆众价格指标数据获取
  62. //getLzProductPriceData := task.NewTask("getLzProductPriceData", "0 10 11-19/1 * * * ", GetLzProductPriceData)
  63. //task.AddTask("getLzProductPriceData", getLzProductPriceData)
  64. //隆众调研指标获取
  65. getLzSurveyProduct := task.NewTask("getLzSurveyProduct", "0 5 08-19/1 * * * ", GetLzSurveyProduct)
  66. task.AddTask("getLzSurveyProduct", getLzSurveyProduct)
  67. //隆众调研指标数据获取
  68. getLzSurveyProductData := task.NewTask("getLzSurveyProductData", "0 10 08-19/1 * * * ", GetLzSurveyProductData)
  69. task.AddTask("getLzSurveyProductData", getLzSurveyProductData)
  70. //发送邮件
  71. sendEmail := task.NewTask("sendEmail", "0 0 12 * * 0 ", SendEmail)
  72. task.AddTask("sendEmail", sendEmail)
  73. oneMinute := task.NewTask("oneMinute", "0 */1 7-23 * * * ", OneMinute)
  74. task.AddTask("oneMinute", oneMinute)
  75. // 正式/试用 用户到期提醒
  76. companyRemind := task.NewTask("companyRemind", "0 30 08 * * *", CompanyRemind)
  77. task.AddTask("companyRemind", companyRemind)
  78. //潜在客户
  79. freeViewerDetail := task.NewTask("freeViewerDetail", "0 0 9 * * 1 ", FreeViewerDetail)
  80. task.AddTask("潜在客户", freeViewerDetail)
  81. //刷新指标数据
  82. refreshData := task.NewTask("refreshData", "0 1 0,19 * * *", RefreshData)
  83. task.AddTask("refreshData", refreshData)
  84. //刷新指标基础数据
  85. //refreshBaseData := task.NewTask("refreshBaseData", "0 1 18,23 * * *", RefreshBaseData)
  86. //task.AddTask("refreshBaseData", refreshBaseData)
  87. //同步弘则数据库中来自,钢联,隆众,有色,人工等基础数据--每隔五分钟,同步一次最新数据
  88. syncBaseData := task.NewTask("syncBaseData", "0 */5 * * * * ", SyncBaseData)
  89. task.AddTask("syncBaseData", syncBaseData)
  90. // 定时往同花顺同步微信群的截止日期(凌晨4点)
  91. syncThsWxGroupEveryDay := task.NewTask("syncThsWxGroupEveryDay", "0 1 4 * * * ", SyncWxGroupEveryDay)
  92. task.AddTask("定时往同花顺同步微信群的截止日期", syncThsWxGroupEveryDay)
  93. //刷新计算指标数据
  94. //refreshCalculateData := task.NewTask("refreshCalculateData", "0 15 0,19 * * *", RefreshCalculateData)
  95. //task.AddTask("refreshCalculateData", refreshCalculateData)
  96. checkDataInterface := task.NewTask("checkDataInterface", "0 */2 * * * * ", data.CheckDataInterface)
  97. task.AddTask("checkDataInterface", checkDataInterface)
  98. checkPbDataInterface := task.NewTask("checkPbDataInterface", "0 */5 * * * * ", data.CheckPbDataInterface)
  99. task.AddTask("checkPbDataInterface", checkPbDataInterface)
  100. }
  101. func TaskTest() {
  102. fmt.Println("The task is start")
  103. //companyReportPermissionClose := task.NewTask("companyTryOut", "0 5 0 * * *", CompanyReportPermissionClose)
  104. companyReportPermissionClose := task.NewTask("companyReportPermissionClose", "0/30 * * * * *", CompanyReportPermissionClose)
  105. task.AddTask("用户产品权限试用-->关闭", companyReportPermissionClose)
  106. task.StartTask()
  107. fmt.Println("The task is end")
  108. }
  109. func SendEmail(cont context.Context) (err error) {
  110. //报告历史访问次数
  111. go ReportViewTimes()
  112. //报告访问详情
  113. go ReportViewDetail()
  114. //用户权限统计
  115. go HongzeUsers()
  116. return
  117. }
  118. func OneMinute(cont context.Context) (err error) {
  119. //日度
  120. //FrequencyByDay()
  121. //周度
  122. FrequencyByWeek()
  123. //月度
  124. FrequencyByMonth()
  125. return
  126. }
  127. func RefreshData(cont context.Context) (err error) {
  128. wg := sync.WaitGroup{}
  129. wg.Add(7)
  130. //wind
  131. go data.RefreshDataFromWind(&wg)
  132. //同花顺
  133. go data.RefreshDataFromThs(&wg)
  134. //彭博
  135. go data.RefreshDataFromPb(&wg)
  136. //手工数据
  137. go data.RefreshDataFromManual(&wg)
  138. //隆众数据
  139. go data.RefreshDataFromLz(&wg)
  140. //有色
  141. go data.RefreshDataFromYs(&wg)
  142. //钢联
  143. go data.RefreshDataFromGl(&wg)
  144. wg.Wait()
  145. data.RefreshDataFromCalculateAll()
  146. time.Sleep(2 * time.Second)
  147. data.RefreshNotice()
  148. return
  149. }
  150. //刷新基础数据
  151. func RefreshBaseData(cont context.Context) (err error) {
  152. //同步有色基础指标数据
  153. go data.SyncSmmIndexDataBase()
  154. return
  155. }
  156. //刷新基础数据
  157. func SyncBaseData(cont context.Context) (err error) {
  158. //同步钢联基础数据
  159. go data.SyncGlDataBase()
  160. //同步隆众基础数据
  161. go data.SyncLzDataBase()
  162. //同步手工数据
  163. go data.SyncManualDataBase()
  164. //同步有色基础数据
  165. return
  166. }
  167. //func RefreshCalculateData(cont context.Context) (err error) {
  168. // //计算指标
  169. // go data.RefreshDataFromCalculateAll()
  170. // //刷新公历转农历数据
  171. // //go data.RefreshDataFromQuarterAll()
  172. // return
  173. //}
  174. //func Task() {
  175. // fmt.Println("start")
  176. // data.RefreshDataFromCalculateAll()
  177. // //startDate := time.Now().AddDate(-30, 0, 0).UnixNano() / 1e6
  178. //
  179. // //fmt.Println(startDate)
  180. // //fmt.Println(endDate)
  181. // fmt.Println("end")
  182. //}
  183. /*
  184. endData:=time.Now().UnixNano()/1e6
  185. dateTime:=time.Unix(endData/1000,0)
  186. fmt.Println(dateTime)
  187. */