From 63be3041b17aada0955399f508077a09add2a3b9 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 16 Jun 2022 17:24:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=AB=98=E5=BE=B7=E9=80=86?= =?UTF-8?q?=E5=9C=B0=E7=90=86=E7=BC=96=E7=A0=81=E6=9B=BF=E6=8D=A2=E5=A4=A9?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E9=80=86=E5=9C=B0=E7=90=86=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/FirePointServiceImpl.java | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index b87b86e..b61d304 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -120,7 +120,6 @@ public class FirePointServiceImpl implements FirePointService { 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()); @@ -130,7 +129,7 @@ public class FirePointServiceImpl implements FirePointService { firePointEntity.setSatelliteImage(firePointQo.getSatelliteImage()); firePointEntity.setAuditFireType("0");//初始化火点为未审核状态 try { - bindStreetCodeName(firePointEntity); + bindAddress(firePointEntity); } catch (Exception e) { e.printStackTrace(); System.out.println("添加火点信息 逆地理编码请求街道编号失败:" + e.getMessage()); @@ -171,7 +170,6 @@ public class FirePointServiceImpl implements FirePointService { shanDongFirePoint.setSatelliteTime(DateTimeUtil.timeMillisToString(firePointQo.getSatelliteTimeTs().longValue())); shanDongFirePoint.setLongitude(firePointQo.getLongitude()); shanDongFirePoint.setLatitude(firePointQo.getLatitude()); - shanDongFirePoint.setFirePointAddress(AddressUtils.getLocal(firePointQo.getLatitude().toString(), firePointQo.getLongitude().toString())); shanDongFirePoint.setSatelliteType(firePointQo.getSatelliteType()); shanDongFirePoint.setLandType(firePointQo.getLandtype()); shanDongFirePoint.setConfidence(firePointQo.getConfidence()); @@ -181,7 +179,7 @@ public class FirePointServiceImpl implements FirePointService { shanDongFirePoint.setSatelliteImage(firePointQo.getSatelliteImage()); shanDongFirePoint.setVerifyState("0"); try { - bindStreetCodeName(shanDongFirePoint); + bindAddress(shanDongFirePoint); } catch (Exception e) { e.printStackTrace(); System.out.println("添加山东火点信息 逆地理编码请求街道编号失败:" + e.getMessage()); @@ -268,39 +266,39 @@ public class FirePointServiceImpl implements FirePointService { } /** - * 为实体类设置街道编号和街道名称 + * 为实体类绑定地址、编号、名称 */ - private void bindStreetCodeName(FirePointEntity firePointEntity) throws Exception { + private void bindAddress(FirePointEntity firePointEntity) throws Exception { List locationList = new ArrayList<>(); locationList.add(firePointEntity.getLongitude() + "," + firePointEntity.getLatitude()); GaoDeIgGeocodeVo geocode = GaoDeApiUtil.geocode(locationList); - String townCode = geocode.getRegeocodes().get(0).getAddressComponent().get(0).getTowncode(); - if (townCode.length() > 9) { - townCode = townCode.substring(0, 9); - } - firePointEntity.setStreetCode(townCode); - List byStreetCode = streetDao.findByStreetCode(townCode); - if (byStreetCode != null && byStreetCode.size() > 0) { - firePointEntity.setStreetName(byStreetCode.get(0).getStreetName()); - } + GaoDeIgGeocodeVo.Regeocode reGeoCode = geocode.getRegeocodes().get(0); + String formattedAddress = reGeoCode.getFormatted_address(); + firePointEntity.setFirePointAddress(formattedAddress); + GaoDeIgGeocodeVo.AddressComponent addressComponent = reGeoCode.getAddressComponent().get(0); + String townCode = addressComponent.getTowncode(); + String fixedTownCode = townCode.length() > 9 ? townCode.substring(0, 9) : townCode; + firePointEntity.setStreetCode(fixedTownCode); + String townShip = addressComponent.getTownship(); + firePointEntity.setStreetName(townShip); } /** - * 为实体类设置街道编号和街道名称 + * 为实体类绑定地址、编号、名称 */ - private void bindStreetCodeName(ShanDongFirePointEntity firePointEntity) throws Exception { + private void bindAddress(ShanDongFirePointEntity firePointEntity) throws Exception { List locationList = new ArrayList<>(); locationList.add(firePointEntity.getLongitude() + "," + firePointEntity.getLatitude()); GaoDeIgGeocodeVo geocode = GaoDeApiUtil.geocode(locationList); - String townCode = geocode.getRegeocodes().get(0).getAddressComponent().get(0).getTowncode(); - if (townCode.length() > 9) { - townCode = townCode.substring(0, 9); - } - firePointEntity.setStreetCode(townCode); - List byStreetCode = streetDao.findByStreetCode(townCode); - if (byStreetCode != null && byStreetCode.size() > 0) { - firePointEntity.setStreetName(byStreetCode.get(0).getStreetName()); - } + GaoDeIgGeocodeVo.Regeocode reGeoCode = geocode.getRegeocodes().get(0); + String formattedAddress = reGeoCode.getFormatted_address(); + firePointEntity.setFirePointAddress(formattedAddress); + GaoDeIgGeocodeVo.AddressComponent addressComponent = reGeoCode.getAddressComponent().get(0); + String townCode = addressComponent.getTowncode(); + String fixedTownCode = townCode.length() > 9 ? townCode.substring(0, 9) : townCode; + firePointEntity.setStreetCode(fixedTownCode); + String townShip = addressComponent.getTownship(); + firePointEntity.setStreetName(townShip); } /**