edb.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package data_manage_permission
  2. import (
  3. "eta/eta_mobile/models/data_manage"
  4. "eta/eta_mobile/models/data_manage/data_manage_permission"
  5. "eta/eta_mobile/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"`
  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. }