封装火点查询接口
This commit is contained in:
parent
0b7e799723
commit
e68a996df0
@ -95,6 +95,9 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
@Resource
|
||||
private RelRoleAuthorityDao relRoleAuthorityDao;
|
||||
|
||||
@Resource
|
||||
private FirePointQueryHelper firePointQueryHelper;
|
||||
|
||||
/**
|
||||
* 添加火点信息
|
||||
*
|
||||
|
@ -1,4 +1,17 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class DateTimeUtils {
|
||||
|
||||
public final static DateTimeFormatter DATE_TIME_FORMATTER_1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public static String localDateTimeToString(LocalDateTime localDateTime) {
|
||||
return DATE_TIME_FORMATTER_1.format(localDateTime);
|
||||
}
|
||||
|
||||
public static LocalDateTime stringToLocalDateTime(String localDateTimeString) {
|
||||
return LocalDateTime.parse(localDateTimeString, DATE_TIME_FORMATTER_1);
|
||||
}
|
||||
}
|
||||
|
69
src/main/java/com/xkrs/utils/FirePointQueryHelper.java
Normal file
69
src/main/java/com/xkrs/utils/FirePointQueryHelper.java
Normal file
@ -0,0 +1,69 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import com.xkrs.dao.FirePointDao;
|
||||
import com.xkrs.model.entity.FirePointEntity;
|
||||
import org.apache.hc.core5.util.TextUtils;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 火点查询工具类
|
||||
*/
|
||||
@Component
|
||||
public class FirePointQueryHelper {
|
||||
|
||||
@Resource
|
||||
private FirePointDao firePointDao;
|
||||
|
||||
public List<FirePointEntity> queryFirePoint(String code, String startTime, String endTime, String satelliteType, String landType) {
|
||||
Specification<FirePointEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
|
||||
//查询条件集合
|
||||
List<Predicate> predicateList = new ArrayList<>();
|
||||
//添加区划编码查询条件
|
||||
if (!TextUtils.isEmpty(code)) {
|
||||
String codeNotZeroEnd = getCodeNotZeroEnd(code);
|
||||
if (!TextUtils.isEmpty(codeNotZeroEnd)) {
|
||||
predicateList.add(criteriaBuilder.like(root.get("streetCode").as(String.class), codeNotZeroEnd + "%"));
|
||||
}
|
||||
}
|
||||
//限制最早开始时间不得早于一个月
|
||||
String earliestStartTime = DateTimeUtils.localDateTimeToString(LocalDateTime.now().minusDays(30));
|
||||
//开始时间查询条件
|
||||
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), earliestStartTime));
|
||||
if (!TextUtils.isEmpty(startTime)) {
|
||||
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime));
|
||||
}
|
||||
//结束时间查询条件
|
||||
if (!TextUtils.isEmpty(endTime)) {
|
||||
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime));
|
||||
}
|
||||
//卫星类型查询条件
|
||||
if (!TextUtils.isEmpty(satelliteType)) {
|
||||
predicateList.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType));
|
||||
}
|
||||
//地物类型查询条件
|
||||
if (!TextUtils.isEmpty(landType)) {
|
||||
predicateList.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType));
|
||||
}
|
||||
Predicate[] predicateArray = new Predicate[predicateList.size()];
|
||||
return criteriaBuilder.and(predicateList.toArray(predicateArray));
|
||||
};
|
||||
return firePointDao.findAll(specification, Sort.by(Sort.Direction.DESC, "satelliteTime"));
|
||||
}
|
||||
|
||||
private String getCodeNotZeroEnd(String code) {
|
||||
String codeNotZeroEnd = code;
|
||||
while (codeNotZeroEnd.endsWith("0")) {
|
||||
codeNotZeroEnd = codeNotZeroEnd.substring(0, codeNotZeroEnd.length() - 1);
|
||||
}
|
||||
return codeNotZeroEnd;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user