登录-获取用户角色信息

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