From 31394ee9a21194980c46e1846d7fb2dea182f543 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G8BCEP0\\HP" <2037158277@qq.com> Date: Tue, 20 Jul 2021 15:07:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E6=97=B6=E9=97=B4=E6=AE=B5=E5=90=84=E5=9C=B0?= =?UTF-8?q?=E5=8C=BA=EF=BC=8C=E5=90=84=E6=A4=8D=E8=A2=AB=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=9A=84=E7=81=AB=E7=82=B9=E6=95=B0=E9=87=8F?= 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 | 17 ++++ src/main/java/com/xkrs/dao/FirePointDao.java | 23 ++++++ .../com/xkrs/service/FirePointService.java | 18 +++++ .../service/impl/FirePointServiceImpl.java | 77 +++++++++++++++++++ 5 files changed, 136 insertions(+) diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index d33756b..ef01d27 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -46,6 +46,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.POST,"/insertAppTask").permitAll() .antMatchers(HttpMethod.GET,"/selectAppTask").permitAll() .antMatchers(HttpMethod.GET,"/selectFirePointBetweenSeven").permitAll() + .antMatchers(HttpMethod.GET,"/selectFirePointNum").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 e76d05d..be79bc3 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -189,4 +189,21 @@ public class FirePointController { } return outputEncapsulationObject(PromptMessageEnum.SUCCESS,firePointEntities,locale); } + + /** + * 查询火点数量 + * @return + */ + @GetMapping("/selectFirePointNum") + public String selectFirePointNum(@RequestParam("keepType") String keepType){ + // keepType为1时,查询近一天的火点数量 + if("1".equals(keepType)){ + return firePointService.selectFirePointNumDay(); + // keepType为2时,查询近一周的火点数量 + }else if("2".equals(keepType)){ + return firePointService.selectFirePointNumWeek(); + }else { + return firePointService.selectFirePointNumMonth(); + } + } } diff --git a/src/main/java/com/xkrs/dao/FirePointDao.java b/src/main/java/com/xkrs/dao/FirePointDao.java index e57e5f2..9a11d81 100644 --- a/src/main/java/com/xkrs/dao/FirePointDao.java +++ b/src/main/java/com/xkrs/dao/FirePointDao.java @@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Component; import java.util.List; +import java.util.Map; /** * @author XinYi Song @@ -38,4 +39,26 @@ public interface FirePointDao extends JpaRepository, JpaSp @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); + + /** + * 查询时间段内各地区的火点数量 + * @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); } diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index afb875f..f2b8fe3 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -77,4 +77,22 @@ public interface FirePointService { * @return */ List selectFirePointByMonth(); + + /** + * 查询近一个月的火点数量 + * @return + */ + String selectFirePointNumMonth(); + + /** + * 查询近一天的火点数量 + * @return + */ + String selectFirePointNumDay(); + + /** + * 查询 + * @return + */ + String selectFirePointNumWeek(); } diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 823e999..f3bd168 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -21,8 +21,10 @@ import javax.transaction.Transactional; import java.io.IOException; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; @@ -252,4 +254,79 @@ public class FirePointServiceImpl implements FirePointService { String startTime = DateTimeUtil.dateTimeToString(localDateTime1); return query.selectFirePointByMonth(startTime,endTime); } + + /** + * 查询近一个月的火点数量 + * @return + */ + @Override + public String selectFirePointNumMonth() { + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + Map map = new HashMap(3); + LocalDateTime localDateTime = LocalDateTime.now(); + LocalDateTime localDateTime2 = localDateTime.plusDays(1); + String endTime = DateTimeUtil.dateTimeToString(localDateTime2); + // 当前时间减30 + LocalDateTime localDateTime1 = localDateTime.minusDays(30); + String startTime = DateTimeUtil.dateTimeToString(localDateTime1); + // 查询近一个月各植被类型的火点数量 + List> maps = firePointDao.selectNumByLandType(startTime, endTime); + map.put("land",maps); + // 查询近一个月各地区火点数量 + List> maps1 = firePointDao.selectNumByArea(startTime, endTime); + map.put("area",maps1); + + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale); + } + + /** + * 查询近一天的火点数量 + * @return + */ + @Override + public String selectFirePointNumDay() { + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + Map map = new HashMap(3); + LocalDateTime localDateTime = LocalDateTime.now(); + LocalDateTime localDateTime2 = localDateTime.plusDays(1); + String endTime = DateTimeUtil.dateTimeToString(localDateTime2); + // 当前时间减1 + LocalDateTime localDateTime1 = localDateTime.minusDays(1); + String startTime = DateTimeUtil.dateTimeToString(localDateTime1); + // 查询近一个月各植被类型的火点数量 + List> maps = firePointDao.selectNumByLandType(startTime, endTime); + map.put("land",maps); + // 查询近一个月各地区火点数量 + List> maps1 = firePointDao.selectNumByArea(startTime, endTime); + map.put("area",maps1); + + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale); + } + + /** + * 查询近一周的火点数量 + * @return + */ + @Override + public String selectFirePointNumWeek() { + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + Map map = new HashMap(3); + LocalDateTime localDateTime = LocalDateTime.now(); + LocalDateTime localDateTime2 = localDateTime.plusDays(1); + String endTime = DateTimeUtil.dateTimeToString(localDateTime2); + // 当前时间减7 + LocalDateTime localDateTime1 = localDateTime.minusDays(7); + String startTime = DateTimeUtil.dateTimeToString(localDateTime1); + // 查询近一个月各植被类型的火点数量 + List> maps = firePointDao.selectNumByLandType(startTime, endTime); + map.put("land",maps); + // 查询近一个月各地区火点数量 + List> maps1 = firePointDao.selectNumByArea(startTime, endTime); + map.put("area",maps1); + + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale); + } }