From c1d7e65756b72345a31faa45c5b5120c2ce5a542 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 2 Jun 2022 10:06:59 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=A6=82=E6=9E=9C=E6=98=AF=E5=B1=B1?= =?UTF-8?q?=E4=B8=9C=E7=9A=84=E7=81=AB=E7=82=B9=EF=BC=8C2=E3=80=81?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=BC=80=E5=85=B3=E5=B7=B2=E6=89=93=E5=BC=80?= =?UTF-8?q?=EF=BC=8C=E9=82=A3=E4=B9=88=E5=B0=B1=E6=8A=8A=E7=81=AB=E7=82=B9?= =?UTF-8?q?=E8=BD=AC=E5=AD=98=E5=88=B0=E5=B1=B1=E4=B8=9C=E7=81=AB=E7=82=B9?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E5=90=A6=E5=88=99=E5=B0=B1=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=AD=98=E5=88=B0=E7=81=AB=E7=82=B9=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/SettingController.java | 18 +- .../com/xkrs/dao/ShanDongFirePointDao.java | 19 ++ .../model/entity/ShanDongFirePointEntity.java | 292 ++++++++++++++++++ .../service/impl/FirePointServiceImpl.java | 124 ++++++-- 4 files changed, 418 insertions(+), 35 deletions(-) create mode 100644 src/main/java/com/xkrs/dao/ShanDongFirePointDao.java create mode 100644 src/main/java/com/xkrs/model/entity/ShanDongFirePointEntity.java diff --git a/src/main/java/com/xkrs/controller/SettingController.java b/src/main/java/com/xkrs/controller/SettingController.java index afe05e5..7ec1074 100644 --- a/src/main/java/com/xkrs/controller/SettingController.java +++ b/src/main/java/com/xkrs/controller/SettingController.java @@ -6,6 +6,7 @@ import com.xkrs.model.entity.SettingEntity; import com.xkrs.model.qo.SettingQo; import org.apache.http.util.TextUtils; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @@ -40,9 +41,22 @@ public class SettingController { settingDao.save(settingEntity); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale); } - SettingEntity settingEntity = settingEntityList.get(0); - settingDao.updateSwitchStateById(settingEntity.getId(), settingQo.getSwitchState()); + for (SettingEntity settingEntity : settingEntityList) { + settingDao.updateSwitchStateById(settingEntity.getId(), settingQo.getSwitchState()); + } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale); } + @GetMapping("/queryswitchstate") + public String querySwitchState() { + Locale locale = LocaleContextHolder.getLocale(); + List settingEntityList = settingDao.findAll(); + if (settingEntityList.isEmpty()) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有状态信息", locale); + } + SettingEntity settingEntity = settingEntityList.get(0); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, settingEntity.getSwitchState(), locale); + } + + } diff --git a/src/main/java/com/xkrs/dao/ShanDongFirePointDao.java b/src/main/java/com/xkrs/dao/ShanDongFirePointDao.java new file mode 100644 index 0000000..7afad1c --- /dev/null +++ b/src/main/java/com/xkrs/dao/ShanDongFirePointDao.java @@ -0,0 +1,19 @@ +package com.xkrs.dao; + +import com.xkrs.model.entity.ShanDongFirePointEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Component; + +@Component +public interface ShanDongFirePointDao extends JpaRepository, JpaSpecificationExecutor { + + /** + * 根据火点编码查询火点信息 + * + * @param fireCode + * @return + */ + ShanDongFirePointEntity findByFireCode(String fireCode); + +} diff --git a/src/main/java/com/xkrs/model/entity/ShanDongFirePointEntity.java b/src/main/java/com/xkrs/model/entity/ShanDongFirePointEntity.java new file mode 100644 index 0000000..97ab427 --- /dev/null +++ b/src/main/java/com/xkrs/model/entity/ShanDongFirePointEntity.java @@ -0,0 +1,292 @@ +package com.xkrs.model.entity; + +import javax.persistence.*; +import java.io.Serializable; + +/** + * @author XinYi Song + */ +@Entity +@Table(name = "fire_point_shandong") +public class ShanDongFirePointEntity implements Serializable { + + /** + * 指定主键,建立自增序列,主键值取自序列 + */ + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "fire_point_shandong_seq_gen") + @SequenceGenerator(name = "fire_point_shandong_seq_gen", sequenceName = "fire_point_shandong_id_seq", allocationSize = 1) + private Integer id; + + /** + * 火点编码 + */ + @Column(length = 32, unique = true, columnDefinition = "varchar(32)") + private String fireCode; + + /** + * 经度 + */ + private double longitude; + + /** + * 纬度 + */ + private double latitude; + + /** + * 省市区的编码 + */ + @Column(length = 32, columnDefinition = "varchar(32)") + private String countyCode; + + /** + * 省市区的名称 + */ + @Column(columnDefinition = "varchar(64)") + private String countyName; + + /** + * 卫星监测的时间 + */ + private String satelliteTime; + + /** + * 卫星的类型 + */ + @Column(columnDefinition = "varchar(64)") + private String satelliteType; + + /** + * 植被类型 + */ + @Column(columnDefinition = "varchar(64)") + private String landType; + + /** + * 添加的时间 + */ + private String addTime; + + /** + * 置信度 + */ + @Column(length = 32, columnDefinition = "varchar(32)") + private String confidence; + + /** + * 详细地址 + */ + private String firePointAddress; + + /** + * 火点状态 0 发现 1预警 2核查 -1,3结案 + */ + @Column(length = 32, columnDefinition = "varchar(32)") + private String fireType; + + /** + * 当前火点的图片 + */ + private String fireImage; + + /** + * 卫星影像图片 + */ + private String satelliteImage; + + /** + * 火点前的图片 + */ + private String beforeFireImage; + + /** + * 火点后的图片 + */ + private String afterFireImage; + + /** + * 街道编码 + */ + @Column(length = 65, columnDefinition = "varchar(65)") + private String streetCode; + + @Column(length = 65, columnDefinition = "varchar(85)") + private String streetName; + + /** + * 0:未审核 + * 1:审核通过 + * 2:审核不通过 + */ + @Column(length = 65, columnDefinition = "varchar(85)") + private String verifyState; + + public ShanDongFirePointEntity() { + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getFireCode() { + return fireCode; + } + + public void setFireCode(String fireCode) { + this.fireCode = fireCode; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public String getCountyCode() { + return countyCode; + } + + public void setCountyCode(String countyCode) { + this.countyCode = countyCode; + } + + public String getCountyName() { + return countyName; + } + + public void setCountyName(String countyName) { + this.countyName = countyName; + } + + public String getSatelliteTime() { + return satelliteTime; + } + + public void setSatelliteTime(String satelliteTime) { + this.satelliteTime = satelliteTime; + } + + public String getSatelliteType() { + return satelliteType; + } + + public void setSatelliteType(String satelliteType) { + this.satelliteType = satelliteType; + } + + public String getLandType() { + return landType; + } + + public void setLandType(String landType) { + this.landType = landType; + } + + public String getAddTime() { + return addTime; + } + + public void setAddTime(String addTime) { + this.addTime = addTime; + } + + public String getConfidence() { + return confidence; + } + + public void setConfidence(String confidence) { + this.confidence = confidence; + } + + public String getFirePointAddress() { + return firePointAddress; + } + + public void setFirePointAddress(String firePointAddress) { + this.firePointAddress = firePointAddress; + } + + public String getFireType() { + return fireType; + } + + public void setFireType(String fireType) { + this.fireType = fireType; + } + + public String getFireImage() { + return fireImage; + } + + public void setFireImage(String fireImage) { + this.fireImage = fireImage; + } + + public String getSatelliteImage() { + return satelliteImage; + } + + public void setSatelliteImage(String satelliteImage) { + this.satelliteImage = satelliteImage; + } + + public String getBeforeFireImage() { + return beforeFireImage; + } + + public void setBeforeFireImage(String beforeFireImage) { + this.beforeFireImage = beforeFireImage; + } + + public String getAfterFireImage() { + return afterFireImage; + } + + public void setAfterFireImage(String afterFireImage) { + this.afterFireImage = afterFireImage; + } + + public String getStreetCode() { + return streetCode; + } + + public void setStreetCode(String streetCode) { + this.streetCode = streetCode; + } + + public String getStreetName() { + return streetName; + } + + public void setStreetName(String streetName) { + this.streetName = streetName; + } + + public String getVerifyState() { + return verifyState; + } + + public void setVerifyState(String verifyState) { + this.verifyState = verifyState; + } + + @Override + public String toString() { + return "ShanDongFirePointEntity{" + "id=" + id + ", fireCode='" + fireCode + '\'' + ", longitude=" + longitude + ", latitude=" + latitude + ", countyCode='" + countyCode + '\'' + ", countyName='" + countyName + '\'' + ", satelliteTime='" + satelliteTime + '\'' + ", satelliteType='" + satelliteType + '\'' + ", landType='" + landType + '\'' + ", addTime='" + addTime + '\'' + ", confidence='" + confidence + '\'' + ", firePointAddress='" + firePointAddress + '\'' + ", fireType='" + fireType + '\'' + ", fireImage='" + fireImage + '\'' + ", satelliteImage='" + satelliteImage + '\'' + ", beforeFireImage='" + beforeFireImage + '\'' + ", afterFireImage='" + afterFireImage + '\'' + ", streetCode='" + streetCode + '\'' + ", streetName='" + streetName + '\'' + ", verifyState='" + verifyState + '\'' + '}'; + } +} diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index e8efa0e..4de09ab 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -42,6 +42,12 @@ public class FirePointServiceImpl implements FirePointService { @Resource private FirePointDao firePointDao; + @Resource + private SettingDao settingDao; + + @Resource + private ShanDongFirePointDao shanDongFirePointDao; + @Resource private Query query; @@ -87,43 +93,96 @@ public class FirePointServiceImpl implements FirePointService { @CacheEvict(value = "FirePointServiceCache", allEntries = true) @Override public FirePointEntity insertFirePoint(FirePointQo firePointQo) { - FirePointEntity firePointEntity = new FirePointEntity(); if (firePointQo.getLandtype().equals("水体")) { return null; - } else if ("Himawari 8".equals(firePointQo.getSatelliteType()) && "L".equals(firePointQo.getConfidence())) { - return null; - } else if ("Himawari 8".equals(firePointQo.getSatelliteType()) && "N".equals(firePointQo.getConfidence())) { - return null; - } else { - FirePointEntity existFireCode = firePointDao.findByFireCode(firePointQo.getFireCode()); - if (existFireCode != null) { - return null; - } - firePointEntity.setFireCode(firePointQo.getFireCode()); - firePointEntity.setCountyCode(firePointQo.getCountyCode().toString()); - firePointEntity.setCountyName(firePointQo.getCountyName()); - firePointEntity.setSatelliteTime(DateTimeUtil.timeMillisToString(firePointQo.getSatelliteTimeTs().longValue())); - firePointEntity.setLongitude(firePointQo.getLongitude()); - firePointEntity.setLatitude(firePointQo.getLatitude()); - firePointEntity.setFirePointAddress(AddressUtils.getLocal(firePointQo.getLatitude().toString(), firePointQo.getLongitude().toString())); - firePointEntity.setSatelliteType(firePointQo.getSatelliteType()); - firePointEntity.setLandType(firePointQo.getLandtype()); - firePointEntity.setConfidence(firePointQo.getConfidence()); - firePointEntity.setAddTime(DateTimeUtil.dateTimeToString(LocalDateTime.now())); - firePointEntity.setFireType("0"); - firePointEntity.setFireImage(firePointQo.getFireImage()); - firePointEntity.setSatelliteImage(firePointQo.getSatelliteImage()); - try { - bindStreetCodeName(firePointEntity); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("添加火点信息 逆地理编码请求街道编号失败:" + e.getMessage()); - } - log.info("-------发现新火点"); - return firePointDao.save(firePointEntity); } + if ("Himawari 8".equals(firePointQo.getSatelliteType()) && "L".equals(firePointQo.getConfidence())) { + return null; + } + if ("Himawari 8".equals(firePointQo.getSatelliteType()) && "N".equals(firePointQo.getConfidence())) { + return null; + } + FirePointEntity firePointEntity = new FirePointEntity(); + firePointEntity.setFireCode(firePointQo.getFireCode()); + firePointEntity.setCountyCode(firePointQo.getCountyCode().toString()); + firePointEntity.setCountyName(firePointQo.getCountyName()); + firePointEntity.setSatelliteTime(DateTimeUtil.timeMillisToString(firePointQo.getSatelliteTimeTs().longValue())); + firePointEntity.setLongitude(firePointQo.getLongitude()); + firePointEntity.setLatitude(firePointQo.getLatitude()); + firePointEntity.setFirePointAddress(AddressUtils.getLocal(firePointQo.getLatitude().toString(), firePointQo.getLongitude().toString())); + firePointEntity.setSatelliteType(firePointQo.getSatelliteType()); + firePointEntity.setLandType(firePointQo.getLandtype()); + firePointEntity.setConfidence(firePointQo.getConfidence()); + firePointEntity.setAddTime(DateTimeUtil.dateTimeToString(LocalDateTime.now())); + firePointEntity.setFireType("0"); + firePointEntity.setFireImage(firePointQo.getFireImage()); + firePointEntity.setSatelliteImage(firePointQo.getSatelliteImage()); + try { + bindStreetCodeName(firePointEntity); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("添加火点信息 逆地理编码请求街道编号失败:" + e.getMessage()); + } + //1、如果是山东的火点,2、同时开关已打开,那么就把火点转存到山东火点表,否则就直接存到火点表 + if (firePointEntity.getCountyCode().startsWith("37") && isSwitchStateOpen()) { + return saveToShanDongFirePoint(firePointEntity); + } + FirePointEntity existFireCode = firePointDao.findByFireCode(firePointEntity.getFireCode()); + if (existFireCode != null) { + return null; + } + log.info("-------发现新火点"); + return firePointDao.save(firePointEntity); } + /** + * 返回开关是否为打开状态 + * + * @return true:已打开,false:已关闭 + */ + private boolean isSwitchStateOpen() { + List settingEntityList = settingDao.findAll(); + if (settingEntityList.isEmpty()) { + return false; + } + SettingEntity settingEntity = settingEntityList.get(0); + return "1".equals(settingEntity.getSwitchState()); + } + + /** + * 保存到山东火点表 + */ + private FirePointEntity saveToShanDongFirePoint(FirePointEntity firePointEntity) { + ShanDongFirePointEntity existFireCode = shanDongFirePointDao.findByFireCode(firePointEntity.getFireCode()); + if (existFireCode != null) { + return null; + } + ShanDongFirePointEntity shanDongFirePointEntity = new ShanDongFirePointEntity(); + shanDongFirePointEntity.setFireCode(firePointEntity.getFireCode()); + shanDongFirePointEntity.setCountyCode(firePointEntity.getCountyCode()); + shanDongFirePointEntity.setCountyName(firePointEntity.getCountyName()); + shanDongFirePointEntity.setSatelliteTime(firePointEntity.getSatelliteTime()); + shanDongFirePointEntity.setLongitude(firePointEntity.getLongitude()); + shanDongFirePointEntity.setLatitude(firePointEntity.getLatitude()); + shanDongFirePointEntity.setFirePointAddress(firePointEntity.getFirePointAddress()); + shanDongFirePointEntity.setSatelliteType(firePointEntity.getSatelliteType()); + shanDongFirePointEntity.setLandType(firePointEntity.getLandType()); + shanDongFirePointEntity.setConfidence(firePointEntity.getConfidence()); + shanDongFirePointEntity.setAddTime(firePointEntity.getAddTime()); + shanDongFirePointEntity.setFireType(firePointEntity.getFireType()); + shanDongFirePointEntity.setFireImage(firePointEntity.getFireImage()); + shanDongFirePointEntity.setSatelliteImage(firePointEntity.getSatelliteImage()); + shanDongFirePointEntity.setStreetCode(firePointEntity.getStreetCode()); + shanDongFirePointEntity.setStreetName(firePointEntity.getStreetName()); + shanDongFirePointEntity.setVerifyState("0"); + log.info("-------发现山东新火点"); + shanDongFirePointDao.save(shanDongFirePointEntity); + return new FirePointEntity(); + } + + /** + * 为实体类设置街道编号和街道名称 + */ private void bindStreetCodeName(FirePointEntity firePointEntity) throws Exception { List locationList = new ArrayList<>(); locationList.add(firePointEntity.getLongitude() + "," + firePointEntity.getLatitude()); @@ -139,7 +198,6 @@ public class FirePointServiceImpl implements FirePointService { } } - /** * 查询今天的火点信息 */