From 1aa674b883dcbfedc789c12e6b79274b59f9ec96 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Fri, 24 Feb 2023 17:15:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E7=94=A8=E6=88=B7=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=81=AB=E7=82=B9=E6=95=B0=E6=8D=AE=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../straw/utils/FirePointConvertUtils.java | 59 +++++++++++++++++++ .../straw/utils/FirePointQueryManager.java | 59 ++++++++++++++++++- 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/xkrs/straw/utils/FirePointConvertUtils.java diff --git a/src/main/java/com/xkrs/straw/utils/FirePointConvertUtils.java b/src/main/java/com/xkrs/straw/utils/FirePointConvertUtils.java new file mode 100644 index 0000000..b4b4003 --- /dev/null +++ b/src/main/java/com/xkrs/straw/utils/FirePointConvertUtils.java @@ -0,0 +1,59 @@ +package com.xkrs.straw.utils; + +import com.xkrs.straw.model.entity.FirePointOrdinaryEntity; +import com.xkrs.straw.model.entity.FirePointPreciseEntity; +import com.xkrs.straw.model.vo.AllFirePointVo; + +/** + * AllFirePointVo输出格式转化工具 + */ +public class FirePointConvertUtils { + + private FirePointConvertUtils() { + } + + public static AllFirePointVo convert(FirePointOrdinaryEntity entity) { + AllFirePointVo allFirePointVo = new AllFirePointVo(); + allFirePointVo.setId(entity.getId()); + allFirePointVo.setFireCode(entity.getFireCode()); + allFirePointVo.setCountyCode(entity.getCountyCode()); + allFirePointVo.setCountyName(entity.getCountyName()); + allFirePointVo.setSatelliteTime(entity.getSatelliteTime()); + allFirePointVo.setLongitude(entity.getLongitude()); + allFirePointVo.setLatitude(entity.getLatitude()); + allFirePointVo.setSatelliteType(entity.getSatelliteType()); + allFirePointVo.setLandType(entity.getLandType()); + allFirePointVo.setConfidence(entity.getConfidence()); + allFirePointVo.setFireImage(entity.getFireImage()); + allFirePointVo.setSatelliteImage(entity.getSatelliteImage()); + allFirePointVo.setTownCode(entity.getTownCode()); + allFirePointVo.setTownName(entity.getTownName()); + allFirePointVo.setAddTime(entity.getAddTime()); + allFirePointVo.setFirePointAddress(entity.getFirePointAddress()); + allFirePointVo.setRemark(entity.getRemark()); + return allFirePointVo; + } + + public static AllFirePointVo convert(FirePointPreciseEntity entity) { + AllFirePointVo allFirePointVo = new AllFirePointVo(); + allFirePointVo.setId(entity.getId()); + allFirePointVo.setFireCode(entity.getFireCode()); + allFirePointVo.setCountyCode(entity.getCountyCode()); + allFirePointVo.setCountyName(entity.getCountyName()); + allFirePointVo.setSatelliteTime(entity.getSatelliteTime()); + allFirePointVo.setLongitude(entity.getLongitude()); + allFirePointVo.setLatitude(entity.getLatitude()); + allFirePointVo.setSatelliteType(entity.getSatelliteType()); + allFirePointVo.setLandType(entity.getLandType()); + allFirePointVo.setConfidence(entity.getConfidence()); + allFirePointVo.setFireImage(entity.getFireImage()); + allFirePointVo.setSatelliteImage(entity.getSatelliteImage()); + allFirePointVo.setTownCode(entity.getTownCode()); + allFirePointVo.setTownName(entity.getTownName()); + allFirePointVo.setAddTime(entity.getAddTime()); + allFirePointVo.setFirePointAddress(entity.getFirePointAddress()); + allFirePointVo.setRemark(entity.getRemark()); + return allFirePointVo; + } + +} diff --git a/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java b/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java index c13edac..725ea8c 100644 --- a/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java +++ b/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java @@ -4,17 +4,25 @@ import com.xkrs.straw.dao.FirePointOrdinaryDao; import com.xkrs.straw.dao.FirePointPreciseDao; import com.xkrs.straw.model.bean.FirePointQueryResultBean; import com.xkrs.straw.model.bean.VipTimeRangeBean; +import com.xkrs.straw.model.entity.FirePointOrdinaryEntity; +import com.xkrs.straw.model.entity.FirePointPreciseEntity; import com.xkrs.straw.model.entity.SysUserEntity; +import com.xkrs.straw.model.vo.AllFirePointVo; import com.xkrs.utils.DateTimeUtil; import com.xkrs.utils.DateTimeUtils; import com.xkrs.utils.FirePointCodeUtils; import org.apache.hc.core5.util.TextUtils; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import javax.persistence.criteria.Predicate; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; @Component public class FirePointQueryManager { @@ -99,8 +107,57 @@ public class FirePointQueryManager { return new FirePointQueryResultBean(false, e.getMessage(), null); } + final String finalMNoRedundantUserCode = mNoRedundantUserCode; + //查询未审核的普通火点 + Specification specificationOrdinary = (root, criteriaQuery, criteriaBuilder) -> { + List predicateList = new ArrayList<>(); + //添加区划编码的过滤 + predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); + for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : mVipTimeRangeItemList) { + String userStartTime = vipTimeRangeItem.getStartTime(); + String userEndTime = vipTimeRangeItem.getEndTime(); + //早于(不包含)VIP开始时间 + Predicate beforeStartTimePredicate = criteriaBuilder.lessThan(root.get("satelliteTime").as(String.class), userStartTime); + //晚于(不包含)VIP结束时间 + Predicate afterEndTimePredicate = criteriaBuilder.greaterThan(root.get("satelliteTime").as(String.class), userEndTime); + predicateList.add(criteriaBuilder.or(beforeStartTimePredicate, afterEndTimePredicate)); + } + return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()])); + }; + //未审核的普通火点列表 + List firePointOrdinaryList = firePointOrdinaryDao.findAll(specificationOrdinary, Sort.by(Sort.Direction.DESC, "satelliteTime")); - return null; + + //查询审核通过的精准火点 + Specification specificationPrecise = (root, criteriaQuery, criteriaBuilder) -> { + List predicateList = new ArrayList<>(); + //添加区划编码的过滤 + predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); + for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : mVipTimeRangeItemList) { + String userStartTime = vipTimeRangeItem.getStartTime(); + String userEndTime = vipTimeRangeItem.getEndTime(); + //晚于(包含)VIP开始时间 + Predicate beforeStartTimePredicate = criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), userStartTime); + //早于(包含)VIP结束时间 + Predicate afterEndTimePredicate = criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), userEndTime); + predicateList.add(criteriaBuilder.and(beforeStartTimePredicate, afterEndTimePredicate)); + } + return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()])); + }; + //审核通过的精准火点列表 + List firePointPreciseList = firePointPreciseDao.findAll(specificationPrecise, Sort.by(Sort.Direction.DESC, "satelliteTime")); + + //将两种数据来源的火点合并到一起 + List resultList = new ArrayList<>(); + for (FirePointOrdinaryEntity firePointOrdinaryEntity : firePointOrdinaryList) { + resultList.add(FirePointConvertUtils.convert(firePointOrdinaryEntity)); + } + for (FirePointPreciseEntity firePointPreciseEntity : firePointPreciseList) { + resultList.add(FirePointConvertUtils.convert(firePointPreciseEntity)); + } + //对合并后的结果进行排序 + List sortedResultList = resultList.stream().sorted(Comparator.comparing(AllFirePointVo::getSatelliteTime)).collect(Collectors.toList()); + return new FirePointQueryResultBean(true, "", sortedResultList); } }