From 1bfaa2c967859a946460b9ff397d3b1f827d0173 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 9 Jan 2021 23:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20Role=20=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/system/mapper/SysMenuMapper.java | 20 +---- .../ruoyi/system/mapper/SysRoleMapper.java | 77 ++----------------- .../system/mapper/SysRoleMenuMapper.java | 44 ----------- .../system/mapper/SysUserRoleMapper.java | 62 --------------- .../resources/mapper/system/SysMenuMapper.xml | 32 -------- .../mapper/system/SysRoleMenuMapper.xml | 34 -------- .../mapper/system/SysUserRoleMapper.xml | 44 ----------- ruoyi-ui/src/api/system/dept.js | 21 +---- ruoyi-ui/src/api/system/permission.js | 9 +++ ruoyi-ui/src/api/system/role.js | 9 --- ruoyi-ui/src/utils/constants.js | 2 +- ruoyi-ui/src/utils/ruoyi.js | 14 ++-- ruoyi-ui/src/views/system/role/index.vue | 27 ++++--- .../permission/SysPermissionController.java | 10 +++ ...SysPermissionAssignRoleDataScopeReqVO.java | 27 +++++++ .../SysPermissionAssignRoleMenuReqVO.java | 2 +- .../permission/vo/role/SysRolePageReqVO.java | 16 ++++ .../permission/vo/role/SysRoleRespVO.java | 4 + .../mysql/dao/permission/SysRoleMapper.java | 4 +- .../dataobject/permission/SysRoleDO.java | 4 +- .../system/enums/SysErrorCodeConstants.java | 3 +- .../permission/SysPermissionService.java | 11 ++- .../service/permission/SysRoleService.java | 10 +++ .../impl/SysPermissionServiceImpl.java | 5 ++ .../permission/impl/SysRoleServiceImpl.java | 19 +++-- .../dashboard/util/date/DateUtils.java | 2 + 26 files changed, 151 insertions(+), 361 deletions(-) delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java delete mode 100644 ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml delete mode 100644 ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/permission/SysPermissionAssignRoleDataScopeReqVO.java diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java index 9e88c1ee3..8aa59cfd1 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java @@ -1,6 +1,7 @@ package com.ruoyi.system.mapper; import java.util.List; + import org.apache.ibatis.annotations.Param; import com.ruoyi.common.core.domain.entity.SysMenu; @@ -9,22 +10,7 @@ import com.ruoyi.common.core.domain.entity.SysMenu; * * @author ruoyi */ -public interface SysMenuMapper -{ - /** - * 查询系统菜单列表 - * - * @param menu 菜单信息 - * @return 菜单列表 - */ - public List selectMenuList(SysMenu menu); - - /** - * 根据用户所有权限 - * - * @return 权限列表 - */ - public List selectMenuPerms(); +public interface SysMenuMapper { /** * 根据用户查询系统菜单列表 @@ -60,7 +46,7 @@ public interface SysMenuMapper /** * 根据角色ID查询菜单树信息 * - * @param roleId 角色ID + * @param roleId 角色ID * @param menuCheckStrictly 菜单树选择项是否关联显示 * @return 选中菜单列表 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java index e4379c97b..0bfacdc01 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java @@ -1,18 +1,19 @@ package com.ruoyi.system.mapper; import java.util.List; + import com.ruoyi.common.core.domain.entity.SysRole; /** * 角色表 数据层 - * + * * @author ruoyi */ -public interface SysRoleMapper -{ +public interface SysRoleMapper { + /** * 根据条件分页查询角色数据 - * + * * @param role 角色信息 * @return 角色数据集合信息 */ @@ -20,88 +21,26 @@ public interface SysRoleMapper /** * 根据用户ID查询角色 - * + * * @param userId 用户ID * @return 角色列表 */ public List selectRolePermissionByUserId(Long userId); - /** - * 查询所有角色 - * - * @return 角色列表 - */ - public List selectRoleAll(); - /** * 根据用户ID获取角色选择框列表 - * + * * @param userId 用户ID * @return 选中角色ID列表 */ public List selectRoleListByUserId(Long userId); - /** - * 通过角色ID查询角色 - * - * @param roleId 角色ID - * @return 角色对象信息 - */ - public SysRole selectRoleById(Long roleId); - /** * 根据用户ID查询角色 - * + * * @param userName 用户名 * @return 角色列表 */ public List selectRolesByUserName(String userName); - /** - * 校验角色名称是否唯一 - * - * @param roleName 角色名称 - * @return 角色信息 - */ - public SysRole checkRoleNameUnique(String roleName); - - /** - * 校验角色权限是否唯一 - * - * @param roleKey 角色权限 - * @return 角色信息 - */ - public SysRole checkRoleKeyUnique(String roleKey); - - /** - * 修改角色信息 - * - * @param role 角色信息 - * @return 结果 - */ - public int updateRole(SysRole role); - - /** - * 新增角色信息 - * - * @param role 角色信息 - * @return 结果 - */ - public int insertRole(SysRole role); - - /** - * 通过角色ID删除角色 - * - * @param roleId 角色ID - * @return 结果 - */ - public int deleteRoleById(Long roleId); - - /** - * 批量删除角色信息 - * - * @param roleIds 需要删除的角色ID - * @return 结果 - */ - public int deleteRoleByIds(Long[] roleIds); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java deleted file mode 100644 index 23391557d..000000000 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.ruoyi.system.mapper; - -import java.util.List; -import com.ruoyi.system.domain.SysRoleMenu; - -/** - * 角色与菜单关联表 数据层 - * - * @author ruoyi - */ -public interface SysRoleMenuMapper -{ - /** - * 查询菜单使用数量 - * - * @param menuId 菜单ID - * @return 结果 - */ - public int checkMenuExistRole(Long menuId); - - /** - * 通过角色ID删除角色和菜单关联 - * - * @param roleId 角色ID - * @return 结果 - */ - public int deleteRoleMenuByRoleId(Long roleId); - - /** - * 批量删除角色菜单关联信息 - * - * @param ids 需要删除的数据ID - * @return 结果 - */ - public int deleteRoleMenu(Long[] ids); - - /** - * 批量新增角色菜单信息 - * - * @param roleMenuList 角色菜单列表 - * @return 结果 - */ - public int batchRoleMenu(List roleMenuList); -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java deleted file mode 100644 index ad3fe62c1..000000000 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.ruoyi.system.mapper; - -import java.util.List; -import org.apache.ibatis.annotations.Param; -import com.ruoyi.system.domain.SysUserRole; - -/** - * 用户与角色关联表 数据层 - * - * @author ruoyi - */ -public interface SysUserRoleMapper -{ - /** - * 通过用户ID删除用户和角色关联 - * - * @param userId 用户ID - * @return 结果 - */ - public int deleteUserRoleByUserId(Long userId); - - /** - * 批量删除用户和角色关联 - * - * @param ids 需要删除的数据ID - * @return 结果 - */ - public int deleteUserRole(Long[] ids); - - /** - * 通过角色ID查询角色使用数量 - * - * @param roleId 角色ID - * @return 结果 - */ - public int countUserRoleByRoleId(Long roleId); - - /** - * 批量新增用户角色信息 - * - * @param userRoleList 用户角色列表 - * @return 结果 - */ - public int batchUserRole(List userRoleList); - - /** - * 删除用户和角色关联信息 - * - * @param userRole 用户和角色关联信息 - * @return 结果 - */ - public int deleteUserRoleInfo(SysUserRole userRole); - - /** - * 批量取消授权用户角色 - * - * @param roleId 角色ID - * @param userIds 需要删除的用户数据ID - * @return 结果 - */ - public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds); -} diff --git a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml index 98343b99b..8fed327f5 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml @@ -4,22 +4,6 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - diff --git a/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml deleted file mode 100644 index e75bb1744..000000000 --- a/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - delete from sys_role_menu where role_id=#{roleId} - - - - delete from sys_role_menu where role_id in - - #{roleId} - - - - - insert into sys_role_menu(role_id, menu_id) values - - (#{item.roleId},#{item.menuId}) - - - - \ No newline at end of file diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml deleted file mode 100644 index 95e07adb1..000000000 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - delete from sys_user_role where user_id=#{userId} - - - - - - delete from sys_user_role where user_id in - - #{userId} - - - - - insert into sys_user_role(user_id, role_id) values - - (#{item.userId},#{item.roleId}) - - - - - delete from sys_user_role where user_id=#{userId} and role_id=#{roleId} - - - - delete from sys_user_role where role_id=#{roleId} and user_id in - - #{userId} - - - \ No newline at end of file diff --git a/ruoyi-ui/src/api/system/dept.js b/ruoyi-ui/src/api/system/dept.js index 3cfa8e506..1ab09fac7 100644 --- a/ruoyi-ui/src/api/system/dept.js +++ b/ruoyi-ui/src/api/system/dept.js @@ -25,24 +25,6 @@ export function getDept(deptId) { }) } -// 查询部门下拉树结构 -// TODO 准备删除 -export function treeselect() { - return request({ - url: '/system/dept/treeselect', - method: 'get' - }) -} - -// 根据角色ID查询部门树结构 -// TODO 准备删除 -export function roleDeptTreeselect(roleId) { - return request({ - url: '/system/dept/roleDeptTreeselect/' + roleId, - method: 'get' - }) -} - // 获取部门精简信息列表 export function listSimpleDepts() { return request({ @@ -76,3 +58,6 @@ export function delDept(deptId) { method: 'delete' }) } + +export class treeselect { +} diff --git a/ruoyi-ui/src/api/system/permission.js b/ruoyi-ui/src/api/system/permission.js index 1ec3eea0e..ac3ed091a 100644 --- a/ruoyi-ui/src/api/system/permission.js +++ b/ruoyi-ui/src/api/system/permission.js @@ -16,3 +16,12 @@ export function assignRoleMenu(data) { data: data }) } + +// 赋予角色数据权限 +export function assignRoleDataScope(data) { + return request({ + url: '/system/permission/assign-role-data-scope', + method: 'post', + data: data + }) +} diff --git a/ruoyi-ui/src/api/system/role.js b/ruoyi-ui/src/api/system/role.js index 3e6fd55b1..a4c5d423f 100644 --- a/ruoyi-ui/src/api/system/role.js +++ b/ruoyi-ui/src/api/system/role.js @@ -35,15 +35,6 @@ export function updateRole(data) { }) } -// 角色数据权限 -export function dataScope(data) { - return request({ - url: '/system/role/dataScope', - method: 'put', - data: data - }) -} - // 角色状态修改 export function changeRoleStatus(id, status) { const data = { diff --git a/ruoyi-ui/src/utils/constants.js b/ruoyi-ui/src/utils/constants.js index fefb97e6b..ac05b64a8 100644 --- a/ruoyi-ui/src/utils/constants.js +++ b/ruoyi-ui/src/utils/constants.js @@ -30,7 +30,7 @@ export const SysRoleTypeEnum = { } /** - * 数据权限的泛微枚举 + * 数据权限的范围枚举 */ export const SysDataScopeEnum = { ALL: 1, // 全部数据权限 diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js index 493aa047d..46eb9d271 100644 --- a/ruoyi-ui/src/utils/ruoyi.js +++ b/ruoyi-ui/src/utils/ruoyi.js @@ -55,15 +55,15 @@ export function resetForm(refName) { // 添加日期范围 export function addDateRange(params, dateRange, propName) { - var search = params; - search.params = {}; - if (null != dateRange && '' != dateRange) { + const search = params; + search.params = {}; + if (null != dateRange && '' !== dateRange) { if (typeof(propName) === "undefined") { - search.params["beginTime"] = dateRange[0]; - search.params["endTime"] = dateRange[1]; + search["beginTime"] = dateRange[0]; + search["endTime"] = dateRange[1]; } else { - search.params["begin" + propName] = dateRange[0]; - search.params["end" + propName] = dateRange[1]; + search["begin" + propName] = dateRange[0]; + search["end" + propName] = dateRange[1]; } } return search; diff --git a/ruoyi-ui/src/views/system/role/index.vue b/ruoyi-ui/src/views/system/role/index.vue index 50cf5cfd4..e43ffbc2e 100644 --- a/ruoyi-ui/src/views/system/role/index.vue +++ b/ruoyi-ui/src/views/system/role/index.vue @@ -248,8 +248,8 @@ import { updateRole } from "@/api/system/role"; import {listSimpleMenus} from "@/api/system/menu"; -import {assignRoleMenu, listRoleMenus} from "@/api/system/permission"; -import {listSimpleDepts, treeselect as deptTreeselect} from "@/api/system/dept"; +import {assignRoleMenu, listRoleMenus, assignRoleDataScope} from "@/api/system/permission"; +import {listSimpleDepts} from "@/api/system/dept"; import {SysCommonStatusEnum, SysDataScopeEnum} from "@/utils/constants"; import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict"; @@ -326,7 +326,10 @@ export default { /** 查询角色列表 */ getList() { this.loading = true; - listRole(this.addDateRange(this.queryParams, this.dateRange)).then( + listRole(this.addDateRange(this.queryParams, [ + this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined, + this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined, + ])).then( response => { this.roleList = response.data.list; this.total = response.data.total; @@ -387,6 +390,7 @@ export default { sort: 0, deptIds: [], menuIds: [], + dataScope: undefined, deptCheckStrictly: false, remark: undefined }; @@ -485,11 +489,11 @@ export default { // 处理 menuOptions 参数 this.deptOptions = []; this.deptOptions.push(...this.handleTree(response.data, "id")); - }); - // 获得角色拥有的数据权限 - getRole(row.id).then(response => { - // TODO 搞一搞 - // this.$refs.dept.setCheckedKeys(res.checkedKeys); + // 获得角色拥有的数据权限 + getRole(row.id).then(response => { + this.form.dataScope = response.data.dataScope; + this.$refs.dept.setCheckedKeys(response.data.dataScopeDeptIds, false); + }); }); }, /** 提交按钮 */ @@ -515,11 +519,10 @@ export default { /** 提交按钮(数据权限) */ submitDataScope: function() { if (this.form.id !== undefined) { - // this.form.deptIds = this.getDeptAllCheckedKeys(); - debugger - dataScope({ + assignRoleDataScope({ roleId: this.form.id, - deptIds: this.form.dataScope !== SysDataScopeEnum.DEPT_CUSTOM ? [] : + dataScope: this.form.dataScope, + dataScopeDeptIds: this.form.dataScope !== SysDataScopeEnum.DEPT_CUSTOM ? [] : this.$refs.dept.getCheckedKeys(false) }).then(response => { this.msgSuccess("修改成功"); diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysPermissionController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysPermissionController.java index 6cd24f560..f10bdb76a 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysPermissionController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysPermissionController.java @@ -1,6 +1,7 @@ package cn.iocoder.dashboard.modules.system.controller.permission; import cn.iocoder.dashboard.common.pojo.CommonResult; +import cn.iocoder.dashboard.modules.system.controller.permission.vo.permission.SysPermissionAssignRoleDataScopeReqVO; import cn.iocoder.dashboard.modules.system.controller.permission.vo.permission.SysPermissionAssignRoleMenuReqVO; import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService; import io.swagger.annotations.Api; @@ -43,6 +44,15 @@ public class SysPermissionController { return success(true); } + @PostMapping("/assign-role-data-scope") + @ApiOperation("赋予角色数据权限") +// @RequiresPermissions("system:permission:assign-role-data-scope") + public CommonResult assignRoleDataScope( + @Validated @RequestBody SysPermissionAssignRoleDataScopeReqVO reqVO) { + permissionService.assignRoleDataScope(reqVO.getRoleId(), reqVO.getDataScope(), reqVO.getDataScopeDeptIds()); + return success(true); + } + // @GetMapping("/list-admin-roles") // @ApiOperation("获得管理员拥有的角色编号列表") //// @RequiresPermissions("system:permission:assign-admin-role") diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/permission/SysPermissionAssignRoleDataScopeReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/permission/SysPermissionAssignRoleDataScopeReqVO.java new file mode 100644 index 000000000..c71304318 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/permission/SysPermissionAssignRoleDataScopeReqVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.dashboard.modules.system.controller.permission.vo.permission; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.util.Collections; +import java.util.Set; + +@ApiModel("赋予角色数据权限 Request VO") +@Data +public class SysPermissionAssignRoleDataScopeReqVO { + + @ApiModelProperty(value = "角色编号", required = true, example = "1") + @NotNull(message = "角色编号不能为空") + private Long roleId; + + @ApiModelProperty(value = "数据范围", required = true, example = "1", notes = "参见 SysDataScopeEnum 枚举类") + @NotNull(message = "数据范围不能为空") +// TODO 这里要多一个枚举校验 + private Integer dataScope; + + @ApiModelProperty(value = "部门编号列表", example = "1,3,5", notes = "只有范围类型为 DEPT_CUSTOM 时,该字段才需要") + private Set dataScopeDeptIds = Collections.emptySet(); // 兜底 + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/permission/SysPermissionAssignRoleMenuReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/permission/SysPermissionAssignRoleMenuReqVO.java index f95ec009b..4d5057244 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/permission/SysPermissionAssignRoleMenuReqVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/permission/SysPermissionAssignRoleMenuReqVO.java @@ -12,7 +12,7 @@ import java.util.Set; @Data public class SysPermissionAssignRoleMenuReqVO { - @ApiModelProperty(value = "角色名", required = true, example = "1") + @ApiModelProperty(value = "角色编号", required = true, example = "1") @NotNull(message = "角色编号不能为空") private Long roleId; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRolePageReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRolePageReqVO.java index 41ac1adb0..3dddb4354 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRolePageReqVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRolePageReqVO.java @@ -5,6 +5,11 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @ApiModel("角色分页 Request VO") @Data @@ -14,7 +19,18 @@ public class SysRolePageReqVO extends PageParam { @ApiModelProperty(value = "角色名称", example = "芋道", notes = "模糊匹配") private String name; + @ApiModelProperty(value = "角色标识", example = "yudao", notes = "模糊匹配") + private String code; + @ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类") private Integer status; + @ApiModelProperty(value = "开始时间", example = "2020-10-24") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date beginTime; + + @ApiModelProperty(value = "结束时间", example = "2020-10-24") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date endTime; + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRoleRespVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRoleRespVO.java index 051d815a3..f65da453d 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRoleRespVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/vo/role/SysRoleRespVO.java @@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import java.util.Date; +import java.util.Set; @ApiModel("角色信息 Response VO") @Data @@ -22,6 +23,9 @@ public class SysRoleRespVO extends SysRoleBaseVO { @ApiModelProperty(value = "数据范围", required = true, example = "1", notes = "参见 DataScopeEnum 枚举类") private Integer dataScope; + @ApiModelProperty(value = "数据范围(指定部门数组)", example = "1") + private Set dataScopeDeptIds; + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类") private Integer status; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/permission/SysRoleMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/permission/SysRoleMapper.java index 188033fb4..71ad24557 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/permission/SysRoleMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/permission/SysRoleMapper.java @@ -14,7 +14,9 @@ public interface SysRoleMapper extends BaseMapper { default IPage selectPage(SysRolePageReqVO reqVO) { return selectPage(MyBatisUtils.buildPage(reqVO), new QueryWrapperX().likeIfPresent("name", reqVO.getName()) - .eqIfPresent("status", reqVO.getStatus())); + .likeIfPresent("code", reqVO.getCode()) + .eqIfPresent("status", reqVO.getStatus()) + .betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime())); } default SysRoleDO selectByName(String name) { diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/permission/SysRoleDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/permission/SysRoleDO.java index ba893ce0e..7e8c375c0 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/permission/SysRoleDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/permission/SysRoleDO.java @@ -12,7 +12,7 @@ import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler; import lombok.Data; import lombok.EqualsAndHashCode; -import java.util.List; +import java.util.Set; /** * 角色 DO @@ -72,6 +72,6 @@ public class SysRoleDO extends BaseDO { * 适用于 {@link #dataScope} 的值为 {@link DataScopeEnum#DEPT_CUSTOM} 时 */ @TableField(typeHandler = FastjsonTypeHandler.class) - private List dataScopeDeptIds; + private Set dataScopeDeptIds; } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java b/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java index 7d0b8a788..4f0bad525 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java @@ -30,7 +30,6 @@ public interface SysErrorCodeConstants { ErrorCode ROLE_NOT_EXISTS = new ErrorCode(1002003000, "角色不存在"); ErrorCode ROLE_NAME_DUPLICATE = new ErrorCode(1002003001, "已经存在名为【{}}】的角色"); ErrorCode ROLE_CODE_DUPLICATE = new ErrorCode(1002003002, "已经存在编码为【{}}】的角色"); - ErrorCode ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE = new ErrorCode(1002003004, "不能修改类型为系统内置的角色"); - ErrorCode ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE = new ErrorCode(1002003005, "不能删除类型为系统内置的角色"); + ErrorCode ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE = new ErrorCode(1002003004, "不能操作类型为系统内置的角色"); } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysPermissionService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysPermissionService.java index 0ff00c9e4..34de1ac11 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysPermissionService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysPermissionService.java @@ -52,13 +52,22 @@ public interface SysPermissionService { Set listRoleMenuIds(Long roleId); /** - * 赋予赋予角色菜单 + * 设置角色菜单 * * @param roleId 角色编号 * @param menuIds 菜单编号集合 */ void assignRoleMenu(Long roleId, Set menuIds); + /** + * 设置角色的数据权限 + * + * @param roleId 角色编号 + * @param dataScope 数据范围 + * @param dataScopeDeptIds 部门编号数组 + */ + void assignRoleDataScope(Long roleId, Integer dataScope, Set dataScopeDeptIds); + /** * 处理角色删除时,删除关联授权角色 * diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysRoleService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysRoleService.java index 8a619a473..62479de7d 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysRoleService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysRoleService.java @@ -8,6 +8,7 @@ import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRo import java.util.Collection; import java.util.List; +import java.util.Set; /** * 角色 Service 接口 @@ -91,4 +92,13 @@ public interface SysRoleService { */ void updateRoleStatus(Long id, Integer status); + /** + * 设置角色的数据权限 + * + * @param id 角色编号 + * @param dataScope 数据范围 + * @param dataScopeDeptIds 部门编号数组 + */ + void updateRoleDataScope(Long id, Integer dataScope, Set dataScopeDeptIds); + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java index 6f645127e..40bbd82af 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java @@ -142,6 +142,11 @@ public class SysPermissionServiceImpl implements SysPermissionService { } } + @Override + public void assignRoleDataScope(Long roleId, Integer dataScope, Set dataScopeDeptIds) { + roleService.updateRoleDataScope(roleId, dataScope, dataScopeDeptIds); + } + @Override public void processRoleDeleted(Long roleId) { // TODO 实现我 diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java index 46bbb2852..eeff67cab 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java @@ -23,10 +23,7 @@ import org.springframework.util.StringUtils; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*; @@ -148,6 +145,18 @@ public class SysRoleServiceImpl implements SysRoleService { roleMapper.updateById(updateObject); } + @Override + public void updateRoleDataScope(Long id, Integer dataScope, Set dataScopeDeptIds) { + // 校验是否可以更新 + checkUpdateRole(id); + // 更新数据范围 + SysRoleDO updateObject = new SysRoleDO(); + updateObject.setId(id); + updateObject.setDataScope(dataScope); + updateObject.setDataScopeDeptIds(dataScopeDeptIds); + roleMapper.updateById(updateObject); + } + /** * 校验角色的唯一字段是否重复 * @@ -187,7 +196,7 @@ public class SysRoleServiceImpl implements SysRoleService { } // 内置角色,不允许删除 if (RoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) { - throw ServiceExceptionUtil.exception(ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE); + throw ServiceExceptionUtil.exception(ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE); } } diff --git a/src/main/java/cn/iocoder/dashboard/util/date/DateUtils.java b/src/main/java/cn/iocoder/dashboard/util/date/DateUtils.java index 611ef05c6..d0f80089f 100644 --- a/src/main/java/cn/iocoder/dashboard/util/date/DateUtils.java +++ b/src/main/java/cn/iocoder/dashboard/util/date/DateUtils.java @@ -8,6 +8,8 @@ import java.util.Date; */ public class DateUtils { + public static final String FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND = "yyyy-MM-dd HH:mm:ss"; + public static Date addTime(Duration duration) { return new Date(System.currentTimeMillis() + duration.toMillis()); }