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" ) // CheckChartPermissionByPermissionIdList // @Description: 检查ETA图库(只包含ETA图库,不包含统计分析等模块)权限 // @author: Roc // @datetime 2024-03-28 16:12:08 // @param chartIsJoinPermission int // @param chartClassifyIsJoinPermission int // @param chartInfoId int // @param chartClassifyId int // @param permissionChartInfoIdList []int // @param permissionChartClassifyIdList []int // @return hasAuth bool func CheckChartPermissionByPermissionIdList(chartIsJoinPermission, chartClassifyIsJoinPermission, chartInfoId, chartClassifyId int, permissionChartInfoIdList, permissionChartClassifyIdList []int) (hasAuth bool) { // 判断 分类是否纳入权限管控 if chartClassifyIsJoinPermission == 1 { // 不属于已授权的分类,那么就无权限 if !utils.InArrayByInt(permissionChartClassifyIdList, chartClassifyId) { return false } } // 判断 指标是否纳入权限管控 if chartIsJoinPermission == 1 { // 不属于已授权的指标,那么就无权限 if !utils.InArrayByInt(permissionChartInfoIdList, chartInfoId) { return false } } hasAuth = true return } // CheckChartClassifyPermissionByPermissionIdList // @Description: 检查EDB分类权限 // @author: Roc // @datetime 2024-03-29 14:35:19 // @param chartClassifyIsJoinPermission int // @param chartClassifyId int // @param permissionChartClassifyIdList []int // @return hasAuth bool func CheckChartClassifyPermissionByPermissionIdList(chartClassifyIsJoinPermission, chartClassifyId int, permissionChartClassifyIdList []int) (hasAuth bool) { // 判断 分类是否纳入权限管控 if chartClassifyIsJoinPermission == 1 { // 不属于已授权的分类,那么就无权限 if !utils.InArrayByInt(permissionChartClassifyIdList, chartClassifyId) { return } } hasAuth = true return } // GetUserChartAndClassifyPermissionList // @Description: 根据用户获取已经授权指标ID列表和指标分类ID列表 // @author: Roc // @datetime 2024-03-28 17:20:36 // @param userId int // @param chartInfoId int 如果传递了chartInfoId,则只返回该chartInfoId的权限列表(其实也就是为了判断是否存在该指标权限了,目的是为了少获取数据) // @param classifyId int classifyId,则只返回该classifyId的权限列表(其实也就是为了判断是否存在该指标分类权限了,目的是为了少获取数据) // @return chartIdList []int // @return classifyIdList []int // @return err error func GetUserChartAndClassifyPermissionList(userId, chartInfoId, classifyId int) (chartIdList, classifyIdList []int, err error) { // 获取有权限的指标ID列表 chartIdList, err = data_manage_permission.GetPermissionChartIdList(userId, chartInfoId) if err != nil { fmt.Println("获取授权指标列表失败, err:", err) return } // 获取有权限的指标分类ID列表 classifyIdList, err = data_manage_permission.GetPermissionChartClassifyIdList(userId, classifyId) if err != nil { fmt.Println("获取授权指标分类列表失败, err:", err) return } return } // GetUserChartClassifyPermissionList // @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 GetUserChartClassifyPermissionList(userId, classifyId int) (classifyIdList []int, err error) { // 获取有权限的指标分类ID列表 classifyIdList, err = data_manage_permission.GetPermissionChartClassifyIdList(userId, classifyId) if err != nil { fmt.Println("获取授权指标分类列表失败, err:", err) return } return } // CheckChartPermissionByChartInfoId // @Description: 根据指标id和指标分类id,检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递) // @author: Roc // @datetime 2024-03-29 13:28:06 // @param chartInfoId int // @param chartClassifyId int // @param chartIsJoinPermission int // @param userId int // @return hasAuth bool // @return err error func CheckChartPermissionByChartInfoId(chartInfoId, chartClassifyId, chartIsJoinPermission, userId int) (hasAuth bool, err error) { currClassify, err := data_manage.GetChartClassifyById(chartClassifyId) if err != nil { return } if currClassify != nil { return CheckChartPermission(chartIsJoinPermission, currClassify.IsJoinPermission, userId, chartInfoId, chartClassifyId) } return } // CheckChartPermission // @Description: 检查EDB指标(含预测指标)权限(方法内部自己获取所有的指标和指标分类权限,不用额外传递) // @author: Roc // @datetime 2024-03-28 16:12:08 // @param chartIsJoinPermission int // @param chartClassifyIsJoinPermission int // @param chartInfoId int // @param chartClassifyId int // @return hasAuth bool func CheckChartPermission(chartIsJoinPermission, chartClassifyIsJoinPermission, userId, chartInfoId, chartClassifyId int) (hasAuth bool, err error) { chartIdList, classifyIdList, err := GetUserChartAndClassifyPermissionList(userId, chartInfoId, chartClassifyId) if err != nil { fmt.Println("GetUserChartAndClassifyPermissionList err:", err) return } hasAuth = CheckChartPermissionByPermissionIdList(chartIsJoinPermission, chartClassifyIsJoinPermission, chartInfoId, chartClassifyId, chartIdList, classifyIdList) return }