chart_info_elastic.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. // EsAddOrEditChartInfo 新增和修改ES中的图表数据
  11. func EsAddOrEditChartInfo(chartInfoId int) {
  12. var err error
  13. defer func() {
  14. if err != nil {
  15. fmt.Println("新增和修改ES中的图表数据失败:", err.Error())
  16. }
  17. }()
  18. itemInfo, _ := data_manage.GetChartInfoById(chartInfoId)
  19. //添加es
  20. err = elastic.EsAddOrEditChartInfoData(utils.CHART_INDEX_NAME, strconv.Itoa(itemInfo.ChartInfoId), itemInfo)
  21. return
  22. }
  23. // EsDeleteChartInfo 删除ES中的图表数据
  24. func EsDeleteChartInfo(chartInfoId int) {
  25. var err error
  26. defer func() {
  27. if err != nil {
  28. fmt.Println("删除ES中的图表数据失败:", err.Error())
  29. }
  30. }()
  31. //添加es
  32. err = elastic.EsDeleteDataV2(utils.CHART_INDEX_NAME, strconv.Itoa(chartInfoId))
  33. return
  34. }
  35. // EsSearchChartInfo 搜索图表信息
  36. func EsSearchChartInfo(keyword string, showSysId int, sourceList []int, noPermissionChartIdList []int, startSize, pageSize int) (list []*data_manage.ChartInfo, total int64, err error) {
  37. list, total, err = elastic.SearchChartInfoData(utils.CHART_INDEX_NAME, keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  38. return
  39. }
  40. // EsAddOrEditMyChartInfoByChartInfoId 根据图表id 新增和修改ES中的图表数据
  41. func EsAddOrEditMyChartInfoByChartInfoId(chartInfoId int) {
  42. errMsg := make([]string, 0)
  43. defer func() {
  44. if len(errMsg) > 0 {
  45. fmt.Println("新增和修改ES中的图表数据失败:", strings.Join(errMsg, "\n"))
  46. }
  47. }()
  48. var condition string
  49. var pars []interface{}
  50. condition += " and a.chart_info_id = ? "
  51. pars = append(pars, chartInfoId)
  52. allList, err := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(condition, pars)
  53. if err != nil {
  54. errMsg = append(errMsg, fmt.Sprintf("EsAddOrEditMyChartInfoByChartInfoId Err:%s", err.Error()))
  55. return
  56. }
  57. for _, v := range allList {
  58. //添加es
  59. err = elastic.EsAddOrEditDataInterface(utils.MY_CHART_INDEX_NAME, strconv.Itoa(v.MyChartId), v)
  60. if err != nil {
  61. errMsg = append(errMsg, fmt.Sprintf("myChartId:%d,添加Es失败,err:%s", v.MyChartId, err.Error()))
  62. }
  63. }
  64. return
  65. }
  66. // EsAddOrEditMyChartInfoByMyChartId 根据我的图库id 新增和修改ES中的图表数据
  67. func EsAddOrEditMyChartInfoByMyChartId(myChartId int) {
  68. errMsg := make([]string, 0)
  69. defer func() {
  70. if len(errMsg) > 0 {
  71. fmt.Println("新增和修改ES中的图表数据失败:", strings.Join(errMsg, "\n"))
  72. }
  73. }()
  74. var condition string
  75. var pars []interface{}
  76. condition += " AND a.my_chart_id = ? "
  77. pars = append(pars, myChartId)
  78. allList, err := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(condition, pars)
  79. if err != nil {
  80. errMsg = append(errMsg, fmt.Sprintf("EsAddOrEditMyChartInfoByMyChartId Err:%s", err.Error()))
  81. return
  82. }
  83. for _, v := range allList {
  84. //添加es
  85. err = elastic.EsAddOrEditDataInterface(utils.MY_CHART_INDEX_NAME, strconv.Itoa(v.MyChartId), v)
  86. if err != nil {
  87. errMsg = append(errMsg, fmt.Sprintf("myChartId:%d,添加Es失败,err:%s", v.MyChartId, err.Error()))
  88. }
  89. }
  90. return
  91. }
  92. // EsDeleteMyChartInfoByMyChartId 根据我的图库id 删除ES中的图表数据
  93. func EsDeleteMyChartInfoByMyChartId(myChartId int) {
  94. var err error
  95. defer func() {
  96. if err != nil {
  97. fmt.Println("删除ES中的图表数据失败:", err.Error())
  98. }
  99. }()
  100. //添加es
  101. err = elastic.EsDeleteDataV2(utils.MY_CHART_INDEX_NAME, strconv.Itoa(myChartId))
  102. return
  103. }
  104. // EsSearchMyChartInfo 搜索图表信息
  105. func EsSearchMyChartInfo(keyword string, adminId int, noPermissionChartIdList []int, startSize, pageSize int) (list []*data_manage.MyChartList, total int64, err error) {
  106. list, total, err = elastic.SearchMyChartInfoData(utils.MY_CHART_INDEX_NAME, keyword, adminId, noPermissionChartIdList, startSize, pageSize)
  107. return
  108. }
  109. // EsDeleteMyChartInfoByMyChartIds 根据我的图表IDs删除ES中的我的图表
  110. func EsDeleteMyChartInfoByMyChartIds(ids []int) {
  111. if len(ids) == 0 {
  112. return
  113. }
  114. errMsg := make([]string, 0)
  115. defer func() {
  116. if len(errMsg) > 0 {
  117. fmt.Println("EsDeleteMyChartInfoByMyChartIds, 删除ES中的我的图表数据失败:", strings.Join(errMsg, "\n"))
  118. }
  119. }()
  120. for _, v := range ids {
  121. id := strconv.Itoa(v)
  122. if e := elastic.EsDeleteDataV2(utils.MY_CHART_INDEX_NAME, id); e != nil {
  123. errMsg = append(errMsg, fmt.Sprintf("myChartId:%d,删除Es失败,err:%s", v, e.Error()))
  124. }
  125. }
  126. return
  127. }