123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- 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" `
- }
- // CheckEdbPermissionByPermissionIdList
- // @Description: 检查EDB指标(含预测指标)权限
- // @author: Roc
- // @datetime 2024-03-28 16:12:08
- // @param edbIsJoinPermission int
- // @param edbClassifyIsJoinPermission int
- // @param edbInfoId int
- // @param edbClassifyId int
- // @param permissionEdbInfoIdList []int
- // @param permissionEdbClassifyIdList []int
- // @return hasAuth bool
- func CheckEdbPermissionByPermissionIdList(edbIsJoinPermission, edbClassifyIsJoinPermission, edbInfoId, edbClassifyId int, permissionEdbInfoIdList, permissionEdbClassifyIdList []int) (hasAuth bool) {
- //hasAuth = true
- // 判断 分类是否纳入权限管控
- if edbClassifyIsJoinPermission == 1 {
- // 不属于已授权的分类,那么就无权限
- if !utils.InArrayByInt(permissionEdbClassifyIdList, edbClassifyId) {
- return false
- }
- }
- // 判断 指标是否纳入权限管控
- if edbIsJoinPermission == 1 {
- // 不属于已授权的指标,那么就无权限
- if !utils.InArrayByInt(permissionEdbInfoIdList, edbInfoId) {
- return false
- }
- }
- hasAuth = true
- return
- }
- // CheckEdbClassifyPermissionByPermissionIdList
- // @Description: 检查EDB分类权限
- // @author: Roc
- // @datetime 2024-03-29 14:35:19
- // @param edbClassifyIsJoinPermission int
- // @param edbClassifyId int
- // @param permissionEdbClassifyIdList []int
- // @return hasAuth bool
- func CheckEdbClassifyPermissionByPermissionIdList(edbClassifyIsJoinPermission, edbClassifyId int, permissionEdbClassifyIdList []int) (hasAuth bool) {
- // 判断 分类是否纳入权限管控
- if edbClassifyIsJoinPermission == 1 {
- // 不属于已授权的分类,那么就无权限
- if !utils.InArrayByInt(permissionEdbClassifyIdList, edbClassifyId) {
- return
- }
- }
- hasAuth = true
- return
- }
- // GetUserEdbAndClassifyPermissionList
- // @Description: 根据用户获取已经授权指标ID列表和指标分类ID列表
- // @author: Roc
- // @datetime 2024-03-28 17:20:36
- // @param userId int
- // @param edbInfoId int 如果传递了edbInfoId,则只返回该edbInfoId的权限列表(其实也就是为了判断是否存在该指标权限了,目的是为了少获取数据)
- // @param classifyId int classifyId,则只返回该classifyId的权限列表(其实也就是为了判断是否存在该指标分类权限了,目的是为了少获取数据)
- // @return edbIdList []int
- // @return classifyIdList []int
- // @return err error
- func GetUserEdbAndClassifyPermissionList(userId, edbInfoId, classifyId int) (edbIdList, classifyIdList []int, err error) {
- // 获取有权限的指标ID列表
- edbIdList, err = data_manage_permission.GetPermissionEdbIdList(userId, edbInfoId)
- if err != nil {
- fmt.Println("获取授权指标列表失败, err:", err)
- return
- }
- // 获取有权限的指标分类ID列表
- classifyIdList, err = data_manage_permission.GetPermissionEdbClassifyIdList(userId, classifyId)
- if err != nil {
- fmt.Println("获取授权指标分类列表失败, err:", err)
- return
- }
- return
- }
- // GetUserEdbClassifyPermissionList
- // @Description: 根据用户获取已经授权指标分类ID列表
- // @author: Roc
- // @datetime 2024-03-28 17:20:36
- // @param userId int
- // @param classifyId int classifyId,则只返回该classifyId的权限列表(其实也就是为了判断是否存在该指标分类权限了,目的是为了少获取数据)
- // @return classifyIdList []int
- // @return err error
- func GetUserEdbClassifyPermissionList(userId, classifyId int) (classifyIdList []int, err error) {
- // 获取有权限的指标分类ID列表
- classifyIdList, err = data_manage_permission.GetPermissionEdbClassifyIdList(userId, classifyId)
- if err != nil {
- fmt.Println("获取授权指标分类列表失败, err:", err)
- return
- }
- return
- }
- // CheckEdbPermissionByEdbInfoId
- // @Description: 根据指标id和指标分类id,检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递)
- // @author: Roc
- // @datetime 2024-03-29 13:28:06
- // @param edbInfoId int
- // @param edbClassifyId int
- // @param edbIsJoinPermission int
- // @param userId int
- // @return hasAuth bool
- // @return err error
- 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
- }
- // CheckEdbPermission
- // @Description: 检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递)
- // @author: Roc
- // @datetime 2024-03-28 16:12:08
- // @param edbIsJoinPermission int
- // @param edbClassifyIsJoinPermission int
- // @param edbInfoId int
- // @param edbClassifyId int
- // @return hasAuth bool
- 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
- }
- // GetUserAllEdbAndClassifyNoPermissionList
- // @Description: 根据用户获取已经未授权的指标ID列表和指标分类ID列表
- // @param userId
- // @param edbInfoType
- // @param edbType
- // @return edbIdList
- // @return classifyIdList
- // @return err
- func GetUserAllEdbAndClassifyNoPermissionList(userId, edbInfoType, edbType int) (edbIdList, classifyIdList []int, err error) {
- // TODO 这块需要调整掉,只获取数据查看的
- edbIdList = make([]int, 0)
- classifyIdList = make([]int, 0)
- // 获取所有无权限指标id列表
- {
- isJoinPermissionEdbIdList, tmpErr := data_manage.GetIsJoinPermissionEdbInfoIdList(edbInfoType, edbType)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 获取有权限的指标ID列表
- 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)
- }
- }
- }
- // 获取所有无权限指标分类id列表
- {
- 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
- }
- // 获取有权限的指标分类ID列表
- 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
- }
- // GetUserAllEdbAndClassifyNoPermissionListV2
- // @Description: 根据用户获取已经未授权的指标ID列表和指标分类ID列表(仅有数据查看(基础的普通指标)的指标了)
- // @param userId
- // @return edbIdList
- // @return classifyIdList
- // @return err
- func GetUserAllEdbAndClassifyNoPermissionListV2(userId int) (edbIdList, classifyIdList []int, err error) {
- edbIdList = make([]int, 0)
- classifyIdList = make([]int, 0)
- // 获取所有无权限指标id列表
- {
- isJoinPermissionEdbIdList, tmpErr := data_manage.GetIsJoinPermissionEdbInfoIdList(utils.EDB_INFO_TYPE, utils.EdbTypeBase)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 获取有权限的指标ID列表
- 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)
- }
- }
- }
- // 获取所有无权限指标分类id列表
- {
- classifyType := 0
- isJoinPermissionEdbClassifyIdList, tmpErr := data_manage.GetIsJoinPermissionEdbClassifyIdList(classifyType)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 获取有权限的指标分类ID列表
- 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
- }
|