Browse Source

替换逻辑图里的指标

xyxie 9 months ago
parent
commit
ff0a39e244

+ 5 - 0
controllers/data_manage/edb_info.go

@@ -19,6 +19,7 @@ import (
 	"eta/eta_api/services/data_stat"
 	"eta/eta_api/services/elastic"
 	etaTrialService "eta/eta_api/services/eta_trial"
+	"eta/eta_api/services/sandbox"
 	"eta/eta_api/utils"
 	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
@@ -3854,6 +3855,10 @@ func (this *ChartInfoController) EdbInfoReplace() {
 	go func() {
 		excel2.ReplaceEdbInExcel(oldEdbInfo, newEdbInfo)
 	}()
+
+	go func() {
+		sandbox.ReplaceEdbInSandbox(oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId)
+	}()
 	br.Msg = "替换成功"
 	br.ErrMsg = "替换成功"
 	br.Ret = 200

+ 2 - 2
models/data_manage/edb_classify.go

@@ -309,8 +309,8 @@ type ExcelBaseInfo struct {
 	ExcelName       string `description:"表格名称"`
 	UniqueCode      string `description:"表格唯一编码"`
 	ExcelClassifyId int    `description:"表格分类id"`
-	SysUserId       int    `description:"操作人id"`
-	SysUserRealName string `description:"操作人真实姓名"`
+	//SysUserId       int    `description:"操作人id"`
+	//SysUserRealName string `description:"操作人真实姓名"`
 }
 type ClassifyDeleteCheckReq struct {
 	ClassifyId int `description:"分类id"`

+ 26 - 0
models/sandbox/sandbox.go

@@ -402,3 +402,29 @@ func GetFirstSandboxByClassifyId(classifyId int) (item *Sandbox, err error) {
 	err = o.Raw(sql, classifyId).QueryRow(&item)
 	return
 }
+
+// UpdateSandboxContent 更新沙盘内容
+func UpdateSandboxContent(list []Sandbox) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	//循环更新沙盘内容
+	for _, sandbox := range list {
+		_, err = to.Update(&sandbox, "Content", "ModifyTime")
+		if err != nil {
+			return
+		}
+	}
+
+	return
+}

+ 2 - 2
services/data/edb_classify.go

@@ -780,12 +780,12 @@ func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, reque
 			//4、知道了:Understood
 			if len(excelIds) > 0 {
 				errMsg = "当前指标已被表格引用,不可删除"
-				tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
+				/*tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
 				if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 					errMsg = "删除失败"
 					err = errors.New("判断指标是否用作表格引用,GetExcelBaseInfoByExcelInfoIdList Err:" + tmpErr.Error())
 					return
-				}
+				}*/
 				return
 			}
 		}

+ 49 - 0
services/sandbox/sandbox.go

@@ -10,6 +10,7 @@ import (
 	"eta/eta_api/utils"
 	"fmt"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -852,3 +853,51 @@ func sandboxClassifyHaveChildV2(allNode []*sandbox.SandboxClassifyItems, node *s
 	}
 	return
 }
+
+func ReplaceEdbInSandbox(oldEdbInfoId, newEdbInfoId int) (err error) {
+	//分页处理沙盘表
+	//查询沙盘总数
+	total, err := sandbox.GetSandboxListCountByCondition("", []interface{}{})
+	if err != nil {
+		err = fmt.Errorf("查询沙盘总数失败 Err:%s", err)
+		return
+	}
+
+	// 根据沙盘列表总数,分页查询
+	// 计算总页数
+	totalPage := (total + 99) / 100 // 使用整数除法,并添加一页以防有余数
+	updateSandBox := make([]sandbox.Sandbox, 0)
+	//查询沙盘列表
+	for i := 0; i < totalPage; i += 1 {
+		startSize := i * 100
+		list, e := sandbox.GetSandboxListByCondition("", []interface{}{}, startSize, 100)
+		if e != nil {
+			err = fmt.Errorf("查询沙盘列表失败 Err:%s", e)
+			return
+		}
+		for _, v := range list {
+			sandOldEdbId := fmt.Sprintf(`"RId":"1-%d","Id":%d,`, oldEdbInfoId, oldEdbInfoId)
+			if strings.Contains(v.Content, sandOldEdbId) {
+				sandNewEdbId := fmt.Sprintf(`"RId":"1-%d","Id":%d,`, newEdbInfoId, newEdbInfoId)
+				v.Sandbox.Content = strings.ReplaceAll(v.Content, sandOldEdbId, sandNewEdbId)
+				updateSandBox = append(updateSandBox, v.Sandbox)
+				if len(updateSandBox) > 100 {
+					err = sandbox.UpdateSandboxContent(updateSandBox)
+					if err != nil {
+						err = fmt.Errorf("更新沙盘表失败 Err:%s", err)
+						return
+					}
+					updateSandBox = make([]sandbox.Sandbox, 0)
+				}
+			}
+		}
+	}
+	if len(updateSandBox) > 0 {
+		err = sandbox.UpdateSandboxContent(updateSandBox)
+		if err != nil {
+			err = fmt.Errorf("更新沙盘表失败 Err:%s", err)
+			return
+		}
+	}
+	return
+}