chart_info_elastic.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package data
  2. import (
  3. "eta_gn/eta_api/models/data_manage"
  4. "eta_gn/eta_api/services/elastic"
  5. "eta_gn/eta_api/utils"
  6. "fmt"
  7. "strconv"
  8. "strings"
  9. )
  10. // AddAllChartInfo
  11. // @Description: 更新es中的所有的图表数据
  12. // @author: Roc
  13. // @datetime 2024-11-20 13:11:35
  14. func AddAllChartInfo() {
  15. allList, err := data_manage.GetChartInfoAllList()
  16. if err != nil {
  17. fmt.Println("GetArticleAll Err:", err.Error())
  18. return
  19. }
  20. total := len(allList)
  21. for k, v := range allList {
  22. AddOrEditChartInfoToEs(v.ChartInfoId)
  23. fmt.Println("剩余", total-k-1, "条图表数据,当前图表id:", v.ChartInfoId)
  24. }
  25. }
  26. // AddOrEditChartInfoToEs 新增和修改ES中的图表数据
  27. func AddOrEditChartInfoToEs(chartInfoId int) {
  28. var err error
  29. defer func() {
  30. if err != nil {
  31. fmt.Println("新增和修改ES中的图表数据失败:", err.Error())
  32. }
  33. }()
  34. itemInfo, err := data_manage.GetChartEsInfoById(chartInfoId)
  35. if err != nil {
  36. return
  37. }
  38. // 获取分享人
  39. obj := data_manage.ChartInfoShare{}
  40. list, _ := obj.GetListByChartInfoId(itemInfo.ChartInfoId)
  41. sharedList := make([]int, 0)
  42. for _, v := range list {
  43. sharedList = append(sharedList, v.SysUserId)
  44. }
  45. itemInfo.SharedUserIdList = sharedList
  46. //添加es
  47. err = elastic.AddOrEditChartInfoToEsData(utils.CHART_INDEX_NAME, strconv.Itoa(itemInfo.ChartInfoId), itemInfo)
  48. return
  49. }
  50. // DeleteChartInfoToEs 删除ES中的图表数据
  51. func DeleteChartInfoToEs(chartInfoId int) {
  52. var err error
  53. defer func() {
  54. if err != nil {
  55. fmt.Println("删除ES中的图表数据失败:", err.Error())
  56. }
  57. }()
  58. //添加es
  59. err = elastic.EsDeleteDataV2(utils.CHART_INDEX_NAME, strconv.Itoa(chartInfoId))
  60. return
  61. }
  62. // EsSearchChartInfo 搜索图表信息
  63. func EsSearchChartInfo(keyword string, showSysId int, sourceList []int, noPermissionChartIdList []int, startSize, pageSize int) (list []*data_manage.ChartInfo, total int64, err error) {
  64. list, total, err = elastic.SearchChartInfoData(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  65. return
  66. }
  67. // ###### 下面是MY ETA 相关,没有意义了
  68. // EsAddOrEditMyChartInfoByChartInfoId 根据图表id 新增和修改ES中的图表数据
  69. func EsAddOrEditMyChartInfoByChartInfoId(chartInfoId int) {
  70. return
  71. errMsg := make([]string, 0)
  72. defer func() {
  73. if len(errMsg) > 0 {
  74. fmt.Println("新增和修改ES中的图表数据失败:", strings.Join(errMsg, "\n"))
  75. }
  76. }()
  77. var condition string
  78. var pars []interface{}
  79. condition += " and a.chart_info_id = ? "
  80. pars = append(pars, chartInfoId)
  81. allList, err := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(condition, pars)
  82. if err != nil {
  83. errMsg = append(errMsg, fmt.Sprintf("EsAddOrEditMyChartInfoByChartInfoId Err:%s", err.Error()))
  84. return
  85. }
  86. for _, v := range allList {
  87. //添加es
  88. err = elastic.EsAddOrEditDataInterface(utils.MY_CHART_INDEX_NAME, strconv.Itoa(v.MyChartId), v)
  89. if err != nil {
  90. errMsg = append(errMsg, fmt.Sprintf("myChartId:%d,添加Es失败,err:%s", v.MyChartId, err.Error()))
  91. }
  92. }
  93. return
  94. }
  95. // EsAddOrEditMyChartInfoByMyChartId 根据我的图库id 新增和修改ES中的图表数据
  96. func EsAddOrEditMyChartInfoByMyChartId(myChartId int) {
  97. return
  98. errMsg := make([]string, 0)
  99. defer func() {
  100. if len(errMsg) > 0 {
  101. fmt.Println("新增和修改ES中的图表数据失败:", strings.Join(errMsg, "\n"))
  102. }
  103. }()
  104. var condition string
  105. var pars []interface{}
  106. condition += " AND a.my_chart_id = ? "
  107. pars = append(pars, myChartId)
  108. allList, err := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(condition, pars)
  109. if err != nil {
  110. errMsg = append(errMsg, fmt.Sprintf("EsAddOrEditMyChartInfoByMyChartId Err:%s", err.Error()))
  111. return
  112. }
  113. for _, v := range allList {
  114. //添加es
  115. err = elastic.EsAddOrEditDataInterface(utils.MY_CHART_INDEX_NAME, strconv.Itoa(v.MyChartId), v)
  116. if err != nil {
  117. errMsg = append(errMsg, fmt.Sprintf("myChartId:%d,添加Es失败,err:%s", v.MyChartId, err.Error()))
  118. }
  119. }
  120. return
  121. }
  122. // EsDeleteMyChartInfoByMyChartId 根据我的图库id 删除ES中的图表数据
  123. func EsDeleteMyChartInfoByMyChartId(myChartId int) {
  124. return
  125. var err error
  126. defer func() {
  127. if err != nil {
  128. fmt.Println("删除ES中的图表数据失败:", err.Error())
  129. }
  130. }()
  131. //添加es
  132. err = elastic.EsDeleteDataV2(utils.MY_CHART_INDEX_NAME, strconv.Itoa(myChartId))
  133. return
  134. }
  135. // EsSearchMyChartInfo 搜索图表信息
  136. func EsSearchMyChartInfo(keyword string, adminId int, noPermissionChartIdList []int, startSize, pageSize int) (list []*data_manage.MyChartList, total int64, err error) {
  137. return
  138. list, total, err = elastic.SearchMyChartInfoData(utils.MY_CHART_INDEX_NAME, keyword, adminId, noPermissionChartIdList, startSize, pageSize)
  139. return
  140. }
  141. // EsDeleteMyChartInfoByMyChartIds 根据我的图表IDs删除ES中的我的图表
  142. func EsDeleteMyChartInfoByMyChartIds(ids []int) {
  143. return
  144. if len(ids) == 0 {
  145. return
  146. }
  147. errMsg := make([]string, 0)
  148. defer func() {
  149. if len(errMsg) > 0 {
  150. fmt.Println("EsDeleteMyChartInfoByMyChartIds, 删除ES中的我的图表数据失败:", strings.Join(errMsg, "\n"))
  151. }
  152. }()
  153. for _, v := range ids {
  154. id := strconv.Itoa(v)
  155. if e := elastic.EsDeleteDataV2(utils.MY_CHART_INDEX_NAME, id); e != nil {
  156. errMsg = append(errMsg, fmt.Sprintf("myChartId:%d,删除Es失败,err:%s", v, e.Error()))
  157. }
  158. }
  159. return
  160. }