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); + } }