|
@@ -2,6 +2,8 @@ package data
|
|
|
|
|
|
import (
|
|
|
"eta/eta_api/models/data_manage"
|
|
|
+ "eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
)
|
|
|
|
|
|
// SetEdbChartPermission
|
|
@@ -203,3 +205,84 @@ func SetEdbChartClassifyPermission(source, subSource int, userList []int, classi
|
|
|
|
|
|
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) {
|
|
|
+ edbIdList, err = data_manage.GetPermissionEdbIdList(userId, edbInfoId)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取授权指标列表失败, err:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ classifyIdList, err = data_manage.GetPermissionEdbClassifyIdList(userId, classifyId)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取授权指标分类列表失败, err:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|
|
|
+}
|
|
|
+
|
|
|
+// 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
|
|
|
+}
|