chart.go 5.6 KB

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