Browse Source

图表移动时,根据分类类型,判断是否会下架图表

xyxie 1 week ago
parent
commit
be989a9c8a
2 changed files with 79 additions and 3 deletions
  1. 2 0
      controllers/data_manage/chart_info.go
  2. 77 3
      services/eta_forum/eta_forum_hub.go

+ 2 - 0
controllers/data_manage/chart_info.go

@@ -5138,6 +5138,8 @@ func (this *ChartInfoController) ModifyChartList() {
 		br.ErrMsg = "更新图表分类失败,Err:" + err.Error()
 		return
 	}
+	
+	go eta_forum.ChartInfoDeleteBatchByChartInfoIds(chartIds, req.ChartClassifyId)
 
 	br.Ret = 200
 	br.Success = true

+ 77 - 3
services/eta_forum/eta_forum_hub.go

@@ -742,7 +742,7 @@ func ChartBatchUpdateAndUpload(chartClassifyInfo *data_manage.ChartClassify, sys
 		success := 0
 
 		// 循环更新100个图表数据
-		for i := 0; offset <= total; i++ {
+		for i := 0; offset < total; i++ {
 			// 查询需要更新的图表信息
 			chartInfos, e := data_manage.GetChartInfoListByCondition(condition, []interface{}{chartClassifyIdList}, offset, pageSize)
 			if e != nil {
@@ -784,7 +784,7 @@ func ChartBatchUpdateAndUpload(chartClassifyInfo *data_manage.ChartClassify, sys
 	offset := 0
 	pageSize := 100
 	success := 0
-	for i := 0; offset <= total; i++ {
+	for i := 0; offset < total; i++ {
 		chartInfos, e := data_manage.GetChartInfoListByCondition(condition, []interface{}{upChartClassifyIdList}, offset, pageSize)
 		if e != nil {
 			err = fmt.Errorf("查询需要新增的图表信息失败: %v", e)
@@ -870,7 +870,7 @@ func ChartInfoDeleteBatch(chartClassifyInfo *data_manage.ChartClassify, sysUser
 	success := 0
 
 	// 循环更新100个图表数据
-	for i := 0; offset <= total; i++ {
+	for i := 0; offset < total; i++ {
 		// 查询需要更新的图表信息
 		chartInfos, e := data_manage.GetChartInfoListByCondition(condition, []interface{}{chartClassifyInfo.Source, chartClassifyIdList}, offset, pageSize)
 		if e != nil {
@@ -898,6 +898,80 @@ func ChartInfoDeleteBatch(chartClassifyInfo *data_manage.ChartClassify, sysUser
 	return	
 }
 
+// 批量删除资源库图表信息
+func ChartInfoDeleteBatchByChartInfoIds(chartInfoIds []int, chartClassifyId int) (err error) {
+	if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
+		return
+	}
+	var tmpErr []error
+	defer func() {
+		stack := ""
+		if err != nil {
+			stack = fmt.Sprintln(stack + err.Error())
+		}
+		if len(tmpErr) > 0 {
+			for _, v := range tmpErr {
+				stack = fmt.Sprintln(stack + v.Error())
+			}
+		}
+		if stack != "" {
+			utils.FileLog.Error("批量删除资源库图表信息失败"+"<br/>"+stack)
+			go alarm_msg.SendAlarmMsg("批量删除资源库图表信息失败"+"<br/>"+stack, 3)
+		}
+	}()
+	// 查询是否精选分类
+	chartClassifyInfo, err := data_manage.GetChartClassifyById(chartClassifyId)
+	if err != nil {
+		return
+	}
+	if chartClassifyInfo.IsSelected == 1 {
+		utils.FileLog.Info("精选分类,不需要删除图表信息")
+		return
+	}
+	// 非精选,需要下架图表,批量删除图表信息
+	condition := " AND source=1 AND chart_info_id in ? AND forum_chart_info_id > 0"
+	total, err := data_manage.GetChartInfoCountByCondition(condition, []interface{}{chartInfoIds})
+	if err != nil {
+		return
+	}	
+	if total == 0 {
+		utils.FileLog.Info("没有需要下架的图表")
+		return
+	}
+	
+	offset := 0
+	pageSize := 100
+	success := 0
+
+	// 循环更新100个图表数据
+	for i := 0; offset < total; i++ {
+		// 查询需要更新的图表信息
+		chartInfos, e := data_manage.GetChartInfoListByCondition(condition, []interface{}{chartInfoIds}, offset, pageSize)
+		if e != nil {
+			err = fmt.Errorf("查询需要更新的图表信息失败: %v", e)
+			return
+		}
+		if len(chartInfos) == 0 {
+			break
+		}
+		// 循环更新图表数据
+		for _, chartInfo := range chartInfos {
+			// 删除图表数据
+			er, msg := DeleteChart(chartInfo.ChartInfoId)
+			if er != nil {
+				er = fmt.Errorf("图表ID %d, 删除图表数据失败: %s, %v", chartInfo.ChartInfoId, msg, er)
+				tmpErr = append(tmpErr, er)
+				continue
+			}
+			success += 1
+		}
+
+		offset += pageSize
+	}
+	fmt.Println("删除图表数据完成, 删除图表数据总数:", success)
+	return	
+}
+
 // 修改分类状态,一键上架至资源库
 func SetChartClassifyResourceStatusUp(chartClassifyInfo *data_manage.ChartClassify, sysUser *system.Admin) (errMsg string, err error) {
 	if chartClassifyInfo.ResourceStatus == utils.ChartClassifyResourceStatusUp {