Browse Source

Merge remote-tracking branch 'origin/eta/1.7.6' into debug

Roc 1 year ago
parent
commit
b2355d4bd3

+ 6 - 6
controllers/data_manage/data_manage_permission/data_manage_permission.go

@@ -205,9 +205,9 @@ func (c *DataMangePermissionController) SetEdbChartClassifyPermission() {
 // @Description 指标/图表/表格权限设置接口
 // @Param   Source   query   int  false       "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格"
 // @Param   SubSource   query   int  false       "子来源 :目前作用于ETA表格,2024-3-26 14:12:09"
-// @Param   UserId   query   int  false       "用户id"
+// @Param   DataId   query   int  false       "资产id"
 // @Success 200 {object} data_manage.ChartListResp
-// @router /edb_chart/permission/show_by_user [get]
+// @router /edb_chart/permission/show_by_data [get]
 func (c *DataMangePermissionController) GetEdbChartPermission() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
@@ -237,7 +237,7 @@ func (c *DataMangePermissionController) GetEdbChartPermission() {
 		return
 	}
 
-	userId, _ := c.GetInt("UserId")
+	dataId, _ := c.GetInt("DataId")
 
 	// 来源判断
 	if source <= 0 || source > 6 {
@@ -254,14 +254,14 @@ func (c *DataMangePermissionController) GetEdbChartPermission() {
 	}
 
 	// 用户判断
-	if userId <= 0 {
-		br.Msg = "请选择用户"
+	if dataId <= 0 {
+		br.Msg = "请选择数据"
 		br.IsSendEmail = false
 		return
 	}
 
 	// 获取已经配置了的资产id列表
-	idList, err := data_manage_permission.GetEdbChartIdListPermissionByUserId(source, subSource, userId)
+	idList, err := data_manage_permission.GetEdbChartIdListPermissionByDataId(source, subSource, dataId)
 	if err != nil {
 		//br.Success = true
 		br.Msg = "获取失败"

+ 68 - 8
controllers/data_manage/edb_info.go

@@ -3133,6 +3133,8 @@ func (this *EdbInfoController) EdbInfoFilterByEs() {
 		}
 	}
 
+	// 是否走ES
+	isEs := false
 	if keyWord != "" {
 		var keyWordArr []string
 		keyWordArr = append(keyWordArr, keyWord)
@@ -3147,6 +3149,7 @@ func (this *EdbInfoController) EdbInfoFilterByEs() {
 			// 允许添加预测指标的搜索
 			total, edbInfoList, err = elastic.SearchAddPredictEdbInfoData(utils.DATA_INDEX_NAME, keyWord, noPermissionEdbInfoIdList, startSize, pageSize)
 		}
+		isEs = true
 	} else {
 		var condition string
 		var pars []interface{}
@@ -3226,12 +3229,39 @@ func (this *EdbInfoController) EdbInfoFilterByEs() {
 			return
 		}
 
-		for i := 0; i < edbInfoListLen; i++ {
-			tmpEdbInfo := edbInfoList[i]
-			if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
-				edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+		if isEs {
+			edbInfoIdList := make([]int, 0)
+			for i := 0; i < edbInfoListLen; i++ {
+				edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
+				tmpEdbInfo := edbInfoList[i]
+				if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
+					edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+				}
+			}
+
+			tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
+				return
+			}
+			edbInfoMap := make(map[int]*data_manage.EdbInfo)
+			for _, v := range tmpEdbList {
+				edbInfoMap[v.EdbInfoId] = v
+			}
+
+			for i := 0; i < edbInfoListLen; i++ {
+				tmpEdbInfoItem := edbInfoList[i]
+				tmpEdbInfo, ok := edbInfoMap[tmpEdbInfoItem.EdbInfoId]
+				if !ok {
+					continue
+				}
+				if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
+					edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+				}
 			}
 		}
+
 	}
 
 	for i := 0; i < edbInfoListLen; i++ {
@@ -4427,6 +4457,8 @@ func (this *EdbInfoController) AllEdbInfoByEs() {
 		}
 	}
 
+	// 是否走ES
+	isEs := false
 	if keyWord != "" {
 		var keyWordArr []string
 		keyWordArr = append(keyWordArr, keyWord)
@@ -4436,6 +4468,7 @@ func (this *EdbInfoController) AllEdbInfoByEs() {
 
 		// 普通的搜索
 		total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, -1, frequency, noPermissionEdbInfoIdList)
+		isEs = true
 	} else {
 		var condition string
 		var pars []interface{}
@@ -4515,12 +4548,39 @@ func (this *EdbInfoController) AllEdbInfoByEs() {
 			return
 		}
 
-		for i := 0; i < edbInfoListLen; i++ {
-			tmpEdbInfo := edbInfoList[i]
-			if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
-				edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+		if isEs {
+			edbInfoIdList := make([]int, 0)
+			for i := 0; i < edbInfoListLen; i++ {
+				edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
+				tmpEdbInfo := edbInfoList[i]
+				if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
+					edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+				}
+			}
+
+			tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
+				return
+			}
+			edbInfoMap := make(map[int]*data_manage.EdbInfo)
+			for _, v := range tmpEdbList {
+				edbInfoMap[v.EdbInfoId] = v
+			}
+
+			for i := 0; i < edbInfoListLen; i++ {
+				tmpEdbInfoItem := edbInfoList[i]
+				tmpEdbInfo, ok := edbInfoMap[tmpEdbInfoItem.EdbInfoId]
+				if !ok {
+					continue
+				}
+				if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
+					edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+				}
 			}
 		}
+
 	}
 
 	for i := 0; i < edbInfoListLen; i++ {

+ 34 - 4
controllers/data_manage/predict_edb_info.go

@@ -1196,6 +1196,8 @@ func (this *PredictEdbInfoController) FilterByEs() {
 		}
 	}
 
+	// 是否走ES
+	isEs := false
 	if keyWord != "" {
 		var keyWordArr []string
 		keyWordArr = append(keyWordArr, keyWord)
@@ -1207,6 +1209,7 @@ func (this *PredictEdbInfoController) FilterByEs() {
 		} else {
 			total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 1, frequency, noPermissionEdbInfoIdList)
 		}
+		isEs = true
 	} else {
 		var condition string
 		var pars []interface{}
@@ -1285,12 +1288,39 @@ func (this *PredictEdbInfoController) FilterByEs() {
 			return
 		}
 
-		for i := 0; i < edbInfoListLen; i++ {
-			tmpEdbInfo := edbInfoList[i]
-			if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
-				edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+		if isEs {
+			edbInfoIdList := make([]int, 0)
+			for i := 0; i < edbInfoListLen; i++ {
+				edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
+				tmpEdbInfo := edbInfoList[i]
+				if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
+					edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+				}
+			}
+
+			tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
+				return
+			}
+			edbInfoMap := make(map[int]*data_manage.EdbInfo)
+			for _, v := range tmpEdbList {
+				edbInfoMap[v.EdbInfoId] = v
+			}
+
+			for i := 0; i < edbInfoListLen; i++ {
+				tmpEdbInfoItem := edbInfoList[i]
+				tmpEdbInfo, ok := edbInfoMap[tmpEdbInfoItem.EdbInfoId]
+				if !ok {
+					continue
+				}
+				if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
+					edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+				}
 			}
 		}
+
 	}
 
 	for i := 0; i < edbInfoListLen; i++ {

+ 6 - 6
models/data_manage/data_manage_permission/data_manage_permission.go

@@ -330,18 +330,18 @@ func GetPermissionEdbClassifyIdListByUserId(userId int, classifyType int) (edbCl
 	return
 }
 
-// GetPermissionEdbIdListByUserId
-// @Description: 根据用户ID获取已经配置的资产(指标、图表、表格)id列表
+// GetPermissionEdbIdListByDataId
+// @Description: 根据资产(指标、图表、表格)ID获取已经配置的用户id列表
 // @author: Roc
 // @datetime 2024-03-29 16:24:46
-// @param userId int
+// @param dataId int
 // @param classifyType int
 // @return edbIdList []int
 // @return err error
-func GetPermissionEdbIdListByUserId(userId int, edbInfoType int) (edbIdList []int, err error) {
+func GetPermissionEdbIdListByDataId(dataId int, edbInfoType int) (edbIdList []int, err error) {
 	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT edb_info_id FROM edb_info_permission WHERE edb_info_type = ? AND sys_user_id = ? `
-	_, err = o.Raw(sql, edbInfoType, userId).QueryRows(&edbIdList)
+	sql := `SELECT sys_user_id FROM edb_info_permission WHERE edb_info_type = ? AND edb_info_id= ? `
+	_, err = o.Raw(sql, edbInfoType, dataId).QueryRows(&edbIdList)
 
 	return
 }

+ 1 - 1
models/data_manage/edb_info.go

@@ -1658,7 +1658,7 @@ type SetEdbDataInsertConfigReq struct {
 // GetEdbInfoByClassifyId 用于分类展示
 func GetEdbInfoByClassifyId(classifyId, edbInfoType, adminId int) (items []*EdbClassifyItems, err error) {
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT edb_info_id,classify_id,edb_name_source AS classify_name,edb_name_en AS classify_name_en,unique_code,source_name,source,sys_user_id,sys_user_real_name,start_date,edb_code,edb_type, sort FROM edb_info WHERE classify_id = ? AND edb_info_type = ?`
+	sql := ` SELECT edb_info_id,classify_id,edb_name_source AS classify_name,edb_name_en AS classify_name_en,unique_code,source_name,source,sys_user_id,sys_user_real_name,start_date,edb_code,edb_type, sort,is_join_permission FROM edb_info WHERE classify_id = ? AND edb_info_type = ?`
 
 	pars := []interface{}{classifyId, edbInfoType}
 	// 如果筛选了用户id

+ 1 - 1
routers/commentsRouter.go

@@ -586,7 +586,7 @@ func init() {
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/data_manage_permission:DataMangePermissionController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/data_manage_permission:DataMangePermissionController"],
         beego.ControllerComments{
             Method: "GetEdbChartPermission",
-            Router: `/edb_chart/permission/show_by_user`,
+            Router: `/edb_chart/permission/show_by_data`,
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),
             Filters: nil,

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

@@ -431,16 +431,16 @@ func GetEdbChartClassifyIdListPermissionByUserId(source, subSource, userId int)
 	return
 }
 
-// GetEdbChartIdListPermissionByUserId
+// GetEdbChartIdListPermissionByDataId
 // @Description: 根据用户id获取已经配置的资产(指标、图表、表格)id列表
 // @author: Roc
 // @datetime 2024-03-29 16:26:10
 // @param source int
 // @param subSource int
-// @param userId int
+// @param dataId int
 // @return idList []int
 // @return err error
-func GetEdbChartIdListPermissionByUserId(source, subSource, userId int) (idList []int, err error) {
+func GetEdbChartIdListPermissionByDataId(source, subSource, dataId int) (idList []int, err error) {
 	switch source {
 	case 3, 4: //ETA指标库、ETA预测指标
 		//tmpList, tmpErr := data_manage.GetEdbInfoListGroupByUserId(dataId)
@@ -455,7 +455,7 @@ func GetEdbChartIdListPermissionByUserId(source, subSource, userId int) (idList
 		if source == 4 {
 			edbInfoType = 1
 		}
-		idList, err = data_manage_permission.GetPermissionEdbIdListByUserId(userId, edbInfoType)
+		idList, err = data_manage_permission.GetPermissionEdbIdListByDataId(dataId, edbInfoType)
 	//case 5: //图库
 	//	tmpList, tmpErr := data_manage.GetChartInfoListGroupByUserId(dataId)
 	//	if tmpErr != nil {