diff --git a/src/main/java/com/xkrs/dao/FirePointDao.java b/src/main/java/com/xkrs/dao/FirePointDao.java index ed710d3..c6ea710 100644 --- a/src/main/java/com/xkrs/dao/FirePointDao.java +++ b/src/main/java/com/xkrs/dao/FirePointDao.java @@ -22,6 +22,9 @@ public interface FirePointDao extends JpaRepository, JpaS */ FirePointEntity findByFireCode(String fireCode); + @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); + /** * 根据火点编码修改火点状态 */ diff --git a/src/main/java/com/xkrs/dao/ShanDongFirePointDao.java b/src/main/java/com/xkrs/dao/ShanDongFirePointDao.java index eb755d7..0811740 100644 --- a/src/main/java/com/xkrs/dao/ShanDongFirePointDao.java +++ b/src/main/java/com/xkrs/dao/ShanDongFirePointDao.java @@ -7,6 +7,8 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Component; +import java.util.List; + @Component public interface ShanDongFirePointDao extends JpaRepository, JpaSpecificationExecutor { @@ -18,6 +20,9 @@ public interface ShanDongFirePointDao extends JpaRepository findDuplicatedData(double longitude, double latitude, String streetCode, String satelliteTime, String satelliteType, String landType); + /** * 在山东临时火点表中根据火点编码修改审核状态 */ diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 4123640..3586fc2 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -126,13 +126,13 @@ public class FirePointServiceImpl implements FirePointService { bindAddress(firePointEntity); } catch (Exception e) { e.printStackTrace(); - System.out.println("添加火点信息 逆地理编码请求街道编号失败:" + e.getMessage()); + log.info("添加火点信息 逆地理编码请求街道编号失败:" + e.getMessage()); + return false; } if (firePointEntity.getCountyCode().startsWith("37")) { return false; } - FirePointEntity existFireCode = firePointDao.findByFireCode(firePointEntity.getFireCode()); - if (existFireCode != null) { + if (checkDuplicatedData(firePointEntity)) { return false; } log.info("-------发现新火点"); @@ -140,6 +140,39 @@ public class FirePointServiceImpl implements FirePointService { return true; } + /** + * 检查重复数据 + * + * @param firePointEntity 待入库实体类 + * @return true-是重复数据,拒绝入库;false-不是重复数据,可以入库 + */ + 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; + } + + /** + * 检查重复数据 + * + * @param shanDongFirePoint 待入库实体类 + * @return true-是重复数据,拒绝入库;false-不是重复数据,可以入库 + */ + private boolean checkDuplicatedDataX(ShanDongFirePointEntity shanDongFirePoint) { + List duplicatedDataList = firePointDao.findDuplicatedData(shanDongFirePoint.getLongitude(), shanDongFirePoint.getLatitude(), shanDongFirePoint.getStreetCode(), shanDongFirePoint.getSatelliteTime(), shanDongFirePoint.getSatelliteType(), shanDongFirePoint.getLandType()); + return duplicatedDataList != null && duplicatedDataList.size() > 0; + } + + /** + * 检查重复数据 + * + * @param shanDongFirePoint 待入库实体类 + * @return true-是重复数据,拒绝入库;false-不是重复数据,可以入库 + */ + private boolean checkDuplicatedData(ShanDongFirePointEntity shanDongFirePoint) { + List duplicatedDataList = shanDongFirePointDao.findDuplicatedData(shanDongFirePoint.getLongitude(), shanDongFirePoint.getLatitude(), shanDongFirePoint.getStreetCode(), shanDongFirePoint.getSatelliteTime(), shanDongFirePoint.getSatelliteType(), shanDongFirePoint.getLandType()); + return duplicatedDataList != null && duplicatedDataList.size() > 0; + } + /** * 添加火点信息 */ @@ -175,17 +208,17 @@ public class FirePointServiceImpl implements FirePointService { e.printStackTrace(); System.out.println("添加山东火点信息 逆地理编码请求街道编号失败:" + e.getMessage()); } + if (checkDuplicatedDataX(shanDongFirePoint) || checkDuplicatedData(shanDongFirePoint)) { + return false; + } //如果是山东的点,就入库 if (shanDongFirePoint.getCountyCode().startsWith("37")) { if (isSwitchStateOpen()) { //如果开关已打开,就只将未审核的火点添加到山东临时表 - if (shanDongFirePointDao.findByFireCode(shanDongFirePoint.getFireCode()) != null) { - //山东临时表已经有编号相同的火点存在,返回添加失败 - return false; - } log.info("-------发现新山东火点"); ShanDongFirePointEntity savedShanDongFirePoint = shanDongFirePointDao.save(shanDongFirePoint); - try {//微信消息通知火点审核工作组 + //微信消息通知火点审核工作组 + try { String messageContent = getMessageContent(savedShanDongFirePoint); WDWxSendMsgUtil.sendMsg("18447024917@chatroom", messageContent, 0); } catch (Exception e) { @@ -194,18 +227,9 @@ public class FirePointServiceImpl implements FirePointService { return true; } else { //如果开关已关闭,就将火点添加到山东临时表,同时自动审核通过添加到全国火点表 - if (shanDongFirePointDao.findByFireCode(shanDongFirePoint.getFireCode()) != null) { - //山东临时表已经有编号相同的火点存在,返回添加失败 - return false; - } - if (firePointDao.findByFireCode(shanDongFirePoint.getFireCode()) != null) { - //全国火点表已经有编号相同的火点存在,返回添加失败 - return false; - } log.info("-------发现新火点"); shanDongFirePoint.setVerifyState("1"); - ShanDongFirePointEntity savedShanDongFirePoint = shanDongFirePointDao.save(shanDongFirePoint); - + shanDongFirePointDao.save(shanDongFirePoint); FirePointEntity firePoint = getFirePointByShanDongFirePoint(shanDongFirePoint); log.info("-------转存新火点"); firePointDao.save(firePoint);