|
@@ -19,6 +19,7 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.excel.ExcelReader;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.excel.ExcelReaderHandle;
|
|
@@ -79,8 +80,7 @@ public class OrgService {
|
|
|
* @param orgDto
|
|
|
*/
|
|
|
private void saveOrgAndExamSite(OrgDto orgDto) {
|
|
|
- Org org = orgRepo.findByParentIdAndCodeAndEnable(orgDto.getParentId(), orgDto.getCode(),
|
|
|
- true);
|
|
|
+ Org org = orgRepo.findByParentIdAndCode(orgDto.getParentId(), orgDto.getCode());
|
|
|
if (org == null) {
|
|
|
|
|
|
Org tempOrg = orgRepo.save(orgAssembler(orgDto));
|
|
@@ -233,33 +233,69 @@ public class OrgService {
|
|
|
return orgRepo.findAll(examExample);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 强校验
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param org
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public Org save(Org org) {
|
|
|
- checkCode(org.getParentId(), org.getCode());
|
|
|
- Org reOrg = orgRepo.save(org);
|
|
|
- dataSendService.sendOrg(reOrg);
|
|
|
- // 删除缓存
|
|
|
- orgMemRepo.remove(reOrg.getId());
|
|
|
- return reOrg;
|
|
|
- }
|
|
|
|
|
|
- private void checkCode(Long parentId, String code) {
|
|
|
- Org old = orgRepo.findFirstByParentIdAndCode(parentId, code);
|
|
|
- if (old != null) {
|
|
|
- throw new RuntimeException("代码已存在");
|
|
|
+ String code = org.getCode();
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
+ throw new StatusException("B-150000", "code is blank");
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- public Org update(Long id, Org org) {
|
|
|
- Org old = orgRepo.findOne(id);
|
|
|
- if (!old.getCode().equals(org.getCode())) {
|
|
|
- checkCode(org.getParentId(), org.getCode());
|
|
|
+ // 顶级机构
|
|
|
+ if (null == org.getParentId()) {
|
|
|
+
|
|
|
+ // 校验顶级机构编码已存在
|
|
|
+ Org rootOrg = orgRepo.findRootOrg(code);
|
|
|
+ if (null != rootOrg) {
|
|
|
+ if (!(null != org.getId() && org.getId().equals(rootOrg.getId()))) {
|
|
|
+ throw new StatusException("B-150001", "顶级机构编码已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增
|
|
|
+ if (null == org.getId()) {
|
|
|
+ Org saved = orgRepo.save(org);
|
|
|
+ org.setId(saved.getId());
|
|
|
+ org.setRootId(saved.getId());
|
|
|
+ }
|
|
|
}
|
|
|
- org.setUpdateTime(new Date());
|
|
|
- Org reOrg = orgRepo.save(org);
|
|
|
- dataSendService.sendOrg(reOrg);
|
|
|
+ // 子机构
|
|
|
+ else {
|
|
|
+ Long rootId = org.getRootId();
|
|
|
+ if (null == rootId) {
|
|
|
+ throw new StatusException("B-150002", "rootId is null");
|
|
|
+ }
|
|
|
+ Org rootOrg = orgRepo.findOne(rootId);
|
|
|
+ if (null == rootOrg || null != rootOrg.getParentId()) {
|
|
|
+ throw new StatusException("B-150003", "rootId is wrong");
|
|
|
+ }
|
|
|
+ Long parentId = org.getParentId();
|
|
|
+
|
|
|
+ Org parentOrg = orgRepo.findOne(parentId);
|
|
|
+ if (!parentOrg.getRootId().equals(rootId)) {
|
|
|
+ throw new StatusException("B-150004", "parentId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ Org subOrg = orgRepo.findByRootIdAndCode(rootId, code);
|
|
|
+ if (null != subOrg) {
|
|
|
+ if (!(null != org.getId() && org.getId().equals(subOrg.getId()))) {
|
|
|
+ throw new StatusException("B-150005", "机构编码已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Org saved = orgRepo.save(org);
|
|
|
+ dataSendService.sendOrg(saved);
|
|
|
// 删除缓存
|
|
|
- orgMemRepo.remove(reOrg.getId());
|
|
|
- return reOrg;
|
|
|
+ orgMemRepo.remove(saved.getId());
|
|
|
+ return saved;
|
|
|
}
|
|
|
|
|
|
public Org findOne(Long id) {
|
|
@@ -275,8 +311,4 @@ public class OrgService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public Org findFirstByParentIdAndCode(Long parentId, String code) {
|
|
|
- return orgRepo.findFirstByParentIdAndCode(parentId, code);
|
|
|
- }
|
|
|
-
|
|
|
}
|