获取用户的过期时间
This commit is contained in:
parent
fe754c6ac9
commit
a85ad2e82e
@ -25,7 +25,7 @@ public class SysUserConvertUtils {
|
||||
sysUserVo.setReceiveSms(entity.getReceiveSms());
|
||||
sysUserVo.setReceiveSmsCount(entity.getReceiveSmsCount());
|
||||
sysUserVo.setRemark(entity.getRemark());
|
||||
sysUserVo.setOverTime(VipTimeRangeUtils.obtainLastOverTime(entity.getVipTimeRangeJson()));
|
||||
sysUserVo.setOverTime(VipTimeRangeUtils.obtainOverTime(entity.getVipTimeRangeJson(), entity.getAddTime(), entity.getDayNum()));
|
||||
return sysUserVo;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,71 @@ public class VipTimeRangeUtils {
|
||||
private VipTimeRangeUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的过期时间
|
||||
*/
|
||||
public static String obtainOverTime(String oldVipTimeRangeJson, String addTime, Long dayNum) {
|
||||
// 试用期结束时间
|
||||
LocalDateTime lastTryTime = obtainLastTryTime(addTime, dayNum);
|
||||
// VIP过期时间
|
||||
LocalDateTime lastOverTime = obtainLastOverTime(oldVipTimeRangeJson);
|
||||
// 如果没有设置过VIP时间范围,那就将试用期结束时间返回
|
||||
if (lastOverTime == null) {
|
||||
return DateTimeUtils.localDateTimeToString(lastTryTime);
|
||||
}
|
||||
//如果VIP时间范围对应的结束时间更晚,那就将VIP时间范围的结束时间返回
|
||||
if (lastOverTime.isAfter(lastTryTime)) {
|
||||
return DateTimeUtils.localDateTimeToString(lastOverTime);
|
||||
}
|
||||
//否则就返回试用期的结束时间
|
||||
return DateTimeUtils.localDateTimeToString(lastTryTime);
|
||||
}
|
||||
|
||||
private static LocalDateTime obtainLastTryTime(String addTime, Long dayNum) {
|
||||
return LocalDateTime.parse(addTime, DateTimeUtils.DATE_TIME_FORMATTER_1).plusDays(dayNum);
|
||||
}
|
||||
|
||||
private static LocalDateTime obtainLastOverTime(String oldVipTimeRangeJson) {
|
||||
//oldVipTimeRangeJson不为空说明不是新注册用户,解析该用户的VIP时间范围
|
||||
VipTimeRangeBean vipTimeRangeBean = JsonUtils.deserialize(oldVipTimeRangeJson, VipTimeRangeBean.class);
|
||||
if (vipTimeRangeBean == null || vipTimeRangeBean.getList() == null || vipTimeRangeBean.getList().size() == 0) {
|
||||
return null;
|
||||
}
|
||||
List<VipTimeRangeBean.VipTimeRangeItemBean> list = vipTimeRangeBean.getList();
|
||||
if (list == null || list.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
//校验数据合法性
|
||||
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemBeanA : list) {
|
||||
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemBeanB : list) {
|
||||
if (vipTimeRangeItemBeanA != vipTimeRangeItemBeanB) {
|
||||
LocalDateTime startLocalDateTimeA = LocalDateTime.parse(vipTimeRangeItemBeanA.getStartTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime endLocalDateTimeA = LocalDateTime.parse(vipTimeRangeItemBeanA.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime startLocalDateTimeB = LocalDateTime.parse(vipTimeRangeItemBeanB.getStartTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime endLocalDateTimeB = LocalDateTime.parse(vipTimeRangeItemBeanB.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
if (startLocalDateTimeB.isBefore(startLocalDateTimeA) && endLocalDateTimeB.isAfter(startLocalDateTimeA)) {
|
||||
throw new RuntimeException("VIP开始结束时间存在交叉现象1,系统数据错误");
|
||||
}
|
||||
if (startLocalDateTimeB.isBefore(endLocalDateTimeA) && endLocalDateTimeB.isAfter(endLocalDateTimeA)) {
|
||||
throw new RuntimeException("VIP开始结束时间存在交叉现象2,系统数据错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//获取结束时间最大的那个Pair
|
||||
VipTimeRangeBean.VipTimeRangeItemBean lastVipTimeRangeItemBean = list.get(0);
|
||||
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemBean : list) {
|
||||
if (lastVipTimeRangeItemBean != vipTimeRangeItemBean) {
|
||||
LocalDateTime endLocalDateTime = LocalDateTime.parse(vipTimeRangeItemBean.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime lastEndLocalDateTime = LocalDateTime.parse(lastVipTimeRangeItemBean.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
if (endLocalDateTime.isAfter(lastEndLocalDateTime)) {
|
||||
lastVipTimeRangeItemBean = vipTimeRangeItemBean;
|
||||
}
|
||||
}
|
||||
}
|
||||
return LocalDateTime.parse(lastVipTimeRangeItemBean.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
}
|
||||
|
||||
public static boolean checkIfInTryTimeRange(String addTime, Long dayNum) {
|
||||
return checkIfInTryTimeRange(addTime, dayNum, LocalDateTime.now());
|
||||
}
|
||||
@ -26,9 +91,6 @@ public class VipTimeRangeUtils {
|
||||
* 校验传入的时间是否在指定的试用期过期时间之前
|
||||
*/
|
||||
public static boolean checkIfInTryTimeRange(String addTime, Long dayNum, LocalDateTime targetLocalDateTime) {
|
||||
if (TextUtils.isEmpty(addTime) || dayNum == null || targetLocalDateTime == null) {
|
||||
return false;
|
||||
}
|
||||
LocalDateTime addLocalDateTime = LocalDateTime.parse(addTime, DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime tryLocalDateTime = addLocalDateTime.plusDays(dayNum);
|
||||
return targetLocalDateTime.isBefore(tryLocalDateTime);
|
||||
@ -114,47 +176,6 @@ public class VipTimeRangeUtils {
|
||||
return vipLocalDateTimeRangePairList;
|
||||
}
|
||||
|
||||
public static String obtainLastOverTime(String oldVipTimeRangeJson) {
|
||||
//oldVipTimeRangeJson不为空说明不是新注册用户,解析该用户的VIP时间范围
|
||||
VipTimeRangeBean vipTimeRangeBean = JsonUtils.deserialize(oldVipTimeRangeJson, VipTimeRangeBean.class);
|
||||
if (vipTimeRangeBean == null || vipTimeRangeBean.getList() == null || vipTimeRangeBean.getList().size() == 0) {
|
||||
throw new RuntimeException("已保存的VIP时间范围反序列化失败");
|
||||
}
|
||||
List<VipTimeRangeBean.VipTimeRangeItemBean> list = vipTimeRangeBean.getList();
|
||||
if (list == null || list.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
//校验数据合法性
|
||||
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemBeanA : list) {
|
||||
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemBeanB : list) {
|
||||
if (vipTimeRangeItemBeanA != vipTimeRangeItemBeanB) {
|
||||
LocalDateTime startLocalDateTimeA = LocalDateTime.parse(vipTimeRangeItemBeanA.getStartTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime endLocalDateTimeA = LocalDateTime.parse(vipTimeRangeItemBeanA.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime startLocalDateTimeB = LocalDateTime.parse(vipTimeRangeItemBeanB.getStartTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime endLocalDateTimeB = LocalDateTime.parse(vipTimeRangeItemBeanB.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
if (startLocalDateTimeB.isBefore(startLocalDateTimeA) && endLocalDateTimeB.isAfter(startLocalDateTimeA)) {
|
||||
throw new RuntimeException("VIP开始结束时间存在交叉现象1,系统数据错误");
|
||||
}
|
||||
if (startLocalDateTimeB.isBefore(endLocalDateTimeA) && endLocalDateTimeB.isAfter(endLocalDateTimeA)) {
|
||||
throw new RuntimeException("VIP开始结束时间存在交叉现象2,系统数据错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//获取结束时间最大的那个Pair
|
||||
VipTimeRangeBean.VipTimeRangeItemBean lastVipTimeRangeItemBean = list.get(0);
|
||||
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemBean : list) {
|
||||
if (lastVipTimeRangeItemBean != vipTimeRangeItemBean) {
|
||||
LocalDateTime endLocalDateTime = LocalDateTime.parse(vipTimeRangeItemBean.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime lastEndLocalDateTime = LocalDateTime.parse(lastVipTimeRangeItemBean.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
if (endLocalDateTime.isAfter(lastEndLocalDateTime)) {
|
||||
lastVipTimeRangeItemBean = vipTimeRangeItemBean;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lastVipTimeRangeItemBean.getEndTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成一个新的 VipTimeRangeJson
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user