123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- package data_manage_permission
- import (
- "eta/eta_api/models/data_manage/data_manage_permission"
- "eta/eta_api/models/data_manage/excel"
- "eta/eta_api/utils"
- "fmt"
- )
- // CheckExcelPermissionByPermissionIdList
- // @Description: 检查ETA图库(只包含ETA图库,不包含统计分析等模块)权限
- // @author: Roc
- // @datetime 2024-03-28 16:12:08
- // @param excelIsJoinPermission int
- // @param excelClassifyIsJoinPermission int
- // @param excelInfoId int
- // @param excelClassifyId int
- // @param permissionExcelInfoIdList []int
- // @param permissionExcelClassifyIdList []int
- // @return hasAuth bool
- func CheckExcelPermissionByPermissionIdList(excelIsJoinPermission, excelClassifyIsJoinPermission, excelInfoId, excelClassifyId int, permissionExcelInfoIdList, permissionExcelClassifyIdList []int) (hasAuth bool) {
- //hasAuth = true
- // 判断 分类是否纳入权限管控
- if excelClassifyIsJoinPermission == 1 {
- // 不属于已授权的分类,那么就无权限
- if !utils.InArrayByInt(permissionExcelClassifyIdList, excelClassifyId) {
- return false
- }
- }
- // 判断 指标是否纳入权限管控
- if excelIsJoinPermission == 1 {
- // 不属于已授权的指标,那么就无权限
- if !utils.InArrayByInt(permissionExcelInfoIdList, excelInfoId) {
- return false
- }
- }
- hasAuth = true
- return
- }
- // CheckExcelClassifyPermissionByPermissionIdList
- // @Description: 检查EDB分类权限
- // @author: Roc
- // @datetime 2024-03-29 14:35:19
- // @param excelClassifyIsJoinPermission int
- // @param excelClassifyId int
- // @param permissionExcelClassifyIdList []int
- // @return hasAuth bool
- func CheckExcelClassifyPermissionByPermissionIdList(excelClassifyIsJoinPermission, excelClassifyId int, permissionExcelClassifyIdList []int) (hasAuth bool) {
- // 判断 分类是否纳入权限管控
- if excelClassifyIsJoinPermission == 1 {
- // 不属于已授权的分类,那么就无权限
- if !utils.InArrayByInt(permissionExcelClassifyIdList, excelClassifyId) {
- return
- }
- }
- hasAuth = true
- return
- }
- // GetUserExcelAndClassifyPermissionList
- // @Description: 根据用户获取已经授权指标ID列表和指标分类ID列表
- // @author: Roc
- // @datetime 2024-03-28 17:20:36
- // @param userId int
- // @param excelInfoId int 如果传递了excelInfoId,则只返回该excelInfoId的权限列表(其实也就是为了判断是否存在该指标权限了,目的是为了少获取数据)
- // @param classifyId int classifyId,则只返回该classifyId的权限列表(其实也就是为了判断是否存在该指标分类权限了,目的是为了少获取数据)
- // @return excelIdList []int
- // @return classifyIdList []int
- // @return err error
- func GetUserExcelAndClassifyPermissionList(userId, excelInfoId, classifyId int) (excelIdList, classifyIdList []int, err error) {
- // 获取有权限的指标ID列表
- excelIdList, err = data_manage_permission.GetPermissionExcelIdList(userId, excelInfoId)
- if err != nil {
- fmt.Println("获取授权指标列表失败, err:", err)
- return
- }
- // 获取有权限的指标分类ID列表
- classifyIdList, err = data_manage_permission.GetPermissionExcelClassifyIdList(userId, classifyId)
- if err != nil {
- fmt.Println("获取授权指标分类列表失败, err:", err)
- return
- }
- return
- }
- // GetUserExcelClassifyPermissionList
- // @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 GetUserExcelClassifyPermissionList(userId, classifyId int) (classifyIdList []int, err error) {
- // 获取有权限的指标分类ID列表
- classifyIdList, err = data_manage_permission.GetPermissionExcelClassifyIdList(userId, classifyId)
- if err != nil {
- fmt.Println("获取授权指标分类列表失败, err:", err)
- return
- }
- return
- }
- // CheckExcelPermissionByExcelInfoId
- // @Description: 根据指标id和指标分类id,检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递)
- // @author: Roc
- // @datetime 2024-03-29 13:28:06
- // @param excelInfoId int
- // @param excelClassifyId int
- // @param excelIsJoinPermission int
- // @param userId int
- // @return hasAuth bool
- // @return err error
- func CheckExcelPermissionByExcelInfoId(excelInfoId, excelClassifyId, excelIsJoinPermission, userId int) (hasAuth bool, err error) {
- currClassify, err := excel.GetExcelClassifyById(excelClassifyId)
- if err != nil {
- return
- }
- if currClassify != nil {
- return CheckExcelPermission(excelIsJoinPermission, currClassify.IsJoinPermission, userId, excelInfoId, excelClassifyId)
- }
- return
- }
- // CheckExcelPermission
- // @Description: 检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递)
- // @author: Roc
- // @datetime 2024-03-28 16:12:08
- // @param excelIsJoinPermission int
- // @param excelClassifyIsJoinPermission int
- // @param excelInfoId int
- // @param excelClassifyId int
- // @return hasAuth bool
- func CheckExcelPermission(excelIsJoinPermission, excelClassifyIsJoinPermission, userId, excelInfoId, excelClassifyId int) (hasAuth bool, err error) {
- excelIdList, classifyIdList, err := GetUserExcelAndClassifyPermissionList(userId, excelInfoId, excelClassifyId)
- if err != nil {
- fmt.Println("GetUserExcelAndClassifyPermissionList err:", err)
- return
- }
- hasAuth = CheckExcelPermissionByPermissionIdList(excelIsJoinPermission, excelClassifyIsJoinPermission, excelInfoId, excelClassifyId, excelIdList, classifyIdList)
- return
- }
- func CheckBalanceExcelPermissionByExcelInfoId(excelInfo *excel.ExcelInfo, excelIsJoinPermission, userId int) (hasAuth bool, err error) {
- // 查询父级ID
- if excelInfo.Source != utils.BALANCE_TABLE {
- return
- }
- parentId := excelInfo.ParentId
- if excelInfo.BalanceType == 1 { //静态表关联的动态表的权限
- parentId = excelInfo.RelExcelInfoId
- }
- parentExcelInfo, err := excel.GetExcelInfoById(parentId)
- if err != nil {
- err = fmt.Errorf("查询表格信息出错 err: %v", err)
- return
- }
- excelClassifyId := parentExcelInfo.ExcelClassifyId
- excelInfoId := parentExcelInfo.ExcelInfoId
- currClassify, err := excel.GetExcelClassifyById(excelClassifyId)
- if err != nil {
- return
- }
- if currClassify != nil {
- return CheckExcelPermission(excelIsJoinPermission, currClassify.IsJoinPermission, userId, excelInfoId, excelClassifyId)
- }
- return
- }
|