wangwei před 6 roky
rodič
revize
25fe40926d

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

@@ -357,7 +357,7 @@ public class OrgController extends ControllerSupport {
 		}
 
 		// 过载保护
-		int total = orgRepo.countByNameLike(name);
+		int total = orgRepo.countByRootIdAndNameLike(getRootOrgId(), name);
 		if (total > 1000) {
 			List<OrgEntity> list = Lists.newArrayList();
 			return list;
@@ -615,12 +615,6 @@ public class OrgController extends ControllerSupport {
 		return saved;
 	}
 
-	@ApiOperation(value = "按ID删除机构", notes = "删除")
-	@DeleteMapping("/{id}")
-	public void deleteSchool(@PathVariable Long id) {
-		orgRepo.delete(id);
-	}
-
 	/**
 	 * 方法注释
 	 *
@@ -628,7 +622,7 @@ public class OrgController extends ControllerSupport {
 	 * @param ids
 	 */
 	@ApiOperation(value = "启用机构", notes = "启用")
-	@PutMapping("/enable/{ids}")
+	@PutMapping("enable/{ids}")
 	public void enableOrgs(@PathVariable String ids) {
 		List<Long> orgIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
 				.collect(Collectors.toList());
@@ -646,7 +640,7 @@ public class OrgController extends ControllerSupport {
 	 * @param ids
 	 */
 	@ApiOperation(value = "禁用机构", notes = "禁用")
-	@PutMapping("/disable/{ids}")
+	@PutMapping("disable/{ids}")
 	public void disableOrgs(@PathVariable String ids) {
 		List<Long> orgIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
 				.collect(Collectors.toList());
@@ -665,7 +659,7 @@ public class OrgController extends ControllerSupport {
 	 * @throws IOException
 	 */
 	@ApiOperation(value = "获取logo")
-	@GetMapping("/logo")
+	@GetMapping("logo")
 	public void getLogo(@RequestParam("domain") String domain, HttpServletResponse response)
 			throws IOException {
 		OrgEntity org = orgRepo.findByParentIdIsNullAndDomainName(domain);
@@ -689,7 +683,7 @@ public class OrgController extends ControllerSupport {
 	 * @throws IOException
 	 */
 	@ApiOperation(value = "导入logo", notes = "导入logo")
-	@PostMapping("/importLogo/{orgId}")
+	@PostMapping("importLogo/{orgId}")
 	public void importLogo(@PathVariable Long orgId, HttpServletRequest request,
 			@RequestParam CommonsMultipartFile file) throws IOException {
 		String schoolLogoPath = PropertiesUtil.getString(PropKeys.SCHOOL_LOGO_PATH);
@@ -724,4 +718,10 @@ public class OrgController extends ControllerSupport {
 		orgPropertyRepo.save(entity);
 	}
 
+	@ApiOperation(value = "删除子机构", notes = "")
+	@DeleteMapping("deleteSubOrg/{orgId}")
+	public void deleteSubOrg(@PathVariable Long orgId) {
+		orgService.deleteSubOrg(orgId, false);
+	}
+
 }

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

@@ -19,22 +19,18 @@ public interface OrgRepo
 
 	List<OrgEntity> findByRootId(Long rootId);
 
-	List<OrgEntity> findByParentIdAndNameLikeAndEnable(Long parentId, String name, Boolean enable);
-
-	OrgEntity findByParentIdAndCode(Long parentId, String code);
-
 	OrgEntity findByParentIdIsNullAndDomainName(String domainName);
 
 	OrgEntity findByRootIdAndCode(Long rootId, String code);
 
 	List<OrgEntity> findByRootIdAndNameLike(Long rootId, String name);
 
-	List<OrgEntity> findByParentIdAndEnable(Long parentId, Boolean enable);
-
 	OrgEntity findByParentIdIsNullAndCode(String code);
 
 	OrgEntity findByParentIdIsNullAndId(Long id);
 
-	int countByNameLike(String name);
+	int countByRootIdAndNameLike(Long rootId, String name);
+
+	int countByRootIdAndParentId(Long rootId, long parentId);
 
 }

+ 2 - 0
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/StudentRepo.java

@@ -28,4 +28,6 @@ public interface StudentRepo
 
 	StudentEntity findBySecurityPhone(String securityPhone);
 
+	int countByRootOrgId(Long rootOrgId);
+
 }

+ 2 - 0
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/UserRepo.java

@@ -36,4 +36,6 @@ public interface UserRepo
 
 	List<UserEntity> findByRootOrgId(Long rootOrgId);
 
+	int countByRootOrgId(Long rootOrgId);
+
 }

+ 9 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/OrgService.java

@@ -30,4 +30,13 @@ public interface OrgService {
 	 */
 	OrgEntity saveSubOrg(OrgInfo orgInfo);
 
+	/**
+	 * 删除子机构
+	 * 
+	 * @author WANGWEI
+	 * @param subOrgId
+	 * @param cascade
+	 */
+	void deleteSubOrg(Long subOrgId, boolean cascade);
+
 }

+ 31 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/OrgServiceImpl.java

@@ -16,6 +16,7 @@ import cn.com.qmth.examcloud.core.basic.dao.ExamSiteRepo;
 import cn.com.qmth.examcloud.core.basic.dao.OrgPropertyRepo;
 import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
 import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
+import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
 import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
 import cn.com.qmth.examcloud.core.basic.dao.UserRoleRelationRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
@@ -45,6 +46,9 @@ public class OrgServiceImpl implements OrgService {
 	@Autowired
 	OrgPropertyRepo orgPropertyRepo;
 
+	@Autowired
+	StudentRepo studentRepo;
+
 	/*
 	 * 保存顶级机构
 	 *
@@ -242,4 +246,31 @@ public class OrgServiceImpl implements OrgService {
 		return map;
 	}
 
+	@Override
+	public void deleteSubOrg(Long subOrgId, boolean cascade) {
+		OrgEntity orgEntity = orgRepo.findOne(subOrgId);
+		if (null == orgEntity.getParentId()) {
+			throw new StatusException("E-001004", "该机构非子机构");
+		}
+		Long rootId = orgEntity.getRootId();
+		Long parentId = orgEntity.getParentId();
+
+		if (0 < orgRepo.countByRootIdAndParentId(rootId, parentId)) {
+			throw new StatusException("E-001004", "该机构有子机构");
+		}
+
+		if (!cascade) {
+			if (0 < userRepo.countByRootOrgId(rootId)) {
+				throw new StatusException("E-001004", "该机构已关联用户");
+			}
+
+			if (0 < studentRepo.countByRootOrgId(rootId)) {
+				throw new StatusException("E-001004", "该机构已关联学生");
+			}
+		}
+
+		orgRepo.delete(orgEntity);
+
+	}
+
 }