避免提前出现24年

develop
Angel 11 months ago
parent 062b553909
commit 6fea4ca252

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

Loading…
Cancel
Save