|
@@ -1,6 +1,8 @@
|
|
|
package com.fs.course.service.impl;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.course.param.FsCourseTrafficLogParam;
|
|
@@ -100,4 +102,68 @@ public class FsCourseTrafficLogServiceImpl implements IFsCourseTrafficLogService
|
|
|
public List<FsCourseTrafficLogListVO> selectTrafficByCompany(FsCourseTrafficLogParam param) {
|
|
|
return fsCourseTrafficLogMapper.selectTrafficByCompany(param);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveCourseTrafficLog() {
|
|
|
+ Integer count = fsCourseTrafficLogMapper.saveCourseTrafficLogByTwoDaysLaterCount();
|
|
|
+ Integer limit = 1000;
|
|
|
+ System.out.println("总数:" + count);
|
|
|
+
|
|
|
+ // Start timing
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ System.out.println("开始处理,时间: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
+
|
|
|
+ // 计算需要查询的次数
|
|
|
+ int totalPages = (count + limit - 1) / limit; // 向上取整
|
|
|
+ for (int page = 0; page < totalPages; page++) {
|
|
|
+ int offset = page * limit;
|
|
|
+
|
|
|
+ System.out.println("开始查询");
|
|
|
+ List<FsCourseTrafficLog> redPacketLogs = fsCourseTrafficLogMapper.selectCourseTrafficLogByTwoDaysLater(0,limit);
|
|
|
+ System.out.println(redPacketLogs);
|
|
|
+ // 处理当前批次的1000条数据
|
|
|
+ if (redPacketLogs==null ||redPacketLogs.isEmpty()) {
|
|
|
+ System.out.println("没有数据");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ fsCourseTrafficLogMapper.insertCourseTrafficLogByTwoDaysLaterBatch(redPacketLogs);
|
|
|
+ Long[] delArray = redPacketLogs.stream()
|
|
|
+ .map(FsCourseTrafficLog::getLogId)
|
|
|
+ .toArray(Long[]::new);
|
|
|
+ fsCourseTrafficLogMapper.deleteFsCourseTrafficLogByLogIds(delArray);
|
|
|
+
|
|
|
+ // 打印进度
|
|
|
+ System.out.printf("已处理: %d/%d (%.2f%%)%n",
|
|
|
+ Math.min(offset + limit, count),
|
|
|
+ count,
|
|
|
+ (double)(offset + limit) / count * 100);
|
|
|
+
|
|
|
+ // Calculate estimated remaining time
|
|
|
+ long currentTime = System.currentTimeMillis();
|
|
|
+ long elapsedTime = currentTime - startTime;
|
|
|
+ double timePerBatch = (double)elapsedTime / (page + 1);
|
|
|
+ long estimatedRemaining = (long)(timePerBatch * (totalPages - page - 1));
|
|
|
+
|
|
|
+ System.out.printf("当前批次耗时: %.2fs, 预计剩余时间: %s%n",
|
|
|
+ timePerBatch / 1000,
|
|
|
+ formatDuration(estimatedRemaining));
|
|
|
+ }
|
|
|
+
|
|
|
+// End timing
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ System.out.println("处理完成,时间: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
+ System.out.printf("总耗时: %s%n", formatDuration(endTime - startTime));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String formatDuration(long millis) {
|
|
|
+ long seconds = millis / 1000;
|
|
|
+ long minutes = seconds / 60;
|
|
|
+ long hours = minutes / 60;
|
|
|
+
|
|
|
+ return String.format("%02d:%02d:%02d",
|
|
|
+ hours,
|
|
|
+ minutes % 60,
|
|
|
+ seconds % 60);
|
|
|
+ }
|
|
|
}
|