task.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. getCeLueArticlePv := task.NewTask("getCeLueArticlePv", "0 */10 * * * *", GetCeLueArticlePv) //通过三方接口获取策略平台上的阅读记录
  23. task.AddTask("getCeLueArticlePv", getCeLueArticlePv)
  24. //会议提醒模板消息推送
  25. sendActivityBeginMsg := task.NewTask("sendActivityBeginMsg", "0 */10 8-22 * * *", SendActivityBeginMsg) //会议前60分钟的提醒
  26. task.AddTask("sendActivityBeginMsg", sendActivityBeginMsg)
  27. sendActivityBeginMsgMeeting := task.NewTask("sendActivityBeginMsgMeeting", "0 */5 8-22 * * *", SendActivityBeginMsgMeeting) //会议前15分钟的提醒
  28. task.AddTask("sendActivityBeginMsgMeeting", sendActivityBeginMsgMeeting)
  29. //预约外呼名单,会前1小时自动发送邮件给专家组
  30. sendEmailFileToExpert := task.NewTask("sendEmailFileToExpert", "0 */5 8-22 * * *", SendEmailFileToExpert) //预约外呼名单,会前1小时自动发送邮件给专家组
  31. task.AddTask("sendEmailFileToExpert", sendEmailFileToExpert)
  32. sendEmailUserWhiteListChange := task.NewTask("sendEmailUserWhiteListChange", "0 00 17 * * *", SendEmailUserWhiteListChange) //新增 和冻结的客户白名单
  33. task.AddTask("白名单发送", sendEmailUserWhiteListChange)
  34. dotongbuShangHai := task.NewTask("dotongbuShangHai", "0 30 3 * * *", DotongbuShangHai) //把信息同步到上海策略品台
  35. task.AddTask("同步用户到上海", dotongbuShangHai)
  36. dotongbuShangHaiSendEmail := task.NewTask("dotongbuShangHaiSendEmail", "0 00 4 * * *", DotongbuShangHaiSendEmail) //发送上海策略品台同步结果名单的邮件附件
  37. task.AddTask("发送上海策略品台同步结果名单的邮件附件", dotongbuShangHaiSendEmail)
  38. getChartListByApi := task.NewTask("getChartListByApi", "0 */30 * * * *", GetChartListByApi) //同步图表
  39. task.AddTask("getChartListByApi", getChartListByApi)
  40. }
  41. if utils.IsTask {
  42. //修改任务状
  43. updateActivitySattus := task.NewTask("syncTacticsListAddreport", "0 */1 8-22 * * *", UpdateActivitySattus)
  44. task.AddTask("updateActivitySattus", updateActivitySattus)
  45. //更新深 和新的标签
  46. updateIndustrialManagementLabel := task.NewTask("updateIndustrialManagementLabel", "0 */30 * * * *", UpdateIndustrialManagementLabel)
  47. task.AddTask("updateIndustrialManagementLabel", updateIndustrialManagementLabel)
  48. //更改对应产业的文章阅读数量
  49. chageIndustrialArticleNum := task.NewTask("chageIndustrialArticleNum", "0 01 00 * * *", ChageIndustrialArticleNum) //更改对应产业的文章阅读数量
  50. task.AddTask("chageIndustrialArticleNum", chageIndustrialArticleNum)
  51. activityAttendanceDetail := task.NewTask("activityAttendanceDetail", "0 00 3 * * *", ActivityAttendanceDetail) //同步进门财经的路演信息
  52. task.AddTask("sendEmailUserWhiteListChange", activityAttendanceDetail)
  53. sendEmailFileForAskMsgResearch := task.NewTask("sendEmailFileForAskMsgResearch", "0 */5 8-22 * * *", SendEmailFileForAskMsgResearch) //研选系列专家电话会,会前1小时将问题列表发送给邮箱
  54. task.AddTask("sendEmailFileForAskMsgResearch", sendEmailFileForAskMsgResearch)
  55. sendEmailFileForAskMsg := task.NewTask("sendEmailFileForAskMsg", "0 */5 8-22 * * *", SendEmailFileForAskMsg) //非研选系列专家电话会,根据主持人姓名,会前15分钟将问题列表发送给至该主持人对应邮箱
  56. task.AddTask("sendEmailFileForAskMsg", sendEmailFileForAskMsg)
  57. }
  58. if utils.RunMode != "release" {
  59. getArticleListByApi := task.NewTask("getArticleListByApi", "0 */60 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章
  60. task.AddTask("getArticleListByApi", getArticleListByApi)
  61. }
  62. //ActivityAttendanceDetail()
  63. //SynchronizationArthistory()//同步原有的阅读记录
  64. //GetAddpArticle() //同步日度点评数据
  65. //SendEmailAllUserWithRAI() //发送当前所有权益用户到沈大爷的邮箱
  66. //SendEmailAllUserWithCompany() //发送这些公司下的用户到沈大爷的邮箱
  67. task.StartTask()
  68. //StatisticalReport()//导出报表
  69. fmt.Println("end")
  70. }
  71. ////白名单发送
  72. //sendEmailUserWhiteList := task.NewTask("sendEmailUserWhiteList", "0 27 17 * * *", SendEmailUserWhiteList) //白名单发送
  73. //task.AddTask("sendEmailUserWhiteList", sendEmailUserWhiteList)
  74. //editOutboundMobile := task.NewTask("editOutboundMobile", "0 */1 8-22 * * *", EditOutboundMobile) //同步外呼号码与手机号
  75. //task.AddTask("sendEmailFileToExpert", editOutboundMobile)
  76. //editUserOutboundMobile := task.NewTask("editUserOutboundMobile", "0 27 14 * * * ", EditUserOutboundMobile) //同步外呼号码与手机号
  77. //task.AddTask("editUserOutboundMobile", editUserOutboundMobile)
  78. func CreateIndex() {
  79. indexName := utils.IndexName
  80. mappingJson := `{
  81. "mappings": {
  82. "dynamic": true,
  83. "properties": {
  84. "ArticleId": {
  85. "type": "integer"
  86. },
  87. "CategoryId": {
  88. "type": "text"
  89. },
  90. "BodyText": {
  91. "type": "text",
  92. "term_vector": "with_positions_offsets",
  93. "analyzer": "ik_smart"
  94. },
  95. "PublishDate": {
  96. "type": "keyword"
  97. },
  98. "SubCategoryName": {
  99. "type": "text",
  100. "term_vector": "with_positions_offsets",
  101. "analyzer": "ik_smart"
  102. },
  103. "Title": {
  104. "type": "text",
  105. "term_vector": "with_positions_offsets",
  106. "analyzer": "ik_smart"
  107. },
  108. "TitleEn": {
  109. "type": "text",
  110. "term_vector": "with_positions_offsets"
  111. },
  112. "UpdateFrequency": {
  113. "type": "text",
  114. "term_vector": "with_positions_offsets"
  115. },
  116. "ExpertBackground": {
  117. "type": "text",
  118. "term_vector": "with_positions_offsets"
  119. }
  120. }
  121. }
  122. }`
  123. EsCreateIndex(indexName, mappingJson)
  124. AddAllArticle()
  125. }
  126. func AddAllArticle() {
  127. endDate := time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
  128. //allList, err := models.GetArticleAll()
  129. allList, err := models.GetArticleAllDate(endDate)
  130. if err != nil {
  131. fmt.Println("GetArticleAll Err:", err.Error())
  132. return
  133. }
  134. indexName := utils.IndexName
  135. for _, v := range allList {
  136. content := html.UnescapeString(v.Body)
  137. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  138. if err != nil {
  139. fmt.Println("create doc err:", err.Error())
  140. return
  141. }
  142. bodyText := doc.Text()
  143. item := new(ElasticTestArticleDetail)
  144. item.ArticleId = v.ArticleId
  145. item.Title = v.Title
  146. item.PublishDate = v.PublishDate
  147. item.BodyText = bodyText
  148. item.ExpertBackground = v.ExpertBackground
  149. item.CategoryId = strconv.Itoa(v.CategoryId)
  150. EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
  151. fmt.Println(v.ArticleId)
  152. }
  153. }
  154. func AddAllArticleV4() {
  155. allList, err := models.GetArticleAll2()
  156. if err != nil {
  157. fmt.Println("GetArticleAll Err:", err.Error())
  158. return
  159. }
  160. indexName := "cygx_article_v4"
  161. for _, v := range allList {
  162. content := html.UnescapeString(v.Body)
  163. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  164. if err != nil {
  165. fmt.Println("create doc err:", err.Error())
  166. return
  167. }
  168. bodyText := doc.Text()
  169. item := new(ElasticTestArticleDetailV4)
  170. item.ArticleId = v.ArticleId
  171. item.Title = v.Title
  172. item.PublishDate = v.PublishDate
  173. item.BodyText = bodyText
  174. item.IsSummary = v.IsSummary
  175. item.IsReport = v.IsReport
  176. //if v.IsReport == 1 {
  177. // item.IsReport = true
  178. //}
  179. //if v.IsSummary == 1 {
  180. // item.IsSummary = true
  181. //}
  182. EsAddOrEditDataV4(indexName, strconv.Itoa(v.ArticleId), item)
  183. fmt.Println(v.ArticleId)
  184. }
  185. }
  186. // "term_vector": "with_positions_offsets"
  187. type ElasticArticleDetail struct {
  188. ArticleId int `description:"报告id"`
  189. Title string `description:"标题"`
  190. TitleEn string `description:"英文标题 "`
  191. UpdateFrequency string `description:"更新周期"`
  192. CreateDate string `description:"创建时间"`
  193. PublishDate string `description:"发布时间"`
  194. Abstract string `description:"摘要"`
  195. CategoryName string `description:"一级分类"`
  196. SubCategoryName string `description:"二级分类"`
  197. InterviewDate string `description:"访谈时间"`
  198. ExpertBackground string `description:"专家背景"`
  199. ExpertNumber string `description:"专家编号"`
  200. Department string `description:"作者"`
  201. ArticleIdMd5 string `description:"纪要id"`
  202. BodyText string `description:"内容"`
  203. }
  204. type ElasticTestArticleDetail struct {
  205. ArticleId int `description:"报告id"`
  206. Title string `description:"标题"`
  207. BodyText string `description:"内容"`
  208. PublishDate string `description:"发布时间"`
  209. ExpertBackground string `description:"专家背景"`
  210. CategoryId string `description:"文章分类"`
  211. }
  212. type ElasticTestArticleDetailV4 struct {
  213. ArticleId int `description:"报告id"`
  214. Title string `description:"标题"`
  215. BodyText string `description:"内容"`
  216. PublishDate string `description:"发布时间"`
  217. IsSummary int `description:"是否属于纪要库"`
  218. IsReport int `description:"是否属于报告"`
  219. }
  220. func GetAddpArticle() {
  221. list, err := models.GetReportList()
  222. for _, v := range list {
  223. var articleId int
  224. maxArticleIdArticleInfo, errMax := models.GetMaxArticleIdInfo()
  225. if errMax != nil {
  226. fmt.Println(errMax)
  227. return
  228. }
  229. articleId = maxArticleIdArticleInfo.ArticleId + 1
  230. item := new(models.CygxArticle)
  231. item.Title = v.Title
  232. item.ArticleId = articleId
  233. item.SellerAndMobile = v.Author
  234. item.PublishDate = v.PublishTime
  235. item.Abstract = v.Abstract
  236. item.Body = html.UnescapeString(v.Content)
  237. item.BodyText, _ = GetReportContentTextSub(v.Content)
  238. item.IsReport = 1
  239. item.Source = 1
  240. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleId))
  241. item.Department = "弘则产品组"
  242. item.ArticleType = "lyjh"
  243. item.IsClass = 1
  244. item.CreateDate = v.CreateTime
  245. item.UpdateFrequency = "unknow"
  246. item.CategoryId = 100 // 100是路演精华对应ID
  247. item.SubCategoryName = "路演精华"
  248. item.HavePublish = 1
  249. item.PublishStatus = 1
  250. item.Periods = strconv.Itoa(v.Stage)
  251. item.VideoUrl = v.VideoUrl
  252. item.VideoName = v.VideoName
  253. item.VideoPlaySeconds = v.VideoPlaySeconds
  254. newId, _ := models.AddCygxArticles(item)
  255. fmt.Println(articleId)
  256. fmt.Println(newId)
  257. fmt.Println(item.ArticleIdMd5)
  258. }
  259. fmt.Println(err)
  260. fmt.Println(list)
  261. }
  262. func SynchronizationArthistory() {
  263. go SynchronizationArtclehistory()
  264. }
  265. //func init() {
  266. //
  267. // var newActivityName string
  268. // list, err := models.GetActivityList()
  269. // if err != nil {
  270. // fmt.Println(err)
  271. // }
  272. // for _, v := range list {
  273. //
  274. // fmt.Println("原来的", v.ActivityName)
  275. // newActivityName = v.ActivityName
  276. // newActivityName = strings.Replace(newActivityName, "【", "", -1)
  277. // newActivityName = strings.Replace(newActivityName, "】", "", -1)
  278. // newActivityName = strings.Replace(newActivityName, "-", "", -1)
  279. // newActivityName = strings.Replace(newActivityName, "—", "", -1)
  280. // newActivityName = strings.Replace(newActivityName, " ", "", -1)
  281. // newActivityName = strings.Replace(newActivityName, ":", "", -1)
  282. // fmt.Println("处理的", newActivityName)
  283. // err = models.UpdateCygxActivityName(v.ActivityId, newActivityName)
  284. // if err != nil {
  285. // fmt.Println(err)
  286. // }
  287. // }
  288. //}