From 8b69e5a874a0b2782a07b0b1611fa3aaeac55e55 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Fri, 3 Feb 2023 10:17:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=8C=E7=81=AB=E7=82=B9?= =?UTF-8?q?=E6=B8=A0=E9=81=93=E5=85=A5=E5=BA=93=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/common/config/WebSecurityConfig.java | 1 + .../com/xkrs/sms/WeChatMessageHelper.java | 2 +- .../DispatchFirePointController.java | 10 +- .../straw/dao/FirePointChannelConfigDao.java | 10 + .../com/xkrs/straw/helper/GeoCodeHelper.java | 101 ++++++++ .../bean/FirePointChannelConfigBean.java | 67 ++++++ .../{ => straw}/model/bean/KeyValueBean.java | 2 +- .../entity/FirePointChannelConfigEntity.java | 50 ++++ .../model/entity/FirePointOrdinaryEntity.java | 60 ++++- .../model/entity/FirePointPreciseEntity.java | 60 ++++- .../service/DispatchFirePointService.java | 2 + .../impl/DispatchFirePointServiceImpl.java | 225 +++++++++++++----- .../straw/utils/DispatchFirePointUtils.java | 110 +++++++++ .../java/com/xkrs/straw/utils/JsonUtils.java | 39 +++ 14 files changed, 660 insertions(+), 79 deletions(-) create mode 100644 src/main/java/com/xkrs/straw/dao/FirePointChannelConfigDao.java create mode 100644 src/main/java/com/xkrs/straw/helper/GeoCodeHelper.java create mode 100644 src/main/java/com/xkrs/straw/model/bean/FirePointChannelConfigBean.java rename src/main/java/com/xkrs/{ => straw}/model/bean/KeyValueBean.java (94%) create mode 100644 src/main/java/com/xkrs/straw/model/entity/FirePointChannelConfigEntity.java create mode 100644 src/main/java/com/xkrs/straw/utils/DispatchFirePointUtils.java create mode 100644 src/main/java/com/xkrs/straw/utils/JsonUtils.java diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index 12a26ab..cc4d0f6 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -35,6 +35,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.OPTIONS).permitAll() .antMatchers("/global/configuration/**").permitAll() .antMatchers("/push/**").permitAll() + .antMatchers("/dispatch/**").permitAll() .antMatchers("/queryFirePoint").permitAll() .antMatchers(HttpMethod.POST, "/api/user/updateSysUser").permitAll() .antMatchers(HttpMethod.GET, "/selectGlobalConfigDict").permitAll() diff --git a/src/main/java/com/xkrs/sms/WeChatMessageHelper.java b/src/main/java/com/xkrs/sms/WeChatMessageHelper.java index 5194167..27f0804 100644 --- a/src/main/java/com/xkrs/sms/WeChatMessageHelper.java +++ b/src/main/java/com/xkrs/sms/WeChatMessageHelper.java @@ -1,11 +1,11 @@ package com.xkrs.sms; import com.xkrs.dao.GlobalConfigurationDao; -import com.xkrs.model.bean.KeyValueBean; import com.xkrs.model.entity.FirePointEntity; import com.xkrs.model.entity.GlobalConfigurationEntity; import com.xkrs.model.entity.SysUserEntity; import com.xkrs.service.GlobalConfigurationService; +import com.xkrs.straw.model.bean.KeyValueBean; import com.xkrs.utils.HttpClientUtils; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/xkrs/straw/controller/DispatchFirePointController.java b/src/main/java/com/xkrs/straw/controller/DispatchFirePointController.java index 98884f4..4166c34 100644 --- a/src/main/java/com/xkrs/straw/controller/DispatchFirePointController.java +++ b/src/main/java/com/xkrs/straw/controller/DispatchFirePointController.java @@ -6,14 +6,13 @@ import com.xkrs.straw.service.DispatchFirePointService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.Locale; @RestController +@RequestMapping(value = "/dispatch") public class DispatchFirePointController { public static Logger log = LoggerFactory.getLogger(FirePointServiceImpl.class); @@ -23,6 +22,11 @@ public class DispatchFirePointController { @Resource private DispatchFirePointService firePointService; + @GetMapping("/debug") + public String debug() { + return firePointService.debug(); + } + @PostMapping("/insertFirePointChannelOrdinary") public String insertFirePointChannelOrdinary(@RequestBody AllFirePointQo firePointQo) { return firePointService.insertFirePointChannelOrdinary(firePointQo); diff --git a/src/main/java/com/xkrs/straw/dao/FirePointChannelConfigDao.java b/src/main/java/com/xkrs/straw/dao/FirePointChannelConfigDao.java new file mode 100644 index 0000000..98f4e4e --- /dev/null +++ b/src/main/java/com/xkrs/straw/dao/FirePointChannelConfigDao.java @@ -0,0 +1,10 @@ +package com.xkrs.straw.dao; + +import com.xkrs.straw.model.entity.FirePointChannelConfigEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Component; + +@Component +public interface FirePointChannelConfigDao extends JpaRepository, JpaSpecificationExecutor { +} diff --git a/src/main/java/com/xkrs/straw/helper/GeoCodeHelper.java b/src/main/java/com/xkrs/straw/helper/GeoCodeHelper.java new file mode 100644 index 0000000..71e5b32 --- /dev/null +++ b/src/main/java/com/xkrs/straw/helper/GeoCodeHelper.java @@ -0,0 +1,101 @@ +package com.xkrs.straw.helper; + +import com.xkrs.model.vo.GaoDeIgGeocodeVo; +import com.xkrs.straw.service.impl.DispatchFirePointServiceImpl; +import com.xkrs.utils.GaoDeApiUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class GeoCodeHelper { + + public static Logger log = LoggerFactory.getLogger(DispatchFirePointServiceImpl.class); + private GaoDeIgGeocodeVo geocode; + + public void doGeoCode(Double longitude, Double latitude) { + try { + List locationList = new ArrayList<>(); + locationList.add(longitude + "," + latitude); + this.geocode = GaoDeApiUtil.geocode(locationList); + } catch (Exception e) { + e.printStackTrace(); + this.geocode = null; + } + } + + public String getCalCountyCode() { + try { + GaoDeIgGeocodeVo.Regeocode reGeoCode = geocode.getRegeocodes().get(0); + GaoDeIgGeocodeVo.AddressComponent addressComponent = reGeoCode.getAddressComponent().get(0); + return addressComponent.getAdcode(); + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + public String getCalCountyName() { + try { + GaoDeIgGeocodeVo.Regeocode reGeoCode = geocode.getRegeocodes().get(0); + GaoDeIgGeocodeVo.AddressComponent addressComponent = reGeoCode.getAddressComponent().get(0); + return addressComponent.getDistrict(); + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + public String getCalTownCode() { + try { + GaoDeIgGeocodeVo.Regeocode reGeoCode = geocode.getRegeocodes().get(0); + GaoDeIgGeocodeVo.AddressComponent addressComponent = reGeoCode.getAddressComponent().get(0); + String townCode = addressComponent.getTowncode(); + return townCode.length() > 9 ? townCode.substring(0, 9) : townCode; + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + public String getCalTownName() { + try { + GaoDeIgGeocodeVo.Regeocode reGeoCode = geocode.getRegeocodes().get(0); + GaoDeIgGeocodeVo.AddressComponent addressComponent = reGeoCode.getAddressComponent().get(0); + return addressComponent.getTownship(); + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + public String getCalFirePointAddress() { + try { + GaoDeIgGeocodeVo.Regeocode reGeoCode = geocode.getRegeocodes().get(0); + return reGeoCode.getFormatted_address(); + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + public boolean checkGeoCodeResult(String receivedCountyCode, String receivedCountyName, String receivedTownCode) { + String calCountyCode = getCalCountyCode(); + String calCountyName = getCalCountyName(); + String calTownCode = getCalTownCode(); + if (!calCountyCode.equals(receivedCountyCode)) { + log.info("-------逆地理编码校验失败:接收到的countyCode=" + receivedCountyCode + ",计算得到的countyCode=" + calCountyCode); + return false; + } + if (!calCountyName.equals(receivedCountyName)) { + log.info("-------逆地理编码校验失败:接收到的countyName=" + receivedCountyName + ",计算得到的countyName=" + calCountyName); + return false; + } + if (!calTownCode.equals(receivedTownCode)) { + log.info("-------逆地理编码校验失败:接收到的townCode=" + receivedTownCode + ",计算得到的townCode=" + calTownCode); + return false; + } + return true; + } +} diff --git a/src/main/java/com/xkrs/straw/model/bean/FirePointChannelConfigBean.java b/src/main/java/com/xkrs/straw/model/bean/FirePointChannelConfigBean.java new file mode 100644 index 0000000..e3efe9c --- /dev/null +++ b/src/main/java/com/xkrs/straw/model/bean/FirePointChannelConfigBean.java @@ -0,0 +1,67 @@ +package com.xkrs.straw.model.bean; + +import java.util.List; + +public class FirePointChannelConfigBean { + + public static final String Ordinary = "Ordinary"; + public static final String Precise = "Precise"; + + /** + * 渠道名称 + */ + private String channelName; + + /** + * 渠道配置列表 + */ + private List configList; + + /** + * 渠道配置 + */ + public static class ChannelConfig { + + /** + * 开始时间 + */ + private String startTime; + + /** + * 结束时间 + */ + private String endTime; + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + } + + public String getChannelName() { + return channelName; + } + + public void setChannelName(String channelName) { + this.channelName = channelName; + } + + public List getConfigList() { + return configList; + } + + public void setConfigList(List configList) { + this.configList = configList; + } +} diff --git a/src/main/java/com/xkrs/model/bean/KeyValueBean.java b/src/main/java/com/xkrs/straw/model/bean/KeyValueBean.java similarity index 94% rename from src/main/java/com/xkrs/model/bean/KeyValueBean.java rename to src/main/java/com/xkrs/straw/model/bean/KeyValueBean.java index 3380758..4054586 100644 --- a/src/main/java/com/xkrs/model/bean/KeyValueBean.java +++ b/src/main/java/com/xkrs/straw/model/bean/KeyValueBean.java @@ -1,4 +1,4 @@ -package com.xkrs.model.bean; +package com.xkrs.straw.model.bean; public class KeyValueBean { diff --git a/src/main/java/com/xkrs/straw/model/entity/FirePointChannelConfigEntity.java b/src/main/java/com/xkrs/straw/model/entity/FirePointChannelConfigEntity.java new file mode 100644 index 0000000..8a63f1a --- /dev/null +++ b/src/main/java/com/xkrs/straw/model/entity/FirePointChannelConfigEntity.java @@ -0,0 +1,50 @@ +package com.xkrs.straw.model.entity; + +import javax.persistence.*; +import java.io.Serializable; + +@Entity +@Table(name = "fire_point_channel_config") +public class FirePointChannelConfigEntity implements Serializable { + + /** + * 指定主键,建立自增序列,主键值取自序列 + */ + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "fire_point_ordinary_seq_gen") + @SequenceGenerator(name = "fire_point_ordinary_seq_gen", sequenceName = "fire_point_ordinary_id_seq", allocationSize = 1) + private Long id; + + /** + * Json配置内容 + */ + @Column(length = 1024, columnDefinition = "varchar(1024)") + private String jsonContent; + + public FirePointChannelConfigEntity() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getJsonContent() { + return jsonContent; + } + + public void setJsonContent(String jsonContent) { + this.jsonContent = jsonContent; + } + + @Override + public String toString() { + return "FirePointChannelConfigEntity{" + + "id=" + id + + ", jsonContent='" + jsonContent + '\'' + + '}'; + } +} diff --git a/src/main/java/com/xkrs/straw/model/entity/FirePointOrdinaryEntity.java b/src/main/java/com/xkrs/straw/model/entity/FirePointOrdinaryEntity.java index 4eedc84..6660d9d 100644 --- a/src/main/java/com/xkrs/straw/model/entity/FirePointOrdinaryEntity.java +++ b/src/main/java/com/xkrs/straw/model/entity/FirePointOrdinaryEntity.java @@ -16,90 +16,110 @@ public class FirePointOrdinaryEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "fire_point_ordinary_seq_gen") @SequenceGenerator(name = "fire_point_ordinary_seq_gen", sequenceName = "fire_point_ordinary_id_seq", allocationSize = 1) - private Integer id; + private Long id; /** * 火点编码 */ @Column(length = 32, unique = true, columnDefinition = "varchar(32)") private String fireCode; + /** * 省市区的编码 */ @Column(length = 32, columnDefinition = "varchar(32)") - private Long countyCode; + private String countyCode; + /** * 省市区的名称 */ @Column(length = 64, columnDefinition = "varchar(64)") private String countyName; + /** * 卫星监测的时间 */ @Column(length = 64, columnDefinition = "varchar(64)") private String satelliteTime; + /** * 经度 */ private Double longitude; + /** * 纬度 */ private Double latitude; + /** * 卫星类型 */ @Column(length = 64, columnDefinition = "varchar(64)") private String satelliteType; + /** * 植被类型 */ @Column(length = 64, columnDefinition = "varchar(64)") private String landType; + /** * 置信度 */ @Column(length = 32, columnDefinition = "varchar(32)") private String confidence; + /** * 当前火点的图片 */ @Column(length = 512, columnDefinition = "varchar(512)") private String fireImage; + /** * 卫星影像图片 */ @Column(length = 512, columnDefinition = "varchar(512)") private String satelliteImage; + /** * 乡镇街道的编码 */ @Column(length = 64, columnDefinition = "varchar(64)") private String townCode; + /** * 乡镇街道的名字 */ @Column(length = 85, columnDefinition = "varchar(85)") private String townName; + /** * 添加的时间 */ @Column(length = 64, columnDefinition = "varchar(64)") private String addTime; + /** * 详细地址 */ @Column(length = 255, columnDefinition = "varchar(255)") private String firePointAddress; + /** + * 备注 + */ + @Column(length = 1024, columnDefinition = "varchar(1024)") + private String remark; + public FirePointOrdinaryEntity() { } - public Integer getId() { + public Long getId() { return id; } - public void setId(Integer id) { + public void setId(Long id) { this.id = id; } @@ -111,11 +131,11 @@ public class FirePointOrdinaryEntity implements Serializable { this.fireCode = fireCode; } - public Long getCountyCode() { + public String getCountyCode() { return countyCode; } - public void setCountyCode(Long countyCode) { + public void setCountyCode(String countyCode) { this.countyCode = countyCode; } @@ -223,8 +243,34 @@ public class FirePointOrdinaryEntity implements Serializable { this.firePointAddress = firePointAddress; } + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + @Override public String toString() { - return "FirePointOrdinaryEntity{" + "id=" + id + ", fireCode='" + fireCode + '\'' + ", countyCode=" + countyCode + ", countyName='" + countyName + '\'' + ", satelliteTime='" + satelliteTime + '\'' + ", longitude=" + longitude + ", latitude=" + latitude + ", satelliteType='" + satelliteType + '\'' + ", landType='" + landType + '\'' + ", confidence='" + confidence + '\'' + ", fireImage='" + fireImage + '\'' + ", satelliteImage='" + satelliteImage + '\'' + ", townCode='" + townCode + '\'' + ", townName='" + townName + '\'' + ", addTime='" + addTime + '\'' + ", firePointAddress='" + firePointAddress + '\'' + '}'; + return "FirePointOrdinaryEntity{" + + "id=" + id + + ", fireCode='" + fireCode + '\'' + + ", countyCode='" + countyCode + '\'' + + ", countyName='" + countyName + '\'' + + ", satelliteTime='" + satelliteTime + '\'' + + ", longitude=" + longitude + + ", latitude=" + latitude + + ", satelliteType='" + satelliteType + '\'' + + ", landType='" + landType + '\'' + + ", confidence='" + confidence + '\'' + + ", fireImage='" + fireImage + '\'' + + ", satelliteImage='" + satelliteImage + '\'' + + ", townCode='" + townCode + '\'' + + ", townName='" + townName + '\'' + + ", addTime='" + addTime + '\'' + + ", firePointAddress='" + firePointAddress + '\'' + + ", remark='" + remark + '\'' + + '}'; } } diff --git a/src/main/java/com/xkrs/straw/model/entity/FirePointPreciseEntity.java b/src/main/java/com/xkrs/straw/model/entity/FirePointPreciseEntity.java index f713793..95ebe03 100644 --- a/src/main/java/com/xkrs/straw/model/entity/FirePointPreciseEntity.java +++ b/src/main/java/com/xkrs/straw/model/entity/FirePointPreciseEntity.java @@ -16,90 +16,110 @@ public class FirePointPreciseEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "fire_point_precise_seq_gen") @SequenceGenerator(name = "fire_point_precise_seq_gen", sequenceName = "fire_point_precise_id_seq", allocationSize = 1) - private Integer id; + private Long id; /** * 火点编码 */ @Column(length = 32, unique = true, columnDefinition = "varchar(32)") private String fireCode; + /** * 省市区的编码 */ @Column(length = 32, columnDefinition = "varchar(32)") - private Long countyCode; + private String countyCode; + /** * 省市区的名称 */ @Column(length = 64, columnDefinition = "varchar(64)") private String countyName; + /** * 卫星监测的时间 */ @Column(length = 64, columnDefinition = "varchar(64)") private String satelliteTime; + /** * 经度 */ private Double longitude; + /** * 纬度 */ private Double latitude; + /** * 卫星类型 */ @Column(length = 64, columnDefinition = "varchar(64)") private String satelliteType; + /** * 植被类型 */ @Column(length = 64, columnDefinition = "varchar(64)") private String landType; + /** * 置信度 */ @Column(length = 32, columnDefinition = "varchar(32)") private String confidence; + /** * 当前火点的图片 */ @Column(length = 512, columnDefinition = "varchar(512)") private String fireImage; + /** * 卫星影像图片 */ @Column(length = 512, columnDefinition = "varchar(512)") private String satelliteImage; + /** * 乡镇街道的编码 */ @Column(length = 64, columnDefinition = "varchar(64)") private String townCode; + /** * 乡镇街道的名字 */ @Column(length = 85, columnDefinition = "varchar(85)") private String townName; + /** * 添加的时间 */ @Column(length = 64, columnDefinition = "varchar(64)") private String addTime; + /** * 详细地址 */ @Column(length = 255, columnDefinition = "varchar(255)") private String firePointAddress; + /** + * 备注 + */ + @Column(length = 1024, columnDefinition = "varchar(1024)") + private String remark; + public FirePointPreciseEntity() { } - public Integer getId() { + public Long getId() { return id; } - public void setId(Integer id) { + public void setId(Long id) { this.id = id; } @@ -111,11 +131,11 @@ public class FirePointPreciseEntity implements Serializable { this.fireCode = fireCode; } - public Long getCountyCode() { + public String getCountyCode() { return countyCode; } - public void setCountyCode(Long countyCode) { + public void setCountyCode(String countyCode) { this.countyCode = countyCode; } @@ -223,8 +243,34 @@ public class FirePointPreciseEntity implements Serializable { this.firePointAddress = firePointAddress; } + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + @Override public String toString() { - return "FirePointPreciseEntity{" + "id=" + id + ", fireCode='" + fireCode + '\'' + ", countyCode=" + countyCode + ", countyName='" + countyName + '\'' + ", satelliteTime='" + satelliteTime + '\'' + ", longitude=" + longitude + ", latitude=" + latitude + ", satelliteType='" + satelliteType + '\'' + ", landType='" + landType + '\'' + ", confidence='" + confidence + '\'' + ", fireImage='" + fireImage + '\'' + ", satelliteImage='" + satelliteImage + '\'' + ", townCode='" + townCode + '\'' + ", townName='" + townName + '\'' + ", addTime='" + addTime + '\'' + ", firePointAddress='" + firePointAddress + '\'' + '}'; + return "FirePointPreciseEntity{" + + "id=" + id + + ", fireCode='" + fireCode + '\'' + + ", countyCode='" + countyCode + '\'' + + ", countyName='" + countyName + '\'' + + ", satelliteTime='" + satelliteTime + '\'' + + ", longitude=" + longitude + + ", latitude=" + latitude + + ", satelliteType='" + satelliteType + '\'' + + ", landType='" + landType + '\'' + + ", confidence='" + confidence + '\'' + + ", fireImage='" + fireImage + '\'' + + ", satelliteImage='" + satelliteImage + '\'' + + ", townCode='" + townCode + '\'' + + ", townName='" + townName + '\'' + + ", addTime='" + addTime + '\'' + + ", firePointAddress='" + firePointAddress + '\'' + + ", remark='" + remark + '\'' + + '}'; } } diff --git a/src/main/java/com/xkrs/straw/service/DispatchFirePointService.java b/src/main/java/com/xkrs/straw/service/DispatchFirePointService.java index f9af330..3ac0e55 100644 --- a/src/main/java/com/xkrs/straw/service/DispatchFirePointService.java +++ b/src/main/java/com/xkrs/straw/service/DispatchFirePointService.java @@ -4,6 +4,8 @@ import com.xkrs.straw.model.qo.AllFirePointQo; public interface DispatchFirePointService { + String debug(); + String insertFirePointChannelOrdinary(AllFirePointQo firePointQo); String insertFirePointChannelPrecise(AllFirePointQo firePointQo); diff --git a/src/main/java/com/xkrs/straw/service/impl/DispatchFirePointServiceImpl.java b/src/main/java/com/xkrs/straw/service/impl/DispatchFirePointServiceImpl.java index cfb7918..c4d36a1 100644 --- a/src/main/java/com/xkrs/straw/service/impl/DispatchFirePointServiceImpl.java +++ b/src/main/java/com/xkrs/straw/service/impl/DispatchFirePointServiceImpl.java @@ -1,56 +1,119 @@ package com.xkrs.straw.service.impl; +import com.xkrs.straw.dao.FirePointChannelConfigDao; import com.xkrs.straw.dao.FirePointOrdinaryDao; import com.xkrs.straw.dao.FirePointPreciseDao; +import com.xkrs.straw.helper.GeoCodeHelper; +import com.xkrs.straw.model.entity.FirePointChannelConfigEntity; +import com.xkrs.straw.model.entity.FirePointOrdinaryEntity; +import com.xkrs.straw.model.entity.FirePointPreciseEntity; import com.xkrs.straw.model.qo.AllFirePointQo; import com.xkrs.straw.service.DispatchFirePointService; +import com.xkrs.straw.utils.DispatchFirePointUtils; +import com.xkrs.utils.DateTimeUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.List; @Service public class DispatchFirePointServiceImpl implements DispatchFirePointService { + public static Logger log = LoggerFactory.getLogger(DispatchFirePointServiceImpl.class); + @Resource + private FirePointChannelConfigDao channelConfigDao; @Resource private FirePointOrdinaryDao firePointOrdinaryDao; private FirePointPreciseDao firePointPreciseDao; + @Override + public String debug() { + +// FirePointChannelConfigBean firePointChannelConfigBean = new FirePointChannelConfigBean(); +// firePointChannelConfigBean.setChannelName(FirePointChannelConfigBean.Precise); +// List configList = new ArrayList<>(); +// +// FirePointChannelConfigBean.ChannelConfig channelConfig1 = new FirePointChannelConfigBean.ChannelConfig(); +// channelConfig1.setStartTime("2022-01-01 00:00:00"); +// channelConfig1.setEndTime("2022-09-01 00:00:00"); +// configList.add(channelConfig1); +// +// FirePointChannelConfigBean.ChannelConfig channelConfig2 = new FirePointChannelConfigBean.ChannelConfig(); +// channelConfig2.setStartTime("2022-10-01 00:00:00"); +// channelConfig2.setEndTime("2022-11-01 00:00:00"); +// configList.add(channelConfig2); +// +// firePointChannelConfigBean.setConfigList(configList); +// String serialize = JsonUtils.serialize(firePointChannelConfigBean); +// FirePointChannelConfigEntity firePointChannelConfigEntity = new FirePointChannelConfigEntity(); +// firePointChannelConfigEntity.setJsonContent(serialize); +// channelConfigDao.save(firePointChannelConfigEntity); + return "null"; + } + @Override public String insertFirePointChannelOrdinary(AllFirePointQo firePointQo) { + String fireCode = firePointQo.getFireCode(); + Long countyCode = firePointQo.getCountyCode(); + String countyName = firePointQo.getCountyName(); + Long satelliteTimeTs = firePointQo.getSatelliteTimeTs(); + Double longitude = firePointQo.getLongitude(); + Double latitude = firePointQo.getLatitude(); + String satelliteType = firePointQo.getSatelliteType(); + String landType = firePointQo.getLandType(); + String confidence = firePointQo.getConfidence(); + String fireImage = firePointQo.getFireImage(); + String satelliteImage = firePointQo.getSatelliteImage(); + String townCode = firePointQo.getTownCode(); - firePointQo.getFireCode(); - firePointQo.getCountyCode(); - firePointQo.getCountyName(); - firePointQo.getSatelliteTimeTs(); - firePointQo.getLongitude(); - firePointQo.getLatitude(); - firePointQo.getSatelliteType(); - firePointQo.getLandType(); - firePointQo.getConfidence(); - firePointQo.getFireImage(); - firePointQo.getSatelliteImage(); - firePointQo.getTownCode(); + LocalDateTime satelliteLocalDateTime = LocalDateTime.ofEpochSecond(satelliteTimeTs, 0, ZoneOffset.ofHours(8)); + String satelliteTime = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime);//卫星时间 + String addTime = DateTimeUtils.localDateTimeToString(LocalDateTime.now());//添加时间 + //普通渠道来的火点直接入库普通火点库 + FirePointOrdinaryEntity firePointOrdinaryEntity = new FirePointOrdinaryEntity(); + firePointOrdinaryEntity.setFireCode(fireCode); + firePointOrdinaryEntity.setCountyCode(String.valueOf(countyCode)); + firePointOrdinaryEntity.setCountyName(countyName); + firePointOrdinaryEntity.setSatelliteTime(satelliteTime); + firePointOrdinaryEntity.setLongitude(longitude); + firePointOrdinaryEntity.setLatitude(latitude); + firePointOrdinaryEntity.setSatelliteType(satelliteType); + firePointOrdinaryEntity.setLandType(landType); + firePointOrdinaryEntity.setConfidence(confidence); + firePointOrdinaryEntity.setFireImage(fireImage); + firePointOrdinaryEntity.setSatelliteImage(satelliteImage); + firePointOrdinaryEntity.setTownCode(townCode); + firePointOrdinaryEntity.setAddTime(addTime); + bindFirePointAddress(firePointOrdinaryEntity); + firePointOrdinaryDao.save(firePointOrdinaryEntity); -// FirePointOrdinaryEntity firePointOrdinaryEntity = new FirePointOrdinaryEntity(); -// firePointOrdinaryEntity.setFireCode(); -// firePointOrdinaryEntity.setCountyCode(); -// firePointOrdinaryEntity.setCountyName(); -// firePointOrdinaryEntity.setSatelliteTime(); -// firePointOrdinaryEntity.setLongitude(); -// firePointOrdinaryEntity.setLatitude(); -// firePointOrdinaryEntity.setSatelliteType(); -// firePointOrdinaryEntity.setLandType(); -// firePointOrdinaryEntity.setConfidence(); -// firePointOrdinaryEntity.setFireImage(); -// firePointOrdinaryEntity.setSatelliteImage(); -// firePointOrdinaryEntity.setTownCode(); -// firePointOrdinaryEntity.setTownName(); -// firePointOrdinaryEntity.setAddTime(); -// firePointOrdinaryEntity.setFirePointAddress(); -// firePointOrdinaryDao.save(firePointOrdinaryEntity); - + List firePointChannelConfigEntityList = channelConfigDao.findAll(); + boolean inPreciseTimeRange = DispatchFirePointUtils.checkIfInPreciseTimeRange(satelliteLocalDateTime, firePointChannelConfigEntityList); + //如果现在不属于精准渠道的时间范围,那么普通渠道来的火点就入库精准火点库 + if (!inPreciseTimeRange) { + FirePointPreciseEntity firePointPreciseEntity = new FirePointPreciseEntity(); + firePointPreciseEntity.setFireCode(fireCode); + firePointPreciseEntity.setCountyCode(String.valueOf(countyCode)); + firePointPreciseEntity.setCountyName(countyName); + firePointPreciseEntity.setSatelliteTime(satelliteTime); + firePointPreciseEntity.setLongitude(longitude); + firePointPreciseEntity.setLatitude(latitude); + firePointPreciseEntity.setSatelliteType(satelliteType); + firePointPreciseEntity.setLandType(landType); + firePointPreciseEntity.setConfidence(confidence); + firePointPreciseEntity.setFireImage(fireImage); + firePointPreciseEntity.setSatelliteImage(satelliteImage); + firePointPreciseEntity.setTownCode(townCode); + firePointPreciseEntity.setAddTime(addTime); + bindFirePointAddress(firePointPreciseEntity); + firePointPreciseDao.save(firePointPreciseEntity); + } return null; } @@ -58,40 +121,82 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService { @Override public String insertFirePointChannelPrecise(AllFirePointQo firePointQo) { - firePointQo.getFireCode(); - firePointQo.getCountyCode(); - firePointQo.getCountyName(); - firePointQo.getSatelliteTimeTs(); - firePointQo.getLongitude(); - firePointQo.getLatitude(); - firePointQo.getSatelliteType(); - firePointQo.getLandType(); - firePointQo.getConfidence(); - firePointQo.getFireImage(); - firePointQo.getSatelliteImage(); - firePointQo.getTownCode(); + String fireCode = firePointQo.getFireCode(); + Long countyCode = firePointQo.getCountyCode(); + String countyName = firePointQo.getCountyName(); + Long satelliteTimeTs = firePointQo.getSatelliteTimeTs(); + Double longitude = firePointQo.getLongitude(); + Double latitude = firePointQo.getLatitude(); + String satelliteType = firePointQo.getSatelliteType(); + String landType = firePointQo.getLandType(); + String confidence = firePointQo.getConfidence(); + String fireImage = firePointQo.getFireImage(); + String satelliteImage = firePointQo.getSatelliteImage(); + String townCode = firePointQo.getTownCode(); + LocalDateTime satelliteLocalDateTime = LocalDateTime.ofEpochSecond(satelliteTimeTs, 0, ZoneOffset.ofHours(8)); + String satelliteTime = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime);//卫星时间 + String addTime = DateTimeUtils.localDateTimeToString(LocalDateTime.now());//添加时间 -// FirePointPreciseEntity firePointPreciseEntity = new FirePointPreciseEntity(); -// firePointPreciseEntity.setFireCode(); -// firePointPreciseEntity.setCountyCode(); -// firePointPreciseEntity.setCountyName(); -// firePointPreciseEntity.setSatelliteTime(); -// firePointPreciseEntity.setLongitude(); -// firePointPreciseEntity.setLatitude(); -// firePointPreciseEntity.setSatelliteType(); -// firePointPreciseEntity.setLandType(); -// firePointPreciseEntity.setConfidence(); -// firePointPreciseEntity.setFireImage(); -// firePointPreciseEntity.setSatelliteImage(); -// firePointPreciseEntity.setTownCode(); -// firePointPreciseEntity.setTownName(); -// firePointPreciseEntity.setAddTime(); -// firePointPreciseEntity.setFirePointAddress(); -// firePointPreciseDao.save(firePointPreciseEntity); - + List firePointChannelConfigEntityList = channelConfigDao.findAll(); + boolean inPreciseTimeRange = DispatchFirePointUtils.checkIfInPreciseTimeRange(satelliteLocalDateTime, firePointChannelConfigEntityList); + //如果现在属于精准渠道的时间范围,那么精准渠道来的火点就入库精准火点库 + if (inPreciseTimeRange) { + FirePointPreciseEntity firePointPreciseEntity = new FirePointPreciseEntity(); + firePointPreciseEntity.setFireCode(fireCode); + firePointPreciseEntity.setCountyCode(String.valueOf(countyCode)); + firePointPreciseEntity.setCountyName(countyName); + firePointPreciseEntity.setSatelliteTime(satelliteTime); + firePointPreciseEntity.setLongitude(longitude); + firePointPreciseEntity.setLatitude(latitude); + firePointPreciseEntity.setSatelliteType(satelliteType); + firePointPreciseEntity.setLandType(landType); + firePointPreciseEntity.setConfidence(confidence); + firePointPreciseEntity.setFireImage(fireImage); + firePointPreciseEntity.setSatelliteImage(satelliteImage); + firePointPreciseEntity.setTownCode(townCode); + firePointPreciseEntity.setAddTime(addTime); + bindFirePointAddress(firePointPreciseEntity); + firePointPreciseDao.save(firePointPreciseEntity); + } return null; } + private void bindFirePointAddress(FirePointPreciseEntity firePointPreciseEntity) { + String countyCode = firePointPreciseEntity.getCountyCode(); + String countyName = firePointPreciseEntity.getCountyName(); + String townCode = firePointPreciseEntity.getTownCode(); + GeoCodeHelper geoCodeHelper = new GeoCodeHelper(); + geoCodeHelper.doGeoCode(firePointPreciseEntity.getLongitude(), firePointPreciseEntity.getLatitude()); + boolean geoCodeResult = geoCodeHelper.checkGeoCodeResult(countyCode, countyName, townCode); + if (geoCodeResult) { + firePointPreciseEntity.setTownCode(geoCodeHelper.getCalTownCode()); + firePointPreciseEntity.setTownName(geoCodeHelper.getCalTownName()); + firePointPreciseEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress()); + firePointPreciseEntity.setRemark(""); + } else { + String remark = "接收到的countyCode=" + countyCode + ",计算得到的countyCode=" + geoCodeHelper.getCalCountyCode() + "。接收到的countyName=" + countyName + ",计算得到的countyName=" + geoCodeHelper.getCalCountyName() + "。接收到的townCode=" + townCode + ",计算得到的townCode=" + geoCodeHelper.getCalTownCode() + "。"; + firePointPreciseEntity.setRemark(remark); + } + } + + private void bindFirePointAddress(FirePointOrdinaryEntity firePointOrdinaryEntity) { + String countyCode = firePointOrdinaryEntity.getCountyCode(); + String countyName = firePointOrdinaryEntity.getCountyName(); + String townCode = firePointOrdinaryEntity.getTownCode(); + GeoCodeHelper geoCodeHelper = new GeoCodeHelper(); + geoCodeHelper.doGeoCode(firePointOrdinaryEntity.getLongitude(), firePointOrdinaryEntity.getLatitude()); + boolean geoCodeResult = geoCodeHelper.checkGeoCodeResult(countyCode, countyName, townCode); + if (geoCodeResult) { + firePointOrdinaryEntity.setTownCode(geoCodeHelper.getCalTownCode()); + firePointOrdinaryEntity.setTownName(geoCodeHelper.getCalTownName()); + firePointOrdinaryEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress()); + firePointOrdinaryEntity.setRemark(""); + } else { + String remark = "接收到的countyCode=" + countyCode + ",计算得到的countyCode=" + geoCodeHelper.getCalCountyCode() + "。接收到的countyName=" + countyName + ",计算得到的countyName=" + geoCodeHelper.getCalCountyName() + "。接收到的townCode=" + townCode + ",计算得到的townCode=" + geoCodeHelper.getCalTownCode() + "。"; + firePointOrdinaryEntity.setRemark(remark); + } + } + } diff --git a/src/main/java/com/xkrs/straw/utils/DispatchFirePointUtils.java b/src/main/java/com/xkrs/straw/utils/DispatchFirePointUtils.java new file mode 100644 index 0000000..5670562 --- /dev/null +++ b/src/main/java/com/xkrs/straw/utils/DispatchFirePointUtils.java @@ -0,0 +1,110 @@ +package com.xkrs.straw.utils; + +import com.xkrs.straw.model.bean.FirePointChannelConfigBean; +import com.xkrs.straw.model.entity.FirePointChannelConfigEntity; +import com.xkrs.straw.service.impl.DispatchFirePointServiceImpl; +import com.xkrs.utils.DateTimeUtils; +import org.apache.hc.core5.util.TextUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.time.LocalDateTime; +import java.util.List; + +public class DispatchFirePointUtils { + + public static Logger log = LoggerFactory.getLogger(DispatchFirePointServiceImpl.class); + + private DispatchFirePointUtils() { + } + + public static boolean checkIfInPreciseTimeRange(LocalDateTime satelliteLocalDateTime, List firePointChannelConfigEntityList) { + if (firePointChannelConfigEntityList == null || firePointChannelConfigEntityList.size() == 0) { + //TODO 报错,发短信通知我 + log.info("系统报错:checkIfInPreciseTimeRange firePointChannelConfigEntityList == null || firePointChannelConfigEntityList.size() == 0"); + return true; + } + for (FirePointChannelConfigEntity firePointChannelConfigEntity : firePointChannelConfigEntityList) { + String jsonContent = firePointChannelConfigEntity.getJsonContent(); + FirePointChannelConfigBean firePointChannelConfigBean = JsonUtils.deserialize(jsonContent, FirePointChannelConfigBean.class); + if (FirePointChannelConfigBean.Precise.equals(firePointChannelConfigBean.getChannelName())) { + List channelConfigList = firePointChannelConfigBean.getConfigList(); + if (channelConfigList == null || channelConfigList.size() == 0) { + //TODO 报错,发短信通知我 + log.info("系统报错:checkIfInPreciseTimeRange channelConfigList == null || channelConfigList.size() == 0"); + return true; + } + for (FirePointChannelConfigBean.ChannelConfig channelConfig : channelConfigList) { + //预处理开始时间 + String startTime = channelConfig.getStartTime();//获取精准火点渠道的开始时间 + boolean needCheckStartTime = !TextUtils.isEmpty(startTime); + LocalDateTime thisYearStartTime = null; + if (needCheckStartTime) { + thisYearStartTime = obtainLocalDateTimeThisYear(startTime); + needCheckStartTime = thisYearStartTime != null; + } + //预处理结束时间 + String endTime = channelConfig.getEndTime();//获取精准火点渠道的结束时间 + boolean needCheckEndTime = !TextUtils.isEmpty(endTime); + LocalDateTime thisYearEndTime = null; + if (needCheckEndTime) { + thisYearEndTime = obtainLocalDateTimeThisYear(endTime); + needCheckEndTime = thisYearEndTime != null; + } + //排列组合4种情况 + if (needCheckStartTime) { + if (needCheckEndTime) { + //开始时间、结束时间都需要比较 + if (satelliteLocalDateTime.isBefore(thisYearStartTime) || thisYearEndTime.isBefore(satelliteLocalDateTime)) { + String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime); + String time1 = DateTimeUtils.localDateTimeToString(thisYearStartTime); + String time2 = DateTimeUtils.localDateTimeToString(thisYearEndTime); + log.info("开始时间、结束时间都需要比较,比较结果:不属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1 + ",结束时间=" + time2); + return false; + } + } else { + //开始时间需要比较,结束时间不需要比较 + if (satelliteLocalDateTime.isBefore(thisYearStartTime)) { + String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime); + String time1 = DateTimeUtils.localDateTimeToString(thisYearStartTime); + log.info("开始时间需要比较,结束时间不需要比较,比较结果:不属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1); + return false; + } + } + } else { + if (needCheckEndTime) { + //开始时间不需要比较,结束时间需要比较 + if (thisYearEndTime.isBefore(satelliteLocalDateTime)) { + String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime); + String time2 = DateTimeUtils.localDateTimeToString(thisYearEndTime); + log.info("开始时间不需要比较,结束时间需要比较,比较结果:不属于精准时间范围内,详情:火点时间=" + time0 + ",结束时间=" + time2); + return false; + } + } else { + //开始时间、结束时间都不需要比较 + log.info("开始时间、结束时间都不需要比较,比较结果:属于精准时间范围内"); + return true; + } + } + } + } + } + //没有因为遇到不符合条件的情况提前退出,就认为在精准渠道配置的时间范围之内 + return true; + } + + /** + * @param formattedTime 2022-01-01 00:00:00 + */ + private static LocalDateTime obtainLocalDateTimeThisYear(String formattedTime) { + try { + LocalDateTime localDateTime = LocalDateTime.parse(formattedTime, DateTimeUtils.DATE_TIME_FORMATTER_1); + int dYear = LocalDateTime.now().getYear() - localDateTime.getYear(); + return localDateTime.plusYears(dYear); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/src/main/java/com/xkrs/straw/utils/JsonUtils.java b/src/main/java/com/xkrs/straw/utils/JsonUtils.java new file mode 100644 index 0000000..247d6f1 --- /dev/null +++ b/src/main/java/com/xkrs/straw/utils/JsonUtils.java @@ -0,0 +1,39 @@ +package com.xkrs.straw.utils; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JsonUtils { + + private static ObjectMapper MAPPER = new ObjectMapper(); + + static { + // 通过spi注册支持的modules(对象映射器),如JavaTimeModule等 + MAPPER.findAndRegisterModules(); + } + + public static String serialize(T data) { + try { + return MAPPER.writeValueAsString(data); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + public static T deserialize(String json, Class clazz) { + try { + return MAPPER.readValue(json, clazz); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + public static T deserialize(String json, TypeReference clazz) { + try { + return MAPPER.readValue(json, clazz); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file