edb.go 4.4 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. type EdbClassifyPermission struct {
  9. ClassifyId int `description:"分类id"`
  10. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  11. EdbInfoId int `orm:"column(edb_info_id);pk" gorm:"primaryKey" `
  12. }
  13. func CheckEdbPermissionByPermissionIdList(edbIsJoinPermission, edbClassifyIsJoinPermission, edbInfoId, edbClassifyId int, permissionEdbInfoIdList, permissionEdbClassifyIdList []int) (hasAuth bool) {
  14. if edbClassifyIsJoinPermission == 1 {
  15. if !utils.InArrayByInt(permissionEdbClassifyIdList, edbClassifyId) {
  16. return false
  17. }
  18. }
  19. if edbIsJoinPermission == 1 {
  20. if !utils.InArrayByInt(permissionEdbInfoIdList, edbInfoId) {
  21. return false
  22. }
  23. }
  24. hasAuth = true
  25. return
  26. }
  27. func CheckEdbClassifyPermissionByPermissionIdList(edbClassifyIsJoinPermission, edbClassifyId int, permissionEdbClassifyIdList []int) (hasAuth bool) {
  28. if edbClassifyIsJoinPermission == 1 {
  29. if !utils.InArrayByInt(permissionEdbClassifyIdList, edbClassifyId) {
  30. return
  31. }
  32. }
  33. hasAuth = true
  34. return
  35. }
  36. func GetUserEdbAndClassifyPermissionList(userId, edbInfoId, classifyId int) (edbIdList, classifyIdList []int, err error) {
  37. edbIdList, err = data_manage_permission.GetPermissionEdbIdList(userId, edbInfoId)
  38. if err != nil {
  39. fmt.Println("获取授权指标列表失败, err:", err)
  40. return
  41. }
  42. classifyIdList, err = data_manage_permission.GetPermissionEdbClassifyIdList(userId, classifyId)
  43. if err != nil {
  44. fmt.Println("获取授权指标分类列表失败, err:", err)
  45. return
  46. }
  47. return
  48. }
  49. func GetUserEdbClassifyPermissionList(userId, classifyId int) (classifyIdList []int, err error) {
  50. classifyIdList, err = data_manage_permission.GetPermissionEdbClassifyIdList(userId, classifyId)
  51. if err != nil {
  52. fmt.Println("获取授权指标分类列表失败, err:", err)
  53. return
  54. }
  55. return
  56. }
  57. func CheckEdbPermissionByEdbInfoId(edbInfoId, edbClassifyId, edbIsJoinPermission, userId int) (hasAuth bool, err error) {
  58. currClassify, err := data_manage.GetEdbClassifyById(edbClassifyId)
  59. if err != nil {
  60. return
  61. }
  62. if currClassify != nil {
  63. return CheckEdbPermission(edbIsJoinPermission, currClassify.IsJoinPermission, userId, edbInfoId, edbClassifyId)
  64. }
  65. return
  66. }
  67. func CheckEdbPermission(edbIsJoinPermission, edbClassifyIsJoinPermission, userId, edbInfoId, edbClassifyId int) (hasAuth bool, err error) {
  68. edbIdList, classifyIdList, err := GetUserEdbAndClassifyPermissionList(userId, edbInfoId, edbClassifyId)
  69. if err != nil {
  70. fmt.Println("GetUserEdbAndClassifyPermissionList err:", err)
  71. return
  72. }
  73. hasAuth = CheckEdbPermissionByPermissionIdList(edbIsJoinPermission, edbClassifyIsJoinPermission, edbInfoId, edbClassifyId, edbIdList, classifyIdList)
  74. return
  75. }
  76. func GetUserAllEdbAndClassifyNoPermissionList(userId, edbInfoType, edbType int) (edbIdList, classifyIdList []int, err error) {
  77. edbIdList = make([]int, 0)
  78. classifyIdList = make([]int, 0)
  79. {
  80. isJoinPermissionEdbIdList, tmpErr := data_manage.GetIsJoinPermissionEdbInfoIdList(edbInfoType, edbType)
  81. if tmpErr != nil {
  82. err = tmpErr
  83. return
  84. }
  85. hasPermissionEdbIdList, tmpErr := data_manage_permission.GetPermissionEdbIdList(userId, 0)
  86. if tmpErr != nil {
  87. err = tmpErr
  88. fmt.Println("获取授权指标列表失败, err:", tmpErr)
  89. return
  90. }
  91. for _, edbId := range isJoinPermissionEdbIdList {
  92. if !utils.InArrayByInt(hasPermissionEdbIdList, edbId) {
  93. edbIdList = append(edbIdList, edbId)
  94. }
  95. }
  96. }
  97. {
  98. classifyType := -1
  99. if edbInfoType == utils.EDB_INFO_TYPE {
  100. if edbType == utils.EdbTypeBase {
  101. classifyType = 0
  102. } else if edbType == utils.EdbTypeCalculate {
  103. classifyType = 2
  104. }
  105. } else if edbInfoType == utils.PREDICT_EDB_INFO_TYPE {
  106. classifyType = 1
  107. }
  108. isJoinPermissionEdbClassifyIdList, tmpErr := data_manage.GetIsJoinPermissionEdbClassifyIdList(classifyType)
  109. if tmpErr != nil {
  110. err = tmpErr
  111. return
  112. }
  113. hasPermissionClassifyIdList, tmpErr := data_manage_permission.GetPermissionEdbClassifyIdList(userId, 0)
  114. if tmpErr != nil {
  115. err = tmpErr
  116. fmt.Println("获取授权指标分类列表失败, err:", err)
  117. return
  118. }
  119. for _, classifyId := range isJoinPermissionEdbClassifyIdList {
  120. if !utils.InArrayByInt(hasPermissionClassifyIdList, classifyId) {
  121. classifyIdList = append(classifyIdList, classifyId)
  122. }
  123. }
  124. }
  125. return
  126. }