Browse Source

定时任务更新图表

xyxie 3 weeks ago
parent
commit
7c1155fa65
1 changed files with 34 additions and 37 deletions
  1. 34 37
      services/chart_info.go

+ 34 - 37
services/chart_info.go

@@ -278,42 +278,39 @@ func ChartInfoSaveBatch() (err error) {
 	if err != nil {
 		return
 	}
-	if total == 0 {
-		return
-	}
-
-	// 批量上传图表信息
-	offset := 0
-	pageSize := 100
-	success := 0
-
-	// 循环更新100个图表数据
-	for i := 0; offset < total; i++ {
-		// 查询需要更新的图表信息
-		chartInfos, e := models.GetChartInfoListByCondition(condition, []interface{}{}, offset, pageSize)
-		if e != nil {
-			err = fmt.Errorf("查询需要更新的图表信息失败: %v", e)
-			return
-		}
-		// 循环更新图表数据
-		for _, chartInfo := range chartInfos {
-			var er error
-			var msg string
-			// 更新图表数据
-			er, msg = UpdateChart(chartInfo.ChartInfoId)
-			
-			if er != nil {
-				er = fmt.Errorf("图表ID %d, 更新图表数据失败: %s, %v", chartInfo.ChartInfoId, msg, er)
-				tmpErr = append(tmpErr, er)
-				continue
+	if total > 0 {
+		// 批量上传图表信息
+		offset := 0
+		pageSize := 100
+		success := 0
+
+		// 循环更新100个图表数据
+		for i := 0; offset < total; i++ {
+			// 查询需要更新的图表信息
+			chartInfos, e := models.GetChartInfoListByCondition(condition, []interface{}{}, offset, pageSize)
+			if e != nil {
+				err = fmt.Errorf("查询需要更新的图表信息失败: %v", e)
+				return
+			}
+			// 循环更新图表数据
+			for _, chartInfo := range chartInfos {
+				var er error
+				var msg string
+				// 更新图表数据
+				er, msg = UpdateChart(chartInfo.ChartInfoId)
+				
+				if er != nil {
+					er = fmt.Errorf("图表ID %d, 更新图表数据失败: %s, %v", chartInfo.ChartInfoId, msg, er)
+					tmpErr = append(tmpErr, er)
+					continue
+				}
+				success += 1
 			}
-			success += 1
-		}
 
-		offset = (i + 1) * pageSize
+			offset = (i + 1) * pageSize
+		}
+		utils.FileLog.Info("更新图表数据完成, 更新图表数据总数:", success)
 	}
-	fmt.Println("更新图表数据完成, 更新图表数据总数:", success)
-
 
 	sysUser, err := models.GetSysUserByAdminName("admin")
 	if err != nil {
@@ -347,9 +344,9 @@ func ChartInfoSaveBatch() (err error) {
 	}
 
 	// 批量上传图表信息
-	offset = 0
-	pageSize = 100
-	success = 0
+	offset := 0
+	pageSize := 100
+	success := 0
 
 	// 循环更新100个图表数据
 	for i := 0; offset < total; i++ {
@@ -376,7 +373,7 @@ func ChartInfoSaveBatch() (err error) {
 
 		offset = (i + 1) * pageSize
 	}
-	fmt.Println("上传图表数据完成, 上传图表数据总数:", success)
+	utils.FileLog.Info("上传图表数据完成, 上传图表数据总数:", success)
 
 	return
 }