task.go 10 KB

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