菜单角色更新
This commit is contained in:
@@ -17,24 +17,17 @@ package org.nl.modules.system.rest;
|
|||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
import cn.dev33.satoken.annotation.SaMode;
|
import cn.dev33.satoken.annotation.SaMode;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.map.MapUtil;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.nl.modules.common.exception.BadRequestException;
|
|
||||||
import org.nl.modules.common.utils.PageUtil;
|
|
||||||
import org.nl.modules.common.utils.SecurityUtils;
|
import org.nl.modules.common.utils.SecurityUtils;
|
||||||
import org.nl.modules.logging.annotation.Log;
|
import org.nl.modules.logging.annotation.Log;
|
||||||
import org.nl.modules.system.domain.Menu;
|
import org.nl.modules.system.domain.Menu;
|
||||||
import org.nl.modules.system.service.MenuService;
|
import org.nl.modules.system.service.MenuService;
|
||||||
import org.nl.modules.system.service.dto.MenuDto;
|
import org.nl.modules.system.service.dto.MenuDto;
|
||||||
import org.nl.modules.system.service.dto.MenuQueryCriteria;
|
|
||||||
import org.nl.modules.system.service.mapstruct.MenuMapper;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -60,7 +53,7 @@ public class MenuController {
|
|||||||
@GetMapping(value = "/build")
|
@GetMapping(value = "/build")
|
||||||
@ApiOperation("根据用户获取菜单")
|
@ApiOperation("根据用户获取菜单")
|
||||||
public ResponseEntity<Object> buildMenus() {
|
public ResponseEntity<Object> buildMenus() {
|
||||||
List<MenuDto> menuDtoList = menuService.findByUser(SecurityUtils.getCurrentUserId());
|
List<MenuDto> menuDtoList = menuService.findByUser(String.valueOf(SecurityUtils.getCurrentUserId()));
|
||||||
List<MenuDto> menuDtos = menuService.buildTree(menuDtoList);
|
List<MenuDto> menuDtos = menuService.buildTree(menuDtoList);
|
||||||
return new ResponseEntity<>(menuService.buildMenus(menuDtos),HttpStatus.OK);
|
return new ResponseEntity<>(menuService.buildMenus(menuDtos),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
@@ -68,7 +61,7 @@ public class MenuController {
|
|||||||
@ApiOperation("返回全部的菜单")
|
@ApiOperation("返回全部的菜单")
|
||||||
@GetMapping(value = "/lazy")
|
@GetMapping(value = "/lazy")
|
||||||
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
|
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
|
||||||
public ResponseEntity<Object> query(@RequestParam Long pid) {
|
public ResponseEntity<Object> query(@RequestParam String pid) {
|
||||||
return new ResponseEntity<>(menuService.getMenus(pid), HttpStatus.OK);
|
return new ResponseEntity<>(menuService.getMenus(pid), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,12 +85,12 @@ public class MenuController {
|
|||||||
@ApiOperation("根据菜单ID返回所有子节点ID,包含自身ID")
|
@ApiOperation("根据菜单ID返回所有子节点ID,包含自身ID")
|
||||||
@GetMapping(value = "/child")
|
@GetMapping(value = "/child")
|
||||||
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
|
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
|
||||||
public ResponseEntity<Object> child(@RequestParam Long id) {
|
public ResponseEntity<Object> child(@RequestParam String id) {
|
||||||
Set<MenuDto> menuSet = new HashSet<>();
|
Set<MenuDto> menuSet = new HashSet<>();
|
||||||
List<MenuDto> menuList = menuService.getMenus(id);
|
List<MenuDto> menuList = menuService.getMenus(id);
|
||||||
menuSet.add(menuService.findById(id));
|
menuSet.add(menuService.findById(id));
|
||||||
menuSet = menuService.getChildMenus(menuList, menuSet);
|
menuSet = menuService.getChildMenus(menuList, menuSet);
|
||||||
Set<Long> ids = menuSet.stream().map(MenuDto::getMenu_id).collect(Collectors.toSet());
|
Set<String> ids = menuSet.stream().map(MenuDto::getMenu_id).collect(Collectors.toSet());
|
||||||
return new ResponseEntity<>(ids, HttpStatus.OK);
|
return new ResponseEntity<>(ids, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,10 +106,10 @@ public class MenuController {
|
|||||||
@ApiOperation("查询菜单:根据ID获取同级与上级数据")
|
@ApiOperation("查询菜单:根据ID获取同级与上级数据")
|
||||||
@PostMapping("/superior")
|
@PostMapping("/superior")
|
||||||
@SaCheckPermission("menu:list")
|
@SaCheckPermission("menu:list")
|
||||||
public ResponseEntity<Object> getSuperior(@RequestBody List<Long> ids) {
|
public ResponseEntity<Object> getSuperior(@RequestBody List<String> ids) {
|
||||||
Set<MenuDto> menuDtos = new LinkedHashSet<>();
|
Set<MenuDto> menuDtos = new LinkedHashSet<>();
|
||||||
if (CollectionUtil.isNotEmpty(ids)) {
|
if (CollectionUtil.isNotEmpty(ids)) {
|
||||||
for (Long id : ids) {
|
for (String id : ids) {
|
||||||
MenuDto menuDto = menuService.findById(id);
|
MenuDto menuDto = menuService.findById(id);
|
||||||
menuDtos.addAll(menuService.getSuperior(menuDto, new ArrayList<>()));
|
menuDtos.addAll(menuService.getSuperior(menuDto, new ArrayList<>()));
|
||||||
}
|
}
|
||||||
@@ -147,12 +140,12 @@ public class MenuController {
|
|||||||
@ApiOperation("删除菜单")
|
@ApiOperation("删除菜单")
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@SaCheckPermission("menu:del")
|
@SaCheckPermission("menu:del")
|
||||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> delete(@RequestBody Set<String> ids) {
|
||||||
Set<MenuDto> menuSet = new HashSet<>();
|
Set<MenuDto> menuSet = new HashSet<>();
|
||||||
for (Long id : ids) {
|
for (String id : ids) {
|
||||||
/* List<MenuDto> menuList = menuService.getMenus(id);*/
|
List<MenuDto> menuList = menuService.getMenus(id);
|
||||||
menuSet.add(menuService.findById(id));
|
menuSet.add(menuService.findById(id));
|
||||||
/*menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet);*/
|
menuSet = menuService.getChildMenus(menuList, menuSet);
|
||||||
}
|
}
|
||||||
menuService.delete(menuSet);
|
menuService.delete(menuSet);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
|
|||||||
import cn.dev33.satoken.annotation.SaMode;
|
import cn.dev33.satoken.annotation.SaMode;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -62,7 +60,7 @@ public class RoleController {
|
|||||||
@ApiOperation("获取单个role")
|
@ApiOperation("获取单个role")
|
||||||
@GetMapping(value = "/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
@SaCheckPermission("roles:list")
|
@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);
|
return new ResponseEntity<>(roleService.findById(id), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,30 +74,33 @@ public class RoleController {
|
|||||||
@ApiOperation("返回全部的角色")
|
@ApiOperation("返回全部的角色")
|
||||||
@GetMapping(value = "/all")
|
@GetMapping(value = "/all")
|
||||||
@SaCheckPermission(value = {"roles:list", "user:add", "user:edit"}, mode = SaMode.AND)
|
@SaCheckPermission(value = {"roles:list", "user:add", "user:edit"}, mode = SaMode.AND)
|
||||||
public ResponseEntity<Object> query() {
|
public ResponseEntity<Object> query(){
|
||||||
return new ResponseEntity<>(roleService.queryAll(), HttpStatus.OK);
|
return new ResponseEntity<>(roleService.queryAll(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("查询角色")
|
@ApiOperation("查询角色")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@SaCheckPermission("roles:list")
|
@SaCheckPermission("roles:list")
|
||||||
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
|
public ResponseEntity<Object> query(Map criteria, Pageable pageable){
|
||||||
JSONObject param = JSONObject.parseObject(JSON.toJSONString(whereJson));
|
return new ResponseEntity<>(roleService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||||
return new ResponseEntity<>(roleService.queryAll(param, page), HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("获取用户级别")
|
@ApiOperation("获取用户级别")
|
||||||
@GetMapping(value = "/level")
|
@GetMapping(value = "/level")
|
||||||
public ResponseEntity<Object> getLevel() {
|
public ResponseEntity<Object> getLevel(){
|
||||||
return new ResponseEntity<>(2, HttpStatus.OK);
|
return new ResponseEntity<>(Dict.create().set("level", getLevels(null)),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Log("新增角色")
|
@Log("新增角色")
|
||||||
@ApiOperation("新增角色")
|
@ApiOperation("新增角色")
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@SaCheckPermission("roles:add")
|
@SaCheckPermission("roles:add")
|
||||||
public ResponseEntity<Object> create(@Validated @RequestBody JSONObject form) {
|
public ResponseEntity<Object> create(@Validated @RequestBody Role resources){
|
||||||
roleService.create(form);
|
if (resources.getId() != null) {
|
||||||
|
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
|
||||||
|
}
|
||||||
|
getLevels(resources.getLevel());
|
||||||
|
// roleService.create(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +108,7 @@ public class RoleController {
|
|||||||
@ApiOperation("修改角色")
|
@ApiOperation("修改角色")
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@SaCheckPermission("roles:edit")
|
@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());
|
getLevels(resources.getLevel());
|
||||||
roleService.update(resources);
|
roleService.update(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
@@ -117,10 +118,10 @@ public class RoleController {
|
|||||||
@ApiOperation("修改角色菜单")
|
@ApiOperation("修改角色菜单")
|
||||||
@PutMapping(value = "/menu")
|
@PutMapping(value = "/menu")
|
||||||
@SaCheckPermission("roles:edit")
|
@SaCheckPermission("roles:edit")
|
||||||
public ResponseEntity<Object> updateMenu(@RequestBody Role resources) {
|
public ResponseEntity<Object> updateMenu(@RequestBody Role resources){
|
||||||
RoleDto role = roleService.findById(resources.getId());
|
RoleDto role = roleService.findById(resources.getId());
|
||||||
getLevels(role.getLevel());
|
getLevels(role.getLevel());
|
||||||
roleService.updateMenu(resources, role);
|
roleService.updateMenu(resources,role);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,27 +129,26 @@ public class RoleController {
|
|||||||
@ApiOperation("删除角色")
|
@ApiOperation("删除角色")
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@SaCheckPermission("roles:del")
|
@SaCheckPermission("roles:del")
|
||||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
RoleDto role = roleService.findById(id);
|
RoleDto role = roleService.findById(id);
|
||||||
getLevels(role.getLevel());
|
getLevels(role.getLevel());
|
||||||
}
|
}
|
||||||
// 验证是否被用户关联
|
// 验证是否被用户关联
|
||||||
roleService.verification(ids);
|
// roleService.verification(ids);
|
||||||
roleService.delete(ids);
|
roleService.delete(ids);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户的角色级别
|
* 获取用户的角色级别
|
||||||
*
|
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
private int getLevels(Integer level) {
|
private int getLevels(Integer level){
|
||||||
List<Integer> levels = roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());
|
List<Integer> levels = roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());
|
||||||
int min = Collections.min(levels);
|
int min = Collections.min(levels);
|
||||||
if (level != null) {
|
if(level != null){
|
||||||
if (level < min) {
|
if(level < min){
|
||||||
throw new BadRequestException("权限不足,你的角色级别:" + min + ",低于操作的角色级别:" + level);
|
throw new BadRequestException("权限不足,你的角色级别:" + min + ",低于操作的角色级别:" + level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public interface MenuService {
|
|||||||
* @param id /
|
* @param id /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
MenuDto findById(long id);
|
MenuDto findById(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建
|
* 创建
|
||||||
@@ -126,7 +126,7 @@ public interface MenuService {
|
|||||||
* @param pid /
|
* @param pid /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<MenuDto> getMenus(Long pid);
|
List<MenuDto> getMenus(String pid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID获取同级与上级数据
|
* 根据ID获取同级与上级数据
|
||||||
@@ -143,5 +143,5 @@ public interface MenuService {
|
|||||||
* @param currentUserId /
|
* @param currentUserId /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<MenuDto> findByUser(Long currentUserId);
|
List<MenuDto> findByUser(String currentUserId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public interface RoleService {
|
|||||||
* 解绑菜单
|
* 解绑菜单
|
||||||
* @param id /
|
* @param id /
|
||||||
*/
|
*/
|
||||||
void untiedMenu(Long id);
|
void untiedMenu(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 待条件分页查询
|
* 待条件分页查询
|
||||||
@@ -134,7 +134,7 @@ public interface RoleService {
|
|||||||
* 验证是否被用户关联
|
* 验证是否被用户关联
|
||||||
* @param ids /
|
* @param ids /
|
||||||
*/
|
*/
|
||||||
void verification(Set<Long> ids);
|
void verification(Set<String> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据菜单Id查询
|
* 根据菜单Id查询
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import java.util.Objects;
|
|||||||
@Setter
|
@Setter
|
||||||
public class MenuDto extends BaseDTO implements Serializable {
|
public class MenuDto extends BaseDTO implements Serializable {
|
||||||
|
|
||||||
private Long menu_id;
|
private String menu_id;
|
||||||
|
|
||||||
private List<MenuDto> children;
|
private List<MenuDto> children;
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public class MenuDto extends BaseDTO implements Serializable {
|
|||||||
|
|
||||||
private String component;
|
private String component;
|
||||||
|
|
||||||
private Long pid;
|
private String pid;
|
||||||
|
|
||||||
private Integer sub_count;
|
private Integer sub_count;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.nl.modules.common.exception.BadRequestException;
|
||||||
import org.nl.modules.common.utils.*;
|
import org.nl.modules.common.utils.*;
|
||||||
import org.nl.modules.system.domain.Menu;
|
import org.nl.modules.system.domain.Menu;
|
||||||
import org.nl.modules.system.domain.Role;
|
import org.nl.modules.system.domain.Role;
|
||||||
@@ -48,8 +49,8 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
JSONArray res = new JSONArray();
|
JSONArray res = new JSONArray();
|
||||||
for (int i = 0; i < content.size(); i++) {
|
for (int i = 0; i < content.size(); i++) {
|
||||||
JSONObject obj = content.getJSONObject(i);
|
JSONObject obj = content.getJSONObject(i);
|
||||||
obj.put("menu_id", obj.getLong("menu_id"));
|
obj.put("menu_id", obj.getString("menu_id"));
|
||||||
obj.put("pid", obj.getLong("pid"));
|
obj.put("pid", obj.getString("pid"));
|
||||||
|
|
||||||
//构建前端需要的数据结构树
|
//构建前端需要的数据结构树
|
||||||
Integer sub_count = obj.getInteger("sub_count");
|
Integer sub_count = obj.getInteger("sub_count");
|
||||||
@@ -108,14 +109,14 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
@Override
|
@Override
|
||||||
public MenuDto menuJsonToMenuDto(JSONObject json) {
|
public MenuDto menuJsonToMenuDto(JSONObject json) {
|
||||||
MenuDto menuDto = new MenuDto();
|
MenuDto menuDto = new MenuDto();
|
||||||
menuDto.setMenu_id(json.getLong("menu_id"));
|
menuDto.setMenu_id(json.getString("menu_id"));
|
||||||
menuDto.setType(json.getInteger("type"));
|
menuDto.setType(json.getInteger("type"));
|
||||||
menuDto.setPermission(json.getString("permission"));
|
menuDto.setPermission(json.getString("permission"));
|
||||||
menuDto.setTitle(json.getString("title"));
|
menuDto.setTitle(json.getString("title"));
|
||||||
menuDto.setMenu_sort(json.getInteger("menu_sort"));
|
menuDto.setMenu_sort(json.getInteger("menu_sort"));
|
||||||
menuDto.setPath(json.getString("path"));
|
menuDto.setPath(json.getString("path"));
|
||||||
menuDto.setComponent(json.getString("component"));
|
menuDto.setComponent(json.getString("component"));
|
||||||
menuDto.setPid(json.getLong("pid"));
|
menuDto.setPid(json.getString("pid"));
|
||||||
menuDto.setSub_count(json.getInteger("sub_count"));
|
menuDto.setSub_count(json.getInteger("sub_count"));
|
||||||
menuDto.setI_frame("1".equals(json.getString("i_frame")));
|
menuDto.setI_frame("1".equals(json.getString("i_frame")));
|
||||||
menuDto.setCache("1".equals(json.getString("cache")));
|
menuDto.setCache("1".equals(json.getString("cache")));
|
||||||
@@ -138,7 +139,7 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
// @Cacheable(key = "'id:' + #p0")
|
// @Cacheable(key = "'id:' + #p0")
|
||||||
public MenuDto findById(long id) {
|
public MenuDto findById(String id) {
|
||||||
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||||
JSONObject json = menuTab.query("menu_id = '" + id + "'").uniqueResult(0);
|
JSONObject json = menuTab.query("menu_id = '" + id + "'").uniqueResult(0);
|
||||||
return this.menuJsonToMenuDto(json);
|
return this.menuJsonToMenuDto(json);
|
||||||
@@ -152,48 +153,12 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
// @Cacheable(key = "'user:' + #p0")
|
// @Cacheable(key = "'user:' + #p0")
|
||||||
public List<MenuDto> findByUser(Long currentUserId) {
|
public List<MenuDto> findByUser(String currentUserId) {
|
||||||
JSONArray arr = WQL.getWO("QSYS_MENU01").addParam("flag", "4").addParam("user_id", String.valueOf(currentUserId)).process().getResultJSONArray(0);
|
JSONArray arr = WQL.getWO("QSYS_MENU01").addParam("flag", "4").addParam("user_id", String.valueOf(currentUserId)).process().getResultJSONArray(0);
|
||||||
List<MenuDto> list = new ArrayList<>();
|
List<MenuDto> list = new ArrayList<>();
|
||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
JSONObject json = arr.getJSONObject(i);
|
JSONObject json = arr.getJSONObject(i);
|
||||||
|
list.add(this.menuJsonToMenuDto(json));
|
||||||
MenuDto dto = new MenuDto();
|
|
||||||
dto.setMenu_id(json.getLong("menu_id"));
|
|
||||||
dto.setType(json.getInteger("type"));
|
|
||||||
dto.setPermission(json.getString("permission"));
|
|
||||||
dto.setTitle(json.getString("title"));
|
|
||||||
dto.setPath(json.getString("path"));
|
|
||||||
dto.setComponent_name(json.getString("name"));
|
|
||||||
dto.setComponent(json.getString("component"));
|
|
||||||
dto.setIcon(json.getString("icon"));
|
|
||||||
dto.setMenu_sort(json.getInteger("menu_sort"));
|
|
||||||
dto.setSub_count(json.getInteger("sub_count"));
|
|
||||||
dto.setPid(json.getLong("pid"));
|
|
||||||
|
|
||||||
|
|
||||||
String cache = json.getString("cache");
|
|
||||||
String iFrame = json.getString("i_frame");
|
|
||||||
String hidden = json.getString("hidden");
|
|
||||||
if (StrUtil.equals(cache, "1")) {
|
|
||||||
dto.setCache(true);
|
|
||||||
} else {
|
|
||||||
dto.setCache(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StrUtil.equals(iFrame, "1")) {
|
|
||||||
dto.setI_frame(true);
|
|
||||||
} else {
|
|
||||||
dto.setI_frame(false);
|
|
||||||
}
|
|
||||||
if (StrUtil.equals(hidden, "1")) {
|
|
||||||
dto.setHidden(true);
|
|
||||||
} else {
|
|
||||||
dto.setHidden(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
list.add(dto);
|
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -210,10 +175,22 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
form.put("update_id", SecurityUtils.getCurrentUserId());
|
form.put("update_id", SecurityUtils.getCurrentUserId());
|
||||||
form.put("update_name", SecurityUtils.getCurrentNickName());
|
form.put("update_name", SecurityUtils.getCurrentNickName());
|
||||||
form.put("update_time", DateUtil.now());
|
form.put("update_time", DateUtil.now());
|
||||||
|
|
||||||
|
//根节点数据库存为null
|
||||||
|
if ("0".equals(form.getString("pid"))){
|
||||||
|
form.remove("pid");
|
||||||
|
}
|
||||||
|
|
||||||
|
//外链外联菜单
|
||||||
|
if("1".equals(form.getString("i_frame"))){
|
||||||
|
String http = "http://", https = "https://";
|
||||||
|
if (!(form.getString("path").toLowerCase().startsWith(http)||form.getString("path").toLowerCase().startsWith(https))) {
|
||||||
|
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
menuTab.insert(form);
|
menuTab.insert(form);
|
||||||
//TODO 更新子节点数量
|
updateSubCnt(menu_id);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -249,12 +226,12 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MenuDto> getMenus(Long pid) {
|
public List<MenuDto> getMenus(String pid) {
|
||||||
// 菜单表【sys_menu】
|
// 菜单表【sys_menu】
|
||||||
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||||
JSONArray menus;
|
JSONArray menus;
|
||||||
if (pid != null && !pid.equals(0L)) {
|
if (pid != null && !pid.equals(0L)) {
|
||||||
menus = menuTab.query("pid = '" + pid + "'").getResultJSONArray(0);
|
menus = menuTab.query("menu_id = '" + pid + "'").getResultJSONArray(0);
|
||||||
} else {
|
} else {
|
||||||
menus = menuTab.query("(pid =0 or pid is null)").getResultJSONArray(0);
|
menus = menuTab.query("(pid =0 or pid is null)").getResultJSONArray(0);
|
||||||
}
|
}
|
||||||
@@ -280,7 +257,7 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
return menus;
|
return menus;
|
||||||
}
|
}
|
||||||
//pid 不为null
|
//pid 不为null
|
||||||
JSONArray arr = menuTab.query("pid = '"+menuDto.getPid()+"'").getResultJSONArray(0);
|
JSONArray arr = menuTab.query("pid = '" + menuDto.getPid() + "'").getResultJSONArray(0);
|
||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
JSONObject json = arr.getJSONObject(i);
|
JSONObject json = arr.getJSONObject(i);
|
||||||
menus.add(this.menuJsonToMenuDto(json));
|
menus.add(this.menuJsonToMenuDto(json));
|
||||||
@@ -291,7 +268,7 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
@Override
|
@Override
|
||||||
public List<MenuDto> buildTree(List<MenuDto> menuDtos) {
|
public List<MenuDto> buildTree(List<MenuDto> menuDtos) {
|
||||||
List<MenuDto> trees = new ArrayList<>();
|
List<MenuDto> trees = new ArrayList<>();
|
||||||
Set<Long> ids = new HashSet<>();
|
Set<String> ids = new HashSet<>();
|
||||||
for (MenuDto menuDTO : menuDtos) {
|
for (MenuDto menuDTO : menuDtos) {
|
||||||
if (menuDTO.getPid() == null) {
|
if (menuDTO.getPid() == null) {
|
||||||
trees.add(menuDTO);
|
trees.add(menuDTO);
|
||||||
@@ -365,7 +342,7 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSubCnt(Long menuId) {
|
private void updateSubCnt(String menuId) {
|
||||||
if (menuId != null) {
|
if (menuId != null) {
|
||||||
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||||
JSONArray arr = menuTab.query("pid = '" + menuId + "'").getResultJSONArray(0);
|
JSONArray arr = menuTab.query("pid = '" + menuId + "'").getResultJSONArray(0);
|
||||||
@@ -380,14 +357,14 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
*
|
*
|
||||||
* @param id 菜单ID
|
* @param id 菜单ID
|
||||||
*/
|
*/
|
||||||
public void delCaches(Long id) {
|
public void delCaches(String id) {
|
||||||
List<User> users = userRepository.findByMenuId(id);
|
/* List<User> users = userRepository.findByMenuId(id);
|
||||||
redisUtils.del("menu::id:" + id);
|
redisUtils.del("menu::id:" + id);
|
||||||
redisUtils.delByKeys("menu::user:", users.stream().map(User::getId).collect(Collectors.toSet()));
|
redisUtils.delByKeys("menu::user:", users.stream().map(User::getId).collect(Collectors.toSet()));
|
||||||
// 清除 Role 缓存
|
// 清除 Role 缓存
|
||||||
List<Role> roles = roleService.findInMenuId(new ArrayList<Long>() {{
|
List<Role> roles = roleService.findInMenuId(new ArrayList<String>() {{
|
||||||
add(id);
|
add(id);
|
||||||
}});
|
}});
|
||||||
redisUtils.delByKeys("role::id:", roles.stream().map(Role::getId).collect(Collectors.toSet()));
|
redisUtils.delByKeys("role::id:", roles.stream().map(Role::getId).collect(Collectors.toSet()));*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,11 +141,16 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public void untiedMenu(String id) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void untiedMenu(Long menuId) {
|
public void untiedMenu(Long menuId) {
|
||||||
// 更新菜单
|
// 更新菜单
|
||||||
roleRepository.untiedMenu(menuId);
|
roleRepository.untiedMenu(menuId);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@@ -203,10 +208,10 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void verification(Set<Long> ids) {
|
public void verification(Set<String> ids) {
|
||||||
if (userRepository.countByRoles(ids) > 0) {
|
/*if (userRepository.countByRoles(ids) > 0) {
|
||||||
throw new BadRequestException("所选角色存在用户关联,请解除关联再试!");
|
throw new BadRequestException("所选角色存在用户关联,请解除关联再试!");
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -141,6 +141,7 @@
|
|||||||
v-loading="crud.loading"
|
v-loading="crud.loading"
|
||||||
lazy
|
lazy
|
||||||
:load="getMenus"
|
:load="getMenus"
|
||||||
|
:auto-load-root-options="false"
|
||||||
:data="crud.data"
|
:data="crud.data"
|
||||||
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
||||||
row-key="menu_id"
|
row-key="menu_id"
|
||||||
@@ -151,6 +152,7 @@
|
|||||||
>
|
>
|
||||||
<el-table-column type="selection" width="55" />
|
<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="菜单标题" 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="system_type" />
|
||||||
<el-table-column show-overflow-tooltip label="菜单类别" width="125px" prop="category" />
|
<el-table-column show-overflow-tooltip label="菜单类别" width="125px" prop="category" />
|
||||||
<el-table-column prop="icon" label="图标" align="center" width="60px">
|
<el-table-column prop="icon" label="图标" align="center" width="60px">
|
||||||
@@ -242,7 +244,7 @@ export default {
|
|||||||
name: 'Menu',
|
name: 'Menu',
|
||||||
components: { Treeselect, IconSelect, crudOperation, rrOperation, udOperation, DateRangePicker },
|
components: { Treeselect, IconSelect, crudOperation, rrOperation, udOperation, DateRangePicker },
|
||||||
cruds() {
|
cruds() {
|
||||||
return CRUD({ title: '菜单', url: 'api/menus', crudMethod: { ...crudMenu }})
|
return CRUD({ title: '菜单', idField: 'menu_id', url: 'api/menus', crudMethod: { ...crudMenu }})
|
||||||
},
|
},
|
||||||
mixins: [presenter(), header(), form(defaultForm), crud()],
|
mixins: [presenter(), header(), form(defaultForm), crud()],
|
||||||
data() {
|
data() {
|
||||||
@@ -274,12 +276,12 @@ export default {
|
|||||||
// 新增与编辑前做的操作
|
// 新增与编辑前做的操作
|
||||||
[CRUD.HOOK.afterToCU](crud, form) {
|
[CRUD.HOOK.afterToCU](crud, form) {
|
||||||
this.menus = []
|
this.menus = []
|
||||||
if (form.menu_id) {
|
if (form.menu_id) { // 修改
|
||||||
if (form.pid === null) {
|
if (form.pid === null) { // 一级菜单,一级的父级菜单的pid为0.
|
||||||
form.pid = 0
|
form.pid = 0
|
||||||
}
|
}
|
||||||
this.getSupDepts(form.menu_id)
|
this.getSupDepts(form.menu_id)
|
||||||
} else {
|
} else { // 新增
|
||||||
this.menus.push({ menu_id: 0, title: '顶级类目', children: null })
|
this.menus.push({ menu_id: 0, title: '顶级类目', children: null })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user