wangwei il y a 6 ans
Parent
commit
02f3742ef8

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

@@ -384,6 +384,59 @@ public class OrgController extends ControllerSupport {
 		return list;
 		return list;
 	}
 	}
 
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param parentId
+	 * @param orgName
+	 * @return
+	 */
+	@ApiOperation(value = "查询子机构树")
+	@GetMapping("query")
+	public List<OrgEntity> querySubOrgTree(@RequestParam(required = true) Long parentId,
+			@RequestParam(required = false) Boolean enable,
+			@RequestParam(required = false) Boolean includeMyself) {
+		User accessUser = getAccessUser();
+		Long rootOrgId = accessUser.getRootOrgId();
+
+		if (null == parentId) {
+			throw new StatusException("B-001249", "parentId is null");
+		}
+
+		OrgEntity parentOrg = orgRepo.findOne(parentId);
+		if (null == parentOrg) {
+			throw new StatusException("B-001250", "parentId is wrong");
+		}
+		validateRootOrgIsolation(parentOrg.getRootId());
+
+		Specification<OrgEntity> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			predicates.add(cb.equal(root.get("rootId"), rootOrgId));
+			predicates.add(cb.equal(root.get("parentId"), parentId));
+			if (null != enable) {
+				predicates.add(cb.equal(root.get("enable"), enable));
+			}
+
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+
+		// 过载保护
+		long total = orgRepo.count(specification);
+		if (total > 1000) {
+			throw new StatusException("B-001251", "total is larger than 1000");
+		}
+
+		Sort sort = new Sort(Direction.ASC, "id");
+		List<OrgEntity> list = orgRepo.findAll(specification, sort);
+
+		if (null != includeMyself && includeMyself) {
+			list.add(0, parentOrg);
+		}
+
+		return list;
+	}
+
 	/**
 	/**
 	 * 方法注释
 	 * 方法注释
 	 *
 	 *