wangwei 7 years ago
parent
commit
244951fc69

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

@@ -141,14 +141,21 @@ public class OrgController extends ControllerSupport {
 	@ApiOperation(value = "模糊查询顶级机构的子机构")
 	@GetMapping("/getSubOrgList/{curPage}/{pageSize}")
 	public Page<Org> getSubOrgListOfRootOrg(@PathVariable Integer curPage,
-			@PathVariable Integer pageSize, @RequestParam Long parentOrgId,
-			@RequestParam String code, @RequestParam String name) {
+			@PathVariable Integer pageSize, @RequestParam Long rootOrgId, @RequestParam String code,
+			@RequestParam String name) {
+
+		User accessUser = getAccessUser();
+		if (!isSuperAdmin()) {
+			if (!accessUser.getRootOrgId().equals(rootOrgId)) {
+				throw new StatusException("B-140001", "非法访问");
+			}
+		}
 
 		Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC,
 				"updateTime");
 
 		Org criteria = new Org();
-		criteria.setParentId(parentOrgId);
+		criteria.setParentId(rootOrgId);
 		criteria.setCode(code);
 		criteria.setName(name);
 
@@ -168,6 +175,27 @@ public class OrgController extends ControllerSupport {
 		return ret;
 	}
 
+	/**
+	 * 修改请通知作者
+	 *
+	 * @author WANGWEI
+	 * @return
+	 */
+	@ApiOperation(value = "查询所有顶级机构")
+	@GetMapping("/getAllRootOrgList")
+	public List<Org> getAllRootOrgList() {
+
+		Specification<Org> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			predicates.add(cb.isNull(root.get("parentId")));
+			predicates.add(cb.equal(root.get("enable"), true));
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+
+		List<Org> ret = orgRepo.findAll(specification);
+		return ret;
+	}
+
 	/**
 	 * 修改请通知作者
 	 *
@@ -217,7 +245,12 @@ public class OrgController extends ControllerSupport {
 	 */
 	@ApiOperation(value = "新增顶级机构", notes = "新增")
 	@PostMapping("addRootOrg")
-	public Org addRootOrg(@RequestBody Org org, HttpServletRequest request) {
+	public Org addRootOrg(@RequestBody Org org) {
+
+		if (!isSuperAdmin()) {
+			throw new StatusException("B-140001", "非法访问");
+		}
+
 		org.setCreateTime(new Date());
 		org.setParentId(null);
 		// 临时
@@ -233,12 +266,16 @@ public class OrgController extends ControllerSupport {
 	 *
 	 * @author WANGWEI
 	 * @param org
-	 * @param request
 	 * @return
 	 */
 	@ApiOperation(value = "更新顶级机构", notes = "更新")
 	@PutMapping("updateRootOrg")
-	public Org updateRootOrg(@RequestBody Org org, HttpServletRequest request) {
+	public Org updateRootOrg(@RequestBody Org org) {
+
+		if (!isSuperAdmin()) {
+			throw new StatusException("B-140001", "非法访问");
+		}
+
 		org.setParentId(null);
 		org.setRootId(org.getId());
 		Org updated = orgService.update(org.getId(), org);
@@ -250,12 +287,11 @@ public class OrgController extends ControllerSupport {
 	 *
 	 * @author WANGWEI
 	 * @param org
-	 * @param request
 	 * @return
 	 */
 	@ApiOperation(value = "新增子机构", notes = "新增")
 	@PostMapping("addSubOrg")
-	public Org addSubOrg(@RequestBody Org org, HttpServletRequest request) {
+	public Org addSubOrg(@RequestBody Org org) {
 		org.setCreateTime(new Date());
 		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
 		org.setParentId(accessUser.getRootOrgId());
@@ -274,7 +310,7 @@ public class OrgController extends ControllerSupport {
 	 */
 	@ApiOperation(value = "更新子机构", notes = "更新")
 	@PutMapping("updateSubOrg")
-	public Org updateSubOrg(@RequestBody Org org, HttpServletRequest request) {
+	public Org updateSubOrg(@RequestBody Org org) {
 		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
 
 		org.setParentId(accessUser.getRootOrgId());
@@ -356,14 +392,14 @@ public class OrgController extends ControllerSupport {
 	}
 
 	@ApiOperation(value = "查询所有学校", notes = "查询所有学校")
-	@GetMapping("/getAllParentOrg")
+	// @GetMapping("/getAllParentOrg")
 	public List<Org> getAllParentOrg() {
 		List<Org> list = orgRepo.findAllParentOrg();
 		return list;
 	}
 
 	@ApiOperation(value = "查询所有印刷机构", notes = "查询所有印刷机构")
-	@GetMapping("/allPrint")
+	// @GetMapping("/allPrint")
 	public List<Org> getAllPrintOrg() {
 		List<Org> orgList = orgRepo.findAllPrintByParentId(0L);
 		return orgList;

+ 1 - 1
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/OrgRepo.java

@@ -42,6 +42,6 @@ public interface OrgRepo
 	@Query(nativeQuery = true, value = "select *from ecs_core_org where parent_id=:parentId and code=:code and enable = 1")
 	Org findFirstByParentIdAndCode(@Param("parentId") Long parentId, @Param("code") String code);
 
-	@Query(nativeQuery = true, value = "select * from ecs_core_org t where t.parent_id = 0 and t.enable = 1 order by t.id")
+	@Query(nativeQuery = true, value = "select * from ecs_core_org t where t.parent_id is null and t.enable = 1 order by t.id")
 	List<Org> findAllParentOrg();
 }