From 83e87fab0fe81a587d061f833665730286cd504b Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 13 Apr 2023 14:39:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=81=AB=E7=82=B9=E9=87=8D=E6=9E=84-=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E9=98=B2=E7=81=AB=E5=AD=A3=E8=AE=A2=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/helper/FirePointQueryManager.java | 9 +- .../com/xkrs/utilsnew/FirePointCodeUtils.java | 5 +- .../com/xkrs/utilsnew/TimeRangeUtils.java | 25 ++++- .../com/xkrs/utilsnew/VipTimeRangeUtils.java | 94 ------------------- 4 files changed, 29 insertions(+), 104 deletions(-) diff --git a/src/main/java/com/xkrs/helper/FirePointQueryManager.java b/src/main/java/com/xkrs/helper/FirePointQueryManager.java index 6d0efb5..de408cf 100644 --- a/src/main/java/com/xkrs/helper/FirePointQueryManager.java +++ b/src/main/java/com/xkrs/helper/FirePointQueryManager.java @@ -6,7 +6,7 @@ import com.xkrs.model.entity.FirePointOrdinaryEntity; import com.xkrs.model.entity.SysUserEntity; import com.xkrs.utilsnew.DateTimeUtils; import com.xkrs.utilsnew.FirePointCodeUtils; -import com.xkrs.utilsnew.VipTimeRangeUtils; +import com.xkrs.utilsnew.TimeRangeUtils; import org.apache.hc.core5.util.TextUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,11 +90,10 @@ public class FirePointQueryManager { }; //未审核的普通火点列表 List firePointList = firePointOrdinaryDao.findAll(specificationOrdinary, Sort.by(Sort.Direction.DESC, "satelliteTime")); - boolean inVipTimeRange = VipTimeRangeUtils.checkIfInVipTimeRange(sysUserEntity.getVipTimeRangeJson());//查询火点后的步骤 - if ((!"管理员".equals(sysUserEntity.getAccountType())) && (!inVipTimeRange)) { - //该账号不是管理员,并且不在VIP时间范围内。(过期的普通用户)那就清空火点的研判标志 + if ((!"管理员".equals(sysUserEntity.getAccountType())) && TimeRangeUtils.checkIfAllExpired(sysUserEntity)) { + //过期的普通用户看不到火点的研判标志 for (FirePointOrdinaryEntity firePoint : firePointList) { - firePoint.setFireStatus(null);//过期的普通用户看不到火点的研判标志 + firePoint.setFireStatus(null); } } return new FirePointQueryResultBean(true, "", firePointList, firePointList.size()); diff --git a/src/main/java/com/xkrs/utilsnew/FirePointCodeUtils.java b/src/main/java/com/xkrs/utilsnew/FirePointCodeUtils.java index 647dcd5..2e7de7b 100644 --- a/src/main/java/com/xkrs/utilsnew/FirePointCodeUtils.java +++ b/src/main/java/com/xkrs/utilsnew/FirePointCodeUtils.java @@ -51,9 +51,8 @@ public class FirePointCodeUtils { if ("管理员".equals(sysUser.getAccountType())) {//管理员用户不发短信 continue; } - boolean inVipTimeRange = VipTimeRangeUtils.checkIfInVipTimeRange(sysUser.getVipTimeRangeJson()); - if (!inVipTimeRange) { - //普通用户最多可以接收3条短信 + if (TimeRangeUtils.checkIfAllExpired(sysUser)) { + //过期用户最多可以接收3条短信 Long receiveSmsCount = sysUser.getReceiveSmsCount(); if (receiveSmsCount != null && receiveSmsCount >= 3) { continue; diff --git a/src/main/java/com/xkrs/utilsnew/TimeRangeUtils.java b/src/main/java/com/xkrs/utilsnew/TimeRangeUtils.java index f11825f..a060cda 100644 --- a/src/main/java/com/xkrs/utilsnew/TimeRangeUtils.java +++ b/src/main/java/com/xkrs/utilsnew/TimeRangeUtils.java @@ -2,22 +2,37 @@ package com.xkrs.utilsnew; import com.xkrs.model.bean.DataWrapper2; import com.xkrs.model.bean.VipTimeRangeBean; +import com.xkrs.model.entity.SysUserEntity; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +/** + * 时间范围工具类 + */ public class 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是否有效 */ public static boolean checkIfVipValid(String vipTimeRangeJson) { LocalDateTime now = LocalDateTime.now(); List> vipRangeList = getVipRangeList(vipTimeRangeJson); + for (DataWrapper2 vipRange : vipRangeList) { + if (checkIfInTargetRange(vipRange.getData1(), vipRange.getData2(), now)) { + return true; + } + } return false; } @@ -53,14 +68,13 @@ public class TimeRangeUtils { return vipRangeList; } - /** * 检查试用期是否有效 */ public static boolean checkIfProbationValid(String addTime, Long dayNum) { LocalDateTime now = LocalDateTime.now(); DataWrapper2 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); } + /** + * 判断test是否在rangeStart和rangeEnd之间 + */ + public static boolean checkIfInTargetRange(LocalDateTime rangeStart, LocalDateTime rangeEnd, LocalDateTime test) { + return rangeStart.isBefore(test) && rangeEnd.isAfter(test); + } + } diff --git a/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java b/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java index 9cd64d0..b8cd0cc 100644 --- a/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java +++ b/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java @@ -1,6 +1,5 @@ package com.xkrs.utilsnew; -import com.xkrs.model.bean.VipLocalDateTimeRangePair; import com.xkrs.model.bean.VipTimeRangeBean; import org.apache.hc.core5.util.TextUtils; import org.slf4j.Logger; @@ -9,7 +8,6 @@ import org.slf4j.LoggerFactory; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; public class VipTimeRangeUtils { @@ -86,98 +84,6 @@ public class VipTimeRangeUtils { 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 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 obtainSortedVipLocalDateTimeRangePairList(List list) { - List 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 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 */