PaperBasicInfo

dev-tmp1
luotaiqian 2026-08-21 15:58:40 +08:00
parent ff1e0ae8fd
commit b4043e8238
2 changed files with 105 additions and 78 deletions

View File

@ -56,7 +56,7 @@ import java.util.stream.Collectors;
* <p> * <p>
* sheetsheet1sheet2 * sheetsheet1sheet2
* *
* /ID -> -> * /ID -> ->
* </p> * </p>
* *
* @author safety-eval * @author safety-eval
@ -769,12 +769,12 @@ public class OrgPersonnelExcelImporter {
} }
/** /**
* *
* <p> * <p>
* -> -> parentId * -> -> parentId
* <ul> * <ul>
* <li></li> * <li>-> </li>
* <li> parentId </li> * <li> -> </li>
* <li> ID deptId </li> * <li> ID deptId </li>
* </ul> * </ul>
*/ */
@ -796,31 +796,53 @@ public class OrgPersonnelExcelImporter {
Map<String, List<OrgDepartmentEntity>> nameMapList = Map<String, List<OrgDepartmentEntity>> nameMapList =
orgDepartmentList.stream().collect(Collectors.groupingBy(OrgDepartmentEntity::getDeptName)); orgDepartmentList.stream().collect(Collectors.groupingBy(OrgDepartmentEntity::getDeptName));
for (OrgPersonnelImportRow row : rows) { for (OrgPersonnelImportRow row : rows) {
Pair<Boolean, OrgDepartmentEntity> l1 = getL1(errors, row, nameMapList); Pair<Boolean, OrgDepartmentEntity> l1 = getL1(errors, row, nameMapList, orgId);
if (!l1.getKey()) { if (!l1.getKey()) {
continue; continue;
} }
OrgDepartmentEntity l1Dept = l1.getValue(); OrgDepartmentEntity l1Dept = l1.getValue();
Pair<Boolean, OrgDepartmentEntity> l2 = getL2(errors, row, nameMapList, l1Dept); Pair<Boolean, OrgDepartmentEntity> l2 = getL2(row, nameMapList, l1Dept, orgId);
if (!l2.getKey() || l2.getValue() == null) { if (!l2.getKey() || l2.getValue() == null) {
continue; continue;
} }
getL3(errors, row, nameMapList, l2.getValue()); getL3(row, nameMapList, l2.getValue(), orgId);
} }
} }
/** /**
* nameMapList
* *
* @param errors errors * @param orgId ID
* @param row row * @param parentId ID 0
* @param nameMapList nameMapList * @param deptName
* @param l2Dept l2Dept * @param nameMapList key:
* @return Pair<Boolean, OrgDepartmentEntity> key true false * @return ID
* value key =true ,value=null
*/ */
private Pair<Boolean, OrgDepartmentEntity> getL3(List<OrgPersonnelImportErrorCO> errors, OrgPersonnelImportRow row private OrgDepartmentEntity createDept(Long orgId, Long parentId, String deptName,
, Map<String, List<OrgDepartmentEntity>> nameMapList, OrgDepartmentEntity l2Dept) { Map<String, List<OrgDepartmentEntity>> nameMapList) {
OrgDepartmentEntity entity = new OrgDepartmentEntity();
entity.setOrgId(orgId);
entity.setParentId(parentId);
entity.setDeptName(deptName);
OrgDepartmentEntity saved = orgDepartmentGateway.save(entity);
nameMapList.computeIfAbsent(deptName, k -> new ArrayList<>()).add(saved);
LOGGER.info("人员导入自动新增部门, orgId={}, parentId={}, deptName={}, deptId={}"
, orgId, parentId, deptName, saved.getId());
return saved;
}
/**
*
*
* @param row
* @param nameMapList key:
* @param l2Dept
* @param orgId ID
* @return Pair<Boolean, OrgDepartmentEntity> key value null
*/
private Pair<Boolean, OrgDepartmentEntity> getL3(OrgPersonnelImportRow row
, Map<String, List<OrgDepartmentEntity>> nameMapList, OrgDepartmentEntity l2Dept, Long orgId) {
String l3 = row.getBasic().getDeptNameLevel3(); String l3 = row.getBasic().getDeptNameLevel3();
if (StrUtil.isBlank(l3)) { if (StrUtil.isBlank(l3)) {
return Pair.of(true, null); return Pair.of(true, null);
@ -828,14 +850,7 @@ public class OrgPersonnelExcelImporter {
// l3 部门查询 // l3 部门查询
List<OrgDepartmentEntity> departmentEntities = nameMapList.get(l3); List<OrgDepartmentEntity> departmentEntities = nameMapList.get(l3);
if (CollectionUtils.isEmpty(departmentEntities)) { if (!CollectionUtils.isEmpty(departmentEntities)) {
errors.add(new OrgPersonnelImportErrorCO(row.getBasic().getRowIndex(), row.getBasic().getAccount(), row.getBasic().getUserName(),
ErrorCode.ORG_PERSONNEL_IMPORT_DEPT_L3_NOT_EXIST.getMessage()));
row.setValidateFail(true);
return Pair.of(false, null);
}
// 三级部门
for (OrgDepartmentEntity departmentEntity : departmentEntities) { for (OrgDepartmentEntity departmentEntity : departmentEntities) {
if (departmentEntity.getDeptName().equals(l3) if (departmentEntity.getDeptName().equals(l3)
&& departmentEntity.getParentId().compareTo(l2Dept.getId()) == 0) { && departmentEntity.getParentId().compareTo(l2Dept.getId()) == 0) {
@ -843,25 +858,25 @@ public class OrgPersonnelExcelImporter {
return Pair.of(true, departmentEntity); return Pair.of(true, departmentEntity);
} }
} }
}
errors.add(new OrgPersonnelImportErrorCO(row.getBasic().getRowIndex(), row.getBasic().getAccount(), row.getBasic().getUserName(), // 二级部门下不存在该三级部门 -> 自动新增
l2Dept.getDeptName() + "下" OrgDepartmentEntity created = createDept(orgId, l2Dept.getId(), l3, nameMapList);
+ ErrorCode.ORG_PERSONNEL_IMPORT_DEPT_L3_NOT_EXIST.getMessage())); row.setDeptId(created.getId());
row.setValidateFail(true); return Pair.of(true, created);
return Pair.of(false, null);
} }
/** /**
*
* *
* @param errors errors * @param row
* @param row row * @param nameMapList key:
* @param nameMapList nameMapList * @param l1Dept
* @param l1Dept l1Dept * @param orgId ID
* @return Pair<Boolean, OrgDepartmentEntity> key true false * @return Pair<Boolean, OrgDepartmentEntity> key value null
* value key =true ,value=null
*/ */
private Pair<Boolean, OrgDepartmentEntity> getL2(List<OrgPersonnelImportErrorCO> errors private Pair<Boolean, OrgDepartmentEntity> getL2(OrgPersonnelImportRow row
, OrgPersonnelImportRow row, Map<String, List<OrgDepartmentEntity>> nameMapList, OrgDepartmentEntity l1Dept) { , Map<String, List<OrgDepartmentEntity>> nameMapList, OrgDepartmentEntity l1Dept, Long orgId) {
String l2 = row.getBasic().getDeptNameLevel2(); String l2 = row.getBasic().getDeptNameLevel2();
if (StrUtil.isBlank(l2)) { if (StrUtil.isBlank(l2)) {
return Pair.of(true, null); return Pair.of(true, null);
@ -869,14 +884,7 @@ public class OrgPersonnelExcelImporter {
// l2 部门查询 // l2 部门查询
List<OrgDepartmentEntity> departmentEntities = nameMapList.get(l2); List<OrgDepartmentEntity> departmentEntities = nameMapList.get(l2);
if (CollectionUtils.isEmpty(departmentEntities)) { if (!CollectionUtils.isEmpty(departmentEntities)) {
errors.add(new OrgPersonnelImportErrorCO(row.getBasic().getRowIndex(), row.getBasic().getAccount(), row.getBasic().getUserName(),
ErrorCode.ORG_PERSONNEL_IMPORT_DEPT_L2_NOT_EXIST.getMessage()));
row.setValidateFail(true);
return Pair.of(false, null);
}
// 二级部门
for (OrgDepartmentEntity departmentEntity : departmentEntities) { for (OrgDepartmentEntity departmentEntity : departmentEntities) {
if (departmentEntity.getDeptName().equals(l2) if (departmentEntity.getDeptName().equals(l2)
&& departmentEntity.getParentId().compareTo(l1Dept.getId()) == 0) { && departmentEntity.getParentId().compareTo(l1Dept.getId()) == 0) {
@ -884,22 +892,26 @@ public class OrgPersonnelExcelImporter {
return Pair.of(true, departmentEntity); return Pair.of(true, departmentEntity);
} }
} }
}
errors.add(new OrgPersonnelImportErrorCO(row.getBasic().getRowIndex(), row.getBasic().getAccount(), row.getBasic().getUserName(), // 一级部门下不存在该二级部门 -> 自动新增
l1Dept.getDeptName() + "下" + ErrorCode.ORG_PERSONNEL_IMPORT_DEPT_L2_NOT_EXIST.getMessage())); OrgDepartmentEntity created = createDept(orgId, l1Dept.getId(), l2, nameMapList);
row.setValidateFail(true); row.setDeptId(created.getId());
return Pair.of(false, null); return Pair.of(true, created);
} }
/** /**
* parentId=0
*
* *
* @param errors errors * @param errors
* @param row row * @param row
* @param nameMapList nameMapList * @param nameMapList key:
* @return Pair<Boolean, String> key true false * @param orgId ID
* @return Pair<Boolean, OrgDepartmentEntity> key value
*/ */
private static Pair<Boolean, OrgDepartmentEntity> getL1(List<OrgPersonnelImportErrorCO> errors, OrgPersonnelImportRow row private Pair<Boolean, OrgDepartmentEntity> getL1(List<OrgPersonnelImportErrorCO> errors, OrgPersonnelImportRow row
, Map<String, List<OrgDepartmentEntity>> nameMapList) { , Map<String, List<OrgDepartmentEntity>> nameMapList, Long orgId) {
String l1 = row.getBasic().getDeptNameLevel1(); String l1 = row.getBasic().getDeptNameLevel1();
if (StrUtil.isBlank(l1)) { if (StrUtil.isBlank(l1)) {
errors.add(new OrgPersonnelImportErrorCO(row.getBasic().getRowIndex(), row.getBasic().getAccount(), row.getBasic().getUserName(), errors.add(new OrgPersonnelImportErrorCO(row.getBasic().getRowIndex(), row.getBasic().getAccount(), row.getBasic().getUserName(),
@ -911,10 +923,10 @@ public class OrgPersonnelExcelImporter {
// l1 部门查询 // l1 部门查询
List<OrgDepartmentEntity> departmentEntities = nameMapList.get(l1); List<OrgDepartmentEntity> departmentEntities = nameMapList.get(l1);
if (CollectionUtils.isEmpty(departmentEntities)) { if (CollectionUtils.isEmpty(departmentEntities)) {
errors.add(new OrgPersonnelImportErrorCO(row.getBasic().getRowIndex(), row.getBasic().getAccount(), row.getBasic().getUserName(), // 机构下不存在该一级部门 -> 自动新增(根节点 parentId=0
ErrorCode.ORG_PERSONNEL_IMPORT_DEPT_L1_NOT_EXIST.getMessage())); OrgDepartmentEntity created = createDept(orgId, 0L, l1, nameMapList);
row.setValidateFail(true); row.setDeptId(created.getId());
return Pair.of(false, null); return Pair.of(true, created);
} }
// 一级部门重复 // 一级部门重复
@ -935,8 +947,8 @@ public class OrgPersonnelExcelImporter {
} }
/** /**
* dept_id + org_id postId * dept_id + org_id postId
* validateFail * validateFail
*/ */
private void validateAndFillPosition(List<OrgPersonnelImportRow> rows, Long orgId, List<OrgPersonnelImportErrorCO> errors) { private void validateAndFillPosition(List<OrgPersonnelImportRow> rows, Long orgId, List<OrgPersonnelImportErrorCO> errors) {
Set<Long> deptIds = new HashSet<>(); Set<Long> deptIds = new HashSet<>();
@ -960,7 +972,7 @@ public class OrgPersonnelExcelImporter {
} }
} }
// 逐行校验:岗位名称为空或部门下岗位不存在 -> 记录异常并标记校验通过则回填岗位ID // 逐行校验:岗位名称为空 -> 记录异常并标记;部门下岗位不存在 -> 自动新增校验通过则回填岗位ID
for (OrgPersonnelImportRow row : rows) { for (OrgPersonnelImportRow row : rows) {
String posName = trim(row.getBasic().getPositionName()); String posName = trim(row.getBasic().getPositionName());
if (!StringUtils.hasText(posName)) { if (!StringUtils.hasText(posName)) {
@ -973,16 +985,33 @@ public class OrgPersonnelExcelImporter {
String key = row.getDeptId() + "|" + posName; String key = row.getDeptId() + "|" + posName;
OrgPositionEntity pos = positionMap.get(key); OrgPositionEntity pos = positionMap.get(key);
if (pos == null) { if (pos == null) {
errors.add(new OrgPersonnelImportErrorCO(row.getBasic().getRowIndex(), row.getBasic().getAccount(), row.getBasic().getUserName(), // 部门下岗位不存在 -> 自动新增并放入缓存(同文件同部门同岗位仅创建一次)
ErrorCode.ORG_PERSONNEL_IMPORT_POSITION_NOT_FOUND.getMessage() pos = createPosition(orgId, row.getDeptId(), posName);
+ "" + posName + "(部门:" + row.getDeptDisplayName() + "")); positionMap.put(key, pos);
row.setValidateFail(true);
continue;
} }
row.setPostId(pos.getId()); row.setPostId(pos.getId());
} }
} }
/**
*
*
* @param orgId ID
* @param deptId ID
* @param positionName
* @return ID
*/
private OrgPositionEntity createPosition(Long orgId, Long deptId, String positionName) {
OrgPositionEntity entity = new OrgPositionEntity();
entity.setOrgId(orgId);
entity.setDeptId(deptId);
entity.setPositionName(positionName);
OrgPositionEntity saved = orgPositionGateway.save(entity);
LOGGER.info("人员导入自动新增岗位, orgId={}, deptId={}, positionName={}, postId={}"
, orgId, deptId, positionName, saved.getId());
return saved;
}
/** /**
* major /seriesMajor * major /seriesMajor
* basic_discipline_major.professional_name in * basic_discipline_major.professional_name in

View File

@ -42,8 +42,6 @@ public enum ErrorCode {
ORG_PERSONNEL_IMPORT_DEPT_NOT_EXIST("01-05-013", "请填写部门名称"), ORG_PERSONNEL_IMPORT_DEPT_NOT_EXIST("01-05-013", "请填写部门名称"),
ORG_PERSONNEL_IMPORT_DEPT_L1_NOT_EXIST("01-05-014", "一级部门名称不存在"), ORG_PERSONNEL_IMPORT_DEPT_L1_NOT_EXIST("01-05-014", "一级部门名称不存在"),
ORG_PERSONNEL_IMPORT_DEPT_L1_REPEAT("01-05-015", "一级部门名称查询到多个,请在部门目录去核验"), ORG_PERSONNEL_IMPORT_DEPT_L1_REPEAT("01-05-015", "一级部门名称查询到多个,请在部门目录去核验"),
ORG_PERSONNEL_IMPORT_DEPT_L2_NOT_EXIST("01-05-016", "二级部门名称不存在"),
ORG_PERSONNEL_IMPORT_DEPT_L3_NOT_EXIST("01-05-017", "三级部门名称不存在"),
// ---- 人员证书 ---- // ---- 人员证书 ----
ORG_PERSONNEL_CERT_NOT_FOUND("01-06-001", "人员证书不存在"), ORG_PERSONNEL_CERT_NOT_FOUND("01-06-001", "人员证书不存在"),