task.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. package services
  2. import (
  3. "fmt"
  4. "github.com/PuerkitoBio/goquery"
  5. "github.com/beego/beego/v2/task"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/utils"
  8. "html"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. func Task() {
  14. fmt.Println("start")
  15. if utils.RunMode == "release" && utils.IsTask {
  16. //syncTacticsListAddreport := task.NewTask("syncTacticsListAddreport", "0 */5 * * * *", SyncTacticsListAddreport) //同步文章
  17. //task.AddTask("syncTacticsListAddreport", syncTacticsListAddreport)
  18. //getSummarytoEs := task.NewTask("getSummarytoEs", "0 */30 * * * *", GetSummarytoEs) //同步纪要库内容到Es
  19. //task.AddTask("getSummarytoEs", getSummarytoEs)
  20. getArticleListByApi := task.NewTask("getArticleListByApi", "0 */5 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章
  21. task.AddTask("getArticleListByApi", getArticleListByApi)
  22. //会议提醒模板消息推送
  23. sendActivityBeginMsg := task.NewTask("sendActivityBeginMsg", "0 */10 6-23 * * *", SendActivityBeginMsg) //会议前60分钟的提醒
  24. task.AddTask("sendActivityBeginMsg", sendActivityBeginMsg)
  25. sendActivityBeginMsgMeeting := task.NewTask("sendActivityBeginMsgMeeting", "0 */5 6-23 * * *", SendActivityBeginMsgMeeting) //会议前15分钟的提醒
  26. task.AddTask("sendActivityBeginMsgMeeting", sendActivityBeginMsgMeeting)
  27. //预约外呼名单,会前1小时自动发送邮件给专家组
  28. sendEmailFileToExpert := task.NewTask("sendEmailFileToExpert", "0 */5 6-23 * * *", SendEmailFileToExpert) //预约外呼名单,会前1小时自动发送邮件给专家组
  29. task.AddTask("sendEmailFileToExpert", sendEmailFileToExpert)
  30. sendEmailUserWhiteListChange := task.NewTask("sendEmailUserWhiteListChange", "0 00 17 * * *", SendEmailUserWhiteListChange) //新增 和冻结的客户白名单
  31. task.AddTask("白名单发送", sendEmailUserWhiteListChange)
  32. dotongbuShangHaiSendEmail := task.NewTask("dotongbuShangHaiSendEmail", "0 00 4 * * *", DotongbuShangHaiSendEmail) //发送上海策略品台同步结果名单的邮件附件
  33. task.AddTask("发送上海策略品台同步结果名单的邮件附件", dotongbuShangHaiSendEmail)
  34. getChartListByApi := task.NewTask("getChartListByApi", "0 */10 * * * *", GetChartDetailByChartId) //同步图表
  35. task.AddTask("getChartListByApi", getChartListByApi)
  36. }
  37. if utils.IsTask {
  38. getYiDongActivity := task.NewTask("getYiDongActivity", "0 */10 * * * *", GetYiDongActivity) //同步易董的活动信息
  39. task.AddTask("getYiDongActivity", getYiDongActivity)
  40. getYiDongActivityMeeting := task.NewTask("getYiDongActivityMeeting", "0 */30 * * * *", GetYiDongActivityMeeting) //同步易董的活动信息
  41. task.AddTask("getYiDongActivityMeeting", getYiDongActivityMeeting)
  42. yiDongSignAppointmentsForThird := task.NewTask("yiDongSignAppointmentsForThird", "0 */10 * * * *", YiDongSignAppointmentsForThird) //会前一小时将,报名信息同步到易董
  43. task.AddTask("yiDongSignAppointmentsForThird", yiDongSignAppointmentsForThird)
  44. //修改任务状
  45. updateActivitySattus := task.NewTask("syncTacticsListAddreport", "0 */1 6-23 * * *", UpdateActivitySattus)
  46. task.AddTask("updateActivitySattus", updateActivitySattus)
  47. //更新深 和新的标签
  48. updateIndustrialManagementLabel := task.NewTask("updateIndustrialManagementLabel", "0 */30 * * * *", UpdateIndustrialManagementLabel)
  49. task.AddTask("updateIndustrialManagementLabel", updateIndustrialManagementLabel)
  50. //更改对应产业的文章阅读数量
  51. chageIndustrialArticleNum := task.NewTask("chageIndustrialArticleNum", "0 01 00 * * *", ChageIndustrialArticleNum) //更改对应产业的文章阅读数量
  52. task.AddTask("chageIndustrialArticleNum", chageIndustrialArticleNum)
  53. activityAttendanceDetail := task.NewTask("activityAttendanceDetail", "0 00 3 * * *", ActivityAttendanceDetail) //同步进门财经的路演信息
  54. task.AddTask("sendEmailUserWhiteListChange", activityAttendanceDetail)
  55. sendEmailFileForAskMsgResearch := task.NewTask("sendEmailFileForAskMsgResearch", "0 */5 6-23 * * *", SendEmailFileForAskMsgResearch) //研选系列专家电话会,会前1小时将问题列表发送给邮箱
  56. task.AddTask("sendEmailFileForAskMsgResearch", sendEmailFileForAskMsgResearch)
  57. sendEmailFileForAskMsg := task.NewTask("sendEmailFileForAskMsg", "0 */5 6-23 * * *", SendEmailFileForAskMsg) //非研选系列专家电话会,根据主持人姓名,会前15分钟将问题列表发送给至该主持人对应邮箱
  58. task.AddTask("sendEmailFileForAskMsg", sendEmailFileForAskMsg)
  59. updateWxUserLabel := task.NewTask("updateWxUserLabel", "0 01 0 * * *", UpdateWxUserLabel) //更新用户的标签
  60. task.AddTask("updateWxUserLabel", updateWxUserLabel)
  61. addAllArticleHistory := task.NewTask("addAllArticleHistory", "0 30 2 * * *", AddAllArticleHistory) //把前一天的用户阅读记录同步到ES
  62. task.AddTask("addAllArticleHistory", addAllArticleHistory)
  63. getCeLueArticlePv := task.NewTask("getCeLueArticlePv", "0 */10 * * * *", GetCeLueArticlePv) //通过三方接口获取策略平台上的阅读记录
  64. task.AddTask("getCeLueArticlePv", getCeLueArticlePv)
  65. reportBillboardUpdate := task.NewTask("reportBillboardUpdate", "0 10 0 * * *", ReportBillboardUpdate) //报告榜单更新
  66. task.AddTask("reportBillboardUpdate", reportBillboardUpdate)
  67. doActivityOnenIdWxTemplateMsg := task.NewTask("doActivityOnenIdWxTemplateMsg", "0 30 16 * * 0", DoActivityOnenIdWxTemplateMsg) //周日下午四点半推送全部活动
  68. task.AddTask("doActivityOnenIdWxTemplateMsg", doActivityOnenIdWxTemplateMsg)
  69. updateCygxActivitySpecialSignupNum := task.NewTask("updateCygxActivitySpecialSignupNum", "0 25 0 * * *", UpdateCygxActivitySpecialSignupNum) //修改专项调研,用户与公司的参与数量
  70. task.AddTask("updateCygxActivitySpecialSignupNum", updateCygxActivitySpecialSignupNum)
  71. updateDailyMonthReadBillboard := task.NewTask("updateDailyMonthReadBillboard", "0 0 3 * * *", UpdateDailyMonthReadBillboard) // 每日3:00更新阅读飙升榜单
  72. task.AddTask("updateDailyMonthReadBillboard", updateDailyMonthReadBillboard)
  73. dotongbuShangHai := task.NewTask("dotongbuShangHai", "0 */20 * * * *", DotongbuShangHai) //把信息同步到上海策略品台
  74. task.AddTask("同步用户到上海", dotongbuShangHai)
  75. addctivitySignupDetail := task.NewTask("addctivitySignupDetail", "0 0 23 * * *", AddctivitySignupDetail) // 获取当天已结束的活动的报名信息。添加到到会详情
  76. task.AddTask("addctivitySignupDetail", addctivitySignupDetail)
  77. sendWxMsgActivitySpecialTwoDays := task.NewTask("sendWxMsgActivitySpecialTwoDays", "0 0 8 * * *", SendWxMsgActivitySpecialTwoDays)
  78. task.AddTask("sendWxMsgActivitySpecialTwoDays", sendWxMsgActivitySpecialTwoDays) //活动开始前两天08:00,提醒报名客户 \提醒报名客户的对口销售
  79. //sendWxMsgActivitySpecialCancel := task.NewTask("sendWxMsgActivitySpecialCancel", "0 0 8 * * *", SendWxMsgActivitySpecialCancel)
  80. //task.AddTask("sendWxMsgActivitySpecialCancel", sendWxMsgActivitySpecialCancel) // 线下活动前4天08:00报名人数不足7人,线上活动前3天08:00报名人数不足10人,活动自动取消发布,并推送模板消息至报名客户及对口销售
  81. makeMorningMeetingReviews := task.NewTask("makeMorningMeetingReviews", "0 30 10 * * *", MakeMorningMeetingReviews)
  82. task.AddTask("makeMorningMeetingReviews", makeMorningMeetingReviews) //每天10::30定时生成晨会精华汇总
  83. }
  84. if utils.RunMode != "release" {
  85. getArticleListByApi := task.NewTask("getArticleListByApi", "0 */60 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章
  86. task.AddTask("getArticleListByApi", getArticleListByApi)
  87. }
  88. //GetCygxActivityAttendanceDetail()
  89. //CreateIndexNameArticleHistory()
  90. //AddAllArticleHistory()
  91. //DoCompany()
  92. //ActivityAttendanceDetail()
  93. //SynchronizationArthistory()//同步原有的阅读记录
  94. //GetAddpArticle() //同步日度点评数据
  95. //SendEmailAllUserWithRAI() //发送当前所有权益用户到沈大爷的邮箱
  96. //SendEmailAllUserWithCompany() //发送这些公司下的用户到沈大爷的邮箱
  97. task.StartTask()
  98. //StatisticalReport()//导出报表
  99. fmt.Println("end")
  100. }
  101. ////白名单发送
  102. //sendEmailUserWhiteList := task.NewTask("sendEmailUserWhiteList", "0 27 17 * * *", SendEmailUserWhiteList) //白名单发送
  103. //task.AddTask("sendEmailUserWhiteList", sendEmailUserWhiteList)
  104. //editOutboundMobile := task.NewTask("editOutboundMobile", "0 */1 8-22 * * *", EditOutboundMobile) //同步外呼号码与手机号
  105. //task.AddTask("sendEmailFileToExpert", editOutboundMobile)
  106. //editUserOutboundMobile := task.NewTask("editUserOutboundMobile", "0 27 14 * * * ", EditUserOutboundMobile) //同步外呼号码与手机号
  107. //task.AddTask("editUserOutboundMobile", editUserOutboundMobile)
  108. func CreateIndex() {
  109. indexName := utils.IndexName
  110. mappingJson := `{
  111. "mappings": {
  112. "dynamic": true,
  113. "properties": {
  114. "ArticleId": {
  115. "type": "integer"
  116. },
  117. "CategoryId": {
  118. "type": "text"
  119. },
  120. "BodyText": {
  121. "type": "text",
  122. "term_vector": "with_positions_offsets",
  123. "analyzer": "ik_smart"
  124. },
  125. "PublishDate": {
  126. "type": "keyword"
  127. },
  128. "SubCategoryName": {
  129. "type": "text",
  130. "term_vector": "with_positions_offsets",
  131. "analyzer": "ik_smart"
  132. },
  133. "Title": {
  134. "type": "text",
  135. "term_vector": "with_positions_offsets",
  136. "analyzer": "ik_smart"
  137. },
  138. "Abstract": {
  139. "type": "text",
  140. "term_vector": "with_positions_offsets",
  141. "analyzer": "ik_smart"
  142. },
  143. "Annotation": {
  144. "type": "text",
  145. "term_vector": "with_positions_offsets",
  146. "analyzer": "ik_smart"
  147. },
  148. "TitleEn": {
  149. "type": "text",
  150. "term_vector": "with_positions_offsets"
  151. },
  152. "UpdateFrequency": {
  153. "type": "text",
  154. "term_vector": "with_positions_offsets"
  155. },
  156. "ExpertBackground": {
  157. "type": "text",
  158. "term_vector": "with_positions_offsets"
  159. }
  160. }
  161. }
  162. }`
  163. EsCreateIndex(indexName, mappingJson)
  164. AddAllArticle()
  165. }
  166. func AddAllArticle() {
  167. endDate := time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
  168. //allList, err := models.GetArticleAll()
  169. allList, err := models.GetArticleAllDate(endDate)
  170. if err != nil {
  171. fmt.Println("GetArticleAll Err:", err.Error())
  172. return
  173. }
  174. indexName := utils.IndexName
  175. for _, v := range allList {
  176. content := html.UnescapeString(v.Body)
  177. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  178. if err != nil {
  179. fmt.Println("create doc err:", err.Error())
  180. return
  181. }
  182. bodyText := doc.Text()
  183. item := new(ElasticTestArticleDetail)
  184. item.ArticleId = v.ArticleId
  185. item.Title = v.Title
  186. item.PublishDate = v.PublishDate
  187. item.BodyText = bodyText
  188. item.ExpertBackground = v.ExpertBackground
  189. item.Annotation, _ = GetReportContentTextSubNew(v.Annotation)
  190. item.Abstract, _ = GetReportContentTextSubNew(v.Abstract)
  191. item.CategoryId = strconv.Itoa(v.CategoryId)
  192. EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
  193. fmt.Println(v.ArticleId)
  194. }
  195. }
  196. func AddAllArticleV4() {
  197. allList, err := models.GetArticleAll2()
  198. if err != nil {
  199. fmt.Println("GetArticleAll Err:", err.Error())
  200. return
  201. }
  202. indexName := "cygx_article_v4"
  203. for _, v := range allList {
  204. content := html.UnescapeString(v.Body)
  205. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  206. if err != nil {
  207. fmt.Println("create doc err:", err.Error())
  208. return
  209. }
  210. bodyText := doc.Text()
  211. item := new(ElasticTestArticleDetailV4)
  212. item.ArticleId = v.ArticleId
  213. item.Title = v.Title
  214. item.PublishDate = v.PublishDate
  215. item.BodyText = bodyText
  216. item.IsSummary = v.IsSummary
  217. item.IsReport = v.IsReport
  218. //if v.IsReport == 1 {
  219. // item.IsReport = true
  220. //}
  221. //if v.IsSummary == 1 {
  222. // item.IsSummary = true
  223. //}
  224. EsAddOrEditDataV4(indexName, strconv.Itoa(v.ArticleId), item)
  225. fmt.Println(v.ArticleId)
  226. }
  227. }
  228. // "term_vector": "with_positions_offsets"
  229. type ElasticArticleDetail struct {
  230. ArticleId int `description:"报告id"`
  231. Title string `description:"标题"`
  232. TitleEn string `description:"英文标题 "`
  233. UpdateFrequency string `description:"更新周期"`
  234. CreateDate string `description:"创建时间"`
  235. PublishDate string `description:"发布时间"`
  236. Abstract string `description:"摘要"`
  237. CategoryName string `description:"一级分类"`
  238. SubCategoryName string `description:"二级分类"`
  239. InterviewDate string `description:"访谈时间"`
  240. ExpertBackground string `description:"专家背景"`
  241. ExpertNumber string `description:"专家编号"`
  242. Department string `description:"作者"`
  243. ArticleIdMd5 string `description:"纪要id"`
  244. BodyText string `description:"内容"`
  245. }
  246. type ElasticTestArticleDetail struct {
  247. ArticleId int `description:"报告id"`
  248. Title string `description:"标题"`
  249. BodyText string `description:"内容"`
  250. PublishDate string `description:"发布时间"`
  251. ExpertBackground string `description:"专家背景"`
  252. CategoryId string `description:"文章分类"`
  253. Abstract string `description:"摘要"`
  254. Annotation string `description:"核心观点"`
  255. }
  256. type ElasticTestArticleDetailV4 struct {
  257. ArticleId int `description:"报告id"`
  258. Title string `description:"标题"`
  259. BodyText string `description:"内容"`
  260. PublishDate string `description:"发布时间"`
  261. IsSummary int `description:"是否属于纪要库"`
  262. IsReport int `description:"是否属于报告"`
  263. }
  264. func GetAddpArticle() {
  265. list, err := models.GetReportList()
  266. for _, v := range list {
  267. var articleId int
  268. maxArticleIdArticleInfo, errMax := models.GetMaxArticleIdInfo()
  269. if errMax != nil {
  270. fmt.Println(errMax)
  271. return
  272. }
  273. articleId = maxArticleIdArticleInfo.ArticleId + 1
  274. item := new(models.CygxArticle)
  275. item.Title = v.Title
  276. item.ArticleId = articleId
  277. item.SellerAndMobile = v.Author
  278. item.PublishDate = v.PublishTime
  279. item.Abstract = v.Abstract
  280. item.Body = html.UnescapeString(v.Content)
  281. item.BodyText, _ = GetReportContentTextSub(v.Content)
  282. item.IsReport = 1
  283. item.Source = 1
  284. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleId))
  285. item.Department = "弘则产品组"
  286. item.ArticleType = "lyjh"
  287. item.IsClass = 1
  288. item.CreateDate = v.CreateTime
  289. item.UpdateFrequency = "unknow"
  290. item.CategoryId = 100 // 100是路演精华对应ID
  291. item.SubCategoryName = "路演精华"
  292. item.HavePublish = 1
  293. item.PublishStatus = 1
  294. item.Periods = strconv.Itoa(v.Stage)
  295. item.VideoUrl = v.VideoUrl
  296. item.VideoName = v.VideoName
  297. item.VideoPlaySeconds = v.VideoPlaySeconds
  298. newId, _ := models.AddCygxArticles(item)
  299. fmt.Println(articleId)
  300. fmt.Println(newId)
  301. fmt.Println(item.ArticleIdMd5)
  302. }
  303. fmt.Println(err)
  304. fmt.Println(list)
  305. }
  306. func SynchronizationArthistory() {
  307. go SynchronizationArtclehistory()
  308. }
  309. //func init() {
  310. //
  311. // var newActivityName string
  312. // list, err := models.GetActivityList()
  313. // if err != nil {
  314. // fmt.Println(err)
  315. // }
  316. // for _, v := range list {
  317. //
  318. // fmt.Println("原来的", v.ActivityName)
  319. // newActivityName = v.ActivityName
  320. // newActivityName = strings.Replace(newActivityName, "【", "", -1)
  321. // newActivityName = strings.Replace(newActivityName, "】", "", -1)
  322. // newActivityName = strings.Replace(newActivityName, "-", "", -1)
  323. // newActivityName = strings.Replace(newActivityName, "—", "", -1)
  324. // newActivityName = strings.Replace(newActivityName, " ", "", -1)
  325. // newActivityName = strings.Replace(newActivityName, ":", "", -1)
  326. // fmt.Println("处理的", newActivityName)
  327. // err = models.UpdateCygxActivityName(v.ActivityId, newActivityName)
  328. // if err != nil {
  329. // fmt.Println(err)
  330. // }
  331. // }
  332. //}
  333. //func init() {
  334. // fmt.Println("init start")
  335. // go UpdateDailyMonthReadBillboardV2()
  336. // fmt.Println("init end")
  337. //}