2021-07-12 14:51:34 +08:00
|
|
|
package com.xkrs.utils;
|
|
|
|
|
2021-07-16 08:47:53 +08:00
|
|
|
import com.xkrs.dao.FirePointDao;
|
|
|
|
import com.xkrs.model.entity.FirePointEntity;
|
2021-07-12 14:51:34 +08:00
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author XinYi Song
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Component
|
|
|
|
public class Query {
|
|
|
|
|
2021-07-16 08:47:53 +08:00
|
|
|
@Resource
|
|
|
|
private FirePointDao firePointDao;
|
2021-07-12 14:51:34 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 动态多条件查询项目信息
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
2021-07-16 08:47:53 +08:00
|
|
|
public List<FirePointEntity> selectFirePoint(String cityCode,String satelliteType,String landType,String startTime,String endTime) {
|
|
|
|
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
|
2021-07-12 14:51:34 +08:00
|
|
|
@Override
|
2021-07-16 08:47:53 +08:00
|
|
|
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
2021-07-12 14:51:34 +08:00
|
|
|
List<Predicate> list = new ArrayList<>();
|
2021-07-16 08:47:53 +08:00
|
|
|
if (cityCode != null && !"".equals(cityCode)) {
|
|
|
|
String substring = cityCode.substring(0, 4);
|
|
|
|
list.add(criteriaBuilder.like(root.get("countyCode").as(String.class), "%" + substring + "%"));
|
2021-07-12 14:51:34 +08:00
|
|
|
}
|
2021-07-16 08:47:53 +08:00
|
|
|
if (satelliteType != null && !"".equals(satelliteType)) {
|
|
|
|
list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType));
|
|
|
|
}
|
|
|
|
if (landType != null && !"".equals(landType)) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
if(endTime != null && !"".equals(endTime)){
|
|
|
|
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(String.class), endTime));
|
2021-07-12 14:51:34 +08:00
|
|
|
}
|
|
|
|
Predicate[] predicates = new Predicate[list.size()];
|
|
|
|
return criteriaBuilder.and(list.toArray(predicates));
|
|
|
|
}
|
|
|
|
};
|
2021-07-16 08:47:53 +08:00
|
|
|
return firePointDao.findAll(specification);
|
|
|
|
}
|
2021-07-12 14:51:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
}
|