mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-09 20:57:21 +08:00
refactor: 用户角色名称调整为角色名称列表返回,并全局优化 Crane4j 组件的使用方式
This commit is contained in:
@@ -16,10 +16,10 @@
|
||||
|
||||
package top.continew.admin.auth.model.resp;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import cn.crane4j.annotation.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.auth.service.OnlineUserService;
|
||||
import top.continew.admin.common.constant.ContainerConstants;
|
||||
|
||||
import java.io.Serial;
|
||||
@@ -43,14 +43,14 @@ public class OnlineUserResp implements Serializable {
|
||||
* ID
|
||||
*/
|
||||
@Schema(description = "ID", example = "1")
|
||||
@Assemble(container = ContainerConstants.USER_NICKNAME, props = @Mapping(ref = "nickname"))
|
||||
@Assemble(prop = ":nickname", container = ContainerConstants.USER_NICKNAME)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 令牌
|
||||
*/
|
||||
@Schema(description = "令牌", example = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOjEsInJuU3RyIjoiTUd6djdyOVFoeHEwdVFqdFAzV3M5YjVJRzh4YjZPSEUifQ.7q7U3ouoN7WPhH2kUEM7vPe5KF3G_qavSG-vRgIxKvE")
|
||||
@Assemble(container = ContainerConstants.ONLINE_USER_LAST_ACTIVE_TIME, props = @Mapping(ref = "lastActiveTime"))
|
||||
@AssembleMethod(prop = ":lastActiveTime", targetType = OnlineUserService.class, method = @ContainerMethod(bindMethod = "getLastActiveTime", type = MappingType.ORDER_OF_KEYS))
|
||||
private String token;
|
||||
|
||||
/**
|
||||
|
@@ -17,8 +17,6 @@
|
||||
package top.continew.admin.auth.service.impl;
|
||||
|
||||
import cn.crane4j.annotation.AutoOperate;
|
||||
import cn.crane4j.annotation.ContainerMethod;
|
||||
import cn.crane4j.annotation.MappingType;
|
||||
import cn.dev33.satoken.dao.SaTokenDao;
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
@@ -30,7 +28,6 @@ import org.springframework.stereotype.Service;
|
||||
import top.continew.admin.auth.model.query.OnlineUserQuery;
|
||||
import top.continew.admin.auth.model.resp.OnlineUserResp;
|
||||
import top.continew.admin.auth.service.OnlineUserService;
|
||||
import top.continew.admin.common.constant.ContainerConstants;
|
||||
import top.continew.admin.common.model.dto.LoginUser;
|
||||
import top.continew.admin.common.util.helper.LoginHelper;
|
||||
import top.continew.starter.core.constant.StringConstants;
|
||||
@@ -84,7 +81,6 @@ public class OnlineUserServiceImpl implements OnlineUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ContainerMethod(namespace = ContainerConstants.ONLINE_USER_LAST_ACTIVE_TIME, type = MappingType.ORDER_OF_KEYS)
|
||||
public LocalDateTime getLastActiveTime(String token) {
|
||||
long lastActiveTime = StpUtil.getStpLogic().getTokenLastActiveTime(token);
|
||||
return lastActiveTime == SaTokenDao.NOT_VALUE_EXPIRE ? null : DateUtil.date(lastActiveTime).toLocalDateTime();
|
||||
|
@@ -59,7 +59,7 @@ public class DeptResp extends BaseDetailResp {
|
||||
*/
|
||||
@Schema(description = "上级部门 ID", example = "2")
|
||||
@ConditionOnExpression(value = "#target.parentId != 0")
|
||||
@AssembleMethod(targetType = DeptService.class, method = @ContainerMethod(bindMethod = "get", resultType = DeptResp.class), props = @Mapping(src = "name", ref = "parentName"))
|
||||
@AssembleMethod(props = @Mapping(src = "name", ref = "parentName"), targetType = DeptService.class, method = @ContainerMethod(bindMethod = "get", resultType = DeptResp.class))
|
||||
@ExcelProperty(value = "上级部门 ID", order = 3)
|
||||
private Long parentId;
|
||||
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package top.continew.admin.system.model.resp;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -81,7 +80,7 @@ public class MessageResp implements Serializable {
|
||||
* 创建人
|
||||
*/
|
||||
@JsonIgnore
|
||||
@Assemble(container = ContainerConstants.USER_NICKNAME, props = @Mapping(ref = "createUserString"))
|
||||
@Assemble(prop = ":createUserString", container = ContainerConstants.USER_NICKNAME)
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
|
@@ -16,14 +16,15 @@
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import cn.crane4j.annotation.AssembleMethod;
|
||||
import cn.crane4j.annotation.ContainerMethod;
|
||||
import cn.crane4j.annotation.MappingType;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.common.constant.ContainerConstants;
|
||||
import top.continew.admin.common.enums.DataScopeEnum;
|
||||
import top.continew.admin.system.service.RoleDeptService;
|
||||
import top.continew.starter.extension.crud.converter.ExcelBaseEnumConverter;
|
||||
import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
|
||||
|
||||
@@ -39,7 +40,7 @@ import java.util.List;
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@Schema(description = "角色详情信息")
|
||||
@Assemble(container = ContainerConstants.ROLE_DEPT_ID_LIST, key = "id", props = @Mapping(ref = "deptIds"))
|
||||
@AssembleMethod(key = "id", prop = ":deptIds", targetType = RoleDeptService.class, method = @ContainerMethod(bindMethod = "listDeptIdByRoleId", type = MappingType.ORDER_OF_KEYS))
|
||||
public class RoleDetailResp extends BaseDetailResp {
|
||||
|
||||
@Serial
|
||||
|
@@ -20,6 +20,7 @@ import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.AssembleMethod;
|
||||
import cn.crane4j.annotation.ContainerMethod;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import cn.crane4j.core.executor.handler.ManyToManyAssembleOperationHandler;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -46,7 +47,7 @@ import java.util.Objects;
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@Schema(description = "用户详情信息")
|
||||
@Assemble(container = ContainerConstants.USER_ROLE_ID_LIST, key = "id", props = @Mapping(ref = "roleIds"))
|
||||
@Assemble(key = "id", prop = ":roleIds", container = ContainerConstants.USER_ROLE_ID_LIST)
|
||||
public class UserDetailResp extends BaseDetailResp {
|
||||
|
||||
@Serial
|
||||
@@ -125,7 +126,7 @@ public class UserDetailResp extends BaseDetailResp {
|
||||
* 部门 ID
|
||||
*/
|
||||
@Schema(description = "部门 ID", example = "5")
|
||||
@AssembleMethod(targetType = DeptService.class, method = @ContainerMethod(bindMethod = "get", resultType = DeptResp.class), props = @Mapping(src = "name", ref = "deptName"))
|
||||
@AssembleMethod(props = @Mapping(src = "name", ref = "deptName"), targetType = DeptService.class, method = @ContainerMethod(bindMethod = "get", resultType = DeptResp.class))
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
@@ -139,14 +140,15 @@ public class UserDetailResp extends BaseDetailResp {
|
||||
* 角色 ID 列表
|
||||
*/
|
||||
@Schema(description = "角色 ID 列表", example = "2")
|
||||
@Assemble(prop = ":roleNames", container = ContainerConstants.USER_ROLE_NAME_LIST, handlerType = ManyToManyAssembleOperationHandler.class)
|
||||
private List<Long> roleIds;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
* 角色名称列表
|
||||
*/
|
||||
@Schema(description = "角色", example = "测试人员")
|
||||
@Schema(description = "角色名称列表", example = "测试人员")
|
||||
@ExcelProperty(value = "角色")
|
||||
private String roleNames;
|
||||
private List<String> roleNames;
|
||||
|
||||
@Override
|
||||
public Boolean getDisabled() {
|
||||
|
@@ -16,11 +16,14 @@
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.AssembleMethod;
|
||||
import cn.crane4j.annotation.ContainerMethod;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import cn.crane4j.core.executor.handler.ManyToManyAssembleOperationHandler;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.common.constant.ContainerConstants;
|
||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.continew.admin.common.enums.GenderEnum;
|
||||
import top.continew.admin.common.util.helper.LoginHelper;
|
||||
@@ -30,6 +33,7 @@ import top.continew.starter.security.mask.annotation.JsonMask;
|
||||
import top.continew.starter.security.mask.enums.MaskType;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -40,6 +44,7 @@ import java.util.Objects;
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "用户信息")
|
||||
@Assemble(key = "id", prop = ":roleIds", container = ContainerConstants.USER_ROLE_ID_LIST)
|
||||
public class UserResp extends BaseDetailResp {
|
||||
|
||||
@Serial
|
||||
@@ -105,7 +110,7 @@ public class UserResp extends BaseDetailResp {
|
||||
* 部门 ID
|
||||
*/
|
||||
@Schema(description = "部门 ID", example = "5")
|
||||
@AssembleMethod(targetType = DeptService.class, method = @ContainerMethod(bindMethod = "get", resultType = DeptResp.class), props = @Mapping(src = "name", ref = "deptName"))
|
||||
@AssembleMethod(props = @Mapping(src = "name", ref = "deptName"), targetType = DeptService.class, method = @ContainerMethod(bindMethod = "get", resultType = DeptResp.class))
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
@@ -114,6 +119,19 @@ public class UserResp extends BaseDetailResp {
|
||||
@Schema(description = "所属部门", example = "测试部")
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 角色 ID 列表
|
||||
*/
|
||||
@Schema(description = "角色 ID 列表", example = "2")
|
||||
@Assemble(prop = ":roleNames", container = ContainerConstants.USER_ROLE_NAME_LIST, handlerType = ManyToManyAssembleOperationHandler.class)
|
||||
private List<Long> roleIds;
|
||||
|
||||
/**
|
||||
* 角色名称列表
|
||||
*/
|
||||
@Schema(description = "角色名称列表", example = "测试人员")
|
||||
private List<String> roleNames;
|
||||
|
||||
@Override
|
||||
public Boolean getDisabled() {
|
||||
return this.getIsSystem() || Objects.equals(this.getId(), LoginHelper.getUserId());
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package top.continew.admin.system.model.resp.log;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import cn.crane4j.annotation.condition.ConditionOnPropertyNotNull;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -155,7 +154,7 @@ public class LogDetailResp implements Serializable {
|
||||
*/
|
||||
@JsonIgnore
|
||||
@ConditionOnPropertyNotNull
|
||||
@Assemble(container = ContainerConstants.USER_NICKNAME, props = @Mapping(ref = "createUserString"))
|
||||
@Assemble(prop = ":createUserString", container = ContainerConstants.USER_NICKNAME)
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
|
@@ -16,13 +16,10 @@
|
||||
|
||||
package top.continew.admin.system.service.impl;
|
||||
|
||||
import cn.crane4j.annotation.ContainerMethod;
|
||||
import cn.crane4j.annotation.MappingType;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.continew.admin.common.constant.ContainerConstants;
|
||||
import top.continew.admin.system.mapper.RoleDeptMapper;
|
||||
import top.continew.admin.system.model.entity.RoleDeptDO;
|
||||
import top.continew.admin.system.service.RoleDeptService;
|
||||
@@ -75,7 +72,6 @@ public class RoleDeptServiceImpl implements RoleDeptService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ContainerMethod(namespace = ContainerConstants.ROLE_DEPT_ID_LIST, type = MappingType.ORDER_OF_KEYS)
|
||||
public List<Long> listDeptIdByRoleId(Long roleId) {
|
||||
return baseMapper.selectDeptIdByRoleId(roleId);
|
||||
}
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package top.continew.admin.system.service.impl;
|
||||
|
||||
import cn.crane4j.annotation.ContainerMethod;
|
||||
import cn.crane4j.annotation.MappingType;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
@@ -25,6 +27,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.continew.admin.auth.service.OnlineUserService;
|
||||
import top.continew.admin.common.constant.CacheConstants;
|
||||
import top.continew.admin.common.constant.ContainerConstants;
|
||||
import top.continew.admin.common.constant.SysConstants;
|
||||
import top.continew.admin.common.enums.DataScopeEnum;
|
||||
import top.continew.admin.common.model.dto.RoleDTO;
|
||||
@@ -142,6 +145,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
|
||||
}
|
||||
|
||||
@Override
|
||||
@ContainerMethod(namespace = ContainerConstants.USER_ROLE_NAME_LIST, type = MappingType.ORDER_OF_KEYS)
|
||||
public List<String> listNameByIds(List<Long> ids) {
|
||||
List<RoleDO> roleList = baseMapper.lambdaQuery().select(RoleDO::getName).in(RoleDO::getId, ids).list();
|
||||
return roleList.stream().map(RoleDO::getName).toList();
|
||||
|
@@ -79,7 +79,6 @@ import static top.continew.admin.system.enums.PasswordPolicyEnum.*;
|
||||
public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserResp, UserDetailResp, UserQuery, UserReq> implements UserService, CommonUserService {
|
||||
|
||||
private final OnlineUserService onlineUserService;
|
||||
private final RoleService roleService;
|
||||
private final UserRoleService userRoleService;
|
||||
private final FileService fileService;
|
||||
private final FileStorageService fileStorageService;
|
||||
@@ -283,17 +282,6 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
return baseMapper.selectNicknameById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fill(Object obj) {
|
||||
super.fill(obj);
|
||||
if (obj instanceof UserDetailResp detail) {
|
||||
List<Long> roleIdList = detail.getRoleIds();
|
||||
if (CollUtil.isNotEmpty(roleIdList)) {
|
||||
detail.setRoleNames(String.join(StringConstants.CHINESE_COMMA, roleService.listNameByIds(roleIdList)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QueryWrapper<UserDO> buildQueryWrapper(UserQuery query) {
|
||||
String description = query.getDescription();
|
||||
|
Reference in New Issue
Block a user