123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728 |
- package data_manage_permission
- import (
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/data_manage/data_manage_permission"
- "eta/eta_api/models/data_manage/excel"
- "eta/eta_api/models/system"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/uuid"
- "strings"
- )
- // SetEdbChartPermission
- // @Description: 单独给资产(指标、图表、ETA表格)设置权限
- // @author: Roc
- // @datetime 2024-03-27 10:52:32
- // @param source int
- // @param subSource int
- // @param userId int
- // @param authUserList []int
- // @param isSelectAll bool
- // @param dataId []string
- // @param noDataId []string
- // @param keyword string
- // @param classify string
- // @param opUserId int 操作人
- // @return err error
- // @return errMsg string
- func SetEdbChartPermission(source, subSource, userId int, authUserList []int, isSelectAll bool, dataIdList, noDataIdList []string, keyword, classify string, opUserId int) (err error, errMsg string) {
- // 如果勾选全部数据,那么
- if isSelectAll {
- // 找出不要的指标ID列表
- noDataIdMap := make(map[string]string, 0)
- for _, v := range noDataIdList {
- noDataIdMap[v] = v
- }
- // 需要转义的指标/图表ID列表
- dataIdList = make([]string, 0)
- // 获取所有指标/图表
- list, _, tmpErr := GetMoveEdbChartList(source, subSource, userId, keyword, classify, 0, 100000)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range list {
- if _, ok := noDataIdMap[v.DataId]; !ok {
- dataIdList = append(dataIdList, v.DataId)
- }
- }
- }
- // dataIdList 做3000条限制
- if len(dataIdList) > 3000 {
- err = fmt.Errorf("数据量条数不要超过3000,请分批设置")
- errMsg = err.Error()
- return
- }
- if len(authUserList) <= 0 {
- // 说明是取消权限管控
- }
- uniqueCode := uuid.NewUUID().Hex32()
- title := `数据权限变更`
- content := `数据权限`
- dataList := make([]data_manage_permission.DataItem, 0)
- switch source {
- case 3, 4:
- //ETA指标库、ETA预测指标
- if source == 3 {
- content += `(ETA指标库)`
- } else {
- content += `(ETA预测指标)`
- }
- tmpList, tmpErr := data_manage.GetEdbInfoListByEdbInfoId(dataIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- dataIdList = make([]string, 0)
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- dataList = append(dataList, data_manage_permission.DataItem{
- DataId: v.EdbInfoId,
- DataCode: v.EdbCode,
- DataName: v.EdbName,
- })
- dataIdList = append(dataIdList, fmt.Sprint(v.EdbInfoId))
- }
- // 重新设置权限
- edbInfoType := 0
- if source == 4 {
- edbInfoType = 1
- }
- err = data_manage_permission.SetPermissionByEdbIdList(dataIdList, authUserList, edbInfoType)
- }
- case 5:
- //图库
- content += `(ETA图库)`
- tmpList, tmpErr := data_manage.GetChartInfoListByChartIdList(dataIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- dataIdList = make([]string, 0)
- for _, v := range tmpList {
- dataList = append(dataList, data_manage_permission.DataItem{
- DataId: v.ChartInfoId,
- DataCode: fmt.Sprint(v.ChartInfoId),
- DataName: v.ChartName,
- })
- dataIdList = append(dataIdList, fmt.Sprint(v.ChartInfoId))
- }
- // 重新设置权限
- chartSource := utils.CHART_SOURCE_DEFAULT
- err = data_manage_permission.SetPermissionByChartIdList(dataIdList, authUserList, chartSource)
- }
- case 6:
- // ETA表格
- content += `(ETA表格)`
- tmpList := make([]*excel.MyExcelInfoList, 0)
- var tmpErr error
- if subSource == utils.BALANCE_TABLE {
- tmpList, tmpErr = excel.GetNoContentExcelListByExcelInfoIdAndParentId(dataIdList)
- } else {
- tmpList, tmpErr = excel.GetNoContentExcelListByExcelInfoIdList(dataIdList)
- }
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- dataIdList = make([]string, 0)
- for _, v := range tmpList {
- dataList = append(dataList, data_manage_permission.DataItem{
- DataId: v.ExcelInfoId,
- DataCode: fmt.Sprint(v.ExcelInfoId),
- DataName: v.ExcelName,
- })
- dataIdList = append(dataIdList, fmt.Sprint(v.ExcelInfoId))
- }
- // 重新设置权限
- err = data_manage_permission.SetPermissionByExcelIdList(dataIdList, authUserList, subSource)
- }
- default:
- return
- }
- if err != nil {
- return
- }
- var authRecordErr error
- defer func() {
- if authRecordErr != nil {
- utils.FileLog.Error(fmt.Sprintf("记录未设置记录资产权限的记录失败:%s;source:%d;sub_source:%d;数据ID列表:%s;授权人列表:%v", authRecordErr.Error(), source, subSource, strings.Join(dataIdList, ","), authUserList))
- }
- }()
- // 获取所有在用的用户
- cond := ` AND enabled = 1`
- pars := make([]interface{}, 0)
- adminList, authRecordErr := system.GetSysAdminList(cond, pars, []string{}, "")
- if authRecordErr != nil {
- return
- }
- // 如果没有授权人,那么就删除未授权记录
- if len(authUserList) < 0 {
- authRecordErr = data_manage_permission.DeleteRecordBySourceAndDataIdList(source, subSource, dataIdList)
- return
- }
- userIdMap := make(map[int]int)
- for _, tmpUserId := range authUserList {
- userIdMap[tmpUserId] = tmpUserId
- }
- noAuthUserIdList := make([]int, 0)
- for _, v := range adminList {
- if _, ok := userIdMap[v.AdminId]; !ok {
- noAuthUserIdList = append(noAuthUserIdList, v.AdminId)
- }
- }
- content += "已关闭"
- // 添加未授权记录
- authRecordErr = data_manage_permission.AddRecordBySourceAndDataIdList(source, subSource, dataList, noAuthUserIdList, authUserList, uniqueCode, title, content, opUserId)
- return
- }
- // SetDataClassifyIsPermission
- // @Description: 设置资产(指标、图表、ETA表格)分类是否涉密
- // @author: Roc
- // @datetime 2024-03-27 10:52:32
- // @param source int
- // @param subSource int
- // @param dataId []string
- // @param opUserId int 操作人id
- // @return err error
- // @return errMsg string
- func SetDataClassifyIsPermission(source, subSource int, classifyIdList []int, opUserId int) (err error, errMsg string) {
- uniqueCode := uuid.NewUUID().Hex32()
- title := `数据权限变更`
- content := `分类权限`
- classifyDataList := make([]data_manage_permission.ClassifyDataItem, 0)
- switch source {
- case 3, 4:
- //ETA指标库、ETA预测指标
- if source == 3 {
- content += `(ETA指标库)`
- } else {
- content += `(ETA预测指标)`
- }
- {
- // 分类信息
- classifyInfoList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range classifyInfoList {
- classifyDataList = append(classifyDataList, data_manage_permission.ClassifyDataItem{
- ClassifyId: v.ClassifyId,
- ClassifyName: v.ClassifyName,
- })
- }
- }
- // 重新设置权限
- classifyType := 0
- if source == 4 {
- classifyType = 1
- }
- err = data_manage_permission.SetIsPermissionEdbChartByEdbClassifyIdList(classifyIdList, classifyType)
- case 5:
- //图库
- content += `(ETA图库)`
- {
- // 分类信息
- classifyInfoList, tmpErr := data_manage.GetChartClassifyByIdList(classifyIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range classifyInfoList {
- classifyDataList = append(classifyDataList, data_manage_permission.ClassifyDataItem{
- ClassifyId: v.ChartClassifyId,
- ClassifyName: v.ChartClassifyName,
- })
- }
- }
- // 重新设置权限
- chartClassifySource := utils.CHART_SOURCE_DEFAULT
- err = data_manage_permission.SetIsPermissionByChartClassifyIdList(classifyIdList, chartClassifySource)
- case 6:
- // ETA表格
- content += `(ETA表格)`
- {
- // 分类信息
- classifyInfoList, tmpErr := excel.GetExcelClassifyByIdList(classifyIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range classifyInfoList {
- classifyDataList = append(classifyDataList, data_manage_permission.ClassifyDataItem{
- ClassifyId: v.ExcelClassifyId,
- ClassifyName: v.ExcelClassifyName,
- })
- }
- }
- // 重新设置权限
- err = data_manage_permission.SetIsPermissionByExcelClassifyIdList(classifyIdList, subSource)
- default:
- return
- }
- if err != nil {
- return
- }
- var authRecordErr error
- defer func() {
- if authRecordErr != nil {
- utils.FileLog.Error(fmt.Sprintf("记录未设置记录资产权限的记录失败:%s;source:%d;sub_source:%d;分类ID列表:%v", authRecordErr.Error(), source, subSource, classifyIdList))
- }
- }()
- // 如果没有涉密的分类,那么就移除所有删除未授权记录
- if len(classifyIdList) <= 0 {
- authRecordErr = data_manage_permission.DeleteClassifyNoAuthRecordBySourceAndClassifyIdList(source, subSource)
- return
- }
- // 获取所有在用的用户
- cond := ` AND enabled = 1`
- pars := make([]interface{}, 0)
- adminList, authRecordErr := system.GetSysAdminList(cond, pars, []string{}, "")
- if authRecordErr != nil {
- return
- }
- noAuthUserIdList := make([]int, 0)
- for _, v := range adminList {
- noAuthUserIdList = append(noAuthUserIdList, v.AdminId)
- }
- content += "已关闭"
- // 添加未授权记录
- authRecordErr = data_manage_permission.AddClassifyNoAuthRecordBySourceAndClassifyIdList(source, subSource, classifyDataList, noAuthUserIdList, uniqueCode, title, content, opUserId)
- return
- }
- // SetEdbChartClassifyPermission
- // @Description: 给用户设置涉密分类的权限
- // @author: Roc
- // @datetime 2024-03-28 14:22:30
- // @param source int
- // @param subSource int
- // @param authUserList []int
- // @param classifyIdList []int
- // @param opUserId int 操作人id
- // @return err error
- // @return errMsg string
- func SetEdbChartClassifyPermission(source, subSource int, authUserList []int, classifyIdList []int, opUserId int) (err error, errMsg string) {
- uniqueCode := uuid.NewUUID().Hex32()
- title := `数据权限变更`
- content := `分类权限`
- secretClassifyInfoList := make([]data_manage_permission.ClassifyDataItem, 0)
- if len(classifyIdList) <= 0 {
- // 说明是取消权限管控
- }
- // 先获取所有的涉密分类,然后根据用户去判断那些分类给权限了
- switch source {
- case 3, 4: //ETA指标库、ETA预测指标
- //ETA指标库、ETA预测指标
- if source == 3 {
- content += `(ETA指标库)`
- } else {
- content += `(ETA预测指标)`
- }
- classifyType := 0
- if source == 4 {
- classifyType = 1
- }
- {
- // 获取已经设置加密的分类信息
- classifyInfoList, tmpErr := data_manage.GetEdbClassifyByClassifyTypeAndIsJoinPermission(classifyType, 1)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range classifyInfoList {
- secretClassifyInfoList = append(secretClassifyInfoList, data_manage_permission.ClassifyDataItem{
- ClassifyId: v.ClassifyId,
- ClassifyName: v.ClassifyName,
- })
- }
- }
- // 重新设置权限
- err = data_manage_permission.SetPermissionByEdbClassifyIdList(classifyIdList, authUserList, classifyType)
- case 5:
- subSource = utils.CHART_SOURCE_DEFAULT
- //图库
- content += `(ETA图库)`
- {
- // 分类信息
- classifyInfoList, tmpErr := data_manage.GetChartClassifyBySourceAndIsJoinPermission(subSource, 1)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range classifyInfoList {
- secretClassifyInfoList = append(secretClassifyInfoList, data_manage_permission.ClassifyDataItem{
- ClassifyId: v.ChartClassifyId,
- ClassifyName: v.ChartClassifyName,
- })
- }
- }
- // 重新设置权限
- err = data_manage_permission.SetPermissionByChartClassifyIdList(classifyIdList, authUserList, subSource)
- case 6:
- // ETA表格
- content += `(ETA表格)`
- {
- // 分类信息
- classifyInfoList, tmpErr := excel.GetExcelClassifyBySourceAndIsJoinPermission(subSource, 1)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range classifyInfoList {
- secretClassifyInfoList = append(secretClassifyInfoList, data_manage_permission.ClassifyDataItem{
- ClassifyId: v.ExcelClassifyId,
- ClassifyName: v.ExcelClassifyName,
- })
- }
- }
- err = data_manage_permission.SetPermissionByExcelClassifyIdList(classifyIdList, authUserList, subSource)
- default:
- return
- }
- if err != nil {
- return
- }
- var authRecordErr error
- defer func() {
- if authRecordErr != nil {
- utils.FileLog.Error(fmt.Sprintf("记录未设置记录资产权限的记录失败:%s;source:%d;sub_source:%d;分类ID列表:%v", authRecordErr.Error(), source, subSource, classifyIdList))
- }
- }()
- content += "已关闭"
- authClassifyIdMap := make(map[int]int)
- for _, v := range classifyIdList {
- authClassifyIdMap[v] = v
- }
- noAuthClassifyMap := make(map[int]data_manage_permission.ClassifyDataItem)
- for _, classifyInfo := range secretClassifyInfoList {
- if _, ok := authClassifyIdMap[classifyInfo.ClassifyId]; !ok {
- noAuthClassifyMap[classifyInfo.ClassifyId] = classifyInfo
- }
- }
- // 添加未授权记录
- authRecordErr = data_manage_permission.AddClassifyNoAuthRecordBySourceAndUserIdList(source, subSource, noAuthClassifyMap, authUserList, uniqueCode, title, content, opUserId)
- return
- }
- // GetEdbChartClassifyIdListPermissionByUserId
- // @Description: 根据用户id获取已经配置的分类id列表
- // @author: Roc
- // @datetime 2024-03-29 16:26:10
- // @param source int
- // @param subSource int
- // @param userId int
- // @return idList []int
- // @return err error
- func GetEdbChartClassifyIdListPermissionByUserId(source, subSource, userId int) (idList []int, err error) {
- switch source {
- case 3, 4: //ETA指标库、ETA预测指标
- //tmpList, tmpErr := data_manage.GetEdbInfoListGroupByUserId(dataId)
- //if tmpErr != nil {
- // err = tmpErr
- // return
- //}
- //if len(tmpList) > 0 {
- //}
- // 重新设置权限
- classifyType := 0
- if source == 4 {
- classifyType = 1
- }
- idList, err = data_manage_permission.GetPermissionEdbClassifyIdListByUserId(userId, classifyType)
- case 5:
- //图库
- chartClassifySource := utils.CHART_SOURCE_DEFAULT
- idList, err = data_manage_permission.GetPermissionChartClassifyIdListByUserId(userId, chartClassifySource)
- case 6:
- // ETA表格
- idList, err = data_manage_permission.GetPermissionExcelClassifyIdListByUserId(userId, subSource)
- default:
- return
- }
- return
- }
- // GetUserIdListPermissionByDataId
- // @Description: 根据资产(指标、图表、表格)id获取已经配置的用户id
- // @author: Roc
- // @datetime 2024-03-29 16:26:10
- // @param source int
- // @param subSource int
- // @param dataId int
- // @return idList []int
- // @return err error
- func GetUserIdListPermissionByDataId(source, subSource, dataId int) (idList []int, err error) {
- switch source {
- case 3, 4:
- // ETA指标库、ETA预测指标
- edbInfoType := 0
- if source == 4 {
- edbInfoType = 1
- }
- idList, err = data_manage_permission.GetPermissionUserIdListByEdbId(dataId, edbInfoType)
- case 5:
- // 图库
- chartClassifySource := utils.CHART_SOURCE_DEFAULT
- idList, err = data_manage_permission.GetPermissionUserIdListByChartId(dataId, chartClassifySource)
- case 6:
- // ETA表格
- idList, err = data_manage_permission.GetPermissionUserIdListByExcelId(dataId, subSource)
- default:
- return
- }
- return
- }
- // GetUserIdListNoPermissionByDataId
- // @Description: 根据资产(指标、图表、表格)id获取没有该资产分类权限的用户id
- // @author: Roc
- // @datetime 2024-03-29 16:26:10
- // @param source int
- // @param subSource int
- // @param dataId int
- // @return idList []int
- // @return err error
- func GetUserIdListNoPermissionByDataId(source, subSource, dataId int) (idList []int, err error) {
- // 已经授权的用户map
- authIdList := make([]int, 0)
- switch source {
- case 3, 4:
- // ETA指标库、ETA预测指标
- edbInfoType := 0
- if source == 4 {
- edbInfoType = 1
- }
- // 获取指标
- edbInfoItem, tmpErr := data_manage.GetEdbInfoById(dataId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 获取分类
- classifyItem, tmpErr := data_manage.GetEdbClassifyById(edbInfoItem.ClassifyId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 判断分类是否涉密,不涉密就直接返回
- if classifyItem.IsJoinPermission == 0 {
- return
- }
- // 获取已经配置分类权限的用户ID列表
- authIdList, err = data_manage_permission.GetPermissionUserIdListByEdbClassifyId(dataId, edbInfoType)
- case 5:
- // 图库
- // 获取图表
- chartInfoItem, tmpErr := data_manage.GetChartInfoById(dataId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 获取分类
- classifyItem, tmpErr := data_manage.GetChartClassifyById(chartInfoItem.ChartClassifyId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 判断分类是否涉密,不涉密就直接返回
- if classifyItem.IsJoinPermission == 0 {
- return
- }
- chartClassifySource := utils.CHART_SOURCE_DEFAULT
- authIdList, err = data_manage_permission.GetPermissionUserIdListByChartClassifyId(dataId, chartClassifySource)
- case 6:
- // ETA表格
- // 获取图表
- excelInfoItem, tmpErr := excel.GetNoContentExcelInfoByExcelId(dataId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 获取分类
- classifyItem, tmpErr := excel.GetExcelClassifyById(excelInfoItem.ExcelClassifyId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 判断分类是否涉密,不涉密就直接返回
- if classifyItem.IsJoinPermission == 0 {
- return
- }
- authIdList, err = data_manage_permission.GetPermissionUserIdListByExcelClassifyId(dataId, subSource)
- default:
- return
- }
- // 已经授权的用户map
- authUserIdMap := make(map[int]int)
- for _, v := range authIdList {
- authUserIdMap[v] = v
- }
- // 获取所有在用的用户
- cond := ` AND enabled = 1`
- pars := make([]interface{}, 0)
- adminList, authRecordErr := system.GetSysAdminList(cond, pars, []string{}, "")
- if authRecordErr != nil {
- return
- }
- for _, v := range adminList {
- if _, ok := authUserIdMap[v.AdminId]; !ok {
- idList = append(idList, v.AdminId)
- }
- }
- return
- }
- // InheritParentClassify
- // @Description: 继承父级分类的涉密权限
- // @author: Roc
- // @datetime 2024-04-07 21:09:16
- // @param source int
- // @param subSource int
- // @param classifyId int
- // @param parentClassifyId int
- // @param classifyName string
- func InheritParentClassify(source, subSource, classifyId, parentClassifyId int, classifyName string) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(fmt.Sprintf("继承父级分类失败:%s;source:%d;sub_source:%d;分类ID列表:%v", err.Error(), source, subSource, classifyId))
- utils.FileLog.Error(fmt.Sprintf("继承父级分类失败:%s;source:%d;sub_source:%d;分类ID列表:%v", err.Error(), source, subSource, classifyId))
- }
- }()
- // 一级分类不用继承
- if parentClassifyId <= 0 {
- return
- }
- uniqueCode := uuid.NewUUID().Hex32()
- switch source {
- case 3, 4:
- //ETA指标库、ETA预测指标
- // 分类信息
- parentClassifyInfo, tmpErr := data_manage.GetEdbClassifyById(parentClassifyId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 没有标记涉密那么就忽略
- if parentClassifyInfo.IsJoinPermission == 0 {
- return
- }
- // 重新设置权限
- classifyType := 0
- if source == 4 {
- classifyType = 1
- }
- err = data_manage_permission.InheritParentClassifyByEdbClassifyId(source, classifyType, classifyId, parentClassifyId, classifyName, uniqueCode)
- case 5:
- //图库
- // 分类信息
- parentClassifyInfo, tmpErr := data_manage.GetChartClassifyById(parentClassifyId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 没有标记涉密那么就忽略
- if parentClassifyInfo.IsJoinPermission == 0 {
- return
- }
- // 重新设置权限
- chartClassifySource := utils.CHART_SOURCE_DEFAULT
- err = data_manage_permission.InheritParentClassifyByChartClassifyId(source, chartClassifySource, classifyId, parentClassifyId, classifyName, uniqueCode)
- case 6:
- // ETA表格
- // 分类信息
- parentClassifyInfo, tmpErr := excel.GetExcelClassifyById(parentClassifyId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 没有标记涉密那么就忽略
- if parentClassifyInfo.IsJoinPermission == 0 {
- return
- }
- // 重新设置权限
- err = data_manage_permission.InheritParentClassifyByExcelClassifyId(source, subSource, classifyId, parentClassifyId, classifyName, uniqueCode)
- default:
- return
- }
- }
|