代码提交-部门/岗位删除,校验是否存在人员

dev-tmp1
zhanglei 2026-08-10 10:45:20 +08:00
parent 6bdab4199e
commit dda94f4623
7 changed files with 104 additions and 0 deletions

View File

@ -14,6 +14,7 @@ public enum ErrorCode {
DATA_NOT_EXIST("01-02-101", "数据不存在"),
// ---- 部门 ----
ORG_DEPARTMENT_NOT_FOUND("01-02-001", "部门不存在"),
ORG_DEPARTMENT_HAS_PERSONNEL("01-02-002", "该部门(含子部门)下存在人员,无法删除"),
// ---- 装备信息 ----
ORG_EQUIPMENT_NOT_FOUND("01-03-001", "装备信息不存在"),
@ -54,6 +55,7 @@ public enum ErrorCode {
ORG_POSITION_NOT_FOUND("01-08-001", "岗位不存在"),
ORG_POSITION_GBS_ROLE_REQUIRED("01-08-002", "岗位关联GBS角色编码不能为空"),
ORG_POSITION_GBS_ROLE_SYNC_ERROR("01-08-003", "岗位关联人员GBS角色同步失败"),
ORG_POSITION_HAS_PERSONNEL("01-08-004", "该岗位下存在人员,无法删除"),
// ---- 机构资质证书 ----
ORG_QUALIFICATION_NOT_FOUND("01-09-001", "机构资质证书不存在"),

View File

@ -30,4 +30,9 @@ public interface OrgDepartmentGateway {
* ID +
*/
List<OrgDepartmentEntity> listByOrgIdAndNames(Long orgId, Collection<String> deptNames);
/**
* ID
*/
List<Long> listSelfAndDescendantIds(Long deptId);
}

View File

@ -47,4 +47,14 @@ public interface OrgPersonnelGateway {
* WPS
*/
java.util.List<OrgPersonnelEntity> listByIds(Collection<Long> ids);
/**
*
*/
boolean existsByDeptIds(Collection<Long> deptIds);
/**
*
*/
boolean existsByPostId(Long postId);
}

View File

@ -4,6 +4,7 @@ import org.qinan.safetyeval.domain.entity.OrgDepartmentEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.OrgDepartmentGateway;
import org.qinan.safetyeval.domain.gateway.OrgPersonnelGateway;
import org.qinan.safetyeval.domain.query.OrgDepartmentQuery;
import org.qinan.safetyeval.domain.query.PageResult;
@ -23,6 +24,9 @@ public class OrgDepartmentDomainService {
@Resource
private OrgDepartmentGateway orgDepartmentGateway;
@Resource
private OrgPersonnelGateway orgPersonnelGateway;
public OrgDepartmentEntity add(OrgDepartmentEntity entity) {
return orgDepartmentGateway.save(entity);
}
@ -44,6 +48,10 @@ public class OrgDepartmentDomainService {
if (existing == null) {
throw new BizException(ErrorCode.ORG_DEPARTMENT_NOT_FOUND);
}
List<Long> deptIds = orgDepartmentGateway.listSelfAndDescendantIds(id);
if (orgPersonnelGateway.existsByDeptIds(deptIds)) {
throw new BizException(ErrorCode.ORG_DEPARTMENT_HAS_PERSONNEL);
}
orgDepartmentGateway.delete(id);
}

View File

@ -3,6 +3,7 @@ package org.qinan.safetyeval.domain.service;
import org.qinan.safetyeval.domain.entity.OrgPositionEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.OrgPersonnelGateway;
import org.qinan.safetyeval.domain.gateway.OrgPositionGateway;
import org.qinan.safetyeval.domain.query.OrgPositionQuery;
import org.qinan.safetyeval.domain.query.PageResult;
@ -21,6 +22,9 @@ public class OrgPositionDomainService {
@Resource
private OrgPositionGateway orgPositionGateway;
@Resource
private OrgPersonnelGateway orgPersonnelGateway;
public OrgPositionEntity add(OrgPositionEntity entity) {
return orgPositionGateway.save(entity);
}
@ -42,6 +46,9 @@ public class OrgPositionDomainService {
if (existing == null) {
throw new BizException(ErrorCode.ORG_POSITION_NOT_FOUND);
}
if (orgPersonnelGateway.existsByPostId(id)) {
throw new BizException(ErrorCode.ORG_POSITION_HAS_PERSONNEL);
}
orgPositionGateway.delete(id);
}

View File

@ -15,8 +15,13 @@ import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@ -97,6 +102,49 @@ public class OrgDepartmentGatewayImpl implements OrgDepartmentGateway {
.collect(Collectors.toList());
}
@Override
public List<Long> listSelfAndDescendantIds(Long deptId) {
if (deptId == null) {
return Collections.emptyList();
}
OrgDepartmentDO root = orgDepartmentMapper.selectById(deptId);
if (root == null) {
return Collections.emptyList();
}
LambdaQueryWrapper<OrgDepartmentDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrgDepartmentDO::getDeleteEnum, "false");
if (root.getOrgId() != null) {
wrapper.eq(OrgDepartmentDO::getOrgId, root.getOrgId());
}
wrapper.select(OrgDepartmentDO::getId, OrgDepartmentDO::getParentId);
List<OrgDepartmentDO> all = orgDepartmentMapper.selectList(wrapper);
Map<Long, List<Long>> childrenMap = new HashMap<>();
for (OrgDepartmentDO item : all) {
if (item.getId() == null) {
continue;
}
Long parentId = item.getParentId();
if (parentId == null) {
continue;
}
childrenMap.computeIfAbsent(parentId, k -> new ArrayList<>()).add(item.getId());
}
List<Long> result = new ArrayList<>();
ArrayDeque<Long> queue = new ArrayDeque<>();
queue.add(deptId);
while (!queue.isEmpty()) {
Long current = queue.poll();
result.add(current);
List<Long> children = childrenMap.get(current);
if (children != null) {
queue.addAll(children);
}
}
return result;
}
private LambdaQueryWrapper<OrgDepartmentDO> buildQueryWrapper(OrgDepartmentQuery query) {
LambdaQueryWrapper<OrgDepartmentDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrgDepartmentDO::getDeleteEnum, "false");

View File

@ -215,5 +215,29 @@ public class OrgPersonnelGatewayImpl implements OrgPersonnelGateway {
return orgPersonnelDoConvertor.converDosToEes(orgPersonnelMapper.selectList(wrapper));
}
@Override
public boolean existsByDeptIds(Collection<Long> deptIds) {
if (deptIds == null || deptIds.isEmpty()) {
return false;
}
LambdaQueryWrapper<OrgPersonnelDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrgPersonnelDO::getDeleteEnum, "false");
wrapper.in(OrgPersonnelDO::getDeptId, deptIds);
wrapper.last("LIMIT 1");
return orgPersonnelMapper.selectCount(wrapper) > 0;
}
@Override
public boolean existsByPostId(Long postId) {
if (postId == null) {
return false;
}
LambdaQueryWrapper<OrgPersonnelDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrgPersonnelDO::getDeleteEnum, "false");
wrapper.eq(OrgPersonnelDO::getPostId, postId);
wrapper.last("LIMIT 1");
return orgPersonnelMapper.selectCount(wrapper) > 0;
}
}