From b4a5f74a062d7ddb359242ba6cfcf284a6eaba5d Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Tue, 10 May 2022 16:15:56 +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/common/config/WebSecurityConfig.java | 5 + .../com/xkrs/controller/StreetController.java | 36 +++++ .../xkrs/controller/StreettController.java | 142 ++++++++++++++++++ .../xkrs/service/impl/SysUserServiceImpl.java | 8 +- src/main/resources/application.properties | 1 - 5 files changed, 187 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/xkrs/controller/StreettController.java diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index 66726ff..dfb25dc 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -69,6 +69,11 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET,"/getCityList").permitAll()//根据省编号获取市列表 .antMatchers(HttpMethod.GET,"/getCountyList").permitAll()//根据市编号获取区县列表 .antMatchers(HttpMethod.GET,"/getStreetList").permitAll()//根据区县编号获取街道列表 + .antMatchers(HttpMethod.GET,"/api/adm/getProvinceList").permitAll()//获取省列表 + .antMatchers(HttpMethod.GET,"/api/adm/getCityList").permitAll()//根据省编号获取市列表 + .antMatchers(HttpMethod.GET,"/api/adm/getCountyList").permitAll()//根据市编号获取区县列表 + .antMatchers(HttpMethod.GET,"/api/adm/getStreetList").permitAll()//根据区县编号获取街道列表 + .antMatchers(HttpMethod.GET,"/updateFirePointStreetCode").permitAll() // 所有其它请求需要身份认证 .anyRequest().authenticated() .and() diff --git a/src/main/java/com/xkrs/controller/StreetController.java b/src/main/java/com/xkrs/controller/StreetController.java index a641b62..4d3ef91 100644 --- a/src/main/java/com/xkrs/controller/StreetController.java +++ b/src/main/java/com/xkrs/controller/StreetController.java @@ -8,6 +8,8 @@ import com.xkrs.dao.StreetDao; import com.xkrs.model.entity.CityEntity; import com.xkrs.model.entity.CountyEntity; import com.xkrs.model.entity.StreetEntity; +import com.xkrs.model.vo.GaoDeIgGeocodeVo; +import com.xkrs.utils.GaoDeApiUtil; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -17,6 +19,7 @@ import javax.annotation.Resource; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -137,4 +140,37 @@ public class StreetController { return "666"; } + @GetMapping("/formatStreetData2") + public String formatStreetData2() { + StringBuilder stringBuilder = new StringBuilder(); + File file = new File("/Users/liuchengqian/Desktop/20200601-20220510火点统计.csv"); + FileInputStream fileInputStream = IoUtil.toStream(file); + BufferedReader reader = IoUtil.getReader(fileInputStream, "UTF-8"); + Stream lines = reader.lines(); +// AtomicInteger count = new AtomicInteger(); + lines.forEach(content -> { + try { + content = content.replace("\"", ""); + String[] split = content.split(","); + List locationList = new ArrayList<>(); + locationList.add(split[0]+ "," +split[1]); + GaoDeIgGeocodeVo geocode = GaoDeApiUtil.geocode(locationList); + String formattedAddress= geocode.getRegeocodes().get(0).getFormatted_address();//getAddressComponent().get(0).getTowncode(); + stringBuilder.append(content).append(",").append(formattedAddress).append("\n"); +// if (townCode.length() > 9) { +// townCode = townCode.substring(0, 9); +// } +// System.out.println(townCode); +// count.getAndIncrement(); +// System.out.println(content + " >>> " + count); +// stringBuilder.append(content).append(",").append() + } catch (Exception e) { + e.printStackTrace(); + System.out.println("格式化街道数据时发生异常:" + e.getMessage()); + } + }); + return stringBuilder.toString(); + } + + } diff --git a/src/main/java/com/xkrs/controller/StreettController.java b/src/main/java/com/xkrs/controller/StreettController.java new file mode 100644 index 0000000..37f4f95 --- /dev/null +++ b/src/main/java/com/xkrs/controller/StreettController.java @@ -0,0 +1,142 @@ +package com.xkrs.controller; + +import cn.hutool.core.io.IoUtil; +import com.xkrs.common.encapsulation.PromptMessageEnum; +import com.xkrs.dao.CityDao; +import com.xkrs.dao.CountyDao; +import com.xkrs.dao.StreetDao; +import com.xkrs.model.entity.CityEntity; +import com.xkrs.model.entity.CountyEntity; +import com.xkrs.model.entity.StreetEntity; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Stream; + +import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; + +@RestController +@RequestMapping(value = "/api/adm") +public class StreettController { + + @Resource + private CityDao cityDao; + + @Resource + private CountyDao countyDao; + + @Resource + private StreetDao streetDao; + + /** + * 获取省列表 + */ + @GetMapping("/getProvinceList") + public String getProvinceList() { + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + List> provinceList = streetDao.selectProvinceList(); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, provinceList, locale); + } + + /** + * 根据省编号获取市列表 + * + * @param provinceCode 省编号 + * @return 市列表 + */ + @GetMapping("/getCityList") + public String getCityList(@RequestParam("provinceCode") String provinceCode) { + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + List> cityList = streetDao.selectCityList(provinceCode); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, cityList, locale); + } + + /** + * 根据市编号获取区县列表 + * + * @param cityCode 市编号 + * @return 区县列表 + */ + @GetMapping("/getCountyList") + public String getCountyList(@RequestParam("cityCode") String cityCode) { + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + List> countyList = streetDao.selectCountyList(cityCode); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, countyList, locale); + } + + /** + * 根据区县编号获取街道列表 + * + * @param countyCode 区县编号 + * @return 街道列表 + */ + @GetMapping("/getStreetList") + public String getStreetList(@RequestParam("countyCode") String countyCode) { + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + List> streetList = streetDao.selectStreetList(countyCode); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, streetList, locale); + } + + @GetMapping("/formatStreetData") + public String formatStreetData() { + File file = new File("/Users/liuchengqian/Downloads/Administrative-divisions-of-China-master/dist/streets2.csv"); + FileInputStream fileInputStream = IoUtil.toStream(file); + BufferedReader reader = IoUtil.getReader(fileInputStream, "UTF-8"); + Stream lines = reader.lines(); + AtomicInteger count = new AtomicInteger(); + lines.forEach(content -> { + try { + content = content.replace("\"", ""); + String[] split = content.split(","); + StreetEntity streetEntity = new StreetEntity(); + streetEntity.setProCode(split[3] + "0000"); + List byProCode1 = cityDao.findByProCode(streetEntity.getProCode()); + if (byProCode1 == null || byProCode1.isEmpty()) { + streetEntity.setProName(""); + } else { + streetEntity.setProName(byProCode1.get(0).getProName()); + } + streetEntity.setCityCode(split[4] + "00"); + List byCityCode1 = countyDao.findByCityCode(streetEntity.getCityCode()); + if (byCityCode1 == null || byCityCode1.isEmpty()) { + streetEntity.setCityName(""); + } else { + streetEntity.setCityName(byCityCode1.get(0).getCityName()); + } + streetEntity.setCountyCode(split[2]); + List byCountyCode = countyDao.findByCountyCode(streetEntity.getCountyCode()); + if (byCountyCode == null || byCountyCode.isEmpty()) { + streetEntity.setCountyName(""); + } else { + streetEntity.setCountyName(byCountyCode.get(0).getCountyName()); + } + streetEntity.setStreetCode(split[0]); + streetEntity.setStreetName(split[1]); + streetDao.save(streetEntity); + count.getAndIncrement(); + System.out.println(content + " >>> " + count); + System.out.println(streetEntity.toString()); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("格式化街道数据时发生异常:" + e.getMessage()); + } + }); + return "666"; + } + +} diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index d3d4340..023b26e 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -153,10 +153,10 @@ public class SysUserServiceImpl implements SysUserService { sysUserEntity.setActiveFlag(0); sysUserEntity.setAccountType("县级"); } - if (9 == countyCode.length()) {//街道账号5天后过期 - sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(5L))); - } else {//省市区县账号3天后过期 - sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(3L))); + if (9 == countyCode.length()) {//街道账号14天后过期 + sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(14L))); + } else {//省市区县账号7天后过期 + sysUserEntity.setOverTime(dateTimeToString(LocalDateTime.now().plusDays(7L))); } sysUserEntity.setStatusCode(0); sysUserEntity.setAddTime(dateTimeToString(LocalDateTime.now())); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0e4ceee..987b328 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,7 +5,6 @@ spring.datasource.url = jdbc:postgresql://118.24.27.47:5432/fire_point spring.datasource.userName = fire_manage spring.datasource.password = fire456 spring.datasource.driverClassName = org.postgresql.Driver - server.tomcat.uri-encoding=UTF-8 # 关闭spring data 的redis仓库