diff --git a/src/main/java/com/xkrs/common/account/JwtLoginFilter.java b/src/main/java/com/xkrs/common/account/JwtLoginFilter.java index b39fb89..dc52445 100644 --- a/src/main/java/com/xkrs/common/account/JwtLoginFilter.java +++ b/src/main/java/com/xkrs/common/account/JwtLoginFilter.java @@ -2,8 +2,8 @@ package com.xkrs.common.account; import com.xkrs.common.encapsulation.OutputEncapsulation; import com.xkrs.common.encapsulation.PromptMessageEnum; -import com.xkrs.dao.StreetDao; import com.xkrs.model.vo.SysUserVo; +import com.xkrs.service.StreetService; import com.xkrs.service.SysUserService; import com.xkrs.utils.IpUtil; import org.slf4j.Logger; @@ -46,7 +46,7 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter { private SysUserService sysUserService; @Resource - private StreetDao streetDao; + private StreetService streetService; public JwtLoginFilter(String url, AuthenticationManager authManager) { super(new AntPathRequestMatcher(url)); @@ -101,6 +101,11 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter { WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); sysUserService = webApplicationContext.getBean(SysUserService.class); } + if (streetService == null) { + ServletContext servletContext = req.getServletContext(); + WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); + streetService = webApplicationContext.getBean(StreetService.class); + } //更新用户登录信息 sysUserService.updateSysUserLogin(auth.getName(), IpUtil.getIpAddr(req)); SysUserVo userByUserName = sysUserService.getUserByUserName(auth.getName()); @@ -110,7 +115,7 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter { response.setCharacterEncoding("UTF-8"); Map map = new HashMap(3); if (9 == userByUserName.getCountyCode().length()) { - List> streetByCountyCode = streetDao.selectStreetList(userByUserName.getCountyCode()); + List> streetByCountyCode = streetService.selectStreetList(userByUserName.getCountyCode()); map.put("county", streetByCountyCode); TokenAuthenticationService.addAuthentication(response, auth.getName(), auth.getAuthorities(), userByUserName, map); } else if (userByUserName.getCountyCode().substring(2).equals("0000")) { diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index bcac94e..66726ff 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -65,6 +65,10 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET,"/api/user/getVerificationCode").permitAll() .antMatchers(HttpMethod.POST,"/api/user/userUnRememberPassword").permitAll() .antMatchers(HttpMethod.POST,"/updateBeforeFireAndAfterFireImage").permitAll() + .antMatchers(HttpMethod.GET,"/getProvinceList").permitAll()//获取省列表 + .antMatchers(HttpMethod.GET,"/getCityList").permitAll()//根据省编号获取市列表 + .antMatchers(HttpMethod.GET,"/getCountyList").permitAll()//根据市编号获取区县列表 + .antMatchers(HttpMethod.GET,"/getStreetList").permitAll()//根据区县编号获取街道列表 // 所有其它请求需要身份认证 .anyRequest().authenticated() .and() diff --git a/src/main/java/com/xkrs/dao/StreetDao.java b/src/main/java/com/xkrs/dao/StreetDao.java index c4a77be..928c0d8 100644 --- a/src/main/java/com/xkrs/dao/StreetDao.java +++ b/src/main/java/com/xkrs/dao/StreetDao.java @@ -8,7 +8,6 @@ import org.springframework.stereotype.Component; import java.util.List; import java.util.Map; -import java.util.Optional; @Component public interface StreetDao extends JpaRepository, JpaSpecificationExecutor { @@ -25,9 +24,9 @@ public interface StreetDao extends JpaRepository, JpaSpec List findByCountyCode(String countyCode); - Optional findByStreetName(String streetName); + List findByStreetName(String streetName); - Optional findByStreetCode(String streetCode); + List findByStreetCode(String streetCode); @Query(value = "SELECT DISTINCT t.pro_code AS code, t.pro_name AS name FROM street AS t", nativeQuery = true) List> selectProvinceList(); diff --git a/src/main/java/com/xkrs/service/StreetService.java b/src/main/java/com/xkrs/service/StreetService.java new file mode 100644 index 0000000..c676dfa --- /dev/null +++ b/src/main/java/com/xkrs/service/StreetService.java @@ -0,0 +1,33 @@ +package com.xkrs.service; + +import com.xkrs.model.entity.StreetEntity; + +import java.util.List; +import java.util.Map; + +public interface StreetService { + + List findByProName(String proName); + + List findByProCode(String proCode); + + List findByCityName(String cityName); + + List findByCityCode(String cityCode); + + List findByCountyName(String countyName); + + List findByCountyCode(String countyCode); + + List findByStreetName(String streetName); + + List findByStreetCode(String streetCode); + + List> selectProvinceList(); + + List> selectCityList(String provinceCode); + + List> selectCountyList(String cityCode); + + List> selectStreetList(String countyCode); +} diff --git a/src/main/java/com/xkrs/service/impl/StreetServiceImpl.java b/src/main/java/com/xkrs/service/impl/StreetServiceImpl.java new file mode 100644 index 0000000..a410194 --- /dev/null +++ b/src/main/java/com/xkrs/service/impl/StreetServiceImpl.java @@ -0,0 +1,77 @@ +package com.xkrs.service.impl; + +import com.xkrs.dao.StreetDao; +import com.xkrs.model.entity.StreetEntity; +import com.xkrs.service.StreetService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +@Service +public class StreetServiceImpl implements StreetService { + + @Resource + private StreetDao streetDao; + + @Override + public List findByProName(String proName) { + return streetDao.findByProName(proName); + } + + @Override + public List findByProCode(String proCode) { + return streetDao.findByProCode(proCode); + } + + @Override + public List findByCityName(String cityName) { + return streetDao.findByCityName(cityName); + } + + @Override + public List findByCityCode(String cityCode) { + return streetDao.findByCityCode(cityCode); + } + + @Override + public List findByCountyName(String countyName) { + return streetDao.findByCountyName(countyName); + } + + @Override + public List findByCountyCode(String countyCode) { + return streetDao.findByCountyCode(countyCode); + } + + @Override + public List findByStreetName(String streetName) { + return streetDao.findByStreetName(streetName); + } + + @Override + public List findByStreetCode(String streetCode) { + return streetDao.findByStreetCode(streetCode); + } + + @Override + public List> selectProvinceList() { + return streetDao.selectProvinceList(); + } + + @Override + public List> selectCityList(String provinceCode) { + return streetDao.selectCityList(provinceCode); + } + + @Override + public List> selectCountyList(String cityCode) { + return streetDao.selectCountyList(cityCode); + } + + @Override + public List> selectStreetList(String countyCode) { + return streetDao.selectStreetList(countyCode); + } +} diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index b34d9cf..d3d4340 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -19,7 +19,6 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Optional; import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; import static com.xkrs.utils.DateTimeUtil.dateTimeToString; @@ -110,12 +109,12 @@ public class SysUserServiceImpl implements SysUserService { } if (9 == countyCode.length()) { - Optional byStreetCodeOptional = streetDao.findByStreetCode(countyCode); - if (byStreetCodeOptional.isEmpty()) { + List byStreetCode = streetDao.findByStreetCode(countyCode); + if (byStreetCode == null || byStreetCode.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "街道编码不存在!", locale); } - Optional byStreetNameOptional = streetDao.findByStreetName(countyName); - if (byStreetNameOptional.isEmpty()) { + List byStreetName = streetDao.findByStreetName(countyName); + if (byStreetName == null || byStreetName.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "您所选择的区域不存在!", locale); } sysUserEntity.setActiveFlag(0);