From 4dc916fd881a739cc2ce2cebe76c2f990726eed8 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Sat, 7 May 2022 16:36:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=A4=9A=E6=9D=A1=E4=BB=B6=E6=9F=A5=E8=AF=A2=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 | 6 +- src/main/java/com/xkrs/dao/FirePointDao.java | 71 ++++++++++++------- .../com/xkrs/service/FirePointService.java | 13 ++++ .../service/impl/FirePointServiceImpl.java | 18 +++-- src/main/java/com/xkrs/utils/Query.java | 56 +++++++++++++++ 5 files changed, 130 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index 05daa35..71ecbfa 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -122,10 +122,8 @@ public class FirePointController { // 验证token String tokenUserName = TokenUtil.getTokenUserName(token); SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName); - // 查询省 - if (9 == sysUserEntity.getCountyCode().length()) { - // 查询县 - List firePointEntities = firePointService.selectFirePointByCounty(sysUserEntity.getCountyCode(), satelliteType, landType, startTime, endTime); + if (9 == sysUserEntity.getCountyCode().length()) {// 查询县 + List firePointEntities = firePointService.selectFirePointByStreet(sysUserEntity.getCountyCode(), satelliteType, landType, startTime, endTime); if (firePointEntities == null || firePointEntities.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有火点数据", locale); } diff --git a/src/main/java/com/xkrs/dao/FirePointDao.java b/src/main/java/com/xkrs/dao/FirePointDao.java index 821c11e..c0b9e3d 100644 --- a/src/main/java/com/xkrs/dao/FirePointDao.java +++ b/src/main/java/com/xkrs/dao/FirePointDao.java @@ -14,46 +14,62 @@ import java.util.Map; * @author XinYi Song */ @Component -public interface FirePointDao extends JpaRepository, JpaSpecificationExecutor { +public interface FirePointDao extends JpaRepository, JpaSpecificationExecutor { /** * 查询今天的火点信息 + * * @param addTime * @param address * @return */ - @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and fire_point_address like CONCAT('%',:address,'%')",nativeQuery = true) - List selectTodayFirePoint(String addTime,String address); + @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and fire_point_address like CONCAT('%',:address,'%')", nativeQuery = true) + List selectTodayFirePoint(String addTime, String address); /** - *查询山东省今天火点信息 + * 查询山东省今天火点信息 + * * @param addTime * @param address * @return */ - @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and fire_point_address like CONCAT('%',:address,'%') and land_type != '耕地'",nativeQuery = true) - List selectTodayFirePointShandong(String addTime,String address); + @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and fire_point_address like CONCAT('%',:address,'%') and land_type != '耕地'", nativeQuery = true) + List selectTodayFirePointShandong(String addTime, String address); /** * 区县条件查询今天火点信息 + * * @param addTime * @param countyCode * @return */ - @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and county_code = :countyCode",nativeQuery = true) - List selectTodayFirePointOne(String addTime,String countyCode); + @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and county_code = :countyCode", nativeQuery = true) + List selectTodayFirePointOne(String addTime, String countyCode); + + /** + * 街道条件查询今天火点信息 + * + * @param addTime + * @param streetCode + * @return + */ + @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and street_code = :streetCode", nativeQuery = true) + List selectTodayFirePointOneStreet(String addTime, String streetCode); + /** * 查询山东省县的今天火点信息 + * * @param addTime * @param countyCode * @return */ - @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and county_code = :countyCode and land_type != '耕地'",nativeQuery = true) - List selectTodayFirePointOneShandong(String addTime,String countyCode); + @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and county_code = :countyCode and land_type != '耕地'", nativeQuery = true) + List selectTodayFirePointOneShandong(String addTime, String countyCode); /** * 根据火点编码查询火点信息 + * * @param fireCode * @return */ @@ -61,63 +77,66 @@ public interface FirePointDao extends JpaRepository, JpaSp /** * 根据火点编码修改火点状态 + * * @param fireCode * @param fireType */ - @Modifying(clearAutomatically=true) - @Query(value = "update fire_point set fire_type = ?2 where fire_code = ?1",nativeQuery = true) - void updateFireTypeByFireCode(String fireCode,String fireType); + @Modifying(clearAutomatically = true) + @Query(value = "update fire_point set fire_type = ?2 where fire_code = ?1", nativeQuery = true) + void updateFireTypeByFireCode(String fireCode, String fireType); /** * 查询时间段内各植被类型的火点数量 + * * @param startTime * @param endTime * @return */ - @Query(value = "select la.land_name landname,count(fp.id) as num from land la left join fire_point fp " + - "on fp.land_type = la.land_name AND fp.add_time BETWEEN ?1 AND ?2 " + - "group by la.land_name",nativeQuery = true) - List> selectNumByLandType(String startTime,String endTime); + @Query(value = "select la.land_name landname,count(fp.id) as num from land la left join fire_point fp " + "on fp.land_type = la.land_name AND fp.add_time BETWEEN ?1 AND ?2 " + "group by la.land_name", nativeQuery = true) + List> selectNumByLandType(String startTime, String endTime); /** * 查询时间段内各地区的火点数量 + * * @param startTime * @param endTime * @return */ - @Query(value = "select ci.city_name cityname,count(fp.id) from city ci left join fire_point fp " + - "on fp.county_code like concat('%',ci.city_code,'%') AND fp.add_time BETWEEN ?1 AND ?2 " + - "group by ci.city_name",nativeQuery = true) - List> selectNumByArea(String startTime,String endTime); + @Query(value = "select ci.city_name cityname,count(fp.id) from city ci left join fire_point fp " + "on fp.county_code like concat('%',ci.city_code,'%') AND fp.add_time BETWEEN ?1 AND ?2 " + "group by ci.city_name", nativeQuery = true) + List> selectNumByArea(String startTime, String endTime); /** * 查询水体类型的id + * * @return */ - @Query(value = "select id from fire_point where land_type = '水体'",nativeQuery = true) + @Query(value = "select id from fire_point where land_type = '水体'", nativeQuery = true) List selectId(); /** * 批量删除水体 + * * @param id */ - @Modifying(clearAutomatically=true) + @Modifying(clearAutomatically = true) void deleteByIdIn(List id); /** * 查询北京的火点 + * * @return */ - @Query(value = "select * from fire_point fp where fp.fire_point_address like concat('%','北京市','%') and fp.add_time BETWEEN '2021-10-19' AND '2021-11-20'",nativeQuery = true) + @Query(value = "select * from fire_point fp where fp.fire_point_address like concat('%','北京市','%') and fp.add_time BETWEEN '2021-10-19' AND '2021-11-20'", nativeQuery = true) List selectBeijing(); /** * 根据火点编码,修改火点前后图片路径 + * * @param fireCode * @param beforeFireImage * @param afterFireImage */ - @Modifying(clearAutomatically=true) - @Query(value = "update fire_point set before_fire_image = ?2,after_fire_image = ?3 where fire_code = ?1",nativeQuery = true) + @Modifying(clearAutomatically = true) + @Query(value = "update fire_point set before_fire_image = ?2,after_fire_image = ?3 where fire_code = ?1", nativeQuery = true) void updateBeforeFireAndAfterFireImage(String fireCode, String beforeFireImage, String afterFireImage); } diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index b6cc12c..a049381 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -70,6 +70,19 @@ public interface FirePointService { */ List selectFirePointByCounty(String cityCode, String satelliteType, String landType, String startTime, String endTime); + /** + * 动态多条件查询火点信息(街道) + * + * @param streetCode + * @param satelliteType + * @param landType + * @param startTime + * @param endTime + * @return + */ + List selectFirePointByStreet(String streetCode, String satelliteType, String landType, String startTime, String endTime); + + /** * 根据火点编码修改火点的状态(预警) * diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 0e1af9f..dc4df7c 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -155,9 +155,7 @@ public class FirePointServiceImpl implements FirePointService { public List selectTodayFirePoint(String countyCode) { String addTime = DateTimeUtil.dateToString(LocalDate.now()); if (9 == countyCode.length()) { - List byStreetCode = streetDao.findByStreetCode(countyCode); - String streetName = byStreetCode.get(0).getStreetName(); - return firePointDao.selectTodayFirePoint(addTime, streetName); + return firePointDao.selectTodayFirePointOneStreet(addTime, countyCode); } else if ("0000".equals(countyCode.substring(2))) { List byProCode = cityDao.findByProCode(countyCode); String proName = byProCode.get(0).getProName(); @@ -245,6 +243,18 @@ public class FirePointServiceImpl implements FirePointService { return query.selectFirePointByCounty(cityCode, satelliteType, landType, startTime, endTime); } + @Override + public List selectFirePointByStreet(String streetCode, String satelliteType, String landType, String startTime, String endTime) { + if (!"".equals(startTime) && !"".equals(endTime)) { + LocalDate localDate = DateTimeUtil.stringToDate(endTime); + // 结束时间 + LocalDate localDate1 = localDate.plusDays(1); + String dateToString = DateTimeUtil.dateToString(localDate1); + return query.selectFirePointByStreet(streetCode, satelliteType, landType, startTime, dateToString); + } + return query.selectFirePointByStreet(streetCode, satelliteType, landType, startTime, endTime); + } + /** * 根据火点编码修改火点的状态(预警) * @@ -394,7 +404,7 @@ public class FirePointServiceImpl implements FirePointService { LocalDateTime localDateTime1 = localDateTime.minusDays(31); String startTime = DateTimeUtil.dateTimeToString(localDateTime1); if (9 == countyCode.length()) { - return query.selectFirePointByMonthCounty(countyCode, startTime, endTime); + return query.selectFirePointByMonthStreet(countyCode, startTime, endTime); } else if ("0000".equals(countyCode.substring(2))) { List byProCode = cityDao.findByProCode(countyCode); String proName = byProCode.get(0).getProName(); diff --git a/src/main/java/com/xkrs/utils/Query.java b/src/main/java/com/xkrs/utils/Query.java index 807167c..2ec56a5 100644 --- a/src/main/java/com/xkrs/utils/Query.java +++ b/src/main/java/com/xkrs/utils/Query.java @@ -132,6 +132,41 @@ public class Query { return firePointDao.findAll(specification); } + /** + * 动态多条件查询项目信息(街道) + */ + public List selectFirePointByStreet(String streetCode, String satelliteType, String landType, String startTime, String endTime) { + Specification specification = (root, criteriaQuery, criteriaBuilder) -> { + List list = new ArrayList<>(); + if (streetCode != null && !"".equals(streetCode)) { + list.add(criteriaBuilder.equal(root.get("streetCode").as(String.class), streetCode)); + } + if (satelliteType != null && !"".equals(satelliteType)) { + list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType)); + } + if (landType != null && !"".equals(landType)) { + list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType)); + } + if (startTime != null && !"".equals(startTime)) { + list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime)); + } + LocalDateTime localDateTime = LocalDateTime.now(); + LocalDateTime localDateTime2 = localDateTime.plusDays(1); + String endTimes = DateTimeUtil.dateTimeToString(localDateTime2); + // 当前时间减30 + LocalDateTime localDateTime1 = localDateTime.minusDays(30); + String startTimes = DateTimeUtil.dateTimeToString(localDateTime1); + list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTimes)); + if (endTime != null && !"".equals(endTime)) { + list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime)); + } + list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTimes)); + Predicate[] predicates = new Predicate[list.size()]; + return criteriaBuilder.and(list.toArray(predicates)); + }; + return firePointDao.findAll(specification); + } + /** * 查询近一周的火点 */ @@ -213,5 +248,26 @@ public class Query { return firePointDao.findAll(specification); } + /** + * 查询近一个月的火点信息(街道) + */ + public List selectFirePointByMonthStreet(String streetCode, String startTime, String endTime) { + Specification specification = (root, criteriaQuery, criteriaBuilder) -> { + List list = new ArrayList<>(); + if (streetCode != null && !"".equals(streetCode)) { + list.add(criteriaBuilder.like(root.get("streetCode").as(String.class), streetCode)); + } + if (startTime != null && !"".equals(startTime)) { + list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime)); + } + if (endTime != null && !"".equals(endTime)) { + list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").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