From 43e2b0e3577f9fe9210c0e480f39b67e0a46b613 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Sat, 7 May 2022 17:45:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=81=AB=E7=82=B9=E7=9A=84?= =?UTF-8?q?=E8=A1=97=E9=81=93=E7=BC=96=E5=8F=B7=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/FirePointController.java | 10 ++++ src/main/java/com/xkrs/dao/FirePointDao.java | 27 +++------- .../com/xkrs/service/FirePointService.java | 7 +++ .../service/impl/FirePointServiceImpl.java | 54 +++++++++++++++++++ 4 files changed, 77 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index 71ecbfa..e10da10 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -59,6 +59,16 @@ public class FirePointController { } } + /** + * 更新火点的街道编号数据 + * + * @return + */ + @GetMapping("/updateFirePointStreetCode") + public String updateFirePointStreetCode() { + return firePointService.updateFirePointStreetCode(); + } + /** * 测试 * diff --git a/src/main/java/com/xkrs/dao/FirePointDao.java b/src/main/java/com/xkrs/dao/FirePointDao.java index c0b9e3d..625cb55 100644 --- a/src/main/java/com/xkrs/dao/FirePointDao.java +++ b/src/main/java/com/xkrs/dao/FirePointDao.java @@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Component; +import javax.transaction.Transactional; import java.util.List; import java.util.Map; @@ -26,16 +27,6 @@ public interface FirePointDao extends JpaRepository, JpaS @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and fire_point_address like CONCAT('%',:address,'%')", nativeQuery = true) List selectTodayFirePoint(String addTime, String address); - /** - * 查询山东省今天火点信息 - * - * @param addTime - * @param address - * @return - */ - @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and fire_point_address like CONCAT('%',:address,'%') and land_type != '耕地'", nativeQuery = true) - List selectTodayFirePointShandong(String addTime, String address); - /** * 区县条件查询今天火点信息 * @@ -56,17 +47,6 @@ public interface FirePointDao extends JpaRepository, JpaS @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and street_code = :streetCode", nativeQuery = true) List selectTodayFirePointOneStreet(String addTime, String streetCode); - - /** - * 查询山东省县的今天火点信息 - * - * @param addTime - * @param countyCode - * @return - */ - @Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and county_code = :countyCode and land_type != '耕地'", nativeQuery = true) - List selectTodayFirePointOneShandong(String addTime, String countyCode); - /** * 根据火点编码查询火点信息 * @@ -139,4 +119,9 @@ public interface FirePointDao extends JpaRepository, JpaS @Modifying(clearAutomatically = true) @Query(value = "update fire_point set before_fire_image = ?2,after_fire_image = ?3 where fire_code = ?1", nativeQuery = true) void updateBeforeFireAndAfterFireImage(String fireCode, String beforeFireImage, String afterFireImage); + + @Transactional(rollbackOn = Exception.class) + @Modifying(clearAutomatically = true) + @Query(value = "UPDATE fire_point SET street_code = ?2 WHERE id = ?1", nativeQuery = true) + void updateStreetCodeById(Integer id, String streetCode); } diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index a049381..0cda0c7 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -187,4 +187,11 @@ public interface FirePointService { * @return */ List selectTodayFire(String countyCode); + + /** + * 更新火点的街道编号数据 + * + * @return + */ + String updateFirePointStreetCode(); } diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index dc4df7c..5f81766 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -147,6 +147,7 @@ public class FirePointServiceImpl implements FirePointService { firePointEntity.setStreetCode(townCode); } + /** * 查询今天的火点信息 */ @@ -598,4 +599,57 @@ public class FirePointServiceImpl implements FirePointService { return fireDao.selectTodayFireOne(addTime, countyCode); } } + + /** + * 更新火点的街道编号数据 + * + * @return + */ + @Override + public String updateFirePointStreetCode() { + System.out.println("开始格式化街道编号"); + List firePointEntityList = firePointDao.findAll(); + long startTimeMillis = System.currentTimeMillis(); + int listSize = firePointEntityList.size(); + for (int i = 0; i < listSize; i++) { + try { + FirePointEntity firePointEntity = firePointEntityList.get(i); + 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); + } + firePointDao.updateStreetCodeById(firePointEntity.getId(), townCode); + if (i % 10 == 0) { + long spendTimeMillis = System.currentTimeMillis() - startTimeMillis; + double remainTimeMillis = (listSize - i) * spendTimeMillis * 1D / i; + System.out.println("已完成(" + i + "/" + listSize + "),用时" + formatDuring(spendTimeMillis) + ",剩余" + formatDuring((long) remainTimeMillis)); + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println("街道编号格式化出现错误:" + e.getMessage()); + } + } + Locale locale = LocaleContextHolder.getLocale(); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "街道编号格式化完毕", locale); + } + + public static String formatDuring(long mss) { + long days = mss / (1000 * 60 * 60 * 24); + long hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60); + long minutes = (mss % (1000 * 60 * 60)) / (1000 * 60); + long seconds = (mss % (1000 * 60)) / 1000; + if (days <= 0 && hours <= 0 && minutes <= 0) { + return seconds + " 秒 "; + } + if (days <= 0 && hours <= 0) { + return minutes + " 分钟 " + seconds + " 秒 "; + } + if (days <= 0) { + return hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒 "; + } + return days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒 "; + } }