|
@@ -14,6 +14,8 @@ import com.fs.common.utils.file.FileUtils;
|
|
|
import com.fs.company.service.ICompanyService;
|
|
import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.company.utils.AudioUtils;
|
|
import com.fs.company.utils.AudioUtils;
|
|
|
import com.fs.company.vo.WangUploadVO;
|
|
import com.fs.company.vo.WangUploadVO;
|
|
|
|
|
+import com.fs.course.domain.FsCourseWatchLog;
|
|
|
|
|
+import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
import com.fs.course.service.ITencentCloudCosService;
|
|
import com.fs.course.service.ITencentCloudCosService;
|
|
|
import com.fs.framework.config.ServerConfig;
|
|
import com.fs.framework.config.ServerConfig;
|
|
|
import com.fs.framework.security.LoginUser;
|
|
import com.fs.framework.security.LoginUser;
|
|
@@ -41,10 +43,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.awt.image.BufferedImage;
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 通用请求处理
|
|
* 通用请求处理
|
|
@@ -90,14 +90,87 @@ public class CommonController
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IQwWorkTaskService qwWorkTaskService;
|
|
private IQwWorkTaskService qwWorkTaskService;
|
|
|
|
|
|
|
|
- @PostMapping("common/test")
|
|
|
|
|
- public R test() throws Exception
|
|
|
|
|
- {
|
|
|
|
|
- qwWorkTaskService.delQwWorkTaskByOver();
|
|
|
|
|
- // qwWorkTaskService.addQwWorkByFirstCourse();
|
|
|
|
|
-// qwWorkTaskService.addQwWorkByCourse();
|
|
|
|
|
-// qwWorkTaskService.addQwWorkByConversionDay();
|
|
|
|
|
- return R.ok();
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsCourseWatchLogMapper courseWatchLogMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("common/test")
|
|
|
|
|
+ public R testWithRange() throws Exception {
|
|
|
|
|
+// String startDate = "2025-08-22 00:00:00";
|
|
|
|
|
+// String endDate = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date())+" 00:00:00";
|
|
|
|
|
+//
|
|
|
|
|
+// log.info("开始按日期范围循环删除课程记录,时间范围:{} 到 {}", startDate, endDate);
|
|
|
|
|
+//
|
|
|
|
|
+// Date start = DateUtils.parseDate(startDate.split(" ")[0]);
|
|
|
|
|
+// Date end = DateUtils.parseDate(DateUtils.getDate());
|
|
|
|
|
+//
|
|
|
|
|
+// long daysBetween = (end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000);
|
|
|
|
|
+//
|
|
|
|
|
+// int batchCount = 0;
|
|
|
|
|
+// int totalInserted = 0;
|
|
|
|
|
+// int totalDeleted = 0;
|
|
|
|
|
+//
|
|
|
|
|
+// // 每次处理一周的数据
|
|
|
|
|
+// int weekSize = 7;
|
|
|
|
|
+//
|
|
|
|
|
+// for (long i = 0; i <= daysBetween; i += weekSize) {
|
|
|
|
|
+// String batchStart = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,
|
|
|
|
|
+// DateUtils.addDays(start, (int)i)) + " 00:00:00";
|
|
|
|
|
+// String batchEnd = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,
|
|
|
|
|
+// DateUtils.addDays(start, (int)Math.min(i + weekSize, daysBetween + 1))) + " 00:00:00";
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// try {
|
|
|
|
|
+// deleteCourse(batchStart, batchEnd);
|
|
|
|
|
+//
|
|
|
|
|
+// batchCount++;
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// // 批次间休眠
|
|
|
|
|
+// Thread.sleep(200);
|
|
|
|
|
+//
|
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
|
+// log.error("处理批次 {}-{} 时发生错误:{}", batchStart, batchEnd, e.getMessage(), e);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// return R.ok()
|
|
|
|
|
+// .put("processedBatches", batchCount)
|
|
|
|
|
+// .put("insertedRecords", totalInserted)
|
|
|
|
|
+// .put("deletedRecords", totalDeleted)
|
|
|
|
|
+// .put("message", String.format("按范围循环删除完成,共处理 %d 个批次,插入 %d 条记录,删除 %d 条记录",
|
|
|
|
|
+// batchCount, totalInserted, totalDeleted));
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private void deleteCourse(String createTime,String createTimeEnd){
|
|
|
|
|
+ // 查询重复的看课记录数据 ,删除保留其中log_id 小的一条
|
|
|
|
|
+ List<FsCourseWatchLog> logs = courseWatchLogMapper.selectWatchLogForDelete(createTime, createTimeEnd);
|
|
|
|
|
+ if (logs == null || logs.isEmpty()){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 获取 logs 的 log_id 放到数组里
|
|
|
|
|
+ // 1. 批量插入到目标表
|
|
|
|
|
+ log.info("时间{} 开始批量插入数据到目标表,数量:{}",createTime, logs.size());
|
|
|
|
|
+ int insertCount = courseWatchLogMapper.batchInsert(logs);
|
|
|
|
|
+ log.info("批量插入完成,插入{}条数据", insertCount);
|
|
|
|
|
+
|
|
|
|
|
+ if (insertCount > 0) {
|
|
|
|
|
+ // 2. 获取成功插入的数据ID
|
|
|
|
|
+ List<Long> idsToDelete = logs.stream()
|
|
|
|
|
+ .limit(insertCount) // 只删除成功插入的数据
|
|
|
|
|
+ .map(FsCourseWatchLog::getLogId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ if (!idsToDelete.isEmpty()) {
|
|
|
|
|
+ // 3. 批量删除源表数据
|
|
|
|
|
+ log.info("开始批量删除源表数据,数量:{}", idsToDelete.size());
|
|
|
|
|
+ int deleteCount = courseWatchLogMapper.batchDeleteByIds(idsToDelete);
|
|
|
|
|
+ log.info("批量删除完成,删除{}条数据", deleteCount);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("common/test2")
|
|
@GetMapping("common/test2")
|