task.go 9.7 KB

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