wangwei 7 yıl önce
ebeveyn
işleme
647f71072c

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

@@ -8,6 +8,7 @@ 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.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -111,6 +112,30 @@ public class PrivilegeController extends ControllerSupport {
 		return ret;
 	}
 
+	@ApiOperation(value = "更新权限")
+	@PutMapping("updatePrivilege")
+	public Privilege updatePrivilege(@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) {
@@ -120,4 +145,15 @@ public class PrivilegeController extends ControllerSupport {
 		}
 		privilegeRepo.delete(id);
 	}
+
+	@ApiOperation(value = "查询权限")
+	@GetMapping("getPrivilege/{id}")
+	public Privilege getPrivilege(@PathVariable Long id) {
+		Privilege privilege = privilegeRepo.findOne(id);
+		if (null == privilege) {
+			throw new StatusException("B-020004", "权限不存在");
+		}
+		return privilege;
+	}
+
 }