diff --git a/src/main/java/com/xkrs/straw/utils/FirePointFilterUtils.java b/src/main/java/com/xkrs/straw/utils/FirePointFilterUtils.java index e7d5fc9..bfb380d 100644 --- a/src/main/java/com/xkrs/straw/utils/FirePointFilterUtils.java +++ b/src/main/java/com/xkrs/straw/utils/FirePointFilterUtils.java @@ -5,6 +5,11 @@ import com.xkrs.straw.dao.FirePointPreciseDao; import com.xkrs.straw.model.bean.DataWrapper2; import com.xkrs.straw.model.entity.FirePointOrdinaryEntity; import com.xkrs.straw.model.entity.FirePointPreciseEntity; +import org.springframework.data.jpa.domain.Specification; + +import javax.persistence.criteria.Predicate; +import java.util.ArrayList; +import java.util.List; public class FirePointFilterUtils { @@ -27,28 +32,43 @@ public class FirePointFilterUtils { return new DataWrapper2<>(Boolean.TRUE, ""); } - public static DataWrapper2 checkDuplicated(FirePointOrdinaryDao firePointOrdinaryDao, FirePointOrdinaryEntity firePointOrdinaryEntity) { -/** - * private boolean checkDuplicatedData(FirePointEntity firePointEntity) { - * List duplicatedDataList = firePointDao.findDuplicatedData(firePointEntity.getLongitude(), firePointEntity.getLatitude(), firePointEntity.getStreetCode(), firePointEntity.getSatelliteTime(), firePointEntity.getSatelliteType(), firePointEntity.getLandType()); - * return duplicatedDataList != null && duplicatedDataList.size() > 0; - * } - * - * - @Query(value = "SELECT * FROM fire_point WHERE longitude = ?1 AND latitude = ?2 AND street_code = ?3 AND satellite_time = ?4 AND satellite_type = ?5 AND land_type = ?6", nativeQuery = true) - List findDuplicatedData(double longitude, double latitude, String streetCode, String satelliteTime, String satelliteType, String landType); - - if (checkDuplicatedData(firePointEntity)) { - log.info("-------该火点和历史火点重复,不入库"); - return false; - } - */ - return null; + public static DataWrapper2 checkDuplicated(FirePointOrdinaryDao firePointDao, FirePointOrdinaryEntity firePointEntity) { + Specification specification = (root, criteriaQuery, criteriaBuilder) -> { + List predicateList = new ArrayList<>(); + predicateList.add(criteriaBuilder.equal(root.get("longitude").as(Double.class), firePointEntity.getLongitude())); + predicateList.add(criteriaBuilder.equal(root.get("latitude").as(Double.class), firePointEntity.getLatitude())); + predicateList.add(criteriaBuilder.equal(root.get("countyCode").as(String.class), firePointEntity.getCountyCode())); + predicateList.add(criteriaBuilder.equal(root.get("countyName").as(String.class), firePointEntity.getCountyName())); + predicateList.add(criteriaBuilder.equal(root.get("townCode").as(String.class), firePointEntity.getTownCode())); + predicateList.add(criteriaBuilder.equal(root.get("satelliteTime").as(String.class), firePointEntity.getSatelliteTime())); + predicateList.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), firePointEntity.getSatelliteType())); + predicateList.add(criteriaBuilder.equal(root.get("landType").as(String.class), firePointEntity.getLandType())); + return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()])); + }; + List list = firePointDao.findAll(specification); + if (list.size() > 0) { + return new DataWrapper2<>(Boolean.TRUE, "该火点和历史火点重复,不入库"); + } + return new DataWrapper2<>(Boolean.FALSE, ""); } - - public static DataWrapper2 checkDuplicated(FirePointPreciseDao firePointPreciseDao, FirePointPreciseEntity firePointPreciseEntity) { - - return null; + public static DataWrapper2 checkDuplicated(FirePointPreciseDao firePointDao, FirePointPreciseEntity firePointEntity) { + Specification specification = (root, criteriaQuery, criteriaBuilder) -> { + List predicateList = new ArrayList<>(); + predicateList.add(criteriaBuilder.equal(root.get("longitude").as(Double.class), firePointEntity.getLongitude())); + predicateList.add(criteriaBuilder.equal(root.get("latitude").as(Double.class), firePointEntity.getLatitude())); + predicateList.add(criteriaBuilder.equal(root.get("countyCode").as(String.class), firePointEntity.getCountyCode())); + predicateList.add(criteriaBuilder.equal(root.get("countyName").as(String.class), firePointEntity.getCountyName())); + predicateList.add(criteriaBuilder.equal(root.get("townCode").as(String.class), firePointEntity.getTownCode())); + predicateList.add(criteriaBuilder.equal(root.get("satelliteTime").as(String.class), firePointEntity.getSatelliteTime())); + predicateList.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), firePointEntity.getSatelliteType())); + predicateList.add(criteriaBuilder.equal(root.get("landType").as(String.class), firePointEntity.getLandType())); + return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()])); + }; + List list = firePointDao.findAll(specification); + if (list.size() > 0) { + return new DataWrapper2<>(Boolean.TRUE, "该火点和历史火点重复,不入库"); + } + return new DataWrapper2<>(Boolean.FALSE, ""); } }