From d54fbc9d4f8981fa0f7f613b33a28a8cd4f764ea Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期日, 25 十月 2026 16:29:53 +0800
Subject: [PATCH] feat(system): 优化用户搜索功能并完善ERP和MES模块验证逻辑

---
 yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/certificate/HrmCertificateServiceImpl.java |   70 ++++++++++++++++++++++++++++++++++-
 1 files changed, 68 insertions(+), 2 deletions(-)

diff --git a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/certificate/HrmCertificateServiceImpl.java b/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/certificate/HrmCertificateServiceImpl.java
index 3ca256f..36b2dca 100644
--- a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/certificate/HrmCertificateServiceImpl.java
+++ b/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/certificate/HrmCertificateServiceImpl.java
@@ -1,22 +1,32 @@
 package cn.iocoder.yudao.module.hrm.service.certificate;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.hrm.controller.admin.certificate.vo.HrmCertificateImportExcelVO;
+import cn.iocoder.yudao.module.hrm.controller.admin.certificate.vo.HrmCertificateImportReqVO;
+import cn.iocoder.yudao.module.hrm.controller.admin.certificate.vo.HrmCertificateImportRespVO;
 import cn.iocoder.yudao.module.hrm.controller.admin.certificate.vo.HrmCertificatePageReqVO;
 import cn.iocoder.yudao.module.hrm.controller.admin.certificate.vo.HrmCertificateSaveReqVO;
 import cn.iocoder.yudao.module.hrm.dal.dataobject.certificate.HrmCertificateDO;
+import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.HrmEmployeeDO;
 import cn.iocoder.yudao.module.hrm.dal.mysql.certificate.HrmCertificateMapper;
+import cn.iocoder.yudao.module.hrm.dal.mysql.employee.HrmEmployeeMapper;
 import cn.iocoder.yudao.module.hrm.service.employee.HrmEmployeeService;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
-import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.HRM_CERTIFICATE_NOT_EXISTS;
-import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.HRM_EMPLOYEE_NOT_EXISTS;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
+import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.*;
 
 /**
  * HRM 璇佷功璧勮川 Service 瀹炵幇绫�
@@ -31,6 +41,8 @@
     private HrmCertificateMapper certificateMapper;
     @Resource
     private HrmEmployeeService employeeService;
+    @Resource
+    private HrmEmployeeMapper employeeMapper;
 
     @Override
     public Long createCertificate(HrmCertificateSaveReqVO createReqVO) {
@@ -80,4 +92,58 @@
         }
     }
 
+    @Override
+    public HrmCertificateImportRespVO importCertificateList(
+            List<HrmCertificateImportExcelVO> importList, HrmCertificateImportReqVO importReqVO) {
+        // 1. 鏍¢獙闈炵┖
+        importList = filterList(importList, item -> StrUtil.isNotBlank(item.getCertName()));
+        if (CollUtil.isEmpty(importList)) {
+            throw exception(CERTIFICATE_IMPORT_LIST_IS_EMPTY);
+        }
+        // 2. 閫愭潯澶勭悊
+        HrmCertificateImportRespVO respVO = HrmCertificateImportRespVO.builder()
+                .createNames(new ArrayList<>())
+                .updateNames(new ArrayList<>())
+                .failureNames(new LinkedHashMap<>())
+                .build();
+        importList.forEach(importCertificate -> {
+            try {
+                // 2.1 瑙f瀽鍛樺伐
+                if (StrUtil.isBlank(importCertificate.getEmployeeName())) {
+                    respVO.getFailureNames().put(importCertificate.getCertName(), "鍛樺伐濮撳悕涓嶈兘涓虹┖");
+                    return;
+                }
+                HrmEmployeeDO employee = employeeMapper.selectByName(importCertificate.getEmployeeName());
+                if (employee == null) {
+                    throw exception(CERTIFICATE_EMPLOYEE_NOT_EXISTS, importCertificate.getEmployeeName());
+                }
+                // 2.2 鍒ゆ柇鏄惁瀛樺湪锛堟寜鍛樺伐+璇佷功缂栧彿鎴栧憳宸�+璇佷功鍚嶇О鍞竴锛�
+                HrmCertificateDO existCertificate = StrUtil.isNotBlank(importCertificate.getCertNo())
+                        ? certificateMapper.selectByEmployeeIdAndCertNo(employee.getId(), importCertificate.getCertNo())
+                        : certificateMapper.selectByEmployeeIdAndCertName(employee.getId(), importCertificate.getCertName());
+                if (existCertificate == null) {
+                    // 2.2.1 鏂板
+                    HrmCertificateDO certificate = BeanUtils.toBean(importCertificate, HrmCertificateDO.class)
+                            .setEmployeeId(employee.getId());
+                    certificateMapper.insert(certificate);
+                    respVO.getCreateNames().add(importCertificate.getCertName());
+                    return;
+                }
+                // 2.2.2 宸插瓨鍦紝鍒ゆ柇鏄惁鍏佽鏇存柊
+                if (!importReqVO.getUpdateSupport()) {
+                    respVO.getFailureNames().put(importCertificate.getCertName(),
+                            StrUtil.format(CERTIFICATE_EXISTS.getMsg(), importCertificate.getCertName()));
+                    return;
+                }
+                HrmCertificateDO updateCertificate = BeanUtils.toBean(importCertificate, HrmCertificateDO.class)
+                        .setId(existCertificate.getId()).setEmployeeId(employee.getId());
+                certificateMapper.updateById(updateCertificate);
+                respVO.getUpdateNames().add(importCertificate.getCertName());
+            } catch (ServiceException ex) {
+                respVO.getFailureNames().put(importCertificate.getCertName(), ex.getMessage());
+            }
+        });
+        return respVO;
+    }
+
 }

--
Gitblit v1.9.3