chart.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. // CheckChartPermissionByPermissionIdList
  9. // @Description: 检查ETA图库(只包含ETA图库,不包含统计分析等模块)权限
  10. // @author: Roc
  11. // @datetime 2024-03-28 16:12:08
  12. // @param chartIsJoinPermission int
  13. // @param chartClassifyIsJoinPermission int
  14. // @param chartInfoId int
  15. // @param chartClassifyId int
  16. // @param permissionChartInfoIdList []int
  17. // @param permissionChartClassifyIdList []int
  18. // @return hasAuth bool
  19. func CheckChartPermissionByPermissionIdList(chartIsJoinPermission, chartClassifyIsJoinPermission, chartInfoId, chartClassifyId int, permissionChartInfoIdList, permissionChartClassifyIdList []int) (hasAuth bool) {
  20. //hasAuth = true
  21. // 判断 分类是否纳入权限管控
  22. if chartClassifyIsJoinPermission == 1 {
  23. // 不属于已授权的分类,那么就无权限
  24. if !utils.InArrayByInt(permissionChartClassifyIdList, chartClassifyId) {
  25. return false
  26. }
  27. }
  28. // 判断 指标是否纳入权限管控
  29. if chartIsJoinPermission == 1 {
  30. // 不属于已授权的指标,那么就无权限
  31. if !utils.InArrayByInt(permissionChartInfoIdList, chartInfoId) {
  32. return false
  33. }
  34. }
  35. hasAuth = true
  36. return
  37. }
  38. // CheckChartClassifyPermissionByPermissionIdList
  39. // @Description: 检查EDB分类权限
  40. // @author: Roc
  41. // @datetime 2024-03-29 14:35:19
  42. // @param chartClassifyIsJoinPermission int
  43. // @param chartClassifyId int
  44. // @param permissionChartClassifyIdList []int
  45. // @return hasAuth bool
  46. func CheckChartClassifyPermissionByPermissionIdList(chartClassifyIsJoinPermission, chartClassifyId int, permissionChartClassifyIdList []int) (hasAuth bool) {
  47. // 判断 分类是否纳入权限管控
  48. if chartClassifyIsJoinPermission == 1 {
  49. // 不属于已授权的分类,那么就无权限
  50. if !utils.InArrayByInt(permissionChartClassifyIdList, chartClassifyId) {
  51. return
  52. }
  53. }
  54. hasAuth = true
  55. return
  56. }
  57. // GetUserChartAndClassifyPermissionList
  58. // @Description: 根据用户获取已经授权指标ID列表和指标分类ID列表
  59. // @author: Roc
  60. // @datetime 2024-03-28 17:20:36
  61. // @param userId int
  62. // @param chartInfoId int 如果传递了chartInfoId,则只返回该chartInfoId的权限列表(其实也就是为了判断是否存在该指标权限了,目的是为了少获取数据)
  63. // @param classifyId int classifyId,则只返回该classifyId的权限列表(其实也就是为了判断是否存在该指标分类权限了,目的是为了少获取数据)
  64. // @return chartIdList []int
  65. // @return classifyIdList []int
  66. // @return err error
  67. func GetUserChartAndClassifyPermissionList(userId, chartInfoId, classifyId int) (chartIdList, classifyIdList []int, err error) {
  68. // 获取有权限的指标ID列表
  69. chartIdList, err = data_manage_permission.GetPermissionChartIdList(userId, chartInfoId)
  70. if err != nil {
  71. fmt.Println("获取授权指标列表失败, err:", err)
  72. return
  73. }
  74. // 获取有权限的指标分类ID列表
  75. classifyIdList, err = data_manage_permission.GetPermissionChartClassifyIdList(userId, classifyId)
  76. if err != nil {
  77. fmt.Println("获取授权指标分类列表失败, err:", err)
  78. return
  79. }
  80. return
  81. }
  82. // GetUserChartClassifyPermissionList
  83. // @Description: 根据用户获取已经授权指标分类ID列表
  84. // @author: Roc
  85. // @datetime 2024-03-28 17:20:36
  86. // @param userId int
  87. // @param classifyId int classifyId,则只返回该classifyId的权限列表(其实也就是为了判断是否存在该指标分类权限了,目的是为了少获取数据)
  88. // @return classifyIdList []int
  89. // @return err error
  90. func GetUserChartClassifyPermissionList(userId, classifyId int) (classifyIdList []int, err error) {
  91. // 获取有权限的指标分类ID列表
  92. classifyIdList, err = data_manage_permission.GetPermissionChartClassifyIdList(userId, classifyId)
  93. if err != nil {
  94. fmt.Println("获取授权指标分类列表失败, err:", err)
  95. return
  96. }
  97. return
  98. }
  99. // CheckChartPermissionByChartInfoId
  100. // @Description: 根据指标id和指标分类id,检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递)
  101. // @author: Roc
  102. // @datetime 2024-03-29 13:28:06
  103. // @param chartInfoId int
  104. // @param chartClassifyId int
  105. // @param chartIsJoinPermission int
  106. // @param userId int
  107. // @return hasAuth bool
  108. // @return err error
  109. func CheckChartPermissionByChartInfoId(chartInfoId, chartClassifyId, chartIsJoinPermission, userId int) (hasAuth bool, err error) {
  110. currClassify, err := data_manage.GetChartClassifyById(chartClassifyId)
  111. if err != nil {
  112. return
  113. }
  114. if currClassify != nil {
  115. return CheckChartPermission(chartIsJoinPermission, currClassify.IsJoinPermission, userId, chartInfoId, chartClassifyId)
  116. }
  117. return
  118. }
  119. // CheckChartPermission
  120. // @Description: 检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递)
  121. // @author: Roc
  122. // @datetime 2024-03-28 16:12:08
  123. // @param chartIsJoinPermission int
  124. // @param chartClassifyIsJoinPermission int
  125. // @param chartInfoId int
  126. // @param chartClassifyId int
  127. // @return hasAuth bool
  128. func CheckChartPermission(chartIsJoinPermission, chartClassifyIsJoinPermission, userId, chartInfoId, chartClassifyId int) (hasAuth bool, err error) {
  129. chartIdList, classifyIdList, err := GetUserChartAndClassifyPermissionList(userId, chartInfoId, chartClassifyId)
  130. if err != nil {
  131. fmt.Println("GetUserChartAndClassifyPermissionList err:", err)
  132. return
  133. }
  134. hasAuth = CheckChartPermissionByPermissionIdList(chartIsJoinPermission, chartClassifyIsJoinPermission, chartInfoId, chartClassifyId, chartIdList, classifyIdList)
  135. return
  136. }