task.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. package services
  2. import (
  3. "fmt"
  4. "github.com/astaxie/beego/toolbox"
  5. "hongze/hongze_cygx/utils"
  6. //"github.com/astaxie/beego/cache"
  7. )
  8. func Task() {
  9. fmt.Println("start")
  10. //同步数据
  11. if utils.RunMode == "release" {
  12. //syncTacticsList := toolbox.NewTask("syncTacticsList", "0 */5 * * * *", SyncTacticsList)
  13. //toolbox.AddTask("syncTacticsList", syncTacticsList)
  14. //toolbox.StartTask()
  15. syncTacticsListAddreport := toolbox.NewTask("syncTacticsListAddreport", "0 */5 * * * *", SyncTacticsListAddreport)
  16. toolbox.AddTask("syncTacticsListAddreport", syncTacticsListAddreport)
  17. //同步纪要库中的Es
  18. syncTacticsListToEs := toolbox.NewTask("syncTacticsListToEs", "0 */30 * * * *", SyncTacticsListToEs)
  19. toolbox.AddTask("syncTacticsListToEs", syncTacticsListToEs)
  20. toolbox.StartTask()
  21. }
  22. if utils.RunMode == "debug" {
  23. //syncTacticsList := toolbox.NewTask("syncTacticsList", "0 */5 * * * *", SyncTacticsList)
  24. //toolbox.AddTask("syncTacticsList", syncTacticsList)
  25. //toolbox.StartTask()
  26. syncTacticsListAddreport := toolbox.NewTask("syncTacticsListAddreport", "0 01 01 * * *", SyncTacticsListAddreport)
  27. toolbox.AddTask("syncTacticsListAddreport", syncTacticsListAddreport)
  28. //同步纪要库中的Es
  29. syncTacticsListToEs := toolbox.NewTask("syncTacticsListToEs", "0 01 01 * * *", SyncTacticsListToEs)
  30. toolbox.AddTask("syncTacticsListToEs", syncTacticsListToEs)
  31. toolbox.StartTask()
  32. }
  33. }
  34. func ElasticOption() {
  35. //SyncTacticsList()
  36. //toolbox.StartTask()
  37. //keyWord := "专家"
  38. //pageSize := 20
  39. //SearchByKeyWord(keyWord, pageSize)
  40. //SaveData()
  41. //GetIndustryMap()
  42. //解析报告
  43. //GetArticleExpert()
  44. //SearchByKeyWordQuery("")
  45. //AddMap()
  46. //同步数据
  47. //ImportData()
  48. //AddMap()
  49. //Search("光伏行业")
  50. //修复报告内容
  51. //GetArticleAll()
  52. //indexName := "article_list"
  53. // mappingJson := `{
  54. //"mappings": {
  55. // "dynamic": true,
  56. // "properties": {
  57. // "ArticleId": {
  58. // "type": "integer"
  59. // },
  60. // "Title": {
  61. // "type": "text",
  62. // "analyzer": "ik_smart"
  63. // },
  64. // "TitleEn": {
  65. // "type": "text",
  66. // "analyzer": "ik_smart"
  67. // },
  68. // "UpdateFrequency": {
  69. // "type": "text",
  70. // "analyzer": "ik_smart"
  71. // },
  72. // "CreateDate": {
  73. // "type": "text",
  74. // "analyzer": "ik_smart"
  75. // },
  76. // "PublishDate": {
  77. // "type": "text",
  78. // "analyzer": "ik_smart"
  79. // },
  80. // "Abstract": {
  81. // "type": "text",
  82. // "analyzer": "ik_smart"
  83. // },
  84. // "CategoryName": {
  85. // "type": "text",
  86. // "analyzer": "ik_smart"
  87. // },
  88. // "SubCategoryName": {
  89. // "type": "text",
  90. // "analyzer": "ik_smart"
  91. // },
  92. // "InterviewDate": {
  93. // "type": "text",
  94. // "analyzer": "ik_smart"
  95. // },
  96. // "ExpertBackground": {
  97. // "type": "text",
  98. // "analyzer": "ik_smart"
  99. // },
  100. // "ExpertNumber": {
  101. // "type": "text",
  102. // "analyzer": "ik_smart"
  103. // },
  104. // "Department": {
  105. // "type": "text",
  106. // "analyzer": "ik_smart"
  107. // },
  108. // "BodyText": {
  109. // "type": "text",
  110. // "analyzer": "ik_smart"
  111. // },
  112. // "ArticleIdMd5": {
  113. // "type": "text",
  114. // "analyzer": "ik_smart"
  115. // }
  116. // }
  117. //}
  118. //}`
  119. //EsCreateIndex(indexName,mappingJson)
  120. //插入数据
  121. //allList, err := models.GetArticleAll()
  122. //if err != nil {
  123. // fmt.Println("GetArticleAll Err:", err.Error())
  124. // return
  125. //}
  126. //
  127. //indexName := "article_list"
  128. //
  129. //for _, v := range allList {
  130. // content := html.UnescapeString(v.Body)
  131. // doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  132. // if err != nil {
  133. // fmt.Println("create doc err:", err.Error())
  134. // return
  135. // }
  136. // bodyText := doc.Text()
  137. //
  138. // item := new(ElasticArticleDetail)
  139. // item.ArticleId = v.ArticleId
  140. // item.Title = v.Title
  141. // item.TitleEn = v.TitleEn
  142. // item.UpdateFrequency = v.UpdateFrequency
  143. // item.CreateDate = v.CreateDate
  144. // item.PublishDate = v.PublishDate
  145. // item.Abstract = v.Abstract
  146. // item.CategoryName = v.CategoryName
  147. // item.SubCategoryName = v.SubCategoryName
  148. // item.InterviewDate = v.InterviewDate
  149. // item.ExpertBackground = v.ExpertBackground
  150. // item.ExpertNumber = v.ExpertNumber
  151. // item.Department = v.Department
  152. // item.ArticleIdMd5 = v.ArticleIdMd5
  153. // item.BodyText = bodyText
  154. // EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
  155. //}
  156. //fmt.Println("bm")
  157. //bm, err := cache.NewCache("file", `{"CachePath":"./cache","FileSuffix":".cache", "EmbedExpiry": "120"}`)
  158. ////
  159. //if err != nil {
  160. // fmt.Println("false",err)
  161. //}
  162. ////fmt.Println(bm)
  163. //key:="put_key_one"
  164. ////bm.Put(key,1,1*time.Second)
  165. //b:=bm.IsExist(key)
  166. //fmt.Println(b)
  167. //同步策略文章
  168. //SyncTacticsList()
  169. //indexName := "article_list"
  170. //EsDeleteData(indexName,)
  171. }
  172. /*
  173. searchItem := new(models.SearchItem)
  174. searchItem.ArticleId, _ = strconv.Atoi(v.Id)
  175. searchItem.Body = v.Highlight["BodyText"]
  176. searchItem.Title = title
  177. searchItem.PublishDate = article.PublishDate
  178. */
  179. func CreateIndex() {
  180. indexName := "cygx_article_test" //utils.IndexName
  181. mappingJson := `{
  182. "mappings": {
  183. "dynamic": true,
  184. "properties": {
  185. "ArticleId": {
  186. "type": "integer"
  187. },
  188. "BodyText": {
  189. "type": "text",
  190. "term_vector": "with_positions_offsets"
  191. },
  192. "PublishDate": {
  193. "type": "text"
  194. },
  195. "SubCategoryName": {
  196. "type": "text",
  197. "term_vector": "with_positions_offsets"
  198. },
  199. "Title": {
  200. "type": "text",
  201. "term_vector": "with_positions_offsets"
  202. },
  203. "TitleEn": {
  204. "type": "text",
  205. "term_vector": "with_positions_offsets"
  206. },
  207. "UpdateFrequency": {
  208. "type": "text",
  209. "term_vector": "with_positions_offsets"
  210. }
  211. }
  212. }
  213. }`
  214. EsCreateIndex(indexName, mappingJson)
  215. }
  216. // "term_vector": "with_positions_offsets"
  217. type ElasticArticleDetail struct {
  218. ArticleId int `description:"报告id"`
  219. Title string `description:"标题"`
  220. TitleEn string `description:"英文标题 "`
  221. UpdateFrequency string `description:"更新周期"`
  222. CreateDate string `description:"创建时间"`
  223. PublishDate string `description:"发布时间"`
  224. Abstract string `description:"摘要"`
  225. CategoryName string `description:"一级分类"`
  226. SubCategoryName string `description:"二级分类"`
  227. InterviewDate string `description:"访谈时间"`
  228. ExpertBackground string `description:"专家背景"`
  229. ExpertNumber string `description:"专家编号"`
  230. Department string `description:"作者"`
  231. ArticleIdMd5 string `description:"纪要id"`
  232. BodyText string `description:"内容"`
  233. }
  234. type ElasticTestArticleDetail struct {
  235. ArticleId int `description:"报告id"`
  236. Title string `description:"标题"`
  237. BodyText string `description:"内容"`
  238. PublishDate string `description:"发布时间"`
  239. }