Browse Source

表格添加了引用

xyxie 8 months ago
parent
commit
d4ec9f5343

+ 6 - 1
controllers/data_manage/excel/excel_info.go

@@ -307,6 +307,8 @@ func (c *ExcelInfoController) Add() {
 	resp.ExcelInfoId = excelInfo.ExcelInfoId
 	resp.UniqueCode = excelInfo.UniqueCode
 
+	//新增指标引用记录
+	_ = data.SaveExcelEdbInfoRelation(excelInfo.ExcelInfoId, excelInfo.Source, false)
 	//新增操作日志
 	//{
 	//	excelLog := &data_manage.ExcelInfoLog{
@@ -997,7 +999,8 @@ func (c *ExcelInfoController) Edit() {
 		ExcelInfoId: excelInfo.ExcelInfoId,
 		UniqueCode:  excelInfo.UniqueCode,
 	}
-
+	//新增指标引用记录
+	_ = data.SaveExcelEdbInfoRelation(excelInfo.ExcelInfoId, excelInfo.Source, false)
 	//删除公共图库那边的缓存
 	_ = utils.Rc.Delete(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelInfo.UniqueCode)
 
@@ -2469,6 +2472,8 @@ func (c *ExcelInfoController) Copy() {
 		br.IsSendEmail = isSendEmail
 		return
 	}
+	//新增指标引用记录
+	_ = data.SaveExcelEdbInfoRelation(excelInfo.ExcelInfoId, excelInfo.Source, true)
 
 	resp := new(response.AddExcelInfoResp)
 	resp.ExcelInfoId = excelInfo.ExcelInfoId

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

@@ -119,6 +119,15 @@ func GetAllExcelEdbMappingByExcelInfoId(excelInfoId int) (items []*ExcelEdbMappi
 	return
 }
 
+// GetAllExcelEdbMappingByExcelInfoIds 根据excel的id获取所有的指标
+func GetAllExcelEdbMappingByExcelInfoIds(excelInfoIds []int) (items []*ExcelEdbMapping, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT a.* FROM  excel_edb_mapping a
+         WHERE a.excel_info_id in (` + utils.GetOrmInReplace(len(excelInfoIds)) + `) ORDER BY a.excel_edb_mapping_id ASC `
+	_, err = o.Raw(sql, excelInfoIds).QueryRows(&items)
+	return
+}
+
 // GetExcelEdbMappingByEdbInfoIdAndSource 根据指标id获取配置关系
 func GetExcelEdbMappingByEdbInfoIdAndSource(edbInfoId int, sources []int) (items []*ExcelEdbMapping, err error) {
 	o := orm.NewOrmUsingDB("data")

+ 65 - 0
services/data/edb_info_relation.go

@@ -2,6 +2,7 @@ package data
 
 import (
 	"eta/eta_api/models/data_manage"
+	excelModel "eta/eta_api/models/data_manage/excel"
 	"eta/eta_api/models/fe_calendar"
 	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/services/sandbox"
@@ -523,3 +524,67 @@ func GetCalculateEdbInfoByEdbInfoId(edbInfoId int, hasFindMap map[int]struct{},
 	hasFindMap[edbInfoId] = struct{}{}
 	return
 }
+
+// SaveExcelEdbInfoRelation 添加/编辑表格时同步修改指标引用关联记录
+func SaveExcelEdbInfoRelation(excelInfoId, source int, addChildExcel bool) (err error) {
+	//查询和指标相关的时间序列表格和混合表格
+	if !utils.InArrayByInt([]int{utils.TIME_TABLE, utils.MIXED_TABLE, utils.BALANCE_TABLE}, source) {
+		return
+	}
+	if addChildExcel && source == utils.BALANCE_TABLE {
+		//查询excel信息,
+		excelInfoList, e := excelModel.GetChildExcelInfoByParentId(excelInfoId)
+		if e != nil {
+			err = fmt.Errorf("查询excel信息失败,错误:%s", e.Error())
+			return
+		}
+
+		//查询
+		if len(excelInfoList) > 0 {
+			//汇总表格ID
+			excelIds := make([]int, 0)
+			for _, v := range excelInfoList {
+				if v.BalanceType == 0 {
+					excelIds = append(excelIds, v.ExcelInfoId)
+				}
+			}
+			mappingList, e := excelModel.GetAllExcelEdbMappingByExcelInfoIds(excelIds)
+			if e != nil {
+				err = fmt.Errorf("查询和指标相关的表格失败,错误:%s", e.Error())
+				return
+			}
+			//整理map
+			mappingMap := make(map[int][]int)
+			for _, v := range mappingList {
+				mappingMap[v.ExcelInfoId] = append(mappingMap[v.ExcelInfoId], v.EdbInfoId)
+			}
+
+			// 添加指标引用
+			for _, v := range excelInfoList {
+				edbInfoIds, ok := mappingMap[v.ExcelInfoId]
+				if !ok {
+					continue
+				}
+				err = saveEdbInfoRelation(edbInfoIds, v.ExcelInfoId, utils.EDB_RELATION_TABLE, source)
+			}
+			//更新
+		}
+	}
+	mappingList, err := excelModel.GetAllExcelEdbMappingByExcelInfoId(excelInfoId)
+	if err != nil {
+		err = fmt.Errorf("查询和指标相关的表格失败,错误:%s", err.Error())
+		return
+	}
+	//查询指标ID
+	edbInfoIds := make([]int, 0)
+	for k := range mappingList {
+		edbInfoIds = append(edbInfoIds, k)
+	}
+	//查询指标引用关联记录
+	//更新指标刷新状态为启用
+	if len(edbInfoIds) == 0 {
+		return
+	}
+	err = saveEdbInfoRelation(edbInfoIds, excelInfoId, utils.EDB_RELATION_TABLE, source)
+	return
+}

+ 4 - 1
services/data/excel/excel_op.go

@@ -2,6 +2,7 @@ package excel
 
 import (
 	"errors"
+	"eta/eta_api/models/data_manage"
 	excelModel "eta/eta_api/models/data_manage/excel"
 	"eta/eta_api/models/system"
 	"eta/eta_api/services"
@@ -98,7 +99,7 @@ func Delete(excelInfo *excelModel.ExcelInfo, sysUser *system.Admin) (err error,
 			err = fmt.Errorf("删除图表,指标信息失败 Err:%s", err.Error())
 			return
 		}
-
+		_ = data_manage.DeleteEdbRelationByObjectIds(excelIds, utils.EDB_RELATION_TABLE)
 		return
 	}
 
@@ -107,6 +108,8 @@ func Delete(excelInfo *excelModel.ExcelInfo, sysUser *system.Admin) (err error,
 	excelInfo.ModifyTime = time.Now()
 	err = excelInfo.Update([]string{"IsDelete", "ModifyTime"})
 
+	// 删除指标引用
+	_ = data_manage.DeleteEdbRelationByObjectIds([]int{excelInfo.ExcelInfoId}, utils.EDB_RELATION_TABLE)
 	return
 }
 

+ 1 - 0
services/sandbox/sandbox.go

@@ -894,6 +894,7 @@ func GetSandBoxEdbIdsByContent(content string) (edbInfoIds []int, err error) {
 			}
 		}
 	}
+	return
 }
 func ReplaceEdbInSandbox(oldEdbInfoId, newEdbInfoId int) (err error) {
 	updateTotal := 0