获得SKU回收站分页列表
This commit is contained in:
@@ -3,6 +3,7 @@ package com.tashow.cloud.common.util.date;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
|
||||
import java.time.*;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -27,6 +28,9 @@ public class DateUtils {
|
||||
|
||||
public static final String FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
|
||||
// 默认数据保留天数
|
||||
private static final long RETENTION_DAYS = 90;
|
||||
/**
|
||||
* 将 LocalDateTime 转换成 Date
|
||||
*
|
||||
@@ -146,4 +150,36 @@ public class DateUtils {
|
||||
return LocalDateTimeUtil.isSameDay(date, LocalDateTime.now().minusDays(1));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据删除时间,计算还剩多少天被彻底删除(默认保留 90 天)
|
||||
*
|
||||
* @param deleteTime 删除时间
|
||||
* @return 剩余天数(>=0),0 表示已过期
|
||||
*/
|
||||
public static long getRemainingDays(Date deleteTime) {
|
||||
if (deleteTime == null) {
|
||||
throw new IllegalArgumentException("删除时间不能为 null");
|
||||
}
|
||||
|
||||
// 将 Date 转换为 LocalDateTime
|
||||
LocalDateTime deleteDateTime = deleteTime.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
|
||||
// 当前时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 到期时间 = 删除时间 + 保留天数
|
||||
LocalDateTime expireTime = deleteDateTime.plusDays(RETENTION_DAYS);
|
||||
|
||||
// 如果当前时间已经超过到期时间,剩余天数为 0
|
||||
if (now.isAfter(expireTime)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 计算剩余天数(向下取整,不进位)
|
||||
return ChronoUnit.DAYS.between(now, expireTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user