fix: 角色分配权限问题。

ing: 代码生成
This commit is contained in:
wangiegie@gmail.com 2017-11-22 21:32:15 +08:00
parent f532838bf7
commit 3539be7054
7 changed files with 489 additions and 9 deletions

View File

@ -64,6 +64,22 @@ public class MenuController extends BaseController {
return menuList;
}
/**
* 返回角色的菜单集合
*
* @param roleName 角色名称
* @return 属性集合
*/
@GetMapping("/roleTree/{roleName}")
public List<Integer> roleTree(@PathVariable String roleName) {
Set<MenuVo> menus = sysMenuService.findMenuByRole(roleName, 0);
List<Integer> menuList = new ArrayList<>();
for (MenuVo menuVo : menus) {
menuList.add(menuVo.getMenuId());
}
return menuList;
}
/**
* 通过ID查询菜单的详细信息
*
@ -94,7 +110,7 @@ public class MenuController extends BaseController {
* TODO 级联删除下级节点
*/
@DeleteMapping("/{id}")
@CacheEvict(value = "menu_details",allEntries = true)
@CacheEvict(value = "menu_details", allEntries = true)
public Boolean menuDel(@PathVariable Integer id) {
// 删除当前节点
SysMenu condition1 = new SysMenu();
@ -112,7 +128,7 @@ public class MenuController extends BaseController {
}
@PutMapping
@CacheEvict(value = "menu_details",allEntries = true)
@CacheEvict(value = "menu_details", allEntries = true)
public Boolean menuUpdate(@RequestBody SysMenu sysMenu) {
return sysMenuService.updateById(sysMenu);
}

View File

@ -1,24 +1,37 @@
package com.github.pig.admin.util;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.toolkit.StringUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
* @author lengleng
* @date 2017/10/29
*/
public class MybatisPlusGenerator {
public static void main(String[] args) {
AutoGenerator mpg = new AutoGenerator();
public static void main(String[] args) {
String outputDir = "D://data";
final String viewOutputDir = outputDir + "/view/";
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir("D://data");
gc.setOutputDir(outputDir);
gc.setFileOverride(true);
gc.setActiveRecord(true);
// XML 二级缓存
@ -52,6 +65,59 @@ public class MybatisPlusGenerator {
pc.setParent("com.github.pig.admin");
mpg.setPackageInfo(pc);
// 注入自定义配置可以在 VM 中使用 cfg.abc 设置的值
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
}
};
// 生成的模版路径不存在时需要先新建
File viewDir = new File(viewOutputDir);
if (!viewDir.exists()) {
viewDir.mkdirs();
}
List<FileOutConfig> focList = new ArrayList<FileOutConfig>();
focList.add(new FileOutConfig("/template/listvue.vue.vm") {
@Override
public String outputFile(TableInfo tableInfo) {
return getGeneratorViewPath(viewOutputDir, tableInfo, "List.vue");
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
//生成controller相关
mpg.execute();
}
/**
* 获取配置文件
*
* @return 配置Props
*/
private static Properties getProperties() {
// 读取配置文件
Resource resource = new ClassPathResource("/config/application.properties");
Properties props = new Properties();
try {
props = PropertiesLoaderUtils.loadProperties(resource);
} catch (IOException e) {
e.printStackTrace();
}
return props;
}
/**
* 页面生成的文件名
*/
private static String getGeneratorViewPath(String viewOutputDir, TableInfo tableInfo, String suffixPath) {
String name = StringUtils.firstToLowerCase(tableInfo.getEntityName());
String path = viewOutputDir + "/" + name + "/" + name + suffixPath;
File viewDir = new File(path).getParentFile();
if (!viewDir.exists()) {
viewDir.mkdirs();
}
return path;
}
}

View File

@ -0,0 +1,179 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
var ${table.entityPath}DataGrid;
$(function() {
${table.entityPath}DataGrid = $('#${table.entityPath}DataGrid').datagrid({
url : '${path}/${table.entityPath}/dataGrid',
striped : true,
rownumbers : true,
pagination : true,
singleSelect : true,
idField : 'id',
sortName : 'id',
sortOrder : 'asc',
pageSize : 20,
pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
frozenColumns : [ [ {
width : '60',
title : '编号',
field : 'id',
sortable : true
}, {
width : '60',
title : '状态',
field : 'status',
sortable : true,
formatter : function(value, row, index) {
switch (value) {
case 0:
return '正常';
case 1:
return '停用';
}
}
}, {
width : '140',
title : '创建时间',
field : 'createTime',
sortable : true
}, {
field : 'action',
title : '操作',
width : 200,
formatter : function(value, row, index) {
var str = '';
<shiro:hasPermission name="/${table.entityPath}/edit">
str += $.formatString('<a href="javascript:void(0)" class="${table.entityPath}-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="${table.entityPath}EditFun(\'{0}\');" >编辑</a>', row.id);
</shiro:hasPermission>
<shiro:hasPermission name="/${table.entityPath}/delete">
str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
str += $.formatString('<a href="javascript:void(0)" class="${table.entityPath}-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="${table.entityPath}DeleteFun(\'{0}\');" >删除</a>', row.id);
</shiro:hasPermission>
return str;
}
} ] ],
onLoadSuccess:function(data){
$('.${table.entityPath}-easyui-linkbutton-edit').linkbutton({text:'编辑'});
$('.${table.entityPath}-easyui-linkbutton-del').linkbutton({text:'删除'});
},
toolbar : '#${table.entityPath}Toolbar'
});
});
/**
* 添加框
* @param url
*/
function ${table.entityPath}AddFun() {
parent.$.modalDialog({
title : '添加',
width : 700,
height : 600,
href : '${path}/${table.entityPath}/addPage',
buttons : [ {
text : '确定',
handler : function() {
parent.$.modalDialog.openner_dataGrid = ${table.entityPath}DataGrid;//因为添加成功之后需要刷新这个treeGrid所以先预定义好
var f = parent.$.modalDialog.handler.find('#${table.entityPath}AddForm');
f.submit();
}
} ]
});
}
/**
* 编辑
*/
function ${table.entityPath}EditFun(id) {
if (id == undefined) {
var rows = ${table.entityPath}DataGrid.datagrid('getSelections');
id = rows[0].id;
} else {
${table.entityPath}DataGrid.datagrid('unselectAll').datagrid('uncheckAll');
}
parent.$.modalDialog({
title : '编辑',
width : 700,
height : 600,
href : '${path}/${table.entityPath}/editPage?id=' + id,
buttons : [ {
text : '确定',
handler : function() {
parent.$.modalDialog.openner_dataGrid = ${table.entityPath}DataGrid;//因为添加成功之后需要刷新这个dataGrid所以先预定义好
var f = parent.$.modalDialog.handler.find('#${table.entityPath}EditForm');
f.submit();
}
} ]
});
}
/**
* 删除
*/
function ${table.entityPath}DeleteFun(id) {
if (id == undefined) {//点击右键菜单才会触发这个
var rows = ${table.entityPath}DataGrid.datagrid('getSelections');
id = rows[0].id;
} else {//点击操作里面的删除图标会触发这个
${table.entityPath}DataGrid.datagrid('unselectAll').datagrid('uncheckAll');
}
parent.$.messager.confirm('询问', '您是否要删除当前角色?', function(b) {
if (b) {
progressLoad();
$.post('${path}/${table.entityPath}/delete', {
id : id
}, function(result) {
if (result.success) {
parent.$.messager.alert('提示', result.msg, 'info');
${table.entityPath}DataGrid.datagrid('reload');
}
progressClose();
}, 'JSON');
}
});
}
/**
* 清除
*/
function ${table.entityPath}CleanFun() {
$('#${table.entityPath}SearchForm input').val('');
${table.entityPath}DataGrid.datagrid('load', {});
}
/**
* 搜索
*/
function ${table.entityPath}SearchFun() {
${table.entityPath}DataGrid.datagrid('load', $.serializeObject($('#${table.entityPath}SearchForm')));
}
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
<div data-options="region:'north',border:false" style="height: 30px; overflow: hidden;background-color: #fff">
<form id="${table.entityPath}SearchForm">
<table>
<tr>
<th>名称:</th>
<td><input name="name" placeholder="搜索条件"/></td>
<td>
<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="${table.entityPath}SearchFun();">查询</a>
<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="${table.entityPath}CleanFun();">清空</a>
</td>
</tr>
</table>
</form>
</div>
<div data-options="region:'center',border:false">
<table id="${table.entityPath}DataGrid" data-options="fit:true,border:false"></table>
</div>
</div>
<div id="${table.entityPath}Toolbar" style="display: none;">
<shiro:hasPermission name="/${table.entityPath}/add">
<a onclick="${table.entityPath}AddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-page-add'">添加</a>
</shiro:hasPermission>
</div>

View File

@ -0,0 +1,89 @@
<template>
<div class="app-container calendar-list-container">
<div class="filter-container">
</div>
<el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit
highlight-current-row style="width: 100%">
#foreach($field in $table.fields)
<template scope="scope">
<el-table-column align="center" label="${field.comment}">
<span>{{scope.row.${field.propertyName}}}</span>
</template>
</el-table-column>
#end
<el-table-column label="操作">
<template scope="scope">
<el-button size="mini" type="danger"
@click="handleDelete(scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
<div v-show="!listLoading" class="pagination-container">
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
:current-page.sync="listQuery.page"
:page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
layout="total, sizes, prev, pager, next, jumper" :total="total">
</el-pagination>
</div>
</div>
</template>
<script>
import { fetchList, delObj } from '@/api/${table.name}'
import waves from '@/directive/waves/index.js' // 水波纹指令
export default {
name: 'table_${table.name}',
directives: {
waves
},
data() {
return {
list: null,
total: null,
listLoading: true,
listQuery: {
page: 1,
limit: 20
},
tableKey: 0
}
},
created() {
this.getList()
},
methods: {
getList() {
this.listLoading = true
fetchList(this.listQuery).then(response => {
this.list = response.data.records
this.total = response.data.total
this.listLoading = false
})
},
handleSizeChange(val) {
this.listQuery.limit = val
this.getList()
},
handleCurrentChange(val) {
this.listQuery.page = val
this.getList()
},
handleDelete(row) {
delObj(row.id)
.then(response => {
this.dialogFormVisible = false
this.getList()
this.$notify({
title: '成功',
message: '删除成功',
type: 'success',
duration: 2000
})
})
}
}
}
</script>

View File

@ -0,0 +1,124 @@
<template>
<div class="app-container calendar-list-container">
<div class="filter-container">
</div>
<el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit
highlight-current-row style="width: 100%">
<el-table-column align="center" label="序号">
<template scope="scope">
<span>{{scope.row.id}}</span>
</template>
</el-table-column>
<el-table-column label="URI" show-overflow-tooltip>
<template scope="scope">
<span>{{ scope.row.requestUri}}</span>
</template>
</el-table-column>
<el-table-column align="center" label="IP">
<template scope="scope">
<span>{{scope.row.remoteAddr}}</span>
</template>
</el-table-column>
<el-table-column align="center" label="METHOD">
<template scope="scope">
<span>{{scope.row.method}}</span>
</template>
</el-table-column>
<el-table-column align="center" label="PARAMS" show-overflow-tooltip>
<template scope="scope">
<span>{{scope.row.params}}</span>
</template>
</el-table-column>
<el-table-column align="center" label="EXCEPTION">
<template scope="scope">
<span>{{scope.row.time}}</span>
</template>
</el-table-column>
<el-table-column align="center" label="创建时间">
<template scope="scope">
<span>{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
</template>
</el-table-column>
<el-table-column label="操作">
<template scope="scope">
<el-button size="mini" type="danger"
@click="handleDelete(scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
<div v-show="!listLoading" class="pagination-container">
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
:current-page.sync="listQuery.page"
:page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
layout="total, sizes, prev, pager, next, jumper" :total="total">
</el-pagination>
</div>
</div>
</template>
<script>
import { fetchList, delObj } from '@/api/log'
import waves from '@/directive/waves/index.js' //
export default {
name: 'table_log',
directives: {
waves
},
data() {
return {
list: null,
total: null,
listLoading: true,
listQuery: {
page: 1,
limit: 20
},
tableKey: 0
}
},
created() {
this.getList()
},
methods: {
getList() {
this.listLoading = true
fetchList(this.listQuery).then(response => {
this.list = response.data.records
this.total = response.data.total
this.listLoading = false
})
},
handleSizeChange(val) {
this.listQuery.limit = val
this.getList()
},
handleCurrentChange(val) {
this.listQuery.page = val
this.getList()
},
handleDelete(row) {
delObj(row.id)
.then(response => {
this.dialogFormVisible = false
this.getList()
this.$notify({
title: '成功',
message: '删除成功',
type: 'success',
duration: 2000
})
})
}
}
}
</script>

View File

@ -16,3 +16,4 @@ spring:
enabled: true
profile: dev
label: master

View File

@ -45,6 +45,11 @@
<artifactId>hutool-all</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
</dependencies>