From 7ff3bef2b332fe081bc211d1edf7ee5f70ce5ad2 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Wed, 8 Jun 2022 10:38:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xkrs/controller/StreetController.java | 8 - .../xkrs/controller/StreettController.java | 64 -------- src/main/java/com/xkrs/dao/CityDao.java | 43 ------ src/main/java/com/xkrs/dao/CountyDao.java | 51 ------- src/main/java/com/xkrs/dao/FirePointDao.java | 29 +--- .../com/xkrs/model/entity/CityEntity.java | 137 ------------------ .../com/xkrs/model/entity/CountyEntity.java | 104 ------------- .../com/xkrs/service/FirePointService.java | 17 --- .../service/impl/FirePointServiceImpl.java | 28 ---- .../xkrs/service/impl/SysUserServiceImpl.java | 39 ++--- 10 files changed, 17 insertions(+), 503 deletions(-) delete mode 100644 src/main/java/com/xkrs/dao/CityDao.java delete mode 100644 src/main/java/com/xkrs/dao/CountyDao.java delete mode 100644 src/main/java/com/xkrs/model/entity/CityEntity.java delete mode 100644 src/main/java/com/xkrs/model/entity/CountyEntity.java diff --git a/src/main/java/com/xkrs/controller/StreetController.java b/src/main/java/com/xkrs/controller/StreetController.java index c665fd7..88296bd 100644 --- a/src/main/java/com/xkrs/controller/StreetController.java +++ b/src/main/java/com/xkrs/controller/StreetController.java @@ -1,8 +1,6 @@ package com.xkrs.controller; import com.xkrs.common.encapsulation.PromptMessageEnum; -import com.xkrs.dao.CityDao; -import com.xkrs.dao.CountyDao; import com.xkrs.dao.StreetDao; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.web.bind.annotation.GetMapping; @@ -19,12 +17,6 @@ import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulat @RestController public class StreetController { - @Resource - private CityDao cityDao; - - @Resource - private CountyDao countyDao; - @Resource private StreetDao streetDao; diff --git a/src/main/java/com/xkrs/controller/StreettController.java b/src/main/java/com/xkrs/controller/StreettController.java index 37f4f95..479fce6 100644 --- a/src/main/java/com/xkrs/controller/StreettController.java +++ b/src/main/java/com/xkrs/controller/StreettController.java @@ -1,13 +1,7 @@ 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; @@ -15,14 +9,9 @@ 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; @@ -30,12 +19,6 @@ import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulat @RequestMapping(value = "/api/adm") public class StreettController { - @Resource - private CityDao cityDao; - - @Resource - private CountyDao countyDao; - @Resource private StreetDao streetDao; @@ -92,51 +75,4 @@ public class StreettController { 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/dao/CityDao.java b/src/main/java/com/xkrs/dao/CityDao.java deleted file mode 100644 index 04814ee..0000000 --- a/src/main/java/com/xkrs/dao/CityDao.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.xkrs.dao; - -import com.xkrs.model.entity.CityEntity; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Query; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Map; - -/** - * @author xkrs - */ -@Component -public interface CityDao extends JpaRepository, JpaSpecificationExecutor { - - /** - * 查询所有市和对应的编码 - * - * @param code - * @return - */ - @Query(value = "select city_name cityname,city_code citycode from city where pro_code = :code", nativeQuery = true) - List> selectCityName(String code); - - /** - * 根据省编码查询信息 - * - * @param proCode - * @return - */ - List findByProCode(String proCode); - - /** - * 根据省名称查询信息 - * - * @param proName - * @return - */ - List findByProName(String proName); - -} diff --git a/src/main/java/com/xkrs/dao/CountyDao.java b/src/main/java/com/xkrs/dao/CountyDao.java deleted file mode 100644 index e5400b0..0000000 --- a/src/main/java/com/xkrs/dao/CountyDao.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.xkrs.dao; - -import com.xkrs.model.entity.CountyEntity; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Map; - -/** - * @author XinYi Song - */ -@Component -public interface CountyDao extends JpaRepository { - /** - * 查询市包含的区县和编码 - * - * @param code - * @return - */ - @Query(value = "select county_name cityname,county_code citycode from county where city_code = :code", nativeQuery = true) - List> selectCountyName(String code); - - /** - * 根据市编码查询信息 - * - * @param cityCode - * @return - */ - List findByCityCode(String cityCode); - - List findByCityName(String cityName); - - /** - * 根据countyCode查询信息 - * - * @param countyCode - * @return - */ - List findByCountyCode(String countyCode); - - /** - * 根据县名称查询信息 - * - * @param countyName - * @return - */ - List findByCountyName(String countyName); - -} diff --git a/src/main/java/com/xkrs/dao/FirePointDao.java b/src/main/java/com/xkrs/dao/FirePointDao.java index 0404bbc..f0181d8 100644 --- a/src/main/java/com/xkrs/dao/FirePointDao.java +++ b/src/main/java/com/xkrs/dao/FirePointDao.java @@ -19,17 +19,11 @@ public interface FirePointDao extends JpaRepository, JpaS /** * 根据火点编码查询火点信息 - * - * @param fireCode - * @return */ FirePointEntity findByFireCode(String fireCode); /** * 根据火点编码修改火点状态 - * - * @param fireCode - * @param fireType */ @Modifying(clearAutomatically = true) @Query(value = "UPDATE fire_point SET fire_type = ?2 WHERE fire_code = ?1", nativeQuery = true) @@ -37,9 +31,6 @@ public interface FirePointDao extends JpaRepository, JpaS /** * 根据火点编码修改审核火点状态 - * - * @param fireCode - * @param auditFireType */ @Modifying(clearAutomatically = true) @Query(value = "UPDATE fire_point SET audit_fire_type = ?2 WHERE fire_code = ?1", nativeQuery = true) @@ -47,54 +38,36 @@ public interface FirePointDao extends JpaRepository, JpaS /** * 查询时间段内各植被类型的火点数量 - * - * @param startTime - * @param endTime - * @return */ - @Query(value = "select la.land_name landname,count(fp.id) as num from land la left join fire_point fp " + "on fp.land_type = la.land_name AND fp.add_time BETWEEN ?1 AND ?2 " + "group by la.land_name", nativeQuery = true) + @Query(value = "select la.land_name landname,count(fp.id) as num from land la left join fire_point fp on fp.land_type = la.land_name AND fp.add_time BETWEEN ?1 AND ?2 group by la.land_name", nativeQuery = true) List> selectNumByLandType(String startTime, String endTime); /** * 查询时间段内各地区的火点数量 - * - * @param startTime - * @param endTime - * @return */ @Query(value = "select ci.city_name cityname,count(fp.id) from city ci left join fire_point fp " + "on fp.county_code like concat('%',ci.city_code,'%') AND fp.add_time BETWEEN ?1 AND ?2 " + "group by ci.city_name", nativeQuery = true) List> selectNumByArea(String startTime, String endTime); /** * 查询水体类型的id - * - * @return */ @Query(value = "select id from fire_point where land_type = '水体'", nativeQuery = true) List selectId(); /** * 批量删除水体 - * - * @param id */ @Modifying(clearAutomatically = true) void deleteByIdIn(List id); /** * 查询北京的火点 - * - * @return */ @Query(value = "select * from fire_point fp where fp.fire_point_address like concat('%','北京市','%') and fp.add_time BETWEEN '2021-10-19' AND '2021-11-20'", nativeQuery = true) List selectBeijing(); /** * 根据火点编码,修改火点前后图片路径 - * - * @param fireCode - * @param beforeFireImage - * @param afterFireImage */ @Modifying(clearAutomatically = true) @Query(value = "update fire_point set before_fire_image = ?2,after_fire_image = ?3 where fire_code = ?1", nativeQuery = true) diff --git a/src/main/java/com/xkrs/model/entity/CityEntity.java b/src/main/java/com/xkrs/model/entity/CityEntity.java deleted file mode 100644 index 8739fc3..0000000 --- a/src/main/java/com/xkrs/model/entity/CityEntity.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.xkrs.model.entity; - -import javax.persistence.*; -import java.io.Serializable; - -/** - * @author xkrs - */ -@Entity -@Table(name = "city") -public class CityEntity implements Serializable { - /** - * 主键id - */ - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "city_seq_gen") - @SequenceGenerator(name = "city_seq_gen", sequenceName = "city_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 cityLatitude; - - /** - * 市经度 - */ - @Column(length = 65, columnDefinition = "varchar(65)") - private String cityLongitude; - - public CityEntity() { - } - - public CityEntity(Integer id, String proName, String proCode, String cityName, String cityCode, String cityLatitude, String cityLongitude) { - this.id = id; - this.proName = proName; - this.proCode = proCode; - this.cityName = cityName; - this.cityCode = cityCode; - this.cityLatitude = cityLatitude; - this.cityLongitude = cityLongitude; - } - - 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 getCityLatitude() { - return cityLatitude; - } - - public void setCityLatitude(String cityLatitude) { - this.cityLatitude = cityLatitude; - } - - public String getCityLongitude() { - return cityLongitude; - } - - public void setCityLongitude(String cityLongitude) { - this.cityLongitude = cityLongitude; - } - - @Override - public String toString() { - return "City{" + - "id=" + id + - ", proName='" + proName + '\'' + - ", proCode='" + proCode + '\'' + - ", cityName='" + cityName + '\'' + - ", cityCode='" + cityCode + '\'' + - ", cityLatitude='" + cityLatitude + '\'' + - ", cityLongitude='" + cityLongitude + '\'' + - '}'; - } -} diff --git a/src/main/java/com/xkrs/model/entity/CountyEntity.java b/src/main/java/com/xkrs/model/entity/CountyEntity.java deleted file mode 100644 index a7a3c79..0000000 --- a/src/main/java/com/xkrs/model/entity/CountyEntity.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.xkrs.model.entity; - -import javax.persistence.*; - -/** - * @author XinYi Song - */ -@Entity -@Table(name = "county") -public class CountyEntity { - /** - * 主键id - */ - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "county_seq_gen") - @SequenceGenerator(name = "county_seq_gen", sequenceName = "county_id_seq",allocationSize = 1) - private Integer id; - - /** - * 区县编码 - */ - @Column(length = 65, columnDefinition = "varchar(65)") - private String countyCode; - - /** - * 区县名称 - */ - @Column(length = 65, columnDefinition = "varchar(65)") - private String countyName; - - /** - * 城市编码 - */ - @Column(length = 65, columnDefinition = "varchar(65)") - private String cityCode; - - /** - * 城市名称 - */ - @Column(length = 65, columnDefinition = "varchar(65)") - private String cityName; - - public CountyEntity() { - } - - public CountyEntity(Integer id, String countyCode, String countyName, String cityCode, String cityName) { - this.id = id; - this.countyCode = countyCode; - this.countyName = countyName; - this.cityCode = cityCode; - this.cityName = cityName; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getCountyCode() { - return countyCode; - } - - public void setCountyCode(String countyCode) { - this.countyCode = countyCode; - } - - public String getCountyName() { - return countyName; - } - - public void setCountyName(String countyName) { - this.countyName = countyName; - } - - public String getCityCode() { - return cityCode; - } - - public void setCityCode(String cityCode) { - this.cityCode = cityCode; - } - - public String getCityName() { - return cityName; - } - - public void setCityName(String cityName) { - this.cityName = cityName; - } - - @Override - public String toString() { - return "CountyEntity{" + - "id=" + id + - ", countyCode='" + countyCode + '\'' + - ", countyName='" + countyName + '\'' + - ", cityCode='" + cityCode + '\'' + - ", cityName='" + cityName + '\'' + - '}'; - } -} diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index 48881e5..0f1e8a0 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -10,7 +10,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; -import java.util.Map; /** * @author XinYi Song @@ -106,22 +105,6 @@ public interface FirePointService { */ String selectFirePointNumWeek(); - /** - * 查询该省所有的市 - * - * @param code - * @return - */ - List> selectCityName(String code); - - /** - * 查询市包含的区县和编码 - * - * @param code - * @return - */ - List> selectCountyName(String code); - /** * 更新火点的街道编号数据 * diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 50a5c7d..7baea4e 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -73,12 +73,6 @@ public class FirePointServiceImpl implements FirePointService { @Resource private FireTaskPhotoDao fireTaskPhotoDao; - @Resource - private CityDao cityDao; - - @Resource - private CountyDao countyDao; - @Resource private StreetDao streetDao; @@ -744,28 +738,6 @@ public class FirePointServiceImpl implements FirePointService { return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale); } - /** - * 查询该省所有的市 - * - * @param code - * @return - */ - @Override - public List> selectCityName(String code) { - return cityDao.selectCityName(code); - } - - /** - * 查询市包含的区县和编码 - * - * @param code - * @return - */ - @Override - public List> selectCountyName(String code) { - return countyDao.selectCountyName(code); - } - /** * 更新火点的街道编号数据 * diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index f347679..088d4aa 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -51,12 +51,6 @@ public class SysUserServiceImpl implements SysUserService { @Resource private NationwideDao nationwideDao; - @Resource - private CityDao cityDao; - - @Resource - private CountyDao countyDao; - @Resource private StreetDao streetDao; @@ -109,47 +103,46 @@ public class SysUserServiceImpl implements SysUserService { if (TextUtils.isEmpty(countyName)) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "省市区街道名称不能为空!", locale); } - if (9 == countyCode.length()) { - List byStreetCode = streetDao.findByStreetCode(countyCode); - if (byStreetCode == null || byStreetCode.isEmpty()) { + List streetCodeList = streetDao.findByStreetCode(countyCode); + if (streetCodeList == null || streetCodeList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "街道编码不存在!", locale); } - List byStreetName = streetDao.findByStreetName(countyName); - if (byStreetName == null || byStreetName.isEmpty()) { + List streetNameList = streetDao.findByStreetName(countyName); + if (streetNameList == null || streetNameList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale); } sysUserEntity.setActiveFlag(0); sysUserEntity.setAccountType("街道级"); } else if ("0000".equals(countyCode.substring(2))) { - List byProCode = cityDao.findByProCode(countyCode); - if (byProCode == null || byProCode.size() == 0) { + List proCodeList = streetDao.findByProCode(countyCode); + if (proCodeList == null || proCodeList.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "省编码不存在!", locale); } - List byProName = cityDao.findByProName(countyName); - if (byProName == null || byProName.size() == 0) { + List proNameList = streetDao.findByProName(countyName); + if (proNameList == null || proNameList.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale); } sysUserEntity.setActiveFlag(1); sysUserEntity.setAccountType("省级"); } else if ("00".equals(countyCode.substring(4)) && !"0000".equals(countyCode.substring(2))) { - List byCityCode = countyDao.findByCityCode(countyCode); - if (byCityCode == null || byCityCode.size() == 0) { + List cityCodeList = streetDao.findByCityCode(countyCode); + if (cityCodeList == null || cityCodeList.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "市编码不存在!", locale); } - List byCityName = countyDao.findByCityName(countyName); - if (byCityName == null || byCityName.size() == 0) { + List cityNameList = streetDao.findByCityName(countyName); + if (cityNameList == null || cityNameList.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale); } sysUserEntity.setActiveFlag(1); sysUserEntity.setAccountType("市级"); } else { - List byCountyCode = countyDao.findByCountyCode(countyCode); - if (byCountyCode == null || byCountyCode.isEmpty()) { + List countyCodeList = streetDao.findByCountyCode(countyCode); + if (countyCodeList == null || countyCodeList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "区县编码不存在!", locale); } - List byCountyName = countyDao.findByCountyName(countyName); - if (byCountyName == null || byCountyName.isEmpty()) { + List countyNameList = streetDao.findByCountyName(countyName); + if (countyNameList == null || countyNameList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale); } sysUserEntity.setActiveFlag(0);