excel.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package data_manage_permission
  2. import (
  3. "eta_gn/eta_api/models/data_manage/data_manage_permission"
  4. "eta_gn/eta_api/models/data_manage/excel"
  5. "eta_gn/eta_api/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. // CheckExcelPermissionByExcelInfoId
  83. // @Description: 根据指标id和指标分类id,检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递)
  84. // @author: Roc
  85. // @datetime 2024-03-29 13:28:06
  86. // @param excelInfoId int
  87. // @param excelClassifyId int
  88. // @param excelIsJoinPermission int
  89. // @param userId int
  90. // @return hasAuth bool
  91. // @return err error
  92. func CheckExcelPermissionByExcelInfoId(excelInfoId, excelClassifyId, excelIsJoinPermission, userId int) (hasAuth bool, err error) {
  93. currClassify, err := excel.GetExcelClassifyById(excelClassifyId)
  94. if err != nil {
  95. return
  96. }
  97. if currClassify != nil {
  98. return CheckExcelPermission(excelIsJoinPermission, currClassify.IsJoinPermission, userId, excelInfoId, excelClassifyId)
  99. }
  100. return
  101. }
  102. // CheckExcelPermission
  103. // @Description: 检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递)
  104. // @author: Roc
  105. // @datetime 2024-03-28 16:12:08
  106. // @param excelIsJoinPermission int
  107. // @param excelClassifyIsJoinPermission int
  108. // @param excelInfoId int
  109. // @param excelClassifyId int
  110. // @return hasAuth bool
  111. func CheckExcelPermission(excelIsJoinPermission, excelClassifyIsJoinPermission, userId, excelInfoId, excelClassifyId int) (hasAuth bool, err error) {
  112. excelIdList, classifyIdList, err := GetUserExcelAndClassifyPermissionList(userId, excelInfoId, excelClassifyId)
  113. if err != nil {
  114. fmt.Println("GetUserExcelAndClassifyPermissionList err:", err)
  115. return
  116. }
  117. hasAuth = CheckExcelPermissionByPermissionIdList(excelIsJoinPermission, excelClassifyIsJoinPermission, excelInfoId, excelClassifyId, excelIdList, classifyIdList)
  118. return
  119. }