火点重构-完善防火季订阅

This commit is contained in:
liuchengqian 2023-04-13 14:39:18 +08:00
parent 2632d73c42
commit 83e87fab0f
4 changed files with 29 additions and 104 deletions

View File

@ -6,7 +6,7 @@ import com.xkrs.model.entity.FirePointOrdinaryEntity;
import com.xkrs.model.entity.SysUserEntity; import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.utilsnew.DateTimeUtils; import com.xkrs.utilsnew.DateTimeUtils;
import com.xkrs.utilsnew.FirePointCodeUtils; import com.xkrs.utilsnew.FirePointCodeUtils;
import com.xkrs.utilsnew.VipTimeRangeUtils; import com.xkrs.utilsnew.TimeRangeUtils;
import org.apache.hc.core5.util.TextUtils; import org.apache.hc.core5.util.TextUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -90,11 +90,10 @@ public class FirePointQueryManager {
}; };
//未审核的普通火点列表 //未审核的普通火点列表
List<FirePointOrdinaryEntity> firePointList = firePointOrdinaryDao.findAll(specificationOrdinary, Sort.by(Sort.Direction.DESC, "satelliteTime")); List<FirePointOrdinaryEntity> firePointList = firePointOrdinaryDao.findAll(specificationOrdinary, Sort.by(Sort.Direction.DESC, "satelliteTime"));
boolean inVipTimeRange = VipTimeRangeUtils.checkIfInVipTimeRange(sysUserEntity.getVipTimeRangeJson());//查询火点后的步骤 if ((!"管理员".equals(sysUserEntity.getAccountType())) && TimeRangeUtils.checkIfAllExpired(sysUserEntity)) {
if ((!"管理员".equals(sysUserEntity.getAccountType())) && (!inVipTimeRange)) { //过期的普通用户看不到火点的研判标志
//该账号不是管理员并且不在VIP时间范围内过期的普通用户那就清空火点的研判标志
for (FirePointOrdinaryEntity firePoint : firePointList) { for (FirePointOrdinaryEntity firePoint : firePointList) {
firePoint.setFireStatus(null);//过期的普通用户看不到火点的研判标志 firePoint.setFireStatus(null);
} }
} }
return new FirePointQueryResultBean(true, "", firePointList, firePointList.size()); return new FirePointQueryResultBean(true, "", firePointList, firePointList.size());

View File

@ -51,9 +51,8 @@ public class FirePointCodeUtils {
if ("管理员".equals(sysUser.getAccountType())) {//管理员用户不发短信 if ("管理员".equals(sysUser.getAccountType())) {//管理员用户不发短信
continue; continue;
} }
boolean inVipTimeRange = VipTimeRangeUtils.checkIfInVipTimeRange(sysUser.getVipTimeRangeJson()); if (TimeRangeUtils.checkIfAllExpired(sysUser)) {
if (!inVipTimeRange) { //过期用户最多可以接收3条短信
//普通用户最多可以接收3条短信
Long receiveSmsCount = sysUser.getReceiveSmsCount(); Long receiveSmsCount = sysUser.getReceiveSmsCount();
if (receiveSmsCount != null && receiveSmsCount >= 3) { if (receiveSmsCount != null && receiveSmsCount >= 3) {
continue; continue;

View File

@ -2,22 +2,37 @@ package com.xkrs.utilsnew;
import com.xkrs.model.bean.DataWrapper2; import com.xkrs.model.bean.DataWrapper2;
import com.xkrs.model.bean.VipTimeRangeBean; import com.xkrs.model.bean.VipTimeRangeBean;
import com.xkrs.model.entity.SysUserEntity;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* 时间范围工具类
*/
public class TimeRangeUtils { public class TimeRangeUtils {
private TimeRangeUtils() { private TimeRangeUtils() {
} }
public static boolean checkIfAllExpired(SysUserEntity sysUserEntity) {
boolean probationExpired = checkIfProbationExpired(sysUserEntity.getAddTime(), sysUserEntity.getDayNum());//试用期是否过期
boolean vipExpired = checkIfVipExpired(sysUserEntity.getVipTimeRangeJson());//VIP是否过期
return probationExpired && vipExpired;
}
/** /**
* 检查VIP是否有效 * 检查VIP是否有效
*/ */
public static boolean checkIfVipValid(String vipTimeRangeJson) { public static boolean checkIfVipValid(String vipTimeRangeJson) {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
List<DataWrapper2<LocalDateTime, LocalDateTime>> vipRangeList = getVipRangeList(vipTimeRangeJson); List<DataWrapper2<LocalDateTime, LocalDateTime>> vipRangeList = getVipRangeList(vipTimeRangeJson);
for (DataWrapper2<LocalDateTime, LocalDateTime> vipRange : vipRangeList) {
if (checkIfInTargetRange(vipRange.getData1(), vipRange.getData2(), now)) {
return true;
}
}
return false; return false;
} }
@ -53,14 +68,13 @@ public class TimeRangeUtils {
return vipRangeList; return vipRangeList;
} }
/** /**
* 检查试用期是否有效 * 检查试用期是否有效
*/ */
public static boolean checkIfProbationValid(String addTime, Long dayNum) { public static boolean checkIfProbationValid(String addTime, Long dayNum) {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
DataWrapper2<LocalDateTime, LocalDateTime> probationRange = getProbationRange(addTime, dayNum); DataWrapper2<LocalDateTime, LocalDateTime> probationRange = getProbationRange(addTime, dayNum);
return false; return checkIfInTargetRange(probationRange.getData1(), probationRange.getData2(), now);
} }
/** /**
@ -80,4 +94,11 @@ public class TimeRangeUtils {
return new DataWrapper2<>(start, end); return new DataWrapper2<>(start, end);
} }
/**
* 判断test是否在rangeStart和rangeEnd之间
*/
public static boolean checkIfInTargetRange(LocalDateTime rangeStart, LocalDateTime rangeEnd, LocalDateTime test) {
return rangeStart.isBefore(test) && rangeEnd.isAfter(test);
}
} }

View File

@ -1,6 +1,5 @@
package com.xkrs.utilsnew; package com.xkrs.utilsnew;
import com.xkrs.model.bean.VipLocalDateTimeRangePair;
import com.xkrs.model.bean.VipTimeRangeBean; import com.xkrs.model.bean.VipTimeRangeBean;
import org.apache.hc.core5.util.TextUtils; import org.apache.hc.core5.util.TextUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -9,7 +8,6 @@ import org.slf4j.LoggerFactory;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class VipTimeRangeUtils { public class VipTimeRangeUtils {
@ -86,98 +84,6 @@ public class VipTimeRangeUtils {
return LocalDateTime.parse(lastVipTimeRangeItemBean.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1); return LocalDateTime.parse(lastVipTimeRangeItemBean.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
} }
public static boolean checkIfInTryTimeRange(String addTime, Long dayNum) {
return checkIfInTryTimeRange(addTime, dayNum, LocalDateTime.now());
}
/**
* 校验传入的时间是否在指定的试用期过期时间之前
*/
public static boolean checkIfInTryTimeRange(String addTime, Long dayNum, LocalDateTime targetLocalDateTime) {
LocalDateTime addLocalDateTime = LocalDateTime.parse(addTime, DateTimeUtils.DATE_TIME_FORMATTER_1);
LocalDateTime tryLocalDateTime = addLocalDateTime.plusDays(dayNum);
return targetLocalDateTime.isBefore(tryLocalDateTime);
}
public static boolean checkIfInVipTimeRange(String vipTimeRangeJson) {
return checkIfInVipTimeRange(vipTimeRangeJson, LocalDateTime.now());
}
/**
* 校验传入的时间是否在指定的VIP时间范围内
*/
public static boolean checkIfInVipTimeRange(String vipTimeRangeJson, LocalDateTime targetLocalDateTime) {
try {
if (TextUtils.isEmpty(vipTimeRangeJson) || targetLocalDateTime == null) {
return false;
}
VipTimeRangeBean vipTimeRangeBean = JsonUtils.deserialize(vipTimeRangeJson, VipTimeRangeBean.class);
if (vipTimeRangeBean == null || vipTimeRangeBean.getList() == null || vipTimeRangeBean.getList().size() == 0) {
return false;
}
List<VipLocalDateTimeRangePair> vipLocalDateTimeRangePairList = obtainSortedVipLocalDateTimeRangePairList(vipTimeRangeBean.getList());
if (vipLocalDateTimeRangePairList.size() == 0) {
return false;
}
for (VipLocalDateTimeRangePair vipLocalDateTimeRangePair : vipLocalDateTimeRangePairList) {
LocalDateTime startLocalDateTime = vipLocalDateTimeRangePair.getStartLocalDateTime();
LocalDateTime endLocalDateTime = vipLocalDateTimeRangePair.getEndLocalDateTime();
if (startLocalDateTime.isBefore(targetLocalDateTime) && endLocalDateTime.isAfter(targetLocalDateTime)) {
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
log.info("检查是否属于VIP时间范围时出错详情=" + e.getMessage());
}
return false;
}
/**
* 根据一个字符串格式时间的列表 生成 一个LocalDateTime格式时间的列表
*/
private static List<VipLocalDateTimeRangePair> obtainSortedVipLocalDateTimeRangePairList(List<VipTimeRangeBean.VipTimeRangeItemBean> list) {
List<VipLocalDateTimeRangePair> vipLocalDateTimeRangePairList = new ArrayList<>();
try {
if (list == null || list.size() == 0) {
return vipLocalDateTimeRangePairList;
}
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemBean : list) {
String startTime = vipTimeRangeItemBean.getStartTime();
LocalDateTime startLocalDateTime = LocalDateTime.parse(startTime, DateTimeUtils.DATE_TIME_FORMATTER_1);
String endTime = vipTimeRangeItemBean.getEndTime();
LocalDateTime endLocalDateTime = LocalDateTime.parse(endTime, DateTimeUtils.DATE_TIME_FORMATTER_1);
VipLocalDateTimeRangePair vipLocalDateTimeRangePair = new VipLocalDateTimeRangePair();
vipLocalDateTimeRangePair.setStartLocalDateTime(startLocalDateTime);
vipLocalDateTimeRangePair.setEndLocalDateTime(endLocalDateTime);
vipLocalDateTimeRangePairList.add(vipLocalDateTimeRangePair);
}
List<VipLocalDateTimeRangePair> sortedVipLocalDateTimeRangePairList = vipLocalDateTimeRangePairList.stream().sorted((o1, o2) -> {
try {
LocalDateTime startLocalDateTime1 = o1.getStartLocalDateTime();
LocalDateTime endLocalDateTime1 = o1.getEndLocalDateTime();
LocalDateTime startLocalDateTime2 = o2.getStartLocalDateTime();
LocalDateTime endLocalDateTime2 = o2.getEndLocalDateTime();
if (startLocalDateTime1.isBefore(startLocalDateTime2) && endLocalDateTime1.isBefore(endLocalDateTime2)) {
return 1;
}
if (startLocalDateTime1.isAfter(startLocalDateTime2) && endLocalDateTime1.isAfter(endLocalDateTime2)) {
return -1;
}
return 0;
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}).collect(Collectors.toList());
return sortedVipLocalDateTimeRangePairList;
} catch (Exception e) {
e.printStackTrace();
}
return vipLocalDateTimeRangePairList;
}
/** /**
* 生成一个新的 VipTimeRangeJson * 生成一个新的 VipTimeRangeJson
*/ */