|
|
@@ -1,7 +1,9 @@
|
|
|
package com.fs.company.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -342,6 +344,55 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @Description: 批量删除红包流水表数据 保留三个月的 每次删除3天的数据
|
|
|
+ * @Param:
|
|
|
+ * @Return:
|
|
|
+ * @Author xgb
|
|
|
+ * @Date 2025/12/30 11:00
|
|
|
+ */
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteRedPacketLogBatch() {
|
|
|
+ // 获取三个月前的时间 格式 2025-08-01 00:00:00
|
|
|
+ LocalDateTime threeMonthsAgo = LocalDateTime.now().minusMonths(3).withDayOfMonth(1).with(LocalTime.MIN);
|
|
|
+ String formattedDate = threeMonthsAgo.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+
|
|
|
+ int totalDeleted = 0;
|
|
|
+ int currentBatchDeleted;
|
|
|
+
|
|
|
+ // 每1000条的记录批量删除,防止长时间锁表
|
|
|
+ do {
|
|
|
+ currentBatchDeleted = companyRedPacketBalanceLogsMapper.deleteBatch(formattedDate);
|
|
|
+ if (currentBatchDeleted > 0) {
|
|
|
+ totalDeleted += currentBatchDeleted;
|
|
|
+ logger.info("删除红包流水表数据: {}条, 累计删除: {}条", currentBatchDeleted, totalDeleted);
|
|
|
+
|
|
|
+ // 添加短暂延迟,避免对数据库造成过大压力
|
|
|
+ try {
|
|
|
+ Thread.sleep(100); // 100ms延迟
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ logger.warn("删除操作被中断");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } while (currentBatchDeleted > 0);
|
|
|
+
|
|
|
+ if (totalDeleted > 0) {
|
|
|
+ logger.info("红包流水表数据清理完成,共删除 {} 条记录", totalDeleted);
|
|
|
+ } else {
|
|
|
+ logger.info("无需删除红包流水表数据,三个月前数据不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ LocalDateTime threeMonthsAgo = LocalDateTime.now().minusMonths(3).withDayOfMonth(1).with(LocalTime.MIN);
|
|
|
+ String formattedDate = threeMonthsAgo.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ System.out.println(formattedDate);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<OptionsVO> selectAllCompanyList(Long deptId) {
|
|
|
return companyMapper.selectAllCompanyList(deptId);
|