登陆时添加了根据用户所在区域编码查询其下所属区域编码

This commit is contained in:
DESKTOP-G8BCEP0\HP 2021-09-24 16:24:12 +08:00
parent 9127969382
commit 28741f5585
5 changed files with 87 additions and 6 deletions

View File

@ -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<Map<String, String>> cityByProCode = sysUserService.findCityByProCode(userByUserName.getCountyCode());
map.put("city",cityByProCode);
List<Map<String, String>> 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<Map<String, String>> 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);
}
}
/**

View File

@ -56,7 +56,7 @@ public class TokenAuthenticationService {
* @param authorities
*/
static void addAuthentication(HttpServletResponse response, String userName,
Collection<? extends GrantedAuthority> authorities, SysUserVo sysUserEntity) {
Collection<? extends GrantedAuthority> 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;

View File

@ -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<Nationwide,Long> {
/**
* 通过省编码查询市名称和编码
* @param proCode
* @return
*/
@Query(value = "select city_name,city_code from nationwide where pro_code = ?",nativeQuery = true)
List<Map<String,String>> findCityByProCode(String proCode);
/**
* 通过省编码查询县名称和编码
* @param proCode
* @return
*/
@Query(value = "select county_name,county_code from nationwide where pro_code = ?",nativeQuery = true)
List<Map<String,String>> findCountyByProCode(String proCode);
/**
* 通过市编码查询区县名称和编码
* @param cityCode
* @return
*/
@Query(value = "select county_name,county_code from nationwide where city_code = ?",nativeQuery = true)
List<Map<String,String>> findCountyByCityCode(String cityCode);
}

View File

@ -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<Map<String,String>> findCityByProCode(String proCode);
/**
* 通过省编码查询县名称和编码
* @param proCode
* @return
*/
List<Map<String,String>> findCountyByProCode(String proCode);
/**
* 通过市编码查询区县名称和编码
* @param cityCode
* @return
*/
List<Map<String,String>> findCountyByCityCode(String cityCode);
}

View File

@ -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<Map<String, String>> findCityByProCode(String proCode) {
return nationwideDao.findCityByProCode(proCode);
}
@Override
public List<Map<String, String>> findCountyByProCode(String proCode) {
return nationwideDao.findCountyByProCode(proCode);
}
@Override
public List<Map<String, String>> findCountyByCityCode(String cityCode) {
return nationwideDao.findCountyByCityCode(cityCode);
}
}