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 }