重写用户获取火点数据的接口

This commit is contained in:
liuchengqian 2023-02-24 10:45:27 +08:00
parent 6d75affb2c
commit 6ddb10b45b
2 changed files with 56 additions and 9 deletions

View File

@ -5,11 +5,15 @@ import com.xkrs.straw.dao.FirePointPreciseDao;
import com.xkrs.straw.model.bean.FirePointQueryResultBean; import com.xkrs.straw.model.bean.FirePointQueryResultBean;
import com.xkrs.straw.model.bean.VipTimeRangeBean; import com.xkrs.straw.model.bean.VipTimeRangeBean;
import com.xkrs.straw.model.entity.SysUserEntity; import com.xkrs.straw.model.entity.SysUserEntity;
import com.xkrs.utils.DateTimeUtil;
import com.xkrs.utils.DateTimeUtils;
import com.xkrs.utils.FirePointCodeUtils; import com.xkrs.utils.FirePointCodeUtils;
import org.apache.hc.core5.util.TextUtils; import org.apache.hc.core5.util.TextUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Component @Component
@ -23,6 +27,8 @@ public class FirePointQueryManager {
public FirePointQueryResultBean queryFirePointBelongToUser(SysUserEntity sysUserEntity, String startTime, String endTime, String satelliteType, String landType) { public FirePointQueryResultBean queryFirePointBelongToUser(SysUserEntity sysUserEntity, String startTime, String endTime, String satelliteType, String landType) {
String mNoRedundantUserCode = null;
final List<VipTimeRangeBean.VipTimeRangeItemBean> mVipTimeRangeItemList = new ArrayList<>();
try { try {
//获取用户注册的区划编码 //获取用户注册的区划编码
String userCode = sysUserEntity.getCountyCode(); String userCode = sysUserEntity.getCountyCode();
@ -52,7 +58,41 @@ public class FirePointQueryManager {
//得到由<开始时间 + 结束时间>组成的集合 //得到由<开始时间 + 结束时间>组成的集合
List<VipTimeRangeBean.VipTimeRangeItemBean> vipTimeRangeItemList = vipTimeRangeBean.getList(); List<VipTimeRangeBean.VipTimeRangeItemBean> vipTimeRangeItemList = vipTimeRangeBean.getList();
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemA : vipTimeRangeItemList) {
//校验用户VIP开始时间合法性
if (!DateTimeUtil.isValidDateTime(vipTimeRangeItemA.getStartTime())) {
return new FirePointQueryResultBean(false, "User VIP 开始时间格式不合法1, StartTime = " + vipTimeRangeItemA.getStartTime(), null);
}
//校验用户VIP结束时间合法性
if (!DateTimeUtil.isValidDateTime(vipTimeRangeItemA.getEndTime())) {
return new FirePointQueryResultBean(false, "User VIP 结束时间格式不合法2, EndTime = " + vipTimeRangeItemA.getEndTime(), null);
}
LocalDateTime userStartLocalDateTimeA = LocalDateTime.parse(vipTimeRangeItemA.getStartTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
LocalDateTime userEndLocalDateTimeA = LocalDateTime.parse(vipTimeRangeItemA.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemB : vipTimeRangeItemList) {
if (vipTimeRangeItemA != vipTimeRangeItemB) {
//校验用户VIP开始时间合法性
if (!DateTimeUtil.isValidDateTime(vipTimeRangeItemB.getStartTime())) {
return new FirePointQueryResultBean(false, "User VIP 开始时间格式不合法3, StartTime = " + vipTimeRangeItemB.getStartTime(), null);
}
//校验用户VIP结束时间合法性
if (!DateTimeUtil.isValidDateTime(vipTimeRangeItemB.getEndTime())) {
return new FirePointQueryResultBean(false, "User VIP 结束时间格式不合法4, EndTime = " + vipTimeRangeItemB.getEndTime(), null);
}
LocalDateTime userStartLocalDateTimeB = LocalDateTime.parse(vipTimeRangeItemB.getStartTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
LocalDateTime userEndLocalDateTimeB = LocalDateTime.parse(vipTimeRangeItemB.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
//校验用户VIP开始结束时间是否存在交叉现象
if (userStartLocalDateTimeB.isBefore(userStartLocalDateTimeA) && userEndLocalDateTimeB.isAfter(userStartLocalDateTimeA)) {
return new FirePointQueryResultBean(false, "User VIP 开始结束时间格式不合法5, 存在交叉现象", null);
}
if (userStartLocalDateTimeB.isBefore(userEndLocalDateTimeA) && userEndLocalDateTimeB.isAfter(userEndLocalDateTimeA)) {
return new FirePointQueryResultBean(false, "User VIP 开始结束时间格式不合法6, 存在交叉现象", null);
}
}
}
}
mNoRedundantUserCode = noRedundantUserCode;
mVipTimeRangeItemList.addAll(vipTimeRangeItemList);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -60,8 +100,6 @@ public class FirePointQueryManager {
} }
//FirePointQueryResultBean
return null; return null;
} }

View File

@ -1,5 +1,7 @@
package com.xkrs.utils; package com.xkrs.utils;
import org.apache.hc.core5.util.TextUtils;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
@ -77,15 +79,22 @@ public class DateTimeUtil {
/** /**
* 判断时间格式 格式必须为 "YYYY-MM-DD HH:mm:ss" * 判断时间格式 格式必须为 "YYYY-MM-DD HH:mm:ss"
*/ */
public static boolean isValidDateTime(String sDateTime) { public static boolean isValidDateTime(String formattedDateTime) {
final int minLen = 19; int validLength = 19;
if ((sDateTime == null) || (sDateTime.length() < minLen)) { if (TextUtils.isEmpty(formattedDateTime) || formattedDateTime.length() != validLength) {
return false; return false;
} }
String eL = "(((01[0-9]{2}|0[2-9][0-9]{2}|[1-9][0-9]{3})-(0?[13578]|1[02])-" + "(0?[1-9]|[12]\\\\d|3[01]))|((01[0-9]{2}|0[2-9][0-9]{2}|[1-9][0-9]{3})-" + "(0?[13456789]|1[012])-(0?[1-9]|[12]\\\\d|30))|((01[0-9]{2}|0[2-9][0-9]{2}|[1-9][0-9]{3})-0?2-" + "(0?[1-9]|1\\\\d|2[0-8]))|(((1[6-9]|[2-9]\\\\d)(0[48]|[2468][048]|[13579][26])|((04|08|12|16|[2468][048]|" + "[3579][26])00))-0?2-29)) (20|21|22|23|[0-1]?\\\\d):[0-5]?\\\\d:[0-5]?\\\\d"; String regex = "^([1-2][0-9][0-9][0-9]-[0-1]{0,1}[0-9]-[0-3]{0,1}[0-9])\\s(20|21|22|23|[0-1]\\d):[0-5]\\d:[0-5]\\d$";
Pattern pat = Pattern.compile(eL); Pattern pattern = Pattern.compile(regex);
Matcher matcher = pat.matcher(sDateTime); Matcher matcher = pattern.matcher(formattedDateTime);
return matcher.matches(); return matcher.matches();
} }
public static void main(String[] args) {
// boolean validDateTime = isValidDateTime("2222-01-21 19:59:59");
// System.out.println("validDateTime = " + validDateTime);
}
} }