diff --git a/src/main/java/com/ssf/mysqloracletest/task/TMotorvehicleTask.java b/src/main/java/com/ssf/mysqloracletest/task/TMotorvehicleTask.java index cbf8afd..fe873ca 100644 --- a/src/main/java/com/ssf/mysqloracletest/task/TMotorvehicleTask.java +++ b/src/main/java/com/ssf/mysqloracletest/task/TMotorvehicleTask.java @@ -51,8 +51,20 @@ public class TMotorvehicleTask { TransitVehicleRecord one = vehicleRecordService.getOne(queryWrapper); Date partitionField = one.getPartitionField(); maxTime = dateFormat.format(partitionField); + + //将maxTime转换为Date对象 + Date maxDate = dateFormat.parse(maxTime); + + //计算2天后的日期 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(maxDate); + calendar.add(Calendar.DAY_OF_MONTH, 2); + Date twoDaysAgo = calendar.getTime(); + + LambdaQueryWrapper Wrapper = Wrappers.lambdaQuery(); Wrapper.gt(TMotorvehicle::getPasstime, maxTime); + Wrapper.le(TMotorvehicle::getPasstime, twoDaysAgo); int countTM = tMotorvehicleService.count(Wrapper); if (countTM > 0) { int count = countTM / 1000; @@ -116,7 +128,7 @@ public class TMotorvehicleTask { //将maxTime转换为Date对象 Date maxDate = dateFormat.parse(maxTime); - //计算7天前的日期 + //计算2天前的日期 Calendar calendar = Calendar.getInstance(); calendar.setTime(maxDate); calendar.add(Calendar.DAY_OF_MONTH, -2); @@ -125,7 +137,8 @@ public class TMotorvehicleTask { //构造删除条件 LambdaQueryWrapper deleteWrapper = Wrappers.lambdaQuery(); deleteWrapper.le(TransitVehicleRecord::getPartitionField, twoDaysAgo); - +// int countTM = vehicleRecordService.count(deleteWrapper); + deleteWrapper.last("LIMIT 10000"); boolean result = vehicleRecordService.remove(deleteWrapper); if (result) { @@ -133,6 +146,7 @@ public class TMotorvehicleTask { } else { System.out.println("删除失败! "); } + } catch (Exception e) { logger.info(StringKit.getTrace(e)); }