Browse Source

Merge branch 'feature/eta1.5.7_edb_replace' into debug

# Conflicts:
#	models/data_manage/excel/excel_info.go
xyxie 10 months ago
parent
commit
a8c6659a63

+ 3 - 2
controllers/data_manage/edb_classify.go

@@ -356,7 +356,7 @@ func (this *EdbClassifyController) DeleteEdbClassifyCheck() {
 		br.IsSendEmail = false
 		br.IsSendEmail = false
 		return
 		return
 	}
 	}
-	deleteStatus, tipsMsg, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
+	deleteStatus, tipsMsg, tableList, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
 	if errMsg != `` {
 	if errMsg != `` {
 		br.Msg = errMsg
 		br.Msg = errMsg
 		br.ErrMsg = errMsg
 		br.ErrMsg = errMsg
@@ -429,6 +429,7 @@ func (this *EdbClassifyController) DeleteEdbClassifyCheck() {
 	resp := new(data_manage.ClassifyDeleteCheckResp)
 	resp := new(data_manage.ClassifyDeleteCheckResp)
 	resp.DeleteStatus = deleteStatus
 	resp.DeleteStatus = deleteStatus
 	resp.TipsMsg = tipsMsg
 	resp.TipsMsg = tipsMsg
+	resp.TableList = tableList
 	br.Ret = 200
 	br.Ret = 200
 	br.Msg = "检测成功"
 	br.Msg = "检测成功"
 	br.Success = true
 	br.Success = true
@@ -467,7 +468,7 @@ func (this *EdbClassifyController) DeleteEdbClassify() {
 		return
 		return
 	}
 	}
 
 
-	nextItem, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
+	nextItem, _, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
 	if errMsg != `` {
 	if errMsg != `` {
 		br.Msg = errMsg
 		br.Msg = errMsg
 		br.ErrMsg = errMsg
 		br.ErrMsg = errMsg

+ 80 - 39
controllers/data_manage/edb_info.go

@@ -6,6 +6,7 @@ import (
 	"eta/eta_api/models"
 	"eta/eta_api/models"
 	"eta/eta_api/models/company"
 	"eta/eta_api/models/company"
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/models/data_manage"
+	"eta/eta_api/models/data_manage/cross_variety"
 	request2 "eta/eta_api/models/data_manage/excel/request"
 	request2 "eta/eta_api/models/data_manage/excel/request"
 	"eta/eta_api/models/data_manage/request"
 	"eta/eta_api/models/data_manage/request"
 	"eta/eta_api/models/data_manage/response"
 	"eta/eta_api/models/data_manage/response"
@@ -3900,41 +3901,28 @@ func (this *ChartInfoController) EdbInfoReplace() {
 	//replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
 	//replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
 	_, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
 	_, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
 	//msgContent := ``
 	//msgContent := ``
-	isFail := false
-	var errmsg string
 	if err != nil {
 	if err != nil {
-		//msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换失败,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n " + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
-		isFail = true
-		errmsg = "replace err:" + err.Error()
-	} else {
-		//msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换成功,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n" + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
-		isFail = false
+		br.Msg = "替换失败"
+		br.ErrMsg = "替换失败 replace err:" + err.Error()
+		return
 	}
 	}
 
 
-	// 添加站内信息
-	//{
-	//	msgItem := new(company.CompanyApprovalMessage)
-	//	msgItem.CreateUserId = sysAdminId
-	//	msgItem.ReceiveUserId = sysAdminId
-	//	msgItem.MessageStatus = 0
-	//	msgItem.Remark = "指标替换"
-	//	msgItem.OperationStatus = 1
-	//	msgItem.Content = msgContent
-	//	msgItem.CreateTime = time.Now()
-	//	msgItem.ModifyTime = time.Now()
-	//	msgItem.MessageType = 3 //1:申请消息,2:审批结果,3:文字消息
-	//	msgItem.SourceType = 4  //消息来源
-	//	err = company.AddCompanyApprovalMessage(msgItem)
-	//}
+	// 替换相关性图表配置
+	go func() {
+		_, _ = data_manage.ReplaceMultipleGraphConfigChartEdb(oldEdbInfo, newEdbInfo)
+		/*if err != nil {
+			br.Msg = "替换失败"
+			br.ErrMsg = "替换失败 replace err:" + err.Error()
+			return
+		}*/
+	}()
 
 
-	if isFail {
-		br.Msg = "替换失败"
-		br.ErrMsg = "替换失败 err:" + errmsg
-	} else {
-		br.Msg = "替换成功"
-		br.ErrMsg = "替换成功"
-		br.Ret = 200
-	}
+	go func() {
+		excel2.ReplaceEdbInExcel(oldEdbInfo, newEdbInfo)
+	}()
+	br.Msg = "替换成功"
+	br.ErrMsg = "替换成功"
+	br.Ret = 200
 	br.IsAddLog = true
 	br.IsAddLog = true
 	return
 	return
 }
 }
@@ -3989,9 +3977,9 @@ func (this *EdbInfoController) RelationChartList() {
 		return
 		return
 	}
 	}
 
 
-	// 关联指标
+	/*// 关联指标
 	condition += ` AND b.edb_info_id = ? `
 	condition += ` AND b.edb_info_id = ? `
-	pars = append(pars, edbInfoId)
+	pars = append(pars, edbInfoId)*/
 
 
 	//只看我的
 	//只看我的
 	isShowMe, _ := this.GetBool("IsShowMe")
 	isShowMe, _ := this.GetBool("IsShowMe")
@@ -4000,8 +3988,47 @@ func (this *EdbInfoController) RelationChartList() {
 		pars = append(pars, sysUser.AdminId)
 		pars = append(pars, sysUser.AdminId)
 	}
 	}
 
 
+	chartIds := make([]int, 0)
+	chartIdMap := make(map[int]bool)
+	// 查询指标绑定的图表
+	edbListTemp, err := data_manage.GetEdbMappingListByEdbInfoId(edbInfoId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取图表信息失败"
+		br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range edbListTemp {
+		if _, ok := chartIdMap[v.ChartInfoId]; !ok {
+			chartIdMap[v.ChartInfoId] = true
+		}
+	}
+	// 查询跨品种的图表
+	tagXList, err := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取图表信息失败"
+		br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
+		return
+	}
+
+	for _, v := range tagXList {
+		if _, ok := chartIdMap[v.ChartInfoId]; !ok {
+			chartIdMap[v.ChartInfoId] = true
+		}
+	}
+
+	tagYList, err := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取图表信息失败"
+		br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range tagYList {
+		if _, ok := chartIdMap[v.ChartInfoId]; !ok {
+			chartIdMap[v.ChartInfoId] = true
+		}
+	}
+
 	// 获取当前账号的不可见图表
 	// 获取当前账号的不可见图表
-	noPermissionChartIdList := make([]int, 0)
 	{
 	{
 		obj := data_manage.EdbInfoNoPermissionAdmin{}
 		obj := data_manage.EdbInfoNoPermissionAdmin{}
 		confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
 		confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
@@ -4011,15 +4038,29 @@ func (this *EdbInfoController) RelationChartList() {
 			return
 			return
 		}
 		}
 		for _, v := range confList {
 		for _, v := range confList {
-			noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
+			if _, ok := chartIdMap[v.ChartInfoId]; ok {
+				delete(chartIdMap, v.ChartInfoId)
+			}
 		}
 		}
 	}
 	}
-	noPermissionChartIdNum := len(noPermissionChartIdList)
-	if noPermissionChartIdNum > 0 {
-		condition += ` AND a.chart_info_id not in  (` + utils.GetOrmInReplace(noPermissionChartIdNum) + `) `
-		pars = append(pars, noPermissionChartIdList)
+	for k, _ := range chartIdMap {
+		chartIds = append(chartIds, k)
 	}
 	}
 
 
+	// 关联指标
+	if len(chartIds) > 0 {
+		condition += `  AND a.chart_info_id in  (` + utils.GetOrmInReplace(len(chartIds)) + `)`
+		pars = append(pars, chartIds)
+	} else {
+		items := make([]*data_manage.ChartInfoView, 0)
+		resp.Paging = page
+		resp.List = items
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		return
+	}
+	// 得到图表ID
 	//获取关联图表列表
 	//获取关联图表列表
 	list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
 	list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 	if err != nil && err.Error() != utils.ErrNoRow() {

+ 3 - 2
controllers/data_manage/predict_edb_classify.go

@@ -302,7 +302,7 @@ func (this *PredictEdbClassifyController) DeleteCheck() {
 		return
 		return
 	}
 	}
 
 
-	deleteStatus, tipsMsg, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
+	deleteStatus, tipsMsg, tableList, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
 	if errMsg != `` {
 	if errMsg != `` {
 		br.Msg = errMsg
 		br.Msg = errMsg
 		br.ErrMsg = errMsg
 		br.ErrMsg = errMsg
@@ -317,6 +317,7 @@ func (this *PredictEdbClassifyController) DeleteCheck() {
 	resp := new(data_manage.ClassifyDeleteCheckResp)
 	resp := new(data_manage.ClassifyDeleteCheckResp)
 	resp.DeleteStatus = deleteStatus
 	resp.DeleteStatus = deleteStatus
 	resp.TipsMsg = tipsMsg
 	resp.TipsMsg = tipsMsg
+	resp.TableList = tableList
 	br.Ret = 200
 	br.Ret = 200
 	br.Msg = "检测成功"
 	br.Msg = "检测成功"
 	br.Success = true
 	br.Success = true
@@ -356,7 +357,7 @@ func (this *PredictEdbClassifyController) Delete() {
 		return
 		return
 	}
 	}
 
 
-	nextItem, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
+	nextItem, _, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
 	if errMsg != `` {
 	if errMsg != `` {
 		br.Msg = errMsg
 		br.Msg = errMsg
 		br.ErrMsg = errMsg
 		br.ErrMsg = errMsg

+ 28 - 6
controllers/sandbox/sandbox.go

@@ -1029,7 +1029,7 @@ func (this *SandboxController) EditSandboxClassify() {
 		br.ErrMsg = "查询子级分类id失败,Err:" + err.Error()
 		br.ErrMsg = "查询子级分类id失败,Err:" + err.Error()
 		return
 		return
 	}
 	}
-	err  = sandbox.UpdateSandboxClassifyChartPermissionById(req.ChartPermissionId, req.ChartPermissionName, ids)
+	err = sandbox.UpdateSandboxClassifyChartPermissionById(req.ChartPermissionId, req.ChartPermissionName, ids)
 	if err != nil {
 	if err != nil {
 		br.Msg = "修改子级分类错误"
 		br.Msg = "修改子级分类错误"
 		br.ErrMsg = "修改子级分类错误,Err:" + err.Error()
 		br.ErrMsg = "修改子级分类错误,Err:" + err.Error()
@@ -1646,7 +1646,7 @@ func (this *SandboxController) ChartClassifyMove() {
 					br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
 					br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
 					return
 					return
 				}
 				}
-				err  = sandbox.UpdateSandboxClassifyChartPermissionById(parentChartClassifyInfo.ChartPermissionId, parentChartClassifyInfo.ChartPermissionName, ids)
+				err = sandbox.UpdateSandboxClassifyChartPermissionById(parentChartClassifyInfo.ChartPermissionId, parentChartClassifyInfo.ChartPermissionName, ids)
 				if err != nil {
 				if err != nil {
 					br.Msg = "修改子级分类错误"
 					br.Msg = "修改子级分类错误"
 					br.ErrMsg = "修改子级分类错误,Err:" + err.Error()
 					br.ErrMsg = "修改子级分类错误,Err:" + err.Error()
@@ -2376,8 +2376,15 @@ func (this *SandboxController) LinkEdbInfoCheck() {
 		br.ErrMsg = "获取指标信息失败,err:" + err.Error()
 		br.ErrMsg = "获取指标信息失败,err:" + err.Error()
 		return
 		return
 	}
 	}
+	edbList := make([]*sandbox.SandboxLinkCheckItem, 0)
 	for _, v := range edbInfoList {
 	for _, v := range edbInfoList {
-		resp.EdbInfoIdList = append(resp.EdbInfoIdList, v.EdbInfoId)
+		tmp := &sandbox.SandboxLinkCheckItem{
+			Id:         v.EdbInfoId,
+			Name:       v.EdbName,
+			UniqueCode: v.UniqueCode,
+			ClassifyId: v.ClassifyId,
+		}
+		edbList = append(edbList, tmp)
 	}
 	}
 
 
 	chartList, err := data_manage.GetChartInfoByIdList(req.ChartInfoIdList)
 	chartList, err := data_manage.GetChartInfoByIdList(req.ChartInfoIdList)
@@ -2386,8 +2393,15 @@ func (this *SandboxController) LinkEdbInfoCheck() {
 		br.ErrMsg = `获取图表列表失败,ERR:` + err.Error()
 		br.ErrMsg = `获取图表列表失败,ERR:` + err.Error()
 		return
 		return
 	}
 	}
+	chartListTmp := make([]*sandbox.SandboxLinkCheckItem, 0)
 	for _, v := range chartList {
 	for _, v := range chartList {
-		resp.ChartInfoIdList = append(resp.ChartInfoIdList, v.ChartInfoId)
+		tmp := &sandbox.SandboxLinkCheckItem{
+			Id:         v.ChartInfoId,
+			Name:       v.ChartName,
+			UniqueCode: v.UniqueCode,
+			ClassifyId: v.ChartClassifyId,
+		}
+		chartListTmp = append(chartListTmp, tmp)
 	}
 	}
 
 
 	reportList, err := models.GetSimpleReportByIds(req.ReportIdList)
 	reportList, err := models.GetSimpleReportByIds(req.ReportIdList)
@@ -2396,10 +2410,18 @@ func (this *SandboxController) LinkEdbInfoCheck() {
 		br.ErrMsg = `获取报告列表失败,ERR:` + err.Error()
 		br.ErrMsg = `获取报告列表失败,ERR:` + err.Error()
 		return
 		return
 	}
 	}
+	reportListTmp := make([]*sandbox.SandboxLinkCheckItem, 0)
 	for _, v := range reportList {
 	for _, v := range reportList {
-		resp.ReportIdList = append(resp.ReportIdList, v.Id)
+		tmp := &sandbox.SandboxLinkCheckItem{
+			Id:         v.Id,
+			Name:       v.Title,
+			UniqueCode: v.ReportCode,
+		}
+		reportListTmp = append(reportListTmp, tmp)
 	}
 	}
-
+	resp.EdbInfoIdList = edbList
+	resp.ChartInfoIdList = chartListTmp
+	resp.ReportIdList = reportListTmp
 	br.Ret = 200
 	br.Ret = 200
 	br.Msg = "检测成功"
 	br.Msg = "检测成功"
 	br.Success = true
 	br.Success = true

+ 9 - 0
models/data_manage/chart_edb_mapping.go

@@ -210,6 +210,15 @@ func GetChartEdbMappingByEdbInfoId(edbInfoId int) (item *ChartEdbInfoMapping, er
 	return
 	return
 }
 }
 
 
+// GetEdbMappingListByEdbInfoId 根据指标id获取edb_mapping
+func GetEdbMappingListByEdbInfoId(edbInfoId int) (item []*ChartEdbInfoMapping, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM chart_edb_mapping
+			 WHERE edb_info_id = ? limit 1`
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&item)
+	return
+}
+
 // GetChartEdbMappingByFutureGoodEdbInfoId 根据指标id获取edb_mapping
 // GetChartEdbMappingByFutureGoodEdbInfoId 根据指标id获取edb_mapping
 func GetChartEdbMappingByFutureGoodEdbInfoId(edbInfoId int) (item *ChartEdbInfoMapping, err error) {
 func GetChartEdbMappingByFutureGoodEdbInfoId(edbInfoId int) (item *ChartEdbInfoMapping, err error) {
 	o := orm.NewOrmUsingDB("data")
 	o := orm.NewOrmUsingDB("data")

+ 16 - 0
models/data_manage/cross_variety/chart_info_cross_variety.go

@@ -72,6 +72,22 @@ func GetChartInfoCrossVarietyByChartInfoId(id int) (item *ChartInfoCrossVariety,
 	return
 	return
 }
 }
 
 
+func GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId int) (items []*ChartInfoCrossVariety, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT a.* FROM chart_info_cross_variety a 
+         join chart_tag_variety b on a.chart_x_tag_id=b.chart_tag_id WHERE b.edb_info_id = ? `
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
+	return
+}
+
+func GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId int) (items []*ChartInfoCrossVariety, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT a.* FROM chart_info_cross_variety a 
+         join chart_tag_variety b on a.chart_y_tag_id=b.chart_tag_id WHERE b.edb_info_id = ? `
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
+	return
+}
+
 // CreateChart
 // CreateChart
 // @Description: 新增跨品种图表
 // @Description: 新增跨品种图表
 // @author: Roc
 // @author: Roc

+ 11 - 0
models/data_manage/cross_variety/chart_tag_variety.go

@@ -260,3 +260,14 @@ func GetChartTagVarietyListByTagIdList(chartTagIdList []int) (items []*ChartTagV
 
 
 	return
 	return
 }
 }
+
+func DeleteChartTagVarietyByEdbInfoId(edbInfoId int) (err error) {
+	// 删除不存在的品种
+	o := orm.NewOrmUsingDB("data")
+	sql := ` DELETE FROM chart_tag_variety WHERE edb_info_id=?`
+	_, err = o.Raw(sql, edbInfoId, edbInfoId).Exec()
+	if err != nil {
+		return
+	}
+	return
+}

+ 4 - 2
models/data_manage/edb_classify.go

@@ -1,6 +1,7 @@
 package data_manage
 package data_manage
 
 
 import (
 import (
+	"eta/eta_api/models/data_manage/excel"
 	"eta/eta_api/utils"
 	"eta/eta_api/utils"
 	"fmt"
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/beego/beego/v2/client/orm"
@@ -298,8 +299,9 @@ type EdbClassifyListResp struct {
 }
 }
 
 
 type ClassifyDeleteCheckResp struct {
 type ClassifyDeleteCheckResp struct {
-	DeleteStatus int    `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:若目录关联指标不可删除,2:确认删除当前目录及包含的子目录吗,3:当前指标已用作画图,不可删除"`
-	TipsMsg      string `description:"提示信息"`
+	DeleteStatus int                    `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:若目录关联指标不可删除,2:确认删除当前目录及包含的子目录吗,3:当前指标已用作画图,不可删除"`
+	TipsMsg      string                 `description:"提示信息"`
+	TableList    []*excel.ExcelBaseInfo `description:"关联的表格"`
 }
 }
 
 
 type ClassifyDeleteCheckReq struct {
 type ClassifyDeleteCheckReq struct {

+ 12 - 1
models/data_manage/edb_info.go

@@ -248,10 +248,21 @@ func DeleteEdbInfoAndData(edbInfoId, source, subSource int) (err error) {
 	// 删除计算指标的关系
 	// 删除计算指标的关系
 	sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id=? `
 	sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id=? `
 	_, err = to.Raw(sql, edbInfoId).Exec()
 	_, err = to.Raw(sql, edbInfoId).Exec()
-
+	if err != nil {
+		return
+	}
 	// 删除预测指标的配置
 	// 删除预测指标的配置
 	sql = ` DELETE FROM predict_edb_conf WHERE predict_edb_info_id=? `
 	sql = ` DELETE FROM predict_edb_conf WHERE predict_edb_info_id=? `
 	_, err = to.Raw(sql, edbInfoId).Exec()
 	_, err = to.Raw(sql, edbInfoId).Exec()
+	if err != nil {
+		return
+	}
+	// 删除跨品种分析标签绑定的指标
+	sql = ` DELETE FROM chart_tag_variety WHERE edb_info_id=?`
+	_, err = to.Raw(sql, edbInfoId).Exec()
+	if err != nil {
+		return
+	}
 	return
 	return
 }
 }
 
 

+ 18 - 2
models/data_manage/excel/excel_edb_mapping.go

@@ -31,12 +31,19 @@ func (e *ExcelEdbMapping) Add() (err error) {
 	return
 	return
 }
 }
 
 
+// Update 更新 excel表格基础信息
+func (e *ExcelEdbMapping) Update(cols []string) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	_, err = o.Update(e, cols...)
+	return
+}
+
 // GetExcelEdbMappingByEdbInfoId 根据指标id获取配置关系
 // GetExcelEdbMappingByEdbInfoId 根据指标id获取配置关系
-func GetExcelEdbMappingByEdbInfoId(edbInfoId int) (item *ExcelEdbMapping, err error) {
+func GetExcelEdbMappingByEdbInfoId(edbInfoId int) (items []*ExcelEdbMapping, err error) {
 	o := orm.NewOrmUsingDB("data")
 	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT *  FROM excel_edb_mapping WHERE 1=1 AND edb_info_id = ? `
 	sql := ` SELECT *  FROM excel_edb_mapping WHERE 1=1 AND edb_info_id = ? `
 
 
-	err = o.Raw(sql, edbInfoId).QueryRow(&item)
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
 	return
 	return
 }
 }
 
 
@@ -89,6 +96,15 @@ func GetNoCustomAnalysisExcelEdbMappingCount(edbInfoId int) (count int, err erro
 	return
 	return
 }
 }
 
 
+func GetNoCustomAnalysisExcelEdbMapping(edbInfoId int) (ids []int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT b.excel_info_id FROM excel_edb_mapping a 
+                          join excel_info b on a.excel_info_id=b.excel_info_id
+                          WHERE edb_info_id=? AND a.source != 4 AND b.is_delete = 0`
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&ids)
+	return
+}
+
 // GetAllExcelEdbMappingByExcelInfoId 根据excel的id获取所有的指标
 // GetAllExcelEdbMappingByExcelInfoId 根据excel的id获取所有的指标
 func GetAllExcelEdbMappingByExcelInfoId(excelInfoId int) (items []*ExcelEdbMapping, err error) {
 func GetAllExcelEdbMappingByExcelInfoId(excelInfoId int) (items []*ExcelEdbMapping, err error) {
 	o := orm.NewOrmUsingDB("data")
 	o := orm.NewOrmUsingDB("data")

+ 74 - 0
models/data_manage/excel/excel_info.go

@@ -1,9 +1,12 @@
 package excel
 package excel
 
 
 import (
 import (
+	"eta/eta_api/models/data_manage"
+	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/utils"
 	"eta/eta_api/utils"
 	"fmt"
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/beego/beego/v2/client/orm"
+	"strconv"
 	"time"
 	"time"
 )
 )
 
 
@@ -63,6 +66,17 @@ type MyExcelInfoList struct {
 	Editor             string                `description:"编辑人"`
 	Editor             string                `description:"编辑人"`
 }
 }
 
 
+type ExcelBaseInfo struct {
+	ExcelInfoId     int    `orm:"column(excel_info_id);pk"`
+	Source          int    `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
+	ExcelType       int    `description:"表格类型,1:指标列,2:日期列,默认:1"`
+	ExcelName       string `description:"表格名称"`
+	UniqueCode      string `description:"表格唯一编码"`
+	ExcelClassifyId int    `description:"表格分类id"`
+	SysUserId       int    `description:"操作人id"`
+	SysUserRealName string `description:"操作人真实姓名"`
+}
+
 // AddExcelInfo 新增表格
 // AddExcelInfo 新增表格
 func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping, childExcel *ExcelInfo) (err error) {
 func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping, childExcel *ExcelInfo) (err error) {
 	o, err := orm.NewOrmUsingDB("data").Begin()
 	o, err := orm.NewOrmUsingDB("data").Begin()
@@ -731,3 +745,63 @@ type ExcelInfoDetailButton struct {
 	RefreshEdbButton bool `description:"是否可刷新指标"`
 	RefreshEdbButton bool `description:"是否可刷新指标"`
 	OpWorkerButton   bool `description:"是否修改协作人"`
 	OpWorkerButton   bool `description:"是否修改协作人"`
 }
 }
+
+func GetExcelBaseInfoByExcelInfoIdList(excelInfoIdList []int) (items []*ExcelBaseInfo, err error) {
+	num := len(excelInfoIdList)
+	if num <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
+	_, err = o.Raw(sql, excelInfoIdList).QueryRows(&items)
+
+	return
+}
+
+// ReplaceEdbInExcel 替换表格中的指标
+func ReplaceEdbInExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, updateExcelList []*ExcelInfo) (err error) {
+	var errmsg string
+	logMsg := `` // 记录替换的日志
+	replaceTotal := 0
+	o := orm.NewOrmUsingDB("data")
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+			if logMsg != `` {
+				utils.FileLog.Info(fmt.Sprintf("替换表格中的指标记录,替换总表格数:%d,旧的指标id:%d,新的指标id:%d;%s", replaceTotal, oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, logMsg))
+			}
+		}
+		if errmsg != "" {
+			fmt.Println("errmsg:" + errmsg)
+		}
+		if err != nil && errmsg != "" {
+			go alarm_msg.SendAlarmMsg("替换替换配置中的指标记录失败提醒,errmsg:"+errmsg, 3)
+		}
+	}()
+	// 替换表格中的内容
+	for _, excelInfo := range updateExcelList {
+		//更新配置中的指标A
+		sql := `UPDATE excel_info SET content=?, modify_time=? WHERE excel_info_id=?`
+		_, err = to.Raw(sql, excelInfo.Content, time.Now(), excelInfo.ExcelInfoId).Exec()
+		if err != nil {
+			errmsg = "更新表格内容失败:Err:" + err.Error()
+			return
+		}
+		//更新配置中的指标B
+		sql = `UPDATE excel_edb_mapping SET edb_info_id=?, modify_time=? WHERE excel_info_id=? and edb_info_id=?`
+		_, err = to.Raw(sql, newEdbInfo.EdbInfoId, time.Now(), excelInfo.ExcelInfoId, oldEdbInfo.EdbInfoId).Exec()
+		if err != nil {
+			errmsg = "更新指标B关联图表配置信息失败:Err:" + err.Error()
+			return
+		}
+		logMsg += `涉及到的表格id:` + strconv.Itoa(excelInfo.ExcelInfoId) + ";"
+		replaceTotal += 1
+	}
+	return
+}

+ 116 - 0
models/data_manage/multiple_graph_config_chart_mapping.go

@@ -1,7 +1,12 @@
 package data_manage
 package data_manage
 
 
 import (
 import (
+	"eta/eta_api/services/alarm_msg"
+	"eta/eta_api/utils"
+	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/beego/beego/v2/client/orm"
+	"strconv"
+	"strings"
 	"time"
 	"time"
 )
 )
 
 
@@ -60,3 +65,114 @@ func GetMultipleGraphConfigChartMappingListById(configId int) (items []*Multiple
 
 
 	return
 	return
 }
 }
+
+// ReplaceMultipleGraphConfigChartEdb 替换配置中的指标
+func ReplaceMultipleGraphConfigChartEdb(oldEdbInfo, newEdbInfo *EdbInfo) (replaceConfigTotal int, err error) {
+	var errmsg string
+	logMsg := `` // 记录替换的日志
+
+	o := orm.NewOrmUsingDB("data")
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+			if logMsg != `` {
+				utils.FileLog.Info(fmt.Sprintf("替换替换配置中的指标记录,旧的指标id:%d,新的指标id:%d;%s", oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, logMsg))
+			}
+		}
+		if errmsg != "" {
+			fmt.Println("errmsg:" + errmsg)
+		}
+		if err != nil && errmsg != "" {
+			go alarm_msg.SendAlarmMsg("替换替换配置中的指标记录失败提醒,errmsg:"+errmsg, 3)
+		}
+	}()
+	//替换multiple_graph_config中的指标
+	{
+		multipleGraphConfigList := make([]*MultipleGraphConfig, 0)
+		csql := `SELECT * FROM multiple_graph_config WHERE (edb_info_id_a=? or edb_info_id_b=?)`
+		_, err = to.Raw(csql, oldEdbInfo.EdbInfoId, oldEdbInfo.EdbInfoId).QueryRows(&multipleGraphConfigList)
+		if err != nil {
+			errmsg = "获取指标关联图表配置信息失败:Err:" + err.Error()
+			return
+		}
+		replaceConfigTotal = len(multipleGraphConfigList)
+		configIdMap := make(map[int]int)
+		configIds := make([]int, 0)
+		configIdStr := make([]string, 0)
+		for _, mv := range multipleGraphConfigList {
+			if _, ok := configIdMap[mv.MultipleGraphConfigId]; !ok {
+				//判断如果达到1000个数,则执行更新语句
+				if len(configIds) >= 1000 {
+					//更新配置中的指标A
+					sql := `UPDATE multiple_graph_config SET edb_info_id_a=?, update_time=? WHERE multiple_graph_config_id IN (?) and edb_info_id_a=?`
+					_, err = to.Raw(sql, newEdbInfo.EdbInfoId, time.Now(), configIds, oldEdbInfo.EdbInfoId).Exec()
+					if err != nil {
+						errmsg = "更新指标A关联图表配置信息失败:Err:" + err.Error()
+						return
+					}
+					//更新配置中的指标B
+					sql = `UPDATE multiple_graph_config SET edb_info_id_b=?, update_time=? WHERE multiple_graph_config_id IN (?) and edb_info_id_b=?`
+					_, err = to.Raw(sql, newEdbInfo.EdbInfoId, time.Now(), configIds, oldEdbInfo.EdbInfoId).Exec()
+					if err != nil {
+						errmsg = "更新指标B关联图表配置信息失败:Err:" + err.Error()
+						return
+					}
+					// 更新指标id
+					sql = `UPDATE multiple_graph_config_edb_mapping SET edb_info_id=?, modify_time=? WHERE multiple_graph_config_id IN (?) and edb_info_id=?`
+					_, err = to.Raw(sql, newEdbInfo.EdbInfoId, time.Now(), configIds, oldEdbInfo.EdbInfoId).Exec()
+					if err != nil {
+						errmsg = "更新指标id关联图表配置信息失败:Err:" + err.Error()
+						return
+					}
+					logMsg += `涉及到的配置id:` + strings.Join(configIdStr, ",") + ";"
+					configIds = make([]int, 0)
+					configIdStr = make([]string, 0)
+				}
+				configIds = append(configIds, mv.MultipleGraphConfigId)
+				configIdStr = append(configIdStr, strconv.Itoa(mv.MultipleGraphConfigId))
+				configIdMap[mv.MultipleGraphConfigId] = mv.MultipleGraphConfigId
+			}
+		}
+		if len(configIds) >= 1000 {
+			//更新配置中的指标A
+			sql := `UPDATE multiple_graph_config SET edb_info_id_a=?, update_time=? WHERE multiple_graph_config_id IN (?) and edb_info_id_a=?`
+			_, err = to.Raw(sql, newEdbInfo.EdbInfoId, time.Now(), configIds, oldEdbInfo.EdbInfoId).Exec()
+			if err != nil {
+				errmsg = "更新指标A关联图表配置信息失败:Err:" + err.Error()
+				return
+			}
+			//更新配置中的指标B
+			sql = `UPDATE multiple_graph_config SET edb_info_id_b=?, update_time=? WHERE multiple_graph_config_id IN (?) and edb_info_id_b=?`
+			_, err = to.Raw(sql, newEdbInfo.EdbInfoId, time.Now(), configIds, oldEdbInfo.EdbInfoId).Exec()
+			if err != nil {
+				errmsg = "更新指标B关联图表配置信息失败:Err:" + err.Error()
+				return
+			}
+			// 更新指标id
+			sql = `UPDATE multiple_graph_config_edb_mapping SET edb_info_id=?, modify_time=? WHERE multiple_graph_config_id IN (?) and edb_info_id=?`
+			_, err = to.Raw(sql, newEdbInfo.EdbInfoId, time.Now(), configIds, oldEdbInfo.EdbInfoId).Exec()
+			if err != nil {
+				errmsg = "更新指标id关联图表配置信息失败:Err:" + err.Error()
+				return
+			}
+			logMsg += `涉及到的配置id:` + strings.Join(configIdStr, ",") + ";"
+			configIds = make([]int, 0)
+			configIdStr = make([]string, 0)
+		}
+	}
+
+	// 替换跨品种标签绑定得到指标ID
+	sql := `UPDATE chart_tag_variety SET edb_info_id=?, modify_time=? WHERE edb_info_id=?`
+	_, err = to.Raw(sql, newEdbInfo.EdbInfoId, time.Now(), oldEdbInfo.EdbInfoId).Exec()
+	if err != nil {
+		errmsg = "更新指标id关联跨品种分析标签失败:Err:" + err.Error()
+		return
+	}
+	return
+}

+ 2 - 2
models/data_manage/my_chart.go

@@ -870,7 +870,7 @@ func GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(condition string, par
 func GetRelationChartListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*ChartInfoView, err error) {
 func GetRelationChartListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*ChartInfoView, err error) {
 	o := orm.NewOrmUsingDB("data")
 	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT a.* FROM chart_info AS a 
 	sql := ` SELECT a.* FROM chart_info AS a 
-	JOIN chart_edb_mapping AS b on a.chart_info_id = b.chart_info_id WHERE 1=1 `
+	WHERE 1=1 `
 	if condition != "" {
 	if condition != "" {
 		sql += condition
 		sql += condition
 	}
 	}
@@ -883,7 +883,7 @@ func GetRelationChartListByCondition(condition string, pars []interface{}, start
 func GetRelationChartListCountByCondition(condition string, pars []interface{}) (count int, err error) {
 func GetRelationChartListCountByCondition(condition string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrmUsingDB("data")
 	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT COUNT(1) AS count FROM chart_info AS a 
 	sql := ` SELECT COUNT(1) AS count FROM chart_info AS a 
-	JOIN chart_edb_mapping AS b on a.chart_info_id = b.chart_info_id WHERE 1=1 `
+	WHERE 1=1 `
 	if condition != "" {
 	if condition != "" {
 		sql += condition
 		sql += condition
 	}
 	}

+ 2 - 2
models/report.go

@@ -230,12 +230,12 @@ func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
 }
 }
 
 
 // GetSimpleReportByIds 根据报告ID查询报告基本信息
 // GetSimpleReportByIds 根据报告ID查询报告基本信息
-func GetSimpleReportByIds(reportIds []int) (list []*ReportDetail, err error) {
+func GetSimpleReportByIds(reportIds []int) (list []*Report, err error) {
 	if len(reportIds) == 0 {
 	if len(reportIds) == 0 {
 		return
 		return
 	}
 	}
 	o := orm.NewOrmUsingDB("rddp")
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `SELECT id, title FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
+	sql := `SELECT id, title, report_code FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
 	_, err = o.Raw(sql, reportIds).QueryRows(&list)
 	_, err = o.Raw(sql, reportIds).QueryRows(&list)
 	return
 	return
 }
 }

+ 12 - 5
models/sandbox/sandbox_classify.go

@@ -247,10 +247,17 @@ type SandboxLinkCheckReq struct {
 	ReportIdList    []int `description:"报告id列表"`
 	ReportIdList    []int `description:"报告id列表"`
 }
 }
 
 
+type SandboxLinkCheckItem struct {
+	Id         int    `description:"id"`
+	Name       string `description:"名称"`
+	UniqueCode string `description:"唯一编码"`
+	ClassifyId int    `description:"分类id"`
+}
+
 type SandboxLinkCheckResp struct {
 type SandboxLinkCheckResp struct {
-	EdbInfoIdList   []int `description:"指标id列表"`
-	ChartInfoIdList []int `description:"图库id列表"`
-	ReportIdList    []int `description:"报告id列表"`
+	EdbInfoIdList   []*SandboxLinkCheckItem `description:"指标id列表"`
+	ChartInfoIdList []*SandboxLinkCheckItem `description:"图库id列表"`
+	ReportIdList    []*SandboxLinkCheckItem `description:"报告id列表"`
 }
 }
 
 
 // 获取所有子级分类id
 // 获取所有子级分类id
@@ -272,7 +279,7 @@ WHERE sc.parent_id = @pv
 // UpdateSandboxClassifyChartPermissionById 根据沙盘id更新品种
 // UpdateSandboxClassifyChartPermissionById 根据沙盘id更新品种
 func UpdateSandboxClassifyChartPermissionById(ChartPermissionId int, ChartPermissionName, Ids string) (err error) {
 func UpdateSandboxClassifyChartPermissionById(ChartPermissionId int, ChartPermissionName, Ids string) (err error) {
 	o := orm.NewOrmUsingDB("data")
 	o := orm.NewOrmUsingDB("data")
-	sql := ` UPDATE sandbox_classify SET chart_permission_id = ?, chart_permission_name = ? WHERE sandbox_classify_id IN ( `+Ids +` ) `
+	sql := ` UPDATE sandbox_classify SET chart_permission_id = ?, chart_permission_name = ? WHERE sandbox_classify_id IN ( ` + Ids + ` ) `
 	_, err = o.Raw(sql, ChartPermissionId, ChartPermissionName).Exec()
 	_, err = o.Raw(sql, ChartPermissionId, ChartPermissionName).Exec()
 	return
 	return
-}
+}

+ 81 - 13
services/data/edb_classify.go

@@ -449,7 +449,7 @@ func EditEdbClassify(classifyId int, classifyName, lang string, sysUser *system.
 }
 }
 
 
 // DeleteCheck 删除检测
 // DeleteCheck 删除检测
-func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus int, tipsMsg string, err error, errMsg string) {
+func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus int, tipsMsg string, tableList []*excel.ExcelBaseInfo, err error, errMsg string) {
 	//删除分类
 	//删除分类
 	if classifyId > 0 && edbInfoId == 0 {
 	if classifyId > 0 && edbInfoId == 0 {
 		// 查找分类
 		// 查找分类
@@ -579,22 +579,56 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 
 
 		// 判断指标是否用作表格引用
 		// 判断指标是否用作表格引用
 		{
 		{
-			calculateCount, tmpErr := excel.GetNoCustomAnalysisExcelEdbMappingCount(edbInfoId)
+			excelIds, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 				errMsg = "删除失败"
 				errMsg = "删除失败"
 				err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
 				err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
 				return
 				return
 			}
 			}
-			if calculateCount > 0 {
+			//英文翻译:
+			//1、当前指标已用作画图,不可删除:The current metric is in use for charting and cannot be deleted
+			//2、当前指标已被表格引用,不可删除:The current metric is referenced by a table and cannot be deleted
+			//3、删除失败:Deletion failed
+			//4、知道了:Understood
+			if len(excelIds) > 0 {
 				deleteStatus = 3
 				deleteStatus = 3
-				tipsMsg = "当前指标已添加到表格,不可删除"
+				tipsMsg = "当前指标已被表格引用,不可删除"
+				tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
+				if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+					errMsg = "删除失败"
+					err = errors.New("判断指标是否用作表格引用,GetExcelBaseInfoByExcelInfoIdList Err:" + tmpErr.Error())
+					return
+				}
 				return
 				return
 			}
 			}
 		}
 		}
 
 
 		// 判断指标是否用作跨品种图表使用
 		// 判断指标是否用作跨品种图表使用
 		{
 		{
-			calculateCount, tmpErr := cross_variety.GetCountByEdbInfoId(edbInfoId)
+			// todo 如果绑定的标签未画图,则允许删除绑定
+			// 查询跨品种的图表
+			tagXList, tmpErr := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
+			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+				errMsg = "删除失败"
+				err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByXEdbInfoId Err:" + tmpErr.Error())
+				return
+			}
+			if len(tagXList) > 0 {
+				errMsg = "当前指标已添加到跨品种分析,不可删除"
+				return
+			}
+			tagYList, tmpErr := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
+			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+				errMsg = "删除失败"
+				err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByYEdbInfoId Err:" + tmpErr.Error())
+				return
+			}
+
+			if len(tagYList) > 0 {
+				errMsg = "当前指标已添加到跨品种分析,不可删除"
+				return
+			}
+			/*calculateCount, tmpErr := cross_variety.GetCountByEdbInfoId(edbInfoId)
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 				errMsg = "删除失败"
 				errMsg = "删除失败"
 				err = errors.New("判断指标是否用作跨品种图表使用,GetCountByEdbInfoId Err:" + tmpErr.Error())
 				err = errors.New("判断指标是否用作跨品种图表使用,GetCountByEdbInfoId Err:" + tmpErr.Error())
@@ -604,14 +638,14 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 				deleteStatus = 3
 				deleteStatus = 3
 				tipsMsg = "当前指标已添加到跨品种分析,不可删除"
 				tipsMsg = "当前指标已添加到跨品种分析,不可删除"
 				return
 				return
-			}
+			}*/
 		}
 		}
 	}
 	}
 	return
 	return
 }
 }
 
 
 // Delete 删除分类/指标
 // Delete 删除分类/指标
-func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, requestUrl string) (nextItem *data_manage.EdbInfo, err error, errMsg string) {
+func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, requestUrl string) (nextItem *data_manage.EdbInfo, tableList []*excel.ExcelBaseInfo, err error, errMsg string) {
 	//删除分类
 	//删除分类
 	if classifyId > 0 && edbInfoId == 0 {
 	if classifyId > 0 && edbInfoId == 0 {
 		// 查找分类
 		// 查找分类
@@ -733,21 +767,55 @@ func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, reque
 
 
 		// 判断指标是否用作表格引用
 		// 判断指标是否用作表格引用
 		{
 		{
-			calculateCount, tmpErr := excel.GetNoCustomAnalysisExcelEdbMappingCount(edbInfoId)
+			excelIds, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 				errMsg = "删除失败"
 				errMsg = "删除失败"
 				err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
 				err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
 				return
 				return
 			}
 			}
-			if calculateCount > 0 {
-				errMsg = "当前指标已添加到表格,不可删除"
+			//英文翻译:
+			//1、当前指标已用作画图,不可删除:The current metric is in use for charting and cannot be deleted
+			//2、当前指标已被表格引用,不可删除:The current metric is referenced by a table and cannot be deleted
+			//3、删除失败:Deletion failed
+			//4、知道了:Understood
+			if len(excelIds) > 0 {
+				errMsg = "当前指标已被表格引用,不可删除"
+				tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
+				if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+					errMsg = "删除失败"
+					err = errors.New("判断指标是否用作表格引用,GetExcelBaseInfoByExcelInfoIdList Err:" + tmpErr.Error())
+					return
+				}
 				return
 				return
 			}
 			}
 		}
 		}
-
 		// 判断指标是否用作跨品种图表使用
 		// 判断指标是否用作跨品种图表使用
 		{
 		{
-			calculateCount, tmpErr := cross_variety.GetCountByEdbInfoId(edbInfoId)
+			// todo 如果绑定的标签未画图,则允许删除绑定
+			// 查询跨品种的图表
+			tagXList, tmpErr := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
+			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+				errMsg = "删除失败"
+				err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByXEdbInfoId Err:" + tmpErr.Error())
+				return
+			}
+			if len(tagXList) > 0 {
+				errMsg = "当前指标已添加到跨品种分析,不可删除"
+				return
+			}
+			tagYList, tmpErr := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
+			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+				errMsg = "删除失败"
+				err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByYEdbInfoId Err:" + tmpErr.Error())
+				return
+			}
+
+			if len(tagYList) > 0 {
+				errMsg = "当前指标已添加到跨品种分析,不可删除"
+				return
+			}
+
+			/*calculateCount, tmpErr := cross_variety.GetCountByEdbInfoId(edbInfoId)
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 				errMsg = "删除失败"
 				errMsg = "删除失败"
 				err = errors.New("判断指标是否用作跨品种图表使用,GetCountByEdbInfoId Err:" + tmpErr.Error())
 				err = errors.New("判断指标是否用作跨品种图表使用,GetCountByEdbInfoId Err:" + tmpErr.Error())
@@ -756,7 +824,7 @@ func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, reque
 			if calculateCount > 0 {
 			if calculateCount > 0 {
 				errMsg = "当前指标已添加到跨品种分析,不可删除"
 				errMsg = "当前指标已添加到跨品种分析,不可删除"
 				return
 				return
-			}
+			}*/
 		}
 		}
 
 
 		//真实删除
 		//真实删除

+ 172 - 0
services/data/excel/excel_info.go

@@ -527,3 +527,175 @@ func GetExcelEdbBatchRefreshKey(source string, primaryId, subId int) string {
 
 
 	return fmt.Sprint("batch_refresh_excel_edb:", source, ":", primaryId, ":", subId)
 	return fmt.Sprint("batch_refresh_excel_edb:", source, ":", primaryId, ":", subId)
 }
 }
+
+// ReplaceEdbInExcel 替换表格中的指标
+func ReplaceEdbInExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo) (err error) {
+	//查询和指标相关的 表格
+	mappingList, err := excel.GetExcelEdbMappingByEdbInfoId(oldEdbInfo.EdbInfoId)
+	if err != nil {
+		err = fmt.Errorf("查询和指标相关的表格失败,错误:%s", err.Error())
+		return
+	}
+	updateList := make([]*excel.ExcelInfo, 0)
+	// 循环列表,根据表格类型单独处理
+	for _, excelMapping := range mappingList {
+		//查询和指标相关的混合表格
+		excelInfo, tmpErr := excel.GetExcelInfoById(excelMapping.ExcelInfoId)
+		if tmpErr != nil {
+			err = fmt.Errorf("查询和指标相关的混合表格失败,错误:%s", tmpErr.Error())
+			return
+		}
+		// 清除缓存
+		key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelInfo.UniqueCode
+		if utils.Re == nil {
+			_ = utils.Rc.Delete(key)
+		}
+		// 根据表格类型,调用不同的处理函数
+		switch excelMapping.Source {
+		case utils.TIME_TABLE: // 时间序列表格
+			// 替换余额表格中的指标
+			newExcelInfo, e := replaceEdbInTimeExcel(oldEdbInfo, newEdbInfo, excelInfo)
+			if e != nil {
+				err = fmt.Errorf("替换余额表格中的指标失败,错误:%s", e.Error())
+				return
+			}
+			updateList = append(updateList, newExcelInfo)
+		case utils.MIXED_TABLE:
+			// 替换余额表格中的指标
+			newExcelInfo, e := replaceEdbInBalanceExcel(oldEdbInfo, newEdbInfo, excelInfo)
+			if e != nil {
+				err = fmt.Errorf("替换余额表格中的指标失败,错误:%s", e.Error())
+				return
+			}
+			updateList = append(updateList, newExcelInfo)
+		default:
+			// 其他表格类型的处理逻辑
+		}
+	}
+
+	err = excel.ReplaceEdbInExcel(oldEdbInfo, newEdbInfo, updateList)
+	if err != nil {
+		err = fmt.Errorf("替换表格中的指标失败,错误:%s", err.Error())
+	}
+
+	//todo 是否需要刷新表格中的指标数据
+	return
+}
+
+func replaceEdbInBalanceExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, excelInfo *excel.ExcelInfo) (newExcelInfo *excel.ExcelInfo, err error) {
+	newExcelInfo = excelInfo
+	var mixedTableReq request.MixedTableReq
+	err = json.Unmarshal([]byte(excelInfo.Content), &mixedTableReq)
+	if err != nil {
+		err = fmt.Errorf("表格json转结构体失败,Err:" + err.Error())
+		return
+	}
+	// 处理data
+	configList := mixedTableReq.Data
+	for ck, rowList := range configList {
+		for rk, cell := range rowList {
+			switch cell.DataType {
+			case request.EdbDT: // 指标信息
+				if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
+					//更换成新指标ID
+					configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
+				}
+			case request.InsertDataDT, request.PopInsertDataDT: // 插值、弹框插值
+				if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
+					//更换成新指标ID
+					configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
+				}
+			case request.InsertEdbCalculateDataDT: // 插入指标计算公式生成的值
+				var config request.CalculateConf
+				err = json.Unmarshal([]byte(cell.Value), &config)
+				if err != nil {
+					return
+				}
+				if cell.EdbInfoId == oldEdbInfo.EdbInfoId {
+					//更换成新指标ID
+					configList[ck][rk].EdbInfoId = newEdbInfo.EdbInfoId
+				}
+				if config.EdbInfoId == oldEdbInfo.EdbInfoId {
+					config.EdbInfoId = newEdbInfo.EdbInfoId
+				}
+				var configStr []byte
+				configStr, err = json.Marshal(config)
+				if err != nil {
+					return
+				}
+				configList[ck][rk].Value = string(configStr)
+			case request.DateDT: // 日期类型
+				// 指标日期类型的单元格需要额外将指标id取出来
+				if cell.DataTimeType == request.EdbDateDT {
+					var config request.EdbDateConf
+					err = json.Unmarshal([]byte(cell.Value), &config)
+					if err != nil {
+						return
+					}
+					if config.EdbInfoId == oldEdbInfo.EdbInfoId {
+						config.EdbInfoId = newEdbInfo.EdbInfoId
+						var configStr []byte
+						configStr, err = json.Marshal(config)
+						if err != nil {
+							return
+						}
+						configList[ck][rk].Value = string(configStr)
+					}
+				}
+			}
+		}
+	}
+
+	mixedTableReq.Data = configList
+	var newContentByte []byte
+	newContentByte, err = json.Marshal(mixedTableReq)
+	if err != nil {
+		return
+	}
+	// 生成的新内容替换原先的旧内容
+	excelInfo.Content = string(newContentByte)
+	newExcelInfo = excelInfo
+	return
+}
+
+func replaceEdbInTimeExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, excelInfo *excel.ExcelInfo) (newExcelInfo *excel.ExcelInfo, err error) {
+	newExcelInfo = excelInfo
+
+	var tableDataConfig TableDataConfig
+	err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
+	if err != nil {
+		err = errors.New("表格json转结构体失败,Err:" + err.Error())
+		return
+	}
+	if len(tableDataConfig.EdbInfoIdList) <= 0 {
+		return
+	}
+	// 实际期数没有的情况下,直接返回吧
+	if tableDataConfig.Num <= 0 {
+		return
+	}
+
+	// 先处理edbInfoList
+	for k, id := range tableDataConfig.EdbInfoIdList {
+		if id == oldEdbInfo.EdbInfoId {
+			tableDataConfig.EdbInfoIdList[k] = newEdbInfo.EdbInfoId
+		}
+	}
+
+	// 先处理tableEdbInfoList
+	for k, tableEdbInfo := range tableDataConfig.TableEdbInfoList {
+		if tableEdbInfo.EdbInfoId == oldEdbInfo.EdbInfoId {
+			tableDataConfig.TableEdbInfoList[k].EdbInfoId = newEdbInfo.EdbInfoId
+		}
+	}
+
+	var newContentByte []byte
+	newContentByte, err = json.Marshal(tableDataConfig)
+	if err != nil {
+		return
+	}
+	// 生成的新内容替换原先的旧内容
+	excelInfo.Content = string(newContentByte)
+	newExcelInfo = excelInfo
+	return
+}

+ 3 - 1
static/ErrMsgConfig.json

@@ -50,5 +50,7 @@
   "系统处理中,请稍后重试!": "The system is processing, please try again later!",
   "系统处理中,请稍后重试!": "The system is processing, please try again later!",
   "固定日期不可为空": "The fixed date cannot be empty",
   "固定日期不可为空": "The fixed date cannot be empty",
   "日期数量已达上限!": "The number of dates has reached the limit!",
   "日期数量已达上限!": "The number of dates has reached the limit!",
-  "该品种已在指标库生成指标,不可删除": "This variety has already generated indicators in the index library and cannot be deleted"
+  "该品种已在指标库生成指标,不可删除": "This variety has already generated indicators in the index library and cannot be deleted",
+  "当前指标已用作画图,不可删除": "The current metric is in use for charting and cannot be deleted",
+  "当前指标已被表格引用,不可删除":"The current metric is referenced by a table and cannot be deleted"
 }
 }