chart_info_elastic.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package services
  2. import (
  3. "eta/eta_forum_admin/models"
  4. "eta/eta_forum_admin/services/elastic"
  5. "eta/eta_forum_admin/utils"
  6. "fmt"
  7. "strconv"
  8. )
  9. func CreateChartInfoIndex() {
  10. indexName := utils.CHART_INDEX_NAME
  11. mappingJson := `{
  12. "mappings": {
  13. "dynamic": true,
  14. "properties": {
  15. "ChartInfoId": {
  16. "type": "integer"
  17. },
  18. "ChartName": {
  19. "type": "text",
  20. "term_vector": "with_positions_offsets",
  21. "analyzer": "ik_smart"
  22. },
  23. "ChartClassifyId": {
  24. "type": "integer"
  25. },
  26. "SysUserId": {
  27. "type": "integer"
  28. },
  29. "SysUserRealName": {
  30. "type": "text",
  31. "term_vector": "with_positions_offsets",
  32. "analyzer": "ik_smart"
  33. },
  34. "UniqueCode": {
  35. "type": "text",
  36. "term_vector": "with_positions_offsets"
  37. },
  38. "Unit": {
  39. "type": "text",
  40. "term_vector": "with_positions_offsets"
  41. },
  42. "CreateTime": {
  43. "type": "date"
  44. },
  45. "ModifyTime": {
  46. "type": "date"
  47. },
  48. "DateType": {
  49. "type": "integer"
  50. },
  51. "StartDate": {
  52. "type": "text",
  53. "term_vector": "with_positions_offsets"
  54. },
  55. "EndDate": {
  56. "type": "text",
  57. "term_vector": "with_positions_offsets"
  58. },
  59. "IsSetName": {
  60. "type": "integer"
  61. },
  62. "EdbInfoIds": {
  63. "type": "text",
  64. "term_vector": "with_positions_offsets"
  65. },
  66. "ChartType": {
  67. "type": "integer"
  68. },
  69. "Calendar": {
  70. "type": "text",
  71. "term_vector": "with_positions_offsets"
  72. },
  73. "ChartImage": {
  74. "type": "text",
  75. "term_vector": "with_positions_offsets"
  76. }
  77. }
  78. }
  79. }`
  80. elastic.EsCreateIndex(indexName, mappingJson)
  81. }
  82. func AddAllChartInfo() {
  83. allList, err := models.GetChartInfoAllList()
  84. if err != nil {
  85. fmt.Println("GetArticleAll Err:", err.Error())
  86. return
  87. }
  88. total := len(allList)
  89. for k, v := range allList {
  90. EsAddOrEditChartInfo(v.ChartInfoId)
  91. //fmt.Println(v.ChartInfoId)
  92. fmt.Println("剩余", total-k-1, "条数据,当前图表id:", v.ChartInfoId)
  93. }
  94. }
  95. // EsAddOrEditChartInfo 新增和修改ES中的图表数据
  96. func EsAddOrEditChartInfo(chartInfoId int) {
  97. var err error
  98. defer func() {
  99. if err != nil {
  100. fmt.Println("新增和修改ES中的图表数据失败:", err.Error())
  101. }
  102. }()
  103. itemInfo, _ := models.GetChartInfoById(chartInfoId)
  104. //添加es
  105. err = elastic.EsAddOrEditChartInfoData(utils.CHART_INDEX_NAME, strconv.Itoa(itemInfo.ChartInfoId), itemInfo)
  106. return
  107. }
  108. // EsDeleteChartInfo 删除ES中的图表数据
  109. func EsDeleteChartInfo(chartInfoId int) {
  110. var err error
  111. defer func() {
  112. if err != nil {
  113. fmt.Println("删除ES中的图表数据失败:", err.Error())
  114. }
  115. }()
  116. //添加es
  117. err = elastic.EsDeleteDataV2(utils.CHART_INDEX_NAME, strconv.Itoa(chartInfoId))
  118. return
  119. }
  120. // EsSearchChartInfo 搜索图表信息
  121. func EsSearchChartInfo(keyword string, showSysId []int, sourceList []int, startSize, pageSize int) (list []*models.ChartInfo, total int64, err error) {
  122. list, total, err = elastic.SearchChartInfoData(utils.CHART_INDEX_NAME, keyword, showSysId, sourceList, startSize, pageSize)
  123. return
  124. }