From b8d8dee1b1c16065321a10a02a510bed22173780 Mon Sep 17 00:00:00 2001 From: XinYi Song <2037158277@qq.com> Date: Tue, 7 Dec 2021 08:32:55 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E4=BA=86=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E5=A4=9A=E6=9D=A1=E4=BB=B6=E6=9F=A5=E8=AF=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=A8=A1=E5=9D=97=EF=BC=8C=E5=BD=93=E5=B1=B1=E4=B8=9C?= =?UTF-8?q?=E7=9C=81=E6=9F=A5=E8=AF=A2=E6=97=B6=EF=BC=8C=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=B8=8D=E5=8C=85=E6=8B=AC=E8=80=95=E5=9C=B0=E7=9A=84=E7=81=AB?= =?UTF-8?q?=E7=82=B9=E4=BF=A1=E6=81=AF=E3=80=82=202=E3=80=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BA=86=E6=9F=A5=E8=AF=A2=E8=BF=91=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=9C=88=E7=81=AB=E7=82=B9=E4=BF=A1=E6=81=AF=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=A8=A1=E5=9D=97=E3=80=82=E5=BD=93=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=B1=B1=E4=B8=9C=E7=9C=81=E7=81=AB=E7=82=B9=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=9F=A5=E8=AF=A2=E4=B8=8D=E5=8C=85=E6=8B=AC?= =?UTF-8?q?=E8=80=95=E5=9C=B0=E7=B1=BB=E5=9E=8B=E7=9A=84=E7=81=AB=E7=82=B9?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/xkrs/dao/CityDao.java | 9 ++++- src/main/java/com/xkrs/dao/FirePointDao.java | 18 +++++++++ .../service/impl/FirePointServiceImpl.java | 36 ++++++++++++++---- src/main/java/com/xkrs/utils/Query.java | 38 +++++++++++++++++-- src/main/resources/application.properties | 4 +- 5 files changed, 91 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/xkrs/dao/CityDao.java b/src/main/java/com/xkrs/dao/CityDao.java index eb45830..2be72e0 100644 --- a/src/main/java/com/xkrs/dao/CityDao.java +++ b/src/main/java/com/xkrs/dao/CityDao.java @@ -50,7 +50,7 @@ public interface CityDao extends JpaRepository, JpaSpecificatio * @param cityName * @return */ - List findByCityName(String cityName); + //List findByCityName(String cityName); /** * 根据省名称查询信息 @@ -58,4 +58,11 @@ public interface CityDao extends JpaRepository, JpaSpecificatio * @return */ List findByProName(String proName); + + /** + * 根据市名查询信息 + * @param cityName + * @return + */ + CityEntity findByCityName(String cityName); } diff --git a/src/main/java/com/xkrs/dao/FirePointDao.java b/src/main/java/com/xkrs/dao/FirePointDao.java index 9380214..88b321e 100644 --- a/src/main/java/com/xkrs/dao/FirePointDao.java +++ b/src/main/java/com/xkrs/dao/FirePointDao.java @@ -25,6 +25,15 @@ public interface FirePointDao extends JpaRepository, JpaSp @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); + /** * 区县条件查询今天火点信息 * @param addTime @@ -34,6 +43,15 @@ public interface FirePointDao extends JpaRepository, JpaSp @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 countyCode + * @return + */ + @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and county_code = :countyCode and and land_type != '耕地'",nativeQuery = true) + List selectTodayFirePointOneShandong(String addTime,String countyCode); + /** * 根据火点编码查询火点信息 * @param fireCode diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 08f5351..f5c4cd7 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -137,12 +137,24 @@ public class FirePointServiceImpl implements FirePointService { if("0000".equals(countyCode.substring(2))){ List byProCode = cityDao.findByProCode(countyCode); String proName = byProCode.get(0).getProName(); + if(proName.equals("山东省")){ + return firePointDao.selectTodayFirePointShandong(addTime,proName); + } return firePointDao.selectTodayFirePoint(addTime,proName); }else if("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))){ List byCityCode = countyDao.findByCityCode(countyCode); String cityName = byCityCode.get(0).getCityName(); + CityEntity byCityName = cityDao.findByCityName(cityName); + if(byCityName.getProName().equals("山东省")){ + return firePointDao.selectTodayFirePointShandong(addTime,cityName); + } return firePointDao.selectTodayFirePoint(addTime,cityName); }else { + CountyEntity byCountyCode = countyDao.findByCountyCode(countyCode); + CityEntity byCityName = cityDao.findByCityName(byCountyCode.getCityName()); + if(byCityName.getProName().equals("山东省")){ + return firePointDao.selectTodayFirePointOneShandong(addTime,countyCode); + } return firePointDao.selectTodayFirePointOne(addTime,countyCode); } } @@ -187,14 +199,16 @@ public class FirePointServiceImpl implements FirePointService { //List byCityCode = cityDao.findByCityCode(cityCodeOne.substring(0,3)); List byCityCode = countyDao.findByCityCode(cityCodeOne); String cityName = byCityCode.get(0).getCityName(); + CityEntity byCityCode1 = cityDao.findByCityName(cityName); + String proName = byCityCode1.getProName(); if(!"".equals(startTime) && !"".equals(endTime)){ LocalDate localDate = DateTimeUtil.stringToDate(endTime); // 结束时间 LocalDate localDate1 = localDate.plusDays(1); String dateToString = DateTimeUtil.dateToString(localDate1); - return query.selectFirePointByCity(cityName,cityCode,satelliteType,landType,startTime,dateToString); + return query.selectFirePointByCity(proName, cityName,cityCode,satelliteType,landType,startTime,dateToString); } - return query.selectFirePointByCity(cityName,cityCode,satelliteType,landType,startTime,endTime); + return query.selectFirePointByCity(proName, cityName,cityCode,satelliteType,landType,startTime,endTime); } /** @@ -210,14 +224,17 @@ public class FirePointServiceImpl implements FirePointService { @Override public List selectFirePointByCounty(String cityCode, String satelliteType, String landType, String startTime, String endTime) { + CountyEntity byCountyCode = countyDao.findByCountyCode(cityCode); + CityEntity byCityCode = cityDao.findByCityName(byCountyCode.getCityName()); + String proName = byCityCode.getProName(); if(!"".equals(startTime) && !"".equals(endTime)){ LocalDate localDate = DateTimeUtil.stringToDate(endTime); // 结束时间 LocalDate localDate1 = localDate.plusDays(1); String dateToString = DateTimeUtil.dateToString(localDate1); - return query.selectFirePointByCounty(cityCode,satelliteType,landType,startTime,dateToString); + return query.selectFirePointByCounty(proName, cityCode,satelliteType,landType,startTime,dateToString); } - return query.selectFirePointByCounty(cityCode,satelliteType,landType,startTime,endTime); + return query.selectFirePointByCounty(proName, cityCode,satelliteType,landType,startTime,endTime); } /** @@ -361,7 +378,7 @@ public class FirePointServiceImpl implements FirePointService { public List selectFirePointByMonth(String countyCode) { LocalDateTime localDateTime = LocalDateTime.now(); String endTime = DateTimeUtil.dateTimeToString(localDateTime); - // 当前时间减7 + // 当前时间减31 LocalDateTime localDateTime1 = localDateTime.minusDays(31); String startTime = DateTimeUtil.dateTimeToString(localDateTime1); if("0000".equals(countyCode.substring(2))){ @@ -371,9 +388,14 @@ public class FirePointServiceImpl implements FirePointService { }else if("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))){ List byCityCode = countyDao.findByCityCode(countyCode); String cityName = byCityCode.get(0).getCityName(); - return query.selectFirePointByMonthCity(cityName,startTime,endTime); + CityEntity byCityName = cityDao.findByCityName(cityName); + String proName = byCityName.getProName(); + return query.selectFirePointByMonthCity(proName, cityName,startTime,endTime); }else { - return query.selectFirePointByMonthCounty(countyCode,startTime,endTime); + CountyEntity byCountyCode = countyDao.findByCountyCode(countyCode); + CityEntity byCityName = cityDao.findByCityName(byCountyCode.getCityName()); + String proName = byCityName.getProName(); + return query.selectFirePointByMonthCounty(proName, countyCode,startTime,endTime); } } diff --git a/src/main/java/com/xkrs/utils/Query.java b/src/main/java/com/xkrs/utils/Query.java index f0fd499..6cc6203 100644 --- a/src/main/java/com/xkrs/utils/Query.java +++ b/src/main/java/com/xkrs/utils/Query.java @@ -44,7 +44,14 @@ public class Query { list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType)); } if (landType != null && !"".equals(landType)) { + if(address.equals("山东省")){ + list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地")); + } list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType)); + }else { + if(address.equals("山东省")){ + list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地")); + } } if(startTime != null && !"".equals(startTime)){ list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime)); @@ -72,7 +79,7 @@ public class Query { * @param * @return */ - public List selectFirePointByCity(String address, String cityCode,String satelliteType,String landType,String startTime,String endTime) { + public List selectFirePointByCity(String proName, String address, String cityCode,String satelliteType,String landType,String startTime,String endTime) { Specification specification = new Specification() { @Override public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { @@ -87,7 +94,14 @@ public class Query { list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType)); } if (landType != null && !"".equals(landType)) { + if(proName.equals("山东省")){ + list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地")); + } list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType)); + }else { + if(proName.equals("山东省")){ + list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地")); + } } if(startTime != null && !"".equals(startTime)){ list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime)); @@ -115,7 +129,7 @@ public class Query { * @param * @return */ - public List selectFirePointByCounty(String cityCode,String satelliteType,String landType,String startTime,String endTime) { + public List selectFirePointByCounty(String proName, String cityCode,String satelliteType,String landType,String startTime,String endTime) { Specification specification = new Specification() { @Override public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { @@ -127,7 +141,14 @@ public class Query { list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType)); } if (landType != null && !"".equals(landType)) { + if(proName.equals("山东省")){ + list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地")); + } list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType)); + }else { + if(proName.equals("山东省")){ + list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地")); + } } if(startTime != null && !"".equals(startTime)){ list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime)); @@ -194,6 +215,9 @@ public class Query { if(endTime != null && !"".equals(endTime)){ list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime)); } + if(address.equals("山东省")){ + list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地")); + } Predicate[] predicates = new Predicate[list.size()]; return criteriaBuilder.and(list.toArray(predicates)); } @@ -208,7 +232,7 @@ public class Query { * @param endTime * @return */ - public List selectFirePointByMonthCity(String address,String startTime,String endTime) { + public List selectFirePointByMonthCity(String proName, String address,String startTime,String endTime) { Specification specification = new Specification() { @Override public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { @@ -222,6 +246,9 @@ public class Query { if(endTime != null && !"".equals(endTime)){ list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime)); } + if(proName.equals("山东省")){ + list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地")); + } Predicate[] predicates = new Predicate[list.size()]; return criteriaBuilder.and(list.toArray(predicates)); } @@ -236,7 +263,7 @@ public class Query { * @param endTime * @return */ - public List selectFirePointByMonthCounty(String countyCode,String startTime,String endTime) { + public List selectFirePointByMonthCounty(String proName, String countyCode,String startTime,String endTime) { Specification specification = new Specification() { @Override public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { @@ -250,6 +277,9 @@ public class Query { if(endTime != null && !"".equals(endTime)){ list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime)); } + if(proName.equals("山东省")){ + list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地")); + } Predicate[] predicates = new Predicate[list.size()]; return criteriaBuilder.and(list.toArray(predicates)); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index dfb719f..0e4ceee 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -35,10 +35,10 @@ spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false ## Redis配置 12 spring.cache.type = redis -spring.redis.database = 8 +spring.redis.database = 12 spring.redis.host = localhost spring.redis.port = 6379 -#spring.redis.password=sdust2020 +spring.redis.password=sdust2020 spring.redis.timeout = 10000 spring.redis.lettuce.pool.max-active = 100 spring.redis.lettuce.pool.max-wait = 10000