Browse Source

fix:未授权记录表分表

Roc 11 months ago
parent
commit
cfb43f03e1

+ 518 - 11
models/data_manage/data_manage_permission/chart.go

@@ -409,21 +409,20 @@ func InheritParentClassifyByChartClassifyId(dataSource, chartSource, classifyId,
 	// 添加未授权记录
 	{
 		// 获取父级未授权的用户记录
-		var parentRecordItems []*DataPermissionClassifyNoAuthRecord
+		var parentRecordItems []*ChartInfoClassifyPermissionNoAuthRecord
 		sql = `SELECT * FROM data_permission_classify_no_auth_record WHERE classify_id = ? AND source = ? AND sub_source = ? ORDER BY data_permission_classify_no_auth_record_id desc LIMIT ?,? `
 		_, err = o.Raw(sql, parentClassifyId, dataSource, chartSource).QueryRows(&parentRecordItems)
 
-		addNoAuthRecordItems := make([]*DataPermissionClassifyNoAuthRecord, 0)
+		addNoAuthRecordItems := make([]*ChartInfoClassifyPermissionNoAuthRecord, 0)
 		for _, v := range parentRecordItems {
-			addNoAuthRecordItems = append(addNoAuthRecordItems, &DataPermissionClassifyNoAuthRecord{
-				DataPermissionClassifyNoAuthRecordId: 0,
-				Source:                               v.Source,
-				SubSource:                            v.SubSource,
-				OpUniqueCode:                         uniqueCode,
-				ClassifyId:                           fmt.Sprint(classifyId),
-				ClassifyName:                         classifyName,
-				SysUserId:                            v.SysUserId,
-				CreateTime:                           time.Now(),
+			addNoAuthRecordItems = append(addNoAuthRecordItems, &ChartInfoClassifyPermissionNoAuthRecord{
+				ChartInfoClassifyPermissionNoAuthRecordId: 0,
+				Source:       v.Source,
+				OpUniqueCode: uniqueCode,
+				ClassifyId:   fmt.Sprint(classifyId),
+				ClassifyName: classifyName,
+				SysUserId:    v.SysUserId,
+				CreateTime:   time.Now(),
 			})
 		}
 
@@ -470,3 +469,511 @@ func InheritParentClassifyByChartClassifyId(dataSource, chartSource, classifyId,
 
 	return
 }
+
+// ChartInfoPermissionNoAuthRecord
+// @Description: 图表数据权限未授权记录表
+type ChartInfoPermissionNoAuthRecord struct {
+	ChartInfoPermissionNoAuthRecordId int64     `json:"chart_info_permission_no_auth_record_id"  orm:"column(chart_info_permission_no_auth_record_id);pk"` // 资产数据操作记录id
+	OpUniqueCode                      string    `json:"op_unique_code"`                                                                                    // 操作的唯一编码,主要是记录统一操作的日志
+	Source                            int32     `json:"source"`                                                                                            // 1:ETA图库;2:商品价格曲线;3:相关性图
+	ChartInfoId                       int32     `json:"chart_info_id"`                                                                                     // 指标id
+	ChartName                         string    `json:"chart_name"`                                                                                        // 图表名称
+	SysUserId                         int32     `json:"sys_user_id"`                                                                                       // 系统用户id
+	CreateTime                        time.Time `json:"create_time"`                                                                                       // 创建时间
+}
+
+// AddChartInfoPermissionNoAuthRecordBySourceAndDataIdList
+// @Description: 添加未授权用户记录
+// @author: Roc
+// @datetime 2024-04-07 15:25:49
+// @param source int
+// @param chartSource int
+// @param dataList []DataItem
+// @param noAuthUserIdList []int 未授权用户
+// @param authUserIdList []int 已授权用户
+// @param uniqueCode
+// @param content string
+// @param opUserId int
+// @return err error
+func AddChartInfoPermissionNoAuthRecordBySourceAndDataIdList(source, chartSource int, dataList []DataItem, noAuthUserIdList, authUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+	num := len(dataList)
+	if num <= 0 {
+		return
+	}
+	dataIdList := make([]int, 0)
+	for _, v := range dataList {
+		dataIdList = append(dataIdList, v.DataId)
+	}
+	userNum := len(noAuthUserIdList)
+	if userNum <= 0 {
+		return
+	}
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+
+	// 根据指标获取已经存在的未授权记录
+	var existList []*ChartInfoPermissionNoAuthRecord
+	sql := `SELECT * FROM chart_info_permission_no_auth_record WHERE  source = ? AND chart_info_id in (` + utils.GetOrmInReplace(num) + `)`
+	_, err = o.Raw(sql, chartSource, dataIdList).QueryRows(&existList)
+	if err != nil {
+		return
+	}
+
+	// 已经标记了的数据
+	existMap := make(map[int32]map[string]*ChartInfoPermissionNoAuthRecord)
+	for _, v := range existList {
+		tmpUserExistMap, ok := existMap[v.SysUserId]
+		if !ok {
+			tmpUserExistMap = make(map[string]*ChartInfoPermissionNoAuthRecord)
+		}
+
+		key := fmt.Sprint(v.Source, "_", v.ChartInfoId)
+		tmpUserExistMap[key] = v
+		existMap[v.SysUserId] = tmpUserExistMap
+	}
+
+	addMessageList := make([]*DataPermissionMessage, 0)
+	addRecordList := make([]*ChartInfoPermissionNoAuthRecord, 0)
+	for _, userId := range noAuthUserIdList {
+		isAdd := false
+
+		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+
+		for _, dataItem := range dataList {
+			// 判断是否已经存在,已经存在就过滤
+			if userExistOk {
+				key := fmt.Sprint(chartSource, "_", dataItem.DataId)
+				_, ok := tmpUserExistMap[key]
+				if ok {
+					continue
+				}
+			}
+
+			isAdd = true
+			addRecordList = append(addRecordList, &ChartInfoPermissionNoAuthRecord{
+				ChartInfoPermissionNoAuthRecordId: 0,
+				OpUniqueCode:                      uniqueCode,
+				Source:                            int32(chartSource),
+				ChartInfoId:                       int32(dataItem.DataId),
+				ChartName:                         dataItem.DataName,
+				SysUserId:                         int32(userId),
+				CreateTime:                        time.Now(),
+			})
+		}
+
+		// 有记录的话,需要添加消息
+		if isAdd {
+			addMessageList = append(addMessageList, &DataPermissionMessage{
+				DataPermissionMessageId: 0,
+				SendUserId:              int32(opUserId),
+				ReceiveUserId:           int32(userId),
+				Content:                 content,
+				Remark:                  content,
+				OpType:                  3,
+				Source:                  int32(source),
+				SubSource:               int32(chartSource),
+				OpUniqueCode:            uniqueCode,
+				IsRead:                  0,
+				CreateTime:              time.Now(),
+				ModifyTime:              time.Now(),
+			})
+		}
+	}
+
+	// 添加消息
+	if len(addMessageList) > 0 {
+		_, err = o.InsertMulti(500, addMessageList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 添加记录
+	if len(addRecordList) > 0 {
+		_, err = o.InsertMulti(500, addRecordList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 已经授权了的用户,需要删除未授权记录
+	authUserIdNum := len(authUserIdList)
+	if authUserIdNum > 0 {
+		sql = `DELETE FROM chart_info_permission_no_auth_record WHERE  source = ? AND sys_user_id in (` + utils.GetOrmInReplace(authUserIdNum) + `) AND chart_info_id in (` + utils.GetOrmInReplace(num) + `)`
+		_, err = o.Raw(sql, chartSource, authUserIdList, dataIdList).Exec()
+	}
+
+	return
+}
+
+// DeleteChartInfoPermissionNoAuthRecordBySourceAndDataIdList
+// @Description: 根据来源和数据id列表删除记录
+// @author: Roc
+// @datetime 2024-04-07 14:47:37
+// @param chartSource int
+// @param dataIdList []string
+// @return err error
+func DeleteChartInfoPermissionNoAuthRecordBySourceAndDataIdList(chartSource int, dataIdList []string) (err error) {
+	num := len(dataIdList)
+	if num <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("data")
+
+	sql := `DELETE FROM chart_info_permission_no_auth_record WHERE source = ? AND chart_info_id in (` + utils.GetOrmInReplace(num) + `)`
+	_, err = o.Raw(sql, chartSource, dataIdList).Exec()
+
+	return
+}
+
+func GetChartInfoDataPermissionNoAuthRecordListByUserId(userId int32, chartSource, startSize, pageSize int) (total int, items []*DataPermissionNoAuthRecord, err error) {
+	o := orm.NewOrmUsingDB("data")
+
+	// 获取总数
+	sql := `SELECT count(1) AS total FROM chart_info_permission_no_auth_record WHERE sys_user_id = ? AND source = ? `
+	err = o.Raw(sql, userId, chartSource).QueryRow(&total)
+	if err != nil {
+		return
+	}
+
+	sql = `SELECT chart_info_permission_no_auth_record_id as data_permission_no_auth_record_id,op_unique_code,source as sub_source,chart_info_id as data_id,chart_name as data_name,sys_user_id,create_time FROM chart_info_permission_no_auth_record WHERE sys_user_id = ? AND source = ? ORDER BY chart_info_permission_no_auth_record_id desc LIMIT ?,? `
+	_, err = o.Raw(sql, userId, chartSource, startSize, pageSize).QueryRows(&items)
+
+	return
+}
+
+type ChartInfoClassifyPermissionNoAuthRecord struct {
+	ChartInfoClassifyPermissionNoAuthRecordId int64     `json:"chart_info_classify_permission_no_auth_record_id" orm:"column(chart_info_classify_permission_no_auth_record_id);pk"` // 资产分类数据操作记录id
+	Source                                    int32     `json:"source"`                                                                                                             // 子来源 :ETA表格中的各种表格类型,以及图表的来源(这个是后续的扩展方向)
+	OpUniqueCode                              string    `json:"op_unique_code"`                                                                                                     // 操作的唯一编码,主要是记录统一操作的日志
+	ClassifyId                                string    `json:"classify_id"`                                                                                                        // 图表资产分类id
+	ClassifyName                              string    `json:"classify_name"`                                                                                                      // 图表资产分类名称
+	SysUserId                                 int32     `json:"sys_user_id"`                                                                                                        // 系统用户id
+	CreateTime                                time.Time `json:"create_time"`                                                                                                        // 创建时间
+}
+
+// AddChartInfoClassifyNoAuthRecordBySourceAndClassifyIdList
+// @Description: 根据分类添加用户分类未授权记录
+// @author: Roc
+// @datetime 2024-04-07 16:44:21
+// @param source int
+// @param chartSource int
+// @param classifyInfoList []ClassifyDataItem
+// @param noAuthUserIdList []int
+// @param uniqueCode string
+// @param content string
+// @param opUserId int
+// @return err error
+func AddChartInfoClassifyNoAuthRecordBySourceAndClassifyIdList(source, chartSource int, classifyInfoList []ClassifyDataItem, noAuthUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+	num := len(classifyInfoList)
+	if num <= 0 {
+		return
+	}
+	// 分类id
+	classifyIdList := make([]int, 0)
+	for _, v := range classifyInfoList {
+		classifyIdList = append(classifyIdList, v.ClassifyId)
+	}
+
+	userNum := len(noAuthUserIdList)
+	if userNum <= 0 {
+		return
+	}
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+
+	// 根据分类获取已经存在的未授权记录
+	var existList []*ChartInfoClassifyPermissionNoAuthRecord
+	sql := `SELECT * FROM chart_info_classify_permission_no_auth_record WHERE source = ? AND classify_id in (` + utils.GetOrmInReplace(num) + `)`
+	_, err = o.Raw(sql, chartSource, classifyIdList).QueryRows(&existList)
+	if err != nil {
+		return
+	}
+
+	// 已经标记了的数据
+	existMap := make(map[int32]map[string]*ChartInfoClassifyPermissionNoAuthRecord)
+	for _, v := range existList {
+		tmpUserExistMap, ok := existMap[v.SysUserId]
+		if !ok {
+			tmpUserExistMap = make(map[string]*ChartInfoClassifyPermissionNoAuthRecord)
+		}
+
+		key := fmt.Sprint(v.Source, "_", v.ClassifyId)
+		tmpUserExistMap[key] = v
+		existMap[v.SysUserId] = tmpUserExistMap
+	}
+
+	addMessageList := make([]*DataPermissionMessage, 0)
+	addRecordList := make([]*ChartInfoClassifyPermissionNoAuthRecord, 0)
+	for _, userId := range noAuthUserIdList {
+		isAdd := false
+
+		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+
+		for _, dataItem := range classifyInfoList {
+			// 判断是否已经存在,已经存在就过滤
+			if userExistOk {
+				key := fmt.Sprint(chartSource, "_", dataItem.ClassifyId)
+				_, ok := tmpUserExistMap[key]
+				if ok {
+					continue
+				}
+			}
+
+			isAdd = true
+			addRecordList = append(addRecordList, &ChartInfoClassifyPermissionNoAuthRecord{
+				ChartInfoClassifyPermissionNoAuthRecordId: 0,
+				Source:       int32(chartSource),
+				OpUniqueCode: uniqueCode,
+				ClassifyId:   fmt.Sprint(dataItem.ClassifyId),
+				ClassifyName: dataItem.ClassifyName,
+				SysUserId:    int32(userId),
+				CreateTime:   time.Now(),
+			})
+		}
+
+		// 有记录的话,需要添加消息
+		if isAdd {
+			addMessageList = append(addMessageList, &DataPermissionMessage{
+				DataPermissionMessageId: 0,
+				SendUserId:              int32(opUserId),
+				ReceiveUserId:           int32(userId),
+				Content:                 content,
+				Remark:                  content,
+				OpType:                  4,
+				Source:                  int32(source),
+				SubSource:               int32(chartSource),
+				OpUniqueCode:            uniqueCode,
+				IsRead:                  0,
+				CreateTime:              time.Now(),
+				ModifyTime:              time.Now(),
+			})
+		}
+	}
+
+	// 添加消息
+	if len(addMessageList) > 0 {
+		_, err = o.InsertMulti(500, addMessageList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 添加记录
+	if len(addRecordList) > 0 {
+		_, err = o.InsertMulti(500, addRecordList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 移除已经公开了的分类权限,需要删除未授权记录
+	authUserIdNum := len(classifyIdList)
+	if authUserIdNum > 0 {
+		sql = `DELETE FROM chart_info_classify_permission_no_auth_record WHERE source = ? AND classify_id not in (` + utils.GetOrmInReplace(num) + `)`
+		_, err = o.Raw(sql, chartSource, classifyIdList).Exec()
+	}
+
+	return
+}
+
+// AddChartInfoClassifyNoAuthRecordBySourceAndUserIdList
+// @Description: 根据用户添加用户分类未授权记录
+// @author: Roc
+// @datetime 2024-04-07 20:12:44
+// @param source int
+// @param chartSource int
+// @param noAuthClassifyMap map[int]ClassifyDataItem
+// @param configUserIdList []int
+// @param uniqueCode string
+// @param content string
+// @param opUserId int
+// @return err error
+func AddChartInfoClassifyNoAuthRecordBySourceAndUserIdList(source, chartSource int, noAuthClassifyMap map[int]ClassifyDataItem, configUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+	// 当前配置用户
+	configUserNum := len(configUserIdList)
+	if configUserNum <= 0 {
+		return
+	}
+
+	//// 总共的涉密分类
+	//noAuthClassifyInfoNum := len(noAuthClassifyMap)
+	//if noAuthClassifyInfoNum <= 0 {
+	//	return
+	//}
+
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+
+	// 根据当前配置用户获取已经存在的未授权记录
+	var existList []*ChartInfoClassifyPermissionNoAuthRecord
+	sql := `SELECT * FROM chart_info_classify_permission_no_auth_record WHERE source = ? AND sys_user_id in (` + utils.GetOrmInReplace(configUserNum) + `)`
+	_, err = o.Raw(sql, chartSource, configUserIdList).QueryRows(&existList)
+	if err != nil {
+		return
+	}
+
+	// 已经标记了的数据
+	existMap := make(map[int32]map[string]*ChartInfoClassifyPermissionNoAuthRecord)
+	delRecordIdMap := make(map[int64]int64)
+	for _, v := range existList {
+		tmpUserExistMap, ok := existMap[v.SysUserId]
+		if !ok {
+			tmpUserExistMap = make(map[string]*ChartInfoClassifyPermissionNoAuthRecord)
+		}
+
+		tmpUserExistMap[v.ClassifyId] = v
+		existMap[v.SysUserId] = tmpUserExistMap
+
+		// 已经配置了的记录id
+		delRecordIdMap[v.ChartInfoClassifyPermissionNoAuthRecordId] = v.ChartInfoClassifyPermissionNoAuthRecordId
+	}
+
+	addMessageList := make([]*DataPermissionMessage, 0)
+	addRecordList := make([]*ChartInfoClassifyPermissionNoAuthRecord, 0)
+	for _, userId := range configUserIdList {
+		isAdd := false
+
+		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+
+		for _, dataItem := range noAuthClassifyMap {
+			// 判断是否已经存在,已经存在就过滤
+			if userExistOk {
+				key := fmt.Sprint(dataItem.ClassifyId)
+				tmpUserRecord, ok := tmpUserExistMap[key]
+				if ok {
+					delete(delRecordIdMap, tmpUserRecord.ChartInfoClassifyPermissionNoAuthRecordId)
+					continue
+				}
+			}
+
+			isAdd = true
+			addRecordList = append(addRecordList, &ChartInfoClassifyPermissionNoAuthRecord{
+				ChartInfoClassifyPermissionNoAuthRecordId: 0,
+				Source:       int32(chartSource),
+				OpUniqueCode: uniqueCode,
+				ClassifyId:   fmt.Sprint(dataItem.ClassifyId),
+				ClassifyName: dataItem.ClassifyName,
+				SysUserId:    int32(userId),
+				CreateTime:   time.Now(),
+			})
+		}
+
+		// 有记录的话,需要添加消息
+		if isAdd {
+			addMessageList = append(addMessageList, &DataPermissionMessage{
+				DataPermissionMessageId: 0,
+				SendUserId:              int32(opUserId),
+				ReceiveUserId:           int32(userId),
+				Content:                 content,
+				Remark:                  content,
+				OpType:                  4,
+				Source:                  int32(source),
+				SubSource:               int32(chartSource),
+				OpUniqueCode:            uniqueCode,
+				IsRead:                  0,
+				CreateTime:              time.Now(),
+				ModifyTime:              time.Now(),
+			})
+		}
+	}
+
+	// 添加消息
+	if len(addMessageList) > 0 {
+		_, err = o.InsertMulti(500, addMessageList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 添加记录
+	if len(addRecordList) > 0 {
+		_, err = o.InsertMulti(500, addRecordList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 需要删除未授权记录
+	delRecordIdNum := len(delRecordIdMap)
+	if delRecordIdNum > 0 {
+		delRecordIdList := make([]int64, 0)
+		for _, v := range delRecordIdMap {
+			delRecordIdList = append(delRecordIdList, v)
+		}
+		sql = `DELETE FROM chart_info_classify_permission_no_auth_record WHERE chart_info_classify_permission_no_auth_record_id in (` + utils.GetOrmInReplace(delRecordIdNum) + `) `
+		_, err = o.Raw(sql, delRecordIdList).Exec()
+	}
+
+	return
+}
+
+// DeleteChartInfoClassifyNoAuthRecordBySourceAndClassifyIdList
+// @Description: 根据来源和删除分类授权记录
+// @author: Roc
+// @datetime 2024-04-07 14:47:37
+// @param chartSource int
+// @return err error
+func DeleteChartInfoClassifyNoAuthRecordBySourceAndClassifyIdList(chartSource int) (err error) {
+	o := orm.NewOrmUsingDB("data")
+
+	sql := `DELETE FROM chart_info_classify_permission_no_auth_record WHERE source = ?`
+	_, err = o.Raw(sql, chartSource).Exec()
+
+	return
+}
+
+// GetChartInfoDataPermissionClassifyNoAuthRecordListByUserId
+// @Description: 根据用户获取未授权的资产分类记录
+// @author: Roc
+// @datetime 2024-04-07 20:14:49
+// @param userId int
+// @param source int
+// @param subSource int
+// @param startSize int
+// @param pageSize int
+// @return total int
+// @return items []*DataPermissionClassifyNoAuthRecord
+// @return err error
+func GetChartInfoDataPermissionClassifyNoAuthRecordListByUserId(userId int32, chartSource, startSize, pageSize int) (total int, items []*DataPermissionClassifyNoAuthRecord, err error) {
+	o := orm.NewOrmUsingDB("data")
+
+	// 获取总数
+	sql := `SELECT count(1) AS total FROM chart_info_classify_permission_no_auth_record WHERE sys_user_id = ? AND source = ? `
+	err = o.Raw(sql, userId, chartSource).QueryRow(&total)
+	if err != nil {
+		return
+	}
+
+	sql = `SELECT chart_info_classify_permission_no_auth_record_id as data_permission_classify_no_auth_record_id,source as sub_source,op_unique_code,classify_id,classify_name,sys_user_id,create_time  FROM chart_info_classify_permission_no_auth_record WHERE sys_user_id = ? AND source = ? ORDER BY chart_info_classify_permission_no_auth_record_id desc LIMIT ?,? `
+	_, err = o.Raw(sql, userId, chartSource, startSize, pageSize).QueryRows(&items)
+
+	return
+}

+ 394 - 251
models/data_manage/data_manage_permission/classify_no_auth_record.go

@@ -1,9 +1,8 @@
 package data_manage_permission
 
 import (
+	"errors"
 	"eta/eta_api/utils"
-	"fmt"
-	"github.com/beego/beego/v2/client/orm"
 	"time"
 )
 
@@ -25,6 +24,327 @@ type ClassifyDataItem struct {
 	ClassifyName string // 资产名称(指标、图表、表格)
 }
 
+//
+//// AddClassifyNoAuthRecordBySourceAndClassifyIdList
+//// @Description: 根据分类添加用户分类未授权记录
+//// @author: Roc
+//// @datetime 2024-04-07 16:44:21
+//// @param source int
+//// @param subSource int
+//// @param classifyInfoList []ClassifyDataItem
+//// @param noAuthUserIdList []int
+//// @param uniqueCode string
+//// @param content string
+//// @param opUserId int
+//// @return err error
+//func AddClassifyNoAuthRecordBySourceAndClassifyIdList(source, subSource int, classifyInfoList []ClassifyDataItem, noAuthUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+//	num := len(classifyInfoList)
+//	if num <= 0 {
+//		return
+//	}
+//	// 分类id
+//	classifyIdList := make([]int, 0)
+//	for _, v := range classifyInfoList {
+//		classifyIdList = append(classifyIdList, v.ClassifyId)
+//	}
+//
+//	userNum := len(noAuthUserIdList)
+//	if userNum <= 0 {
+//		return
+//	}
+//	o, err := orm.NewOrmUsingDB("data").Begin()
+//	if err != nil {
+//		return
+//	}
+//	defer func() {
+//		if err != nil {
+//			_ = o.Rollback()
+//		} else {
+//			_ = o.Commit()
+//		}
+//	}()
+//
+//	// 根据分类获取已经存在的未授权记录
+//	var existList []*DataPermissionClassifyNoAuthRecord
+//	sql := `SELECT * FROM data_permission_classify_no_auth_record WHERE source = ? AND sub_source = ? AND classify_id in (` + utils.GetOrmInReplace(num) + `)`
+//	_, err = o.Raw(sql, source, subSource, classifyIdList).QueryRows(&existList)
+//	if err != nil {
+//		return
+//	}
+//
+//	// 已经标记了的数据
+//	existMap := make(map[int32]map[string]*DataPermissionClassifyNoAuthRecord)
+//	for _, v := range existList {
+//		tmpUserExistMap, ok := existMap[v.SysUserId]
+//		if !ok {
+//			tmpUserExistMap = make(map[string]*DataPermissionClassifyNoAuthRecord)
+//		}
+//
+//		key := fmt.Sprint(v.Source, "_", v.SubSource, "_", v.ClassifyId)
+//		tmpUserExistMap[key] = v
+//		existMap[v.SysUserId] = tmpUserExistMap
+//	}
+//
+//	addMessageList := make([]*DataPermissionMessage, 0)
+//	addRecordList := make([]*DataPermissionClassifyNoAuthRecord, 0)
+//	for _, userId := range noAuthUserIdList {
+//		isAdd := false
+//
+//		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+//
+//		for _, dataItem := range classifyInfoList {
+//			// 判断是否已经存在,已经存在就过滤
+//			if userExistOk {
+//				key := fmt.Sprint(source, "_", subSource, "_", dataItem.ClassifyId)
+//				_, ok := tmpUserExistMap[key]
+//				if ok {
+//					continue
+//				}
+//			}
+//
+//			isAdd = true
+//			addRecordList = append(addRecordList, &DataPermissionClassifyNoAuthRecord{
+//				DataPermissionClassifyNoAuthRecordId: 0,
+//				Source:                               int32(source),
+//				SubSource:                            int32(subSource),
+//				OpUniqueCode:                         uniqueCode,
+//				ClassifyId:                           fmt.Sprint(dataItem.ClassifyId),
+//				ClassifyName:                         dataItem.ClassifyName,
+//				SysUserId:                            int32(userId),
+//				CreateTime:                           time.Now(),
+//			})
+//		}
+//
+//		// 有记录的话,需要添加消息
+//		if isAdd {
+//			addMessageList = append(addMessageList, &DataPermissionMessage{
+//				DataPermissionMessageId: 0,
+//				SendUserId:              int32(opUserId),
+//				ReceiveUserId:           int32(userId),
+//				Content:                 content,
+//				Remark:                  content,
+//				OpType:                  4,
+//				Source:                  int32(source),
+//				SubSource:               int32(subSource),
+//				OpUniqueCode:            uniqueCode,
+//				IsRead:                  0,
+//				CreateTime:              time.Now(),
+//				ModifyTime:              time.Now(),
+//			})
+//		}
+//	}
+//
+//	// 添加消息
+//	if len(addMessageList) > 0 {
+//		_, err = o.InsertMulti(500, addMessageList)
+//		if err != nil {
+//			return
+//		}
+//	}
+//
+//	// 添加记录
+//	if len(addRecordList) > 0 {
+//		_, err = o.InsertMulti(500, addRecordList)
+//		if err != nil {
+//			return
+//		}
+//	}
+//
+//	// 移除已经公开了的分类权限,需要删除未授权记录
+//	authUserIdNum := len(classifyIdList)
+//	if authUserIdNum > 0 {
+//		sql = `DELETE FROM data_permission_classify_no_auth_record WHERE source = ? AND sub_source = ? AND classify_id not in (` + utils.GetOrmInReplace(num) + `)`
+//		_, err = o.Raw(sql, source, subSource, classifyIdList).Exec()
+//	}
+//
+//	return
+//}
+//
+//// AddClassifyNoAuthRecordBySourceAndUserIdList
+//// @Description: 根据用户添加用户分类未授权记录
+//// @author: Roc
+//// @datetime 2024-04-07 20:12:44
+//// @param source int
+//// @param subSource int
+//// @param noAuthClassifyMap map[int]ClassifyDataItem
+//// @param configUserIdList []int
+//// @param uniqueCode string
+//// @param content string
+//// @param opUserId int
+//// @return err error
+//func AddClassifyNoAuthRecordBySourceAndUserIdList(source, subSource int, noAuthClassifyMap map[int]ClassifyDataItem, configUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+//	// 当前配置用户
+//	configUserNum := len(configUserIdList)
+//	if configUserNum <= 0 {
+//		return
+//	}
+//
+//	//// 总共的涉密分类
+//	//noAuthClassifyInfoNum := len(noAuthClassifyMap)
+//	//if noAuthClassifyInfoNum <= 0 {
+//	//	return
+//	//}
+//
+//	o, err := orm.NewOrmUsingDB("data").Begin()
+//	if err != nil {
+//		return
+//	}
+//	defer func() {
+//		if err != nil {
+//			_ = o.Rollback()
+//		} else {
+//			_ = o.Commit()
+//		}
+//	}()
+//
+//	// 根据当前配置用户获取已经存在的未授权记录
+//	var existList []*DataPermissionClassifyNoAuthRecord
+//	sql := `SELECT * FROM data_permission_classify_no_auth_record WHERE source = ? AND sub_source = ? AND sys_user_id in (` + utils.GetOrmInReplace(configUserNum) + `)`
+//	_, err = o.Raw(sql, source, subSource, configUserIdList).QueryRows(&existList)
+//	if err != nil {
+//		return
+//	}
+//
+//	// 已经标记了的数据
+//	existMap := make(map[int32]map[string]*DataPermissionClassifyNoAuthRecord)
+//	delRecordIdMap := make(map[int64]int64)
+//	for _, v := range existList {
+//		tmpUserExistMap, ok := existMap[v.SysUserId]
+//		if !ok {
+//			tmpUserExistMap = make(map[string]*DataPermissionClassifyNoAuthRecord)
+//		}
+//
+//		tmpUserExistMap[v.ClassifyId] = v
+//		existMap[v.SysUserId] = tmpUserExistMap
+//
+//		// 已经配置了的记录id
+//		delRecordIdMap[v.DataPermissionClassifyNoAuthRecordId] = v.DataPermissionClassifyNoAuthRecordId
+//	}
+//
+//	addMessageList := make([]*DataPermissionMessage, 0)
+//	addRecordList := make([]*DataPermissionClassifyNoAuthRecord, 0)
+//	for _, userId := range configUserIdList {
+//		isAdd := false
+//
+//		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+//
+//		for _, dataItem := range noAuthClassifyMap {
+//			// 判断是否已经存在,已经存在就过滤
+//			if userExistOk {
+//				key := fmt.Sprint(dataItem.ClassifyId)
+//				tmpUserRecord, ok := tmpUserExistMap[key]
+//				if ok {
+//					delete(delRecordIdMap, tmpUserRecord.DataPermissionClassifyNoAuthRecordId)
+//					continue
+//				}
+//			}
+//
+//			isAdd = true
+//			addRecordList = append(addRecordList, &DataPermissionClassifyNoAuthRecord{
+//				DataPermissionClassifyNoAuthRecordId: 0,
+//				Source:                               int32(source),
+//				SubSource:                            int32(subSource),
+//				OpUniqueCode:                         uniqueCode,
+//				ClassifyId:                           fmt.Sprint(dataItem.ClassifyId),
+//				ClassifyName:                         dataItem.ClassifyName,
+//				SysUserId:                            int32(userId),
+//				CreateTime:                           time.Now(),
+//			})
+//		}
+//
+//		// 有记录的话,需要添加消息
+//		if isAdd {
+//			addMessageList = append(addMessageList, &DataPermissionMessage{
+//				DataPermissionMessageId: 0,
+//				SendUserId:              int32(opUserId),
+//				ReceiveUserId:           int32(userId),
+//				Content:                 content,
+//				Remark:                  content,
+//				OpType:                  4,
+//				Source:                  int32(source),
+//				SubSource:               int32(subSource),
+//				OpUniqueCode:            uniqueCode,
+//				IsRead:                  0,
+//				CreateTime:              time.Now(),
+//				ModifyTime:              time.Now(),
+//			})
+//		}
+//	}
+//
+//	// 添加消息
+//	if len(addMessageList) > 0 {
+//		_, err = o.InsertMulti(500, addMessageList)
+//		if err != nil {
+//			return
+//		}
+//	}
+//
+//	// 添加记录
+//	if len(addRecordList) > 0 {
+//		_, err = o.InsertMulti(500, addRecordList)
+//		if err != nil {
+//			return
+//		}
+//	}
+//
+//	// 需要删除未授权记录
+//	delRecordIdNum := len(delRecordIdMap)
+//	if delRecordIdNum > 0 {
+//		delRecordIdList := make([]int64, 0)
+//		for _, v := range delRecordIdMap {
+//			delRecordIdList = append(delRecordIdList, v)
+//		}
+//		sql = `DELETE FROM data_permission_classify_no_auth_record WHERE data_permission_classify_no_auth_record_id in (` + utils.GetOrmInReplace(delRecordIdNum) + `) `
+//		_, err = o.Raw(sql, delRecordIdList).Exec()
+//	}
+//
+//	return
+//}
+//
+//// DeleteClassifyNoAuthRecordBySourceAndClassifyIdList
+//// @Description: 根据来源和删除分类授权记录
+//// @author: Roc
+//// @datetime 2024-04-07 14:47:37
+//// @param source int
+//// @param subSource int
+//// @return err error
+//func DeleteClassifyNoAuthRecordBySourceAndClassifyIdList(source, subSource int) (err error) {
+//	o := orm.NewOrmUsingDB("data")
+//
+//	sql := `DELETE FROM data_permission_classify_no_auth_record WHERE source = ? AND sub_source = ?`
+//	_, err = o.Raw(sql, source, subSource).Exec()
+//
+//	return
+//}
+//
+//// GetDataPermissionClassifyNoAuthRecordListByUserId
+//// @Description: 根据用户获取未授权的资产分类记录
+//// @author: Roc
+//// @datetime 2024-04-07 20:14:49
+//// @param userId int
+//// @param source int
+//// @param subSource int
+//// @param startSize int
+//// @param pageSize int
+//// @return total int
+//// @return items []*DataPermissionClassifyNoAuthRecord
+//// @return err error
+//func GetDataPermissionClassifyNoAuthRecordListByUserId(userId, source, subSource int32, startSize, pageSize int) (total int, items []*DataPermissionClassifyNoAuthRecord, err error) {
+//	o := orm.NewOrmUsingDB("data")
+//
+//	// 获取总数
+//	sql := `SELECT count(1) AS total FROM data_permission_classify_no_auth_record WHERE sys_user_id = ? AND source = ? AND sub_source = ? `
+//	err = o.Raw(sql, userId, source, subSource).QueryRow(&total)
+//	if err != nil {
+//		return
+//	}
+//
+//	sql = `SELECT * FROM data_permission_classify_no_auth_record WHERE sys_user_id = ? AND source = ? AND sub_source = ? ORDER BY data_permission_classify_no_auth_record_id desc LIMIT ?,? `
+//	_, err = o.Raw(sql, userId, source, subSource, startSize, pageSize).QueryRows(&items)
+//
+//	return
+//}
+
 // AddClassifyNoAuthRecordBySourceAndClassifyIdList
 // @Description: 根据分类添加用户分类未授权记录
 // @author: Roc
@@ -38,125 +358,27 @@ type ClassifyDataItem struct {
 // @param opUserId int
 // @return err error
 func AddClassifyNoAuthRecordBySourceAndClassifyIdList(source, subSource int, classifyInfoList []ClassifyDataItem, noAuthUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
-	num := len(classifyInfoList)
-	if num <= 0 {
-		return
-	}
-	// 分类id
-	classifyIdList := make([]int, 0)
-	for _, v := range classifyInfoList {
-		classifyIdList = append(classifyIdList, v.ClassifyId)
-	}
-
-	userNum := len(noAuthUserIdList)
-	if userNum <= 0 {
-		return
-	}
-	o, err := orm.NewOrmUsingDB("data").Begin()
-	if err != nil {
-		return
-	}
-	defer func() {
-		if err != nil {
-			_ = o.Rollback()
-		} else {
-			_ = o.Commit()
+	switch source {
+	case 3, 4:
+		edbClassifyType := 0
+		if source == 4 {
+			edbClassifyType = 1
 		}
-	}()
-
-	// 根据分类获取已经存在的未授权记录
-	var existList []*DataPermissionClassifyNoAuthRecord
-	sql := `SELECT * FROM data_permission_classify_no_auth_record WHERE source = ? AND sub_source = ? AND classify_id in (` + utils.GetOrmInReplace(num) + `)`
-	_, err = o.Raw(sql, source, subSource, classifyIdList).QueryRows(&existList)
-	if err != nil {
+		err = AddEdbInfoClassifyNoAuthRecordBySourceAndClassifyIdList(source, edbClassifyType, classifyInfoList, noAuthUserIdList, uniqueCode, content, opUserId)
+	case 5:
+		//图库
+		chartSource := utils.CHART_SOURCE_DEFAULT
+		err = AddChartInfoClassifyNoAuthRecordBySourceAndClassifyIdList(source, chartSource, classifyInfoList, noAuthUserIdList, uniqueCode, content, opUserId)
+
+	case 6:
+		// ETA表格
+		err = AddExcelInfoClassifyNoAuthRecordBySourceAndClassifyIdList(source, subSource, classifyInfoList, noAuthUserIdList, uniqueCode, content, opUserId)
+
+	default:
+		err = errors.New("错误的source")
 		return
 	}
 
-	// 已经标记了的数据
-	existMap := make(map[int32]map[string]*DataPermissionClassifyNoAuthRecord)
-	for _, v := range existList {
-		tmpUserExistMap, ok := existMap[v.SysUserId]
-		if !ok {
-			tmpUserExistMap = make(map[string]*DataPermissionClassifyNoAuthRecord)
-		}
-
-		key := fmt.Sprint(v.Source, "_", v.SubSource, "_", v.ClassifyId)
-		tmpUserExistMap[key] = v
-		existMap[v.SysUserId] = tmpUserExistMap
-	}
-
-	addMessageList := make([]*DataPermissionMessage, 0)
-	addRecordList := make([]*DataPermissionClassifyNoAuthRecord, 0)
-	for _, userId := range noAuthUserIdList {
-		isAdd := false
-
-		tmpUserExistMap, userExistOk := existMap[int32(userId)]
-
-		for _, dataItem := range classifyInfoList {
-			// 判断是否已经存在,已经存在就过滤
-			if userExistOk {
-				key := fmt.Sprint(source, "_", subSource, "_", dataItem.ClassifyId)
-				_, ok := tmpUserExistMap[key]
-				if ok {
-					continue
-				}
-			}
-
-			isAdd = true
-			addRecordList = append(addRecordList, &DataPermissionClassifyNoAuthRecord{
-				DataPermissionClassifyNoAuthRecordId: 0,
-				Source:                               int32(source),
-				SubSource:                            int32(subSource),
-				OpUniqueCode:                         uniqueCode,
-				ClassifyId:                           fmt.Sprint(dataItem.ClassifyId),
-				ClassifyName:                         dataItem.ClassifyName,
-				SysUserId:                            int32(userId),
-				CreateTime:                           time.Now(),
-			})
-		}
-
-		// 有记录的话,需要添加消息
-		if isAdd {
-			addMessageList = append(addMessageList, &DataPermissionMessage{
-				DataPermissionMessageId: 0,
-				SendUserId:              int32(opUserId),
-				ReceiveUserId:           int32(userId),
-				Content:                 content,
-				Remark:                  content,
-				OpType:                  4,
-				Source:                  int32(source),
-				SubSource:               int32(subSource),
-				OpUniqueCode:            uniqueCode,
-				IsRead:                  0,
-				CreateTime:              time.Now(),
-				ModifyTime:              time.Now(),
-			})
-		}
-	}
-
-	// 添加消息
-	if len(addMessageList) > 0 {
-		_, err = o.InsertMulti(500, addMessageList)
-		if err != nil {
-			return
-		}
-	}
-
-	// 添加记录
-	if len(addRecordList) > 0 {
-		_, err = o.InsertMulti(500, addRecordList)
-		if err != nil {
-			return
-		}
-	}
-
-	// 移除已经公开了的分类权限,需要删除未授权记录
-	authUserIdNum := len(classifyIdList)
-	if authUserIdNum > 0 {
-		sql = `DELETE FROM data_permission_classify_no_auth_record WHERE source = ? AND sub_source = ? AND classify_id not in (` + utils.GetOrmInReplace(num) + `)`
-		_, err = o.Raw(sql, source, subSource, classifyIdList).Exec()
-	}
-
 	return
 }
 
@@ -173,131 +395,27 @@ func AddClassifyNoAuthRecordBySourceAndClassifyIdList(source, subSource int, cla
 // @param opUserId int
 // @return err error
 func AddClassifyNoAuthRecordBySourceAndUserIdList(source, subSource int, noAuthClassifyMap map[int]ClassifyDataItem, configUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
-	// 当前配置用户
-	configUserNum := len(configUserIdList)
-	if configUserNum <= 0 {
-		return
-	}
-
-	//// 总共的涉密分类
-	//noAuthClassifyInfoNum := len(noAuthClassifyMap)
-	//if noAuthClassifyInfoNum <= 0 {
-	//	return
-	//}
-
-	o, err := orm.NewOrmUsingDB("data").Begin()
-	if err != nil {
-		return
-	}
-	defer func() {
-		if err != nil {
-			_ = o.Rollback()
-		} else {
-			_ = o.Commit()
+	switch source {
+	case 3, 4:
+		edbClassifyType := 0
+		if source == 4 {
+			edbClassifyType = 1
 		}
-	}()
-
-	// 根据当前配置用户获取已经存在的未授权记录
-	var existList []*DataPermissionClassifyNoAuthRecord
-	sql := `SELECT * FROM data_permission_classify_no_auth_record WHERE source = ? AND sub_source = ? AND sys_user_id in (` + utils.GetOrmInReplace(configUserNum) + `)`
-	_, err = o.Raw(sql, source, subSource, configUserIdList).QueryRows(&existList)
-	if err != nil {
+		err = AddEdbInfoClassifyNoAuthRecordBySourceAndUserIdList(source, edbClassifyType, noAuthClassifyMap, configUserIdList, uniqueCode, content, opUserId)
+	case 5:
+		//图库
+		chartSource := utils.CHART_SOURCE_DEFAULT
+		err = AddChartInfoClassifyNoAuthRecordBySourceAndUserIdList(source, chartSource, noAuthClassifyMap, configUserIdList, uniqueCode, content, opUserId)
+
+	case 6:
+		// ETA表格
+		err = AddExcelInfoClassifyNoAuthRecordBySourceAndUserIdList(source, subSource, noAuthClassifyMap, configUserIdList, uniqueCode, content, opUserId)
+
+	default:
+		err = errors.New("错误的source")
 		return
 	}
 
-	// 已经标记了的数据
-	existMap := make(map[int32]map[string]*DataPermissionClassifyNoAuthRecord)
-	delRecordIdMap := make(map[int64]int64)
-	for _, v := range existList {
-		tmpUserExistMap, ok := existMap[v.SysUserId]
-		if !ok {
-			tmpUserExistMap = make(map[string]*DataPermissionClassifyNoAuthRecord)
-		}
-
-		tmpUserExistMap[v.ClassifyId] = v
-		existMap[v.SysUserId] = tmpUserExistMap
-
-		// 已经配置了的记录id
-		delRecordIdMap[v.DataPermissionClassifyNoAuthRecordId] = v.DataPermissionClassifyNoAuthRecordId
-	}
-
-	addMessageList := make([]*DataPermissionMessage, 0)
-	addRecordList := make([]*DataPermissionClassifyNoAuthRecord, 0)
-	for _, userId := range configUserIdList {
-		isAdd := false
-
-		tmpUserExistMap, userExistOk := existMap[int32(userId)]
-
-		for _, dataItem := range noAuthClassifyMap {
-			// 判断是否已经存在,已经存在就过滤
-			if userExistOk {
-				key := fmt.Sprint(dataItem.ClassifyId)
-				tmpUserRecord, ok := tmpUserExistMap[key]
-				if ok {
-					delete(delRecordIdMap, tmpUserRecord.DataPermissionClassifyNoAuthRecordId)
-					continue
-				}
-			}
-
-			isAdd = true
-			addRecordList = append(addRecordList, &DataPermissionClassifyNoAuthRecord{
-				DataPermissionClassifyNoAuthRecordId: 0,
-				Source:                               int32(source),
-				SubSource:                            int32(subSource),
-				OpUniqueCode:                         uniqueCode,
-				ClassifyId:                           fmt.Sprint(dataItem.ClassifyId),
-				ClassifyName:                         dataItem.ClassifyName,
-				SysUserId:                            int32(userId),
-				CreateTime:                           time.Now(),
-			})
-		}
-
-		// 有记录的话,需要添加消息
-		if isAdd {
-			addMessageList = append(addMessageList, &DataPermissionMessage{
-				DataPermissionMessageId: 0,
-				SendUserId:              int32(opUserId),
-				ReceiveUserId:           int32(userId),
-				Content:                 content,
-				Remark:                  content,
-				OpType:                  4,
-				Source:                  int32(source),
-				SubSource:               int32(subSource),
-				OpUniqueCode:            uniqueCode,
-				IsRead:                  0,
-				CreateTime:              time.Now(),
-				ModifyTime:              time.Now(),
-			})
-		}
-	}
-
-	// 添加消息
-	if len(addMessageList) > 0 {
-		_, err = o.InsertMulti(500, addMessageList)
-		if err != nil {
-			return
-		}
-	}
-
-	// 添加记录
-	if len(addRecordList) > 0 {
-		_, err = o.InsertMulti(500, addRecordList)
-		if err != nil {
-			return
-		}
-	}
-
-	// 需要删除未授权记录
-	delRecordIdNum := len(delRecordIdMap)
-	if delRecordIdNum > 0 {
-		delRecordIdList := make([]int64, 0)
-		for _, v := range delRecordIdMap {
-			delRecordIdList = append(delRecordIdList, v)
-		}
-		sql = `DELETE FROM data_permission_classify_no_auth_record WHERE data_permission_classify_no_auth_record_id in (` + utils.GetOrmInReplace(delRecordIdNum) + `) `
-		_, err = o.Raw(sql, delRecordIdList).Exec()
-	}
-
 	return
 }
 
@@ -309,10 +427,26 @@ func AddClassifyNoAuthRecordBySourceAndUserIdList(source, subSource int, noAuthC
 // @param subSource int
 // @return err error
 func DeleteClassifyNoAuthRecordBySourceAndClassifyIdList(source, subSource int) (err error) {
-	o := orm.NewOrmUsingDB("data")
-
-	sql := `DELETE FROM data_permission_classify_no_auth_record WHERE source = ? AND sub_source = ?`
-	_, err = o.Raw(sql, source, subSource).Exec()
+	switch source {
+	case 3, 4:
+		edbClassifyType := 0
+		if source == 4 {
+			edbClassifyType = 1
+		}
+		err = DeleteEdbInfoClassifyNoAuthRecordBySourceAndClassifyIdList(edbClassifyType)
+	case 5:
+		//图库
+		chartSource := utils.CHART_SOURCE_DEFAULT
+		err = DeleteChartInfoClassifyNoAuthRecordBySourceAndClassifyIdList(chartSource)
+
+	case 6:
+		// ETA表格
+		err = DeleteExcelInfoClassifyNoAuthRecordBySourceAndClassifyIdList(subSource)
+
+	default:
+		err = errors.New("错误的source")
+		return
+	}
 
 	return
 }
@@ -330,17 +464,26 @@ func DeleteClassifyNoAuthRecordBySourceAndClassifyIdList(source, subSource int)
 // @return items []*DataPermissionClassifyNoAuthRecord
 // @return err error
 func GetDataPermissionClassifyNoAuthRecordListByUserId(userId, source, subSource int32, startSize, pageSize int) (total int, items []*DataPermissionClassifyNoAuthRecord, err error) {
-	o := orm.NewOrmUsingDB("data")
-
-	// 获取总数
-	sql := `SELECT count(1) AS total FROM data_permission_classify_no_auth_record WHERE sys_user_id = ? AND source = ? AND sub_source = ? `
-	err = o.Raw(sql, userId, source, subSource).QueryRow(&total)
-	if err != nil {
+	switch source {
+	case 3, 4:
+		edbClassifyType := 0
+		if source == 4 {
+			edbClassifyType = 1
+		}
+		total, items, err = GetEdbInfoDataPermissionClassifyNoAuthRecordListByUserId(userId, edbClassifyType, startSize, pageSize)
+	case 5:
+		//图库
+		chartSource := utils.CHART_SOURCE_DEFAULT
+		total, items, err = GetChartInfoDataPermissionClassifyNoAuthRecordListByUserId(userId, chartSource, startSize, pageSize)
+
+	case 6:
+		// ETA表格
+		total, items, err = GetExcelInfoDataPermissionClassifyNoAuthRecordListByUserId(userId, subSource, startSize, pageSize)
+
+	default:
+		err = errors.New("错误的source")
 		return
 	}
 
-	sql = `SELECT * FROM data_permission_classify_no_auth_record WHERE sys_user_id = ? AND source = ? AND sub_source = ? ORDER BY data_permission_classify_no_auth_record_id desc LIMIT ?,? `
-	_, err = o.Raw(sql, userId, source, subSource, startSize, pageSize).QueryRows(&items)
-
 	return
 }

+ 534 - 12
models/data_manage/data_manage_permission/edb.go

@@ -407,21 +407,20 @@ func InheritParentClassifyByEdbClassifyId(source, classifyType, classifyId, pare
 	// 添加未授权记录
 	{
 		// 获取父级未授权的用户记录
-		var parentRecordItems []*DataPermissionClassifyNoAuthRecord
-		sql = `SELECT * FROM data_permission_classify_no_auth_record WHERE classify_id = ? AND source = ? AND sub_source = ? ORDER BY data_permission_classify_no_auth_record_id desc LIMIT ?,? `
+		var parentRecordItems []*EdbInfoClassifyPermissionNoAuthRecord
+		sql = `SELECT * FROM edb_info_classify_permission_no_auth_record WHERE classify_id = ? AND edb_classify_type = ? ORDER BY edb_info_classify_permission_no_auth_record_id desc LIMIT ?,? `
 		_, err = o.Raw(sql, parentClassifyId, source, classifyType).QueryRows(&parentRecordItems)
 
-		addNoAuthRecordItems := make([]*DataPermissionClassifyNoAuthRecord, 0)
+		addNoAuthRecordItems := make([]*EdbInfoClassifyPermissionNoAuthRecord, 0)
 		for _, v := range parentRecordItems {
-			addNoAuthRecordItems = append(addNoAuthRecordItems, &DataPermissionClassifyNoAuthRecord{
-				DataPermissionClassifyNoAuthRecordId: 0,
-				Source:                               v.Source,
-				SubSource:                            v.SubSource,
-				OpUniqueCode:                         uniqueCode,
-				ClassifyId:                           fmt.Sprint(classifyId),
-				ClassifyName:                         classifyName,
-				SysUserId:                            v.SysUserId,
-				CreateTime:                           time.Now(),
+			addNoAuthRecordItems = append(addNoAuthRecordItems, &EdbInfoClassifyPermissionNoAuthRecord{
+				EdbInfoClassifyPermissionNoAuthRecordId: 0,
+				EdbClassifyType:                         v.EdbClassifyType,
+				OpUniqueCode:                            uniqueCode,
+				ClassifyId:                              fmt.Sprint(classifyId),
+				ClassifyName:                            classifyName,
+				SysUserId:                               v.SysUserId,
+				CreateTime:                              time.Now(),
 			})
 		}
 
@@ -468,3 +467,526 @@ func InheritParentClassifyByEdbClassifyId(source, classifyType, classifyId, pare
 
 	return
 }
+
+// EdbInfoPermissionNoAuthRecord
+// @Description: 指标数据权限未授权记录表
+type EdbInfoPermissionNoAuthRecord struct {
+	EdbInfoPermissionNoAuthRecordId int64     `json:"edb_info_permission_no_auth_record_id"  orm:"column(edb_info_permission_no_auth_record_id);pk"` // 资产数据操作记录id
+	OpUniqueCode                    string    `json:"op_unique_code"`                                                                                // 操作的唯一编码,主要是记录统一操作的日志
+	EdbInfoType                     int32     `json:"edb_info_type"`                                                                                 // 指标类型,0:普通指标,1:预测指标
+	EdbInfoId                       int32     `json:"edb_info_id"`                                                                                   // 指标id
+	EdbCode                         string    `json:"edb_code"`                                                                                      // 指标编码
+	EdbName                         string    `json:"edb_name"`                                                                                      // 指标名称
+	SysUserId                       int32     `json:"sys_user_id"`                                                                                   // 系统用户id
+	CreateTime                      time.Time `json:"create_time"`                                                                                   // 创建时间
+}
+
+// AddEdbInfoPermissionNoAuthRecordBySourceAndDataIdList
+// @Description: 添加未授权用户记录
+// @author: Roc
+// @datetime 2024-04-07 15:25:49
+// @param source int
+// @param edbInfoType int
+// @param dataList []DataItem
+// @param noAuthUserIdList []int 未授权用户
+// @param authUserIdList []int 已授权用户
+// @param uniqueCode
+// @param content string
+// @param opUserId int
+// @return err error
+func AddEdbInfoPermissionNoAuthRecordBySourceAndDataIdList(source, edbInfoType int, dataList []DataItem, noAuthUserIdList, authUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+	num := len(dataList)
+	if num <= 0 {
+		return
+	}
+	dataIdList := make([]int, 0)
+	for _, v := range dataList {
+		dataIdList = append(dataIdList, v.DataId)
+	}
+	userNum := len(noAuthUserIdList)
+	if userNum <= 0 {
+		return
+	}
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+
+	// 根据指标获取已经存在的未授权记录
+	var existList []*EdbInfoPermissionNoAuthRecord
+	sql := `SELECT * FROM edb_info_permission_no_auth_record WHERE  edb_info_type = ? AND edb_info_id in (` + utils.GetOrmInReplace(num) + `)`
+	_, err = o.Raw(sql, edbInfoType, dataIdList).QueryRows(&existList)
+	if err != nil {
+		return
+	}
+
+	// 已经标记了的数据
+	existMap := make(map[int32]map[string]*EdbInfoPermissionNoAuthRecord)
+	for _, v := range existList {
+		tmpUserExistMap, ok := existMap[v.SysUserId]
+		if !ok {
+			tmpUserExistMap = make(map[string]*EdbInfoPermissionNoAuthRecord)
+		}
+
+		key := fmt.Sprint(v.EdbInfoType, "_", v.EdbInfoId)
+		tmpUserExistMap[key] = v
+		existMap[v.SysUserId] = tmpUserExistMap
+	}
+
+	addMessageList := make([]*DataPermissionMessage, 0)
+	addRecordList := make([]*EdbInfoPermissionNoAuthRecord, 0)
+	for _, userId := range noAuthUserIdList {
+		isAdd := false
+
+		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+
+		for _, dataItem := range dataList {
+			// 判断是否已经存在,已经存在就过滤
+			if userExistOk {
+				key := fmt.Sprint(edbInfoType, "_", dataItem.DataId)
+				_, ok := tmpUserExistMap[key]
+				if ok {
+					continue
+				}
+			}
+
+			isAdd = true
+			addRecordList = append(addRecordList, &EdbInfoPermissionNoAuthRecord{
+				EdbInfoPermissionNoAuthRecordId: 0,
+				OpUniqueCode:                    uniqueCode,
+				EdbInfoType:                     int32(edbInfoType),
+				EdbInfoId:                       int32(dataItem.DataId),
+				EdbCode:                         dataItem.DataCode,
+				EdbName:                         dataItem.DataName,
+				SysUserId:                       int32(userId),
+				CreateTime:                      time.Now(),
+			})
+		}
+
+		// 有记录的话,需要添加消息
+		if isAdd {
+			addMessageList = append(addMessageList, &DataPermissionMessage{
+				DataPermissionMessageId: 0,
+				SendUserId:              int32(opUserId),
+				ReceiveUserId:           int32(userId),
+				Content:                 content,
+				Remark:                  content,
+				OpType:                  3,
+				Source:                  int32(source),
+				SubSource:               int32(edbInfoType),
+				OpUniqueCode:            uniqueCode,
+				IsRead:                  0,
+				CreateTime:              time.Now(),
+				ModifyTime:              time.Now(),
+			})
+		}
+	}
+
+	// 添加消息
+	if len(addMessageList) > 0 {
+		_, err = o.InsertMulti(500, addMessageList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 添加记录
+	if len(addRecordList) > 0 {
+		_, err = o.InsertMulti(500, addRecordList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 已经授权了的用户,需要删除未授权记录
+	authUserIdNum := len(authUserIdList)
+	if authUserIdNum > 0 {
+		sql = `DELETE FROM edb_info_permission_no_auth_record WHERE  edb_info_type = ? AND sys_user_id in (` + utils.GetOrmInReplace(authUserIdNum) + `) AND edb_info_id in (` + utils.GetOrmInReplace(num) + `)`
+		_, err = o.Raw(sql, edbInfoType, authUserIdList, dataIdList).Exec()
+	}
+
+	return
+}
+
+// DeleteEdbInfoPermissionNoAuthRecordBySourceAndDataIdList
+// @Description: 根据来源和数据id列表删除记录
+// @author: Roc
+// @datetime 2024-04-07 14:47:37
+// @param source int
+// @param subSource int
+// @param dataIdList []string
+// @return err error
+func DeleteEdbInfoPermissionNoAuthRecordBySourceAndDataIdList(edbInfoType int, dataIdList []string) (err error) {
+	num := len(dataIdList)
+	if num <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("data")
+
+	sql := `DELETE FROM edb_info_permission_no_auth_record WHERE edb_info_type = ? AND edb_info_id in (` + utils.GetOrmInReplace(num) + `)`
+	_, err = o.Raw(sql, edbInfoType, dataIdList).Exec()
+
+	return
+}
+
+// GetEdbInfoDataPermissionNoAuthRecordListByUserId
+// @Description: 获取明细数据
+// @author: Roc
+// @datetime 2024-04-10 14:23:15
+// @param userId int32
+// @param edbInfoType int32
+// @param startSize int
+// @param pageSize int
+// @return total int
+// @return items []*DataPermissionNoAuthRecord
+// @return err error
+func GetEdbInfoDataPermissionNoAuthRecordListByUserId(userId int32, edbInfoType, startSize, pageSize int) (total int, items []*DataPermissionNoAuthRecord, err error) {
+	o := orm.NewOrmUsingDB("data")
+
+	// 获取总数
+	sql := `SELECT count(1) AS total FROM edb_info_permission_no_auth_record WHERE sys_user_id = ? AND edb_info_type = ? `
+	err = o.Raw(sql, userId, edbInfoType).QueryRow(&total)
+	if err != nil {
+		return
+	}
+
+	sql = `SELECT edb_info_permission_no_auth_record_id as data_permission_no_auth_record_id,op_unique_code,edb_info_type as sub_source,edb_info_id as data_id,edb_code as data_code,edb_name as data_name,sys_user_id,create_time FROM edb_info_permission_no_auth_record WHERE sys_user_id = ? AND edb_info_type = ? ORDER BY edb_info_permission_no_auth_record_id desc LIMIT ?,? `
+	_, err = o.Raw(sql, userId, edbInfoType, startSize, pageSize).QueryRows(&items)
+
+	return
+}
+
+type EdbInfoClassifyPermissionNoAuthRecord struct {
+	EdbInfoClassifyPermissionNoAuthRecordId int64     `json:"edb_info_classify_permission_no_auth_record_id" orm:"column(edb_info_classify_permission_no_auth_record_id);pk"` // 资产分类数据操作记录id
+	EdbClassifyType                         int32     `json:"edb_classify_type"`                                                                                              // 子来源 :ETA表格中的各种表格类型,以及图表的来源(这个是后续的扩展方向)
+	OpUniqueCode                            string    `json:"op_unique_code"`                                                                                                 // 操作的唯一编码,主要是记录统一操作的日志
+	ClassifyId                              string    `json:"classify_id"`                                                                                                    // 资产分类id(指标、图表、表格)
+	ClassifyName                            string    `json:"classify_name"`                                                                                                  // 资产分类名称(指标、图表、表格)
+	SysUserId                               int32     `json:"sys_user_id"`                                                                                                    // 系统用户id
+	CreateTime                              time.Time `json:"create_time"`                                                                                                    // 创建时间
+}
+
+// AddEdbInfoClassifyNoAuthRecordBySourceAndClassifyIdList
+// @Description: 根据分类添加用户分类未授权记录
+// @author: Roc
+// @datetime 2024-04-07 16:44:21
+// @param source int
+// @param edbClassifyType int
+// @param classifyInfoList []ClassifyDataItem
+// @param noAuthUserIdList []int
+// @param uniqueCode string
+// @param content string
+// @param opUserId int
+// @return err error
+func AddEdbInfoClassifyNoAuthRecordBySourceAndClassifyIdList(source, edbClassifyType int, classifyInfoList []ClassifyDataItem, noAuthUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+	num := len(classifyInfoList)
+	if num <= 0 {
+		return
+	}
+	// 分类id
+	classifyIdList := make([]int, 0)
+	for _, v := range classifyInfoList {
+		classifyIdList = append(classifyIdList, v.ClassifyId)
+	}
+
+	userNum := len(noAuthUserIdList)
+	if userNum <= 0 {
+		return
+	}
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+
+	// 根据分类获取已经存在的未授权记录
+	var existList []*EdbInfoClassifyPermissionNoAuthRecord
+	sql := `SELECT * FROM edb_info_classify_permission_no_auth_record WHERE edb_classify_type = ? AND classify_id in (` + utils.GetOrmInReplace(num) + `)`
+	_, err = o.Raw(sql, edbClassifyType, classifyIdList).QueryRows(&existList)
+	if err != nil {
+		return
+	}
+
+	// 已经标记了的数据
+	existMap := make(map[int32]map[string]*EdbInfoClassifyPermissionNoAuthRecord)
+	for _, v := range existList {
+		tmpUserExistMap, ok := existMap[v.SysUserId]
+		if !ok {
+			tmpUserExistMap = make(map[string]*EdbInfoClassifyPermissionNoAuthRecord)
+		}
+
+		key := fmt.Sprint(v.EdbClassifyType, "_", v.ClassifyId)
+		tmpUserExistMap[key] = v
+		existMap[v.SysUserId] = tmpUserExistMap
+	}
+
+	addMessageList := make([]*DataPermissionMessage, 0)
+	addRecordList := make([]*EdbInfoClassifyPermissionNoAuthRecord, 0)
+	for _, userId := range noAuthUserIdList {
+		isAdd := false
+
+		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+
+		for _, dataItem := range classifyInfoList {
+			// 判断是否已经存在,已经存在就过滤
+			if userExistOk {
+				key := fmt.Sprint(edbClassifyType, "_", dataItem.ClassifyId)
+				_, ok := tmpUserExistMap[key]
+				if ok {
+					continue
+				}
+			}
+
+			isAdd = true
+			addRecordList = append(addRecordList, &EdbInfoClassifyPermissionNoAuthRecord{
+				EdbInfoClassifyPermissionNoAuthRecordId: 0,
+				EdbClassifyType:                         int32(edbClassifyType),
+				OpUniqueCode:                            uniqueCode,
+				ClassifyId:                              fmt.Sprint(dataItem.ClassifyId),
+				ClassifyName:                            dataItem.ClassifyName,
+				SysUserId:                               int32(userId),
+				CreateTime:                              time.Now(),
+			})
+		}
+
+		// 有记录的话,需要添加消息
+		if isAdd {
+			addMessageList = append(addMessageList, &DataPermissionMessage{
+				DataPermissionMessageId: 0,
+				SendUserId:              int32(opUserId),
+				ReceiveUserId:           int32(userId),
+				Content:                 content,
+				Remark:                  content,
+				OpType:                  4,
+				Source:                  int32(source),
+				SubSource:               int32(edbClassifyType),
+				OpUniqueCode:            uniqueCode,
+				IsRead:                  0,
+				CreateTime:              time.Now(),
+				ModifyTime:              time.Now(),
+			})
+		}
+	}
+
+	// 添加消息
+	if len(addMessageList) > 0 {
+		_, err = o.InsertMulti(500, addMessageList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 添加记录
+	if len(addRecordList) > 0 {
+		_, err = o.InsertMulti(500, addRecordList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 移除已经公开了的分类权限,需要删除未授权记录
+	authUserIdNum := len(classifyIdList)
+	if authUserIdNum > 0 {
+		sql = `DELETE FROM edb_info_classify_permission_no_auth_record WHERE edb_classify_type = ? AND classify_id not in (` + utils.GetOrmInReplace(num) + `)`
+		_, err = o.Raw(sql, edbClassifyType, classifyIdList).Exec()
+	}
+
+	return
+}
+
+// AddEdbInfoClassifyNoAuthRecordBySourceAndUserIdList
+// @Description: 根据用户添加用户分类未授权记录
+// @author: Roc
+// @datetime 2024-04-07 20:12:44
+// @param source int
+// @param edbClassifyType int
+// @param noAuthClassifyMap map[int]ClassifyDataItem
+// @param configUserIdList []int
+// @param uniqueCode string
+// @param content string
+// @param opUserId int
+// @return err error
+func AddEdbInfoClassifyNoAuthRecordBySourceAndUserIdList(source, edbClassifyType int, noAuthClassifyMap map[int]ClassifyDataItem, configUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+	// 当前配置用户
+	configUserNum := len(configUserIdList)
+	if configUserNum <= 0 {
+		return
+	}
+
+	//// 总共的涉密分类
+	//noAuthClassifyInfoNum := len(noAuthClassifyMap)
+	//if noAuthClassifyInfoNum <= 0 {
+	//	return
+	//}
+
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+
+	// 根据当前配置用户获取已经存在的未授权记录
+	var existList []*EdbInfoClassifyPermissionNoAuthRecord
+	sql := `SELECT * FROM edb_info_classify_permission_no_auth_record WHERE edb_classify_type = ? AND sys_user_id in (` + utils.GetOrmInReplace(configUserNum) + `)`
+	_, err = o.Raw(sql, edbClassifyType, configUserIdList).QueryRows(&existList)
+	if err != nil {
+		return
+	}
+
+	// 已经标记了的数据
+	existMap := make(map[int32]map[string]*EdbInfoClassifyPermissionNoAuthRecord)
+	delRecordIdMap := make(map[int64]int64)
+	for _, v := range existList {
+		tmpUserExistMap, ok := existMap[v.SysUserId]
+		if !ok {
+			tmpUserExistMap = make(map[string]*EdbInfoClassifyPermissionNoAuthRecord)
+		}
+
+		tmpUserExistMap[v.ClassifyId] = v
+		existMap[v.SysUserId] = tmpUserExistMap
+
+		// 已经配置了的记录id
+		delRecordIdMap[v.EdbInfoClassifyPermissionNoAuthRecordId] = v.EdbInfoClassifyPermissionNoAuthRecordId
+	}
+
+	addMessageList := make([]*DataPermissionMessage, 0)
+	addRecordList := make([]*EdbInfoClassifyPermissionNoAuthRecord, 0)
+	for _, userId := range configUserIdList {
+		isAdd := false
+
+		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+
+		for _, dataItem := range noAuthClassifyMap {
+			// 判断是否已经存在,已经存在就过滤
+			if userExistOk {
+				key := fmt.Sprint(dataItem.ClassifyId)
+				tmpUserRecord, ok := tmpUserExistMap[key]
+				if ok {
+					delete(delRecordIdMap, tmpUserRecord.EdbInfoClassifyPermissionNoAuthRecordId)
+					continue
+				}
+			}
+
+			isAdd = true
+			addRecordList = append(addRecordList, &EdbInfoClassifyPermissionNoAuthRecord{
+				EdbInfoClassifyPermissionNoAuthRecordId: 0,
+				EdbClassifyType:                         int32(edbClassifyType),
+				OpUniqueCode:                            uniqueCode,
+				ClassifyId:                              fmt.Sprint(dataItem.ClassifyId),
+				ClassifyName:                            dataItem.ClassifyName,
+				SysUserId:                               int32(userId),
+				CreateTime:                              time.Now(),
+			})
+		}
+
+		// 有记录的话,需要添加消息
+		if isAdd {
+			addMessageList = append(addMessageList, &DataPermissionMessage{
+				DataPermissionMessageId: 0,
+				SendUserId:              int32(opUserId),
+				ReceiveUserId:           int32(userId),
+				Content:                 content,
+				Remark:                  content,
+				OpType:                  4,
+				Source:                  int32(source),
+				SubSource:               int32(edbClassifyType),
+				OpUniqueCode:            uniqueCode,
+				IsRead:                  0,
+				CreateTime:              time.Now(),
+				ModifyTime:              time.Now(),
+			})
+		}
+	}
+
+	// 添加消息
+	if len(addMessageList) > 0 {
+		_, err = o.InsertMulti(500, addMessageList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 添加记录
+	if len(addRecordList) > 0 {
+		_, err = o.InsertMulti(500, addRecordList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 需要删除未授权记录
+	delRecordIdNum := len(delRecordIdMap)
+	if delRecordIdNum > 0 {
+		delRecordIdList := make([]int64, 0)
+		for _, v := range delRecordIdMap {
+			delRecordIdList = append(delRecordIdList, v)
+		}
+		sql = `DELETE FROM edb_info_classify_permission_no_auth_record WHERE edb_info_classify_permission_no_auth_record_id in (` + utils.GetOrmInReplace(delRecordIdNum) + `) `
+		_, err = o.Raw(sql, delRecordIdList).Exec()
+	}
+
+	return
+}
+
+// DeleteEdbInfoClassifyNoAuthRecordBySourceAndClassifyIdList
+// @Description: 根据来源和删除分类授权记录
+// @author: Roc
+// @datetime 2024-04-07 14:47:37
+// @param source int
+// @param edbClassifyType int
+// @return err error
+func DeleteEdbInfoClassifyNoAuthRecordBySourceAndClassifyIdList(edbClassifyType int) (err error) {
+	o := orm.NewOrmUsingDB("data")
+
+	sql := `DELETE FROM edb_info_classify_permission_no_auth_record WHERE edb_classify_type = ?`
+	_, err = o.Raw(sql, edbClassifyType).Exec()
+
+	return
+}
+
+// GetEdbInfoDataPermissionClassifyNoAuthRecordListByUserId
+// @Description: 根据用户获取未授权的资产分类记录
+// @author: Roc
+// @datetime 2024-04-07 20:14:49
+// @param userId int
+// @param source int
+// @param subSource int
+// @param startSize int
+// @param pageSize int
+// @return total int
+// @return items []*DataPermissionClassifyNoAuthRecord
+// @return err error
+func GetEdbInfoDataPermissionClassifyNoAuthRecordListByUserId(userId int32, edbClassifyType, startSize, pageSize int) (total int, items []*DataPermissionClassifyNoAuthRecord, err error) {
+	o := orm.NewOrmUsingDB("data")
+
+	// 获取总数
+	sql := `SELECT count(1) AS total FROM edb_info_classify_permission_no_auth_record WHERE sys_user_id = ? AND edb_classify_type = ? `
+	err = o.Raw(sql, userId, edbClassifyType).QueryRow(&total)
+	if err != nil {
+		return
+	}
+
+	sql = `SELECT edb_info_classify_permission_no_auth_record_id as data_permission_classify_no_auth_record_id,edb_classify_type as sub_source,op_unique_code,classify_id,classify_name,sys_user_id,create_time  FROM edb_info_classify_permission_no_auth_record WHERE sys_user_id = ? AND edb_classify_type = ? ORDER BY edb_info_classify_permission_no_auth_record_id desc LIMIT ?,? `
+	_, err = o.Raw(sql, userId, edbClassifyType, startSize, pageSize).QueryRows(&items)
+
+	return
+}

+ 519 - 11
models/data_manage/data_manage_permission/excel.go

@@ -405,21 +405,20 @@ func InheritParentClassifyByExcelClassifyId(dataSource, excelSource, classifyId,
 	// 添加未授权记录
 	{
 		// 获取父级未授权的用户记录
-		var parentRecordItems []*DataPermissionClassifyNoAuthRecord
+		var parentRecordItems []*ExcelInfoClassifyPermissionNoAuthRecord
 		sql = `SELECT * FROM data_permission_classify_no_auth_record WHERE classify_id = ? AND source = ? AND sub_source = ? ORDER BY data_permission_classify_no_auth_record_id desc LIMIT ?,? `
 		_, err = o.Raw(sql, parentClassifyId, dataSource, excelSource).QueryRows(&parentRecordItems)
 
-		addNoAuthRecordItems := make([]*DataPermissionClassifyNoAuthRecord, 0)
+		addNoAuthRecordItems := make([]*ExcelInfoClassifyPermissionNoAuthRecord, 0)
 		for _, v := range parentRecordItems {
-			addNoAuthRecordItems = append(addNoAuthRecordItems, &DataPermissionClassifyNoAuthRecord{
-				DataPermissionClassifyNoAuthRecordId: 0,
-				Source:                               v.Source,
-				SubSource:                            v.SubSource,
-				OpUniqueCode:                         uniqueCode,
-				ClassifyId:                           fmt.Sprint(classifyId),
-				ClassifyName:                         classifyName,
-				SysUserId:                            v.SysUserId,
-				CreateTime:                           time.Now(),
+			addNoAuthRecordItems = append(addNoAuthRecordItems, &ExcelInfoClassifyPermissionNoAuthRecord{
+				ExcelInfoClassifyPermissionNoAuthRecordId: 0,
+				Source:       v.Source,
+				OpUniqueCode: uniqueCode,
+				ClassifyId:   fmt.Sprint(classifyId),
+				ClassifyName: classifyName,
+				SysUserId:    v.SysUserId,
+				CreateTime:   time.Now(),
 			})
 		}
 
@@ -466,3 +465,512 @@ func InheritParentClassifyByExcelClassifyId(dataSource, excelSource, classifyId,
 
 	return
 }
+
+// ExcelInfoPermissionNoAuthRecord
+// @Description: ETA表格数据权限未授权记录表
+type ExcelInfoPermissionNoAuthRecord struct {
+	ExcelInfoPermissionNoAuthRecordId int64     `json:"excel_info_permission_no_auth_record_id"  orm:"column(excel_info_permission_no_auth_record_id);pk"` // 资产数据操作记录id
+	OpUniqueCode                      string    `json:"op_unique_code"`                                                                                    // 操作的唯一编码,主要是记录统一操作的日志
+	Source                            int32     `json:"source"`                                                                                            // 表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1
+	ExcelInfoId                       int32     `json:"excel_info_id"`                                                                                     // 指标id
+	ExcelName                         string    `json:"excel_name"`                                                                                        // 图表名称
+	SysUserId                         int32     `json:"sys_user_id"`                                                                                       // 系统用户id
+	CreateTime                        time.Time `json:"create_time"`                                                                                       // 创建时间
+}
+
+// AddExcelInfoPermissionNoAuthRecordBySourceAndDataIdList
+// @Description: 添加未授权用户记录
+// @author: Roc
+// @datetime 2024-04-07 15:25:49
+// @param source int
+// @param excelSource int
+// @param dataList []DataItem
+// @param noAuthUserIdList []int 未授权用户
+// @param authUserIdList []int 已授权用户
+// @param uniqueCode
+// @param content string
+// @param opUserId int
+// @return err error
+func AddExcelInfoPermissionNoAuthRecordBySourceAndDataIdList(source, excelSource int, dataList []DataItem, noAuthUserIdList, authUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+	num := len(dataList)
+	if num <= 0 {
+		return
+	}
+	dataIdList := make([]int, 0)
+	for _, v := range dataList {
+		dataIdList = append(dataIdList, v.DataId)
+	}
+	userNum := len(noAuthUserIdList)
+	if userNum <= 0 {
+		return
+	}
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+
+	// 根据指标获取已经存在的未授权记录
+	var existList []*ExcelInfoPermissionNoAuthRecord
+	sql := `SELECT * FROM excel_info_permission_no_auth_record WHERE  source = ? AND excel_info_id in (` + utils.GetOrmInReplace(num) + `)`
+	_, err = o.Raw(sql, excelSource, dataIdList).QueryRows(&existList)
+	if err != nil {
+		return
+	}
+
+	// 已经标记了的数据
+	existMap := make(map[int32]map[string]*ExcelInfoPermissionNoAuthRecord)
+	for _, v := range existList {
+		tmpUserExistMap, ok := existMap[v.SysUserId]
+		if !ok {
+			tmpUserExistMap = make(map[string]*ExcelInfoPermissionNoAuthRecord)
+		}
+
+		key := fmt.Sprint(v.Source, "_", v.ExcelInfoId)
+		tmpUserExistMap[key] = v
+		existMap[v.SysUserId] = tmpUserExistMap
+	}
+
+	addMessageList := make([]*DataPermissionMessage, 0)
+	addRecordList := make([]*ExcelInfoPermissionNoAuthRecord, 0)
+	for _, userId := range noAuthUserIdList {
+		isAdd := false
+
+		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+
+		for _, dataItem := range dataList {
+			// 判断是否已经存在,已经存在就过滤
+			if userExistOk {
+				key := fmt.Sprint(excelSource, "_", dataItem.DataId)
+				_, ok := tmpUserExistMap[key]
+				if ok {
+					continue
+				}
+			}
+
+			isAdd = true
+			addRecordList = append(addRecordList, &ExcelInfoPermissionNoAuthRecord{
+				ExcelInfoPermissionNoAuthRecordId: 0,
+				OpUniqueCode:                      uniqueCode,
+				Source:                            int32(excelSource),
+				ExcelInfoId:                       int32(dataItem.DataId),
+				ExcelName:                         dataItem.DataName,
+				SysUserId:                         int32(userId),
+				CreateTime:                        time.Now(),
+			})
+		}
+
+		// 有记录的话,需要添加消息
+		if isAdd {
+			addMessageList = append(addMessageList, &DataPermissionMessage{
+				DataPermissionMessageId: 0,
+				SendUserId:              int32(opUserId),
+				ReceiveUserId:           int32(userId),
+				Content:                 content,
+				Remark:                  content,
+				OpType:                  3,
+				Source:                  int32(source),
+				SubSource:               int32(excelSource),
+				OpUniqueCode:            uniqueCode,
+				IsRead:                  0,
+				CreateTime:              time.Now(),
+				ModifyTime:              time.Now(),
+			})
+		}
+	}
+
+	// 添加消息
+	if len(addMessageList) > 0 {
+		_, err = o.InsertMulti(500, addMessageList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 添加记录
+	if len(addRecordList) > 0 {
+		_, err = o.InsertMulti(500, addRecordList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 已经授权了的用户,需要删除未授权记录
+	authUserIdNum := len(authUserIdList)
+	if authUserIdNum > 0 {
+		sql = `DELETE FROM excel_info_permission_no_auth_record WHERE  source = ? AND sys_user_id in (` + utils.GetOrmInReplace(authUserIdNum) + `) AND excel_info_id in (` + utils.GetOrmInReplace(num) + `)`
+		_, err = o.Raw(sql, excelSource, authUserIdList, dataIdList).Exec()
+	}
+
+	return
+}
+
+// DeleteExcelInfoPermissionNoAuthRecordBySourceAndDataIdList
+// @Description: 根据来源和数据id列表删除记录
+// @author: Roc
+// @datetime 2024-04-07 14:47:37
+// @param excelSource int
+// @param dataIdList []string
+// @return err error
+func DeleteExcelInfoPermissionNoAuthRecordBySourceAndDataIdList(excelSource int, dataIdList []string) (err error) {
+	num := len(dataIdList)
+	if num <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("data")
+
+	sql := `DELETE FROM excel_info_permission_no_auth_record WHERE source = ? AND excel_info_id in (` + utils.GetOrmInReplace(num) + `)`
+	_, err = o.Raw(sql, excelSource, dataIdList).Exec()
+
+	return
+}
+
+func GetExcelInfoDataPermissionNoAuthRecordListByUserId(userId, excelSource int32, startSize, pageSize int) (total int, items []*DataPermissionNoAuthRecord, err error) {
+	o := orm.NewOrmUsingDB("data")
+
+	// 获取总数
+	sql := `SELECT count(1) AS total FROM excel_info_permission_no_auth_record WHERE sys_user_id = ? AND source = ? `
+	err = o.Raw(sql, userId, excelSource).QueryRow(&total)
+	if err != nil {
+		return
+	}
+
+	sql = `SELECT excel_info_permission_no_auth_record_id as data_permission_no_auth_record_id,op_unique_code,source as sub_source,excel_info_id as data_id,excel_name as data_name,sys_user_id,create_time FROM excel_info_permission_no_auth_record WHERE sys_user_id = ? AND source = ? ORDER BY excel_info_permission_no_auth_record_id desc LIMIT ?,? `
+	_, err = o.Raw(sql, userId, excelSource, startSize, pageSize).QueryRows(&items)
+
+	return
+}
+
+type ExcelInfoClassifyPermissionNoAuthRecord struct {
+	ExcelInfoClassifyPermissionNoAuthRecordId int64     `json:"excel_info_classify_permission_no_auth_record_id" orm:"column(excel_info_classify_permission_no_auth_record_id);pk"` // 资产分类数据操作记录id
+	Source                                    int32     `json:"source"`                                                                                                             // 子来源 :ETA表格中的各种表格类型,以及图表的来源(这个是后续的扩展方向)
+	OpUniqueCode                              string    `json:"op_unique_code"`                                                                                                     // 操作的唯一编码,主要是记录统一操作的日志
+	ClassifyId                                string    `json:"classify_id"`                                                                                                        // ETA表格资产分类id
+	ClassifyName                              string    `json:"classify_name"`                                                                                                      // ETA表格资产分类名称
+	SysUserId                                 int32     `json:"sys_user_id"`                                                                                                        // 系统用户id
+	CreateTime                                time.Time `json:"create_time"`                                                                                                        // 创建时间
+}
+
+// AddExcelInfoClassifyNoAuthRecordBySourceAndClassifyIdList
+// @Description: 根据分类添加用户分类未授权记录
+// @author: Roc
+// @datetime 2024-04-07 16:44:21
+// @param source int
+// @param excelSource int
+// @param classifyInfoList []ClassifyDataItem
+// @param noAuthUserIdList []int
+// @param uniqueCode string
+// @param content string
+// @param opUserId int
+// @return err error
+func AddExcelInfoClassifyNoAuthRecordBySourceAndClassifyIdList(source, excelSource int, classifyInfoList []ClassifyDataItem, noAuthUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+	num := len(classifyInfoList)
+	if num <= 0 {
+		return
+	}
+	// 分类id
+	classifyIdList := make([]int, 0)
+	for _, v := range classifyInfoList {
+		classifyIdList = append(classifyIdList, v.ClassifyId)
+	}
+
+	userNum := len(noAuthUserIdList)
+	if userNum <= 0 {
+		return
+	}
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+
+	// 根据分类获取已经存在的未授权记录
+	var existList []*ExcelInfoClassifyPermissionNoAuthRecord
+	sql := `SELECT * FROM excel_info_classify_permission_no_auth_record WHERE source = ? AND classify_id in (` + utils.GetOrmInReplace(num) + `)`
+	_, err = o.Raw(sql, excelSource, classifyIdList).QueryRows(&existList)
+	if err != nil {
+		return
+	}
+
+	// 已经标记了的数据
+	existMap := make(map[int32]map[string]*ExcelInfoClassifyPermissionNoAuthRecord)
+	for _, v := range existList {
+		tmpUserExistMap, ok := existMap[v.SysUserId]
+		if !ok {
+			tmpUserExistMap = make(map[string]*ExcelInfoClassifyPermissionNoAuthRecord)
+		}
+
+		key := fmt.Sprint(v.Source, "_", v.ClassifyId)
+		tmpUserExistMap[key] = v
+		existMap[v.SysUserId] = tmpUserExistMap
+	}
+
+	addMessageList := make([]*DataPermissionMessage, 0)
+	addRecordList := make([]*ExcelInfoClassifyPermissionNoAuthRecord, 0)
+	for _, userId := range noAuthUserIdList {
+		isAdd := false
+
+		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+
+		for _, dataItem := range classifyInfoList {
+			// 判断是否已经存在,已经存在就过滤
+			if userExistOk {
+				key := fmt.Sprint(excelSource, "_", dataItem.ClassifyId)
+				_, ok := tmpUserExistMap[key]
+				if ok {
+					continue
+				}
+			}
+
+			isAdd = true
+			addRecordList = append(addRecordList, &ExcelInfoClassifyPermissionNoAuthRecord{
+				ExcelInfoClassifyPermissionNoAuthRecordId: 0,
+				Source:       int32(excelSource),
+				OpUniqueCode: uniqueCode,
+				ClassifyId:   fmt.Sprint(dataItem.ClassifyId),
+				ClassifyName: dataItem.ClassifyName,
+				SysUserId:    int32(userId),
+				CreateTime:   time.Now(),
+			})
+		}
+
+		// 有记录的话,需要添加消息
+		if isAdd {
+			addMessageList = append(addMessageList, &DataPermissionMessage{
+				DataPermissionMessageId: 0,
+				SendUserId:              int32(opUserId),
+				ReceiveUserId:           int32(userId),
+				Content:                 content,
+				Remark:                  content,
+				OpType:                  4,
+				Source:                  int32(source),
+				SubSource:               int32(excelSource),
+				OpUniqueCode:            uniqueCode,
+				IsRead:                  0,
+				CreateTime:              time.Now(),
+				ModifyTime:              time.Now(),
+			})
+		}
+	}
+
+	// 添加消息
+	if len(addMessageList) > 0 {
+		_, err = o.InsertMulti(500, addMessageList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 添加记录
+	if len(addRecordList) > 0 {
+		_, err = o.InsertMulti(500, addRecordList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 移除已经公开了的分类权限,需要删除未授权记录
+	authUserIdNum := len(classifyIdList)
+	if authUserIdNum > 0 {
+		sql = `DELETE FROM excel_info_classify_permission_no_auth_record WHERE source = ? AND classify_id not in (` + utils.GetOrmInReplace(num) + `)`
+		_, err = o.Raw(sql, excelSource, classifyIdList).Exec()
+	}
+
+	return
+}
+
+// AddExcelInfoClassifyNoAuthRecordBySourceAndUserIdList
+// @Description: 根据用户添加用户分类未授权记录
+// @author: Roc
+// @datetime 2024-04-07 20:12:44
+// @param source int
+// @param excelSource int
+// @param noAuthClassifyMap map[int]ClassifyDataItem
+// @param configUserIdList []int
+// @param uniqueCode string
+// @param content string
+// @param opUserId int
+// @return err error
+func AddExcelInfoClassifyNoAuthRecordBySourceAndUserIdList(source, excelSource int, noAuthClassifyMap map[int]ClassifyDataItem, configUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+	// 当前配置用户
+	configUserNum := len(configUserIdList)
+	if configUserNum <= 0 {
+		return
+	}
+
+	//// 总共的涉密分类
+	//noAuthClassifyInfoNum := len(noAuthClassifyMap)
+	//if noAuthClassifyInfoNum <= 0 {
+	//	return
+	//}
+
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+
+	// 根据当前配置用户获取已经存在的未授权记录
+	var existList []*ExcelInfoClassifyPermissionNoAuthRecord
+	sql := `SELECT * FROM excel_info_classify_permission_no_auth_record WHERE source = ? AND sys_user_id in (` + utils.GetOrmInReplace(configUserNum) + `)`
+	_, err = o.Raw(sql, excelSource, configUserIdList).QueryRows(&existList)
+	if err != nil {
+		return
+	}
+
+	// 已经标记了的数据
+	existMap := make(map[int32]map[string]*ExcelInfoClassifyPermissionNoAuthRecord)
+	delRecordIdMap := make(map[int64]int64)
+	for _, v := range existList {
+		tmpUserExistMap, ok := existMap[v.SysUserId]
+		if !ok {
+			tmpUserExistMap = make(map[string]*ExcelInfoClassifyPermissionNoAuthRecord)
+		}
+
+		tmpUserExistMap[v.ClassifyId] = v
+		existMap[v.SysUserId] = tmpUserExistMap
+
+		// 已经配置了的记录id
+		delRecordIdMap[v.ExcelInfoClassifyPermissionNoAuthRecordId] = v.ExcelInfoClassifyPermissionNoAuthRecordId
+	}
+
+	addMessageList := make([]*DataPermissionMessage, 0)
+	addRecordList := make([]*ExcelInfoClassifyPermissionNoAuthRecord, 0)
+	for _, userId := range configUserIdList {
+		isAdd := false
+
+		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+
+		for _, dataItem := range noAuthClassifyMap {
+			// 判断是否已经存在,已经存在就过滤
+			if userExistOk {
+				key := fmt.Sprint(dataItem.ClassifyId)
+				tmpUserRecord, ok := tmpUserExistMap[key]
+				if ok {
+					delete(delRecordIdMap, tmpUserRecord.ExcelInfoClassifyPermissionNoAuthRecordId)
+					continue
+				}
+			}
+
+			isAdd = true
+			addRecordList = append(addRecordList, &ExcelInfoClassifyPermissionNoAuthRecord{
+				ExcelInfoClassifyPermissionNoAuthRecordId: 0,
+				Source:       int32(excelSource),
+				OpUniqueCode: uniqueCode,
+				ClassifyId:   fmt.Sprint(dataItem.ClassifyId),
+				ClassifyName: dataItem.ClassifyName,
+				SysUserId:    int32(userId),
+				CreateTime:   time.Now(),
+			})
+		}
+
+		// 有记录的话,需要添加消息
+		if isAdd {
+			addMessageList = append(addMessageList, &DataPermissionMessage{
+				DataPermissionMessageId: 0,
+				SendUserId:              int32(opUserId),
+				ReceiveUserId:           int32(userId),
+				Content:                 content,
+				Remark:                  content,
+				OpType:                  4,
+				Source:                  int32(source),
+				SubSource:               int32(excelSource),
+				OpUniqueCode:            uniqueCode,
+				IsRead:                  0,
+				CreateTime:              time.Now(),
+				ModifyTime:              time.Now(),
+			})
+		}
+	}
+
+	// 添加消息
+	if len(addMessageList) > 0 {
+		_, err = o.InsertMulti(500, addMessageList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 添加记录
+	if len(addRecordList) > 0 {
+		_, err = o.InsertMulti(500, addRecordList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 需要删除未授权记录
+	delRecordIdNum := len(delRecordIdMap)
+	if delRecordIdNum > 0 {
+		delRecordIdList := make([]int64, 0)
+		for _, v := range delRecordIdMap {
+			delRecordIdList = append(delRecordIdList, v)
+		}
+		sql = `DELETE FROM excel_info_classify_permission_no_auth_record WHERE excel_info_classify_permission_no_auth_record_id in (` + utils.GetOrmInReplace(delRecordIdNum) + `) `
+		_, err = o.Raw(sql, delRecordIdList).Exec()
+	}
+
+	return
+}
+
+// DeleteExcelInfoClassifyNoAuthRecordBySourceAndClassifyIdList
+// @Description: 根据来源和删除分类授权记录
+// @author: Roc
+// @datetime 2024-04-07 14:47:37
+// @param source int
+// @param excelSource int
+// @return err error
+func DeleteExcelInfoClassifyNoAuthRecordBySourceAndClassifyIdList(excelSource int) (err error) {
+	o := orm.NewOrmUsingDB("data")
+
+	sql := `DELETE FROM excel_info_classify_permission_no_auth_record WHERE source = ?`
+	_, err = o.Raw(sql, excelSource).Exec()
+
+	return
+}
+
+// GetExcelInfoDataPermissionClassifyNoAuthRecordListByUserId
+// @Description: 根据用户获取未授权的资产分类记录
+// @author: Roc
+// @datetime 2024-04-07 20:14:49
+// @param userId int
+// @param source int
+// @param subSource int
+// @param startSize int
+// @param pageSize int
+// @return total int
+// @return items []*DataPermissionClassifyNoAuthRecord
+// @return err error
+func GetExcelInfoDataPermissionClassifyNoAuthRecordListByUserId(userId, excelSource int32, startSize, pageSize int) (total int, items []*DataPermissionClassifyNoAuthRecord, err error) {
+	o := orm.NewOrmUsingDB("data")
+
+	// 获取总数
+	sql := `SELECT count(1) AS total FROM excel_info_classify_permission_no_auth_record WHERE sys_user_id = ? AND source = ? `
+	err = o.Raw(sql, userId, excelSource).QueryRow(&total)
+	if err != nil {
+		return
+	}
+
+	sql = `SELECT excel_info_classify_permission_no_auth_record_id as data_permission_classify_no_auth_record_id,source as sub_source,op_unique_code,classify_id,classify_name,sys_user_id,create_time  FROM excel_info_classify_permission_no_auth_record WHERE sys_user_id = ? AND source = ? ORDER BY excel_info_classify_permission_no_auth_record_id desc LIMIT ?,? `
+	_, err = o.Raw(sql, userId, excelSource, startSize, pageSize).QueryRows(&items)
+
+	return
+}

+ 233 - 129
models/data_manage/data_manage_permission/no_auth_record.go

@@ -1,9 +1,8 @@
 package data_manage_permission
 
 import (
+	"errors"
 	"eta/eta_api/utils"
-	"fmt"
-	"github.com/beego/beego/v2/client/orm"
 	"time"
 )
 
@@ -22,7 +21,7 @@ type DataPermissionNoAuthRecord struct {
 }
 
 type DataItem struct {
-	DataId   string `json:"data_id"`   // 资产id(指标、图表、表格)
+	DataId   int    `json:"data_id"`   // 资产id(指标、图表、表格)
 	DataCode string `json:"data_code"` // 资产code(指标、图表、表格)
 	DataName string `json:"data_name"` // 资产名称(指标、图表、表格)
 }
@@ -41,124 +40,192 @@ type DataItem struct {
 // @param opUserId int
 // @return err error
 func AddRecordBySourceAndDataIdList(source, subSource int, dataList []DataItem, noAuthUserIdList, authUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
-	num := len(dataList)
-	if num <= 0 {
-		return
-	}
-	dataIdList := make([]string, 0)
-	for _, v := range dataList {
-		dataIdList = append(dataIdList, v.DataId)
-	}
-	userNum := len(noAuthUserIdList)
-	if userNum <= 0 {
-		return
-	}
-	o, err := orm.NewOrmUsingDB("data").Begin()
-	if err != nil {
-		return
-	}
-	defer func() {
-		if err != nil {
-			_ = o.Rollback()
-		} else {
-			_ = o.Commit()
+	switch source {
+	case 3, 4:
+		edbInfoType := 0
+		if source == 4 {
+			edbInfoType = 1
 		}
-	}()
+		err = AddEdbInfoPermissionNoAuthRecordBySourceAndDataIdList(source, edbInfoType, dataList, noAuthUserIdList, authUserIdList, uniqueCode, content, opUserId)
 
-	// 根据指标获取已经存在的未授权记录
-	var existList []*DataPermissionNoAuthRecord
-	sql := `SELECT * FROM data_permission_no_auth_record WHERE source = ? AND sub_source = ? AND data_id in (` + utils.GetOrmInReplace(num) + `)`
-	_, err = o.Raw(sql, source, subSource, dataIdList).QueryRows(&existList)
-	if err != nil {
-		return
-	}
+	case 5:
+		//图库
+		chartSource := utils.CHART_SOURCE_DEFAULT
+		err = AddChartInfoPermissionNoAuthRecordBySourceAndDataIdList(source, chartSource, dataList, noAuthUserIdList, authUserIdList, uniqueCode, content, opUserId)
 
-	// 已经标记了的数据
-	existMap := make(map[int32]map[string]*DataPermissionNoAuthRecord)
-	for _, v := range existList {
-		tmpUserExistMap, ok := existMap[v.SysUserId]
-		if !ok {
-			tmpUserExistMap = make(map[string]*DataPermissionNoAuthRecord)
-		}
+	case 6:
+		// ETA表格
+		err = AddExcelInfoPermissionNoAuthRecordBySourceAndDataIdList(source, subSource, dataList, noAuthUserIdList, authUserIdList, uniqueCode, content, opUserId)
 
-		key := fmt.Sprint(v.Source, "_", v.SubSource, "_", v.DataId)
-		tmpUserExistMap[key] = v
-		existMap[v.SysUserId] = tmpUserExistMap
+	default:
+		return errors.New("错误的source")
 	}
+	return
+}
 
-	addMessageList := make([]*DataPermissionMessage, 0)
-	addRecordList := make([]*DataPermissionNoAuthRecord, 0)
-	for _, userId := range noAuthUserIdList {
-		isAdd := false
-
-		tmpUserExistMap, userExistOk := existMap[int32(userId)]
-
-		for _, dataItem := range dataList {
-			// 判断是否已经存在,已经存在就过滤
-			if userExistOk {
-				key := fmt.Sprint(source, "_", subSource, "_", dataItem.DataId)
-				_, ok := tmpUserExistMap[key]
-				if ok {
-					continue
-				}
-			}
-
-			isAdd = true
-			addRecordList = append(addRecordList, &DataPermissionNoAuthRecord{
-				DataPermissionNoAuthRecordId: 0,
-				Source:                       int32(source),
-				SubSource:                    int32(subSource),
-				OpUniqueCode:                 uniqueCode,
-				DataId:                       dataItem.DataId,
-				DataCode:                     dataItem.DataCode,
-				DataName:                     dataItem.DataName,
-				SysUserId:                    int32(userId),
-				CreateTime:                   time.Now(),
-			})
-		}
-
-		// 有记录的话,需要添加消息
-		if isAdd {
-			addMessageList = append(addMessageList, &DataPermissionMessage{
-				DataPermissionMessageId: 0,
-				SendUserId:              int32(opUserId),
-				ReceiveUserId:           int32(userId),
-				Content:                 content,
-				Remark:                  content,
-				OpType:                  3,
-				Source:                  int32(source),
-				SubSource:               int32(subSource),
-				OpUniqueCode:            uniqueCode,
-				IsRead:                  0,
-				CreateTime:              time.Now(),
-				ModifyTime:              time.Now(),
-			})
-		}
-	}
+// AddRecordBySourceAndDataIdList
+// @Description: 添加未授权用户记录
+// @author: Roc
+// @datetime 2024-04-07 15:25:49
+// @param source int
+// @param subSource int
+// @param dataList []DataItem
+// @param noAuthUserIdList []int 未授权用户
+// @param authUserIdList []int 已授权用户
+// @param uniqueCode
+// @param content string
+// @param opUserId int
+// @return err error
+//func AddRecordBySourceAndDataIdList(source, subSource int, dataList []DataItem, noAuthUserIdList, authUserIdList []int, uniqueCode, content string, opUserId int) (err error) {
+//	num := len(dataList)
+//	if num <= 0 {
+//		return
+//	}
+//	dataIdList := make([]string, 0)
+//	for _, v := range dataList {
+//		dataIdList = append(dataIdList, v.DataId)
+//	}
+//	userNum := len(noAuthUserIdList)
+//	if userNum <= 0 {
+//		return
+//	}
+//	o, err := orm.NewOrmUsingDB("data").Begin()
+//	if err != nil {
+//		return
+//	}
+//	defer func() {
+//		if err != nil {
+//			_ = o.Rollback()
+//		} else {
+//			_ = o.Commit()
+//		}
+//	}()
+//
+//	// 根据指标获取已经存在的未授权记录
+//	var existList []*DataPermissionNoAuthRecord
+//	sql := `SELECT * FROM data_permission_no_auth_record WHERE source = ? AND sub_source = ? AND data_id in (` + utils.GetOrmInReplace(num) + `)`
+//	_, err = o.Raw(sql, source, subSource, dataIdList).QueryRows(&existList)
+//	if err != nil {
+//		return
+//	}
+//
+//	// 已经标记了的数据
+//	existMap := make(map[int32]map[string]*DataPermissionNoAuthRecord)
+//	for _, v := range existList {
+//		tmpUserExistMap, ok := existMap[v.SysUserId]
+//		if !ok {
+//			tmpUserExistMap = make(map[string]*DataPermissionNoAuthRecord)
+//		}
+//
+//		key := fmt.Sprint(v.Source, "_", v.SubSource, "_", v.DataId)
+//		tmpUserExistMap[key] = v
+//		existMap[v.SysUserId] = tmpUserExistMap
+//	}
+//
+//	addMessageList := make([]*DataPermissionMessage, 0)
+//	addRecordList := make([]*DataPermissionNoAuthRecord, 0)
+//	for _, userId := range noAuthUserIdList {
+//		isAdd := false
+//
+//		tmpUserExistMap, userExistOk := existMap[int32(userId)]
+//
+//		for _, dataItem := range dataList {
+//			// 判断是否已经存在,已经存在就过滤
+//			if userExistOk {
+//				key := fmt.Sprint(source, "_", subSource, "_", dataItem.DataId)
+//				_, ok := tmpUserExistMap[key]
+//				if ok {
+//					continue
+//				}
+//			}
+//
+//			isAdd = true
+//			addRecordList = append(addRecordList, &DataPermissionNoAuthRecord{
+//				DataPermissionNoAuthRecordId: 0,
+//				Source:                       int32(source),
+//				SubSource:                    int32(subSource),
+//				OpUniqueCode:                 uniqueCode,
+//				DataId:                       dataItem.DataId,
+//				DataCode:                     dataItem.DataCode,
+//				DataName:                     dataItem.DataName,
+//				SysUserId:                    int32(userId),
+//				CreateTime:                   time.Now(),
+//			})
+//		}
+//
+//		// 有记录的话,需要添加消息
+//		if isAdd {
+//			addMessageList = append(addMessageList, &DataPermissionMessage{
+//				DataPermissionMessageId: 0,
+//				SendUserId:              int32(opUserId),
+//				ReceiveUserId:           int32(userId),
+//				Content:                 content,
+//				Remark:                  content,
+//				OpType:                  3,
+//				Source:                  int32(source),
+//				SubSource:               int32(subSource),
+//				OpUniqueCode:            uniqueCode,
+//				IsRead:                  0,
+//				CreateTime:              time.Now(),
+//				ModifyTime:              time.Now(),
+//			})
+//		}
+//	}
+//
+//	// 添加消息
+//	if len(addMessageList) > 0 {
+//		_, err = o.InsertMulti(500, addMessageList)
+//		if err != nil {
+//			return
+//		}
+//	}
+//
+//	// 添加记录
+//	if len(addRecordList) > 0 {
+//		_, err = o.InsertMulti(500, addRecordList)
+//		if err != nil {
+//			return
+//		}
+//	}
+//
+//	// 已经授权了的用户,需要删除未授权记录
+//	authUserIdNum := len(authUserIdList)
+//	if authUserIdNum > 0 {
+//		sql = `DELETE FROM data_permission_no_auth_record WHERE  source = ? AND sub_source = ? AND sys_user_id in (` + utils.GetOrmInReplace(authUserIdNum) + `) AND data_id in (` + utils.GetOrmInReplace(num) + `)`
+//		_, err = o.Raw(sql, source, subSource, authUserIdList, dataIdList).Exec()
+//	}
+//
+//	return
+//}
 
-	// 添加消息
-	if len(addMessageList) > 0 {
-		_, err = o.InsertMulti(500, addMessageList)
-		if err != nil {
-			return
+// DeleteRecordBySourceAndDataIdList
+// @Description: 根据来源和数据id列表删除记录
+// @author: Roc
+// @datetime 2024-04-07 14:47:37
+// @param source int
+// @param subSource int
+// @param dataIdList []string
+// @return err error
+func DeleteRecordBySourceAndDataIdList(source, subSource int, dataIdList []string) (err error) {
+	switch source {
+	case 3, 4:
+		edbInfoType := 0
+		if source == 4 {
+			edbInfoType = 1
 		}
-	}
+		err = DeleteEdbInfoPermissionNoAuthRecordBySourceAndDataIdList(edbInfoType, dataIdList)
+	case 5:
+		//图库
+		chartSource := utils.CHART_SOURCE_DEFAULT
+		err = DeleteChartInfoPermissionNoAuthRecordBySourceAndDataIdList(chartSource, dataIdList)
 
-	// 添加记录
-	if len(addRecordList) > 0 {
-		_, err = o.InsertMulti(500, addRecordList)
-		if err != nil {
-			return
-		}
-	}
+	case 6:
+		// ETA表格
+		err = DeleteExcelInfoPermissionNoAuthRecordBySourceAndDataIdList(subSource, dataIdList)
 
-	// 已经授权了的用户,需要删除未授权记录
-	authUserIdNum := len(authUserIdList)
-	if authUserIdNum > 0 {
-		sql = `DELETE FROM data_permission_no_auth_record WHERE  source = ? AND sub_source = ? AND sys_user_id in (` + utils.GetOrmInReplace(authUserIdNum) + `) AND data_id in (` + utils.GetOrmInReplace(num) + `)`
-		_, err = o.Raw(sql, source, subSource, authUserIdList, dataIdList).Exec()
+	default:
+		return errors.New("错误的source")
 	}
-
 	return
 }
 
@@ -170,18 +237,46 @@ func AddRecordBySourceAndDataIdList(source, subSource int, dataList []DataItem,
 // @param subSource int
 // @param dataIdList []string
 // @return err error
-func DeleteRecordBySourceAndDataIdList(source, subSource int, dataIdList []string) (err error) {
-	num := len(dataIdList)
-	if num <= 0 {
-		return
-	}
-	o := orm.NewOrmUsingDB("data")
-
-	sql := `DELETE FROM data_permission_no_auth_record WHERE source = ? AND sub_source = ? AND data_id in (` + utils.GetOrmInReplace(num) + `)`
-	_, err = o.Raw(sql, source, subSource, dataIdList).Exec()
+//func DeleteRecordBySourceAndDataIdList(source, subSource int, dataIdList []string) (err error) {
+//	num := len(dataIdList)
+//	if num <= 0 {
+//		return
+//	}
+//	o := orm.NewOrmUsingDB("data")
+//
+//	sql := `DELETE FROM data_permission_no_auth_record WHERE source = ? AND sub_source = ? AND data_id in (` + utils.GetOrmInReplace(num) + `)`
+//	_, err = o.Raw(sql, source, subSource, dataIdList).Exec()
+//
+//	return
+//}
 
-	return
-}
+// GetDataPermissionNoAuthRecordListByUserId
+// @Description: 根据用户获取未授权的资产记录
+// @author: Roc
+// @datetime 2024-04-07 20:15:01
+// @param userId int
+// @param source int
+// @param subSource int
+// @param startSize int
+// @param pageSize int
+// @return total int
+// @return items []*DataPermissionNoAuthRecord
+// @return err error
+//func GetDataPermissionNoAuthRecordListByUserId(userId, source, subSource int32, startSize, pageSize int) (total int, items []*DataPermissionNoAuthRecord, err error) {
+//	o := orm.NewOrmUsingDB("data")
+//
+//	// 获取总数
+//	sql := `SELECT count(1) AS total FROM data_permission_no_auth_record WHERE sys_user_id = ? AND source = ? AND sub_source = ? `
+//	err = o.Raw(sql, userId, source, subSource).QueryRow(&total)
+//	if err != nil {
+//		return
+//	}
+//
+//	sql = `SELECT * FROM data_permission_no_auth_record WHERE sys_user_id = ? AND source = ? AND sub_source = ? ORDER BY data_permission_no_auth_record_id desc LIMIT ?,? `
+//	_, err = o.Raw(sql, userId, source, subSource, startSize, pageSize).QueryRows(&items)
+//
+//	return
+//}
 
 // GetDataPermissionNoAuthRecordListByUserId
 // @Description: 根据用户获取未授权的资产记录
@@ -196,17 +291,26 @@ func DeleteRecordBySourceAndDataIdList(source, subSource int, dataIdList []strin
 // @return items []*DataPermissionNoAuthRecord
 // @return err error
 func GetDataPermissionNoAuthRecordListByUserId(userId, source, subSource int32, startSize, pageSize int) (total int, items []*DataPermissionNoAuthRecord, err error) {
-	o := orm.NewOrmUsingDB("data")
+	switch source {
+	case 3, 4:
+		edbInfoType := 0
+		if source == 4 {
+			edbInfoType = 1
+		}
+		total, items, err = GetEdbInfoDataPermissionNoAuthRecordListByUserId(userId, edbInfoType, startSize, pageSize)
+	case 5:
+		//图库
+		chartSource := utils.CHART_SOURCE_DEFAULT
+		total, items, err = GetChartInfoDataPermissionNoAuthRecordListByUserId(userId, chartSource, startSize, pageSize)
+
+	case 6:
+		// ETA表格
+		total, items, err = GetExcelInfoDataPermissionNoAuthRecordListByUserId(userId, subSource, startSize, pageSize)
 
-	// 获取总数
-	sql := `SELECT count(1) AS total FROM data_permission_no_auth_record WHERE sys_user_id = ? AND source = ? AND sub_source = ? `
-	err = o.Raw(sql, userId, source, subSource).QueryRow(&total)
-	if err != nil {
+	default:
+		err = errors.New("错误的source")
 		return
 	}
 
-	sql = `SELECT * FROM data_permission_no_auth_record WHERE sys_user_id = ? AND source = ? AND sub_source = ? ORDER BY data_permission_no_auth_record_id desc LIMIT ?,? `
-	_, err = o.Raw(sql, userId, source, subSource, startSize, pageSize).QueryRows(&items)
-
 	return
 }

+ 16 - 10
models/db.go

@@ -560,15 +560,21 @@ func initEdbRefresh() {
 // @datetime 2024-03-27 14:03:11
 func initDataMangePerMission() {
 	orm.RegisterModel(
-		new(data_manage_permission.EdbInfoPermission),                  // 指标权限表
-		new(data_manage_permission.EdbClassifyPermission),              // 指标分类权限表
-		new(data_manage_permission.ChartInfoPermission),                // 图表权限表
-		new(data_manage_permission.ChartClassifyPermission),            // 图表分类权限表
-		new(data_manage_permission.ExcelInfoPermission),                // ETA表格权限表
-		new(data_manage_permission.ExcelClassifyPermission),            // ETA表格分类权限表
-		new(data_manage_permission.DataPermissionMessage),              // 数据权限变更消息表
-		new(data_manage_permission.DataPermissionMoveRecord),           // 数据资产转移记录表
-		new(data_manage_permission.DataPermissionClassifyNoAuthRecord), // 资产分类数据权限未授权记录表
-		new(data_manage_permission.DataPermissionNoAuthRecord),         // 资产数据权限设置记录表
+		new(data_manage_permission.EdbInfoPermission),                       // 指标权限表
+		new(data_manage_permission.EdbClassifyPermission),                   // 指标分类权限表
+		new(data_manage_permission.ChartInfoPermission),                     // 图表权限表
+		new(data_manage_permission.ChartClassifyPermission),                 // 图表分类权限表
+		new(data_manage_permission.ExcelInfoPermission),                     // ETA表格权限表
+		new(data_manage_permission.ExcelClassifyPermission),                 // ETA表格分类权限表
+		new(data_manage_permission.DataPermissionMessage),                   // 数据权限变更消息表
+		new(data_manage_permission.DataPermissionMoveRecord),                // 数据资产转移记录表
+		new(data_manage_permission.EdbInfoPermissionNoAuthRecord),           // 指标资产数据未授权分类记录表
+		new(data_manage_permission.ChartInfoPermissionNoAuthRecord),         // 图表资产数据未授权分类记录表
+		new(data_manage_permission.ExcelInfoPermissionNoAuthRecord),         // ETA表格资产数据未授权分类记录表
+		new(data_manage_permission.EdbInfoClassifyPermissionNoAuthRecord),   // 指标资产分类数据未授权分类记录表
+		new(data_manage_permission.ChartInfoClassifyPermissionNoAuthRecord), // 图表资产分类数据未授权分类记录表
+		new(data_manage_permission.ExcelInfoClassifyPermissionNoAuthRecord), // ETA表格资产分类数据未授权分类记录表
+		new(data_manage_permission.DataPermissionClassifyNoAuthRecord),      // 资产分类数据权限未授权记录表
+		new(data_manage_permission.DataPermissionNoAuthRecord),              // 资产数据权限设置记录表
 	)
 }

+ 3 - 3
services/data/data_manage_permission/edb_permission.go

@@ -77,7 +77,7 @@ func SetEdbChartPermission(source, subSource, userId int, authUserList []int, is
 		if len(tmpList) > 0 {
 			for _, v := range tmpList {
 				dataList = append(dataList, data_manage_permission.DataItem{
-					DataId:   fmt.Sprint(v.EdbInfoId),
+					DataId:   v.EdbInfoId,
 					DataCode: v.EdbCode,
 					DataName: v.EdbName,
 				})
@@ -103,7 +103,7 @@ func SetEdbChartPermission(source, subSource, userId int, authUserList []int, is
 			dataIdList = make([]string, 0)
 			for _, v := range tmpList {
 				dataList = append(dataList, data_manage_permission.DataItem{
-					DataId:   fmt.Sprint(v.ChartInfoId),
+					DataId:   v.ChartInfoId,
 					DataCode: fmt.Sprint(v.ChartInfoId),
 					DataName: v.ChartName,
 				})
@@ -127,7 +127,7 @@ func SetEdbChartPermission(source, subSource, userId int, authUserList []int, is
 			dataIdList = make([]string, 0)
 			for _, v := range tmpList {
 				dataList = append(dataList, data_manage_permission.DataItem{
-					DataId:   fmt.Sprint(v.ExcelInfoId),
+					DataId:   v.ExcelInfoId,
 					DataCode: fmt.Sprint(v.ExcelInfoId),
 					DataName: v.ExcelName,
 				})