角色菜单更新

This commit is contained in:
ludj
2022-11-30 19:18:35 +08:00
parent 4004f6d4df
commit 66aaa6f2b8
7 changed files with 144 additions and 151 deletions

View File

@@ -19,6 +19,8 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.lang.Dict;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@@ -29,6 +31,7 @@ import org.nl.modules.system.service.RoleService;
import org.nl.modules.system.service.dto.RoleDto;
import org.nl.modules.system.service.dto.RoleQueryCriteria;
import org.nl.modules.system.service.dto.RoleSmallDto;
import org.nl.modules.wql.core.bean.WQLObject;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -60,44 +63,29 @@ public class RoleController {
@ApiOperation("获取单个role")
@GetMapping(value = "/{id}")
@SaCheckPermission("roles:list")
public ResponseEntity<Object> query(@PathVariable Long id){
public ResponseEntity<Object> query(@PathVariable Long id) {
return new ResponseEntity<>(roleService.findById(id), HttpStatus.OK);
}
@ApiOperation("导出角色数据")
@GetMapping(value = "/download")
@SaCheckPermission("role:list")
public void download(HttpServletResponse response, RoleQueryCriteria criteria) throws IOException {
roleService.download(roleService.queryAll(criteria), response);
}
@ApiOperation("返回全部的角色")
@GetMapping(value = "/all")
@SaCheckPermission(value = {"roles:list", "user:add", "user:edit"}, mode = SaMode.AND)
public ResponseEntity<Object> query(){
return new ResponseEntity<>(roleService.queryAll(),HttpStatus.OK);
}
@ApiOperation("查询角色")
@GetMapping
@SaCheckPermission("roles:list")
public ResponseEntity<Object> query(Map criteria, Pageable pageable){
return new ResponseEntity<>(roleService.queryAll(criteria,pageable),HttpStatus.OK);
public ResponseEntity<Object> query(Map criteria, Pageable pageable) {
return new ResponseEntity<>(roleService.queryAll(criteria, pageable), HttpStatus.OK);
}
@ApiOperation("获取用户级别")
@GetMapping(value = "/level")
public ResponseEntity<Object> getLevel(){
return new ResponseEntity<>(Dict.create().set("level", getLevels(null)),HttpStatus.OK);
public ResponseEntity<Object> getLevel() {
return new ResponseEntity<>(Dict.create().set("level", getLevels(null)), HttpStatus.OK);
}
@Log("新增角色")
@ApiOperation("新增角色")
@PostMapping
@SaCheckPermission("roles:add")
public ResponseEntity<Object> create(@Validated @RequestBody Role resources){
public ResponseEntity<Object> create(@Validated @RequestBody Role resources) {
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
}
getLevels(resources.getLevel());
// roleService.create(resources);
@@ -108,7 +96,7 @@ public class RoleController {
@ApiOperation("修改角色")
@PutMapping
@SaCheckPermission("roles:edit")
public ResponseEntity<Object> update(@Validated(Role.Update.class) @RequestBody Role resources){
public ResponseEntity<Object> update(@Validated(Role.Update.class) @RequestBody Role resources) {
getLevels(resources.getLevel());
roleService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
@@ -117,11 +105,20 @@ public class RoleController {
@Log("修改角色菜单")
@ApiOperation("修改角色菜单")
@PutMapping(value = "/menu")
@SaCheckPermission("roles:edit")
public ResponseEntity<Object> updateMenu(@RequestBody Role resources){
RoleDto role = roleService.findById(resources.getId());
getLevels(role.getLevel());
roleService.updateMenu(resources,role);
// @SaCheckPermission("roles:edit")
public ResponseEntity<Object> updateMenu(@RequestBody JSONObject form) {
String role_id = form.getString("id");
JSONArray menus = form.getJSONArray("menus");
WQLObject rmTab = WQLObject.getWQLObject("sys_roles_menus");
rmTab.delete("role_id = " + role_id + "");
for (int i = 0; i < menus.size(); i++) {
JSONObject json = menus.getJSONObject(i);
JSONObject param = new JSONObject();
param.put("role_id", role_id);
param.put("menu_id", json.getString("menu_id"));
rmTab.insert(param);
}
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@@ -129,22 +126,17 @@ public class RoleController {
@ApiOperation("删除角色")
@DeleteMapping
@SaCheckPermission("roles:del")
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
for (Long id : ids) {
RoleDto role = roleService.findById(id);
getLevels(role.getLevel());
}
// 验证是否被用户关联
// roleService.verification(ids);
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
roleService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* 获取用户的角色级别
*
* @return /
*/
private int getLevels(Integer level){
private int getLevels(Integer level) {
/* List<Integer> levels = roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(Role::getLevel).collect(Collectors.toList());
int min = Collections.min(levels);
if(level != null){

View File

@@ -36,10 +36,12 @@ import java.util.Set;
public interface RoleService {
/**
* 查询全部数据
* @return /
* 查询数据分页
* @param whereJson 条件
* @param page 分页参数
* @return Map<String,Object>
*/
List<RoleDto> queryAll();
JSONObject queryAll(Map whereJson, Pageable page);
/**
* 根据ID查询
@@ -92,15 +94,6 @@ public interface RoleService {
* @param id /
*/
void untiedMenu(Long id);
/**
* 待条件分页查询
* @param whereJson 条件
* @param page 分页参数
* @return /
*/
Map<String,Object> queryAll(Map whereJson, Pageable page);
/**
* 查询全部
* @param criteria 条件
@@ -108,13 +101,6 @@ public interface RoleService {
*/
List<RoleDto> queryAll(RoleQueryCriteria criteria);
/**
* 导出数据
* @param queryAll 待导出的数据
* @param response /
* @throws IOException /
*/
void download(List<RoleDto> queryAll, HttpServletResponse response) throws IOException;
/**
* 获取用户权限信息

View File

@@ -182,7 +182,6 @@ public class MenuServiceImpl implements MenuService {
if ("0".equals(form.getString("pid"))) {
form.remove("pid");
}
//外链外联菜单
if ("1".equals(form.getString("i_frame"))) {
String http = "http://", https = "https://";
@@ -193,6 +192,42 @@ public class MenuServiceImpl implements MenuService {
menuTab.insert(form);
updateSubCnt(form.getString("pid"));
//更新所属系统system_type字段
updateSystemType(menu_id);
}
/**
* 更新某个菜单属于某个系统
*
* @param menu_id 菜单标识
*/
void updateSystemType(String menu_id) {
String rootMenuId = this.findRootMenuId(menu_id);
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
JSONObject rootMenuObj = menuTab.query("menu_id = '" + rootMenuId + "'").uniqueResult(0);
JSONObject param = new JSONObject();
param.put("system_type", rootMenuObj.getString("title"));
param.put("menu_id", menu_id);
menuTab.update(param);
}
/**
* 查找菜单顶级菜单标识
*
* @param menu_id
* @return
*/
private String findRootMenuId(String menu_id) {
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
JSONObject menuObj = menuTab.query("menu_id = '" + menu_id + "'").uniqueResult(0);
String pid = menuObj.getString("pid");
if (StrUtil.isEmpty(pid)) {
return menu_id;
} else {
return findRootMenuId(pid);
}
}
@Override
@@ -226,6 +261,8 @@ public class MenuServiceImpl implements MenuService {
// 计算父级菜单节点数目
updateSubCnt(oldPid);
updateSubCnt(newPid);
updateSystemType(newMenu.getMenu_id());
// 清理缓存
// delCaches(resources.getId());
}

View File

@@ -17,6 +17,7 @@ package org.nl.modules.system.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
@@ -38,6 +39,7 @@ import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.ResultBean;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
import org.nl.wms.sch.service.dto.RegionDto;
import org.nl.wms.util.IdUtil;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
@@ -69,21 +71,26 @@ public class RoleServiceImpl implements RoleService {
// private final UserCacheClean userCacheClean;
@Override
public List<RoleDto> queryAll() {
Sort sort = Sort.by(Sort.Direction.ASC, "level");
return roleMapper.toDto(roleRepository.findAll(sort));
public JSONObject queryAll(Map whereJson, Pageable page) {
WQLObject wo = WQLObject.getWQLObject("sys_role");
WQLObject rmTab = WQLObject.getWQLObject("sys_roles_menus");
ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "", "update_time desc");
final JSONObject json = rb.pageResult();
JSONArray arr = json.getJSONArray("content");
for (int i = 0; i < arr.size(); i++) {
JSONObject roleObj = arr.getJSONObject(i);
JSONArray menus = rmTab.query("role_id = '" + roleObj.getString("role_id") + "'").getResultJSONArray(0);
roleObj.put("menus", menus);
}
return json;
}
@Override
public List<RoleDto> queryAll(RoleQueryCriteria criteria) {
return roleMapper.toDto(roleRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
return null;
}
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
ResultBean rb = WQLObject.getWQLObject("sys_role").pagequery(WqlUtil.getHttpContext(page), "", "");
return rb.pageResult();
}
@Override
@Cacheable(key = "'id:' + #p0")
@@ -153,11 +160,12 @@ public class RoleServiceImpl implements RoleService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Set<Long> ids) {
WQLObject wo = WQLObject.getWQLObject("sys_role");
WQLObject rmTab = WQLObject.getWQLObject("sys_roles_menus");
for (Long id : ids) {
// 更新相关缓存
delCaches(id, null);
wo.delete("role_id =" + id);
rmTab.delete("role_id =" + id);
}
roleRepository.deleteAllByIdIn(ids);
}
@Override
@@ -179,10 +187,10 @@ public class RoleServiceImpl implements RoleService {
public List<String> getPermissionList(JSONObject userDto) {
List<String> permission = new LinkedList<>();
// 查看是否为管理员
permission.add("admin");
permission.add("admin");
HashMap<String, String> map = new HashMap<>();
map.put("flag", "1");
map.put("user_id",userDto.getString("user_id"));
map.put("user_id", userDto.getString("user_id"));
JSONArray rows = WQL.getWO("SYS_MENU").addParamMap(map).process().getResultJSONArray(0);
for (int i = 0; i < rows.size(); i++) {
JSONObject jsonObject = rows.getJSONObject(i);
@@ -191,20 +199,6 @@ public class RoleServiceImpl implements RoleService {
return permission;
}
@Override
public void download(List<RoleDto> roles, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (RoleDto role : roles) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("角色名称", role.getName());
map.put("角色级别", role.getLevel());
map.put("描述", role.getDescription());
// map.put("创建日期", role.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
@Override
public void verification(Set<Long> ids) {
if (userRepository.countByRoles(ids) > 0) {

View File

@@ -27,29 +27,15 @@
width="650px"
>
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="mini" label-width="80px">
<el-form-item label="子系统" prop="type">
<el-radio-group v-model="form.system_type" size="mini" style="width: 190px">
<el-radio-button label="1">目录</el-radio-button>
<el-radio-button label="2">菜单</el-radio-button>
<el-radio-button label="3">按钮</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="菜单分类" prop="type">
<el-radio-group v-model="form.category" size="mini">
<el-radio-button label="1">LMSPC</el-radio-button>
<el-radio-button label="2">LMS手持</el-radio-button>
<el-radio-button label="3">ACSPC</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="菜单类型" prop="type">
<el-radio-group v-model="form.type" size="mini" style="width: 190px">
<el-radio-button label="0">目录</el-radio-button>
<el-radio-button label="1">菜单</el-radio-button>
<el-radio-button label="2">按钮</el-radio-button>
<el-radio-group v-model="form.type" size="mini">
<el-radio-button label="1">系统</el-radio-button>
<el-radio-button label="2">目录</el-radio-button>
<el-radio-button label="3">菜单</el-radio-button>
<el-radio-button label="4">按钮</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-show="form.type.toString() !== '2'" label="菜单图标" prop="icon">
<el-form-item v-show="form.type.toString() !== '1' && form.type.toString() !== '4' " label="菜单图标" prop="icon">
<el-popover
placement="bottom-start"
width="450"
@@ -69,19 +55,19 @@
</el-input>
</el-popover>
</el-form-item>
<el-form-item v-show="form.type.toString() !== '2'" label="外链菜单" prop="i_frame">
<el-form-item v-show="form.type.toString() !== '2' && form.type.toString() !== '1'" label="外链菜单" prop="i_frame">
<el-radio-group v-model="form.i_frame" size="mini">
<el-radio-button label="1">是</el-radio-button>
<el-radio-button label="0">否</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-show="form.type.toString() === '1'" label="菜单缓存" prop="cache">
<el-form-item v-show="form.type.toString() === '2'" label="菜单缓存" prop="cache">
<el-radio-group v-model="form.cache" size="mini">
<el-radio-button label="1">是</el-radio-button>
<el-radio-button label="0">否</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-show="form.type.toString() !== '2'" label="菜单可见" prop="hidden">
<el-form-item v-show="form.type.toString() !== '2' && form.type.toString() !== '1' " label="菜单可见" prop="hidden">
<el-radio-group v-model="form.hidden" size="mini">
<el-radio-button label="1">是</el-radio-button>
<el-radio-button label="0">否</el-radio-button>
@@ -97,10 +83,10 @@
<el-form-item v-if="form.type.toString() === '2'" label="按钮名称" prop="title">
<el-input v-model="form.title" placeholder="按钮名称" style="width: 190px;" />
</el-form-item>
<el-form-item v-show="form.type.toString() !== '0'" label="权限标识" prop="permission">
<el-form-item v-show="form.type.toString() !== '1' " label="权限标识" prop="permission">
<el-input v-model="form.permission" :disabled="form.i_frame=='1'" placeholder="权限标识" style="width: 190px;" />
</el-form-item>
<el-form-item v-if="form.type.toString() !== '2'" label="路由地址" prop="path">
<el-form-item v-if="form.type.toString() !== '1' && form.type.toString() !== '2'" label="路由地址" prop="path">
<el-input v-model="form.path" placeholder="路由地址" style="width: 190px;" />
</el-form-item>
<el-form-item label="菜单排序" prop="menuSort">
@@ -112,10 +98,10 @@
style="width: 190px;"
/>
</el-form-item>
<el-form-item v-show="!form.i_frame && form.type.toString() === '1'" label="组件名称" prop="componentName">
<el-form-item v-show="!form.i_frame && form.type.toString() === '3' " label="组件名称" prop="componentName">
<el-input v-model="form.componentName" style="width: 190px;" placeholder="匹配组件内Name字段" />
</el-form-item>
<el-form-item v-show="!form.i_frame && form.type.toString() === '1'" label="组件路径" prop="component">
<el-form-item v-show="!form.i_frame && (form.type.toString() === '2' ||form.type.toString() === '3' ) " label="组件路径" prop="component">
<el-input v-model="form.component" style="width: 190px;" placeholder="组件路径" />
</el-form-item>
<el-form-item label="上级类目" prop="pid">
@@ -152,7 +138,6 @@
>
<el-table-column type="selection" width="55" />
<el-table-column show-overflow-tooltip label="菜单标题" width="125px" prop="title" />
<el-table-column show-overflow-tooltip label="父Id" width="125px" prop="pid" />
<el-table-column show-overflow-tooltip label="子系统" width="125px" prop="system_type" />
<el-table-column show-overflow-tooltip label="菜单类别" width="125px" prop="category" />
<el-table-column prop="icon" label="图标" align="center" width="60px">

View File

@@ -13,9 +13,9 @@
class="filter-item"
@keyup.enter.native="crud.toQuery"
/>
<rrOperation/>
<rrOperation />
</div>
<crudOperation :permission="permission"/>
<crudOperation :permission="permission" />
</div>
<!-- 表单渲染 -->
<el-dialog
@@ -28,10 +28,10 @@
>
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="mini" label-width="80px">
<el-form-item label="角色名称" prop="name">
<el-input v-model="form.name" style="width: 380px;"/>
<el-input v-model="form.name" style="width: 380px;" />
</el-form-item>
<el-form-item label="备注" prop="description">
<el-input v-model="form.description" style="width: 380px;" rows="2" type="textarea"/>
<el-input v-model="form.description" style="width: 380px;" rows="2" type="textarea" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
@@ -55,9 +55,9 @@
@selection-change="crud.selectionChangeHandler"
@current-change="handleCurrentChange"
>
<el-table-column type="selection" width="55"/>
<el-table-column prop="name" label="名称" min-width="100" show-overflow-tooltip/>
<el-table-column show-overflow-tooltip prop="description" label="描述"/>
<el-table-column type="selection" width="55" />
<el-table-column prop="name" label="名称" min-width="100" show-overflow-tooltip />
<el-table-column show-overflow-tooltip prop="description" label="描述" />
<el-table-column show-overflow-tooltip width="135px" prop="createTime" label="创建日期">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
@@ -79,7 +79,7 @@
</el-table-column>
</el-table>
<!--分页组件-->
<pagination/>
<pagination />
</el-card>
</el-col>
<!-- 菜单授权 -->
@@ -110,8 +110,8 @@
/>
<el-tree
lazy
ref="menu"
lazy
:data="menus"
:default-checked-keys="menuIds"
:load="getMenuDatas"
@@ -144,7 +144,7 @@ export default {
name: 'Role',
components: { pagination, crudOperation, rrOperation, udOperation, DateRangePicker, crudMenu },
cruds() {
return CRUD({ title: '角色', url: 'api/roles', crudMethod: { ...crudRoles } })
return CRUD({ title: '角色', url: 'api/roles', crudMethod: { ...crudRoles }})
},
mixins: [presenter(), header(), form(defaultForm), crud()],
data() {
@@ -210,18 +210,17 @@ export default {
},
// 触发单选
handleCurrentChange(val) {
console.log('val:', val)
if (val) {
const _this = this
// 清空菜单的选中
this.$refs.menu.setCheckedKeys([])
// 保存当前的角色id
this.currentId = val.role_id
/* // 初始化默认选中的key
this.menuIds = []
val.menus.forEach(function(data) {
_this.menuIds.push(data.id)
})*/
// 初始化默认选中的key
this.menuIds = []
val.menus.forEach(function(data) {
_this.menuIds.push(data.menu_id)
})
this.showButton = true
}
},
@@ -252,8 +251,8 @@ export default {
this.menuLoading = true
const role = { id: this.currentId, menus: [] }
// 得到已选中的 key 值
this.menuIds.forEach(function(id) {
const menu = { id: id }
this.menuIds.forEach(function(menu_id) {
const menu = { menu_id: menu_id }
role.menus.push(menu)
})
crudRoles.editMenu(role).then(() => {

View File

@@ -2,27 +2,27 @@
<div class="app-container">
<el-row :gutter="20">
<!--侧边部门数据-->
<!-- <el-col :xs="9" :sm="6" :md="5" :lg="5" :xl="4">-->
<!-- <div class="head-container">-->
<!-- <el-input-->
<!-- v-model="deptName"-->
<!-- clearable-->
<!-- size="mini"-->
<!-- placeholder="请输入部门名称"-->
<!-- prefix-icon="el-icon-search"-->
<!-- class="filter-item"-->
<!-- @input="getDeptDatas"-->
<!-- />-->
<!-- </div>-->
<!-- <el-tree-->
<!-- :data="deptDatas"-->
<!-- :load="getDeptDatas"-->
<!-- :props="defaultProps"-->
<!-- :expand-on-click-node="false"-->
<!-- lazy-->
<!-- @node-click="handleNodeClick"-->
<!-- />-->
<!-- </el-col>-->
<el-col :xs="9" :sm="6" :md="5" :lg="5" :xl="4">
<div class="head-container">
<el-input
v-model="deptName"
clearable
size="mini"
placeholder="请输入部门名称"
prefix-icon="el-icon-search"
class="filter-item"
@input="getDeptDatas"
/>
</div>
<el-tree
:data="deptDatas"
:load="getDeptDatas"
:props="defaultProps"
:expand-on-click-node="false"
lazy
@node-click="handleNodeClick"
/>
</el-col>
<!--用户数据-->
<el-col :xs="15" :sm="18" :md="19" :lg="19" :xl="20">
<!--工具栏-->