火点重构-尽早检查重复数据,减少不必要操作
This commit is contained in:
parent
affcfbc474
commit
ce85cf0b42
@ -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<Boolean, String> checkDuplicatedWrapper1 = FirePointFilterUtils.checkDuplicated(firePointOrdinaryDao, firePointOrdinaryEntity);
|
||||
if (checkDuplicatedWrapper1.getData1()) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, checkDuplicatedWrapper1.getData2(), locale);
|
||||
}
|
||||
firePointOrdinaryDao.save(firePointOrdinaryEntity);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale);
|
||||
}
|
||||
|
@ -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<Boolean, String> checkDuplicated(FirePointOrdinaryDao firePointDao, FirePointOrdinaryEntity firePointEntity) {
|
||||
public static boolean checkDuplicated(FirePointOrdinaryDao firePointDao, FirePointOrdinaryEntity firePointEntity) {
|
||||
Specification<FirePointOrdinaryEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
|
||||
List<Predicate> 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<FirePointOrdinaryEntity> 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<Boolean, String> checkDuplicated(FirePointPreciseDao firePointDao, FirePointPreciseEntity firePointEntity) {
|
||||
Specification<FirePointPreciseEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
|
||||
List<Predicate> 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<FirePointPreciseEntity> list = firePointDao.findAll(specification);
|
||||
if (list.size() > 0) {
|
||||
return new DataWrapper2<>(Boolean.TRUE, "该火点和历史火点重复,不入库");
|
||||
}
|
||||
return new DataWrapper2<>(Boolean.FALSE, "");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user