merge
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package com.xwbing.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xwbing.annotation.LogInfo;
|
||||
import com.xwbing.constant.CommonConstant;
|
||||
import com.xwbing.constant.CommonEnum;
|
||||
import com.xwbing.entity.SysAuthority;
|
||||
import com.xwbing.entity.vo.SysAuthVo;
|
||||
import com.xwbing.service.SysAuthorityService;
|
||||
import com.xwbing.util.JSONObjResult;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/11/15 10:36
|
||||
* 作者: xiangwb
|
||||
* 说明: 权限控制层
|
||||
*/
|
||||
@Api(tags = "authorityApi", description = "权限相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/authority/")
|
||||
public class SysAuthorityControl {
|
||||
@Resource
|
||||
private SysAuthorityService sysAuthorityService;
|
||||
|
||||
@LogInfo("添加权限")
|
||||
@PostMapping("save")
|
||||
public JSONObject save(@RequestBody SysAuthority sysAuthority) {
|
||||
RestMessage save = sysAuthorityService.save(sysAuthority);
|
||||
return JSONObjResult.toJSONObj(save);
|
||||
}
|
||||
|
||||
@LogInfo("删除权限")
|
||||
@GetMapping("removeById")
|
||||
public JSONObject removeById(@RequestParam String id) {
|
||||
if (StringUtils.isEmpty(id))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
RestMessage result = sysAuthorityService.removeById(id);
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
|
||||
@LogInfo("修改权限")
|
||||
@PostMapping("update")
|
||||
public JSONObject update(@RequestBody SysAuthority sysAuthority) {
|
||||
if (StringUtils.isEmpty(sysAuthority.getId()))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
String enable = sysAuthority.getEnable();
|
||||
// 如果禁用,查询是否有子节点,如果有,子节点也要被禁用
|
||||
if (CommonConstant.ISNOTENABLE.equals(enable)) {
|
||||
// 子节点的权限都禁用
|
||||
if (!sysAuthorityService.disableChildrenByParentId(sysAuthority.getId())) {
|
||||
return JSONObjResult.toJSONObj("禁用子节点权限失败");
|
||||
}
|
||||
} else {
|
||||
// 如果是启用看父节点是否被禁用,一级的不需要判断
|
||||
if (!CommonConstant.ROOT.equals(sysAuthority.getParentId())) {
|
||||
SysAuthority parent = sysAuthorityService.getById(sysAuthority.getParentId());
|
||||
if (parent != null && CommonEnum.YesOrNoEnum.NO.getCode().equals(parent.getEnable()))
|
||||
return JSONObjResult.toJSONObj("父节点已被禁用,请先启用父节点");
|
||||
}
|
||||
}
|
||||
RestMessage result = sysAuthorityService.update(sysAuthority);
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
|
||||
@LogInfo("根据父节点查询子节点(非递归)")
|
||||
@PostMapping("listByParentId")
|
||||
public JSONObject listByParentId(String parentId) {
|
||||
if (StringUtils.isEmpty(parentId))
|
||||
parentId = CommonConstant.ROOT;
|
||||
if (!CommonConstant.ROOT.equals(parentId) && sysAuthorityService.getById(parentId) == null)
|
||||
return JSONObjResult.toJSONObj("父节点不存在");
|
||||
List<SysAuthority> queryByParentId = sysAuthorityService.listByParentEnable(parentId, null);
|
||||
return JSONObjResult.toJSONObj(queryByParentId, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("根据是否启用查询所有权限")
|
||||
@PostMapping("listAuthorityByEnable")
|
||||
public JSONObject listAuthorityByEnable(@RequestParam String enable) {
|
||||
if (StringUtils.isEmpty(enable))
|
||||
return JSONObjResult.toJSONObj("是否启用不能为空");
|
||||
List<SysAuthority> authoritys = sysAuthorityService.listByEnable(enable);
|
||||
return JSONObjResult.toJSONObj(authoritys, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("递归查询所有权限")
|
||||
@PostMapping("queryTree")
|
||||
public JSONObject queryTree(String enable) {
|
||||
List<SysAuthVo> authoritys = sysAuthorityService.queryAllChildren(CommonConstant.ROOT, enable);
|
||||
return JSONObjResult.toJSONObj(authoritys, true, "");
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,8 @@ public class SysRoleControl {
|
||||
@LogInfo("删除角色")
|
||||
@GetMapping("removeById")
|
||||
public JSONObject removeById(@RequestParam String id) {
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
if (StringUtils.isEmpty(id))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
}
|
||||
RestMessage result = sysRoleService.removeById(id);
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
@@ -55,9 +54,8 @@ public class SysRoleControl {
|
||||
@LogInfo("修改角色")
|
||||
@PostMapping("update")
|
||||
public JSONObject update(@RequestBody SysRole sysRole) {
|
||||
if (StringUtils.isEmpty(sysRole.getId())) {
|
||||
if (StringUtils.isEmpty(sysRole.getId()))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
}
|
||||
RestMessage result = sysRoleService.update(sysRole);
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
@@ -65,31 +63,27 @@ public class SysRoleControl {
|
||||
@LogInfo("获取角色详情")
|
||||
@GetMapping("getById")
|
||||
public JSONObject getById(@RequestParam String id) {
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
if (StringUtils.isEmpty(id))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
}
|
||||
SysRole sysRole = sysRoleService.getById(id);
|
||||
if (sysRole == null) {
|
||||
if (sysRole == null)
|
||||
return JSONObjResult.toJSONObj("该角色不存在");
|
||||
}
|
||||
return JSONObjResult.toJSONObj(sysRole, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("根据角色主键查找权限")
|
||||
@PostMapping("listAuthorityByRoleId")
|
||||
public JSONObject listAuthorityByRoleId(@RequestParam String roleId, String enable) {
|
||||
if (StringUtils.isEmpty(roleId)) {
|
||||
if (StringUtils.isEmpty(roleId))
|
||||
return JSONObjResult.toJSONObj("角色主键不能为空");
|
||||
}
|
||||
SysRole sysRole = sysRoleService.getById(roleId);
|
||||
if (sysRole == null) {
|
||||
if (sysRole == null)
|
||||
return JSONObjResult.toJSONObj("该角色不存在");
|
||||
}
|
||||
List<SysAuthority> authoritys = sysAuthorityService.listByRoleIdEnable(roleId, enable);
|
||||
return JSONObjResult.toJSONObj(authoritys, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("保存角色 权限主键")
|
||||
@LogInfo("保存角色权限")
|
||||
@PostMapping("saveAuthoritys")
|
||||
public JSONObject saveAuthoritys(@RequestParam String authorityIds, @RequestParam String roleId) {
|
||||
if (StringUtils.isEmpty(authorityIds))
|
||||
@@ -97,9 +91,8 @@ public class SysRoleControl {
|
||||
if (StringUtils.isEmpty(roleId))
|
||||
return JSONObjResult.toJSONObj("角色主键不能为空");
|
||||
SysRole sysRole = sysRoleService.getById(roleId);
|
||||
if (sysRole == null) {
|
||||
if (sysRole == null)
|
||||
return JSONObjResult.toJSONObj("该角色不存在");
|
||||
}
|
||||
String ids[] = authorityIds.split(",");
|
||||
List<SysRoleAuthority> list = new ArrayList<>();
|
||||
for (String id : ids) {
|
||||
|
||||
Reference in New Issue
Block a user