task.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. package services
  2. import (
  3. "fmt"
  4. "github.com/PuerkitoBio/goquery"
  5. //"github.com/beego/beego/v2/adapter/toolbox"
  6. "github.com/beego/beego/v2/task"
  7. "hongze/hongze_cygx/models"
  8. "hongze/hongze_cygx/utils"
  9. "html"
  10. "strconv"
  11. "strings"
  12. "time"
  13. //"github.com/beego/beego/v2/adapter/cache"
  14. )
  15. func Task() {
  16. fmt.Println("start")
  17. //同步数据
  18. if utils.RunMode == "release" {
  19. //syncTacticsList := toolbox.NewTask("syncTacticsList", "0 */5 * * * *", SyncTacticsList)
  20. //toolbox.AddTask("syncTacticsList", syncTacticsList)
  21. //toolbox.StartTask()
  22. syncTacticsListAddreport := task.NewTask("syncTacticsListAddreport", "0 */5 * * * *", SyncTacticsListAddreport)
  23. task.AddTask("syncTacticsListAddreport", syncTacticsListAddreport)
  24. //同步纪要库中的Es
  25. //syncTacticsListToEs := toolbox.NewTask("syncTacticsListToEs", "0 */30 * * * *", SyncTacticsListToEs)
  26. //toolbox.AddTask("syncTacticsListToEs", syncTacticsListToEs)
  27. getSummarytoEs := task.NewTask("getSummarytoEs", "0 */30 * * * *", GetSummarytoEs) //同步纪要库内容到Es
  28. task.AddTask("getSummarytoEs", getSummarytoEs)
  29. //toolbox.StartTask()
  30. }
  31. //UpdateActivitySattus()
  32. //修改任务状态
  33. updateActivitySattus := task.NewTask("syncTacticsListAddreport", "0 */1 8-22 * * *", UpdateActivitySattus)
  34. task.AddTask("updateActivitySattus", updateActivitySattus)
  35. //更新深 和新的标签
  36. updateIndustrialManagementLabel := task.NewTask("updateIndustrialManagementLabel", "0 */30 * * * *", UpdateIndustrialManagementLabel)
  37. task.AddTask("updateIndustrialManagementLabel", updateIndustrialManagementLabel)
  38. //更新报告的搜索栏内容
  39. //UpdateIndustrialManagementSubjectNnames()
  40. //会议提醒模板消息推送
  41. sendActivityBeginMsg := task.NewTask("sendActivityBeginMsg", "0 */10 8-22 * * *", SendActivityBeginMsg) //会议前60分钟的提醒
  42. task.AddTask("sendActivityBeginMsg", sendActivityBeginMsg)
  43. sendActivityBeginMsgMeeting := task.NewTask("sendActivityBeginMsgMeeting", "0 */5 8-22 * * *", SendActivityBeginMsgMeeting) //会议前15分钟的提醒
  44. task.AddTask("sendActivityBeginMsgMeeting", sendActivityBeginMsgMeeting)
  45. //预约外呼名单,会前1小时自动发送邮件给专家组
  46. sendEmailFileToExpert := task.NewTask("sendEmailFileToExpert", "0 */5 8-22 * * *", SendEmailFileToExpert) //预约外呼名单,会前1小时自动发送邮件给专家组
  47. task.AddTask("sendEmailFileToExpert", sendEmailFileToExpert)
  48. //editOutboundMobile := task.NewTask("editOutboundMobile", "0 */1 8-22 * * *", EditOutboundMobile) //同步外呼号码与手机号
  49. //task.AddTask("sendEmailFileToExpert", editOutboundMobile)
  50. //editUserOutboundMobile := task.NewTask("editUserOutboundMobile", "0 27 14 * * * ", EditUserOutboundMobile) //同步外呼号码与手机号
  51. //task.AddTask("editUserOutboundMobile", editUserOutboundMobile)
  52. task.StartTask()
  53. fmt.Println("end")
  54. }
  55. func ElasticOption() {
  56. //SyncTacticsList()
  57. //toolbox.StartTask()
  58. //keyWord := "专家"
  59. //pageSize := 20
  60. //SearchByKeyWord(keyWord, pageSize)
  61. //SaveData()
  62. //GetIndustryMap()
  63. //解析报告
  64. //GetArticleExpert()
  65. //SearchByKeyWordQuery("")
  66. //AddMap()
  67. //同步数据
  68. //ImportData()
  69. //AddMap()
  70. //Search("光伏行业")
  71. //修复报告内容
  72. //GetArticleAll()
  73. //indexName := "article_list"
  74. // mappingJson := `{
  75. //"mappings": {
  76. // "dynamic": true,
  77. // "properties": {
  78. // "ArticleId": {
  79. // "type": "integer"
  80. // },
  81. // "Title": {
  82. // "type": "text",
  83. // "analyzer": "ik_smart"
  84. // },
  85. // "TitleEn": {
  86. // "type": "text",
  87. // "analyzer": "ik_smart"
  88. // },
  89. // "UpdateFrequency": {
  90. // "type": "text",
  91. // "analyzer": "ik_smart"
  92. // },
  93. // "CreateDate": {
  94. // "type": "text",
  95. // "analyzer": "ik_smart"
  96. // },
  97. // "PublishDate": {
  98. // "type": "text",
  99. // "analyzer": "ik_smart"
  100. // },
  101. // "Abstract": {
  102. // "type": "text",
  103. // "analyzer": "ik_smart"
  104. // },
  105. // "CategoryName": {
  106. // "type": "text",
  107. // "analyzer": "ik_smart"
  108. // },
  109. // "SubCategoryName": {
  110. // "type": "text",
  111. // "analyzer": "ik_smart"
  112. // },
  113. // "InterviewDate": {
  114. // "type": "text",
  115. // "analyzer": "ik_smart"
  116. // },
  117. // "ExpertBackground": {
  118. // "type": "text",
  119. // "analyzer": "ik_smart"
  120. // },
  121. // "ExpertNumber": {
  122. // "type": "text",
  123. // "analyzer": "ik_smart"
  124. // },
  125. // "Department": {
  126. // "type": "text",
  127. // "analyzer": "ik_smart"
  128. // },
  129. // "BodyText": {
  130. // "type": "text",
  131. // "analyzer": "ik_smart"
  132. // },
  133. // "ArticleIdMd5": {
  134. // "type": "text",
  135. // "analyzer": "ik_smart"
  136. // }
  137. // }
  138. //}
  139. //}`
  140. //EsCreateIndex(indexName,mappingJson)
  141. //插入数据
  142. //allList, err := models.GetArticleAll()
  143. //if err != nil {
  144. // fmt.Println("GetArticleAll Err:", err.Error())
  145. // return
  146. //}
  147. //
  148. //indexName := "article_list"
  149. //
  150. //for _, v := range allList {
  151. // content := html.UnescapeString(v.Body)
  152. // doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  153. // if err != nil {
  154. // fmt.Println("create doc err:", err.Error())
  155. // return
  156. // }
  157. // bodyText := doc.Text()
  158. //
  159. // item := new(ElasticArticleDetail)
  160. // item.ArticleId = v.ArticleId
  161. // item.Title = v.Title
  162. // item.TitleEn = v.TitleEn
  163. // item.UpdateFrequency = v.UpdateFrequency
  164. // item.CreateDate = v.CreateDate
  165. // item.PublishDate = v.PublishDate
  166. // item.Abstract = v.Abstract
  167. // item.CategoryName = v.CategoryName
  168. // item.SubCategoryName = v.SubCategoryName
  169. // item.InterviewDate = v.InterviewDate
  170. // item.ExpertBackground = v.ExpertBackground
  171. // item.ExpertNumber = v.ExpertNumber
  172. // item.Department = v.Department
  173. // item.ArticleIdMd5 = v.ArticleIdMd5
  174. // item.BodyText = bodyText
  175. // EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
  176. //}
  177. //fmt.Println("bm")
  178. //bm, err := cache.NewCache("file", `{"CachePath":"./cache","FileSuffix":".cache", "EmbedExpiry": "120"}`)
  179. ////
  180. //if err != nil {
  181. // fmt.Println("false",err)
  182. //}
  183. ////fmt.Println(bm)
  184. //key:="put_key_one"
  185. ////bm.Put(key,1,1*time.Second)
  186. //b:=bm.IsExist(key)
  187. //fmt.Println(b)
  188. //同步策略文章
  189. //SyncTacticsList()
  190. //indexName := "article_list"
  191. //EsDeleteData(indexName,)
  192. }
  193. /*
  194. searchItem := new(models.SearchItem)
  195. searchItem.ArticleId, _ = strconv.Atoi(v.Id)
  196. searchItem.Body = v.Highlight["BodyText"]
  197. searchItem.Title = title
  198. searchItem.PublishDate = article.PublishDate
  199. */
  200. func CreateIndex() {
  201. indexName := "cygx_article_v4" //utils.IndexName
  202. mappingJson := `{
  203. "mappings": {
  204. "dynamic": true,
  205. "properties": {
  206. "ArticleId": {
  207. "type": "integer"
  208. },
  209. "BodyText": {
  210. "type": "text",
  211. "term_vector": "with_positions_offsets",
  212. "analyzer": "ik_smart"
  213. },
  214. "PublishDate": {
  215. "type": "keyword"
  216. },
  217. "SubCategoryName": {
  218. "type": "text",
  219. "term_vector": "with_positions_offsets",
  220. "analyzer": "ik_smart"
  221. },
  222. "Title": {
  223. "type": "text",
  224. "term_vector": "with_positions_offsets",
  225. "analyzer": "ik_smart"
  226. },
  227. "TitleEn": {
  228. "type": "text",
  229. "term_vector": "with_positions_offsets"
  230. },
  231. "UpdateFrequency": {
  232. "type": "text",
  233. "term_vector": "with_positions_offsets"
  234. }
  235. }
  236. }
  237. }`
  238. EsCreateIndex(indexName, mappingJson)
  239. }
  240. func AddAllArticle() {
  241. endDate := time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
  242. //allList, err := models.GetArticleAll()
  243. allList, err := models.GetArticleAllDate(endDate)
  244. if err != nil {
  245. fmt.Println("GetArticleAll Err:", err.Error())
  246. return
  247. }
  248. indexName := utils.IndexName
  249. for _, v := range allList {
  250. content := html.UnescapeString(v.Body)
  251. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  252. if err != nil {
  253. fmt.Println("create doc err:", err.Error())
  254. return
  255. }
  256. bodyText := doc.Text()
  257. item := new(ElasticTestArticleDetail)
  258. item.ArticleId = v.ArticleId
  259. item.Title = v.Title
  260. item.PublishDate = v.PublishDate
  261. item.BodyText = bodyText
  262. EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
  263. fmt.Println(v.ArticleId)
  264. }
  265. }
  266. func AddAllArticleV4() {
  267. allList, err := models.GetArticleAll2()
  268. if err != nil {
  269. fmt.Println("GetArticleAll Err:", err.Error())
  270. return
  271. }
  272. indexName := "cygx_article_v4"
  273. for _, v := range allList {
  274. content := html.UnescapeString(v.Body)
  275. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  276. if err != nil {
  277. fmt.Println("create doc err:", err.Error())
  278. return
  279. }
  280. bodyText := doc.Text()
  281. item := new(ElasticTestArticleDetailV4)
  282. item.ArticleId = v.ArticleId
  283. item.Title = v.Title
  284. item.PublishDate = v.PublishDate
  285. item.BodyText = bodyText
  286. item.IsSummary = v.IsSummary
  287. item.IsReport = v.IsReport
  288. //if v.IsReport == 1 {
  289. // item.IsReport = true
  290. //}
  291. //if v.IsSummary == 1 {
  292. // item.IsSummary = true
  293. //}
  294. EsAddOrEditDataV4(indexName, strconv.Itoa(v.ArticleId), item)
  295. fmt.Println(v.ArticleId)
  296. }
  297. }
  298. // "term_vector": "with_positions_offsets"
  299. type ElasticArticleDetail struct {
  300. ArticleId int `description:"报告id"`
  301. Title string `description:"标题"`
  302. TitleEn string `description:"英文标题 "`
  303. UpdateFrequency string `description:"更新周期"`
  304. CreateDate string `description:"创建时间"`
  305. PublishDate string `description:"发布时间"`
  306. Abstract string `description:"摘要"`
  307. CategoryName string `description:"一级分类"`
  308. SubCategoryName string `description:"二级分类"`
  309. InterviewDate string `description:"访谈时间"`
  310. ExpertBackground string `description:"专家背景"`
  311. ExpertNumber string `description:"专家编号"`
  312. Department string `description:"作者"`
  313. ArticleIdMd5 string `description:"纪要id"`
  314. BodyText string `description:"内容"`
  315. }
  316. type ElasticTestArticleDetail struct {
  317. ArticleId int `description:"报告id"`
  318. Title string `description:"标题"`
  319. BodyText string `description:"内容"`
  320. PublishDate string `description:"发布时间"`
  321. }
  322. type ElasticTestArticleDetailV4 struct {
  323. ArticleId int `description:"报告id"`
  324. Title string `description:"标题"`
  325. BodyText string `description:"内容"`
  326. PublishDate string `description:"发布时间"`
  327. IsSummary int `description:"是否属于纪要库"`
  328. IsReport int `description:"是否属于报告"`
  329. }