Browse Source

Merge branch 'feature/eta1.8.5_excel_balance' into debug

xyxie 10 months ago
parent
commit
32953e73d2

+ 9 - 0
models/data_manage/excel/excel_chart_edb.go

@@ -273,6 +273,15 @@ func GetExcelChartEdbMappingByChartInfoId(chartInfoId int) (list []*ExcelChartEd
 	return
 }
 
+func GetExcelInfoByChartInfoId(chartInfoId int) (item *ExcelInfo, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT i.*
+             FROM excel_chart_edb e left join excel_info i on e.excel_info_id=i.excel_info_id
+			 WHERE e.chart_info_id=? limit 1`
+	err = o.Raw(sql, chartInfoId).QueryRow(&item)
+	return
+}
+
 // 同时删除指标和指标数据
 func DeleteExcelChartEdbAndData(excelInfoIds []int, chartInfoIds []int) (err error) {
 	o, err := orm.NewOrmUsingDB("data").Begin()

+ 1 - 1
models/data_manage/excel/excel_info.go

@@ -252,7 +252,7 @@ func GetExcelInfoListByCondition(condition string, pars []interface{}) (items []
 	if condition != "" {
 		sql += condition
 	}
-	sql += ` ORDER BY excel_info_id asc `
+	sql += ` ORDER BY sort asc, excel_info_id asc`
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }

+ 34 - 54
services/data/chart_info_excel_balance.go

@@ -8,6 +8,7 @@ import (
 	excelModel "eta/eta_api/models/data_manage/excel"
 	"eta/eta_api/models/data_manage/excel/request"
 	"eta/eta_api/models/system"
+	"eta/eta_api/services/data/data_manage_permission"
 	"eta/eta_api/utils"
 	"fmt"
 	"math"
@@ -963,23 +964,20 @@ func CheckBalanceChartCacheAndPermission(chartInfo *data_manage.ChartInfoView, i
 	adminId := sysUser.AdminId
 	// todo 图表数据权限
 	// 已授权分类id
-	/*permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(adminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
+	permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(adminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
 	if err != nil {
 		errMsg = "获取已授权分类id数据失败,Err:" + err.Error()
 		return
 	}
 
-	// 指标数据map
-	edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
 	defer func() {
 		if isOk {
-
 			// 图表权限校验
 			{
-				resp.ChartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
+				resp.ChartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, 0, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
 
 				//图表操作权限
-				chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, resp.ChartInfo.HaveOperaAuth)
+				chartInfo.IsEdit = CheckOpChartPermission(sysUser, chartInfo.SysUserId, resp.ChartInfo.HaveOperaAuth)
 				chartInfo.Button = data_manage.ChartViewButton{
 					IsEdit:    chartInfo.IsEdit,
 					IsEnChart: chartInfo.IsEnChart,
@@ -998,66 +996,48 @@ func CheckBalanceChartCacheAndPermission(chartInfo *data_manage.ChartInfoView, i
 				//}
 			}
 
-			// 指标权限
+			// todo 是否需要返回平衡表指标权限即判断平衡表的表格数据权限
 			{
-				classifyMap := make(map[int]*data_manage.EdbClassify)
-				// 分类
-				{
-					classifyIdList := make([]int, 0)
-					for _, v := range resp.EdbInfoList {
-						classifyIdList = append(classifyIdList, v.ClassifyId)
-					}
-					classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
-					if tmpErr != nil {
-						errMsg = "获取分类列表失败,Err:" + tmpErr.Error()
-						return
-					}
-					for _, v := range classifyList {
-						classifyMap[v.ClassifyId] = v
-					}
+				// 查询图表关联的表格ID
+				excelInfo, e := excelModel.GetExcelInfoByChartInfoId(chartInfo.ChartInfoId)
+				if e != nil {
+					errMsg = "获取图表关联的表格ID失败,Err:" + e.Error()
+					err = e
+					return
 				}
-
-				// 指标
-				if len(edbClassifyPermissionMap) < 0 {
-					edbInfoIdList := make([]int, 0)
-					for _, v := range resp.EdbInfoList {
-						edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
-					}
-					edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
-					if tmpErr != nil {
-						errMsg = "获取指标列表失败,Err:" + tmpErr.Error()
-						return
+				checkExcelInfo := excelInfo
+				if excelInfo.Source == utils.BALANCE_TABLE {
+					checkExcelInfoId := excelInfo.ExcelInfoId
+					if excelInfo.BalanceType == 1 {
+						checkExcelInfoId = excelInfo.RelExcelInfoId
+					} else {
+						if excelInfo.ParentId > 0 {
+							checkExcelInfoId = excelInfo.ParentId
+						}
 					}
-					for _, v := range edbInfoList {
-						edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
-							ClassifyId:       v.ClassifyId,
-							IsJoinPermission: v.IsJoinPermission,
-							EdbInfoId:        v.EdbInfoId,
+					if checkExcelInfoId != excelInfo.ExcelInfoId {
+						checkExcelInfo, err = excelModel.GetExcelInfoById(excelInfo.ExcelInfoId)
+						if err != nil {
+							errMsg = "获取平衡表格信息失败"
+							err = errors.New("获取平衡表格信息失败,Err:" + err.Error())
+							return
 						}
 					}
 				}
 
-				// 获取所有有权限的指标和分类
-				permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
-				if err != nil {
-					errMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
+				haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, adminId)
+				if e != nil {
+					errMsg = "获取平衡表格数据权限失败"
+					err = errors.New("获取表格权限信息失败,Err" + e.Error())
 					return
 				}
-
+				// 数据权限
 				for _, v := range resp.EdbInfoList {
-					// 数据权限
-					edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
-					if !ok {
-						continue
-					}
-
-					if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
-						v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
-					}
+					v.HaveOperaAuth = haveOperaAuth
 				}
 			}
 		}
-	}()*/
+	}()
 	key := GetChartInfoDataKey(chartInfo.ChartInfoId)
 	if utils.Re == nil && isCache {
 		if utils.Re == nil && utils.Rc.IsExist(key) {
@@ -1274,7 +1254,7 @@ func AddBalanceStaticExcel(oldExcelInfo *excelModel.ExcelInfo, versionName strin
 		UpdateUserId:       sysUser.AdminId,
 		UpdateUserRealName: sysUser.AdminName,
 		BalanceType:        balanceType,
-		Sort:               0,
+		Sort:               oldExcelInfo.Sort,
 		IsDelete:           0,
 		ModifyTime:         time.Now(),
 		CreateTime:         time.Now(),