public_chart.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package data
  2. import (
  3. "eta_gn/eta_api/models/data_manage"
  4. "eta_gn/eta_api/models/data_manage/request"
  5. "eta_gn/eta_api/models/system"
  6. "eta_gn/eta_api/services/elastic"
  7. "eta_gn/eta_api/utils"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "strings"
  10. )
  11. // DeleteChartPublicCheck
  12. // @Description: 移除指标公共检测
  13. // @author: Roc
  14. // @datetime 2024-12-05 10:23:01
  15. // @param classifyId int
  16. // @param chartInfoId int
  17. // @param sysUser *system.Admin
  18. // @return deleteStatus int
  19. // @return tipsMsg string
  20. // @return tableList []*data_manage.ExcelBaseInfo
  21. // @return err error
  22. // @return errMsg string
  23. func DeleteChartPublicCheck(chartInfoId int, sysUser *system.Admin) (deleteStatus int, tipsMsg string, tableList []*data_manage.ExcelBaseInfo, err error, errMsg string) {
  24. // TODO 操作权限校验
  25. {
  26. }
  27. // 移除指标
  28. if chartInfoId > 0 {
  29. // TODO 需要判断该指标是否被其他人给收藏了
  30. //if chartInfo == nil {
  31. // errMsg = "指标已删除,请刷新页面"
  32. // return
  33. //}
  34. //if chartCount > 0 {
  35. // deleteStatus = 3
  36. // tipsMsg = "当前指标已用作画图,不可删除"
  37. // return
  38. //}
  39. return
  40. }
  41. return
  42. }
  43. // GetChartSearchPar
  44. // @Description: 获取查询参数
  45. // @author: Roc
  46. // @datetime 2024-12-05 14:13:25
  47. // @param req request.SearchPublicChartReq
  48. // @return keyword string
  49. // @return searchChartPublicList []int
  50. // @return sourceList []int
  51. // @return classifyIdList []int
  52. // @return publicClassifyIdList []int
  53. // @return chartTypeList []int
  54. // @return chartInfoType int
  55. // @return chartAuth int
  56. // @return sortMap map[string]string
  57. func GetChartSearchPar(req request.SearchPublicChartReq) (keyword string, searchChartPublicList, sourceList, chartTypeList, classifyIdList, publicClassifyIdList []int, chartAuth int, sortMap map[string]string) {
  58. keyword = req.Keyword
  59. keyword = strings.TrimSpace(keyword) //移除字符串首尾空格
  60. //指标来源
  61. sourceList = []int{utils.CHART_TYPE_CURVE}
  62. chartTypeList = req.ChartTypeList
  63. // 选择的分类
  64. classifyIdList = req.ClassifyIdList
  65. // 公开分类
  66. publicClassifyIdList = req.PublicClassifyIdList
  67. // 指标公开状态:1:未公开,2:已提交;3:已公开。可多选,默认是未公开
  68. chartPublicList := req.ChartPublicList
  69. if len(chartPublicList) <= 0 {
  70. chartPublicList = []int{1}
  71. }
  72. chartAuth = 1 // 选择范围是:只有我的指标
  73. searchChartPublicList = make([]int, 0) // 0:全部,1:未公开,2:已提交;3:已公开
  74. if len(chartPublicList) > 0 && !utils.InArrayByInt(chartPublicList, 0) {
  75. // 不含全部
  76. for _, v := range chartPublicList {
  77. switch v {
  78. case 1: // 未公开
  79. searchChartPublicList = append(searchChartPublicList, utils.DataPublicDefault)
  80. case 2: // 已提交
  81. searchChartPublicList = append(searchChartPublicList, utils.DataPublicCommit, utils.DataPublicReject)
  82. case 3: // 已公开
  83. searchChartPublicList = append(searchChartPublicList, utils.DataPublicSuccess)
  84. }
  85. }
  86. } else {
  87. searchChartPublicList = []int{0, 1, 2, 3}
  88. }
  89. sortMap = make(map[string]string)
  90. // 如果没有搜索关键词,则默认根据指标编码倒序排序
  91. if keyword == `` {
  92. sortMap["ChartInfoId"] = `desc`
  93. }
  94. return
  95. }
  96. // GetAllChartInfoListBySearchPublicChartReq
  97. // @Description: 获取所有的指标列表
  98. // @author: Roc
  99. // @datetime 2024-12-04 15:43:14
  100. // @param req request.SearchPublicChartReq
  101. // @param userId int
  102. // @return chartInfoIdList []*data_manage.ChartInfoList
  103. // @return err error
  104. func GetAllChartInfoListBySearchPublicChartReq(req request.SearchPublicChartReq, userId int) (chartInfoList []*data_manage.ChartInfoView, err error) {
  105. // 获取查询参数
  106. keyword, searchChartPublicList, sourceList, chartTypeList, chartClassifyIdList, publicClassifyIdList, chartAuth, sortMap := GetChartSearchPar(req)
  107. _, chartInfoList, err = getAllChartInfoDataByPublic(keyword, 1, searchChartPublicList, sourceList, chartTypeList, chartClassifyIdList, publicClassifyIdList, chartAuth, userId, sortMap)
  108. if err != nil {
  109. return
  110. }
  111. return
  112. }
  113. // getAllChartInfoDataByShared
  114. // @Description: 获取所有的指标列表(设置公开的时候)
  115. // @author: Roc
  116. // @datetime 2024-12-04 15:27:53
  117. // @param keyword string
  118. // @param currPage int
  119. // @param chartShare int
  120. // @param sourceList []int
  121. // @param classifyIdList []int
  122. // @param chartTypeList []int
  123. // @param chartInfoType int
  124. // @param chartAuth int
  125. // @param sysUserId int
  126. // @param sortMap map[string]string
  127. // @return total int64
  128. // @return list []*data_manage.ChartInfoList
  129. // @return err error
  130. func getAllChartInfoDataByPublic(keyword string, currPage int, searchChartPublicList, sourceList, chartTypeList, classifyIdList, publicClassifyIdList []int, chartAuth, sysUserId int, sortMap map[string]string) (total int64, list []*data_manage.ChartInfoView, err error) {
  131. // 每页获取数据的数量
  132. pageSize := 5000
  133. var startSize int
  134. if currPage <= 0 {
  135. currPage = 1
  136. }
  137. startSize = paging.StartIndex(currPage, pageSize)
  138. total, list, err = elastic.SearchChartInfoDataByPublic(keyword, startSize, pageSize, searchChartPublicList, sourceList, chartTypeList, classifyIdList, publicClassifyIdList, chartAuth, sysUserId, sortMap)
  139. if err != nil {
  140. return
  141. }
  142. page := paging.GetPaging(currPage, pageSize, int(total))
  143. if !page.IsEnd {
  144. _, nextList, tmpErr := getAllChartInfoDataByPublic(keyword, page.NextIndex, searchChartPublicList, sourceList, chartTypeList, classifyIdList, publicClassifyIdList, chartAuth, sysUserId, sortMap)
  145. if tmpErr != nil {
  146. err = tmpErr
  147. return
  148. }
  149. list = append(list, nextList...)
  150. }
  151. return
  152. }