Commit 055bc15b by chamberone

feat: 添加角色信息

1 parent 5365be9a
......@@ -26,11 +26,6 @@ public class ResourceInfo {
*/
private String extra;
/**
* 团队id
*/
@NotBlank(message = "团队ID不能为空!")
private String teamId;
/**
* 描述
*/
private String description;
......
......@@ -22,11 +22,6 @@ public class RoleInfo {
@NotBlank(message = "角色名称不能为空!")
private String name;
/**
* 团队id
*/
@NotBlank(message = "团队ID不能为空!")
private String teamId;
/**
* 角色组id
*/
private String groupId;
......
package com.dituhui.pea.pojo;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
......@@ -20,4 +22,7 @@ public class UserLoginDTO {
private String wechat;
private String token;
private List<RoleInfo> roles;
private List<ResourceInfo> resource;
}
......@@ -9,8 +9,6 @@ import org.springframework.data.repository.CrudRepository;
/**
* 角色表(Role)表数据库访问层
*
* @author zl
* @since 2020-12-09 15:33:38
*/
public interface RoleDao extends JpaRepository<RoleEntity, String>,
JpaSpecificationExecutor<RoleEntity>, CrudRepository<RoleEntity, String> {
......
......@@ -24,6 +24,12 @@ public interface UserRoleDao extends JpaRepository<UserRoleEntity, String>,
*/
List<UserRoleEntity> findByRoleId(String roleId);
/**
* 根据用户ID查询
* @param roleId 角色ID
* @return
*/
List<UserRoleEntity> findByUserId(String userId);
/**
* 根据角色ID和用户ID删除
......
......@@ -2,6 +2,7 @@ package com.dituhui.pea.user.service;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
......@@ -12,18 +13,24 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.enums.RedisKeyGroup;
import com.dituhui.pea.enums.StatusCodeEnum;
import com.dituhui.pea.enums.ThirdPartyEnum;
import com.dituhui.pea.exception.BusinessException;
import com.dituhui.pea.pojo.RoleInfo;
import com.dituhui.pea.pojo.ThirdUserInfo;
import com.dituhui.pea.pojo.UserInfo;
import com.dituhui.pea.pojo.UserLoginDTO;
import com.dituhui.pea.user.commom.RedisService;
import com.dituhui.pea.user.constant.TextConstant;
import com.dituhui.pea.user.dao.RoleDao;
import com.dituhui.pea.user.dao.UserDao;
import com.dituhui.pea.user.dao.UserRoleDao;
import com.dituhui.pea.user.entity.RoleEntity;
import com.dituhui.pea.user.entity.UserEntity;
import com.dituhui.pea.user.entity.UserRoleEntity;
import com.dituhui.pea.user.factory.ThirdStrategy;
import com.dituhui.pea.user.factory.ThirdStrategyFactory;
import com.dituhui.pea.user.utils.TextHelper;
......@@ -47,7 +54,7 @@ public class UserService {
/**
* 失效时间ms
*/
private static final int aliveTime = 7200000;
private static final int LIVE_TIME_MILLIS = 7200000;
@Autowired
UserDao userDao;
......@@ -58,17 +65,35 @@ public class UserService {
@Autowired
private RedisService redisService;
@Autowired
UserRoleDao userRoleDao;
@Autowired
RoleDao roleDao;
public Result<?> userLogin(String account, String password) {
UserEntity user = userDao.findByAccountAndPassword(account, SecureUtil.md5(password));
log.info("{}:{}:{}:{}", account, password, SecureUtil.md5(password), user);
log.info("{}/{} login", account, password);
if (null != user) {
// 生成token
UserLoginDTO userDTO = BeanUtil.copyProperties(user, UserLoginDTO.class);
// 生成token
String uuid = IdUtil.simpleUUID();
// 2小时
long timestamp = System.currentTimeMillis() + aliveTime;
long timestamp = System.currentTimeMillis() + LIVE_TIME_MILLIS;
redisService.set(RedisKeyGroup.authToken + ":" + uuid, user, timestamp);
UserLoginDTO userDTO = BeanUtil.copyProperties(user, UserLoginDTO.class);
// 获取角色
List<UserRoleEntity> userRoles = userRoleDao.findByUserId(user.getId());
if (CollectionUtils.isNotEmpty(userRoles)) {
List<RoleEntity> roles = roleDao
.findAllById(userRoles.stream().map(r -> r.getRoleId()).collect(Collectors.toList()));
if (CollectionUtils.isNotEmpty(roles)) {
userDTO.setRoles(roles.stream().map(r -> BeanUtil.copyProperties(r, RoleInfo.class))
.collect(Collectors.toList()));
}
}
// 获取资源
userDTO.setToken(uuid);
return Result.success(userDTO);
} else {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!