Quellcode durchsuchen

启用禁用机构优化 权限校验

WANG vor 6 Jahren
Ursprung
Commit
2c99ba36fe

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

@@ -60,14 +60,23 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.OrgPropertyEntity;
 import cn.com.qmth.examcloud.core.basic.dao.enums.OrgProperty;
 import cn.com.qmth.examcloud.core.basic.service.bean.OrgInfo;
 import cn.com.qmth.examcloud.core.basic.service.impl.OrgServiceImpl;
+import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
+import cn.com.qmth.examcloud.task.api.request.SyncOrgReq;
 import cn.com.qmth.examcloud.web.config.SystemConfig;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
+import cn.com.qmth.examcloud.web.support.ApiId;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.web.support.Naked;
 import io.swagger.annotations.ApiOperation;
 
 /**
- * 机构服务API Created by songyue on 17/1/14.
+ * {@link StatusException} 状态码范围:001XXX<br>
+ * {@link ApiId}范围: 100-199<br>
+ *
+ *
+ * @author WANGWEI
+ * @date 2019年6月11日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
  */
 @Transactional
 @RestController
@@ -86,6 +95,9 @@ public class OrgController extends ControllerSupport {
 	@Autowired
 	SystemConfig systemConfig;
 
+	@Autowired
+	DataSyncCloudService dataSyncCloudService;
+
 	@ApiOperation(value = "分页查询所有机构")
 	@GetMapping("fullOrgPage/{curPage}/{pageSize}")
 	public PageInfo<OrgDomain> getFullOrgPage(@PathVariable Integer curPage,
@@ -830,13 +842,9 @@ public class OrgController extends ControllerSupport {
 	@ApiOperation(value = "启用机构", notes = "启用")
 	@PutMapping("enable/{ids}")
 	public void enableOrgs(@PathVariable String ids) {
-		List<Long> orgIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+		List<Long> orgIdList = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
 				.collect(Collectors.toList());
-		for (Long orgId : orgIds) {
-			OrgEntity org = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
-			org.setEnable(true);
-			orgRepo.save(org);
-		}
+		setOrgsEnable(orgIdList, true);
 	}
 
 	/**
@@ -848,12 +856,43 @@ public class OrgController extends ControllerSupport {
 	@ApiOperation(value = "禁用机构", notes = "禁用")
 	@PutMapping("disable/{ids}")
 	public void disableOrgs(@PathVariable String ids) {
-		List<Long> orgIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+		List<Long> orgIdList = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
 				.collect(Collectors.toList());
-		for (Long orgId : orgIds) {
+		setOrgsEnable(orgIdList, false);
+	}
+
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param orgIdList
+	 * @param enable
+	 */
+	private void setOrgsEnable(List<Long> orgIdList, Boolean enable) {
+		List<OrgEntity> savedList = Lists.newArrayList();
+		for (Long orgId : orgIdList) {
 			OrgEntity org = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
-			org.setEnable(false);
-			orgRepo.save(org);
+			if (null == org.getParentId()) {
+				if (!isSuperAdmin()) {
+					throw new StatusException("001550", "非法操作");
+				}
+			}
+			validateRootOrgIsolation(org.getRootId());
+
+			org.setEnable(enable);
+			OrgEntity saved = orgRepo.saveAndFlush(org);
+			savedList.add(saved);
+		}
+
+		for (OrgEntity saved : savedList) {
+			SyncOrgReq req = new SyncOrgReq();
+			req.setEnable(saved.getEnable());
+			req.setId(saved.getId());
+			req.setName(saved.getName());
+			req.setParentId(saved.getParentId());
+			req.setRootId(saved.getRootId());
+			req.setSyncType("update");
+			dataSyncCloudService.syncOrg(req);
 		}
 	}