This commit is contained in:
liuchengqian 2023-03-02 15:36:07 +08:00
parent 2ab8598f83
commit d1ec3daef7

View File

@ -6,6 +6,7 @@ import com.xkrs.straw.model.bean.FirePointQueryResultBean;
import com.xkrs.straw.model.bean.VipTimeRangeBean; import com.xkrs.straw.model.bean.VipTimeRangeBean;
import com.xkrs.straw.model.entity.FirePointOrdinaryEntity; import com.xkrs.straw.model.entity.FirePointOrdinaryEntity;
import com.xkrs.straw.model.entity.FirePointPreciseEntity; import com.xkrs.straw.model.entity.FirePointPreciseEntity;
import com.xkrs.straw.model.entity.SysUserEntity;
import com.xkrs.straw.model.vo.AllFirePointVo; import com.xkrs.straw.model.vo.AllFirePointVo;
import com.xkrs.utils.DateTimeUtil; import com.xkrs.utils.DateTimeUtil;
import com.xkrs.utils.DateTimeUtils; import com.xkrs.utils.DateTimeUtils;
@ -36,9 +37,11 @@ public class FirePointQueryManager {
@Resource @Resource
private FirePointPreciseDao firePointPreciseDao; private FirePointPreciseDao firePointPreciseDao;
// public FirePointQueryResultBean queryFirePointBelongToUser(SysUserEntity sysUserEntity, String startTime, String endTime, String satelliteType, String landType) { public FirePointQueryResultBean queryFirePointBelongToUser(SysUserEntity sysUserEntity, String startTime, String endTime, String satelliteType, String landType) {
// String countyCode = sysUserEntity.getCountyCode();
// } String vipTimeRangeJson = sysUserEntity.getVipTimeRangeJson();
return queryFirePointBelongToUser(countyCode, vipTimeRangeJson, startTime, endTime, satelliteType, landType);
}
public FirePointQueryResultBean queryFirePointBelongToUser(String userCode, String vipTimeRangeJson, String startTime, String endTime, String satelliteType, String landType) { public FirePointQueryResultBean queryFirePointBelongToUser(String userCode, String vipTimeRangeJson, String startTime, String endTime, String satelliteType, String landType) {
@ -110,6 +113,131 @@ public class FirePointQueryManager {
return new FirePointQueryResultBean(e.getMessage()); return new FirePointQueryResultBean(e.getMessage());
} }
return queryFirePointBelongToUser(mNoRedundantUserCode, mVipTimeRangeItemList, startTime, endTime, satelliteType, landType);
}
public FirePointQueryResultBean queryFirePointBelongToUser(String noRedundantUserCode, List<VipTimeRangeBean.VipTimeRangeItemBean> vipTimeRangeItemList, String startTime, String endTime, String satelliteType, String landType) {
//如果格式化后的用户区划编码是空就返回失败
if (TextUtils.isEmpty(noRedundantUserCode)) {
return new FirePointQueryResultBean("User CountyCode Error 2, noRedundantUserCode = " + noRedundantUserCode);
}
//VIP时间范围发生了异常返回失败
if (vipTimeRangeItemList == null || vipTimeRangeItemList.size() == 0) {
return new FirePointQueryResultBean("User VipTimeRangeJson Error 2, 已保存的VIP时间范围出现错误");
}
final String finalMNoRedundantUserCode = noRedundantUserCode;
//查询未审核的普通火点
Specification<FirePointOrdinaryEntity> specificationOrdinary = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
//添加区划编码的过滤
predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%"));
//开始时间查询条件
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));
}
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : vipTimeRangeItemList) {
String userStartTime = vipTimeRangeItem.getStartTime();
String userEndTime = vipTimeRangeItem.getEndTime();
//早于不包含VIP开始时间
Predicate beforeStartTimePredicate = criteriaBuilder.lessThan(root.get("satelliteTime").as(String.class), userStartTime);
//晚于不包含VIP结束时间
Predicate afterEndTimePredicate = criteriaBuilder.greaterThan(root.get("satelliteTime").as(String.class), userEndTime);
predicateList.add(criteriaBuilder.or(beforeStartTimePredicate, afterEndTimePredicate));
}
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
};
//未审核的普通火点列表
List<FirePointOrdinaryEntity> firePointOrdinaryList = firePointOrdinaryDao.findAll(specificationOrdinary, Sort.by(Sort.Direction.DESC, "satelliteTime"));
//查询审核通过的精准火点
Specification<FirePointPreciseEntity> specificationPrecise = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
//添加区划编码的过滤
predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%"));
//开始时间查询条件
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));
}
List<Predicate> subPredicateList = new ArrayList<>();
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : vipTimeRangeItemList) {
String userStartTime = vipTimeRangeItem.getStartTime();
String userEndTime = vipTimeRangeItem.getEndTime();
//晚于包含VIP开始时间
Predicate beforeStartTimePredicate = criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), userStartTime);
//早于包含VIP结束时间
Predicate afterEndTimePredicate = criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), userEndTime);
subPredicateList.add(criteriaBuilder.and(beforeStartTimePredicate, afterEndTimePredicate));
}
if (subPredicateList.size() == 0) {
} else if (subPredicateList.size() == 1) {
predicateList.add(subPredicateList.get(0));
} else {
Predicate orPredicate = null;
for (int i = 1; i < subPredicateList.size(); i++) {
if (i == 1) {
orPredicate = criteriaBuilder.or(subPredicateList.get(0), subPredicateList.get(1));
} else {
orPredicate = criteriaBuilder.or(orPredicate, subPredicateList.get(i));
}
}
predicateList.add(orPredicate);
}
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
};
//审核通过的精准火点列表
List<FirePointPreciseEntity> firePointPreciseList = firePointPreciseDao.findAll(specificationPrecise, Sort.by(Sort.Direction.DESC, "satelliteTime"));
//将两种数据来源的火点合并到一起
List<AllFirePointVo> resultList = new ArrayList<>();
for (FirePointOrdinaryEntity firePointOrdinaryEntity : firePointOrdinaryList) {
resultList.add(FirePointConvertUtils.convert(firePointOrdinaryEntity));
}
for (FirePointPreciseEntity firePointPreciseEntity : firePointPreciseList) {
resultList.add(FirePointConvertUtils.convert(firePointPreciseEntity));
}
//对合并后的结果进行排序
List<AllFirePointVo> sortedResultList = resultList.stream().sorted(Comparator.comparing(AllFirePointVo::getSatelliteTime)).collect(Collectors.toList());
return new FirePointQueryResultBean(true, "", sortedResultList, sortedResultList.size());
// { // {
// final String commonSql = "SELECT t.id AS id, t.fire_code AS fireCode, t.county_code AS countyCode, t.county_name AS countyName, t.satellite_time AS satelliteTime, t.longitude AS longitude, t.latitude AS latitude, t.satellite_type AS satelliteType, t.land_type AS landType, t.confidence AS confidence, t.fire_image AS fireImage, t.satellite_image AS satelliteImage, t.town_code AS townCode, t.town_name AS townName, t.add_time AS addTime, t.fire_point_address AS firePointAddress, t.remark AS remark"; // final String commonSql = "SELECT t.id AS id, t.fire_code AS fireCode, t.county_code AS countyCode, t.county_name AS countyName, t.satellite_time AS satelliteTime, t.longitude AS longitude, t.latitude AS latitude, t.satellite_type AS satelliteType, t.land_type AS landType, t.confidence AS confidence, t.fire_image AS fireImage, t.satellite_image AS satelliteImage, t.town_code AS townCode, t.town_name AS townName, t.add_time AS addTime, t.fire_point_address AS firePointAddress, t.remark AS remark";
// //
@ -163,117 +291,6 @@ public class FirePointQueryManager {
// return new FirePointQueryResultBean(true, "", resultList); // return new FirePointQueryResultBean(true, "", resultList);
// //
// } // }
final String finalMNoRedundantUserCode = mNoRedundantUserCode;
//查询未审核的普通火点
Specification<FirePointOrdinaryEntity> specificationOrdinary = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
//添加区划编码的过滤
predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%"));
//开始时间查询条件
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));
}
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : mVipTimeRangeItemList) {
String userStartTime = vipTimeRangeItem.getStartTime();
String userEndTime = vipTimeRangeItem.getEndTime();
//早于不包含VIP开始时间
Predicate beforeStartTimePredicate = criteriaBuilder.lessThan(root.get("satelliteTime").as(String.class), userStartTime);
//晚于不包含VIP结束时间
Predicate afterEndTimePredicate = criteriaBuilder.greaterThan(root.get("satelliteTime").as(String.class), userEndTime);
predicateList.add(criteriaBuilder.or(beforeStartTimePredicate, afterEndTimePredicate));
}
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
};
//未审核的普通火点列表
List<FirePointOrdinaryEntity> firePointOrdinaryList = firePointOrdinaryDao.findAll(specificationOrdinary, Sort.by(Sort.Direction.DESC, "satelliteTime"));
//查询审核通过的精准火点
Specification<FirePointPreciseEntity> specificationPrecise = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
//添加区划编码的过滤
predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%"));
//开始时间查询条件
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));
}
List<Predicate> subPredicateList = new ArrayList<>();
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : mVipTimeRangeItemList) {
String userStartTime = vipTimeRangeItem.getStartTime();
String userEndTime = vipTimeRangeItem.getEndTime();
//晚于包含VIP开始时间
Predicate beforeStartTimePredicate = criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), userStartTime);
//早于包含VIP结束时间
Predicate afterEndTimePredicate = criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), userEndTime);
subPredicateList.add(criteriaBuilder.and(beforeStartTimePredicate, afterEndTimePredicate));
}
if (subPredicateList.size() == 0) {
} else if (subPredicateList.size() == 1) {
predicateList.add(subPredicateList.get(0));
} else {
Predicate orPredicate = null;
for (int i = 1; i < subPredicateList.size(); i++) {
if (i == 1) {
orPredicate = criteriaBuilder.or(subPredicateList.get(0), subPredicateList.get(1));
} else {
orPredicate = criteriaBuilder.or(orPredicate, subPredicateList.get(i));
}
}
predicateList.add(orPredicate);
}
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
};
//审核通过的精准火点列表
List<FirePointPreciseEntity> firePointPreciseList = firePointPreciseDao.findAll(specificationPrecise, Sort.by(Sort.Direction.DESC, "satelliteTime"));
//将两种数据来源的火点合并到一起
List<AllFirePointVo> resultList = new ArrayList<>();
for (FirePointOrdinaryEntity firePointOrdinaryEntity : firePointOrdinaryList) {
resultList.add(FirePointConvertUtils.convert(firePointOrdinaryEntity));
}
for (FirePointPreciseEntity firePointPreciseEntity : firePointPreciseList) {
resultList.add(FirePointConvertUtils.convert(firePointPreciseEntity));
}
//对合并后的结果进行排序
List<AllFirePointVo> sortedResultList = resultList.stream().sorted(Comparator.comparing(AllFirePointVo::getSatelliteTime)).collect(Collectors.toList());
return new FirePointQueryResultBean(true, "", sortedResultList, sortedResultList.size());
} }
} }