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

This commit is contained in:
liuchengqian 2023-03-01 16:18:46 +08:00
parent 243d90d031
commit 7d5025b9ab

View File

@ -4,6 +4,8 @@ import com.xkrs.straw.dao.FirePointOrdinaryDao;
import com.xkrs.straw.dao.FirePointPreciseDao; import com.xkrs.straw.dao.FirePointPreciseDao;
import com.xkrs.straw.model.bean.FirePointQueryResultBean; 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.FirePointPreciseEntity;
import com.xkrs.straw.model.entity.SysUserEntity; 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;
@ -12,14 +14,17 @@ import com.xkrs.utils.FirePointCodeUtils;
import org.apache.hc.core5.util.TextUtils; import org.apache.hc.core5.util.TextUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Component @Component
public class FirePointQueryManager { public class FirePointQueryManager {
@ -105,46 +110,48 @@ public class FirePointQueryManager {
e.printStackTrace(); e.printStackTrace();
return new FirePointQueryResultBean(false, e.getMessage(), null); return new FirePointQueryResultBean(false, e.getMessage(), null);
} }
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";
StringBuilder ordinaryBuilder = new StringBuilder(commonSql); // {
ordinaryBuilder.append(" FROM fire_point_ordinary AS t"); // 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";
ordinaryBuilder.append(" WHERE (t.town_code LIKE '" + mNoRedundantUserCode + "%')"); //
ordinaryBuilder.append(" AND ("); // StringBuilder ordinaryBuilder = new StringBuilder(commonSql);
for (int i = 0; i < mVipTimeRangeItemList.size(); i++) { // ordinaryBuilder.append(" FROM fire_point_ordinary AS t");
VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem = mVipTimeRangeItemList.get(i); // ordinaryBuilder.append(" WHERE (t.town_code LIKE '" + mNoRedundantUserCode + "%')");
String userStartTime = vipTimeRangeItem.getStartTime(); // ordinaryBuilder.append(" AND (");
String userEndTime = vipTimeRangeItem.getEndTime(); // for (int i = 0; i < mVipTimeRangeItemList.size(); i++) {
//早于不包含VIP开始时间或者晚于不包含VIP结束时间 // VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem = mVipTimeRangeItemList.get(i);
if (i > 0) { // String userStartTime = vipTimeRangeItem.getStartTime();
ordinaryBuilder.append(" AND "); // String userEndTime = vipTimeRangeItem.getEndTime();
} // //早于不包含VIP开始时间或者晚于不包含VIP结束时间
ordinaryBuilder.append("(t.satellite_time<'" + userStartTime + "' OR t.satellite_time>'" + userEndTime + "')"); // if (i > 0) {
} // ordinaryBuilder.append(" AND ");
ordinaryBuilder.append(")"); // }
ordinaryBuilder.append(" ORDER BY t.satellite_time DESC"); // ordinaryBuilder.append("(t.satellite_time<'" + userStartTime + "' OR t.satellite_time>'" + userEndTime + "')");
String ordinarySql = ordinaryBuilder.toString(); // }
log.info(sysUserEntity.getCountyName() + ":ordinarySql:" + ordinarySql); // ordinaryBuilder.append(")");
// ordinaryBuilder.append(" ORDER BY t.satellite_time DESC");
// String ordinarySql = ordinaryBuilder.toString();
// log.info(sysUserEntity.getCountyName() + ":ordinarySql:" + ordinarySql);
// List<AllFirePointVo> voList1 = firePointOrdinaryDao.customQuery(ordinarySql); // List<AllFirePointVo> voList1 = firePointOrdinaryDao.customQuery(ordinarySql);
//
StringBuilder preciseBuilder = new StringBuilder(commonSql); // StringBuilder preciseBuilder = new StringBuilder(commonSql);
preciseBuilder.append(" FROM fire_point_precise AS t"); // preciseBuilder.append(" FROM fire_point_precise AS t");
preciseBuilder.append(" WHERE (t.town_code LIKE '" + mNoRedundantUserCode + "%')"); // preciseBuilder.append(" WHERE (t.town_code LIKE '" + mNoRedundantUserCode + "%')");
preciseBuilder.append(" AND ("); // preciseBuilder.append(" AND (");
for (int i = 0; i < mVipTimeRangeItemList.size(); i++) { // for (int i = 0; i < mVipTimeRangeItemList.size(); i++) {
VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem = mVipTimeRangeItemList.get(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开始时间并且早于包含VIP结束时间
if (i > 0) { // if (i > 0) {
preciseBuilder.append(" OR "); // preciseBuilder.append(" OR ");
} // }
preciseBuilder.append("(t.satellite_time>='" + userStartTime + "' AND t.satellite_time<='" + userEndTime + "')"); // preciseBuilder.append("(t.satellite_time>='" + userStartTime + "' AND t.satellite_time<='" + userEndTime + "')");
} // }
preciseBuilder.append(")"); // preciseBuilder.append(")");
preciseBuilder.append(" ORDER BY t.satellite_time DESC"); // preciseBuilder.append(" ORDER BY t.satellite_time DESC");
String preciseSql = preciseBuilder.toString(); // String preciseSql = preciseBuilder.toString();
log.info(sysUserEntity.getCountyName() + ":preciseSql:" + preciseSql); // log.info(sysUserEntity.getCountyName() + ":preciseSql:" + preciseSql);
// List<AllFirePointVo> voList2 = firePointPreciseDao.customQuery(preciseSql); // List<AllFirePointVo> voList2 = firePointPreciseDao.customQuery(preciseSql);
// //
// //将两种数据来源的火点合并到一起 // //将两种数据来源的火点合并到一起
@ -155,57 +162,60 @@ public class FirePointQueryManager {
// resultList.sort(Comparator.comparing(AllFirePointVo::getSatelliteTime)); // resultList.sort(Comparator.comparing(AllFirePointVo::getSatelliteTime));
// //
// 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<>(); Specification<FirePointOrdinaryEntity> specificationOrdinary = (root, criteriaQuery, criteriaBuilder) -> {
// //添加区划编码的过滤 List<Predicate> predicateList = new ArrayList<>();
// predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); //添加区划编码的过滤
// for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : mVipTimeRangeItemList) { predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%"));
// String userStartTime = vipTimeRangeItem.getStartTime(); for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : mVipTimeRangeItemList) {
// String userEndTime = vipTimeRangeItem.getEndTime(); String userStartTime = vipTimeRangeItem.getStartTime();
// //早于不包含VIP开始时间 String userEndTime = vipTimeRangeItem.getEndTime();
// Predicate beforeStartTimePredicate = criteriaBuilder.lessThan(root.get("satelliteTime").as(String.class), userStartTime); //早于不包含VIP开始时间
// //晚于不包含VIP结束时间 Predicate beforeStartTimePredicate = criteriaBuilder.lessThan(root.get("satelliteTime").as(String.class), userStartTime);
// Predicate afterEndTimePredicate = criteriaBuilder.greaterThan(root.get("satelliteTime").as(String.class), userEndTime); //晚于不包含VIP结束时间
// predicateList.add(criteriaBuilder.or(beforeStartTimePredicate, afterEndTimePredicate)); 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()])); }
// }; return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
// //未审核的普通火点列表 };
// List<FirePointOrdinaryEntity> firePointOrdinaryList = firePointOrdinaryDao.findAll(specificationOrdinary, Sort.by(Sort.Direction.DESC, "satelliteTime")); //未审核的普通火点列表
// List<FirePointOrdinaryEntity> firePointOrdinaryList = firePointOrdinaryDao.findAll(specificationOrdinary, Sort.by(Sort.Direction.DESC, "satelliteTime"));
//
// //查询审核通过的精准火点
// Specification<FirePointPreciseEntity> specificationPrecise = (root, criteriaQuery, criteriaBuilder) -> { //查询审核通过的精准火点
// List<Predicate> predicateList = new ArrayList<>(); 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) { predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%"));
// String userStartTime = vipTimeRangeItem.getStartTime(); for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItem : mVipTimeRangeItemList) {
// String userEndTime = vipTimeRangeItem.getEndTime(); String userStartTime = vipTimeRangeItem.getStartTime();
// //晚于包含VIP开始时间 String userEndTime = vipTimeRangeItem.getEndTime();
// Predicate beforeStartTimePredicate = criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), userStartTime); //晚于包含VIP开始时间
// //早于包含VIP结束时间 Predicate beforeStartTimePredicate = criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), userStartTime);
// Predicate afterEndTimePredicate = criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), userEndTime); //早于包含VIP结束时间
// predicateList.add(criteriaBuilder.and(beforeStartTimePredicate, afterEndTimePredicate)); 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()])); }
// }; return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
// //审核通过的精准火点列表 };
// List<FirePointPreciseEntity> firePointPreciseList = firePointPreciseDao.findAll(specificationPrecise, Sort.by(Sort.Direction.DESC, "satelliteTime")); //审核通过的精准火点列表
// List<FirePointPreciseEntity> firePointPreciseList = firePointPreciseDao.findAll(specificationPrecise, Sort.by(Sort.Direction.DESC, "satelliteTime"));
// //将两种数据来源的火点合并到一起
// List<AllFirePointVo> resultList = new ArrayList<>(); //将两种数据来源的火点合并到一起
// for (FirePointOrdinaryEntity firePointOrdinaryEntity : firePointOrdinaryList) { List<AllFirePointVo> resultList = new ArrayList<>();
// resultList.add(FirePointConvertUtils.convert(firePointOrdinaryEntity)); for (FirePointOrdinaryEntity firePointOrdinaryEntity : firePointOrdinaryList) {
// } resultList.add(FirePointConvertUtils.convert(firePointOrdinaryEntity));
// for (FirePointPreciseEntity firePointPreciseEntity : firePointPreciseList) { }
// resultList.add(FirePointConvertUtils.convert(firePointPreciseEntity)); 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); List<AllFirePointVo> sortedResultList = resultList.stream().sorted(Comparator.comparing(AllFirePointVo::getSatelliteTime)).collect(Collectors.toList());
return new FirePointQueryResultBean(true, "", sortedResultList);
} }
} }