日期改为时间戳类型

This commit is contained in:
tianfeng 2025-11-05 18:59:14 +08:00
parent f52a547b18
commit 89fd614569
4 changed files with 41 additions and 16 deletions

View File

@ -8,6 +8,7 @@ import com.red.circle.other.domain.propcoupon.PropCouponStatus;
import com.red.circle.other.domain.propcoupon.PropCouponType; import com.red.circle.other.domain.propcoupon.PropCouponType;
import com.red.circle.other.infra.database.rds.entity.props.PropCouponDO; import com.red.circle.other.infra.database.rds.entity.props.PropCouponDO;
import com.red.circle.other.infra.database.rds.entity.props.PropCouponUseRecordDO; import com.red.circle.other.infra.database.rds.entity.props.PropCouponUseRecordDO;
import com.red.circle.other.infra.utils.ZonedDateTimeUtils;
/** /**
* 道具券对象转换器 * 道具券对象转换器
@ -37,9 +38,10 @@ public class PropCouponConvertor {
co.setStatusName(propCoupon.getStatus().getDesc()); co.setStatusName(propCoupon.getStatus().getDesc());
co.setSource(propCoupon.getSource().getCode()); co.setSource(propCoupon.getSource().getCode());
co.setSourceName(propCoupon.getSource().getDesc()); co.setSourceName(propCoupon.getSource().getDesc());
co.setExpireTime(propCoupon.getExpireTime());
co.setUseTime(propCoupon.getUseTime()); co.setExpireTime(ZonedDateTimeUtils.toTimestamp(propCoupon.getExpireTime()));
co.setCreateTime(propCoupon.getCreateTime()); co.setUseTime(ZonedDateTimeUtils.toTimestamp(propCoupon.getUseTime()));
co.setCreateTime(ZonedDateTimeUtils.toTimestamp(propCoupon.getCreateTime()));
return co; return co;
} }
@ -79,10 +81,10 @@ public class PropCouponConvertor {
if (source != null) { if (source != null) {
co.setSourceName(source.getDesc()); co.setSourceName(source.getDesc());
} }
co.setExpireTime(propCouponDO.getExpireTime()); co.setExpireTime(ZonedDateTimeUtils.toTimestamp(propCouponDO.getExpireTime()));
co.setUseTime(propCouponDO.getUseTime()); co.setUseTime(ZonedDateTimeUtils.toTimestamp(propCouponDO.getUseTime()));
co.setCreateTime(propCouponDO.getCreateTime()); co.setCreateTime(ZonedDateTimeUtils.toTimestamp(propCouponDO.getCreateTime()));
return co; return co;
} }
@ -117,7 +119,7 @@ public class PropCouponConvertor {
co.setReceiverId(recordDO.getReceiverId()); co.setReceiverId(recordDO.getReceiverId());
co.setRemark(recordDO.getRemark()); co.setRemark(recordDO.getRemark());
co.setCreateTime(recordDO.getCreateTime()); co.setCreateTime(ZonedDateTimeUtils.toTimestamp(recordDO.getCreateTime()));
return co; return co;
} }

View File

@ -3,6 +3,7 @@ package com.red.circle.other.app.dto.clientobject;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import java.sql.Timestamp;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/** /**
@ -77,18 +78,15 @@ public class PropCouponCO {
/** /**
* 过期时间 * 过期时间
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Timestamp expireTime;
private LocalDateTime expireTime;
/** /**
* 使用时间 * 使用时间
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Timestamp useTime;
private LocalDateTime useTime;
/** /**
* 创建时间 * 创建时间
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Timestamp createTime;
private LocalDateTime createTime;
} }

View File

@ -3,6 +3,7 @@ package com.red.circle.other.app.dto.clientobject;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import java.sql.Timestamp;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/** /**
@ -77,6 +78,5 @@ public class PropCouponRecordCO {
/** /**
* 创建时间 * 创建时间
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Timestamp createTime;
private LocalDateTime createTime;
} }

View File

@ -3,6 +3,7 @@ package com.red.circle.other.infra.utils;
import com.alibaba.cloud.commons.lang.StringUtils; import com.alibaba.cloud.commons.lang.StringUtils;
import com.red.circle.tool.core.date.ZonedId; import com.red.circle.tool.core.date.ZonedId;
import java.sql.Timestamp;
import java.time.DayOfWeek; import java.time.DayOfWeek;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
@ -440,6 +441,30 @@ public final class ZonedDateTimeUtils {
return time.format(DateTimeFormatter.ofPattern(format.getPattern())); return time.format(DateTimeFormatter.ofPattern(format.getPattern()));
} }
/**
* localDateTime 转毫秒
* @param localDateTime
* @return
*/
public static long toTimestampMillis(LocalDateTime localDateTime) {
if (localDateTime == null) {
throw new IllegalArgumentException("LocalDateTime cannot be null");
}
return localDateTime.atZone(ZonedId.ASIA_RIYADH.getZonedId()).toInstant().toEpochMilli();
}
/**
* localDateTime 转时间戳
* @param localDateTime
* @return
*/
public static Timestamp toTimestamp(LocalDateTime localDateTime) {
if (localDateTime == null) {
return null;
}
return Timestamp.from(localDateTime.atZone(ZonedId.ASIA_RIYADH.getZonedId()).toInstant());
}
/** /**
* 转换zoneId * 转换zoneId
* *