refactor(core): 升级时间字段为 LocalDateTime

- 将 SystemTenant 及相关 VO 的过期时间字段由 java.util.Date 替换为 java.time.LocalDateTime
- 同步修改 DateUtils.dateBetween 签名并适配 LocalDateTime 计算
- 调整 FeatureAuthController 与 LoginService 中的时间比较逻辑
- 保持功能不变,提升类型安全与时区清晰度
This commit is contained in:
2026-03-30 09:04:36 +08:00
parent abe20c99fe
commit 5fec4cb020
7 changed files with 26 additions and 22 deletions

View File

@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
/** /**
@@ -91,8 +92,8 @@ public class FeatureAuthController {
// 5. 校验租户是否过期(根据功能代码选择不同的过期时间字段) // 5. 校验租户是否过期(根据功能代码选择不同的过期时间字段)
String featureCode = request.getFeatureCode(); String featureCode = request.getFeatureCode();
Date expireTime = getFeatureExpireTime(tenant, featureCode); LocalDateTime expireTime = getFeatureExpireTime(tenant, featureCode);
if (expireTime != null && expireTime.before(new Date())) { if (expireTime != null && expireTime.isBefore(LocalDateTime.now())) {
throw new BusinessException(ErrorCode.PACKAGE_EXPIRED, "该功能套餐已过期"); throw new BusinessException(ErrorCode.PACKAGE_EXPIRED, "该功能套餐已过期");
} }
@@ -119,7 +120,7 @@ public class FeatureAuthController {
/** /**
* 根据功能代码获取对应的过期时间 * 根据功能代码获取对应的过期时间
*/ */
private Date getFeatureExpireTime(SystemTenant tenant, String featureCode) { private LocalDateTime getFeatureExpireTime(SystemTenant tenant, String featureCode) {
if (featureCode == null) { if (featureCode == null) {
return tenant.getExpireTime(); return tenant.getExpireTime();
} }

View File

@@ -84,28 +84,28 @@ public class SystemTenant {
*/ */
@TableField(value = "expire_time") @TableField(value = "expire_time")
@ApiModelProperty(value="过期时间") @ApiModelProperty(value="过期时间")
private Date expireTime; private LocalDateTime expireTime;
/** /**
* 爬主播过期时间 * 爬主播过期时间
*/ */
@TableField(value = "crawl_expire_time") @TableField(value = "crawl_expire_time")
@ApiModelProperty(value="爬主播过期时间") @ApiModelProperty(value="爬主播过期时间")
private Date crawlExpireTime; private LocalDateTime crawlExpireTime;
/** /**
* ai过期时间 * ai过期时间
*/ */
@TableField(value = "expire_time")
@ApiModelProperty(value="ai过期时间") @ApiModelProperty(value="ai过期时间")
private Date aiExpireTime; @TableField(value = "ai_expire_time")
private LocalDateTime aiExpireTime;
/** /**
* 大哥过期时间 * 大哥过期时间
*/ */
@TableField(value = "expire_time")
@ApiModelProperty(value="大哥过期时间") @ApiModelProperty(value="大哥过期时间")
private Date brotherExpireTime; @TableField(value = "brother_expire_time")
private LocalDateTime brotherExpireTime;
/** /**
@@ -125,9 +125,9 @@ public class SystemTenant {
/** /**
* 创建时间 * 创建时间
*/ */
@TableField(value = "create_time")
@ApiModelProperty(value="创建时间") @ApiModelProperty(value="创建时间")
private Date createTime; @TableField(value = "create_time")
private LocalDateTime createTime;
/** /**
* 更新者 * 更新者
@@ -141,7 +141,7 @@ public class SystemTenant {
*/ */
@TableField(value = "update_time") @TableField(value = "update_time")
@ApiModelProperty(value="更新时间") @ApiModelProperty(value="更新时间")
private Date updateTime; private LocalDateTime updateTime;
/** /**
* 是否删除 * 是否删除

View File

@@ -11,5 +11,5 @@ import java.util.Date;
*/ */
@Data @Data
public class SystemTenantVO { public class SystemTenantVO {
private Date expiredTime; private LocalDateTime expiredTime;
} }

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
/* /*
@@ -32,13 +33,13 @@ public class SystemUsersVO {
private String tokenValue; private String tokenValue;
private Date expireTime; private LocalDateTime expireTime;
private Date brotherExpireTime; private LocalDateTime brotherExpireTime;
private Date aiExpireTime; private LocalDateTime aiExpireTime;
private Date crawlExpireTime; private LocalDateTime crawlExpireTime;
private Byte aiReplay; private Byte aiReplay;

View File

@@ -102,7 +102,7 @@ public class LoginService {
StpUtil.login(user.getId(), scene.getSaMode()); StpUtil.login(user.getId(), scene.getSaMode());
switch (scene) { switch (scene) {
case AI_CHAT: case AI_CHAT:
StpUtil.renewTimeout(DateUtils.dateBetween(systemTenant.getAiExpireTime(),DateUtil.date())); StpUtil.renewTimeout(DateUtils.dateBetween(systemTenant.getAiExpireTime(), DateUtil.date().toLocalDateTime()));
BeanUtil.copyProperties(user, vo); BeanUtil.copyProperties(user, vo);
vo.setTokenName(StpUtil.getTokenName()); vo.setTokenName(StpUtil.getTokenName());
vo.setTokenValue(StpUtil.getTokenValue()); vo.setTokenValue(StpUtil.getTokenValue());

View File

@@ -51,14 +51,14 @@ public class SystemUsersServiceImpl extends ServiceImpl<SystemUsersMapper,System
@Override @Override
public boolean isExpired(Long tendId) { public boolean isExpired(Long tendId) {
SystemTenant systemTenant = systemTenantMapper.selectById(tendId); SystemTenant systemTenant = systemTenantMapper.selectById(tendId);
long between = DateUtil.between(systemTenant.getExpireTime(), DateUtil.date(), DateUnit.DAY); long between = DateUtil.between(DateUtil.date(systemTenant.getExpireTime()), DateUtil.date(), DateUnit.DAY);
return between < 0; return between < 0;
} }
@Override @Override
public Long getTenantExpiredTime(Long tenantId) { public Long getTenantExpiredTime(Long tenantId) {
SystemTenant systemTenant = systemTenantMapper.selectById(tenantId); SystemTenant systemTenant = systemTenantMapper.selectById(tenantId);
long between = DateUtil.between(systemTenant.getExpireTime(), DateUtil.date(), DateUnit.SECOND); long between = DateUtil.between(DateUtil.date(systemTenant.getExpireTime()), DateUtil.date(), DateUnit.SECOND);
if (between > 0 ) { if (between > 0 ) {
return between; return between;
} }

View File

@@ -3,6 +3,7 @@ package com.yupi.springbootinit.utils;
import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
/* /*
@@ -11,7 +12,8 @@ import java.util.Date;
*/ */
public class DateUtils { public class DateUtils {
public static Long dateBetween(Date date1, Date date2) { public static Long dateBetween(LocalDateTime date1, LocalDateTime date2) {
return DateUtil.between(date1, date2, DateUnit.SECOND);
return DateUtil.between(DateUtil.date(date1), DateUtil.date(date2), DateUnit.SECOND);
} }
} }