diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index 1187bad..74b69a7 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -247,11 +247,16 @@ public class FirePointController { * @return */ @GetMapping("/selectCityName") - public String selectCityName(){ + public String selectCityName(@RequestParam("code") String code){ // 获取区域信息 Locale locale = LocaleContextHolder.getLocale(); - List> maps = firePointService.selectCityName(); - return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); + if(code.substring(2).equals("0000")){ + List> maps = firePointService.selectCityName(code); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); + }else { + List> maps = firePointService.selectCountyName(code); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); + } } /** diff --git a/src/main/java/com/xkrs/dao/CityDao.java b/src/main/java/com/xkrs/dao/CityDao.java index 69b9927..9f27699 100644 --- a/src/main/java/com/xkrs/dao/CityDao.java +++ b/src/main/java/com/xkrs/dao/CityDao.java @@ -25,8 +25,9 @@ public interface CityDao extends JpaRepository, JpaSpecificatio /** * 查询所有市和对应的编码 + * @param code * @return */ - @Query(value = "select city_name cityname,city_code citycode from city",nativeQuery = true) - List> selectCityName(); + @Query(value = "select city_name cityname,city_code citycode from city where pro_code = :code",nativeQuery = true) + List> selectCityName(String code); } diff --git a/src/main/java/com/xkrs/dao/CountyDao.java b/src/main/java/com/xkrs/dao/CountyDao.java index d131465..6914b6e 100644 --- a/src/main/java/com/xkrs/dao/CountyDao.java +++ b/src/main/java/com/xkrs/dao/CountyDao.java @@ -2,11 +2,22 @@ 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); } diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index 202b905..c2387b2 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -124,7 +124,15 @@ public interface FirePointService { /** * 查询该省所有的市 + * @param code * @return */ - List> selectCityName(); + 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 698ce53..555112e 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -63,6 +63,9 @@ public class FirePointServiceImpl implements FirePointService { @Resource private CityDao cityDao; + @Resource + private CountyDao countyDao; + /** * 添加火点信息 * @param firePointQo @@ -386,10 +389,21 @@ public class FirePointServiceImpl implements FirePointService { /** * 查询该省所有的市 + * @param code * @return */ @Override - public List> selectCityName() { - return cityDao.selectCityName(); + public List> selectCityName(String code) { + return cityDao.selectCityName(code); + } + + /** + * 查询市包含的区县和编码 + * @param code + * @return + */ + @Override + public List> selectCountyName(String code) { + return countyDao.selectCountyName(code); } }