task.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package services
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/beego/beego/v2/task"
  6. "hongze/hongze_task/services/company_contract"
  7. "hongze/hongze_task/services/data"
  8. "hongze/hongze_task/utils"
  9. )
  10. func Task() {
  11. fmt.Println("task start")
  12. //如果是生产环境,才需要走这些任务
  13. if utils.RunMode == "release" {
  14. releaseTask()
  15. }
  16. //每日定时合同处理
  17. handleCompanyContract := task.NewTask("handleCompanyContract", "0 1 0 * * *", company_contract.HandleCompanyContract)
  18. task.AddTask("每日定时合同处理", handleCompanyContract)
  19. //正式->试用
  20. companyTryOut := task.NewTask("companyTryOut", "0 5 0 * * *", CompanyTryOut)
  21. task.AddTask("正式->试用", companyTryOut)
  22. //试用->冻结
  23. companyFreeze := task.NewTask("companyFreeze", "0 10 0 * * *", CompanyFreeze)
  24. task.AddTask("试用->冻结", companyFreeze)
  25. //冻结->流失
  26. companyLoss := task.NewTask("companyLoss", "0 20 0 * * *", CompanyLoss)
  27. task.AddTask("冻结->流失", companyLoss)
  28. //用户产品权限试用-->关闭
  29. companyReportPermissionClose := task.NewTask("companyReportPermissionClose", "0 30 0 * * *", CompanyReportPermissionClose)
  30. task.AddTask("用户产品权限试用-->关闭", companyReportPermissionClose)
  31. //删除日志记录
  32. //deleteReportSaveLog := task.NewTask("deleteReportSaveLog", "0 30 08 * * *", DeleteReportSaveLog)
  33. //task.AddTask("deleteReportSaveLog", deleteReportSaveLog)
  34. // 存量客户数据统计
  35. stackCompanyStatistic := task.NewTask("stackCompanyStatistic", "0 35 0 * * *", StackCompanyStatistic)
  36. task.AddTask("存量客户数据统计", stackCompanyStatistic)
  37. task.StartTask()
  38. //GetHistoryLzProductDetail()
  39. //GetLzPrice()
  40. //GetLzProductDetail()
  41. //LzExportExcel()
  42. //GetLzProductList()GetLzProductDetail
  43. fmt.Println("task end")
  44. }
  45. //生产环境需要走的任务
  46. func releaseTask() {
  47. //隆众指标获取
  48. //getLzProductList := task.NewTask("getLzProductList", "0 0 11-19/1 * * * ", GetLzProductList)
  49. //task.AddTask("getLzProductList", getLzProductList)
  50. //隆众指标数据获取
  51. //getLzProductDetail := task.NewTask("getLzProductDetail", "0 5 11-19/1 * * * ", GetLzProductDetail)
  52. //task.AddTask("getLzProductDetail", getLzProductDetail)
  53. //隆众价格指标获取
  54. //getLzProductPriceProduct := task.NewTask("getLzProductPriceProduct", "0 5 11-19/1 * * * ", GetLzProductPriceProduct)
  55. //task.AddTask("getLzProductPriceProduct", getLzProductPriceProduct)
  56. //隆众价格指标数据获取
  57. //getLzProductPriceData := task.NewTask("getLzProductPriceData", "0 10 11-19/1 * * * ", GetLzProductPriceData)
  58. //task.AddTask("getLzProductPriceData", getLzProductPriceData)
  59. //隆众调研指标获取
  60. getLzSurveyProduct := task.NewTask("getLzSurveyProduct", "0 5 11-19/1 * * * ", GetLzSurveyProduct)
  61. task.AddTask("getLzSurveyProduct", getLzSurveyProduct)
  62. //隆众调研指标数据获取
  63. getLzSurveyProductData := task.NewTask("getLzSurveyProductData", "0 10 11-19/1 * * * ", GetLzSurveyProductData)
  64. task.AddTask("getLzSurveyProductData", getLzSurveyProductData)
  65. //发送邮件
  66. sendEmail := task.NewTask("sendEmail", "0 0 12 * * 0 ", SendEmail)
  67. task.AddTask("sendEmail", sendEmail)
  68. oneMinute := task.NewTask("oneMinute", "0 */1 7-23 * * * ", OneMinute)
  69. task.AddTask("oneMinute", oneMinute)
  70. // 正式/试用 用户到期提醒
  71. companyRemind := task.NewTask("companyRemind", "0 30 08 * * *", CompanyRemind)
  72. task.AddTask("companyRemind", companyRemind)
  73. //潜在客户
  74. freeViewerDetail := task.NewTask("freeViewerDetail", "0 0 9 * * 1 ", FreeViewerDetail)
  75. task.AddTask("潜在客户", freeViewerDetail)
  76. //刷新指标数据
  77. refreshData := task.NewTask("refreshData", "0 1 0,19 * * *", RefreshData)
  78. task.AddTask("refreshData", refreshData)
  79. //刷新计算指标数据
  80. refreshCalculateData := task.NewTask("refreshCalculateData", "0 15 0,19 * * *", RefreshCalculateData)
  81. task.AddTask("refreshCalculateData", refreshCalculateData)
  82. checkDataInterface := task.NewTask("checkDataInterface", "0 */2 * * * * ", data.CheckDataInterface)
  83. task.AddTask("checkDataInterface", checkDataInterface)
  84. checkPbDataInterface := task.NewTask("checkPbDataInterface", "0 */5 * * * * ", data.CheckPbDataInterface)
  85. task.AddTask("checkPbDataInterface", checkPbDataInterface)
  86. }
  87. func TaskTest() {
  88. fmt.Println("The task is start")
  89. //companyReportPermissionClose := task.NewTask("companyTryOut", "0 5 0 * * *", CompanyReportPermissionClose)
  90. companyReportPermissionClose := task.NewTask("companyReportPermissionClose", "0/30 * * * * *", CompanyReportPermissionClose)
  91. task.AddTask("用户产品权限试用-->关闭", companyReportPermissionClose)
  92. task.StartTask()
  93. fmt.Println("The task is end")
  94. }
  95. func SendEmail(cont context.Context) (err error) {
  96. //报告历史访问次数
  97. go ReportViewTimes()
  98. //报告访问详情
  99. go ReportViewDetail()
  100. //用户权限统计
  101. go HongzeUsers()
  102. return
  103. }
  104. func OneMinute(cont context.Context) (err error) {
  105. //日度
  106. //FrequencyByDay()
  107. //周度
  108. FrequencyByWeek()
  109. //月度
  110. FrequencyByMonth()
  111. return
  112. }
  113. func RefreshData(cont context.Context) (err error) {
  114. //wind
  115. go data.RefreshDataFromWind()
  116. //同花顺
  117. go data.RefreshDataFromThs()
  118. //彭博
  119. go data.RefreshDataFromPb()
  120. return
  121. }
  122. func RefreshCalculateData(cont context.Context) (err error) {
  123. //计算指标
  124. go data.RefreshDataFromCalculateAll()
  125. //刷新公历转农历数据
  126. //go data.RefreshDataFromQuarterAll()
  127. return
  128. }
  129. //func Task() {
  130. // fmt.Println("start")
  131. // cont := new(context.Context)
  132. // GetLzSurveyProductData(*cont)
  133. // //startDate := time.Now().AddDate(-30, 0, 0).UnixNano() / 1e6
  134. //
  135. // //fmt.Println(startDate)
  136. // //fmt.Println(endDate)
  137. // fmt.Println("end")
  138. //}
  139. /*
  140. endData:=time.Now().UnixNano()/1e6
  141. dateTime:=time.Unix(endData/1000,0)
  142. fmt.Println(dateTime)
  143. */