添加了查询不同时间段各地区,各植被类型的火点数量

This commit is contained in:
DESKTOP-G8BCEP0\HP 2021-07-20 15:07:37 +08:00
parent 71a1392ccc
commit 31394ee9a2
5 changed files with 136 additions and 0 deletions

View File

@ -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()

View File

@ -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();
}
}
}

View File

@ -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<FirePointEntity,Long>, 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<Map<String,Object>> 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<Map<String,Object>> selectNumByArea(String startTime,String endTime);
}

View File

@ -77,4 +77,22 @@ public interface FirePointService {
* @return
*/
List<FirePointEntity> selectFirePointByMonth();
/**
* 查询近一个月的火点数量
* @return
*/
String selectFirePointNumMonth();
/**
* 查询近一天的火点数量
* @return
*/
String selectFirePointNumDay();
/**
* 查询
* @return
*/
String selectFirePointNumWeek();
}

View File

@ -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<Map<String, Object>> maps = firePointDao.selectNumByLandType(startTime, endTime);
map.put("land",maps);
// 查询近一个月各地区火点数量
List<Map<String, Object>> 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<Map<String, Object>> maps = firePointDao.selectNumByLandType(startTime, endTime);
map.put("land",maps);
// 查询近一个月各地区火点数量
List<Map<String, Object>> 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<Map<String, Object>> maps = firePointDao.selectNumByLandType(startTime, endTime);
map.put("land",maps);
// 查询近一个月各地区火点数量
List<Map<String, Object>> maps1 = firePointDao.selectNumByArea(startTime, endTime);
map.put("area",maps1);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale);
}
}