84 lines
2.9 KiB
Java
84 lines
2.9 KiB
Java
|
package com.xkrs.utilsnew;
|
||
|
|
||
|
import com.xkrs.model.bean.DataWrapper2;
|
||
|
import com.xkrs.model.bean.VipTimeRangeBean;
|
||
|
|
||
|
import java.time.LocalDateTime;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
public class TimeRangeUtils {
|
||
|
|
||
|
private TimeRangeUtils() {
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 检查VIP是否有效
|
||
|
*/
|
||
|
public static boolean checkIfVipValid(String vipTimeRangeJson) {
|
||
|
LocalDateTime now = LocalDateTime.now();
|
||
|
List<DataWrapper2<LocalDateTime, LocalDateTime>> vipRangeList = getVipRangeList(vipTimeRangeJson);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 检查VIP是否过期(OK)
|
||
|
*/
|
||
|
public static boolean checkIfVipExpired(String vipTimeRangeJson) {
|
||
|
return !checkIfVipValid(vipTimeRangeJson);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取VIP范围列表(OK)
|
||
|
*/
|
||
|
public static List<DataWrapper2<LocalDateTime, LocalDateTime>> getVipRangeList(String vipTimeRangeJson) {
|
||
|
List<DataWrapper2<LocalDateTime, LocalDateTime>> vipRangeList = new ArrayList<>();//VIP范围结果列表
|
||
|
List<VipTimeRangeBean.VipTimeRangeItemBean> list = new ArrayList<>();//Json解析的VIP范围列表
|
||
|
try {
|
||
|
VipTimeRangeBean vipTimeRangeBean = JsonUtils.deserialize(vipTimeRangeJson, VipTimeRangeBean.class);
|
||
|
if (vipTimeRangeBean.getList() == null || vipTimeRangeBean.getList().size() == 0) {
|
||
|
throw new RuntimeException("VipTimeRangeJson Error");
|
||
|
}
|
||
|
list.addAll(vipTimeRangeBean.getList());
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
for (VipTimeRangeBean.VipTimeRangeItemBean item : list) {
|
||
|
DateTimeUtils.checkDateTimeFormat(item.getStartTime());
|
||
|
DateTimeUtils.checkDateTimeFormat(item.getEndTime());
|
||
|
LocalDateTime start = DateTimeUtils.formatToLocalDateTime(item.getStartTime());
|
||
|
LocalDateTime end = DateTimeUtils.formatToLocalDateTime(item.getEndTime());
|
||
|
vipRangeList.add(new DataWrapper2<>(start, end));
|
||
|
}
|
||
|
return vipRangeList;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 检查试用期是否有效
|
||
|
*/
|
||
|
public static boolean checkIfProbationValid(String addTime, Long dayNum) {
|
||
|
LocalDateTime now = LocalDateTime.now();
|
||
|
DataWrapper2<LocalDateTime, LocalDateTime> probationRange = getProbationRange(addTime, dayNum);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 检查试用期是否过期(OK)
|
||
|
*/
|
||
|
public static boolean checkIfProbationExpired(String addTime, Long dayNum) {
|
||
|
return !checkIfProbationValid(addTime, dayNum);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取试用期范围(OK)
|
||
|
*/
|
||
|
public static DataWrapper2<LocalDateTime, LocalDateTime> getProbationRange(String addTime, Long dayNum) {
|
||
|
DateTimeUtils.checkDateTimeFormat(addTime);
|
||
|
LocalDateTime start = DateTimeUtils.formatToLocalDateTime(addTime);
|
||
|
LocalDateTime end = start.plusDays(dayNum);
|
||
|
return new DataWrapper2<>(start, end);
|
||
|
}
|
||
|
|
||
|
}
|