123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package data_manage_permission
- import (
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/models/data_manage/data_manage_permission"
- "eta_gn/eta_api/utils"
- "fmt"
- )
- type EdbClassifyPermission struct {
- ClassifyId int `description:"分类id"`
- IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
- EdbInfoId int `orm:"column(edb_info_id);pk" gorm:"primaryKey" `
- }
- func CheckEdbPermissionByPermissionIdList(edbIsJoinPermission, edbClassifyIsJoinPermission, edbInfoId, edbClassifyId int, permissionEdbInfoIdList, permissionEdbClassifyIdList []int) (hasAuth bool) {
- if edbClassifyIsJoinPermission == 1 {
- if !utils.InArrayByInt(permissionEdbClassifyIdList, edbClassifyId) {
- return false
- }
- }
- if edbIsJoinPermission == 1 {
- if !utils.InArrayByInt(permissionEdbInfoIdList, edbInfoId) {
- return false
- }
- }
- hasAuth = true
- return
- }
- func CheckEdbClassifyPermissionByPermissionIdList(edbClassifyIsJoinPermission, edbClassifyId int, permissionEdbClassifyIdList []int) (hasAuth bool) {
- if edbClassifyIsJoinPermission == 1 {
- if !utils.InArrayByInt(permissionEdbClassifyIdList, edbClassifyId) {
- return
- }
- }
- hasAuth = true
- return
- }
- func GetUserEdbAndClassifyPermissionList(userId, edbInfoId, classifyId int) (edbIdList, classifyIdList []int, err error) {
- edbIdList, err = data_manage_permission.GetPermissionEdbIdList(userId, edbInfoId)
- if err != nil {
- fmt.Println("获取授权指标列表失败, err:", err)
- return
- }
- classifyIdList, err = data_manage_permission.GetPermissionEdbClassifyIdList(userId, classifyId)
- if err != nil {
- fmt.Println("获取授权指标分类列表失败, err:", err)
- return
- }
- return
- }
- func GetUserEdbClassifyPermissionList(userId, classifyId int) (classifyIdList []int, err error) {
- classifyIdList, err = data_manage_permission.GetPermissionEdbClassifyIdList(userId, classifyId)
- if err != nil {
- fmt.Println("获取授权指标分类列表失败, err:", err)
- return
- }
- return
- }
- func CheckEdbPermissionByEdbInfoId(edbInfoId, edbClassifyId, edbIsJoinPermission, userId int) (hasAuth bool, err error) {
- currClassify, err := data_manage.GetEdbClassifyById(edbClassifyId)
- if err != nil {
- return
- }
- if currClassify != nil {
- return CheckEdbPermission(edbIsJoinPermission, currClassify.IsJoinPermission, userId, edbInfoId, edbClassifyId)
- }
- return
- }
- func CheckEdbPermission(edbIsJoinPermission, edbClassifyIsJoinPermission, userId, edbInfoId, edbClassifyId int) (hasAuth bool, err error) {
- edbIdList, classifyIdList, err := GetUserEdbAndClassifyPermissionList(userId, edbInfoId, edbClassifyId)
- if err != nil {
- fmt.Println("GetUserEdbAndClassifyPermissionList err:", err)
- return
- }
- hasAuth = CheckEdbPermissionByPermissionIdList(edbIsJoinPermission, edbClassifyIsJoinPermission, edbInfoId, edbClassifyId, edbIdList, classifyIdList)
- return
- }
- func GetUserAllEdbAndClassifyNoPermissionList(userId, edbInfoType, edbType int) (edbIdList, classifyIdList []int, err error) {
- edbIdList = make([]int, 0)
- classifyIdList = make([]int, 0)
- {
- isJoinPermissionEdbIdList, tmpErr := data_manage.GetIsJoinPermissionEdbInfoIdList(edbInfoType, edbType)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- hasPermissionEdbIdList, tmpErr := data_manage_permission.GetPermissionEdbIdList(userId, 0)
- if tmpErr != nil {
- err = tmpErr
- fmt.Println("获取授权指标列表失败, err:", tmpErr)
- return
- }
- for _, edbId := range isJoinPermissionEdbIdList {
- if !utils.InArrayByInt(hasPermissionEdbIdList, edbId) {
- edbIdList = append(edbIdList, edbId)
- }
- }
- }
- {
- classifyType := -1
- if edbInfoType == utils.EDB_INFO_TYPE {
- if edbType == utils.EdbTypeBase {
- classifyType = 0
- } else if edbType == utils.EdbTypeCalculate {
- classifyType = 2
- }
- } else if edbInfoType == utils.PREDICT_EDB_INFO_TYPE {
- classifyType = 1
- }
- isJoinPermissionEdbClassifyIdList, tmpErr := data_manage.GetIsJoinPermissionEdbClassifyIdList(classifyType)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- hasPermissionClassifyIdList, tmpErr := data_manage_permission.GetPermissionEdbClassifyIdList(userId, 0)
- if tmpErr != nil {
- err = tmpErr
- fmt.Println("获取授权指标分类列表失败, err:", err)
- return
- }
- for _, classifyId := range isJoinPermissionEdbClassifyIdList {
- if !utils.InArrayByInt(hasPermissionClassifyIdList, classifyId) {
- classifyIdList = append(classifyIdList, classifyId)
- }
- }
- }
- return
- }
|