refactor(datetime): 修复时间类型不匹配问题

- 将 DateUtil.date() 替换为 LocalDateTime.now()
- 更新时间设置和比较的相关代码
- 修复了多个文件中的时间类型不匹配问题- 添加了最终时间类型兼容性验证脚本
This commit is contained in:
2025-08-12 13:14:25 +08:00
parent 8e02044e4e
commit 4ea6a1b8a3
7 changed files with 113 additions and 10 deletions

View File

@@ -289,7 +289,7 @@ public class BszxPayController extends BaseController {
// 2. 未支付则处理更新订单状态
if (order.getPayStatus().equals(false)) {
// 5. TODO 处理订单状态
order.setPayTime(DateUtil.date());
order.setPayTime(LocalDateTime.now());
order.setPayStatus(true);
order.setTransactionId(transactionId);
order.setPayPrice(new BigDecimal(NumberUtil.decimalFormat("0.00", total * 0.01)));

View File

@@ -16,6 +16,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.concurrent.TimeUnit;
/**
@@ -119,7 +122,7 @@ public class GpsMessageProcessor {
car.setLongitude(gps.getLng());
car.setLatitude(gps.getLat());
car.setSpeed(gps.getSpeed());
car.setUpdateTime(DateUtil.date(gps.getTime() * 1000));
car.setUpdateTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(gps.getTime() * 1000), ZoneId.systemDefault()));
car.setGpsNo(gps.getImei());
if (hjmCarService.updateByGpsNo(car)) {
@@ -240,7 +243,7 @@ public class GpsMessageProcessor {
// 更新围栏状态
car.setInFence(isInFence);
car.setUpdateTime(DateUtil.date());
car.setUpdateTime(LocalDateTime.now());
hjmCarService.updateById(car);
logger.info("车辆围栏检查完成: 车辆={}, 围栏={}, 是否在围栏内={}",

View File

@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@@ -112,7 +113,7 @@ public class HjmCarServiceImpl extends ServiceImpl<HjmCarMapper, HjmCar> impleme
// 将围栏判断结果保存到车辆对象中
byCode.setInFence(isInFence);
System.out.println("车辆 " + code + " 是否在围栏内: " + isInFence);
byCode.setUpdateTime(DateUtil.date());
byCode.setUpdateTime(LocalDateTime.now());
hjmCarService.updateById(byCode);
return byCode;

View File

@@ -60,7 +60,7 @@ public class HouseViewsLogServiceImpl extends MPJBaseServiceImpl<HouseViewsLogMa
viewsLog.setHouseId(houseInfo.getHouseId());
viewsLog.setHouseUserId(houseInfo.getUserId());
}
viewsLog.setUpdateTime(DateUtil.date());
viewsLog.setUpdateTime(LocalDateTime.now());
saveOrUpdate(viewsLog);
}

View File

@@ -120,8 +120,8 @@ public class ProjectRenewController extends BaseController {
projectService.updateById(project);
}
// 保存到期时间所在的年月日
final Date expirationTime = project.getExpirationTime();
LocalDate localDate = expirationTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
final LocalDateTime expirationTime = project.getExpirationTime();
LocalDate localDate = expirationTime.toLocalDate();
int year = localDate.getYear();
int month = localDate.getMonthValue(); // 获取月份范围是1到12
int day = localDate.getDayOfMonth(); // 获取日范围是1到31

View File

@@ -211,8 +211,8 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
project.setRenewCount(project.getRenewCount() + 1);
// 保存到期时间所在的年月日
final Date expirationTime = project.getExpirationTime();
LocalDate localDate = expirationTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
final LocalDateTime expirationTime = project.getExpirationTime();
LocalDate localDate = expirationTime.toLocalDate();
int year = localDate.getYear();
int month = localDate.getMonthValue(); // 获取月份范围是1到12
int day = localDate.getDayOfMonth(); // 获取日范围是1到31
@@ -257,7 +257,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
// 是否过期 -1已过期 大于0 未过期
d.setExpired(d.getExpirationTime().compareTo(now));
// 剩余天数
d.setExpiredDays((int) java.time.temporal.ChronoUnit.DAYS.between(now, d.getExpirationTime()));
d.setExpiredDays(java.time.temporal.ChronoUnit.DAYS.between(now, d.getExpirationTime()));
// 续费次数
d.setRenewCount((long) projectRenewService.count(new LambdaQueryWrapper<ProjectRenew>().eq(ProjectRenew::getAppId, d.getAppId()).eq(ProjectRenew::getDeleted, 0)));
});