excel.go 5.6 KB

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