From 5b02a11b0ebf7d93e79ebb7aee7b67c5461d369b Mon Sep 17 00:00:00 2001 From: XinYi Song <2037158277@qq.com> Date: Wed, 1 Dec 2021 14:13:05 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E4=BA=86=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=B3=A8=E5=86=8C=E5=8A=9F=E8=83=BD=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=202=E3=80=81=E4=BF=AE=E6=94=B9=E7=81=AB=E7=82=B9=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=E4=BF=AE=E6=94=B9=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=9F=A5=E8=AF=A2=E4=B8=80=E4=B8=AA=E6=9C=88=E7=81=AB?= =?UTF-8?q?=E7=82=B9=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/common/config/WebSecurityConfig.java | 1 + .../xkrs/controller/FirePointController.java | 8 +++ src/main/java/com/xkrs/dao/CityDao.java | 2 +- src/main/java/com/xkrs/dao/CountyDao.java | 2 + src/main/java/com/xkrs/dao/FirePointDao.java | 7 +++ .../service/impl/FirePointServiceImpl.java | 36 +++++++++++-- .../xkrs/service/impl/SysUserServiceImpl.java | 4 +- .../java/com/xkrs/utils/DateTimeUtil.java | 7 ++- src/main/java/com/xkrs/utils/Query.java | 53 ++++++++++++++----- src/main/resources/application.properties | 2 +- 10 files changed, 99 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index ef534a9..6e796dd 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -60,6 +60,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.POST,"/insertFireTest").permitAll() .antMatchers(HttpMethod.POST,"/importCityExcel").permitAll() .antMatchers(HttpMethod.POST,"/deleteShuiTi").permitAll() + .antMatchers(HttpMethod.GET,"/selectBeijing").permitAll() // 所有其它请求需要身份认证 .anyRequest().authenticated() .and() diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index 5e52482..6c36af8 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -339,4 +339,12 @@ public class FirePointController { firePointDao.deleteByIdIn(integers); return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"删除成功",locale); } + + @GetMapping("/selectBeijing") + public String selectBeijing(){ + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + List firePointEntities = firePointDao.selectBeijing(); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,firePointEntities,locale); + } } diff --git a/src/main/java/com/xkrs/dao/CityDao.java b/src/main/java/com/xkrs/dao/CityDao.java index 8ef9c71..eb45830 100644 --- a/src/main/java/com/xkrs/dao/CityDao.java +++ b/src/main/java/com/xkrs/dao/CityDao.java @@ -36,7 +36,7 @@ public interface CityDao extends JpaRepository, JpaSpecificatio * @param cityCode * @return */ - List findByCityCode(String cityCode); + CityEntity findByCityCode(String cityCode); /** * 根据省编码查询信息 diff --git a/src/main/java/com/xkrs/dao/CountyDao.java b/src/main/java/com/xkrs/dao/CountyDao.java index 5c79431..00bf312 100644 --- a/src/main/java/com/xkrs/dao/CountyDao.java +++ b/src/main/java/com/xkrs/dao/CountyDao.java @@ -28,6 +28,8 @@ public interface CountyDao extends JpaRepository { */ List findByCityCode(String cityCode); + List findByCityName(String cityName); + /** * 根据countyCode查询信息 * @param countyCode diff --git a/src/main/java/com/xkrs/dao/FirePointDao.java b/src/main/java/com/xkrs/dao/FirePointDao.java index e733b8f..9380214 100644 --- a/src/main/java/com/xkrs/dao/FirePointDao.java +++ b/src/main/java/com/xkrs/dao/FirePointDao.java @@ -85,4 +85,11 @@ public interface FirePointDao extends JpaRepository, JpaSp */ @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) + List selectBeijing(); } diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 5bccfe4..118e453 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -11,6 +11,9 @@ import com.xkrs.service.FirePointService; import com.xkrs.utils.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; import org.springframework.cglib.beans.BeanCopier; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; @@ -29,6 +32,7 @@ import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulat /** * @author XinYi Song */ +@CacheConfig(cacheNames = "FirePointServiceCache") @Service public class FirePointServiceImpl implements FirePointService { @@ -75,11 +79,16 @@ public class FirePointServiceImpl implements FirePointService { * @param firePointQo * @return */ + @CacheEvict(value = "FirePointServiceCache",allEntries = true) @Override public FirePointEntity insertFirePoint(FirePointQo firePointQo) { FirePointEntity firePointEntity = new FirePointEntity(); if(firePointQo.getLandtype().equals("水体")){ return null; + }else if("Himawari 8".equals(firePointQo.getSatelliteType()) && "L".equals(firePointQo.getConfidence())){ + return null; + }else if("Himawari 8".equals(firePointQo.getSatelliteType()) && "N".equals(firePointQo.getConfidence())){ + return null; }else { firePointEntity.setFireCode(firePointQo.getFireCode()); firePointEntity.setCountyCode(firePointQo.getCountyCode().toString()); @@ -121,6 +130,7 @@ public class FirePointServiceImpl implements FirePointService { * @param * @return */ + @Cacheable(keyGenerator = "keyGenerator", unless="#result == null") @Override public List selectTodayFirePoint(String countyCode) { String addTime = DateTimeUtil.dateToString(LocalDate.now()); @@ -146,11 +156,16 @@ public class FirePointServiceImpl implements FirePointService { * @param endTime * @return */ + @Cacheable(keyGenerator = "keyGenerator", unless="#result == null") @Override public List selectFirePoint(String proCode,String cityCode, String satelliteType, String landType, String startTime, String endTime) { List byProCode = cityDao.findByProCode(proCode); String proName = byProCode.get(0).getProName(); - return query.selectFirePointByPro(proName,cityCode, satelliteType, landType, startTime, endTime); + LocalDate localDate = DateTimeUtil.stringToDate(endTime); + // 结束时间 + LocalDate localDate1 = localDate.plusDays(1); + String dateToString = DateTimeUtil.dateToString(localDate1); + return query.selectFirePointByPro(proName,cityCode, satelliteType, landType, startTime, dateToString); } /** @@ -163,12 +178,17 @@ public class FirePointServiceImpl implements FirePointService { * @param endTime * @return */ + @Cacheable(keyGenerator = "keyGenerator", unless="#result == null") @Override public List selectFirePointByCity(String cityCodeOne, String cityCode, String satelliteType, String landType, String startTime, String endTime) { //List byCityCode = cityDao.findByCityCode(cityCodeOne.substring(0,3)); List byCityCode = countyDao.findByCityCode(cityCodeOne); String cityName = byCityCode.get(0).getCityName(); - return query.selectFirePointByCity(cityName,cityCode,satelliteType,landType,startTime,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); } /** @@ -180,9 +200,14 @@ public class FirePointServiceImpl implements FirePointService { * @param endTime * @return */ + @Cacheable(keyGenerator = "keyGenerator", unless="#result == null") @Override public List selectFirePointByCounty(String cityCode, String satelliteType, String landType, String startTime, String endTime) { - return query.selectFirePointByCounty(cityCode,satelliteType,landType,startTime,endTime); + LocalDate localDate = DateTimeUtil.stringToDate(endTime); + // 结束时间 + LocalDate localDate1 = localDate.plusDays(1); + String dateToString = DateTimeUtil.dateToString(localDate1); + return query.selectFirePointByCounty(cityCode,satelliteType,landType,startTime,dateToString); } /** @@ -305,6 +330,7 @@ public class FirePointServiceImpl implements FirePointService { * 查询近一周的火点信息 * @return */ + @Cacheable(keyGenerator = "keyGenerator", unless="#result == null") @Override public List selectFirePointBetweenSeven() { LocalDateTime localDateTime = LocalDateTime.now(); @@ -320,6 +346,7 @@ public class FirePointServiceImpl implements FirePointService { * 查询近一个月的火点信息 * @return */ + @Cacheable(keyGenerator = "keyGenerator", unless="#result == null") @Override public List selectFirePointByMonth(String countyCode) { LocalDateTime localDateTime = LocalDateTime.now(); @@ -345,6 +372,7 @@ public class FirePointServiceImpl implements FirePointService { * 查询近一个月的火点数量 * @return */ + @Cacheable(keyGenerator = "keyGenerator", unless="#result == null") @Override public String selectFirePointNumMonth() { // 获取区域信息 @@ -370,6 +398,7 @@ public class FirePointServiceImpl implements FirePointService { * 查询近一天的火点数量 * @return */ + @Cacheable(keyGenerator = "keyGenerator", unless="#result == null") @Override public String selectFirePointNumDay() { // 获取区域信息 @@ -395,6 +424,7 @@ public class FirePointServiceImpl implements FirePointService { * 查询近一周的火点数量 * @return */ + @Cacheable(keyGenerator = "keyGenerator", unless="#result == null") @Override public String selectFirePointNumWeek() { // 获取区域信息 diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index c06d97a..30d51f2 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -112,11 +112,11 @@ public class SysUserServiceImpl implements SysUserService { sysUserEntity.setActiveFlag(1); sysUserEntity.setAccountType("省级"); }else if("00".equals(sysUserQo.getCountyCode().substring(4)) && !"0000".equals(sysUserQo.getCountyCode().substring(2))){ - List byCityCode = cityDao.findByCityCode(sysUserQo.getCountyCode()); + List byCityCode = countyDao.findByCityCode(sysUserQo.getCountyCode()); if(byCityCode == null || byCityCode.size() == 0){ return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"市编码不存在!",locale); } - List byCityName = cityDao.findByCityName(sysUserQo.getCountyName()); + List byCityName = countyDao.findByCityName(sysUserQo.getCountyName()); if(byCityName == null || byCityName.size() == 0){ return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"您所选择的区域不存在!",locale); } diff --git a/src/main/java/com/xkrs/utils/DateTimeUtil.java b/src/main/java/com/xkrs/utils/DateTimeUtil.java index 0d9b64f..48851c4 100644 --- a/src/main/java/com/xkrs/utils/DateTimeUtil.java +++ b/src/main/java/com/xkrs/utils/DateTimeUtil.java @@ -218,8 +218,11 @@ public class DateTimeUtil { } public static void main(String[] args) { - long l = dateToTimeMillis(LocalDateTime.now()); - System.out.println("------"+l); + LocalDate now = LocalDate.now(); + LocalDate localDate = now.plusDays(1); + String s = dateToString(localDate); + LocalDate localDate1 = stringToDate(s); + System.out.println(localDate1); } } diff --git a/src/main/java/com/xkrs/utils/Query.java b/src/main/java/com/xkrs/utils/Query.java index a24772a..f0fd499 100644 --- a/src/main/java/com/xkrs/utils/Query.java +++ b/src/main/java/com/xkrs/utils/Query.java @@ -10,6 +10,7 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -46,11 +47,19 @@ public class Query { list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType)); } if(startTime != null && !"".equals(startTime)){ - list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(String.class), 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("addTime").as(String.class), 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)); } @@ -81,11 +90,19 @@ public class Query { list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType)); } if(startTime != null && !"".equals(startTime)){ - list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(String.class), 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("addTime").as(String.class), 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)); } @@ -113,11 +130,19 @@ public class Query { list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType)); } if(startTime != null && !"".equals(startTime)){ - list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(String.class), 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("addTime").as(String.class), 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)); } @@ -137,10 +162,10 @@ public class Query { 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)); + list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime)); } if(endTime != null && !"".equals(endTime)){ - list.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(String.class), endTime)); + list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime)); } Predicate[] predicates = new Predicate[list.size()]; return criteriaBuilder.and(list.toArray(predicates)); @@ -164,10 +189,10 @@ public class Query { list.add(criteriaBuilder.like(root.get("firePointAddress").as(String.class), "%" + address + "%")); } if(startTime != null && !"".equals(startTime)){ - list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(String.class), startTime)); + list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime)); } if(endTime != null && !"".equals(endTime)){ - list.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(String.class), endTime)); + list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime)); } Predicate[] predicates = new Predicate[list.size()]; return criteriaBuilder.and(list.toArray(predicates)); @@ -192,10 +217,10 @@ public class Query { list.add(criteriaBuilder.like(root.get("firePointAddress").as(String.class), "%" + address + "%")); } if(startTime != null && !"".equals(startTime)){ - list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(String.class), startTime)); + list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime)); } if(endTime != null && !"".equals(endTime)){ - list.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(String.class), endTime)); + list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime)); } Predicate[] predicates = new Predicate[list.size()]; return criteriaBuilder.and(list.toArray(predicates)); @@ -220,10 +245,10 @@ public class Query { list.add(criteriaBuilder.like(root.get("countyCode").as(String.class), countyCode)); } if(startTime != null && !"".equals(startTime)){ - list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(String.class), startTime)); + list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime)); } if(endTime != null && !"".equals(endTime)){ - list.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(String.class), endTime)); + list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime)); } 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 385b415..dc4dca0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -35,7 +35,7 @@ spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false ## Redis配置 spring.cache.type = redis -spring.redis.database = 8 +spring.redis.database = 12 spring.redis.host = localhost spring.redis.port = 6379 spring.redis.password=sdust2020