diff --git a/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java index 9c8c608..31fdb76 100644 --- a/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/DispatchFirePointServiceImpl.java @@ -96,6 +96,9 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService { firePointOrdinaryEntity.setFireImage(fireImage); firePointOrdinaryEntity.setSatelliteImage(satelliteImage); firePointOrdinaryEntity.setAddTime(addTime); + if (FirePointFilterUtils.checkDuplicated(firePointOrdinaryDao, firePointOrdinaryEntity)) { + return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "该火点和历史火点重复", locale); + } StreetEntity streetEntity = obtainInfoByCountyCode(countyCode); if (streetEntity != null) { firePointOrdinaryEntity.setProCode(streetEntity.getProCode()); @@ -107,10 +110,6 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService { firePointOrdinaryEntity.setCountyName(countyName); firePointOrdinaryEntity.setTownCode(townCode); bindFirePointAddress(firePointOrdinaryEntity); - DataWrapper2 checkDuplicatedWrapper1 = FirePointFilterUtils.checkDuplicated(firePointOrdinaryDao, firePointOrdinaryEntity); - if (checkDuplicatedWrapper1.getData1()) { - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, checkDuplicatedWrapper1.getData2(), locale); - } firePointOrdinaryDao.save(firePointOrdinaryEntity); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale); } diff --git a/src/main/java/com/xkrs/utilsnew/FirePointFilterUtils.java b/src/main/java/com/xkrs/utilsnew/FirePointFilterUtils.java index f7951cc..bacd354 100644 --- a/src/main/java/com/xkrs/utilsnew/FirePointFilterUtils.java +++ b/src/main/java/com/xkrs/utilsnew/FirePointFilterUtils.java @@ -1,10 +1,8 @@ package com.xkrs.utilsnew; import com.xkrs.dao.FirePointOrdinaryDao; -import com.xkrs.dao.FirePointPreciseDao; import com.xkrs.model.bean.DataWrapper2; import com.xkrs.model.entity.FirePointOrdinaryEntity; -import com.xkrs.model.entity.FirePointPreciseEntity; import org.springframework.data.jpa.domain.Specification; import javax.persistence.criteria.Predicate; @@ -32,43 +30,18 @@ public class FirePointFilterUtils { return new DataWrapper2<>(Boolean.TRUE, ""); } - public static DataWrapper2 checkDuplicated(FirePointOrdinaryDao firePointDao, FirePointOrdinaryEntity firePointEntity) { + public static boolean 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, ""); + return list.size() > 0; } - 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, ""); - } }