104 lines
6.0 KiB
Java
104 lines
6.0 KiB
Java
package com.xkrs.helper;
|
||
|
||
import com.xkrs.dao.FirePointOrdinaryDao;
|
||
import com.xkrs.model.bean.FirePointQueryResultBean;
|
||
import com.xkrs.model.entity.FirePointOrdinaryEntity;
|
||
import com.xkrs.model.entity.SysUserEntity;
|
||
import com.xkrs.utilsnew.DateTimeUtils;
|
||
import com.xkrs.utilsnew.FirePointCodeUtils;
|
||
import com.xkrs.utilsnew.VipTimeRangeUtils;
|
||
import org.apache.hc.core5.util.TextUtils;
|
||
import org.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.data.domain.PageRequest;
|
||
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 FirePointQueryManager {
|
||
|
||
public static Logger log = LoggerFactory.getLogger(FirePointQueryManager.class);
|
||
|
||
@Resource
|
||
private FirePointOrdinaryDao firePointOrdinaryDao;
|
||
|
||
/**
|
||
* 查询火点播报(无token)
|
||
*
|
||
* @param limit 最大数量
|
||
*/
|
||
public FirePointQueryResultBean queryFirePointBroadcast(Integer limit) {
|
||
int size = (limit != null && limit > 0) ? limit : 10;
|
||
PageRequest pageRequest = PageRequest.of(1, size, Sort.by(Sort.Direction.DESC, "satelliteTime"));
|
||
List<FirePointOrdinaryEntity> firePointList = firePointOrdinaryDao.findAll(pageRequest).getContent();
|
||
return new FirePointQueryResultBean(true, "", firePointList, firePointList.size());
|
||
}
|
||
|
||
public FirePointQueryResultBean queryFirePointBelongToUser(SysUserEntity sysUserEntity, String userSubAreaCountyCode, String startTime, String endTime, String satelliteType, String landType) {
|
||
|
||
String noRedundantUserCode = ("管理员".equals(sysUserEntity.getAccountType())) ? null : FirePointCodeUtils.getFormatCutCode(sysUserEntity.getCountyCode());
|
||
String userSubAreaCutCountyCode = (TextUtils.isEmpty(userSubAreaCountyCode)) ? null : FirePointCodeUtils.getFormatCutCode(userSubAreaCountyCode);
|
||
|
||
//查询未审核的普通火点
|
||
Specification<FirePointOrdinaryEntity> specificationOrdinary = (root, criteriaQuery, criteriaBuilder) -> {
|
||
List<Predicate> predicateList = new ArrayList<>();
|
||
//非空判断
|
||
predicateList.add(criteriaBuilder.isNotNull(root.get("proCode").as(String.class)));
|
||
predicateList.add(criteriaBuilder.isNotNull(root.get("proName").as(String.class)));
|
||
predicateList.add(criteriaBuilder.isNotNull(root.get("cityCode").as(String.class)));
|
||
predicateList.add(criteriaBuilder.isNotNull(root.get("cityName").as(String.class)));
|
||
predicateList.add(criteriaBuilder.isNotNull(root.get("countyCode").as(String.class)));
|
||
predicateList.add(criteriaBuilder.isNotNull(root.get("countyName").as(String.class)));
|
||
//添加区划编码的过滤
|
||
if (!TextUtils.isEmpty(noRedundantUserCode)) {
|
||
predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), noRedundantUserCode + "%"));
|
||
}
|
||
//添加子区域区划编码的过滤(比如查询火点的系统用户所属的区划是山东省,但是该用户目前只想查询青岛市的火点,那么noRedundantUserCode=山东省区划,userSubAreaCutCountyCode=青岛市区划)
|
||
if (!TextUtils.isEmpty(userSubAreaCutCountyCode)) {
|
||
predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), userSubAreaCutCountyCode + "%"));
|
||
}
|
||
//开始时间查询条件
|
||
if (!TextUtils.isEmpty(startTime)) {
|
||
LocalDateTime startTime1 = DateTimeUtils.stringToLocalDateTime(startTime);
|
||
LocalDateTime startTime2 = LocalDateTime.of(startTime1.getYear(), startTime1.getMonth(), startTime1.getDayOfMonth(), 0, 0, 0, 0);
|
||
String startTimeString = DateTimeUtils.localDateTimeToString(startTime2);
|
||
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTimeString));
|
||
}
|
||
//结束时间查询条件
|
||
if (!TextUtils.isEmpty(endTime)) {
|
||
LocalDateTime endTime1 = DateTimeUtils.stringToLocalDateTime(endTime).plusDays(1);
|
||
LocalDateTime endTime2 = LocalDateTime.of(endTime1.getYear(), endTime1.getMonth(), endTime1.getDayOfMonth(), 0, 0, 0, 0);
|
||
String endTimeString = DateTimeUtils.localDateTimeToString(endTime2);
|
||
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTimeString));
|
||
}
|
||
//卫星类型查询条件
|
||
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));
|
||
}
|
||
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
||
};
|
||
//未审核的普通火点列表
|
||
List<FirePointOrdinaryEntity> firePointList = firePointOrdinaryDao.findAll(specificationOrdinary, Sort.by(Sort.Direction.DESC, "satelliteTime"));
|
||
boolean inVipTimeRange = VipTimeRangeUtils.checkIfInVipTimeRange(sysUserEntity.getVipTimeRangeJson());//查询火点后的步骤
|
||
if ((!"管理员".equals(sysUserEntity.getAccountType())) && (!inVipTimeRange)) {
|
||
//该账号不是管理员,并且不在VIP时间范围内。(过期的普通用户)那就清空火点的研判标志
|
||
for (FirePointOrdinaryEntity firePoint : firePointList) {
|
||
firePoint.setFireStatus(null);//过期的普通用户看不到火点的研判标志
|
||
}
|
||
}
|
||
return new FirePointQueryResultBean(true, "", firePointList, firePointList.size());
|
||
}
|
||
|
||
}
|