Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts:
#	yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImplTest.java
  • Loading branch information
YunaiV committed Apr 4, 2024
2 parents c945f43 + 9ade968 commit 0d8cac4
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import cn.iocoder.yudao.framework.datapermission.core.aop.DataPermissionContextHolder;
import lombok.SneakyThrows;

import java.util.concurrent.Callable;

/**
* 数据权限 Util
*
Expand Down Expand Up @@ -40,4 +42,22 @@ public static void executeIgnore(Runnable runnable) {
}
}

/**
* 忽略数据权限,执行对应的逻辑
*
* @param callable 逻辑
* @return 执行结果
*/
@SneakyThrows
public static <T> T executeIgnore(Callable<T> callable) {
DataPermission dataPermission = getDisableDataPermissionDisable();
DataPermissionContextHolder.add(dataPermission);
try {
// 执行 callable
return callable.call();
} finally {
DataPermissionContextHolder.remove();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
public interface DictTypeConstants {

String REDIS_TIMEOUT_TYPE = "infra_redis_timeout_type"; // Redis 超时类型

String JOB_STATUS = "infra_job_status"; // 定时任务状态的枚举
String JOB_LOG_STATUS = "infra_job_log_status"; // 定时任务日志状态的枚举

Expand All @@ -17,4 +15,6 @@ public interface DictTypeConstants {
String CONFIG_TYPE = "infra_config_type"; // 参数配置类型
String BOOLEAN_STRING = "infra_boolean_string"; // Boolean 是否类型

String OPERATE_TYPE = "infra_operate_type"; // 操作类型

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class ApiAccessLogRespVO {

@Schema(description = "操作分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty(value = "操作分类", converter = DictConvert.class)
@DictFormat(DictTypeConstants.OPERATE_TYPE)
@DictFormat(cn.iocoder.yudao.module.infra.enums.DictTypeConstants.OPERATE_TYPE)
private Integer operateType;

@Schema(description = "开始请求时间", requiredMode = Schema.RequiredMode.REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public interface DictTypeConstants {

String USER_SEX = "system_user_sex"; // 用户性别

String OPERATE_TYPE = "system_operate_type"; // 操作类型

String LOGIN_TYPE = "system_login_type"; // 登录日志的类型
String LOGIN_RESULT = "system_login_result"; // 登录结果

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.system.enums;

/**
* System 操作日志枚举
* 目的:统一管理,也减少 Service 里各种“复杂”字符串
*
* @author 芋道源码
*/
public interface LogRecordConstants {

// ======================= SYSTEM_USER 用户 =======================

String SYSTEM_USER_TYPE = "SYSTEM 用户";
String SYSTEM_USER_CREATE_SUB_TYPE = "创建用户";
String SYSTEM_USER_CREATE_SUCCESS = "创建了用户【{{#user.nickname}}】";
String SYSTEM_USER_UPDATE_SUB_TYPE = "更新用户";
String SYSTEM_USER_UPDATE_SUCCESS = "更新了用户【{{#user.nickname}}】: {_DIFF{#updateReqVO}}";
String SYSTEM_USER_DELETE_SUB_TYPE = "删除用户";
String SYSTEM_USER_DELETE_SUCCESS = "删除了用户【{{#user.nickname}}】";
String SYSTEM_USER_UPDATE_PASSWORD_SUB_TYPE = "重置用户密码";
String SYSTEM_USER_UPDATE_PASSWORD_SUCCESS = "将用户【{{#user.nickname}}】的密码从【{{#user.password}}】重置为【{{#newPassword}}】";

// ======================= SYSTEM_ROLE 角色 =======================

String SYSTEM_ROLE_TYPE = "SYSTEM 角色";
String SYSTEM_ROLE_CREATE_SUB_TYPE = "创建角色";
String SYSTEM_ROLE_CREATE_SUCCESS = "创建了角色【{{#role.name}}】";
String SYSTEM_ROLE_UPDATE_SUB_TYPE = "更新角色";
String SYSTEM_ROLE_UPDATE_SUCCESS = "更新了角色【{{#role.name}}】: {_DIFF{#updateReqVO}}";
String SYSTEM_ROLE_DELETE_SUB_TYPE = "删除角色";
String SYSTEM_ROLE_DELETE_SUCCESS = "删除了角色【{{#role.name}}】";

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ public CommonResult<Boolean> updateRole(@Valid @RequestBody RoleSaveReqVO update
return success(true);
}

@PutMapping("/update-status")
@Operation(summary = "修改角色状态")
@PreAuthorize("@ss.hasPermission('system:role:update')")
public CommonResult<Boolean> updateRoleStatus(@Valid @RequestBody RoleUpdateStatusReqVO reqVO) {
roleService.updateRoleStatus(reqVO.getId(), reqVO.getStatus());
return success(true);
}

@DeleteMapping("/delete")
@Operation(summary = "删除角色")
@Parameter(name = "id", description = "角色编号", required = true, example = "1024")
Expand Down Expand Up @@ -87,10 +79,10 @@ public CommonResult<PageResult<RoleRespVO>> getRolePage(RolePageReqVO pageReqVO)

@GetMapping({"/list-all-simple", "/simple-list"})
@Operation(summary = "获取角色精简信息列表", description = "只包含被开启的角色,主要用于前端的下拉选项")
public CommonResult<List<RoleSimpleRespVO>> getSimpleRoleList() {
public CommonResult<List<RoleRespVO>> getSimpleRoleList() {
List<RoleDO> list = roleService.getRoleListByStatus(singleton(CommonStatusEnum.ENABLE.getStatus()));
list.sort(Comparator.comparing(RoleDO::getSort));
return success(BeanUtils.toBean(list, RoleSimpleRespVO.class));
return success(BeanUtils.toBean(list, RoleRespVO.class));
}

@GetMapping("/export-excel")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role;

import com.mzt.logapi.starter.annotation.DiffLogField;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Schema(description = "管理后台 - 角色创建 Request VO")
@Schema(description = "管理后台 - 角色创建/更新 Request VO")
@Data
public class RoleSaveReqVO {

Expand All @@ -16,19 +17,23 @@ public class RoleSaveReqVO {

@Schema(description = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "管理员")
@NotBlank(message = "角色名称不能为空")
@Size(max = 30, message = "角色名称长度不能超过30个字符")
@Size(max = 30, message = "角色名称长度不能超过 30 个字符")
@DiffLogField(name = "角色名称")
private String name;

@NotBlank(message = "角色标志不能为空")
@Size(max = 100, message = "角色标志长度不能超过100个字符")
@Size(max = 100, message = "角色标志长度不能超过 100 个字符")
@Schema(description = "角色编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "ADMIN")
@DiffLogField(name = "角色标志")
private String code;

@Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "显示顺序不能为空")
@DiffLogField(name = "显示顺序")
private Integer sort;

@Schema(description = "备注", example = "我是一个角色")
@DiffLogField(name = "备注")
private String remark;

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.validation.Mobile;
import cn.iocoder.yudao.module.system.framework.operatelog.core.DeptParseFunction;
import cn.iocoder.yudao.module.system.framework.operatelog.core.PostParseFunction;
import cn.iocoder.yudao.module.system.framework.operatelog.core.SexParseFunction;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mzt.logapi.starter.annotation.DiffLogField;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
Expand All @@ -21,34 +25,43 @@ public class UserSaveReqVO {
@NotBlank(message = "用户账号不能为空")
@Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户账号由 数字、字母 组成")
@Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符")
@DiffLogField(name = "用户账号")
private String username;

@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@Size(max = 30, message = "用户昵称长度不能超过30个字符")
@DiffLogField(name = "用户昵称")
private String nickname;

@Schema(description = "备注", example = "我是一个用户")
@DiffLogField(name = "备注")
private String remark;

@Schema(description = "部门ID", example = "我是一个用户")
@Schema(description = "部门编号", example = "我是一个用户")
@DiffLogField(name = "部门", function = DeptParseFunction.NAME)
private Long deptId;

@Schema(description = "岗位编号数组", example = "1")
@DiffLogField(name = "岗位", function = PostParseFunction.NAME)
private Set<Long> postIds;

@Schema(description = "用户邮箱", example = "[email protected]")
@Email(message = "邮箱格式不正确")
@Size(max = 50, message = "邮箱长度不能超过 50 个字符")
@DiffLogField(name = "用户邮箱")
private String email;

@Schema(description = "手机号码", example = "15601691300")
@Mobile
@DiffLogField(name = "手机号码")
private String mobile;

@Schema(description = "用户性别,参见 SexEnum 枚举类", example = "1")
@DiffLogField(name = "用户性别", function = SexParseFunction.NAME)
private Integer sex;

@Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
@DiffLogField(name = "用户头像")
private String avatar;

// ========== 仅【创建】时,需要传递的字段 ==========
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cn.iocoder.yudao.module.system.framework.operatelog.core;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.mzt.logapi.service.IParseFunction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
Expand All @@ -21,7 +22,7 @@ public class AdminUserParseFunction implements IParseFunction {
public static final String NAME = "getAdminUserById";

@Resource
private AdminUserApi adminUserApi;
private AdminUserService adminUserService;

@Override
public String functionName() {
Expand All @@ -35,7 +36,7 @@ public String apply(Object value) {
}

// 获取用户信息
AdminUserRespDTO user = adminUserApi.getUser(Long.parseLong(value.toString()));
AdminUserDO user = adminUserService.getUser(Convert.toLong(value));
if (user == null) {
log.warn("[apply][获取用户{{}}为空", value);
return "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.system.framework.operatelog.core;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import com.mzt.logapi.service.IParseFunction;
Expand Down Expand Up @@ -32,7 +33,7 @@ public String apply(Object value) {
if (StrUtil.isEmptyIfStr(value)) {
return "";
}
return AreaUtils.format(Integer.parseInt(value.toString()));
return AreaUtils.format(Convert.toInt(value));
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package cn.iocoder.yudao.module.system.framework.operatelog.core;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.service.dept.DeptService;
import com.mzt.logapi.service.IParseFunction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
* 管理员名字的 {@link IParseFunction} 实现类
* 部门名字的 {@link IParseFunction} 实现类
*
* @author HUIHUI
*/
Expand All @@ -21,7 +22,7 @@ public class DeptParseFunction implements IParseFunction {
public static final String NAME = "getDeptById";

@Resource
private DeptApi deptApi;
private DeptService deptService;

@Override
public String functionName() {
Expand All @@ -35,7 +36,7 @@ public String apply(Object value) {
}

// 获取部门信息
DeptRespDTO dept = deptApi.getDept(Long.parseLong(value.toString()));
DeptDO dept = deptService.getDept(Convert.toLong(value));
if (dept == null) {
log.warn("[apply][获取部门{{}}为空", value);
return "";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.system.framework.operatelog.core;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
import cn.iocoder.yudao.module.system.service.dept.PostService;
import com.mzt.logapi.service.IParseFunction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
* 岗位名字的 {@link IParseFunction} 实现类
*
* @author HUIHUI
*/
@Slf4j
@Component
public class PostParseFunction implements IParseFunction {

public static final String NAME = "getPostById";

@Resource
private PostService postService;

@Override
public String functionName() {
return NAME;
}

@Override
public String apply(Object value) {
if (StrUtil.isEmptyIfStr(value)) {
return "";
}

// 获取岗位信息
PostDO post = postService.getPost(Convert.toLong(value));
if (post == null) {
log.warn("[apply][获取岗位{{}}为空", value);
return "";
}
return post.getName();
}

}
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/**
* 占位文件,避免文件夹缩进
*/
package cn.iocoder.yudao.module.system.framework.operatelog;
Loading

0 comments on commit 0d8cac4

Please sign in to comment.