This commit is contained in:
liuchengqian 2023-03-05 14:07:21 +08:00
parent 087118421b
commit 7be85ebda4

View File

@ -5,6 +5,11 @@ import com.xkrs.straw.dao.FirePointPreciseDao;
import com.xkrs.straw.model.bean.DataWrapper2; import com.xkrs.straw.model.bean.DataWrapper2;
import com.xkrs.straw.model.entity.FirePointOrdinaryEntity; import com.xkrs.straw.model.entity.FirePointOrdinaryEntity;
import com.xkrs.straw.model.entity.FirePointPreciseEntity; 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 { public class FirePointFilterUtils {
@ -27,28 +32,43 @@ public class FirePointFilterUtils {
return new DataWrapper2<>(Boolean.TRUE, ""); return new DataWrapper2<>(Boolean.TRUE, "");
} }
public static DataWrapper2<Boolean, String> checkDuplicated(FirePointOrdinaryDao firePointOrdinaryDao, FirePointOrdinaryEntity firePointOrdinaryEntity) { public static DataWrapper2<Boolean, String> checkDuplicated(FirePointOrdinaryDao firePointDao, FirePointOrdinaryEntity firePointEntity) {
/** Specification<FirePointOrdinaryEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
* private boolean checkDuplicatedData(FirePointEntity firePointEntity) { List<Predicate> predicateList = new ArrayList<>();
* List<FirePointEntity> duplicatedDataList = firePointDao.findDuplicatedData(firePointEntity.getLongitude(), firePointEntity.getLatitude(), firePointEntity.getStreetCode(), firePointEntity.getSatelliteTime(), firePointEntity.getSatelliteType(), firePointEntity.getLandType()); predicateList.add(criteriaBuilder.equal(root.get("longitude").as(Double.class), firePointEntity.getLongitude()));
* return duplicatedDataList != null && duplicatedDataList.size() > 0; 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()));
@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) predicateList.add(criteriaBuilder.equal(root.get("satelliteTime").as(String.class), firePointEntity.getSatelliteTime()));
List<FirePointEntity> findDuplicatedData(double longitude, double latitude, String streetCode, String satelliteTime, String satelliteType, String landType); predicateList.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), firePointEntity.getSatelliteType()));
predicateList.add(criteriaBuilder.equal(root.get("landType").as(String.class), firePointEntity.getLandType()));
if (checkDuplicatedData(firePointEntity)) { return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
log.info("-------该火点和历史火点重复,不入库"); };
return false; List<FirePointOrdinaryEntity> list = firePointDao.findAll(specification);
} if (list.size() > 0) {
*/ return new DataWrapper2<>(Boolean.TRUE, "该火点和历史火点重复,不入库");
return null; }
return new DataWrapper2<>(Boolean.FALSE, "");
} }
public static DataWrapper2<Boolean, String> checkDuplicated(FirePointPreciseDao firePointDao, FirePointPreciseEntity firePointEntity) {
public static DataWrapper2<Boolean, String> checkDuplicated(FirePointPreciseDao firePointPreciseDao, FirePointPreciseEntity firePointPreciseEntity) { Specification<FirePointPreciseEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
return null; 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, "");
} }
} }