diff --git a/src/main/java/com/xkrs/controller/DispatchFirePointController.java b/src/main/java/com/xkrs/controller/DispatchFirePointController.java index ec77136..0f049a8 100644 --- a/src/main/java/com/xkrs/controller/DispatchFirePointController.java +++ b/src/main/java/com/xkrs/controller/DispatchFirePointController.java @@ -1,18 +1,31 @@ package com.xkrs.controller; +import com.xkrs.common.encapsulation.PromptMessageEnum; +import com.xkrs.dao.FirePointOrdinaryDao; +import com.xkrs.dao.FirePointPreciseDao; +import com.xkrs.dao.StreetDao; import com.xkrs.dao.SysUserDao; import com.xkrs.helper.FirePointSubscribeManager; +import com.xkrs.model.entity.FirePointOrdinaryEntity; import com.xkrs.model.qo.AllFirePointQo; import com.xkrs.service.DispatchFirePointService; import com.xkrs.service.impl.FirePointServiceImpl; +import org.apache.hc.core5.util.TextUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +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; import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; @RestController public class DispatchFirePointController { @@ -24,9 +37,17 @@ public class DispatchFirePointController { private DispatchFirePointService firePointService; @Resource private FirePointSubscribeManager firePointSubscribeManager; + @Resource + private FirePointOrdinaryDao firePointOrdinaryDao; + @Resource + private FirePointPreciseDao firePointPreciseDao; + @Resource + private StreetDao streetDao; + private final Locale locale = LocaleContextHolder.getLocale(); @GetMapping("/debug") public String debug() { + // List sysUserEntityList = sysUserDao.findAll(); // for (SysUserEntity sysUserEntity : sysUserEntityList) { // String addTime = sysUserEntity.getAddTime(); @@ -49,7 +70,42 @@ public class DispatchFirePointController { // sysUserEntity.setVipTimeRangeJson(serialize); // sysUserDao.save(sysUserEntity); // } - return "OKkkkkkkk"; + + List> maps = streetDao.selectProCityPair(); + List firePointOrdinaryEntityList = firePointOrdinaryDao.findAll(); + List errorList = new ArrayList<>(); + for (FirePointOrdinaryEntity firePointOrdinaryEntity : firePointOrdinaryEntityList) { + String countyCode = firePointOrdinaryEntity.getCountyCode(); + String proCode = countyCode.substring(0, 2) + "0000"; + firePointOrdinaryEntity.setProCode(proCode); + firePointOrdinaryEntity.setProName(obtainProName(maps, proCode)); + String cityCode = countyCode.substring(0, 4) + "00"; + firePointOrdinaryEntity.setCityCode(cityCode); + firePointOrdinaryEntity.setCityName(obtainCityName(maps, cityCode)); + if (TextUtils.isEmpty(firePointOrdinaryEntity.getCountyCode()) || TextUtils.isEmpty(firePointOrdinaryEntity.getCountyName()) || TextUtils.isEmpty(firePointOrdinaryEntity.getCityCode()) || TextUtils.isEmpty(firePointOrdinaryEntity.getCityName()) || TextUtils.isEmpty(firePointOrdinaryEntity.getProCode()) || TextUtils.isEmpty(firePointOrdinaryEntity.getProName())) { + errorList.add(firePointOrdinaryEntity.getFireCode()); + } + } + firePointOrdinaryDao.saveAll(firePointOrdinaryEntityList); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, errorList, locale); + } + + private String obtainProName(List> maps, String proCode) { + for (Map map : maps) { + if (map.get("pro_code").equals(proCode)) { + return map.get("pro_name"); + } + } + return null; + } + + private String obtainCityName(List> maps, String cityCode) { + for (Map map : maps) { + if (map.get("city_code").equals(cityCode)) { + return map.get("city_name"); + } + } + return null; } @GetMapping("/autoSync") diff --git a/src/main/java/com/xkrs/dao/StreetDao.java b/src/main/java/com/xkrs/dao/StreetDao.java index 928c0d8..e61919b 100644 --- a/src/main/java/com/xkrs/dao/StreetDao.java +++ b/src/main/java/com/xkrs/dao/StreetDao.java @@ -39,4 +39,7 @@ public interface StreetDao extends JpaRepository, JpaSpec @Query(value = "SELECT DISTINCT t.street_code AS code, t.street_name AS name FROM street AS t WHERE t.county_code = ?1", nativeQuery = true) List> selectStreetList(String countyCode); + + @Query(value = "SELECT t.pro_code, t.pro_name, t.city_code, t.city_name FROM street AS t group by pro_code, pro_name, city_code, city_name", nativeQuery = true) + List> selectProCityPair(); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c2a146e..ed82a60 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,7 +23,7 @@ spring.datasource.hikari.validation-timeout = 3000 ## Spring Data JPA 配置 spring.jpa.database = POSTGRESQL spring.jpa.database-platform = org.hibernate.dialect.PostgreSQLDialect -spring.jpa.show-sql = true +spring.jpa.show-sql = false # 指定 ddl mode (none, validate, create, create-drop, update) spring.jpa.hibernate.ddl-auto = update # 命名策略