wangwei 6 年 前
コミット
6bbfcf0609

+ 45 - 7
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/OrgController.java

@@ -442,8 +442,24 @@ public class OrgController extends ControllerSupport {
 			throw new StatusException("B-140001", "非法访问");
 		}
 
+		Long id = domain.getId();
+		if (null == id) {
+			throw new StatusException("B-140001", "id is null");
+		}
+
+		OrgEntity orgEntity = orgRepo.findOne(id);
+		if (null == orgEntity) {
+			throw new StatusException("B-140002", "orgEntity is null");
+		}
+
+		validateRootOrgIsolation(orgEntity.getRootId());
+
 		OrgInfo info = new OrgInfo();
-		info.setCode(domain.getCode());
+		
+		info.setCode(orgEntity.getCode());
+		info.setParentId(orgEntity.getParentId());
+		info.setRootId(orgEntity.getRootId());
+		
 		info.setName(domain.getName());
 		info.setContacts(domain.getContacts());
 		info.setTelephone(domain.getTelephone());
@@ -473,19 +489,30 @@ public class OrgController extends ControllerSupport {
 		trim(domain, true);
 
 		User accessUser = getAccessUser();
+		Long rootId = domain.getRootId();
+		if (null == rootId) {
+			throw new StatusException("B-140001", "rootId is null");
+		}
+
+		validateRootOrgIsolation(rootId);
 
 		OrgEntity subOrg = orgRepo.findByRootIdAndCode(accessUser.getRootOrgId(), domain.getCode());
 		if (null != subOrg) {
 			throw new StatusException("B-140001", "机构代码已存在");
 		}
 
+		Long parentId = domain.getParentId();
+		if (null == parentId) {
+			parentId = rootId;
+		}
+
 		OrgInfo info = new OrgInfo();
 		info.setCode(domain.getCode());
 		info.setName(domain.getName());
 		info.setContacts(domain.getContacts());
 		info.setTelephone(domain.getTelephone());
-		info.setParentId(accessUser.getRootOrgId());
-		info.setRootId(accessUser.getRootOrgId());
+		info.setParentId(parentId);
+		info.setRootId(rootId);
 		info.setRemark(domain.getRemark());
 
 		Map<String, String> properties = domain.getProperties();
@@ -510,15 +537,26 @@ public class OrgController extends ControllerSupport {
 	public OrgEntity updateSubOrg(@RequestBody OrgDomain domain) {
 		trim(domain, true);
 
-		User accessUser = getAccessUser();
+		Long id = domain.getId();
+		if (null == id) {
+			throw new StatusException("B-140001", "id is null");
+		}
+
+		OrgEntity orgEntity = orgRepo.findOne(id);
+		if (null == orgEntity) {
+			throw new StatusException("B-140002", "orgEntity is null");
+		}
+
+		validateRootOrgIsolation(orgEntity.getRootId());
 
 		OrgInfo info = new OrgInfo();
-		info.setCode(domain.getCode());
+		info.setCode(orgEntity.getCode());
+		info.setParentId(orgEntity.getParentId());
+		info.setRootId(orgEntity.getRootId());
+
 		info.setName(domain.getName());
 		info.setContacts(domain.getContacts());
 		info.setTelephone(domain.getTelephone());
-		info.setParentId(accessUser.getRootOrgId());
-		info.setRootId(accessUser.getRootOrgId());
 		info.setRemark(domain.getRemark());
 
 		Map<String, String> properties = domain.getProperties();