public_chart.go 5.6 KB

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