edb.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. package data_manage_permission
  2. import (
  3. "eta_gn/eta_api/models/data_manage"
  4. "eta_gn/eta_api/models/data_manage/data_manage_permission"
  5. "eta_gn/eta_api/utils"
  6. "fmt"
  7. )
  8. type EdbClassifyPermission struct {
  9. ClassifyId int `description:"分类id"`
  10. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  11. EdbInfoId int `orm:"column(edb_info_id);pk" gorm:"primaryKey" `
  12. }
  13. // CheckEdbPermissionByPermissionIdList
  14. // @Description: 检查EDB指标(含预测指标)权限
  15. // @author: Roc
  16. // @datetime 2024-03-28 16:12:08
  17. // @param edbIsJoinPermission int
  18. // @param edbClassifyIsJoinPermission int
  19. // @param edbInfoId int
  20. // @param edbClassifyId int
  21. // @param permissionEdbInfoIdList []int
  22. // @param permissionEdbClassifyIdList []int
  23. // @return hasAuth bool
  24. func CheckEdbPermissionByPermissionIdList(edbIsJoinPermission, edbClassifyIsJoinPermission, edbInfoId, edbClassifyId int, permissionEdbInfoIdList, permissionEdbClassifyIdList []int) (hasAuth bool) {
  25. //hasAuth = true
  26. // 判断 分类是否纳入权限管控
  27. if edbClassifyIsJoinPermission == 1 {
  28. // 不属于已授权的分类,那么就无权限
  29. if !utils.InArrayByInt(permissionEdbClassifyIdList, edbClassifyId) {
  30. return false
  31. }
  32. }
  33. // 判断 指标是否纳入权限管控
  34. if edbIsJoinPermission == 1 {
  35. // 不属于已授权的指标,那么就无权限
  36. if !utils.InArrayByInt(permissionEdbInfoIdList, edbInfoId) {
  37. return false
  38. }
  39. }
  40. hasAuth = true
  41. return
  42. }
  43. // CheckEdbClassifyPermissionByPermissionIdList
  44. // @Description: 检查EDB分类权限
  45. // @author: Roc
  46. // @datetime 2024-03-29 14:35:19
  47. // @param edbClassifyIsJoinPermission int
  48. // @param edbClassifyId int
  49. // @param permissionEdbClassifyIdList []int
  50. // @return hasAuth bool
  51. func CheckEdbClassifyPermissionByPermissionIdList(edbClassifyIsJoinPermission, edbClassifyId int, permissionEdbClassifyIdList []int) (hasAuth bool) {
  52. // 判断 分类是否纳入权限管控
  53. if edbClassifyIsJoinPermission == 1 {
  54. // 不属于已授权的分类,那么就无权限
  55. if !utils.InArrayByInt(permissionEdbClassifyIdList, edbClassifyId) {
  56. return
  57. }
  58. }
  59. hasAuth = true
  60. return
  61. }
  62. // GetUserEdbAndClassifyPermissionList
  63. // @Description: 根据用户获取已经授权指标ID列表和指标分类ID列表
  64. // @author: Roc
  65. // @datetime 2024-03-28 17:20:36
  66. // @param userId int
  67. // @param edbInfoId int 如果传递了edbInfoId,则只返回该edbInfoId的权限列表(其实也就是为了判断是否存在该指标权限了,目的是为了少获取数据)
  68. // @param classifyId int classifyId,则只返回该classifyId的权限列表(其实也就是为了判断是否存在该指标分类权限了,目的是为了少获取数据)
  69. // @return edbIdList []int
  70. // @return classifyIdList []int
  71. // @return err error
  72. func GetUserEdbAndClassifyPermissionList(userId, edbInfoId, classifyId int) (edbIdList, classifyIdList []int, err error) {
  73. // 获取有权限的指标ID列表
  74. edbIdList, err = data_manage_permission.GetPermissionEdbIdList(userId, edbInfoId)
  75. if err != nil {
  76. fmt.Println("获取授权指标列表失败, err:", err)
  77. return
  78. }
  79. // 获取有权限的指标分类ID列表
  80. classifyIdList, err = data_manage_permission.GetPermissionEdbClassifyIdList(userId, classifyId)
  81. if err != nil {
  82. fmt.Println("获取授权指标分类列表失败, err:", err)
  83. return
  84. }
  85. return
  86. }
  87. // GetUserEdbClassifyPermissionList
  88. // @Description: 根据用户获取已经授权指标分类ID列表
  89. // @author: Roc
  90. // @datetime 2024-03-28 17:20:36
  91. // @param userId int
  92. // @param classifyId int classifyId,则只返回该classifyId的权限列表(其实也就是为了判断是否存在该指标分类权限了,目的是为了少获取数据)
  93. // @return classifyIdList []int
  94. // @return err error
  95. func GetUserEdbClassifyPermissionList(userId, classifyId int) (classifyIdList []int, err error) {
  96. // 获取有权限的指标分类ID列表
  97. classifyIdList, err = data_manage_permission.GetPermissionEdbClassifyIdList(userId, classifyId)
  98. if err != nil {
  99. fmt.Println("获取授权指标分类列表失败, err:", err)
  100. return
  101. }
  102. return
  103. }
  104. // CheckEdbPermissionByEdbInfoId
  105. // @Description: 根据指标id和指标分类id,检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递)
  106. // @author: Roc
  107. // @datetime 2024-03-29 13:28:06
  108. // @param edbInfoId int
  109. // @param edbClassifyId int
  110. // @param edbIsJoinPermission int
  111. // @param userId int
  112. // @return hasAuth bool
  113. // @return err error
  114. func CheckEdbPermissionByEdbInfoId(edbInfoId, edbClassifyId, edbIsJoinPermission, userId int) (hasAuth bool, err error) {
  115. currClassify, err := data_manage.GetEdbClassifyById(edbClassifyId)
  116. if err != nil {
  117. return
  118. }
  119. if currClassify != nil {
  120. return CheckEdbPermission(edbIsJoinPermission, currClassify.IsJoinPermission, userId, edbInfoId, edbClassifyId)
  121. }
  122. return
  123. }
  124. // CheckEdbPermission
  125. // @Description: 检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递)
  126. // @author: Roc
  127. // @datetime 2024-03-28 16:12:08
  128. // @param edbIsJoinPermission int
  129. // @param edbClassifyIsJoinPermission int
  130. // @param edbInfoId int
  131. // @param edbClassifyId int
  132. // @return hasAuth bool
  133. func CheckEdbPermission(edbIsJoinPermission, edbClassifyIsJoinPermission, userId, edbInfoId, edbClassifyId int) (hasAuth bool, err error) {
  134. edbIdList, classifyIdList, err := GetUserEdbAndClassifyPermissionList(userId, edbInfoId, edbClassifyId)
  135. if err != nil {
  136. fmt.Println("GetUserEdbAndClassifyPermissionList err:", err)
  137. return
  138. }
  139. hasAuth = CheckEdbPermissionByPermissionIdList(edbIsJoinPermission, edbClassifyIsJoinPermission, edbInfoId, edbClassifyId, edbIdList, classifyIdList)
  140. return
  141. }
  142. // GetUserAllEdbAndClassifyNoPermissionList
  143. // @Description: 根据用户获取已经未授权的指标ID列表和指标分类ID列表
  144. // @param userId
  145. // @param edbInfoType
  146. // @param edbType
  147. // @return edbIdList
  148. // @return classifyIdList
  149. // @return err
  150. func GetUserAllEdbAndClassifyNoPermissionList(userId, edbInfoType, edbType int) (edbIdList, classifyIdList []int, err error) {
  151. // TODO 这块需要调整掉,只获取数据查看的
  152. edbIdList = make([]int, 0)
  153. classifyIdList = make([]int, 0)
  154. // 获取所有无权限指标id列表
  155. {
  156. isJoinPermissionEdbIdList, tmpErr := data_manage.GetIsJoinPermissionEdbInfoIdList(edbInfoType, edbType)
  157. if tmpErr != nil {
  158. err = tmpErr
  159. return
  160. }
  161. // 获取有权限的指标ID列表
  162. hasPermissionEdbIdList, tmpErr := data_manage_permission.GetPermissionEdbIdList(userId, 0)
  163. if tmpErr != nil {
  164. err = tmpErr
  165. fmt.Println("获取授权指标列表失败, err:", tmpErr)
  166. return
  167. }
  168. for _, edbId := range isJoinPermissionEdbIdList {
  169. if !utils.InArrayByInt(hasPermissionEdbIdList, edbId) {
  170. edbIdList = append(edbIdList, edbId)
  171. }
  172. }
  173. }
  174. // 获取所有无权限指标分类id列表
  175. {
  176. classifyType := -1
  177. if edbInfoType == utils.EDB_INFO_TYPE {
  178. // 普通指标
  179. if edbType == utils.EdbTypeBase {
  180. classifyType = 0
  181. } else if edbType == utils.EdbTypeCalculate {
  182. classifyType = 2
  183. }
  184. } else if edbInfoType == utils.PREDICT_EDB_INFO_TYPE {
  185. // 预测指标
  186. classifyType = 1
  187. }
  188. isJoinPermissionEdbClassifyIdList, tmpErr := data_manage.GetIsJoinPermissionEdbClassifyIdList(classifyType)
  189. if tmpErr != nil {
  190. err = tmpErr
  191. return
  192. }
  193. // 获取有权限的指标分类ID列表
  194. hasPermissionClassifyIdList, tmpErr := data_manage_permission.GetPermissionEdbClassifyIdList(userId, 0)
  195. if tmpErr != nil {
  196. err = tmpErr
  197. fmt.Println("获取授权指标分类列表失败, err:", err)
  198. return
  199. }
  200. for _, classifyId := range isJoinPermissionEdbClassifyIdList {
  201. if !utils.InArrayByInt(hasPermissionClassifyIdList, classifyId) {
  202. classifyIdList = append(classifyIdList, classifyId)
  203. }
  204. }
  205. }
  206. return
  207. }
  208. // GetUserAllEdbAndClassifyNoPermissionListV2
  209. // @Description: 根据用户获取已经未授权的指标ID列表和指标分类ID列表(仅有数据查看(基础的普通指标)的指标了)
  210. // @param userId
  211. // @return edbIdList
  212. // @return classifyIdList
  213. // @return err
  214. func GetUserAllEdbAndClassifyNoPermissionListV2(userId int) (edbIdList, classifyIdList []int, err error) {
  215. edbIdList = make([]int, 0)
  216. classifyIdList = make([]int, 0)
  217. // 获取所有无权限指标id列表
  218. {
  219. isJoinPermissionEdbIdList, tmpErr := data_manage.GetIsJoinPermissionEdbInfoIdList(utils.EDB_INFO_TYPE, utils.EdbTypeBase)
  220. if tmpErr != nil {
  221. err = tmpErr
  222. return
  223. }
  224. // 获取有权限的指标ID列表
  225. hasPermissionEdbIdList, tmpErr := data_manage_permission.GetPermissionEdbIdList(userId, 0)
  226. if tmpErr != nil {
  227. err = tmpErr
  228. fmt.Println("获取授权指标列表失败, err:", tmpErr)
  229. return
  230. }
  231. for _, edbId := range isJoinPermissionEdbIdList {
  232. if !utils.InArrayByInt(hasPermissionEdbIdList, edbId) {
  233. edbIdList = append(edbIdList, edbId)
  234. }
  235. }
  236. }
  237. // 获取所有无权限指标分类id列表
  238. {
  239. classifyType := 0
  240. isJoinPermissionEdbClassifyIdList, tmpErr := data_manage.GetIsJoinPermissionEdbClassifyIdList(classifyType)
  241. if tmpErr != nil {
  242. err = tmpErr
  243. return
  244. }
  245. // 获取有权限的指标分类ID列表
  246. hasPermissionClassifyIdList, tmpErr := data_manage_permission.GetPermissionEdbClassifyIdList(userId, 0)
  247. if tmpErr != nil {
  248. err = tmpErr
  249. fmt.Println("获取授权指标分类列表失败, err:", err)
  250. return
  251. }
  252. for _, classifyId := range isJoinPermissionEdbClassifyIdList {
  253. if !utils.InArrayByInt(hasPermissionClassifyIdList, classifyId) {
  254. classifyIdList = append(classifyIdList, classifyId)
  255. }
  256. }
  257. }
  258. return
  259. }