员工信息管理, 页面查询优化

dev-tmp1
zhanglei 2026-08-11 14:41:40 +08:00
parent 9342ab42d3
commit 423d03f416
2 changed files with 321 additions and 95 deletions

View File

@ -241,14 +241,11 @@ public class OrgPersonnelExecutor implements OrgPersonnelApi {
PageResult<OrgPersonnelEntity> pageResult = orgPersonnelDomainService.page(domainQuery); PageResult<OrgPersonnelEntity> pageResult = orgPersonnelDomainService.page(domainQuery);
List<OrgPersonnelCO> records = pageResult.getRecords().stream() List<OrgPersonnelCO> records = pageResult.getRecords().stream()
.map(entity -> { .map(orgPersonnelConvertor::toCO)
OrgPersonnelCO co = orgPersonnelConvertor.toCO(entity);
enrich(co);
return co;
})
.collect(java.util.stream.Collectors.toList()); .collect(java.util.stream.Collectors.toList());
if (orgPersonnelViewEnricher != null) {
fillCertsBatch(records); orgPersonnelViewEnricher.enrichPersonnelBatch(records);
}
return PageResponse.of(records, pageResult.getTotal()); return PageResponse.of(records, pageResult.getTotal());
} }
@ -398,42 +395,6 @@ public class OrgPersonnelExecutor implements OrgPersonnelApi {
} }
} }
/**
* CO
*/
private void fillCertsBatch(List<OrgPersonnelCO> records) {
if (orgPersonnelCertDomainService == null || CollectionUtils.isEmpty(records)) {
return;
}
List<Long> personnelIds = records.stream()
.map(OrgPersonnelCO::getId)
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(personnelIds)) {
return;
}
List<OrgPersonnelCertEntity> certs = orgPersonnelCertDomainService.listByPersonnelIds(personnelIds);
if (CollectionUtils.isEmpty(certs)) {
return;
}
Map<Long, List<OrgPersonnelCertEntity>> certMap = certs.stream()
.collect(Collectors.groupingBy(OrgPersonnelCertEntity::getPersonnelId));
for (OrgPersonnelCO co : records) {
List<OrgPersonnelCertEntity> personCerts = certMap.get(co.getId());
if (CollectionUtils.isEmpty(personCerts)) {
continue;
}
for (OrgPersonnelCertEntity cert : personCerts) {
OrgPersonnelCertCO certCO = orgPersonnelCertConvertor.entityToCO(cert);
if (CertTypeCodeEnum.REGISTERED_SAFETY_ENGINEER.getCode().equals(cert.getCertTypeCode())) {
co.setRegisteredSafetyEngineerCert(certCO);
} else if (CertTypeCodeEnum.EVALUATOR.getCode().equals(cert.getCertTypeCode())) {
co.setEvaluatorCert(certCO);
}
}
}
}
@Override @Override
public SingleResponse<OrgPersonnelCO> updateOriginFace(OrgPersonnelUpdateOriginFaceCmd cmd) { public SingleResponse<OrgPersonnelCO> updateOriginFace(OrgPersonnelUpdateOriginFaceCmd cmd) {
OrgPersonnelEntity existing = orgPersonnelDomainService.get(cmd.getId()); OrgPersonnelEntity existing = orgPersonnelDomainService.get(cmd.getId());

View File

@ -1,25 +1,39 @@
package org.qinan.safetyeval.app.support; package org.qinan.safetyeval.app.support;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.qinan.safetyeval.client.co.OrgPersonnelCO; import org.qinan.safetyeval.client.co.OrgPersonnelCO;
import org.qinan.safetyeval.client.co.OrgPersonnelCertCO;
import org.qinan.safetyeval.client.co.OrgResignApplyCO; import org.qinan.safetyeval.client.co.OrgResignApplyCO;
import org.qinan.safetyeval.domain.constant.CertTypeCodeEnum;
import org.qinan.safetyeval.domain.constant.basic.IndustryEnum;
import org.qinan.safetyeval.domain.constant.basic.ProfessionalCapabilityEnum;
import org.qinan.safetyeval.domain.entity.*; import org.qinan.safetyeval.domain.entity.*;
import org.qinan.safetyeval.domain.gateway.*; import org.qinan.safetyeval.domain.gateway.*;
import org.qinan.safetyeval.domain.major.gateway.BasicDisciplineMajorGateway; import org.qinan.safetyeval.domain.major.gateway.BasicDisciplineMajorGateway;
import org.qinan.safetyeval.domain.major.model.BasicDisciplineMajorE; import org.qinan.safetyeval.domain.major.model.BasicDisciplineMajorE;
import org.qinan.safetyeval.domain.query.OrgPersonnelCertQuery; import org.qinan.safetyeval.domain.query.OrgPersonnelCertQuery;
import org.qinan.safetyeval.domain.query.PageResult; import org.qinan.safetyeval.domain.query.PageResult;
import org.qinan.safetyeval.domain.constant.basic.IndustryEnum;
import org.qinan.safetyeval.domain.constant.basic.ProfessionalCapabilityEnum;
import org.qinan.safetyeval.domain.standards.gateway.IndustryProfessionalStandardsGateway; import org.qinan.safetyeval.domain.standards.gateway.IndustryProfessionalStandardsGateway;
import org.qinan.safetyeval.domain.standards.model.IndustryProfessionalStandardsE; import org.qinan.safetyeval.domain.standards.model.IndustryProfessionalStandardsE;
import org.qinan.safetyeval.infrastructure.convertor.OrgPersonnelCertConvertor;
import org.qinan.safetyeval.infrastructure.dataobject.OrgDepartmentDO;
import org.qinan.safetyeval.infrastructure.dataobject.OrgPersonnelChangeDO;
import org.qinan.safetyeval.infrastructure.dataobject.OrgPositionDO;
import org.qinan.safetyeval.infrastructure.dataobject.OrgResignApplyDO;
import org.qinan.safetyeval.infrastructure.mapper.OrgDepartmentMapper;
import org.qinan.safetyeval.infrastructure.mapper.OrgPersonnelChangeMapper;
import org.qinan.safetyeval.infrastructure.mapper.OrgPositionMapper;
import org.qinan.safetyeval.infrastructure.mapper.OrgResignApplyMapper;
import org.qinan.safetyeval.infrastructure.persistence.domainobject.BasicDisciplineMajorDO;
import org.qinan.safetyeval.infrastructure.persistence.domainobject.IndustryProfessionalStandardsDO;
import org.qinan.safetyeval.infrastructure.persistence.mapper.BasicDisciplineMajorMapper;
import org.qinan.safetyeval.infrastructure.persistence.mapper.IndustryProfessionalStandardsMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -28,6 +42,8 @@ import java.util.stream.Collectors;
@Component @Component
public class OrgPersonnelViewEnricher { public class OrgPersonnelViewEnricher {
private static final int CERT_DISPLAY_LIMIT = 200;
@Autowired(required = false) @Autowired(required = false)
private OrgDepartmentGateway orgDepartmentGateway; private OrgDepartmentGateway orgDepartmentGateway;
@ -52,6 +68,27 @@ public class OrgPersonnelViewEnricher {
@Autowired(required = false) @Autowired(required = false)
private IndustryProfessionalStandardsGateway industryProfessionalStandardsGateway; private IndustryProfessionalStandardsGateway industryProfessionalStandardsGateway;
@Autowired(required = false)
private OrgDepartmentMapper orgDepartmentMapper;
@Autowired(required = false)
private OrgPositionMapper orgPositionMapper;
@Autowired(required = false)
private BasicDisciplineMajorMapper basicDisciplineMajorMapper;
@Autowired(required = false)
private OrgPersonnelChangeMapper orgPersonnelChangeMapper;
@Autowired(required = false)
private OrgResignApplyMapper orgResignApplyMapper;
@Autowired(required = false)
private IndustryProfessionalStandardsMapper industryProfessionalStandardsMapper;
@Autowired(required = false)
private OrgPersonnelCertConvertor orgPersonnelCertConvertor;
public void enrichPersonnel(OrgPersonnelCO co) { public void enrichPersonnel(OrgPersonnelCO co) {
if (co == null) { if (co == null) {
return; return;
@ -77,18 +114,119 @@ public class OrgPersonnelViewEnricher {
OrgPersonnelCertQuery certQuery = new OrgPersonnelCertQuery(); OrgPersonnelCertQuery certQuery = new OrgPersonnelCertQuery();
certQuery.setPersonnelId(co.getId()); certQuery.setPersonnelId(co.getId());
certQuery.setPageNum(1L); certQuery.setPageNum(1L);
certQuery.setPageSize(200L); certQuery.setPageSize((long) CERT_DISPLAY_LIMIT);
PageResult<OrgPersonnelCertEntity> certPage = orgPersonnelCertGateway.page(certQuery); PageResult<OrgPersonnelCertEntity> certPage = orgPersonnelCertGateway.page(certQuery);
String certNames = certPage.getRecords().stream() applyCertDisplayFields(co, certPage.getRecords());
}
enrichChangeSummary(co);
}
applyEmploymentDefault(co);
}
/**
* enrich {@link #enrichPersonnel(OrgPersonnelCO)} +
*/
public void enrichPersonnelBatch(List<OrgPersonnelCO> records) {
if (CollectionUtils.isEmpty(records)) {
return;
}
Set<Long> deptIds = new HashSet<>();
Set<Long> postIds = new HashSet<>();
Set<Long> majorIds = new HashSet<>();
List<Long> personnelIds = new ArrayList<>();
for (OrgPersonnelCO co : records) {
if (co == null) {
continue;
}
if (co.getDeptId() != null) {
deptIds.add(co.getDeptId());
}
if (co.getPostId() != null) {
postIds.add(co.getPostId());
}
if (co.getBasicDisciplineMajorId() != null) {
majorIds.add(co.getBasicDisciplineMajorId());
}
if (co.getId() != null) {
personnelIds.add(co.getId());
}
}
Map<Long, String> deptNameMap = loadDeptNameMap(deptIds);
Map<Long, String> postNameMap = loadPostNameMap(postIds);
Map<Long, String> majorNameMap = loadMajorNameMap(majorIds);
Map<Long, List<OrgPersonnelCertEntity>> certMap = loadCertMap(personnelIds);
Map<Long, Integer> changeCountMap = loadChangeCountMap(personnelIds);
Map<Long, List<OrgResignApplyEntity>> resignMap = loadResignMap(personnelIds);
Map<Long, String> standardsCodeCache = buildStandardsCodeCacheBatch(certMap.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toList()));
for (OrgPersonnelCO co : records) {
if (co == null) {
continue;
}
if (co.getDeptId() != null) {
co.setDeptName(deptNameMap.get(co.getDeptId()));
}
if (co.getPostId() != null) {
co.setPostName(postNameMap.get(co.getPostId()));
}
if (co.getBasicDisciplineMajorId() != null) {
co.setBasicDisciplineMajorName(majorNameMap.get(co.getBasicDisciplineMajorId()));
}
if (co.getId() != null) {
List<OrgPersonnelCertEntity> personCerts = certMap.getOrDefault(co.getId(), Collections.emptyList());
applyCertDisplayFields(co, limitCertsForDisplay(personCerts), standardsCodeCache);
applyNestedCerts(co, personCerts);
co.setChangeCount(changeCountMap.getOrDefault(co.getId(), 0));
applyResignDisplay(co, resignMap.get(co.getId()));
}
applyEmploymentDefault(co);
}
}
private void applyCertDisplayFields(OrgPersonnelCO co, List<OrgPersonnelCertEntity> records) {
applyCertDisplayFields(co, records, null);
}
private void applyCertDisplayFields(OrgPersonnelCO co, List<OrgPersonnelCertEntity> records,
Map<Long, String> standardsCodeCache) {
if (CollectionUtils.isEmpty(records)) {
co.setCertNames("");
co.setAbilityNames("");
return;
}
co.setCertNames(buildCertNames(records));
if (standardsCodeCache == null) {
standardsCodeCache = buildStandardsCodeCache(records);
}
co.setAbilityNames(buildAbilityNames(records, standardsCodeCache));
}
private List<OrgPersonnelCertEntity> limitCertsForDisplay(List<OrgPersonnelCertEntity> certs) {
if (CollectionUtils.isEmpty(certs)) {
return Collections.emptyList();
}
if (certs.size() <= CERT_DISPLAY_LIMIT) {
return certs;
}
return new ArrayList<>(certs.subList(0, CERT_DISPLAY_LIMIT));
}
private String buildCertNames(List<OrgPersonnelCertEntity> records) {
return records.stream()
.map(OrgPersonnelCertEntity::getCertName) .map(OrgPersonnelCertEntity::getCertName)
.filter(StringUtils::hasText) .filter(StringUtils::hasText)
.collect(Collectors.joining("、")); .collect(Collectors.joining("、"));
co.setCertNames(certNames); }
// 构建能力汇总: "专业范围:专业能力;专业范围:专业能力"
// 当 professionalCapabilityCode 为空时,尝试通过 industryProfessionalStandardsId 查标准表获取 private Map<Long, String> buildStandardsCodeCache(List<OrgPersonnelCertEntity> records) {
List<OrgPersonnelCertEntity> records = certPage.getRecords();
Map<Long, String> standardsCodeCache = new HashMap<>(); Map<Long, String> standardsCodeCache = new HashMap<>();
if (industryProfessionalStandardsGateway != null) { if (industryProfessionalStandardsGateway == null) {
return standardsCodeCache;
}
records.stream() records.stream()
.filter(c -> !StringUtils.hasText(c.getProfessionalCapabilityCode()) .filter(c -> !StringUtils.hasText(c.getProfessionalCapabilityCode())
&& c.getIndustryProfessionalStandardsId() != null) && c.getIndustryProfessionalStandardsId() != null)
@ -100,8 +238,11 @@ public class OrgPersonnelViewEnricher {
standardsCodeCache.put(sid, standards.getProfessionalCapabilityCode()); standardsCodeCache.put(sid, standards.getProfessionalCapabilityCode());
} }
}); });
return standardsCodeCache;
} }
String abilityNames = records.stream()
private String buildAbilityNames(List<OrgPersonnelCertEntity> records, Map<Long, String> standardsCodeCache) {
return records.stream()
.filter(c -> StringUtils.hasText(c.getBusinessScope())) .filter(c -> StringUtils.hasText(c.getBusinessScope()))
.map(c -> { .map(c -> {
String code = c.getProfessionalCapabilityCode(); String code = c.getProfessionalCapabilityCode();
@ -111,7 +252,6 @@ public class OrgPersonnelViewEnricher {
if (!StringUtils.hasText(code)) { if (!StringUtils.hasText(code)) {
return null; return null;
} }
// 转换 code 为中文名称
IndustryEnum industryEnum = IndustryEnum.ofCode(c.getBusinessScope()); IndustryEnum industryEnum = IndustryEnum.ofCode(c.getBusinessScope());
String scopeName = industryEnum != null ? industryEnum.getValue() : c.getBusinessScope(); String scopeName = industryEnum != null ? industryEnum.getValue() : c.getBusinessScope();
ProfessionalCapabilityEnum capEnum = ProfessionalCapabilityEnum.ofCode(code); ProfessionalCapabilityEnum capEnum = ProfessionalCapabilityEnum.ofCode(code);
@ -120,21 +260,139 @@ public class OrgPersonnelViewEnricher {
}) })
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.joining("")); .collect(Collectors.joining(""));
co.setAbilityNames(abilityNames);
} }
enrichChangeSummary(co);
private void applyNestedCerts(OrgPersonnelCO co, List<OrgPersonnelCertEntity> personCerts) {
if (orgPersonnelCertConvertor == null || CollectionUtils.isEmpty(personCerts)) {
return;
} }
if (co.getEmploymentStatusCode() == null) { for (OrgPersonnelCertEntity cert : personCerts) {
co.setEmploymentStatusCode(1); OrgPersonnelCertCO certCO = orgPersonnelCertConvertor.entityToCO(cert);
co.setEmploymentStatusName("在职"); if (CertTypeCodeEnum.REGISTERED_SAFETY_ENGINEER.getCode().equals(cert.getCertTypeCode())) {
co.setRegisteredSafetyEngineerCert(certCO);
} else if (CertTypeCodeEnum.EVALUATOR.getCode().equals(cert.getCertTypeCode())) {
co.setEvaluatorCert(certCO);
} }
} }
}
private Map<Long, String> loadDeptNameMap(Set<Long> deptIds) {
if (CollectionUtils.isEmpty(deptIds) || orgDepartmentMapper == null) {
return Collections.emptyMap();
}
return orgDepartmentMapper.selectBatchIds(deptIds).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(OrgDepartmentDO::getId, OrgDepartmentDO::getDeptName, (a, b) -> a));
}
private Map<Long, String> loadPostNameMap(Set<Long> postIds) {
if (CollectionUtils.isEmpty(postIds) || orgPositionMapper == null) {
return Collections.emptyMap();
}
return orgPositionMapper.selectBatchIds(postIds).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(OrgPositionDO::getId, OrgPositionDO::getPositionName, (a, b) -> a));
}
private Map<Long, String> loadMajorNameMap(Set<Long> majorIds) {
if (CollectionUtils.isEmpty(majorIds) || basicDisciplineMajorMapper == null) {
return Collections.emptyMap();
}
return basicDisciplineMajorMapper.selectBatchIds(majorIds).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(BasicDisciplineMajorDO::getId, BasicDisciplineMajorDO::getProfessionalName, (a, b) -> a));
}
private Map<Long, List<OrgPersonnelCertEntity>> loadCertMap(List<Long> personnelIds) {
if (CollectionUtils.isEmpty(personnelIds) || orgPersonnelCertGateway == null) {
return Collections.emptyMap();
}
List<OrgPersonnelCertEntity> certs = orgPersonnelCertGateway.listByPersonnelIds(personnelIds);
if (CollectionUtils.isEmpty(certs)) {
return Collections.emptyMap();
}
return certs.stream().collect(Collectors.groupingBy(OrgPersonnelCertEntity::getPersonnelId));
}
private Map<Long, Integer> loadChangeCountMap(List<Long> personnelIds) {
if (CollectionUtils.isEmpty(personnelIds) || orgPersonnelChangeMapper == null) {
return Collections.emptyMap();
}
LambdaQueryWrapper<OrgPersonnelChangeDO> wrapper = new LambdaQueryWrapper<>();
wrapper.select(OrgPersonnelChangeDO::getPersonnelId);
wrapper.in(OrgPersonnelChangeDO::getPersonnelId, personnelIds);
wrapper.eq(OrgPersonnelChangeDO::getDeleteEnum, "false");
List<OrgPersonnelChangeDO> changes = orgPersonnelChangeMapper.selectList(wrapper);
if (CollectionUtils.isEmpty(changes)) {
return Collections.emptyMap();
}
return changes.stream()
.collect(Collectors.groupingBy(OrgPersonnelChangeDO::getPersonnelId,
Collectors.collectingAndThen(Collectors.counting(), Long::intValue)));
}
private Map<Long, List<OrgResignApplyEntity>> loadResignMap(List<Long> personnelIds) {
if (CollectionUtils.isEmpty(personnelIds) || orgResignApplyMapper == null) {
return Collections.emptyMap();
}
LambdaQueryWrapper<OrgResignApplyDO> wrapper = new LambdaQueryWrapper<>();
wrapper.in(OrgResignApplyDO::getPersonnelId, personnelIds);
wrapper.eq(OrgResignApplyDO::getDeleteEnum, "false");
wrapper.orderByDesc(OrgResignApplyDO::getApplyTime);
wrapper.orderByDesc(OrgResignApplyDO::getId);
List<OrgResignApplyDO> applies = orgResignApplyMapper.selectList(wrapper);
if (CollectionUtils.isEmpty(applies)) {
return Collections.emptyMap();
}
Map<Long, List<OrgResignApplyEntity>> result = new LinkedHashMap<>();
for (OrgResignApplyDO apply : applies) {
result.computeIfAbsent(apply.getPersonnelId(), key -> new ArrayList<>()).add(toResignEntity(apply));
}
return result;
}
private OrgResignApplyEntity toResignEntity(OrgResignApplyDO dataObject) {
OrgResignApplyEntity entity = new OrgResignApplyEntity();
entity.setId(dataObject.getId());
entity.setPersonnelId(dataObject.getPersonnelId());
entity.setAuditStatusCode(dataObject.getAuditStatusCode());
return entity;
}
private Map<Long, String> buildStandardsCodeCacheBatch(List<OrgPersonnelCertEntity> allCerts) {
Map<Long, String> standardsCodeCache = new HashMap<>();
if (CollectionUtils.isEmpty(allCerts) || industryProfessionalStandardsMapper == null) {
return standardsCodeCache;
}
Set<Long> standardsIds = allCerts.stream()
.filter(c -> !StringUtils.hasText(c.getProfessionalCapabilityCode())
&& c.getIndustryProfessionalStandardsId() != null)
.map(OrgPersonnelCertEntity::getIndustryProfessionalStandardsId)
.collect(Collectors.toSet());
if (CollectionUtils.isEmpty(standardsIds)) {
return standardsCodeCache;
}
List<IndustryProfessionalStandardsDO> standardsList = industryProfessionalStandardsMapper.selectBatchIds(standardsIds);
if (CollectionUtils.isEmpty(standardsList)) {
return standardsCodeCache;
}
for (IndustryProfessionalStandardsDO standards : standardsList) {
if (standards != null && StringUtils.hasText(standards.getProfessionalCapabilityCode())) {
standardsCodeCache.put(standards.getId(), standards.getProfessionalCapabilityCode());
}
}
return standardsCodeCache;
}
private void enrichChangeSummary(OrgPersonnelCO co) { private void enrichChangeSummary(OrgPersonnelCO co) {
List<OrgPersonnelChangeEntity> changes = orgPersonnelChangeGateway != null ? orgPersonnelChangeGateway.listByPersonnelId(co.getId()) : null; List<OrgPersonnelChangeEntity> changes = orgPersonnelChangeGateway != null ? orgPersonnelChangeGateway.listByPersonnelId(co.getId()) : null;
co.setChangeCount(changes != null ? changes.size() : 0); co.setChangeCount(changes != null ? changes.size() : 0);
List<OrgResignApplyEntity> applies = orgResignApplyGateway != null ? orgResignApplyGateway.listByPersonnelId(co.getId()) : null; List<OrgResignApplyEntity> applies = orgResignApplyGateway != null ? orgResignApplyGateway.listByPersonnelId(co.getId()) : null;
applyResignDisplay(co, applies);
}
private void applyResignDisplay(OrgPersonnelCO co, List<OrgResignApplyEntity> applies) {
if (applies == null || applies.isEmpty()) { if (applies == null || applies.isEmpty()) {
return; return;
} }
@ -146,6 +404,13 @@ public class OrgPersonnelViewEnricher {
co.setResignAuditStatus(displayApply.getAuditStatusCode() != null ? displayApply.getAuditStatusCode() : 0); co.setResignAuditStatus(displayApply.getAuditStatusCode() != null ? displayApply.getAuditStatusCode() : 0);
} }
private void applyEmploymentDefault(OrgPersonnelCO co) {
if (co.getEmploymentStatusCode() == null) {
co.setEmploymentStatusCode(1);
co.setEmploymentStatusName("在职");
}
}
public void enrichResignApply(OrgResignApplyCO co) { public void enrichResignApply(OrgResignApplyCO co) {
if (co == null) { if (co == null) {
return; return;