wangwei 7 роки тому
батько
коміт
c22449674c

+ 38 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/PrivilegeController.java

@@ -4,13 +4,17 @@ import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
 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.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.RestController;
 
 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.TreeUtil;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
@@ -82,4 +86,38 @@ public class PrivilegeController extends ControllerSupport {
 
 		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);
+	}
 }