review code.
This commit is contained in:
@@ -47,6 +47,8 @@ public enum ErrorCode implements CodeInfo {
|
|||||||
|
|
||||||
ROLE_PRESENT(703, "角色 [{}] 不存在"),
|
ROLE_PRESENT(703, "角色 [{}] 不存在"),
|
||||||
|
|
||||||
|
DATA_ALTER(704, "数据发生改变, 请刷新后重试"),
|
||||||
|
|
||||||
// -------------------- 自定义 - 通用 --------------------
|
// -------------------- 自定义 - 通用 --------------------
|
||||||
|
|
||||||
NETWORK_FLUCTUATION(900, "当前环境网路波动"),
|
NETWORK_FLUCTUATION(900, "当前环境网路波动"),
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public interface ErrorMessage {
|
|||||||
|
|
||||||
String INVALID_PARAM = "参数验证失败";
|
String INVALID_PARAM = "参数验证失败";
|
||||||
|
|
||||||
|
String DATA_ABSENT = "数据不存在";
|
||||||
|
|
||||||
String DATA_PRESENT = "数据已存在";
|
String DATA_PRESENT = "数据已存在";
|
||||||
|
|
||||||
String NAME_PRESENT = "名称已存在";
|
String NAME_PRESENT = "名称已存在";
|
||||||
@@ -33,16 +35,10 @@ public interface ErrorMessage {
|
|||||||
|
|
||||||
String PARENT_MENU_ABSENT = "父菜单不存在";
|
String PARENT_MENU_ABSENT = "父菜单不存在";
|
||||||
|
|
||||||
String DATA_ABSENT = "数据不存在";
|
|
||||||
|
|
||||||
String USERNAME_PASSWORD_ERROR = "用户名或密码错误";
|
String USERNAME_PASSWORD_ERROR = "用户名或密码错误";
|
||||||
|
|
||||||
String MAX_LOGIN_FAILED = "登陆失败次数已上限";
|
String MAX_LOGIN_FAILED = "登陆失败次数已上限";
|
||||||
|
|
||||||
String USER_ABSENT = "用户不存在";
|
String USER_ABSENT = "用户不存在";
|
||||||
|
|
||||||
String USER_DISABLED = "用户已被禁用";
|
|
||||||
|
|
||||||
String USER_LOCKED = "用户已被锁定";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.orion.ops.framework.mybatis.core.query;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
|
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||||
|
import com.orion.ops.framework.common.utils.Valid;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@@ -38,16 +40,31 @@ public class Conditions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* id list
|
* eq
|
||||||
*
|
*
|
||||||
* @param idMapping idMapping
|
* @param mapping mapping
|
||||||
* @param ids ids
|
* @param e e
|
||||||
* @param <T> T
|
* @param <T> T
|
||||||
* @param <ID> ID
|
* @param <E> E
|
||||||
* @return wrapper
|
* @return wrapper
|
||||||
*/
|
*/
|
||||||
public static <T, ID> LambdaQueryWrapper<T> id(SFunction<T, ID> idMapping, Collection<ID> ids) {
|
public static <T, E> LambdaQueryWrapper<T> eq(SFunction<T, E> mapping, E e) {
|
||||||
return new ValidateLambdaWrapper<T>().in(idMapping, ids);
|
Valid.notNull(e, ErrorMessage.INVALID_PARAM);
|
||||||
|
return new LambdaQueryWrapper<T>().eq(mapping, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* in
|
||||||
|
*
|
||||||
|
* @param mapping mapping
|
||||||
|
* @param es es
|
||||||
|
* @param <T> T
|
||||||
|
* @param <E> E
|
||||||
|
* @return wrapper
|
||||||
|
*/
|
||||||
|
public static <T, E> LambdaQueryWrapper<T> in(SFunction<T, E> mapping, Collection<E> es) {
|
||||||
|
Valid.notEmpty(es, ErrorMessage.INVALID_PARAM);
|
||||||
|
return new LambdaQueryWrapper<T>().in(mapping, es);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||||||
import com.orion.lang.define.wrapper.DataGrid;
|
import com.orion.lang.define.wrapper.DataGrid;
|
||||||
import com.orion.lang.define.wrapper.IPageRequest;
|
import com.orion.lang.define.wrapper.IPageRequest;
|
||||||
import com.orion.lang.define.wrapper.Pager;
|
import com.orion.lang.define.wrapper.Pager;
|
||||||
|
import com.orion.lang.utils.Objects1;
|
||||||
import com.orion.lang.utils.Valid;
|
import com.orion.lang.utils.Valid;
|
||||||
import com.orion.lang.utils.collect.Lists;
|
import com.orion.lang.utils.collect.Lists;
|
||||||
import com.orion.ops.framework.common.constant.Const;
|
import com.orion.ops.framework.common.constant.Const;
|
||||||
@@ -60,7 +61,7 @@ public class DataQuery<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DataQuery<T> only() {
|
public DataQuery<T> only() {
|
||||||
this.wrapper.last(Const.LIMIT_1);
|
wrapper.last(Const.LIMIT_1);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,29 +69,28 @@ public class DataQuery<T> {
|
|||||||
return dao.selectOne(wrapper);
|
return dao.selectOne(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<T> optional() {
|
public <R> R get(Function<T, R> mapper) {
|
||||||
return Optional.ofNullable(dao.selectOne(wrapper));
|
Valid.notNull(mapper, "convert function is null");
|
||||||
|
return Objects1.map(dao.selectOne(wrapper), mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <R> Optional<R> optional(Function<T, R> mapper) {
|
public Optional<T> optional() {
|
||||||
Valid.notNull(mapper, "convert function is null");
|
return Optional.ofNullable(dao.selectOne(wrapper));
|
||||||
return Optional.ofNullable(dao.selectOne(wrapper))
|
|
||||||
.map(mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> list() {
|
public List<T> list() {
|
||||||
return dao.selectList(wrapper);
|
return dao.selectList(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<T> stream() {
|
public <R> List<R> list(Function<T, R> mapper) {
|
||||||
return dao.selectList(wrapper).stream();
|
|
||||||
}
|
|
||||||
|
|
||||||
public <R> List<R> stream(Function<T, R> mapper) {
|
|
||||||
Valid.notNull(mapper, "convert function is null");
|
Valid.notNull(mapper, "convert function is null");
|
||||||
return Lists.map(dao.selectList(wrapper), mapper);
|
return Lists.map(dao.selectList(wrapper), mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stream<T> stream() {
|
||||||
|
return dao.selectList(wrapper).stream();
|
||||||
|
}
|
||||||
|
|
||||||
public Long count() {
|
public Long count() {
|
||||||
return dao.selectCount(wrapper);
|
return dao.selectCount(wrapper);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,4 +56,6 @@ DELETE {{baseUrl}}/${package.ModuleName}/${typeHyphen}/delete-batch?idList=1,2,3
|
|||||||
Authorization: {{token}}
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
|
||||||
|
${httpComment}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ${package.Controller};
|
package ${package.Controller};
|
||||||
|
|
||||||
import com.orion.lang.define.wrapper.DataGrid;
|
import com.orion.lang.define.wrapper.DataGrid;
|
||||||
|
import com.orion.ops.framework.common.annotation.IgnoreLog;
|
||||||
import com.orion.ops.framework.common.annotation.RestWrapper;
|
import com.orion.ops.framework.common.annotation.RestWrapper;
|
||||||
import ${package.Service}.*;
|
import ${package.Service}.*;
|
||||||
#foreach($pkg in ${customFilePackages})
|
#foreach($pkg in ${customFilePackages})
|
||||||
@@ -57,6 +58,7 @@ public class ${table.controllerName} {
|
|||||||
return ${typeLower}Service.update${type}(request);
|
return ${typeLower}Service.update${type}(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IgnoreLog
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "${apiComment.get}")
|
@Operation(summary = "${apiComment.get}")
|
||||||
@Parameter(name = "id", description = "id", required = true)
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
@@ -65,6 +67,7 @@ public class ${table.controllerName} {
|
|||||||
return ${typeLower}Service.get${type}(id);
|
return ${typeLower}Service.get${type}(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IgnoreLog
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@Operation(summary = "${apiComment.list}")
|
@Operation(summary = "${apiComment.list}")
|
||||||
@Parameter(name = "idList", description = "idList", required = true)
|
@Parameter(name = "idList", description = "idList", required = true)
|
||||||
@@ -73,6 +76,7 @@ public class ${table.controllerName} {
|
|||||||
return ${typeLower}Service.get${type}List(idList);
|
return ${typeLower}Service.get${type}List(idList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IgnoreLog
|
||||||
@PostMapping("/query")
|
@PostMapping("/query")
|
||||||
@Operation(summary = "${apiComment.query}")
|
@Operation(summary = "${apiComment.query}")
|
||||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
|
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
|
||||||
@@ -80,7 +84,7 @@ public class ${table.controllerName} {
|
|||||||
return ${typeLower}Service.get${type}Page(request);
|
return ${typeLower}Service.get${type}Page(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
@Operation(summary = "${apiComment.delete}")
|
@Operation(summary = "${apiComment.delete}")
|
||||||
@Parameter(name = "id", description = "id", required = true)
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
|
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
|
||||||
@@ -88,7 +92,7 @@ public class ${table.controllerName} {
|
|||||||
return ${typeLower}Service.delete${type}(id);
|
return ${typeLower}Service.delete${type}(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/delete-batch")
|
@DeleteMapping("/delete-batch")
|
||||||
@Operation(summary = "${apiComment.batchDelete}")
|
@Operation(summary = "${apiComment.batchDelete}")
|
||||||
@Parameter(name = "idList", description = "idList", required = true)
|
@Parameter(name = "idList", description = "idList", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
|
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ public class GlobalExceptionHandler {
|
|||||||
IllegalArgumentException.class
|
IllegalArgumentException.class
|
||||||
})
|
})
|
||||||
public HttpWrapper<?> invalidArgumentExceptionHandler(Exception ex) {
|
public HttpWrapper<?> invalidArgumentExceptionHandler(Exception ex) {
|
||||||
log.error("invalidArgumentExceptionHandler {}", ex.getMessage());
|
log.error("invalidArgumentExceptionHandler {}", ex.getMessage(), ex);
|
||||||
return ErrorCode.BAD_REQUEST.wrapper().msg(ex.getMessage());
|
return ErrorCode.BAD_REQUEST.wrapper().msg(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ package com.orion.ops.module.infra.controller;
|
|||||||
|
|
||||||
import com.orion.ops.framework.common.annotation.IgnoreLog;
|
import com.orion.ops.framework.common.annotation.IgnoreLog;
|
||||||
import com.orion.ops.framework.common.annotation.RestWrapper;
|
import com.orion.ops.framework.common.annotation.RestWrapper;
|
||||||
import com.orion.ops.module.infra.entity.request.menu.SystemMenuCreateRequest;
|
import com.orion.ops.module.infra.entity.request.menu.*;
|
||||||
import com.orion.ops.module.infra.entity.request.menu.SystemMenuQueryRequest;
|
|
||||||
import com.orion.ops.module.infra.entity.request.menu.SystemMenuUpdateRequest;
|
|
||||||
import com.orion.ops.module.infra.entity.request.menu.SystemMenuUpdateStatusRequest;
|
|
||||||
import com.orion.ops.module.infra.entity.vo.SystemMenuVO;
|
import com.orion.ops.module.infra.entity.vo.SystemMenuVO;
|
||||||
import com.orion.ops.module.infra.service.SystemMenuService;
|
import com.orion.ops.module.infra.service.SystemMenuService;
|
||||||
|
import com.orion.ops.module.infra.service.SystemRoleMenuService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@@ -38,6 +36,9 @@ public class SystemMenuController {
|
|||||||
@Resource
|
@Resource
|
||||||
private SystemMenuService systemMenuService;
|
private SystemMenuService systemMenuService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SystemRoleMenuService systemRoleMenuService;
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建菜单")
|
@Operation(summary = "创建菜单")
|
||||||
@PreAuthorize("@ss.hasPermission('infra:system-menu:create')")
|
@PreAuthorize("@ss.hasPermission('infra:system-menu:create')")
|
||||||
@@ -59,6 +60,14 @@ public class SystemMenuController {
|
|||||||
return systemMenuService.updateSystemMenuStatus(request);
|
return systemMenuService.updateSystemMenuStatus(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/bind")
|
||||||
|
@Operation(summary = "绑定角色菜单")
|
||||||
|
@PreAuthorize("@ss.hasPermission('infra:system-menu:bind')")
|
||||||
|
public Integer bindRoleMenu(@RequestBody SystemMenuBindRequest request) {
|
||||||
|
return systemRoleMenuService.bindRoleMenu(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@IgnoreLog
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "通过 id 查询菜单")
|
@Operation(summary = "通过 id 查询菜单")
|
||||||
@Parameter(name = "id", description = "id", required = true)
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
@@ -75,7 +84,7 @@ public class SystemMenuController {
|
|||||||
return systemMenuService.getSystemMenuList(request);
|
return systemMenuService.getSystemMenuList(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
@Operation(summary = "通过 id 级联删除菜单")
|
@Operation(summary = "通过 id 级联删除菜单")
|
||||||
@Parameter(name = "id", description = "id", required = true)
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('infra:system-menu:delete')")
|
@PreAuthorize("@ss.hasPermission('infra:system-menu:delete')")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.orion.ops.module.infra.controller;
|
package com.orion.ops.module.infra.controller;
|
||||||
|
|
||||||
import com.orion.lang.define.wrapper.DataGrid;
|
import com.orion.lang.define.wrapper.DataGrid;
|
||||||
|
import com.orion.ops.framework.common.annotation.IgnoreLog;
|
||||||
import com.orion.ops.framework.common.annotation.RestWrapper;
|
import com.orion.ops.framework.common.annotation.RestWrapper;
|
||||||
import com.orion.ops.module.infra.entity.request.role.SystemRoleCreateRequest;
|
import com.orion.ops.module.infra.entity.request.role.SystemRoleCreateRequest;
|
||||||
import com.orion.ops.module.infra.entity.request.role.SystemRoleQueryRequest;
|
import com.orion.ops.module.infra.entity.request.role.SystemRoleQueryRequest;
|
||||||
@@ -59,6 +60,7 @@ public class SystemRoleController {
|
|||||||
return systemRoleService.updateRoleStatus(request);
|
return systemRoleService.updateRoleStatus(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IgnoreLog
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "通过 id 查询角色")
|
@Operation(summary = "通过 id 查询角色")
|
||||||
@Parameter(name = "id", description = "id", required = true)
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
@@ -67,6 +69,7 @@ public class SystemRoleController {
|
|||||||
return systemRoleService.getSystemRole(id);
|
return systemRoleService.getSystemRole(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IgnoreLog
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@Operation(summary = "查询所有角色")
|
@Operation(summary = "查询所有角色")
|
||||||
@PreAuthorize("@ss.hasPermission('infra:system-role:query')")
|
@PreAuthorize("@ss.hasPermission('infra:system-role:query')")
|
||||||
@@ -74,6 +77,7 @@ public class SystemRoleController {
|
|||||||
return systemRoleService.getSystemRoleList();
|
return systemRoleService.getSystemRoleList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IgnoreLog
|
||||||
@PostMapping("/query")
|
@PostMapping("/query")
|
||||||
@Operation(summary = "分页查询角色")
|
@Operation(summary = "分页查询角色")
|
||||||
@PreAuthorize("@ss.hasPermission('infra:system-role:query')")
|
@PreAuthorize("@ss.hasPermission('infra:system-role:query')")
|
||||||
@@ -81,7 +85,7 @@ public class SystemRoleController {
|
|||||||
return systemRoleService.getSystemRolePage(request);
|
return systemRoleService.getSystemRolePage(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
@Operation(summary = "通过 id 删除角色")
|
@Operation(summary = "通过 id 删除角色")
|
||||||
@Parameter(name = "id", description = "id", required = true)
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('infra:system-role:delete')")
|
@PreAuthorize("@ss.hasPermission('infra:system-role:delete')")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.orion.ops.module.infra.controller;
|
|||||||
import com.orion.lang.define.wrapper.DataGrid;
|
import com.orion.lang.define.wrapper.DataGrid;
|
||||||
import com.orion.lang.define.wrapper.HttpWrapper;
|
import com.orion.lang.define.wrapper.HttpWrapper;
|
||||||
import com.orion.lang.utils.collect.Lists;
|
import com.orion.lang.utils.collect.Lists;
|
||||||
|
import com.orion.ops.framework.common.annotation.IgnoreLog;
|
||||||
import com.orion.ops.framework.common.annotation.RestWrapper;
|
import com.orion.ops.framework.common.annotation.RestWrapper;
|
||||||
import com.orion.ops.module.infra.entity.request.user.*;
|
import com.orion.ops.module.infra.entity.request.user.*;
|
||||||
import com.orion.ops.module.infra.entity.vo.SystemUserVO;
|
import com.orion.ops.module.infra.entity.vo.SystemUserVO;
|
||||||
@@ -85,6 +86,7 @@ public class SystemUserController {
|
|||||||
return HttpWrapper.ok();
|
return HttpWrapper.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IgnoreLog
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "通过 id 查询用户")
|
@Operation(summary = "通过 id 查询用户")
|
||||||
@Parameter(name = "id", description = "id", required = true)
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
@@ -93,6 +95,7 @@ public class SystemUserController {
|
|||||||
return systemUserService.getSystemUser(id);
|
return systemUserService.getSystemUser(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IgnoreLog
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@Operation(summary = "查询所有用户")
|
@Operation(summary = "查询所有用户")
|
||||||
@PreAuthorize("@ss.hasPermission('infra:system-user:query')")
|
@PreAuthorize("@ss.hasPermission('infra:system-user:query')")
|
||||||
@@ -100,6 +103,7 @@ public class SystemUserController {
|
|||||||
return systemUserService.getSystemUserList();
|
return systemUserService.getSystemUserList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IgnoreLog
|
||||||
@PostMapping("/query")
|
@PostMapping("/query")
|
||||||
@Operation(summary = "分页查询用户")
|
@Operation(summary = "分页查询用户")
|
||||||
@PreAuthorize("@ss.hasPermission('infra:system-user:query')")
|
@PreAuthorize("@ss.hasPermission('infra:system-user:query')")
|
||||||
@@ -107,7 +111,7 @@ public class SystemUserController {
|
|||||||
return systemUserService.getSystemUserPage(request);
|
return systemUserService.getSystemUserPage(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
@Operation(summary = "通过 id 删除用户")
|
@Operation(summary = "通过 id 删除用户")
|
||||||
@Parameter(name = "id", description = "id", required = true)
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('infra:system-user:delete')")
|
@PreAuthorize("@ss.hasPermission('infra:system-user:delete')")
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
|||||||
import com.orion.ops.module.infra.entity.domain.SystemRoleMenuDO;
|
import com.orion.ops.module.infra.entity.domain.SystemRoleMenuDO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色菜单关联 Mapper 接口
|
* 角色菜单关联 Mapper 接口
|
||||||
*
|
*
|
||||||
@@ -34,10 +36,22 @@ public interface SystemRoleMenuDAO extends IMapper<SystemRoleMenuDO> {
|
|||||||
* @param roleId roleId
|
* @param roleId roleId
|
||||||
* @return effect
|
* @return effect
|
||||||
*/
|
*/
|
||||||
default Integer deleteByRoleId(Long roleId) {
|
default int deleteByRoleId(Long roleId) {
|
||||||
LambdaQueryWrapper<SystemRoleMenuDO> wrapper = this.wrapper()
|
LambdaQueryWrapper<SystemRoleMenuDO> wrapper = this.wrapper()
|
||||||
.eq(SystemRoleMenuDO::getRoleId, roleId);
|
.eq(SystemRoleMenuDO::getRoleId, roleId);
|
||||||
return this.delete(wrapper);
|
return this.delete(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 menuId 删除
|
||||||
|
*
|
||||||
|
* @param menuIdList menuIdList
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
default int deleteByMenuId(List<Long> menuIdList) {
|
||||||
|
LambdaQueryWrapper<SystemRoleMenuDO> wrapper = this.wrapper()
|
||||||
|
.in(SystemRoleMenuDO::getMenuId, menuIdList);
|
||||||
|
return this.delete(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public interface SystemUserRoleDAO extends IMapper<SystemUserRoleDO> {
|
|||||||
* @param userId userId
|
* @param userId userId
|
||||||
* @return effect
|
* @return effect
|
||||||
*/
|
*/
|
||||||
default Integer deleteByUserId(Long userId) {
|
default int deleteByUserId(Long userId) {
|
||||||
LambdaQueryWrapper<SystemUserRoleDO> wrapper = this.wrapper()
|
LambdaQueryWrapper<SystemUserRoleDO> wrapper = this.wrapper()
|
||||||
.eq(SystemUserRoleDO::getUserId, userId);
|
.eq(SystemUserRoleDO::getUserId, userId);
|
||||||
return this.delete(wrapper);
|
return this.delete(wrapper);
|
||||||
@@ -79,7 +79,7 @@ public interface SystemUserRoleDAO extends IMapper<SystemUserRoleDO> {
|
|||||||
* @param roleId roleId
|
* @param roleId roleId
|
||||||
* @return effect
|
* @return effect
|
||||||
*/
|
*/
|
||||||
default Integer deleteByRoleId(Long roleId) {
|
default int deleteByRoleId(Long roleId) {
|
||||||
LambdaQueryWrapper<SystemUserRoleDO> wrapper = this.wrapper()
|
LambdaQueryWrapper<SystemUserRoleDO> wrapper = this.wrapper()
|
||||||
.eq(SystemUserRoleDO::getRoleId, roleId);
|
.eq(SystemUserRoleDO::getRoleId, roleId);
|
||||||
return this.delete(wrapper);
|
return this.delete(wrapper);
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.orion.ops.module.infra.entity.request.menu;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单 绑定角色请求对象
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-7-18 10:18
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(name = "SystemMenuBindRequest", description = "菜单 绑定角色请求对象")
|
||||||
|
public class SystemMenuBindRequest implements Serializable {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(description = "roleId")
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
@NotEmpty
|
||||||
|
@Schema(description = "菜单id集合")
|
||||||
|
private List<Long> idList;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.orion.ops.module.infra.service;
|
package com.orion.ops.module.infra.service;
|
||||||
|
|
||||||
|
import com.orion.ops.module.infra.entity.request.menu.SystemMenuBindRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色菜单关联 服务类
|
* 角色菜单关联 服务类
|
||||||
*
|
*
|
||||||
@@ -9,4 +11,12 @@ package com.orion.ops.module.infra.service;
|
|||||||
*/
|
*/
|
||||||
public interface SystemRoleMenuService {
|
public interface SystemRoleMenuService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定角色菜单
|
||||||
|
*
|
||||||
|
* @param request request
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
Integer bindRoleMenu(SystemMenuBindRequest request);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import com.orion.lang.utils.Exceptions;
|
|||||||
import com.orion.lang.utils.collect.Lists;
|
import com.orion.lang.utils.collect.Lists;
|
||||||
import com.orion.lang.utils.crypto.Signatures;
|
import com.orion.lang.utils.crypto.Signatures;
|
||||||
import com.orion.ops.framework.common.constant.Const;
|
import com.orion.ops.framework.common.constant.Const;
|
||||||
|
import com.orion.ops.framework.common.constant.ErrorCode;
|
||||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||||
import com.orion.ops.framework.common.crypto.ValueCrypto;
|
|
||||||
import com.orion.ops.framework.common.security.LoginUser;
|
import com.orion.ops.framework.common.security.LoginUser;
|
||||||
import com.orion.ops.framework.common.utils.CryptoUtils;
|
import com.orion.ops.framework.common.utils.CryptoUtils;
|
||||||
import com.orion.ops.framework.common.utils.IpUtils;
|
import com.orion.ops.framework.common.utils.IpUtils;
|
||||||
@@ -51,9 +51,6 @@ import java.util.stream.Collectors;
|
|||||||
@Service
|
@Service
|
||||||
public class AuthenticationServiceImpl implements AuthenticationService {
|
public class AuthenticationServiceImpl implements AuthenticationService {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ValueCrypto valueCrypto;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SystemUserDAO systemUserDAO;
|
private SystemUserDAO systemUserDAO;
|
||||||
|
|
||||||
@@ -250,10 +247,10 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
|||||||
private void checkUserStatus(Integer status) {
|
private void checkUserStatus(Integer status) {
|
||||||
if (UserStatusEnum.DISABLED.getStatus().equals(status)) {
|
if (UserStatusEnum.DISABLED.getStatus().equals(status)) {
|
||||||
// 禁用状态
|
// 禁用状态
|
||||||
throw Exceptions.argument(ErrorMessage.USER_DISABLED);
|
throw ErrorCode.USER_DISABLED.exception();
|
||||||
} else if (UserStatusEnum.LOCKED.getStatus().equals(status)) {
|
} else if (UserStatusEnum.LOCKED.getStatus().equals(status)) {
|
||||||
// 锁定状态
|
// 锁定状态
|
||||||
throw Exceptions.argument(ErrorMessage.USER_LOCKED);
|
throw ErrorCode.USER_LOCKED.exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.orion.ops.module.infra.service.impl;
|
package com.orion.ops.module.infra.service.impl;
|
||||||
|
|
||||||
import com.orion.lang.utils.collect.Lists;
|
import com.orion.lang.utils.collect.Lists;
|
||||||
|
import com.orion.ops.framework.common.security.LoginUser;
|
||||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||||
import com.orion.ops.module.infra.convert.SystemMenuConvert;
|
import com.orion.ops.module.infra.convert.SystemMenuConvert;
|
||||||
import com.orion.ops.module.infra.convert.SystemUserConvert;
|
import com.orion.ops.module.infra.convert.SystemUserConvert;
|
||||||
@@ -16,6 +17,7 @@ import com.orion.ops.module.infra.entity.vo.SystemMenuVO;
|
|||||||
import com.orion.ops.module.infra.entity.vo.UserBaseInfoVO;
|
import com.orion.ops.module.infra.entity.vo.UserBaseInfoVO;
|
||||||
import com.orion.ops.module.infra.entity.vo.UserPermissionVO;
|
import com.orion.ops.module.infra.entity.vo.UserPermissionVO;
|
||||||
import com.orion.ops.module.infra.enums.MenuStatusEnum;
|
import com.orion.ops.module.infra.enums.MenuStatusEnum;
|
||||||
|
import com.orion.ops.module.infra.enums.MenuTypeEnum;
|
||||||
import com.orion.ops.module.infra.enums.RoleStatusEnum;
|
import com.orion.ops.module.infra.enums.RoleStatusEnum;
|
||||||
import com.orion.ops.module.infra.service.PermissionService;
|
import com.orion.ops.module.infra.service.PermissionService;
|
||||||
import com.orion.ops.module.infra.service.SystemMenuService;
|
import com.orion.ops.module.infra.service.SystemMenuService;
|
||||||
@@ -156,6 +158,8 @@ public class PermissionServiceImpl implements PermissionService {
|
|||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
.distinct()
|
.distinct()
|
||||||
|
.filter(s -> MenuStatusEnum.ENABLED.getStatus().equals(s.getStatus()))
|
||||||
|
.filter(s -> !MenuTypeEnum.FUNCTION.getType().equals(s.getType()))
|
||||||
.map(SystemMenuConvert.MAPPER::to)
|
.map(SystemMenuConvert.MAPPER::to)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
// 构建菜单树
|
// 构建菜单树
|
||||||
@@ -177,18 +181,18 @@ public class PermissionServiceImpl implements PermissionService {
|
|||||||
.map(roleMenuCache::get)
|
.map(roleMenuCache::get)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
|
.filter(s -> MenuStatusEnum.ENABLED.getStatus().equals(s.getStatus()))
|
||||||
.map(SystemMenuCacheDTO::getPermission)
|
.map(SystemMenuCacheDTO::getPermission)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.distinct()
|
.distinct()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
// 组装数据
|
// 组装数据
|
||||||
UserPermissionVO vo = new UserPermissionVO().builder()
|
return UserPermissionVO.builder()
|
||||||
.user(user)
|
.user(user)
|
||||||
.roles(roles)
|
.roles(roles)
|
||||||
.permissions(permissions)
|
.permissions(permissions)
|
||||||
.build();
|
.build();
|
||||||
return vo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,7 +202,9 @@ public class PermissionServiceImpl implements PermissionService {
|
|||||||
*/
|
*/
|
||||||
private List<String> getUserEnabledRoles() {
|
private List<String> getUserEnabledRoles() {
|
||||||
// 获取当前用户角色
|
// 获取当前用户角色
|
||||||
List<String> roles = SecurityUtils.getLoginUser().getRoles();
|
List<String> roles = Optional.ofNullable(SecurityUtils.getLoginUser())
|
||||||
|
.map(LoginUser::getRoles)
|
||||||
|
.orElse(Lists.empty());
|
||||||
if (Lists.isEmpty(roles)) {
|
if (Lists.isEmpty(roles)) {
|
||||||
return Lists.empty();
|
return Lists.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.orion.ops.framework.common.utils.Valid;
|
|||||||
import com.orion.ops.framework.mybatis.core.query.Conditions;
|
import com.orion.ops.framework.mybatis.core.query.Conditions;
|
||||||
import com.orion.ops.module.infra.convert.SystemMenuConvert;
|
import com.orion.ops.module.infra.convert.SystemMenuConvert;
|
||||||
import com.orion.ops.module.infra.dao.SystemMenuDAO;
|
import com.orion.ops.module.infra.dao.SystemMenuDAO;
|
||||||
|
import com.orion.ops.module.infra.dao.SystemRoleMenuDAO;
|
||||||
import com.orion.ops.module.infra.entity.domain.SystemMenuDO;
|
import com.orion.ops.module.infra.entity.domain.SystemMenuDO;
|
||||||
import com.orion.ops.module.infra.entity.dto.SystemMenuCacheDTO;
|
import com.orion.ops.module.infra.entity.dto.SystemMenuCacheDTO;
|
||||||
import com.orion.ops.module.infra.entity.request.menu.SystemMenuCreateRequest;
|
import com.orion.ops.module.infra.entity.request.menu.SystemMenuCreateRequest;
|
||||||
@@ -23,6 +24,7 @@ import com.orion.ops.module.infra.service.SystemMenuService;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -43,6 +45,9 @@ public class SystemMenuServiceImpl implements SystemMenuService {
|
|||||||
@Resource
|
@Resource
|
||||||
private SystemMenuDAO systemMenuDAO;
|
private SystemMenuDAO systemMenuDAO;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SystemRoleMenuDAO systemRoleMenuDAO;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
|
|
||||||
@@ -180,19 +185,20 @@ public class SystemMenuServiceImpl implements SystemMenuService {
|
|||||||
List<SystemMenuCacheDTO> cache = permissionService.getMenuCache();
|
List<SystemMenuCacheDTO> cache = permissionService.getMenuCache();
|
||||||
// 获取要删除的id
|
// 获取要删除的id
|
||||||
List<Long> updateIdList = this.getChildrenIdList(id, cache, record.getType());
|
List<Long> updateIdList = this.getChildrenIdList(id, cache, record.getType());
|
||||||
|
// 修改状态
|
||||||
|
SystemMenuDO update = new SystemMenuDO();
|
||||||
|
update.setStatus(status);
|
||||||
|
int effect = systemMenuDAO.update(update, Conditions.in(SystemMenuDO::getId, updateIdList));
|
||||||
// 修改引用缓存状态
|
// 修改引用缓存状态
|
||||||
cache.stream()
|
cache.stream()
|
||||||
.filter(s -> updateIdList.contains(s.getId()))
|
.filter(s -> updateIdList.contains(s.getId()))
|
||||||
.forEach(s -> s.setStatus(status));
|
.forEach(s -> s.setStatus(status));
|
||||||
// 修改状态
|
|
||||||
SystemMenuDO update = new SystemMenuDO();
|
|
||||||
update.setStatus(status);
|
|
||||||
int effect = systemMenuDAO.update(update, Conditions.id(SystemMenuDO::getId, updateIdList));
|
|
||||||
log.info("SystemMenuService-updateSystemMenuStatus updateIdList: {}, effect: {}", JSON.toJSONString(updateIdList), effect);
|
log.info("SystemMenuService-updateSystemMenuStatus updateIdList: {}, effect: {}", JSON.toJSONString(updateIdList), effect);
|
||||||
return effect;
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Integer deleteSystemMenu(Long id) {
|
public Integer deleteSystemMenu(Long id) {
|
||||||
// 查询
|
// 查询
|
||||||
SystemMenuDO record = systemMenuDAO.selectById(id);
|
SystemMenuDO record = systemMenuDAO.selectById(id);
|
||||||
@@ -201,14 +207,16 @@ public class SystemMenuServiceImpl implements SystemMenuService {
|
|||||||
List<SystemMenuCacheDTO> cache = permissionService.getMenuCache();
|
List<SystemMenuCacheDTO> cache = permissionService.getMenuCache();
|
||||||
// 获取要删除的id
|
// 获取要删除的id
|
||||||
List<Long> deletedIdList = this.getChildrenIdList(id, cache, record.getType());
|
List<Long> deletedIdList = this.getChildrenIdList(id, cache, record.getType());
|
||||||
|
// 删除菜单
|
||||||
|
int effect = systemMenuDAO.deleteBatchIds(deletedIdList);
|
||||||
|
// 删除角色菜单关联
|
||||||
|
effect += systemRoleMenuDAO.deleteByMenuId(deletedIdList);
|
||||||
// 删除菜单缓存
|
// 删除菜单缓存
|
||||||
cache.removeIf(s -> deletedIdList.contains(s.getId()));
|
cache.removeIf(s -> deletedIdList.contains(s.getId()));
|
||||||
// 删除引用缓存
|
// 删除引用缓存
|
||||||
permissionService.getRoleMenuCache()
|
permissionService.getRoleMenuCache()
|
||||||
.values()
|
.values()
|
||||||
.forEach(roleMenus -> roleMenus.removeIf(s -> deletedIdList.contains(s.getId())));
|
.forEach(roleMenus -> roleMenus.removeIf(s -> deletedIdList.contains(s.getId())));
|
||||||
// 删除
|
|
||||||
int effect = systemMenuDAO.deleteBatchIds(deletedIdList);
|
|
||||||
log.info("SystemMenuService-deleteSystemMenu deletedIdList: {}, effect: {}", JSON.toJSONString(deletedIdList), effect);
|
log.info("SystemMenuService-deleteSystemMenu deletedIdList: {}, effect: {}", JSON.toJSONString(deletedIdList), effect);
|
||||||
return effect;
|
return effect;
|
||||||
}
|
}
|
||||||
@@ -222,7 +230,7 @@ public class SystemMenuServiceImpl implements SystemMenuService {
|
|||||||
* @return childrenId
|
* @return childrenId
|
||||||
*/
|
*/
|
||||||
private List<Long> getChildrenIdList(Long id, List<SystemMenuCacheDTO> cache, Integer type) {
|
private List<Long> getChildrenIdList(Long id, List<SystemMenuCacheDTO> cache, Integer type) {
|
||||||
// 需要移除的菜单id
|
// 需要更新的菜单id
|
||||||
List<Long> idList = new ArrayList<>();
|
List<Long> idList = new ArrayList<>();
|
||||||
idList.add(id);
|
idList.add(id);
|
||||||
// 级联查询
|
// 级联查询
|
||||||
@@ -252,7 +260,7 @@ public class SystemMenuServiceImpl implements SystemMenuService {
|
|||||||
* 验证创建菜单参数 不进行重复性校验
|
* 验证创建菜单参数 不进行重复性校验
|
||||||
*
|
*
|
||||||
* @param domain domain
|
* @param domain domain
|
||||||
* @param record record
|
* @param menuType menuType
|
||||||
*/
|
*/
|
||||||
private void validateRequest(SystemMenuDO domain, Integer menuType) {
|
private void validateRequest(SystemMenuDO domain, Integer menuType) {
|
||||||
// 父id不能为当前id
|
// 父id不能为当前id
|
||||||
|
|||||||
@@ -1,11 +1,31 @@
|
|||||||
package com.orion.ops.module.infra.service.impl;
|
package com.orion.ops.module.infra.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.orion.lang.utils.collect.Lists;
|
||||||
|
import com.orion.ops.framework.common.constant.ErrorCode;
|
||||||
|
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||||
|
import com.orion.ops.framework.common.utils.Valid;
|
||||||
|
import com.orion.ops.framework.mybatis.core.query.Conditions;
|
||||||
|
import com.orion.ops.module.infra.convert.SystemMenuConvert;
|
||||||
|
import com.orion.ops.module.infra.dao.SystemMenuDAO;
|
||||||
|
import com.orion.ops.module.infra.dao.SystemRoleDAO;
|
||||||
import com.orion.ops.module.infra.dao.SystemRoleMenuDAO;
|
import com.orion.ops.module.infra.dao.SystemRoleMenuDAO;
|
||||||
|
import com.orion.ops.module.infra.entity.domain.SystemMenuDO;
|
||||||
|
import com.orion.ops.module.infra.entity.domain.SystemRoleDO;
|
||||||
|
import com.orion.ops.module.infra.entity.domain.SystemRoleMenuDO;
|
||||||
|
import com.orion.ops.module.infra.entity.dto.SystemMenuCacheDTO;
|
||||||
|
import com.orion.ops.module.infra.entity.request.menu.SystemMenuBindRequest;
|
||||||
|
import com.orion.ops.module.infra.service.PermissionService;
|
||||||
import com.orion.ops.module.infra.service.SystemRoleMenuService;
|
import com.orion.ops.module.infra.service.SystemRoleMenuService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色菜单关联 服务实现类
|
* 角色菜单关联 服务实现类
|
||||||
@@ -18,7 +38,72 @@ import javax.annotation.Resource;
|
|||||||
@Service
|
@Service
|
||||||
public class SystemRoleMenuServiceImpl implements SystemRoleMenuService {
|
public class SystemRoleMenuServiceImpl implements SystemRoleMenuService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SystemRoleDAO systemRoleDAO;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SystemMenuDAO systemMenuDAO;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SystemRoleMenuDAO systemRoleMenuDAO;
|
private SystemRoleMenuDAO systemRoleMenuDAO;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PermissionService permissionService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Integer bindRoleMenu(SystemMenuBindRequest request) {
|
||||||
|
Long roleId = request.getRoleId();
|
||||||
|
List<Long> menuIdList = request.getIdList();
|
||||||
|
// 检查角色是否存在
|
||||||
|
SystemRoleDO role = Valid.notNull(systemRoleDAO.selectById(roleId), ErrorMessage.ROLE_ABSENT);
|
||||||
|
// 查询菜单列表
|
||||||
|
List<SystemMenuDO> menuList = systemMenuDAO.selectBatchIds(menuIdList);
|
||||||
|
if (menuIdList.size() != menuList.size()) {
|
||||||
|
throw ErrorCode.DATA_ALTER.exception();
|
||||||
|
}
|
||||||
|
// 查询角色菜单
|
||||||
|
List<Long> beforeMenuIdList = systemRoleMenuDAO.of()
|
||||||
|
.wrapper(Conditions.eq(SystemRoleMenuDO::getRoleId, roleId))
|
||||||
|
.list(SystemRoleMenuDO::getMenuId);
|
||||||
|
// 计算需要删除的
|
||||||
|
List<Long> deleteMenuIdList = beforeMenuIdList.stream()
|
||||||
|
.filter(s -> !menuIdList.contains(s))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
// 计算需要新增的
|
||||||
|
List<Long> insertMenuIdList = menuIdList.stream()
|
||||||
|
.filter(s -> !beforeMenuIdList.contains(s))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
int effect = 0;
|
||||||
|
// 删除
|
||||||
|
if (!deleteMenuIdList.isEmpty()) {
|
||||||
|
LambdaQueryWrapper<SystemRoleMenuDO> deleteWrapper = systemRoleMenuDAO.wrapper()
|
||||||
|
.eq(SystemRoleMenuDO::getRoleId, roleId)
|
||||||
|
.in(SystemRoleMenuDO::getMenuId, deleteMenuIdList);
|
||||||
|
effect += systemRoleMenuDAO.delete(deleteWrapper);
|
||||||
|
}
|
||||||
|
// 插入
|
||||||
|
if (!insertMenuIdList.isEmpty()) {
|
||||||
|
List<SystemRoleMenuDO> insertRecords = insertMenuIdList.stream()
|
||||||
|
.map(s -> {
|
||||||
|
SystemRoleMenuDO record = new SystemRoleMenuDO();
|
||||||
|
record.setRoleId(roleId);
|
||||||
|
record.setMenuId(s);
|
||||||
|
return record;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
systemRoleMenuDAO.insertBatch(insertRecords);
|
||||||
|
effect += insertMenuIdList.size();
|
||||||
|
}
|
||||||
|
// 更新缓存
|
||||||
|
Map<String, List<SystemMenuCacheDTO>> cache = permissionService.getRoleMenuCache();
|
||||||
|
List<SystemMenuCacheDTO> roleCache = cache.get(role.getCode());
|
||||||
|
if (Lists.isEmpty(roleCache)) {
|
||||||
|
roleCache = new ArrayList<>();
|
||||||
|
cache.put(role.getCode(), roleCache);
|
||||||
|
}
|
||||||
|
roleCache.clear();
|
||||||
|
roleCache.addAll(SystemMenuConvert.MAPPER.toCache(menuList));
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class SystemUserRoleServiceImpl implements SystemUserRoleService {
|
|||||||
public Integer deleteUserRoles(SystemUserUpdateRoleRequest request) {
|
public Integer deleteUserRoles(SystemUserUpdateRoleRequest request) {
|
||||||
Long userId = request.getId();
|
Long userId = request.getId();
|
||||||
// 删除用户关联
|
// 删除用户关联
|
||||||
Integer effect = systemUserRoleDAO.deleteByUserId(userId);
|
int effect = systemUserRoleDAO.deleteByUserId(userId);
|
||||||
// 更新缓存中的角色
|
// 更新缓存中的角色
|
||||||
RedisUtils.<LoginUser>processSetJson(UserCacheKeyDefine.USER_INFO, s -> {
|
RedisUtils.<LoginUser>processSetJson(UserCacheKeyDefine.USER_INFO, s -> {
|
||||||
s.setRoles(Lists.empty());
|
s.setRoles(Lists.empty());
|
||||||
@@ -82,7 +82,7 @@ public class SystemUserRoleServiceImpl implements SystemUserRoleService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 删除用户角色关联
|
// 删除用户角色关联
|
||||||
Integer effect = systemUserRoleDAO.deleteByUserId(userId);
|
int effect = systemUserRoleDAO.deleteByUserId(userId);
|
||||||
// 重新添加用户角色关联
|
// 重新添加用户角色关联
|
||||||
List<SystemUserRoleDO> addUserRoles = userRoles.stream().map(s -> {
|
List<SystemUserRoleDO> addUserRoles = userRoles.stream().map(s -> {
|
||||||
SystemUserRoleDO ur = new SystemUserRoleDO();
|
SystemUserRoleDO ur = new SystemUserRoleDO();
|
||||||
@@ -91,6 +91,7 @@ public class SystemUserRoleServiceImpl implements SystemUserRoleService {
|
|||||||
return ur;
|
return ur;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
systemUserRoleDAO.insertBatch(addUserRoles);
|
systemUserRoleDAO.insertBatch(addUserRoles);
|
||||||
|
effect += addUserRoles.size();
|
||||||
// 更新缓存中的角色
|
// 更新缓存中的角色
|
||||||
RedisUtils.<LoginUser>processSetJson(UserCacheKeyDefine.USER_INFO, s -> {
|
RedisUtils.<LoginUser>processSetJson(UserCacheKeyDefine.USER_INFO, s -> {
|
||||||
s.setRoles(new ArrayList<>(roleCodeList));
|
s.setRoles(new ArrayList<>(roleCodeList));
|
||||||
|
|||||||
Reference in New Issue
Block a user