重写用户获取火点数据的接口

This commit is contained in:
liuchengqian 2023-02-28 16:32:34 +08:00
parent 0cbf9ce5c3
commit cac53e215f

View File

@ -108,56 +108,99 @@ public class FirePointQueryManager {
} }
final String finalMNoRedundantUserCode = mNoRedundantUserCode; final String finalMNoRedundantUserCode = mNoRedundantUserCode;
//查询未审核的普通火点
Specification<FirePointOrdinaryEntity> specificationOrdinary = (root, criteriaQuery, criteriaBuilder) -> { 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";
List<Predicate> predicateList = new ArrayList<>();
//添加区划编码的过滤 StringBuilder ordinaryBuilder = new StringBuilder(commonSql);
predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); ordinaryBuilder.append(" FROM fire_point_ordinary AS t");
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : mVipTimeRangeItemList) { ordinaryBuilder.append(" WHERE (t.town_code LIKE '" + finalMNoRedundantUserCode + "%')");
ordinaryBuilder.append(" AND (");
for (int i = 0; i < mVipTimeRangeItemList.size(); i++) {
VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem = mVipTimeRangeItemList.get(i);
String userStartTime = vipTimeRangeItem.getStartTime(); String userStartTime = vipTimeRangeItem.getStartTime();
String userEndTime = vipTimeRangeItem.getEndTime(); String userEndTime = vipTimeRangeItem.getEndTime();
//早于不包含VIP开始时间 //早于不包含VIP开始时间或者晚于不包含VIP结束时间
Predicate beforeStartTimePredicate = criteriaBuilder.lessThan(root.get("satelliteTime").as(String.class), userStartTime); if (i > 0) {
//晚于不包含VIP结束时间 ordinaryBuilder.append(" AND ");
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()])); ordinaryBuilder.append("(t.satellite_time<'" + userStartTime + "' OR t.satellite_time>'" + userEndTime + "')");
}; }
//未审核的普通火点列表 ordinaryBuilder.append(")");
List<FirePointOrdinaryEntity> firePointOrdinaryList = firePointOrdinaryDao.findAll(specificationOrdinary, Sort.by(Sort.Direction.DESC, "satelliteTime")); ordinaryBuilder.append(" ORDER BY t.satellite_time DESC");
String ordinarySql = ordinaryBuilder.toString();
System.out.println("ordinarySql = " + ordinarySql);
StringBuilder preciseBuilder = new StringBuilder(commonSql);
//查询审核通过的精准火点 preciseBuilder.append(" FROM fire_point_precise AS t");
Specification<FirePointPreciseEntity> specificationPrecise = (root, criteriaQuery, criteriaBuilder) -> { preciseBuilder.append(" WHERE (t.town_code LIKE '" + finalMNoRedundantUserCode + "%')");
List<Predicate> predicateList = new ArrayList<>(); preciseBuilder.append(" AND (");
//添加区划编码的过滤 for (int i = 0; i < mVipTimeRangeItemList.size(); i++) {
predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem = mVipTimeRangeItemList.get(i);
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : mVipTimeRangeItemList) {
String userStartTime = vipTimeRangeItem.getStartTime(); String userStartTime = vipTimeRangeItem.getStartTime();
String userEndTime = vipTimeRangeItem.getEndTime(); String userEndTime = vipTimeRangeItem.getEndTime();
//晚于包含VIP开始时间 //晚于包含VIP开始时间并且早于包含VIP结束时间
Predicate beforeStartTimePredicate = criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), userStartTime); if (i > 0) {
//早于包含VIP结束时间 preciseBuilder.append(" OR ");
Predicate afterEndTimePredicate = criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), userEndTime);
predicateList.add(criteriaBuilder.and(beforeStartTimePredicate, afterEndTimePredicate));
} }
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()])); preciseBuilder.append("(t.satellite_time>='" + userStartTime + "' AND t.satellite_time<='" + userEndTime + "')");
}; }
//审核通过的精准火点列表 preciseBuilder.append(")");
List<FirePointPreciseEntity> firePointPreciseList = firePointPreciseDao.findAll(specificationPrecise, Sort.by(Sort.Direction.DESC, "satelliteTime")); preciseBuilder.append(" ORDER BY t.satellite_time DESC");
String preciseSql = preciseBuilder.toString();
System.out.println("preciseSql = " + preciseSql);
//将两种数据来源的火点合并到一起 return new FirePointQueryResultBean(true, "", null);
List<AllFirePointVo> resultList = new ArrayList<>();
for (FirePointOrdinaryEntity firePointOrdinaryEntity : firePointOrdinaryList) { // //查询未审核的普通火点
resultList.add(FirePointConvertUtils.convert(firePointOrdinaryEntity)); // Specification<FirePointOrdinaryEntity> specificationOrdinary = (root, criteriaQuery, criteriaBuilder) -> {
} // List<Predicate> predicateList = new ArrayList<>();
for (FirePointPreciseEntity firePointPreciseEntity : firePointPreciseList) { // //添加区划编码的过滤
resultList.add(FirePointConvertUtils.convert(firePointPreciseEntity)); // predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%"));
} // for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : mVipTimeRangeItemList) {
//对合并后的结果进行排序 // String userStartTime = vipTimeRangeItem.getStartTime();
List<AllFirePointVo> sortedResultList = resultList.stream().sorted(Comparator.comparing(AllFirePointVo::getSatelliteTime)).collect(Collectors.toList()); // String userEndTime = vipTimeRangeItem.getEndTime();
return new FirePointQueryResultBean(true, "", sortedResultList); // //早于不包含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 + "%"));
// 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);
// predicateList.add(criteriaBuilder.and(beforeStartTimePredicate, afterEndTimePredicate));
// }
// 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);
} }
} }