From 28741f5585fc48a8c6afc1bc88044a8e379483e9 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G8BCEP0\\HP" <2037158277@qq.com> Date: Fri, 24 Sep 2021 16:24:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E9=99=86=E6=97=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E6=A0=B9=E6=8D=AE=E7=94=A8=E6=88=B7=E6=89=80=E5=9C=A8?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E7=BC=96=E7=A0=81=E6=9F=A5=E8=AF=A2=E5=85=B6?= =?UTF-8?q?=E4=B8=8B=E6=89=80=E5=B1=9E=E5=8C=BA=E5=9F=9F=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/common/account/JwtLoginFilter.java | 19 ++++++++++++- .../account/TokenAuthenticationService.java | 4 ++- src/main/java/com/xkrs/dao/NationwideDao.java | 27 +++++++++++++++++++ .../java/com/xkrs/service/SysUserService.java | 19 +++++++++++++ .../xkrs/service/impl/SysUserServiceImpl.java | 24 ++++++++++++++--- 5 files changed, 87 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/xkrs/common/account/JwtLoginFilter.java b/src/main/java/com/xkrs/common/account/JwtLoginFilter.java index e30581e..ce04288 100644 --- a/src/main/java/com/xkrs/common/account/JwtLoginFilter.java +++ b/src/main/java/com/xkrs/common/account/JwtLoginFilter.java @@ -28,7 +28,10 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.List; import java.util.Locale; +import java.util.Map; /** * jwt登录过滤器 @@ -106,7 +109,21 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter { response.setHeader("Access-Control-Allow-Credentials", "false"); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); - TokenAuthenticationService.addAuthentication(response, auth.getName(),auth.getAuthorities(),userByUserName); + Map map = new HashMap(3); + if(userByUserName.getCountyCode().substring(2).equals("0000")){ + List> cityByProCode = sysUserService.findCityByProCode(userByUserName.getCountyCode()); + map.put("city",cityByProCode); + List> countyByProCode = sysUserService.findCountyByProCode(userByUserName.getCountyCode()); + map.put("county",countyByProCode); + TokenAuthenticationService.addAuthentication(response, auth.getName(),auth.getAuthorities(),userByUserName,map); + }else if(userByUserName.getCountyCode().substring(4).equals("00") && !userByUserName.getCountyCode().substring(2).equals("0000")) { + List> countyByCityCode = sysUserService.findCountyByCityCode(userByUserName.getCountyCode()); + map.put("county",countyByCityCode); + TokenAuthenticationService.addAuthentication(response, auth.getName(),auth.getAuthorities(),userByUserName,map); + }else { + map.put("county",null); + TokenAuthenticationService.addAuthentication(response, auth.getName(),auth.getAuthorities(),userByUserName,map); + } } /** diff --git a/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java b/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java index 0ae8969..6c49ef8 100644 --- a/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java +++ b/src/main/java/com/xkrs/common/account/TokenAuthenticationService.java @@ -56,7 +56,7 @@ public class TokenAuthenticationService { * @param authorities */ static void addAuthentication(HttpServletResponse response, String userName, - Collection authorities, SysUserVo sysUserEntity) { + Collection authorities, SysUserVo sysUserEntity, Map map1) { Locale locale = new Locale("zh", "CN"); Map map = new HashMap(3); @@ -95,6 +95,7 @@ public class TokenAuthenticationService { .compact(); map.put("token",jwt); map.put("user",sysUserEntity); + map.put("cityAndCounty",map1); }else { /** * 过期时间6小时 @@ -115,6 +116,7 @@ public class TokenAuthenticationService { .compact(); map.put("token",jwt); map.put("user",sysUserEntity); + map.put("cityAndCounty",map1); } // 将 JWT 写入 body PrintWriter out = null; diff --git a/src/main/java/com/xkrs/dao/NationwideDao.java b/src/main/java/com/xkrs/dao/NationwideDao.java index b5e34a0..bf064aa 100644 --- a/src/main/java/com/xkrs/dao/NationwideDao.java +++ b/src/main/java/com/xkrs/dao/NationwideDao.java @@ -2,12 +2,39 @@ package com.xkrs.dao; import com.xkrs.model.entity.Nationwide; 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 NationwideDao extends JpaRepository { + /** + * 通过省编码查询市名称和编码 + * @param proCode + * @return + */ + @Query(value = "select city_name,city_code from nationwide where pro_code = ?",nativeQuery = true) + List> findCityByProCode(String proCode); + + /** + * 通过省编码查询县名称和编码 + * @param proCode + * @return + */ + @Query(value = "select county_name,county_code from nationwide where pro_code = ?",nativeQuery = true) + List> findCountyByProCode(String proCode); + + /** + * 通过市编码查询区县名称和编码 + * @param cityCode + * @return + */ + @Query(value = "select county_name,county_code from nationwide where city_code = ?",nativeQuery = true) + List> findCountyByCityCode(String cityCode); } diff --git a/src/main/java/com/xkrs/service/SysUserService.java b/src/main/java/com/xkrs/service/SysUserService.java index ef23fc0..38f6974 100644 --- a/src/main/java/com/xkrs/service/SysUserService.java +++ b/src/main/java/com/xkrs/service/SysUserService.java @@ -3,8 +3,10 @@ package com.xkrs.service; import com.xkrs.model.entity.SysUserEntity; import com.xkrs.model.qo.SysUserQo; import com.xkrs.model.vo.SysUserVo; +import org.springframework.data.jpa.repository.Query; import java.util.List; +import java.util.Map; /** * 系统用户服务接口 @@ -150,4 +152,21 @@ public interface SysUserService { * @param loginNum */ void updateLoginNum(Integer userId,Integer loginNum); + + + List> findCityByProCode(String proCode); + + /** + * 通过省编码查询县名称和编码 + * @param proCode + * @return + */ + List> findCountyByProCode(String proCode); + + /** + * 通过市编码查询区县名称和编码 + * @param cityCode + * @return + */ + List> findCountyByCityCode(String cityCode); } diff --git a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java index 73f38a4..01815e7 100644 --- a/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java @@ -1,10 +1,7 @@ package com.xkrs.service.impl; import com.xkrs.common.encapsulation.PromptMessageEnum; -import com.xkrs.dao.RelRoleAuthorityDao; -import com.xkrs.dao.RelUserRoleDao; -import com.xkrs.dao.SysRoleDao; -import com.xkrs.dao.SysUserDao; +import com.xkrs.dao.*; import com.xkrs.model.entity.RelRoleAuthorityEntity; import com.xkrs.model.entity.RelUserRoleEntity; import com.xkrs.model.entity.SysRoleEntity; @@ -25,6 +22,7 @@ import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.List; import java.util.Locale; +import java.util.Map; import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; import static com.xkrs.utils.DateTimeUtil.dateTimeToString; @@ -53,6 +51,9 @@ public class SysUserServiceImpl implements SysUserService { @Resource private RedisService redisService; + @Resource + private NationwideDao nationwideDao; + /** * 检查用户名是否存在 * @param userName @@ -375,4 +376,19 @@ public class SysUserServiceImpl implements SysUserService { sysUserDao.updateLoginNum(userId,loginNum); } + @Override + public List> findCityByProCode(String proCode) { + return nationwideDao.findCityByProCode(proCode); + } + + @Override + public List> findCountyByProCode(String proCode) { + return nationwideDao.findCountyByProCode(proCode); + } + + @Override + public List> findCountyByCityCode(String cityCode) { + return nationwideDao.findCountyByCityCode(cityCode); + } + }