|
@@ -4,13 +4,17 @@ import java.util.List;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.web.helpers.tree.EleTreeNode;
|
|
import cn.com.qmth.examcloud.commons.web.helpers.tree.EleTreeNode;
|
|
import cn.com.qmth.examcloud.commons.web.helpers.tree.TreeUtil;
|
|
import cn.com.qmth.examcloud.commons.web.helpers.tree.TreeUtil;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
@@ -82,4 +86,38 @@ public class PrivilegeController extends ControllerSupport {
|
|
|
|
|
|
return rootNode;
|
|
return rootNode;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "增加权限")
|
|
|
|
+ @PostMapping("addPrivilege")
|
|
|
|
+ public Privilege addPrivilege(@RequestBody Privilege privilege) {
|
|
|
|
+
|
|
|
|
+ PrivilegeGroup group = privilegeGroupRepo.findOne(privilege.getGroupId());
|
|
|
|
+ if (null == group) {
|
|
|
|
+ throw new StatusException("B-020001", "权限组不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (null != privilege.getParentId()) {
|
|
|
|
+ Privilege parentPrivilege = privilegeRepo.findOne(privilege.getParentId());
|
|
|
|
+ if (null == parentPrivilege) {
|
|
|
|
+ throw new StatusException("B-020002", "父权限不存在");
|
|
|
|
+ }
|
|
|
|
+ if (parentPrivilege.getGroupId().equals(privilege.getGroupId())) {
|
|
|
|
+ throw new StatusException("B-020003", "权限组错误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Privilege ret = privilegeRepo.save(privilege);
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "删除权限")
|
|
|
|
+ @DeleteMapping("deletePrivilege/{id}")
|
|
|
|
+ public void deletePrivilege(@PathVariable Long id) {
|
|
|
|
+ Privilege privilege = privilegeRepo.findOne(id);
|
|
|
|
+ if (null == privilege) {
|
|
|
|
+ throw new StatusException("B-020004", "权限不存在");
|
|
|
|
+ }
|
|
|
|
+ privilegeRepo.delete(id);
|
|
|
|
+ }
|
|
}
|
|
}
|