From 2632d73c42f73a1437c5c62a8493c7c5f1aeebdf Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 13 Apr 2023 12:00:37 +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/service/impl/SysUserServiceImpl.java | 14 ++-- .../com/xkrs/utilsnew/TimeRangeUtils.java | 83 +++++++++++++++++++ .../com/xkrs/utilsnew/VipTimeRangeUtils.java | 2 +- 3 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/xkrs/utilsnew/TimeRangeUtils.java diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index 0995c01..b864a61 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -109,6 +109,7 @@ public class SysUserServiceImpl implements SysUserService { } sysUserEntity.setActiveFlag(0); sysUserEntity.setAccountType("街道级"); + sysUserEntity.setDayNum(7L); } else if ("0000".equals(countyCode.substring(2))) { List proCodeList = streetDao.findByProCode(countyCode); if (proCodeList == null || proCodeList.size() == 0) { @@ -120,6 +121,7 @@ public class SysUserServiceImpl implements SysUserService { } sysUserEntity.setActiveFlag(1); sysUserEntity.setAccountType("省级"); + sysUserEntity.setDayNum(5L); } else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) { List cityCodeList = streetDao.findByCityCode(countyCode); if (cityCodeList == null || cityCodeList.size() == 0) { @@ -131,6 +133,7 @@ public class SysUserServiceImpl implements SysUserService { } sysUserEntity.setActiveFlag(1); sysUserEntity.setAccountType("市级"); + sysUserEntity.setDayNum(5L); } else { List countyCodeList = streetDao.findByCountyCode(countyCode); if (countyCodeList == null || countyCodeList.isEmpty()) { @@ -142,11 +145,7 @@ public class SysUserServiceImpl implements SysUserService { } sysUserEntity.setActiveFlag(0); sysUserEntity.setAccountType("县级"); - } - if (9 == countyCode.length()) {//街道账号7天后过期 sysUserEntity.setDayNum(7L); - } else {//省市区县账号5天后过期 - sysUserEntity.setDayNum(5L); } sysUserEntity.setVipTimeRangeJson(""); sysUserEntity.setAddTime(dateTimeToString(LocalDateTime.now())); @@ -211,6 +210,7 @@ public class SysUserServiceImpl implements SysUserService { } sysUserEntity.setActiveFlag(0); sysUserEntity.setAccountType("街道级"); + sysUserEntity.setDayNum(7L); } else if ("0000".equals(countyCode.substring(2))) { List proCodeList = streetDao.findByProCode(countyCode); if (proCodeList == null || proCodeList.size() == 0) { @@ -222,6 +222,7 @@ public class SysUserServiceImpl implements SysUserService { } sysUserEntity.setActiveFlag(1); sysUserEntity.setAccountType("省级"); + sysUserEntity.setDayNum(5L); } else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) { List cityCodeList = streetDao.findByCityCode(countyCode); if (cityCodeList == null || cityCodeList.size() == 0) { @@ -233,6 +234,7 @@ public class SysUserServiceImpl implements SysUserService { } sysUserEntity.setActiveFlag(1); sysUserEntity.setAccountType("市级"); + sysUserEntity.setDayNum(5L); } else { List countyCodeList = streetDao.findByCountyCode(countyCode); if (countyCodeList == null || countyCodeList.isEmpty()) { @@ -244,11 +246,7 @@ public class SysUserServiceImpl implements SysUserService { } sysUserEntity.setActiveFlag(0); sysUserEntity.setAccountType("县级"); - } - if (9 == countyCode.length()) {//街道账号7天后过期 sysUserEntity.setDayNum(7L); - } else {//省市区县账号5天后过期 - sysUserEntity.setDayNum(5L); } sysUserEntity.setVipTimeRangeJson(""); sysUserEntity.setAddTime(dateTimeToString(LocalDateTime.now())); diff --git a/src/main/java/com/xkrs/utilsnew/TimeRangeUtils.java b/src/main/java/com/xkrs/utilsnew/TimeRangeUtils.java new file mode 100644 index 0000000..f11825f --- /dev/null +++ b/src/main/java/com/xkrs/utilsnew/TimeRangeUtils.java @@ -0,0 +1,83 @@ +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> vipRangeList = getVipRangeList(vipTimeRangeJson); + return false; + } + + /** + * 检查VIP是否过期(OK) + */ + public static boolean checkIfVipExpired(String vipTimeRangeJson) { + return !checkIfVipValid(vipTimeRangeJson); + } + + /** + * 获取VIP范围列表(OK) + */ + public static List> getVipRangeList(String vipTimeRangeJson) { + List> vipRangeList = new ArrayList<>();//VIP范围结果列表 + List 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 probationRange = getProbationRange(addTime, dayNum); + return false; + } + + /** + * 检查试用期是否过期(OK) + */ + public static boolean checkIfProbationExpired(String addTime, Long dayNum) { + return !checkIfProbationValid(addTime, dayNum); + } + + /** + * 获取试用期范围(OK) + */ + public static DataWrapper2 getProbationRange(String addTime, Long dayNum) { + DateTimeUtils.checkDateTimeFormat(addTime); + LocalDateTime start = DateTimeUtils.formatToLocalDateTime(addTime); + LocalDateTime end = start.plusDays(dayNum); + return new DataWrapper2<>(start, end); + } + +} diff --git a/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java b/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java index 605f972..9cd64d0 100644 --- a/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java +++ b/src/main/java/com/xkrs/utilsnew/VipTimeRangeUtils.java @@ -43,7 +43,7 @@ public class VipTimeRangeUtils { } private static LocalDateTime obtainLastOverTime(String oldVipTimeRangeJson) { - //oldVipTimeRangeJson不为空说明不是新注册用户,解析该用户的VIP时间范围 + //只有付费签约的用户VipTimeRangeJson字段才不为空,注册试用的用户由DayNum字段设置的天数决定试用时长 if (TextUtils.isEmpty(oldVipTimeRangeJson)) { return null; }