feat: 角色管理初始化

This commit is contained in:
fit2cloud-chenyw 2021-02-23 22:16:43 +08:00
parent 73bf229464
commit 923d7509a2
8 changed files with 217 additions and 14 deletions

View File

@ -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<RoleNodeResponse> query(@Param("request")RoleGridRequest request);
}

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.dataease.base.mapper.ext.ExtSysRoleMapper">
<resultMap id="BaseResultMap" type="io.dataease.controller.sys.response.RoleNodeResponse" extends="io.dataease.base.mapper.SysRoleMapper.BaseResultMap">
<result column="menuIds" property="menu_ids"/>
<collection property="menuIds" ofType="long">
<constructor>
<arg column="menu_id"/>
</constructor>
</collection>
</resultMap>
<select id="query" resultMap="BaseResultMap">
select r.*, m.menu_id
from sys_role r left join sys_roles_menus m on r.role_id = m.role_id
<where>
<if test="request.name != null">
AND r.name like CONCAT('%', #{request.name},'%')
</if>
</where>
order by r.update_time desc
</select>
</mapper>

View File

@ -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<List<RoleNodeResponse>> roleGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody RoleGridRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, sysRoleService.query(request));
}
}

View File

@ -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;
}

View File

@ -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<Long> menuIds;
private List<Long> dataIds;
}

View File

@ -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<RoleNodeResponse> query(RoleGridRequest request){
List<RoleNodeResponse> result = extSysRoleMapper.query(request);
return result;
}
}

View File

@ -53,4 +53,12 @@ CREATE TABLE IF NOT EXISTS `sys_role` (
PRIMARY KEY (`role_id`) USING BTREE, PRIMARY KEY (`role_id`) USING BTREE,
UNIQUE KEY `uniq_name` (`name`), UNIQUE KEY `uniq_name` (`name`),
KEY `role_name_index` (`name`) KEY `role_name_index` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='角色表'; ) 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='角色菜单关联';

View File

@ -1,13 +1,13 @@
<template> <template>
<div style="height: 100%" v-loading="result.loading"> <div style="height: 100%" v-loading="result.loading">
<el-container style="width: 100%; height: 100%;border: 1px solid #eee"> <el-container style="width: 100%; height: 100%;border: 1px solid #eee">
<el-aside width="30%" style="border: 1px solid #eee"> <el-aside width="70%" style="border: 1px solid #eee">
<el-card class="table-card"> <el-card class="table-card">
<template v-slot:header> <template v-slot:header>
<ms-table-header :condition.sync="condition" @search="search" @create="create" :create-tip="$t('user.create')" :title="$t('commons.user')"/> <ms-table-header :condition.sync="condition" @search="search" @create="create" :create-tip="$t('user.create')" :title="$t('commons.user')"/>
</template> </template>
<el-table border class="adjust-table" :data="tableData" style="width: 100%"> <el-table border class="adjust-table" :data="tableData" style="width: 100%;">
<el-table-column prop="name" label="名称" /> <el-table-column prop="name" label="名称" />
<el-table-column :show-overflow-tooltip="true" width="135px" prop="createTime" label="创建日期"> <el-table-column :show-overflow-tooltip="true" width="135px" prop="createTime" label="创建日期">
<template v-slot:default="scope"> <template v-slot:default="scope">
@ -21,18 +21,32 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
<ms-table-pagination :change="search" :current-page.sync="currentPage" :page-size.sync="pageSize" :total="total"/> <ms-table-pagination :change="search" :current-page.sync="currentPage" :page-size.sync="pageSize" :total="total"/>
</el-card> </el-card>
</el-aside> </el-aside>
<el-main style=""> <el-main style="">
<el-tabs v-model="activeName" @tab-click="handleClick"> <el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane label="菜单飞配" name="first">菜单飞配</el-tab-pane> <el-tab-pane label="菜单授权" name="first">
<el-tab-pane label="数据分配" name="second">数据分配</el-tab-pane> <el-tree
ref="menu"
lazy
:data="menus"
:default-checked-keys="menuIds"
:load="getMenuDatas"
:props="defaultProps"
check-strictly
accordion
show-checkbox
node-key="menuId"
@check="menuChange"
/>
</el-tab-pane>
<el-tab-pane label="数据授权" name="second">玩命开发中...</el-tab-pane>
</el-tabs> </el-tabs>
</el-main> </el-main>
</el-container> </el-container>
</div> </div>
</template> </template>
<script> <script>
import MsCreateBox from "../CreateBox"; import MsCreateBox from "../CreateBox";
@ -55,7 +69,7 @@ export default {
data() { data() {
return { return {
result: {}, result: {},
queryPath: '/user/special/list', queryPath: '/api/role/roleGrid',
deletePath: '/user/special/delete/', deletePath: '/user/special/delete/',
createPath: '/user/special/add', createPath: '/user/special/add',
updatePath: '/user/special/update', updatePath: '/user/special/update',
@ -64,23 +78,36 @@ export default {
total: 0, total: 0,
condition: {}, condition: {},
tableData: [], tableData: [],
menus: [],
menuIds: [],
defaultProps: {},
activeName: 'second' activeName: 'second'
}; };
}, },
activated() {
this.search();
},
methods: { methods: {
handleClick(tab, event) { handleClick(tab, event) {
console.log(tab, event); console.log(tab, event);
}, },
create(){},
search(){ search(){
this.result = this.$post(this.queryPath, this.condition, response => { this.result = this.$post(this.queryPath+ "/" + this.currentPage + "/" + this.pageSize, this.condition, response => {
let data = response.data; let data = response.data;
this.total = data.itemCount; this.total = data.itemCount;
this.tableData = data.listObject; this.tableData = data.listObject;
}) })
}, },
edit(row){ edit(row){
},
getMenuDatas(node, resolve){
},
menuChange(menu){
}, },
handleDelete(row){ handleDelete(row){
@ -91,5 +118,5 @@ export default {
<style scoped> <style scoped>
</style> </style>