From 9127969382ad527662d8d791ea75ed2df8513b25 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G8BCEP0\\HP" <2037158277@qq.com> Date: Fri, 24 Sep 2021 15:19:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=AF=BB=E5=8F=96ex?= =?UTF-8?q?cel=E8=AF=BB=E5=8F=96=E5=85=A8=E5=9B=BD=E7=9C=81=E5=B8=82?= =?UTF-8?q?=E5=8C=BA=E5=88=B0=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/common/config/WebSecurityConfig.java | 1 + .../xkrs/controller/FirePointController.java | 14 ++ src/main/java/com/xkrs/dao/NationwideDao.java | 13 ++ .../com/xkrs/model/entity/Nationwide.java | 137 ++++++++++++++++++ .../com/xkrs/service/FirePointService.java | 7 + .../service/impl/FirePointServiceImpl.java | 36 ++++- 6 files changed, 204 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/xkrs/dao/NationwideDao.java create mode 100644 src/main/java/com/xkrs/model/entity/Nationwide.java diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index 84ac9a6..8f6ee06 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -58,6 +58,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.POST,"/uploadFileMore").permitAll() .antMatchers(HttpMethod.POST,"/uploadFile").permitAll() .antMatchers(HttpMethod.POST,"/insertFireTest").permitAll() + .antMatchers(HttpMethod.POST,"/importCityExcel").permitAll() // 所有其它请求需要身份认证 .anyRequest().authenticated() .and() diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index f26e2ec..4968751 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -293,4 +293,18 @@ public class FirePointController { return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"添加成功",locale); } } + + /** + * 导入全国省市区 + * @param file + * @return + * @throws Exception + */ + @PostMapping("/importCityExcel") + public String importCityExcel(MultipartFile file) throws Exception { + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + firePointService.importCityExcel(file); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"导入成功",locale); + } } diff --git a/src/main/java/com/xkrs/dao/NationwideDao.java b/src/main/java/com/xkrs/dao/NationwideDao.java new file mode 100644 index 0000000..b5e34a0 --- /dev/null +++ b/src/main/java/com/xkrs/dao/NationwideDao.java @@ -0,0 +1,13 @@ +package com.xkrs.dao; + +import com.xkrs.model.entity.Nationwide; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Component; + +/** + * @author XinYi Song + */ +@Component +public interface NationwideDao extends JpaRepository { + +} diff --git a/src/main/java/com/xkrs/model/entity/Nationwide.java b/src/main/java/com/xkrs/model/entity/Nationwide.java new file mode 100644 index 0000000..802c6bc --- /dev/null +++ b/src/main/java/com/xkrs/model/entity/Nationwide.java @@ -0,0 +1,137 @@ +package com.xkrs.model.entity; + +import javax.persistence.*; + +/** + * @author XinYi Song + * 全国省市区 + */ +@Entity +@Table(name = "nationwide") +public class Nationwide { + /** + * 主键id + */ + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "nationwide_seq_gen") + @SequenceGenerator(name = "nationwide_seq_gen", sequenceName = "nationwide_id_seq",allocationSize = 1) + private Integer id; + + /** + * 省名称 + */ + @Column(length = 65, columnDefinition = "varchar(65)") + private String proName; + + /** + * 省编码 + */ + @Column(length = 65, columnDefinition = "varchar(65)") + private String proCode; + + /** + * 市名称 + */ + @Column(length = 65, columnDefinition = "varchar(65)") + private String cityName; + + /** + * 市编码 + */ + @Column(length = 65, columnDefinition = "varchar(65)") + private String cityCode; + + /** + * 区县名称 + */ + @Column(length = 65, columnDefinition = "varchar(65)") + private String countyName; + + /** + * 区县编码 + */ + @Column(length = 65, columnDefinition = "varchar(65)") + private String countyCode; + + public Nationwide() { + } + + public Nationwide(Integer id, String proName, String proCode, String cityName, String cityCode, String countyName, String countyCode) { + this.id = id; + this.proName = proName; + this.proCode = proCode; + this.cityName = cityName; + this.cityCode = cityCode; + this.countyName = countyName; + this.countyCode = countyCode; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getProName() { + return proName; + } + + public void setProName(String proName) { + this.proName = proName; + } + + public String getProCode() { + return proCode; + } + + public void setProCode(String proCode) { + this.proCode = proCode; + } + + public String getCityName() { + return cityName; + } + + public void setCityName(String cityName) { + this.cityName = cityName; + } + + public String getCityCode() { + return cityCode; + } + + public void setCityCode(String cityCode) { + this.cityCode = cityCode; + } + + public String getCountyName() { + return countyName; + } + + public void setCountyName(String countyName) { + this.countyName = countyName; + } + + public String getCountyCode() { + return countyCode; + } + + public void setCountyCode(String countyCode) { + this.countyCode = countyCode; + } + + @Override + public String toString() { + return "Nationwide{" + + "id=" + id + + ", proName='" + proName + '\'' + + ", proCode='" + proCode + '\'' + + ", cityName='" + cityName + '\'' + + ", cityCode='" + cityCode + '\'' + + ", countyName='" + countyName + '\'' + + ", countyCode='" + countyCode + '\'' + + '}'; + } +} diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index 22816e5..6b72119 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -143,4 +143,11 @@ public interface FirePointService { * @return */ FirePoint insertFireTest(FirePointQo firePointQo); + + /** + * 导入全国省市区 + * @param file + * @throws Exception + */ + void importCityExcel(MultipartFile file) throws Exception; } diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 56b911e..2723407 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -21,10 +21,8 @@ import javax.transaction.Transactional; import java.io.IOException; import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; @@ -69,6 +67,9 @@ public class FirePointServiceImpl implements FirePointService { @Resource private FireDao fireDao; + @Resource + private NationwideDao nationwideDao; + /** * 添加火点信息 * @param firePointQo @@ -457,4 +458,31 @@ public class FirePointServiceImpl implements FirePointService { log.info("-------发现新火点"); return fireDao.save(firePoint); } + + /** + * 导入全国省市区 + * @param file + * @throws Exception + */ + @Transactional(rollbackOn = Exception.class) + @Override + public void importCityExcel(MultipartFile file) throws Exception { + //调用封装好的工具 + ExcelImportUtil importUtil = new ExcelImportUtil(file); + //调用导入的方法,获取sheet表的内容 + List> maps = importUtil.readExcelContent(); + //导入订单详情表 + List orderDetails = maps.stream().filter(Objects::nonNull).map(map -> { + Nationwide nationwide = new Nationwide(); + nationwide.setProName(map.get("pro_name")); + nationwide.setProCode(map.get("pro_code")); + nationwide.setCityName(map.get("city_name")); + nationwide.setCityCode(map.get("city_code")); + nationwide.setCountyName(map.get("town_name")); + nationwide.setCountyCode(map.get("town_code")); + return nationwide; + }).collect(Collectors.toList()); + //批量添加到订单详情 + nationwideDao.saveAll(orderDetails); + } }