Browse Source

精选目录移动处理

xyxie 3 weeks ago
parent
commit
c50f2846f8

+ 27 - 3
controllers/data_manage/chart_classify.go

@@ -848,6 +848,9 @@ func (this *ChartClassifyController) ChartClassifyMove() {
 		br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
 		return
 	}
+	oldParentId := chartClassifyInfo.ParentId
+	oldLevelPath := chartClassifyInfo.LevelPath
+	oldSelected := chartClassifyInfo.IsSelected
 
 	// 校验移动的父级目录下是否有重名分类
 	exists, e := data_manage.GetChartClassifyByParentIdAndName(req.ParentClassifyId, chartClassifyInfo.ChartClassifyName, req.ClassifyId)
@@ -886,14 +889,18 @@ func (this *ChartClassifyController) ChartClassifyMove() {
 	}
 	updateCol := make([]string, 0)
 
-	//判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
-	if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
-		parentChartClassifyInfo, err := data_manage.GetChartClassifyById(req.ParentClassifyId)
+	var parentChartClassifyInfo *data_manage.ChartClassify
+	if req.ParentClassifyId > 0 {
+		parentChartClassifyInfo, err = data_manage.GetChartClassifyById(req.ParentClassifyId)
 		if err != nil {
 			br.Msg = "移动失败"
 			br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
 			return
 		}
+	}
+	//判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
+	if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
+		
 		chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
 		chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
 		chartClassifyInfo.ModifyTime = time.Now()
@@ -966,6 +973,23 @@ func (this *ChartClassifyController) ChartClassifyMove() {
 			return
 		}
 	}
+	if oldParentId != req.ParentClassifyId {
+		if err = data.UpdateChartClassifyLevelPathWithChildren(chartClassifyInfo, parentChartClassifyInfo, oldParentId, oldLevelPath); err != nil {
+			br.Msg = "修改分类失败"
+			br.ErrMsg = "更新分类level_path失败,Err:" + err.Error()
+			return
+		}
+	}
+	// 如果是精选目录,则需要同步到ETA资源库
+	if chartClassifyInfo.Source == utils.CHART_SOURCE_DEFAULT {
+		// 如果当前目录的精选标识发生变化,需要同步更新子目录的精选标识
+		if err = data.UpdateChildClassifySelection(chartClassifyInfo, parentChartClassifyInfo, oldSelected); err != nil {
+			br.Msg = "修改分类失败"
+			br.ErrMsg = "更新子目录精选标识失败,Err:" + err.Error()
+			return
+		}
+		go eta_forum.ChartClassifySaveBatch(chartClassifyInfo.Source)
+	}
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "移动成功"

+ 15 - 1
controllers/data_manage/chart_info.go

@@ -783,7 +783,7 @@ func (this *ChartInfoController) ChartInfoMove() {
 			return
 		}
 	}
-
+	oldClassifyId := chartInfo.ChartClassifyId
 	//如果改变了分类,那么移动该图表数据
 	if chartInfo.ChartClassifyId != req.ChartClassifyId {
 		//查询需要修改的分类下是否存在同一个图表名称
@@ -874,6 +874,20 @@ func (this *ChartInfoController) ChartInfoMove() {
 		}
 		//添加es数据
 		go data.EsAddOrEditChartInfo(chartInfo.ChartInfoId)
+
+		// 判断是否为精选目录
+			// 如果该目录不是精选目录,且该图表已经上架,则需撤回该图表
+			if oldClassifyId != req.ChartClassifyId {
+				parentChartClassifyInfo, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
+				if err != nil {
+					br.Msg = "移动失败"
+					br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
+					return
+				}
+				if parentChartClassifyInfo.IsSelected == 0 && chartInfo.ForumChartInfoId > 0 {
+					go eta_forum.DeleteChart(chartInfo.ChartInfoId)
+				}
+			}
 	}
 
 	if err != nil {

+ 3 - 3
services/data/chart_classify.go

@@ -807,7 +807,7 @@ func moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify,
 				}
 			}
 			if source == utils.CHART_SOURCE_DEFAULT {
-				if err = updateChildClassifySelection(chartClassifyInfo, parentChartClassifyInfo, oldSelected); err != nil {
+				if err = UpdateChildClassifySelection(chartClassifyInfo, parentChartClassifyInfo, oldSelected); err != nil {
 					errMsg = "移动失败"
 					err = errors.New("更新子目录精选标识失败,Err:" + err.Error())
 					return
@@ -1065,7 +1065,7 @@ func GetChartClassifyParentRecursive(list []*data_manage.ChartClassifyItems, cla
 }
 
 // 新增处理子分类精选状态的函数
-func updateChildClassifySelection(classifyInfo *data_manage.ChartClassify, parentClassifyInfo *data_manage.ChartClassify, oldSelected int) error {
+func UpdateChildClassifySelection(classifyInfo *data_manage.ChartClassify, parentClassifyInfo *data_manage.ChartClassify, oldSelected int) error {
 	// 处理一级目录
 	if classifyInfo.ParentId == 0 {
 		if oldSelected != classifyInfo.IsSelected {
@@ -1212,7 +1212,7 @@ func EditChartClassifyV2(chartClassifyId, parentId, source int, chartClassifyNam
 	// 如果是精选目录,则需要同步到ETA资源库
 	if classifyInfo.Source == utils.CHART_SOURCE_DEFAULT {
 		// 如果当前目录的精选标识发生变化,需要同步更新子目录的精选标识
-		if err = updateChildClassifySelection(classifyInfo, parentClassifyInfo, oldSelected); err != nil {
+		if err = UpdateChildClassifySelection(classifyInfo, parentClassifyInfo, oldSelected); err != nil {
 			errMsg = "修改分类失败"
 			err = fmt.Errorf("更新子目录精选标识失败,Err:%w", err)
 			return