From 3e8dd2e22b48744d044df2264e0e1512e93504a4 Mon Sep 17 00:00:00 2001 From: "DESKTOP-4U0TDEF\\20371" <2037158277@qq.com> Date: Mon, 19 Jul 2021 10:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=BF=91=E4=B8=80=E4=B8=AA=E6=9C=88=E7=9A=84=E7=81=AB=E7=82=B9?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/FirePointController.java | 17 ++++++++++++- .../com/xkrs/service/FirePointService.java | 6 +++++ .../service/impl/FirePointServiceImpl.java | 14 +++++++++++ src/main/java/com/xkrs/utils/Query.java | 24 +++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index 49c7113..e76d05d 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -172,6 +172,21 @@ public class FirePointController { if(firePointEntities == null || firePointEntities.size() == 0){ return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有火点数据",locale); } - return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,firePointEntities,locale); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,firePointEntities,locale); + } + + /** + * 查询近一个月的火点信息 + * @return + */ + @GetMapping("/selectFirePointByMonth") + public String selectFirePointByMonth() { + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + List firePointEntities = firePointService.selectFirePointByMonth(); + if(firePointEntities == null || firePointEntities.size() == 0){ + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有火点数据",locale); + } + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,firePointEntities,locale); } } diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index f990db2..afb875f 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -71,4 +71,10 @@ public interface FirePointService { * @return */ List selectFirePointBetweenSeven(); + + /** + * 查询近一个月的火点信息 + * @return + */ + List selectFirePointByMonth(); } diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 7ea556a..823e999 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -238,4 +238,18 @@ public class FirePointServiceImpl implements FirePointService { String startTime = DateTimeUtil.dateTimeToString(localDateTime1); return query.selectFirePointBetweenThree(startTime, endTime); } + + /** + * 查询近一个月的火点信息 + * @return + */ + @Override + public List selectFirePointByMonth() { + LocalDateTime localDateTime = LocalDateTime.now(); + String endTime = DateTimeUtil.dateTimeToString(localDateTime); + // 当前时间减7 + LocalDateTime localDateTime1 = localDateTime.minusDays(30); + String startTime = DateTimeUtil.dateTimeToString(localDateTime1); + return query.selectFirePointByMonth(startTime,endTime); + } } diff --git a/src/main/java/com/xkrs/utils/Query.java b/src/main/java/com/xkrs/utils/Query.java index ec382e7..486b26b 100644 --- a/src/main/java/com/xkrs/utils/Query.java +++ b/src/main/java/com/xkrs/utils/Query.java @@ -80,5 +80,29 @@ public class Query { return firePointDao.findAll(specification); } + /** + * 查询近一个月的火点 + * @param startTime + * @param endTime + * @return + */ + public List selectFirePointByMonth(String startTime,String endTime) { + Specification specification = new Specification() { + @Override + public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { + List list = new ArrayList<>(); + if(startTime != null && !"".equals(startTime)){ + list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(String.class), startTime)); + } + if(endTime != null && !"".equals(endTime)){ + list.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(String.class), endTime)); + } + Predicate[] predicates = new Predicate[list.size()]; + return criteriaBuilder.and(list.toArray(predicates)); + } + }; + return firePointDao.findAll(specification); + } + } \ No newline at end of file