From d1ec3daef7433ec7051618b1a80f9fb574175e48 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 2 Mar 2023 15:36:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../straw/utils/FirePointQueryManager.java | 245 ++++++++++-------- 1 file changed, 131 insertions(+), 114 deletions(-) diff --git a/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java b/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java index 44228fb..f3e6b04 100644 --- a/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java +++ b/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java @@ -6,6 +6,7 @@ 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; @@ -36,9 +37,11 @@ public class FirePointQueryManager { @Resource private FirePointPreciseDao firePointPreciseDao; -// 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 countyCode = sysUserEntity.getCountyCode(); + String vipTimeRangeJson = sysUserEntity.getVipTimeRangeJson(); + return queryFirePointBelongToUser(countyCode, vipTimeRangeJson, startTime, endTime, satelliteType, landType); + } public FirePointQueryResultBean queryFirePointBelongToUser(String userCode, String vipTimeRangeJson, String startTime, String endTime, String satelliteType, String landType) { @@ -110,6 +113,131 @@ public class FirePointQueryManager { return new FirePointQueryResultBean(e.getMessage()); } + return queryFirePointBelongToUser(mNoRedundantUserCode, mVipTimeRangeItemList, startTime, endTime, satelliteType, landType); + } + + public FirePointQueryResultBean queryFirePointBelongToUser(String noRedundantUserCode, List vipTimeRangeItemList, String startTime, String endTime, String satelliteType, String landType) { + + //如果格式化后的用户区划编码是空,就返回失败 + if (TextUtils.isEmpty(noRedundantUserCode)) { + return new FirePointQueryResultBean("User CountyCode Error 2, noRedundantUserCode = " + noRedundantUserCode); + } + //VIP时间范围发生了异常,返回失败 + if (vipTimeRangeItemList == null || vipTimeRangeItemList.size() == 0) { + return new FirePointQueryResultBean("User VipTimeRangeJson Error 2, 已保存的VIP时间范围出现错误"); + } + + final String finalMNoRedundantUserCode = noRedundantUserCode; + //查询未审核的普通火点 + Specification specificationOrdinary = (root, criteriaQuery, criteriaBuilder) -> { + List predicateList = new ArrayList<>(); + //添加区划编码的过滤 + predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); + //开始时间查询条件 + if (!TextUtils.isEmpty(startTime)) { + LocalDateTime startTime1 = DateTimeUtils.stringToLocalDateTime(startTime); + LocalDateTime startTime2 = LocalDateTime.of(startTime1.getYear(), startTime1.getMonth(), startTime1.getDayOfMonth(), 0, 0, 0, 0); + String startTimeString = DateTimeUtils.localDateTimeToString(startTime2); + predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTimeString)); + } + //结束时间查询条件 + if (!TextUtils.isEmpty(endTime)) { + LocalDateTime endTime1 = DateTimeUtils.stringToLocalDateTime(endTime).plusDays(1); + LocalDateTime endTime2 = LocalDateTime.of(endTime1.getYear(), endTime1.getMonth(), endTime1.getDayOfMonth(), 0, 0, 0, 0); + String endTimeString = DateTimeUtils.localDateTimeToString(endTime2); + predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTimeString)); + } + //卫星类型查询条件 + if (!TextUtils.isEmpty(satelliteType)) { + predicateList.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType)); + } + //地物类型查询条件 + if (!TextUtils.isEmpty(landType)) { + predicateList.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType)); + } + for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : vipTimeRangeItemList) { + 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")); + + + //查询审核通过的精准火点 + Specification specificationPrecise = (root, criteriaQuery, criteriaBuilder) -> { + List predicateList = new ArrayList<>(); + //添加区划编码的过滤 + predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); + //开始时间查询条件 + if (!TextUtils.isEmpty(startTime)) { + LocalDateTime startTime1 = DateTimeUtils.stringToLocalDateTime(startTime); + LocalDateTime startTime2 = LocalDateTime.of(startTime1.getYear(), startTime1.getMonth(), startTime1.getDayOfMonth(), 0, 0, 0, 0); + String startTimeString = DateTimeUtils.localDateTimeToString(startTime2); + predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTimeString)); + } + //结束时间查询条件 + if (!TextUtils.isEmpty(endTime)) { + LocalDateTime endTime1 = DateTimeUtils.stringToLocalDateTime(endTime).plusDays(1); + LocalDateTime endTime2 = LocalDateTime.of(endTime1.getYear(), endTime1.getMonth(), endTime1.getDayOfMonth(), 0, 0, 0, 0); + String endTimeString = DateTimeUtils.localDateTimeToString(endTime2); + predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTimeString)); + } + //卫星类型查询条件 + if (!TextUtils.isEmpty(satelliteType)) { + predicateList.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType)); + } + //地物类型查询条件 + if (!TextUtils.isEmpty(landType)) { + predicateList.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType)); + } + List subPredicateList = new ArrayList<>(); + for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : vipTimeRangeItemList) { + 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); + subPredicateList.add(criteriaBuilder.and(beforeStartTimePredicate, afterEndTimePredicate)); + } + if (subPredicateList.size() == 0) { + } else if (subPredicateList.size() == 1) { + predicateList.add(subPredicateList.get(0)); + } else { + Predicate orPredicate = null; + for (int i = 1; i < subPredicateList.size(); i++) { + if (i == 1) { + orPredicate = criteriaBuilder.or(subPredicateList.get(0), subPredicateList.get(1)); + } else { + orPredicate = criteriaBuilder.or(orPredicate, subPredicateList.get(i)); + } + } + predicateList.add(orPredicate); + } + 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, sortedResultList.size()); + // { // final String commonSql = "SELECT t.id AS id, t.fire_code AS fireCode, t.county_code AS countyCode, t.county_name AS countyName, t.satellite_time AS satelliteTime, t.longitude AS longitude, t.latitude AS latitude, t.satellite_type AS satelliteType, t.land_type AS landType, t.confidence AS confidence, t.fire_image AS fireImage, t.satellite_image AS satelliteImage, t.town_code AS townCode, t.town_name AS townName, t.add_time AS addTime, t.fire_point_address AS firePointAddress, t.remark AS remark"; // @@ -163,117 +291,6 @@ public class FirePointQueryManager { // return new FirePointQueryResultBean(true, "", resultList); // // } - - final String finalMNoRedundantUserCode = mNoRedundantUserCode; - //查询未审核的普通火点 - Specification specificationOrdinary = (root, criteriaQuery, criteriaBuilder) -> { - List predicateList = new ArrayList<>(); - //添加区划编码的过滤 - predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); - //开始时间查询条件 - if (!TextUtils.isEmpty(startTime)) { - LocalDateTime startTime1 = DateTimeUtils.stringToLocalDateTime(startTime); - LocalDateTime startTime2 = LocalDateTime.of(startTime1.getYear(), startTime1.getMonth(), startTime1.getDayOfMonth(), 0, 0, 0, 0); - String startTimeString = DateTimeUtils.localDateTimeToString(startTime2); - predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTimeString)); - } - //结束时间查询条件 - if (!TextUtils.isEmpty(endTime)) { - LocalDateTime endTime1 = DateTimeUtils.stringToLocalDateTime(endTime).plusDays(1); - LocalDateTime endTime2 = LocalDateTime.of(endTime1.getYear(), endTime1.getMonth(), endTime1.getDayOfMonth(), 0, 0, 0, 0); - String endTimeString = DateTimeUtils.localDateTimeToString(endTime2); - predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTimeString)); - } - //卫星类型查询条件 - if (!TextUtils.isEmpty(satelliteType)) { - predicateList.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType)); - } - //地物类型查询条件 - if (!TextUtils.isEmpty(landType)) { - predicateList.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType)); - } - 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")); - - - //查询审核通过的精准火点 - Specification specificationPrecise = (root, criteriaQuery, criteriaBuilder) -> { - List predicateList = new ArrayList<>(); - //添加区划编码的过滤 - predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); - //开始时间查询条件 - if (!TextUtils.isEmpty(startTime)) { - LocalDateTime startTime1 = DateTimeUtils.stringToLocalDateTime(startTime); - LocalDateTime startTime2 = LocalDateTime.of(startTime1.getYear(), startTime1.getMonth(), startTime1.getDayOfMonth(), 0, 0, 0, 0); - String startTimeString = DateTimeUtils.localDateTimeToString(startTime2); - predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTimeString)); - } - //结束时间查询条件 - if (!TextUtils.isEmpty(endTime)) { - LocalDateTime endTime1 = DateTimeUtils.stringToLocalDateTime(endTime).plusDays(1); - LocalDateTime endTime2 = LocalDateTime.of(endTime1.getYear(), endTime1.getMonth(), endTime1.getDayOfMonth(), 0, 0, 0, 0); - String endTimeString = DateTimeUtils.localDateTimeToString(endTime2); - predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTimeString)); - } - //卫星类型查询条件 - if (!TextUtils.isEmpty(satelliteType)) { - predicateList.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType)); - } - //地物类型查询条件 - if (!TextUtils.isEmpty(landType)) { - predicateList.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType)); - } - List subPredicateList = new ArrayList<>(); - 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); - subPredicateList.add(criteriaBuilder.and(beforeStartTimePredicate, afterEndTimePredicate)); - } - if (subPredicateList.size() == 0) { - } else if (subPredicateList.size() == 1) { - predicateList.add(subPredicateList.get(0)); - } else { - Predicate orPredicate = null; - for (int i = 1; i < subPredicateList.size(); i++) { - if (i == 1) { - orPredicate = criteriaBuilder.or(subPredicateList.get(0), subPredicateList.get(1)); - } else { - orPredicate = criteriaBuilder.or(orPredicate, subPredicateList.get(i)); - } - } - predicateList.add(orPredicate); - } - 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, sortedResultList.size()); } }