登录-获取用户角色信息
This commit is contained in:
+24
-17
@@ -7,6 +7,7 @@ import com.aliyuncs.exceptions.ClientException;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.jero.modules.config.entity.SysConfig;
|
import com.jero.modules.config.entity.SysConfig;
|
||||||
import com.jero.modules.config.service.ISysConfigService;
|
import com.jero.modules.config.service.ISysConfigService;
|
||||||
|
import com.jero.modules.system.entity.SysRole;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -34,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.management.relation.Role;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
@@ -152,7 +154,7 @@ public class LoginController {
|
|||||||
//update-end--Author:wangshuai Date:20200714 for:登录日志没有记录人员
|
//update-end--Author:wangshuai Date:20200714 for:登录日志没有记录人员
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出登录
|
* 退出登录
|
||||||
* @param request
|
* @param request
|
||||||
@@ -186,7 +188,7 @@ public class LoginController {
|
|||||||
return Result.error("Token无效!");
|
return Result.error("Token无效!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取访问量
|
* 获取访问量
|
||||||
* @return
|
* @return
|
||||||
@@ -217,7 +219,7 @@ public class LoginController {
|
|||||||
result.success("登录成功");
|
result.success("登录成功");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取访问量
|
* 获取访问量
|
||||||
* @return
|
* @return
|
||||||
@@ -238,8 +240,8 @@ public class LoginController {
|
|||||||
result.setResult(oConvertUtils.toLowerCasePageList(list));
|
result.setResult(oConvertUtils.toLowerCasePageList(list));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登陆成功选择用户当前部门
|
* 登陆成功选择用户当前部门
|
||||||
* @param user
|
* @param user
|
||||||
@@ -264,7 +266,7 @@ public class LoginController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信登录接口
|
* 短信登录接口
|
||||||
*
|
*
|
||||||
* @param jsonObject
|
* @param jsonObject
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -313,7 +315,7 @@ public class LoginController {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* smsmode 短信模板方式 0 .登录模板、1.注册模板、2.忘记密码模板
|
* smsmode 短信模板方式 0 .登录模板、1.注册模板、2.忘记密码模板
|
||||||
*/
|
*/
|
||||||
@@ -345,11 +347,11 @@ public class LoginController {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号登录接口
|
* 手机号登录接口
|
||||||
*
|
*
|
||||||
* @param jsonObject
|
* @param jsonObject
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -358,14 +360,14 @@ public class LoginController {
|
|||||||
public Result<JSONObject> phoneLogin(@RequestBody JSONObject jsonObject) {
|
public Result<JSONObject> phoneLogin(@RequestBody JSONObject jsonObject) {
|
||||||
Result<JSONObject> result = new Result<JSONObject>();
|
Result<JSONObject> result = new Result<JSONObject>();
|
||||||
String phone = jsonObject.getString("mobile");
|
String phone = jsonObject.getString("mobile");
|
||||||
|
|
||||||
//校验用户有效性
|
//校验用户有效性
|
||||||
SysUser sysUser = sysUserService.getUserByPhone(phone);
|
SysUser sysUser = sysUserService.getUserByPhone(phone);
|
||||||
result = sysUserService.checkUserIsEffective(sysUser);
|
result = sysUserService.checkUserIsEffective(sysUser);
|
||||||
if(!result.isSuccess()) {
|
if(!result.isSuccess()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
String smscode = jsonObject.getString("captcha");
|
String smscode = jsonObject.getString("captcha");
|
||||||
Object code = redisUtil.get(phone);
|
Object code = redisUtil.get(phone);
|
||||||
if (!smscode.equals(code)) {
|
if (!smscode.equals(code)) {
|
||||||
@@ -416,6 +418,11 @@ public class LoginController {
|
|||||||
// update-end--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
|
// update-end--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
|
||||||
obj.put("multi_depart", 2);
|
obj.put("multi_depart", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取用户角色信息
|
||||||
|
List<SysRole> userRoleListInfo = sysUserService.queryUserRoleListInfoByUserId(sysUser.getId());
|
||||||
|
sysUser.setUserRoleList(userRoleListInfo);
|
||||||
|
|
||||||
//获取配置信息
|
//获取配置信息
|
||||||
List<SysConfig> sysConfigs = iSysConfigService.queryList();
|
List<SysConfig> sysConfigs = iSysConfigService.queryList();
|
||||||
if(CollectionUtils.isNotEmpty(sysConfigs)){
|
if(CollectionUtils.isNotEmpty(sysConfigs)){
|
||||||
@@ -469,7 +476,7 @@ public class LoginController {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* app登录
|
* app登录
|
||||||
* @param sysLoginModel
|
* @param sysLoginModel
|
||||||
@@ -481,14 +488,14 @@ public class LoginController {
|
|||||||
Result<JSONObject> result = new Result<JSONObject>();
|
Result<JSONObject> result = new Result<JSONObject>();
|
||||||
String username = sysLoginModel.getUsername();
|
String username = sysLoginModel.getUsername();
|
||||||
String password = sysLoginModel.getPassword();
|
String password = sysLoginModel.getPassword();
|
||||||
|
|
||||||
//1. 校验用户是否有效
|
//1. 校验用户是否有效
|
||||||
SysUser sysUser = sysUserService.getUserByName(username);
|
SysUser sysUser = sysUserService.getUserByName(username);
|
||||||
result = sysUserService.checkUserIsEffective(sysUser);
|
result = sysUserService.checkUserIsEffective(sysUser);
|
||||||
if(!result.isSuccess()) {
|
if(!result.isSuccess()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//2. 校验用户名或密码是否正确
|
//2. 校验用户名或密码是否正确
|
||||||
String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());
|
String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());
|
||||||
String syspassword = sysUser.getPassword();
|
String syspassword = sysUser.getPassword();
|
||||||
@@ -496,7 +503,7 @@ public class LoginController {
|
|||||||
result.error500("用户名或密码错误");
|
result.error500("用户名或密码错误");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
String orgCode = sysUser.getOrgCode();
|
String orgCode = sysUser.getOrgCode();
|
||||||
if(oConvertUtils.isEmpty(orgCode)) {
|
if(oConvertUtils.isEmpty(orgCode)) {
|
||||||
//如果当前用户无选择部门 查看部门关联信息
|
//如果当前用户无选择部门 查看部门关联信息
|
||||||
@@ -512,7 +519,7 @@ public class LoginController {
|
|||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
//用户登录信息
|
//用户登录信息
|
||||||
obj.put("userInfo", sysUser);
|
obj.put("userInfo", sysUser);
|
||||||
|
|
||||||
// 生成token
|
// 生成token
|
||||||
String token = JwtUtil.sign(username, syspassword);
|
String token = JwtUtil.sign(username, syspassword);
|
||||||
// 设置超时时间
|
// 设置超时时间
|
||||||
@@ -567,4 +574,4 @@ public class LoginController {
|
|||||||
result.setResult(publicKeyBase64);
|
result.setResult(publicKeyBase64);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -15,6 +15,7 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -187,4 +188,8 @@ public class SysUser implements Serializable {
|
|||||||
//新添加的字段
|
//新添加的字段
|
||||||
private String jobCode;
|
private String jobCode;
|
||||||
private String jobTitle;
|
private String jobTitle;
|
||||||
|
|
||||||
|
//用户角色
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<SysRole> userRoleList;
|
||||||
}
|
}
|
||||||
|
|||||||
+8
@@ -8,11 +8,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
import com.jero.common.api.vo.Result;
|
import com.jero.common.api.vo.Result;
|
||||||
import com.jero.common.system.vo.SysUserCacheInfo;
|
import com.jero.common.system.vo.SysUserCacheInfo;
|
||||||
import com.jero.modules.system.entity.PPEmployee;
|
import com.jero.modules.system.entity.PPEmployee;
|
||||||
|
import com.jero.modules.system.entity.SysRole;
|
||||||
import com.jero.modules.system.entity.SysUser;
|
import com.jero.modules.system.entity.SysUser;
|
||||||
import com.jero.modules.system.model.DepartIdModel;
|
import com.jero.modules.system.model.DepartIdModel;
|
||||||
import com.jero.modules.system.model.SysUserSysDepartModel;
|
import com.jero.modules.system.model.SysUserSysDepartModel;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.management.relation.Role;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -262,4 +264,10 @@ public interface ISysUserService extends IService<SysUser> {
|
|||||||
|
|
||||||
void updatePPUserInfo(SysUser sysUser, PPEmployee ppEmployee);
|
void updatePPUserInfo(SysUser sysUser, PPEmployee ppEmployee);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户id,查询用户角色列表信息
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysRole> queryUserRoleListInfoByUserId(String userId);
|
||||||
}
|
}
|
||||||
|
|||||||
+18
@@ -24,6 +24,7 @@ import com.jero.modules.system.model.SysUserSysDepartModel;
|
|||||||
import com.jero.modules.system.service.ISysUserService;
|
import com.jero.modules.system.service.ISysUserService;
|
||||||
import com.jero.modules.system.vo.SysUserDepVo;
|
import com.jero.modules.system.vo.SysUserDepVo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
@@ -568,4 +569,21 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
updateById(sysUser);
|
updateById(sysUser);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysRole> queryUserRoleListInfoByUserId(String userId) {
|
||||||
|
List<SysRole> result = new ArrayList<>();
|
||||||
|
QueryWrapper<SysUserRole> userRoleQueryWrapper = new QueryWrapper<>();
|
||||||
|
userRoleQueryWrapper.lambda().eq(SysUserRole::getUserId,userId);
|
||||||
|
List<SysUserRole> sysUserRoles = this.sysUserRoleMapper.selectList(userRoleQueryWrapper);
|
||||||
|
if(CollectionUtils.isNotEmpty(sysUserRoles)){
|
||||||
|
List<String> roleIdList = sysUserRoles.stream().map(SysUserRole::getRoleId).distinct().collect(Collectors.toList());
|
||||||
|
if(CollectionUtils.isNotEmpty(roleIdList)){
|
||||||
|
QueryWrapper<SysRole> roleQueryWrapper = new QueryWrapper<>();
|
||||||
|
roleQueryWrapper.lambda().in(SysRole::getId,roleIdList);
|
||||||
|
result = this.sysRoleMapper.selectList(roleQueryWrapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user