task.go 7.8 KB

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