浏览代码

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

# Conflicts:
#	models/data_manage/excel/excel_info.go
xyxie 10 月之前
父节点
当前提交
caf167e9da

+ 6 - 0
controllers/data_manage/edb_classify.go

@@ -367,6 +367,12 @@ func (this *EdbClassifyController) DeleteEdbClassifyCheck() {
 		}
 		return
 	}
+	if this.Lang == "en" {
+		if utils.ViperConfig.InConfig(tipsMsg) {
+			tipsMsg = utils.ViperConfig.GetString(tipsMsg)
+		}
+	}
+
 	//var deleteStatus int
 	//var tipsMsg string
 	////删除分类

+ 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"
@@ -3920,6 +3921,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"`

+ 8 - 3
models/data_manage/excel/excel_edb_mapping.go

@@ -96,12 +96,17 @@ func GetNoCustomAnalysisExcelEdbMappingCount(edbInfoId int) (count int, err erro
 	return
 }
 
-func GetNoCustomAnalysisExcelEdbMapping(edbInfoId int) (ids []int, err error) {
+type ExcelEdbMappingWithParentIdItem struct {
+	ExcelInfoId int
+	ParentId    int
+}
+
+func GetNoCustomAnalysisExcelEdbMapping(edbInfoId int) (items []ExcelEdbMappingWithParentIdItem, err error) {
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT b.excel_info_id FROM excel_edb_mapping a 
+	sql := ` SELECT b.excel_info_id, b.parent_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)
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
 	return
 }
 

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

@@ -714,26 +714,6 @@ func ModifyExcelInfoUserIdByOldUserId(oldUserIdList []int, userId int, userName
 	return
 }
 
-// GetChildExcelInfoByParentId 根据id 获取eta表格详情
-func GetChildExcelInfoByParentId(parentId int) (items []*ExcelInfo, err error) {
-	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,excel_image,file_url,sort,create_time,modify_time,is_join_permission, parent_id, balance_type, update_user_id,update_user_real_name FROM excel_info WHERE parent_id=? AND is_delete=0 order by sort asc, excel_info_id asc`
-	_, err = o.Raw(sql, parentId).QueryRows(&items)
-	return
-}
-
-// ExcelInfoDetailButton 操作按钮
-type ExcelInfoDetailButton struct {
-	RefreshButton    bool `description:"是否可刷新"`
-	CopyButton       bool `description:"是否可另存为"`
-	DownloadButton   bool `description:"是否可下载"`
-	OpButton         bool `description:"是否可编辑"`
-	DeleteButton     bool `description:"是否可删除"`
-	OpEdbButton      bool `description:"是否可生成指标"`
-	RefreshEdbButton bool `description:"是否可刷新指标"`
-	OpWorkerButton   bool `description:"是否修改协作人"`
-}
-
 func GetExcelBaseInfoByExcelInfoIdList(excelInfoIdList []int) (items []*data_manage.ExcelBaseInfo, err error) {
 	num := len(excelInfoIdList)
 	if num <= 0 {
@@ -793,3 +773,23 @@ func ReplaceEdbInExcel(oldEdbInfoId, newEdbInfoId int, updateExcelList []*ExcelI
 	}
 	return
 }
+
+// GetChildExcelInfoByParentId 根据id 获取eta表格详情
+func GetChildExcelInfoByParentId(parentId int) (items []*ExcelInfo, err error) {
+	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,excel_image,file_url,sort,create_time,modify_time,is_join_permission, parent_id, balance_type, update_user_id,update_user_real_name FROM excel_info WHERE parent_id=? AND is_delete=0 order by sort asc, excel_info_id asc`
+	_, err = o.Raw(sql, parentId).QueryRows(&items)
+	return
+}
+
+// ExcelInfoDetailButton 操作按钮
+type ExcelInfoDetailButton struct {
+	RefreshButton    bool `description:"是否可刷新"`
+	CopyButton       bool `description:"是否可另存为"`
+	DownloadButton   bool `description:"是否可下载"`
+	OpButton         bool `description:"是否可编辑"`
+	DeleteButton     bool `description:"是否可删除"`
+	OpEdbButton      bool `description:"是否可生成指标"`
+	RefreshEdbButton bool `description:"是否可刷新指标"`
+	OpWorkerButton   bool `description:"是否修改协作人"`
+}

+ 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
+}

+ 17 - 13
services/data/edb_classify.go

@@ -557,7 +557,7 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 			}
 			if calculateCount > 0 {
 				deleteStatus = 4
-				tipsMsg = "当前指标已用作指标运算,不可删除"
+				tipsMsg = "当前指标已用作指标运算,不可删除"
 				return
 			}
 		}
@@ -571,7 +571,7 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 				return
 			}
 			if predictEdbInfoCount > 0 {
-				deleteStatus = 3
+				deleteStatus = 5
 				tipsMsg = "当前指标已用作预测指标,不可删除"
 				return
 			}
@@ -579,7 +579,7 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 
 		// 判断指标是否用作表格引用
 		{
-			excelIds, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
+			tableItems, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 				errMsg = "删除失败"
 				err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
@@ -590,9 +590,17 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 			//2、当前指标已被表格引用,不可删除:The current metric is referenced by a table and cannot be deleted
 			//3、删除失败:Deletion failed
 			//4、知道了:Understood
-			if len(excelIds) > 0 {
-				deleteStatus = 3
+			if len(tableItems) > 0 {
+				deleteStatus = 6
 				tipsMsg = "当前指标已被表格引用,不可删除"
+				var excelIds []int
+				for _, tableItem := range tableItems {
+					if tableItem.ParentId > 0 {
+						excelIds = append(excelIds, tableItem.ParentId)
+					} else {
+						excelIds = append(excelIds, tableItem.ExcelInfoId)
+					}
+				}
 				tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
 				if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 					errMsg = "删除失败"
@@ -614,6 +622,7 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 				return
 			}
 			if len(tagXList) > 0 {
+				deleteStatus = 7
 				errMsg = "当前指标已添加到跨品种分析,不可删除"
 				return
 			}
@@ -625,6 +634,7 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 			}
 
 			if len(tagYList) > 0 {
+				deleteStatus = 7
 				errMsg = "当前指标已添加到跨品种分析,不可删除"
 				return
 			}
@@ -767,7 +777,7 @@ func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, reque
 
 		// 判断指标是否用作表格引用
 		{
-			excelIds, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
+			tableItems, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 				errMsg = "删除失败"
 				err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
@@ -778,14 +788,8 @@ func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, reque
 			//2、当前指标已被表格引用,不可删除:The current metric is referenced by a table and cannot be deleted
 			//3、删除失败:Deletion failed
 			//4、知道了:Understood
-			if len(excelIds) > 0 {
+			if len(tableItems) > 0 {
 				errMsg = "当前指标已被表格引用,不可删除"
-				tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
-				if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
-					errMsg = "删除失败"
-					err = errors.New("判断指标是否用作表格引用,GetExcelBaseInfoByExcelInfoIdList Err:" + tmpErr.Error())
-					return
-				}
 				return
 			}
 		}

+ 7 - 1
services/data/excel/excel_info.go

@@ -8,6 +8,7 @@ import (
 	"eta/eta_api/models/data_manage/excel/request"
 	"eta/eta_api/models/data_manage/excel/response"
 	"eta/eta_api/models/system"
+	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/services/data"
 	"eta/eta_api/services/data/data_manage_permission"
 	"eta/eta_api/utils"
@@ -530,6 +531,11 @@ func GetExcelEdbBatchRefreshKey(source string, primaryId, subId int) string {
 
 // ReplaceEdbInExcel 替换表格中的指标
 func ReplaceEdbInExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo) (err error) {
+	defer func() {
+		if err != nil {
+			go alarm_msg.SendAlarmMsg("替换表格中的指标失败提醒,errmsg:"+err.Error(), 3)
+		}
+	}()
 	//查询和指标相关的 表格
 	mappingList, err := excel.GetExcelEdbMappingByEdbInfoId(oldEdbInfo.EdbInfoId)
 	if err != nil {
@@ -578,7 +584,7 @@ func ReplaceEdbInExcel(oldEdbInfo, newEdbInfo *data_manage.EdbInfo) (err error)
 		err = fmt.Errorf("替换表格中的指标失败,错误:%s", err.Error())
 		return
 	}
-	
+
 	//todo 是否需要刷新表格中的指标数据
 	return
 }

+ 55 - 0
services/sandbox/sandbox.go

@@ -7,9 +7,11 @@ import (
 	"eta/eta_api/models/sandbox"
 	"eta/eta_api/models/sandbox/request"
 	"eta/eta_api/models/system"
+	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/utils"
 	"fmt"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -852,3 +854,56 @@ func sandboxClassifyHaveChildV2(allNode []*sandbox.SandboxClassifyItems, node *s
 	}
 	return
 }
+
+func ReplaceEdbInSandbox(oldEdbInfoId, newEdbInfoId int) (err error) {
+	//分页处理沙盘表
+	defer func() {
+		if err != nil {
+			go alarm_msg.SendAlarmMsg("替换沙盘中的指标记录失败提醒,errmsg:"+err.Error(), 3)
+		}
+	}()
+	//查询沙盘总数
+	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
+}