public_edb.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. // DeleteEdbPublicCheck
  12. // @Description: 移除指标公共检测
  13. // @author: Roc
  14. // @datetime 2024-12-05 10:23:01
  15. // @param classifyId int
  16. // @param edbInfoId 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 DeleteEdbPublicCheck(edbInfoId int, sysUser *system.Admin) (deleteStatus int, tipsMsg string, tableList []*data_manage.ExcelBaseInfo, err error, errMsg string) {
  24. // TODO 操作权限校验
  25. {
  26. }
  27. // 移除指标
  28. if edbInfoId > 0 {
  29. // TODO 需要判断该指标是否被其他人给收藏了
  30. //if edbInfo == 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. // GetSearchPar
  44. // @Description: 获取查询参数
  45. // @author: Roc
  46. // @datetime 2024-12-05 14:13:25
  47. // @param req request.SearchPublicEdbReq
  48. // @return keyword string
  49. // @return searchEdbPublicList []int
  50. // @return sourceList []int
  51. // @return classifyIdList []int
  52. // @return publicClassifyIdList []int
  53. // @return edbTypeList []int
  54. // @return edbInfoType int
  55. // @return edbAuth int
  56. // @return sortMap map[string]string
  57. func GetSearchPar(req request.SearchPublicEdbReq) (keyword string, searchEdbPublicList, sourceList, classifyIdList, publicClassifyIdList, edbTypeList []int, edbInfoType, edbAuth int, sortMap map[string]string) {
  58. keyword = req.Keyword
  59. keyword = strings.TrimSpace(keyword) //移除字符串首尾空格
  60. //指标来源
  61. sourceList = req.SourceList
  62. // 选择的分类
  63. classifyIdList = req.ClassifyIdList
  64. publicClassifyIdList = req.PublicClassifyIdList
  65. // 指标公开状态:1:未公开,2:已提交;3:已公开。可多选,默认是未公开
  66. edbPublicList := req.EdbPublicList
  67. if len(edbPublicList) <= 0 {
  68. edbPublicList = []int{1}
  69. }
  70. edbInfoType = 0 // 普通指标
  71. edbTypeList = []int{utils.EdbTypeCalculate} // 普通指标中的计算指标
  72. edbAuth = 1 // 选择范围是:只有我的指标
  73. searchEdbPublicList = make([]int, 0) // 0:全部,1:未公开,2:已提交;3:已公开
  74. if len(edbPublicList) > 0 && !utils.InArrayByInt(edbPublicList, 0) {
  75. // 不含全部
  76. for _, v := range edbPublicList {
  77. switch v {
  78. case 1: // 未公开
  79. searchEdbPublicList = append(searchEdbPublicList, utils.DataPublicDefault)
  80. case 2: // 已提交
  81. searchEdbPublicList = append(searchEdbPublicList, utils.DataPublicCommit, utils.DataPublicReject)
  82. case 3: // 已公开
  83. searchEdbPublicList = append(searchEdbPublicList, utils.DataPublicSuccess)
  84. }
  85. }
  86. } else {
  87. searchEdbPublicList = []int{0, 1, 2, 3}
  88. }
  89. sortMap = make(map[string]string)
  90. // 如果没有搜索关键词,则默认根据指标编码倒序排序
  91. if keyword == `` {
  92. sortMap["EdbInfoId"] = `desc`
  93. }
  94. return
  95. }
  96. // GetAllEdbInfoListBySearchPublicEdbReq
  97. // @Description: 获取所有的指标列表
  98. // @author: Roc
  99. // @datetime 2024-12-04 15:43:14
  100. // @param req request.SearchPublicEdbReq
  101. // @param userId int
  102. // @return edbInfoIdList []*data_manage.EdbInfoList
  103. // @return err error
  104. func GetAllEdbInfoListBySearchPublicEdbReq(req request.SearchPublicEdbReq, userId int) (edbInfoList []*data_manage.EdbInfoList, err error) {
  105. // 获取查询参数
  106. keyword, searchEdbPublicList, sourceList, edbClassifyIdList, publicClassifyIdList, edbTypeList, edbInfoType, edbAuth, sortMap := GetSearchPar(req)
  107. _, edbInfoList, err = getAllEdbInfoDataByPublic(keyword, 1, searchEdbPublicList, sourceList, edbClassifyIdList, publicClassifyIdList, edbTypeList, edbInfoType, edbAuth, userId, sortMap)
  108. if err != nil {
  109. return
  110. }
  111. return
  112. }
  113. // getAllEdbInfoDataByShared
  114. // @Description: 获取所有的指标列表(设置公开的时候)
  115. // @author: Roc
  116. // @datetime 2024-12-04 15:27:53
  117. // @param keyword string
  118. // @param currPage int
  119. // @param edbShare int
  120. // @param sourceList []int
  121. // @param classifyIdList []int
  122. // @param edbTypeList []int
  123. // @param edbInfoType int
  124. // @param edbAuth int
  125. // @param sysUserId int
  126. // @param sortMap map[string]string
  127. // @return total int64
  128. // @return list []*data_manage.EdbInfoList
  129. // @return err error
  130. func getAllEdbInfoDataByPublic(keyword string, currPage int, searchEdbPublicList, sourceList, classifyIdList, publicClassifyIdList, edbTypeList []int, edbInfoType, edbAuth, sysUserId int, sortMap map[string]string) (total int64, list []*data_manage.EdbInfoList, 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.SearchEdbInfoDataByPublic(keyword, startSize, pageSize, searchEdbPublicList, sourceList, classifyIdList, publicClassifyIdList, edbTypeList, edbInfoType, edbAuth, sysUserId, sortMap)
  139. if err != nil {
  140. return
  141. }
  142. page := paging.GetPaging(currPage, pageSize, int(total))
  143. if !page.IsEnd {
  144. _, nextList, tmpErr := getAllEdbInfoDataByPublic(keyword, page.NextIndex, searchEdbPublicList, sourceList, classifyIdList, publicClassifyIdList, edbTypeList, edbInfoType, edbAuth, sysUserId, sortMap)
  145. if tmpErr != nil {
  146. err = tmpErr
  147. return
  148. }
  149. list = append(list, nextList...)
  150. }
  151. return
  152. }