登陆时添加了根据用户所在区域编码查询其下所属区域编码
This commit is contained in:
parent
9127969382
commit
28741f5585
@ -28,7 +28,10 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* jwt登录过滤器
|
* jwt登录过滤器
|
||||||
@ -106,7 +109,21 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter {
|
|||||||
response.setHeader("Access-Control-Allow-Credentials", "false");
|
response.setHeader("Access-Control-Allow-Credentials", "false");
|
||||||
response.setContentType("application/json");
|
response.setContentType("application/json");
|
||||||
response.setCharacterEncoding("UTF-8");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +56,7 @@ public class TokenAuthenticationService {
|
|||||||
* @param authorities
|
* @param authorities
|
||||||
*/
|
*/
|
||||||
static void addAuthentication(HttpServletResponse response, String userName,
|
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");
|
Locale locale = new Locale("zh", "CN");
|
||||||
Map map = new HashMap(3);
|
Map map = new HashMap(3);
|
||||||
@ -95,6 +95,7 @@ public class TokenAuthenticationService {
|
|||||||
.compact();
|
.compact();
|
||||||
map.put("token",jwt);
|
map.put("token",jwt);
|
||||||
map.put("user",sysUserEntity);
|
map.put("user",sysUserEntity);
|
||||||
|
map.put("cityAndCounty",map1);
|
||||||
}else {
|
}else {
|
||||||
/**
|
/**
|
||||||
* 过期时间6小时
|
* 过期时间6小时
|
||||||
@ -115,6 +116,7 @@ public class TokenAuthenticationService {
|
|||||||
.compact();
|
.compact();
|
||||||
map.put("token",jwt);
|
map.put("token",jwt);
|
||||||
map.put("user",sysUserEntity);
|
map.put("user",sysUserEntity);
|
||||||
|
map.put("cityAndCounty",map1);
|
||||||
}
|
}
|
||||||
// 将 JWT 写入 body
|
// 将 JWT 写入 body
|
||||||
PrintWriter out = null;
|
PrintWriter out = null;
|
||||||
|
@ -2,12 +2,39 @@ package com.xkrs.dao;
|
|||||||
|
|
||||||
import com.xkrs.model.entity.Nationwide;
|
import com.xkrs.model.entity.Nationwide;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author XinYi Song
|
* @author XinYi Song
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public interface NationwideDao extends JpaRepository<Nationwide,Long> {
|
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);
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,10 @@ package com.xkrs.service;
|
|||||||
import com.xkrs.model.entity.SysUserEntity;
|
import com.xkrs.model.entity.SysUserEntity;
|
||||||
import com.xkrs.model.qo.SysUserQo;
|
import com.xkrs.model.qo.SysUserQo;
|
||||||
import com.xkrs.model.vo.SysUserVo;
|
import com.xkrs.model.vo.SysUserVo;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统用户服务接口
|
* 系统用户服务接口
|
||||||
@ -150,4 +152,21 @@ public interface SysUserService {
|
|||||||
* @param loginNum
|
* @param loginNum
|
||||||
*/
|
*/
|
||||||
void updateLoginNum(Integer userId,Integer 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);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package com.xkrs.service.impl;
|
package com.xkrs.service.impl;
|
||||||
|
|
||||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||||
import com.xkrs.dao.RelRoleAuthorityDao;
|
import com.xkrs.dao.*;
|
||||||
import com.xkrs.dao.RelUserRoleDao;
|
|
||||||
import com.xkrs.dao.SysRoleDao;
|
|
||||||
import com.xkrs.dao.SysUserDao;
|
|
||||||
import com.xkrs.model.entity.RelRoleAuthorityEntity;
|
import com.xkrs.model.entity.RelRoleAuthorityEntity;
|
||||||
import com.xkrs.model.entity.RelUserRoleEntity;
|
import com.xkrs.model.entity.RelUserRoleEntity;
|
||||||
import com.xkrs.model.entity.SysRoleEntity;
|
import com.xkrs.model.entity.SysRoleEntity;
|
||||||
@ -25,6 +22,7 @@ import javax.annotation.Resource;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||||
import static com.xkrs.utils.DateTimeUtil.dateTimeToString;
|
import static com.xkrs.utils.DateTimeUtil.dateTimeToString;
|
||||||
@ -53,6 +51,9 @@ public class SysUserServiceImpl implements SysUserService {
|
|||||||
@Resource
|
@Resource
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private NationwideDao nationwideDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查用户名是否存在
|
* 检查用户名是否存在
|
||||||
* @param userName
|
* @param userName
|
||||||
@ -375,4 +376,19 @@ public class SysUserServiceImpl implements SysUserService {
|
|||||||
sysUserDao.updateLoginNum(userId,loginNum);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user