From 6abeff14947b7d9f70866ee23db72da3b040616e Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Wed, 1 Mar 2023 16:58:46 +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/FirePointQueryManager.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java b/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java index 05f97cc..6d6c159 100644 --- a/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java +++ b/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java @@ -191,6 +191,8 @@ public class FirePointQueryManager { List predicateList = new ArrayList<>(); //添加区划编码的过滤 predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); + + List subPredicateList = new ArrayList<>(); for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : mVipTimeRangeItemList) { String userStartTime = vipTimeRangeItem.getStartTime(); String userEndTime = vipTimeRangeItem.getEndTime(); @@ -198,7 +200,21 @@ public class FirePointQueryManager { 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)); + 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()])); };