From 923d7509a27a402202292123c04a9db89d407e59 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Tue, 23 Feb 2021 22:16:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A7=92=E8=89=B2=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/mapper/ext/ExtSysRoleMapper.java | 14 +++++ .../base/mapper/ext/ExtSysRoleMapper.xml | 26 +++++++++ .../controller/sys/SysRoleController.java | 55 +++++++++++++++++++ .../sys/request/RoleGridRequest.java | 11 ++++ .../sys/response/RoleNodeResponse.java | 14 +++++ .../dataease/service/sys/SysRoleService.java | 48 ++++++++++++++++ .../resources/db/migration/V8__system.sql | 10 +++- .../business/components/settings/sys/role.vue | 53 +++++++++++++----- 8 files changed, 217 insertions(+), 14 deletions(-) create mode 100644 backend/src/main/java/io/dataease/base/mapper/ext/ExtSysRoleMapper.java create mode 100644 backend/src/main/java/io/dataease/base/mapper/ext/ExtSysRoleMapper.xml create mode 100644 backend/src/main/java/io/dataease/controller/sys/SysRoleController.java create mode 100644 backend/src/main/java/io/dataease/controller/sys/request/RoleGridRequest.java create mode 100644 backend/src/main/java/io/dataease/controller/sys/response/RoleNodeResponse.java create mode 100644 backend/src/main/java/io/dataease/service/sys/SysRoleService.java diff --git a/backend/src/main/java/io/dataease/base/mapper/ext/ExtSysRoleMapper.java b/backend/src/main/java/io/dataease/base/mapper/ext/ExtSysRoleMapper.java new file mode 100644 index 0000000000..7af7d39ae6 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/ext/ExtSysRoleMapper.java @@ -0,0 +1,14 @@ +package io.dataease.base.mapper.ext; + +import io.dataease.controller.sys.request.RoleGridRequest; +import io.dataease.controller.sys.response.RoleNodeResponse; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + + +public interface ExtSysRoleMapper { + + + List query(@Param("request")RoleGridRequest request); +} diff --git a/backend/src/main/java/io/dataease/base/mapper/ext/ExtSysRoleMapper.xml b/backend/src/main/java/io/dataease/base/mapper/ext/ExtSysRoleMapper.xml new file mode 100644 index 0000000000..f2887ccd61 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/ext/ExtSysRoleMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + diff --git a/backend/src/main/java/io/dataease/controller/sys/SysRoleController.java b/backend/src/main/java/io/dataease/controller/sys/SysRoleController.java new file mode 100644 index 0000000000..782983eaf8 --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/sys/SysRoleController.java @@ -0,0 +1,55 @@ +package io.dataease.controller.sys; + + +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import io.dataease.base.domain.SysRole; +import io.dataease.commons.utils.PageUtils; +import io.dataease.commons.utils.Pager; +import io.dataease.controller.sys.request.RoleGridRequest; +import io.dataease.controller.sys.response.RoleNodeResponse; +import io.dataease.service.sys.SysRoleService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import java.util.List; + +@RestController +@RequiredArgsConstructor +@Api(tags = "系统:角色管理") +@RequestMapping("/api/role") +public class SysRoleController { + + @Resource + private SysRoleService sysRoleService; + + + @ApiOperation("新增角色") + @PostMapping("/create") + public void create(@RequestBody SysRole role){ + sysRoleService.add(role); + } + + + @ApiOperation("删除角色") + @PostMapping("/delete") + public void delete(Long roleId){ + sysRoleService.delete(roleId); + } + + + @ApiOperation("更新角色") + @PostMapping("/update") + public void update(@RequestBody SysRole role){ + sysRoleService.update(role); + } + + @ApiOperation("查询角色") + @PostMapping("/roleGrid/{goPage}/{pageSize}") + public Pager> roleGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody RoleGridRequest request) { + Page page = PageHelper.startPage(goPage, pageSize, true); + return PageUtils.setPageInfo(page, sysRoleService.query(request)); + } +} diff --git a/backend/src/main/java/io/dataease/controller/sys/request/RoleGridRequest.java b/backend/src/main/java/io/dataease/controller/sys/request/RoleGridRequest.java new file mode 100644 index 0000000000..744c9a7c9e --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/sys/request/RoleGridRequest.java @@ -0,0 +1,11 @@ +package io.dataease.controller.sys.request; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class RoleGridRequest implements Serializable { + + private String name; +} diff --git a/backend/src/main/java/io/dataease/controller/sys/response/RoleNodeResponse.java b/backend/src/main/java/io/dataease/controller/sys/response/RoleNodeResponse.java new file mode 100644 index 0000000000..ee500f16e4 --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/sys/response/RoleNodeResponse.java @@ -0,0 +1,14 @@ +package io.dataease.controller.sys.response; + +import io.dataease.base.domain.SysRole; +import lombok.Data; + +import java.util.List; + +@Data +public class RoleNodeResponse extends SysRole { + + private List menuIds; + + private List dataIds; +} diff --git a/backend/src/main/java/io/dataease/service/sys/SysRoleService.java b/backend/src/main/java/io/dataease/service/sys/SysRoleService.java new file mode 100644 index 0000000000..5bbfbcb9d3 --- /dev/null +++ b/backend/src/main/java/io/dataease/service/sys/SysRoleService.java @@ -0,0 +1,48 @@ +package io.dataease.service.sys; + + +import io.dataease.base.domain.SysRole; +import io.dataease.base.mapper.SysRoleMapper; +import io.dataease.base.mapper.ext.ExtSysRoleMapper; +import io.dataease.controller.sys.request.RoleGridRequest; +import io.dataease.controller.sys.response.RoleNodeResponse; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service +public class SysRoleService { + + @Resource + private SysRoleMapper mapper; + + @Resource + private ExtSysRoleMapper extSysRoleMapper; + + + public int add(SysRole role){ + Long now = System.currentTimeMillis(); + role.setCreateTime(now); + role.setUpdateTime(now); + return mapper.insert(role); + } + + + public int update(SysRole role){ + Long now = System.currentTimeMillis(); + role.setUpdateTime(now); + return mapper.updateByPrimaryKey(role); + } + + public int delete(Long roleId){ + return mapper.deleteByPrimaryKey(roleId); + } + + + public List query(RoleGridRequest request){ + List result = extSysRoleMapper.query(request); + + return result; + } +} diff --git a/backend/src/main/resources/db/migration/V8__system.sql b/backend/src/main/resources/db/migration/V8__system.sql index db658fbd77..6c4db16f9d 100644 --- a/backend/src/main/resources/db/migration/V8__system.sql +++ b/backend/src/main/resources/db/migration/V8__system.sql @@ -53,4 +53,12 @@ CREATE TABLE IF NOT EXISTS `sys_role` ( PRIMARY KEY (`role_id`) USING BTREE, UNIQUE KEY `uniq_name` (`name`), KEY `role_name_index` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='角色表'; \ No newline at end of file +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='角色表'; + + +CREATE TABLE IF NOT EXISTS `sys_roles_menus` ( + `menu_id` bigint(20) NOT NULL COMMENT '菜单ID', + `role_id` bigint(20) NOT NULL COMMENT '角色ID', + PRIMARY KEY (`menu_id`,`role_id`) USING BTREE, + KEY `FKcngg2qadojhi3a651a5adkvbq` (`role_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='角色菜单关联'; \ No newline at end of file diff --git a/frontend/src/business/components/settings/sys/role.vue b/frontend/src/business/components/settings/sys/role.vue index 17c74f3b46..6150a9bc2d 100644 --- a/frontend/src/business/components/settings/sys/role.vue +++ b/frontend/src/business/components/settings/sys/role.vue @@ -1,13 +1,13 @@