task.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 8-22 * * *", SendActivityBeginMsg) //会议前60分钟的提醒
  24. task.AddTask("sendActivityBeginMsg", sendActivityBeginMsg)
  25. sendActivityBeginMsgMeeting := task.NewTask("sendActivityBeginMsgMeeting", "0 */5 8-22 * * *", SendActivityBeginMsgMeeting) //会议前15分钟的提醒
  26. task.AddTask("sendActivityBeginMsgMeeting", sendActivityBeginMsgMeeting)
  27. //预约外呼名单,会前1小时自动发送邮件给专家组
  28. sendEmailFileToExpert := task.NewTask("sendEmailFileToExpert", "0 */5 8-22 * * *", SendEmailFileToExpert) //预约外呼名单,会前1小时自动发送邮件给专家组
  29. task.AddTask("sendEmailFileToExpert", sendEmailFileToExpert)
  30. sendEmailFileForAskMsgResearch := task.NewTask("sendEmailFileForAskMsgResearch", "0 */5 8-22 * * *", SendEmailFileForAskMsgResearch) //研选系列专家电话会,会前1小时将问题列表发送给邮箱
  31. task.AddTask("sendEmailFileForAskMsgResearch", sendEmailFileForAskMsgResearch)
  32. sendEmailFileForAskMsg := task.NewTask("sendEmailFileForAskMsg", "0 */5 8-22 * * *", SendEmailFileForAskMsg) //非研选系列专家电话会,根据主持人姓名,会前15分钟将问题列表发送给至该主持人对应邮箱
  33. task.AddTask("sendEmailFileForAskMsg", sendEmailFileForAskMsg)
  34. sendEmailUserWhiteListChange := task.NewTask("sendEmailUserWhiteListChange", "0 00 17 * * *", SendEmailUserWhiteListChange) //新增 和冻结的客户白名单
  35. task.AddTask("sendEmailUserWhiteListChange", sendEmailUserWhiteListChange)
  36. }
  37. if utils.IsTask {
  38. //修改任务状
  39. updateActivitySattus := task.NewTask("syncTacticsListAddreport", "0 */1 8-22 * * *", UpdateActivitySattus)
  40. task.AddTask("updateActivitySattus", updateActivitySattus)
  41. //更新深 和新的标签
  42. updateIndustrialManagementLabel := task.NewTask("updateIndustrialManagementLabel", "0 */30 * * * *", UpdateIndustrialManagementLabel)
  43. task.AddTask("updateIndustrialManagementLabel", updateIndustrialManagementLabel)
  44. //更改对应产业的文章阅读数量
  45. chageIndustrialArticleNum := task.NewTask("chageIndustrialArticleNum", "0 01 00 * * *", ChageIndustrialArticleNum) //更改对应产业的文章阅读数量
  46. task.AddTask("chageIndustrialArticleNum", chageIndustrialArticleNum)
  47. }
  48. //GetAddpArticle() //同步日度点评数据
  49. task.StartTask()
  50. fmt.Println("end")
  51. }
  52. ////白名单发送
  53. //sendEmailUserWhiteList := task.NewTask("sendEmailUserWhiteList", "0 27 17 * * *", SendEmailUserWhiteList) //白名单发送
  54. //task.AddTask("sendEmailUserWhiteList", sendEmailUserWhiteList)
  55. //editOutboundMobile := task.NewTask("editOutboundMobile", "0 */1 8-22 * * *", EditOutboundMobile) //同步外呼号码与手机号
  56. //task.AddTask("sendEmailFileToExpert", editOutboundMobile)
  57. //editUserOutboundMobile := task.NewTask("editUserOutboundMobile", "0 27 14 * * * ", EditUserOutboundMobile) //同步外呼号码与手机号
  58. //task.AddTask("editUserOutboundMobile", editUserOutboundMobile)
  59. func ElasticOption() {
  60. //SyncTacticsList()
  61. //toolbox.StartTask()
  62. //keyWord := "专家"
  63. //pageSize := 20
  64. //SearchByKeyWord(keyWord, pageSize)
  65. //SaveData()
  66. //GetIndustryMap()
  67. //解析报告
  68. //GetArticleExpert()
  69. //SearchByKeyWordQuery("")
  70. //AddMap()
  71. //同步数据
  72. //ImportData()
  73. //AddMap()
  74. //Search("光伏行业")
  75. //修复报告内容
  76. //GetArticleAll()
  77. //indexName := "article_list"
  78. // mappingJson := `{
  79. //"mappings": {
  80. // "dynamic": true,
  81. // "properties": {
  82. // "ArticleId": {
  83. // "type": "integer"
  84. // },
  85. // "Title": {
  86. // "type": "text",
  87. // "analyzer": "ik_smart"
  88. // },
  89. // "TitleEn": {
  90. // "type": "text",
  91. // "analyzer": "ik_smart"
  92. // },
  93. // "UpdateFrequency": {
  94. // "type": "text",
  95. // "analyzer": "ik_smart"
  96. // },
  97. // "CreateDate": {
  98. // "type": "text",
  99. // "analyzer": "ik_smart"
  100. // },
  101. // "PublishDate": {
  102. // "type": "text",
  103. // "analyzer": "ik_smart"
  104. // },
  105. // "Abstract": {
  106. // "type": "text",
  107. // "analyzer": "ik_smart"
  108. // },
  109. // "CategoryName": {
  110. // "type": "text",
  111. // "analyzer": "ik_smart"
  112. // },
  113. // "SubCategoryName": {
  114. // "type": "text",
  115. // "analyzer": "ik_smart"
  116. // },
  117. // "InterviewDate": {
  118. // "type": "text",
  119. // "analyzer": "ik_smart"
  120. // },
  121. // "ExpertBackground": {
  122. // "type": "text",
  123. // "analyzer": "ik_smart"
  124. // },
  125. // "ExpertNumber": {
  126. // "type": "text",
  127. // "analyzer": "ik_smart"
  128. // },
  129. // "Department": {
  130. // "type": "text",
  131. // "analyzer": "ik_smart"
  132. // },
  133. // "BodyText": {
  134. // "type": "text",
  135. // "analyzer": "ik_smart"
  136. // },
  137. // "ArticleIdMd5": {
  138. // "type": "text",
  139. // "analyzer": "ik_smart"
  140. // }
  141. // }
  142. //}
  143. //}`
  144. //EsCreateIndex(indexName,mappingJson)
  145. //插入数据
  146. //allList, err := models.GetArticleAll()
  147. //if err != nil {
  148. // fmt.Println("GetArticleAll Err:", err.Error())
  149. // return
  150. //}
  151. //
  152. //indexName := "article_list"
  153. //
  154. //for _, v := range allList {
  155. // content := html.UnescapeString(v.Body)
  156. // doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  157. // if err != nil {
  158. // fmt.Println("create doc err:", err.Error())
  159. // return
  160. // }
  161. // bodyText := doc.Text()
  162. //
  163. // item := new(ElasticArticleDetail)
  164. // item.ArticleId = v.ArticleId
  165. // item.Title = v.Title
  166. // item.TitleEn = v.TitleEn
  167. // item.UpdateFrequency = v.UpdateFrequency
  168. // item.CreateDate = v.CreateDate
  169. // item.PublishDate = v.PublishDate
  170. // item.Abstract = v.Abstract
  171. // item.CategoryName = v.CategoryName
  172. // item.SubCategoryName = v.SubCategoryName
  173. // item.InterviewDate = v.InterviewDate
  174. // item.ExpertBackground = v.ExpertBackground
  175. // item.ExpertNumber = v.ExpertNumber
  176. // item.Department = v.Department
  177. // item.ArticleIdMd5 = v.ArticleIdMd5
  178. // item.BodyText = bodyText
  179. // EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
  180. //}
  181. //fmt.Println("bm")
  182. //bm, err := cache.NewCache("file", `{"CachePath":"./cache","FileSuffix":".cache", "EmbedExpiry": "120"}`)
  183. ////
  184. //if err != nil {
  185. // fmt.Println("false",err)
  186. //}
  187. ////fmt.Println(bm)
  188. //key:="put_key_one"
  189. ////bm.Put(key,1,1*time.Second)
  190. //b:=bm.IsExist(key)
  191. //fmt.Println(b)
  192. //同步策略文章
  193. //SyncTacticsList()
  194. //indexName := "article_list"
  195. //EsDeleteData(indexName,)
  196. }
  197. /*
  198. searchItem := new(models.SearchItem)
  199. searchItem.ArticleId, _ = strconv.Atoi(v.Id)
  200. searchItem.Body = v.Highlight["BodyText"]
  201. searchItem.Title = title
  202. searchItem.PublishDate = article.PublishDate
  203. */
  204. func CreateIndex() {
  205. indexName := "cygx_article_v4" //utils.IndexName
  206. mappingJson := `{
  207. "mappings": {
  208. "dynamic": true,
  209. "properties": {
  210. "ArticleId": {
  211. "type": "integer"
  212. },
  213. "BodyText": {
  214. "type": "text",
  215. "term_vector": "with_positions_offsets",
  216. "analyzer": "ik_smart"
  217. },
  218. "PublishDate": {
  219. "type": "keyword"
  220. },
  221. "SubCategoryName": {
  222. "type": "text",
  223. "term_vector": "with_positions_offsets",
  224. "analyzer": "ik_smart"
  225. },
  226. "Title": {
  227. "type": "text",
  228. "term_vector": "with_positions_offsets",
  229. "analyzer": "ik_smart"
  230. },
  231. "TitleEn": {
  232. "type": "text",
  233. "term_vector": "with_positions_offsets"
  234. },
  235. "UpdateFrequency": {
  236. "type": "text",
  237. "term_vector": "with_positions_offsets"
  238. }
  239. }
  240. }
  241. }`
  242. EsCreateIndex(indexName, mappingJson)
  243. AddAllArticle()
  244. }
  245. func AddAllArticle() {
  246. endDate := time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
  247. //allList, err := models.GetArticleAll()
  248. allList, err := models.GetArticleAllDate(endDate)
  249. if err != nil {
  250. fmt.Println("GetArticleAll Err:", err.Error())
  251. return
  252. }
  253. indexName := utils.IndexName
  254. for _, v := range allList {
  255. content := html.UnescapeString(v.Body)
  256. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  257. if err != nil {
  258. fmt.Println("create doc err:", err.Error())
  259. return
  260. }
  261. bodyText := doc.Text()
  262. item := new(ElasticTestArticleDetail)
  263. item.ArticleId = v.ArticleId
  264. item.Title = v.Title
  265. item.PublishDate = v.PublishDate
  266. item.BodyText = bodyText
  267. EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
  268. fmt.Println(v.ArticleId)
  269. }
  270. }
  271. func AddAllArticleV4() {
  272. allList, err := models.GetArticleAll2()
  273. if err != nil {
  274. fmt.Println("GetArticleAll Err:", err.Error())
  275. return
  276. }
  277. indexName := "cygx_article_v4"
  278. for _, v := range allList {
  279. content := html.UnescapeString(v.Body)
  280. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  281. if err != nil {
  282. fmt.Println("create doc err:", err.Error())
  283. return
  284. }
  285. bodyText := doc.Text()
  286. item := new(ElasticTestArticleDetailV4)
  287. item.ArticleId = v.ArticleId
  288. item.Title = v.Title
  289. item.PublishDate = v.PublishDate
  290. item.BodyText = bodyText
  291. item.IsSummary = v.IsSummary
  292. item.IsReport = v.IsReport
  293. //if v.IsReport == 1 {
  294. // item.IsReport = true
  295. //}
  296. //if v.IsSummary == 1 {
  297. // item.IsSummary = true
  298. //}
  299. EsAddOrEditDataV4(indexName, strconv.Itoa(v.ArticleId), item)
  300. fmt.Println(v.ArticleId)
  301. }
  302. }
  303. // "term_vector": "with_positions_offsets"
  304. type ElasticArticleDetail struct {
  305. ArticleId int `description:"报告id"`
  306. Title string `description:"标题"`
  307. TitleEn string `description:"英文标题 "`
  308. UpdateFrequency string `description:"更新周期"`
  309. CreateDate string `description:"创建时间"`
  310. PublishDate string `description:"发布时间"`
  311. Abstract string `description:"摘要"`
  312. CategoryName string `description:"一级分类"`
  313. SubCategoryName string `description:"二级分类"`
  314. InterviewDate string `description:"访谈时间"`
  315. ExpertBackground string `description:"专家背景"`
  316. ExpertNumber string `description:"专家编号"`
  317. Department string `description:"作者"`
  318. ArticleIdMd5 string `description:"纪要id"`
  319. BodyText string `description:"内容"`
  320. }
  321. type ElasticTestArticleDetail struct {
  322. ArticleId int `description:"报告id"`
  323. Title string `description:"标题"`
  324. BodyText string `description:"内容"`
  325. PublishDate string `description:"发布时间"`
  326. }
  327. type ElasticTestArticleDetailV4 struct {
  328. ArticleId int `description:"报告id"`
  329. Title string `description:"标题"`
  330. BodyText string `description:"内容"`
  331. PublishDate string `description:"发布时间"`
  332. IsSummary int `description:"是否属于纪要库"`
  333. IsReport int `description:"是否属于报告"`
  334. }
  335. func GetAddpArticle() {
  336. list, err := models.GetReportList()
  337. for _, v := range list {
  338. var articleId int
  339. maxArticleIdArticleInfo, errMax := models.GetMaxArticleIdInfo()
  340. if errMax != nil {
  341. fmt.Println(errMax)
  342. return
  343. }
  344. articleId = maxArticleIdArticleInfo.ArticleId + 1
  345. item := new(models.CygxArticle)
  346. item.Title = v.Title
  347. item.ArticleId = articleId
  348. item.SellerAndMobile = v.Author
  349. item.PublishDate = v.PublishTime
  350. item.Abstract = v.Abstract
  351. item.Body = html.UnescapeString(v.Content)
  352. item.BodyText, _ = GetReportContentTextSub(v.Content)
  353. item.IsReport = 1
  354. item.Source = 1
  355. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleId))
  356. item.Department = "弘则产品组"
  357. item.ArticleType = "lyjh"
  358. item.IsClass = 1
  359. item.CreateDate = v.CreateTime
  360. item.UpdateFrequency = "unknow"
  361. item.CategoryId = 100 // 100是路演精华对应ID
  362. item.SubCategoryName = "路演精华"
  363. item.HavePublish = 1
  364. item.PublishStatus = 1
  365. item.Periods = strconv.Itoa(v.Stage)
  366. item.VideoUrl = v.VideoUrl
  367. item.VideoName = v.VideoName
  368. item.VideoPlaySeconds = v.VideoPlaySeconds
  369. newId, _ := models.AddCygxArticles(item)
  370. fmt.Println(articleId)
  371. fmt.Println(newId)
  372. fmt.Println(item.ArticleIdMd5)
  373. }
  374. fmt.Println(err)
  375. fmt.Println(list)
  376. }