dev-tmp1
luotaiqian 2026-08-19 10:32:42 +08:00
parent f47700a51e
commit 81083e45b2
2 changed files with 46 additions and 12 deletions

View File

@ -5,6 +5,7 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.jjb.saas.system.client.user.request.RoleDeptAddCmd;
import com.jjb.saas.system.client.user.request.UserAddCmd;
@ -30,12 +31,16 @@ import org.qinan.safetyeval.domain.major.model.BasicDisciplineMajorE;
import org.qinan.safetyeval.domain.service.OrgPersonnelDomainService;
import org.qinan.safetyeval.infrastructure.adapter.ThreadLocalUserInfoAdapter;
import org.qinan.safetyeval.infrastructure.convertor.BasicDisciplineMajorDoConvertor;
import org.qinan.safetyeval.infrastructure.convertor.OrgPersonnelCertConvertor;
import org.qinan.safetyeval.infrastructure.dataobject.OrgPersonnelCertDO;
import org.qinan.safetyeval.infrastructure.mapper.OrgPersonnelCertMapper;
import org.qinan.safetyeval.infrastructure.remote.SystemRemote;
import org.qinan.safetyeval.infrastructure.support.InsertFieldDefaults;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
@ -83,6 +88,15 @@ public class OrgPersonnelExcelImporter {
@Resource
private OrgPersonnelDomainService orgPersonnelDomainService;
@Resource
private OrgPersonnelCertMapper orgPersonnelCertMapper;
@Resource
private OrgPersonnelCertConvertor orgPersonnelCertConvertor;
@Resource
private TransactionTemplate transactionTemplate;
@Resource
private SystemRemote systemRemote;
@ -171,11 +185,10 @@ public class OrgPersonnelExcelImporter {
int successCount = 0;
for (OrgPersonnelImportRow row : rows) {
String account = trim(row.getBasic().getAccount());
// 账号在库中已存在 -> 跳过该行,记录异常
if (existingAccounts.contains(account)) {
errors.add(new OrgPersonnelImportErrorCO(row.getBasic().getRowIndex(), account, trim(row.getBasic().getUserName()),
"账号已存在,跳过该行"));
errors.add(new OrgPersonnelImportErrorCO(row.getBasic().getRowIndex()
, account, row.getBasic().getUserName(), "账号已存在,跳过该行"));
continue;
}
@ -185,11 +198,19 @@ public class OrgPersonnelExcelImporter {
// 行内枚举/数据校验未通过,已记录异常
continue;
}
List<OrgPersonnelCertEntity> personnelCertEntities = buildOrgPersonnelCert(row, orgId, errors, personnelEntity);
List<OrgPersonnelCertDO> personnelCertEntities = buildOrgPersonnelCert(row, errors, personnelEntity);
Long userId = addUserIfAbsentAndAppendRole(personnelEntity);
personnelEntity.setId(userId);
orgPersonnelDomainService.add(personnelEntity);
transactionTemplate.execute(status -> {
orgPersonnelDomainService.add(personnelEntity);
if (!CollectionUtils.isEmpty(personnelCertEntities)) {
Db.saveBatch(personnelCertEntities);
}
return null;
});
successCount++;
} catch (Exception ex) {
LOGGER.warn("导入人员落库失败, rowIndex={}, account={}", row.getBasic().getRowIndex(), account, ex);
@ -204,17 +225,25 @@ public class OrgPersonnelExcelImporter {
/**
*
* @param row row
* @param orgId orgId
* @param errors errors
* @param personnelEntity personnelEntity
* @return OrgPersonnelCertEntity
*/
private List<OrgPersonnelCertEntity> buildOrgPersonnelCert(OrgPersonnelImportRow row
, Long orgId, List<OrgPersonnelImportErrorCO> errors, OrgPersonnelEntity personnelEntity) {
if (row.getCapability() == null) {
private List<OrgPersonnelCertDO> buildOrgPersonnelCert(OrgPersonnelImportRow row
, List<OrgPersonnelImportErrorCO> errors, OrgPersonnelEntity personnelEntity) {
List<OrgPersonnelCertEntity> personnelCertEntities = row.getBasic().getPersonnelCertEntities();
if (CollectionUtils.isEmpty(personnelCertEntities)) {
return Collections.emptyList();
}
return null;
List<OrgPersonnelCertDO> orgPersonnelCertDOList = new ArrayList<>(personnelCertEntities.size());
for (OrgPersonnelCertEntity personnelCertEntity : personnelCertEntities) {
personnelCertEntity.setPersonnelId(personnelEntity.getId());
OrgPersonnelCertDO orgPersonnelCertDO = orgPersonnelCertConvertor.entityToDO(personnelCertEntity);
orgPersonnelCertDO.setOrgId(personnelCertEntity.getOrgId());
orgPersonnelCertDOList.add(orgPersonnelCertDO);
}
return orgPersonnelCertDOList;
}
/**
@ -578,7 +607,7 @@ public class OrgPersonnelExcelImporter {
cert.setCertCategoryCode(categoryEnum.getIndustry().getCode());
cert.setCertNo(certNo);
cert.setPractisingCertCode(practiceCertNo);
InsertFieldDefaults.applyIgnoreOrgId(cert);
InsertFieldDefaults.apply(cert);
return cert;
}
@ -638,7 +667,7 @@ public class OrgPersonnelExcelImporter {
// 注安等级编码同证书等级SENIOR/MIDDLE/JUNIOR
cert.setCertLevel(levelEnum.getCode());
cert.setCertNo(certNo);
InsertFieldDefaults.applyIgnoreOrgId(cert);
InsertFieldDefaults.apply(cert);
return cert;
}
@ -1118,6 +1147,7 @@ public class OrgPersonnelExcelImporter {
entity.setProcessControlLeaderFlag(YES.equals(basic.getProcessControlLeader()));
// 能力认证一/二、注安证书、评价师证书、高级工程师等
entity.setCapabilityAssessment(basic.getCapabilityAssessment());
entity.setTitleCodeArr(basic.getTitleCodeArr());
return entity;
}

View File

@ -9,6 +9,8 @@ import org.qinan.safetyeval.client.dto.OrgPersonnelCertModifyCmd;
import org.qinan.safetyeval.domain.entity.OrgPersonnelCertEntity;
import org.qinan.safetyeval.infrastructure.dataobject.OrgPersonnelCertDO;
import java.util.List;
/**
* Cmd/Entity/CO/DO
*
@ -29,4 +31,6 @@ public interface OrgPersonnelCertConvertor {
@Mapping(target = "orgId", ignore = true)
OrgPersonnelCertDO entityToDO(OrgPersonnelCertEntity entity);
List<OrgPersonnelCertDO> entityToDOList(List<OrgPersonnelCertEntity> entities);
}