添加了查询近一个月的火点信息

This commit is contained in:
DESKTOP-4U0TDEF\20371 2021-07-19 10:51:05 +08:00
parent 17a7ef2455
commit 3e8dd2e22b
4 changed files with 60 additions and 1 deletions

View File

@ -172,6 +172,21 @@ public class FirePointController {
if(firePointEntities == null || firePointEntities.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有火点数据",locale);
}
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,firePointEntities,locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,firePointEntities,locale);
}
/**
* 查询近一个月的火点信息
* @return
*/
@GetMapping("/selectFirePointByMonth")
public String selectFirePointByMonth() {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
List<FirePointEntity> firePointEntities = firePointService.selectFirePointByMonth();
if(firePointEntities == null || firePointEntities.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有火点数据",locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,firePointEntities,locale);
}
}

View File

@ -71,4 +71,10 @@ public interface FirePointService {
* @return
*/
List<FirePointEntity> selectFirePointBetweenSeven();
/**
* 查询近一个月的火点信息
* @return
*/
List<FirePointEntity> selectFirePointByMonth();
}

View File

@ -238,4 +238,18 @@ public class FirePointServiceImpl implements FirePointService {
String startTime = DateTimeUtil.dateTimeToString(localDateTime1);
return query.selectFirePointBetweenThree(startTime, endTime);
}
/**
* 查询近一个月的火点信息
* @return
*/
@Override
public List<FirePointEntity> selectFirePointByMonth() {
LocalDateTime localDateTime = LocalDateTime.now();
String endTime = DateTimeUtil.dateTimeToString(localDateTime);
// 当前时间减7
LocalDateTime localDateTime1 = localDateTime.minusDays(30);
String startTime = DateTimeUtil.dateTimeToString(localDateTime1);
return query.selectFirePointByMonth(startTime,endTime);
}
}

View File

@ -80,5 +80,29 @@ public class Query {
return firePointDao.findAll(specification);
}
/**
* 查询近一个月的火点
* @param startTime
* @param endTime
* @return
*/
public List<FirePointEntity> selectFirePointByMonth(String startTime,String endTime) {
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
@Override
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> list = new ArrayList<>();
if(startTime != null && !"".equals(startTime)){
list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(String.class), startTime));
}
if(endTime != null && !"".equals(endTime)){
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(String.class), endTime));
}
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return firePointDao.findAll(specification);
}
}