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/salary/HrmEmployeeSocialSecurityServiceImpl.java |   92 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 90 insertions(+), 2 deletions(-)

diff --git a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmEmployeeSocialSecurityServiceImpl.java b/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmEmployeeSocialSecurityServiceImpl.java
index a2cf5d0..9663732 100644
--- a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmEmployeeSocialSecurityServiceImpl.java
+++ b/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmEmployeeSocialSecurityServiceImpl.java
@@ -1,23 +1,37 @@
 package cn.iocoder.yudao.module.hrm.service.salary;
 
+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.salary.vo.HrmEmployeeSocialSecurityImportExcelVO;
+import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmEmployeeSocialSecurityImportReqVO;
+import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmEmployeeSocialSecurityImportRespVO;
 import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmEmployeeSocialSecurityPageReqVO;
+import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.HrmEmployeeDO;
 import cn.iocoder.yudao.module.hrm.dal.dataobject.salary.HrmEmployeeSocialSecurityDO;
+import cn.iocoder.yudao.module.hrm.dal.dataobject.salary.HrmSocialSecuritySchemeDO;
+import cn.iocoder.yudao.module.hrm.dal.mysql.employee.HrmEmployeeMapper;
 import cn.iocoder.yudao.module.hrm.dal.mysql.salary.HrmEmployeeSocialSecurityMapper;
+import cn.iocoder.yudao.module.hrm.dal.mysql.salary.HrmSocialSecuritySchemeMapper;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
+import java.util.ArrayList;
+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.EMPLOYEE_SOCIAL_SECURITY_NOT_EXISTS;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
+import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.*;
 
 /**
  * 鍛樺伐绀句繚鍏Н閲戞。妗� Service 瀹炵幇绫�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Service
 @Validated
@@ -25,6 +39,10 @@
 
     @Resource
     private HrmEmployeeSocialSecurityMapper employeeSocialSecurityMapper;
+    @Resource
+    private HrmEmployeeMapper employeeMapper;
+    @Resource
+    private HrmSocialSecuritySchemeMapper schemeMapper;
 
     @Override
     public Long createEmployeeSocialSecurity(HrmEmployeeSocialSecurityDO socialSecurity) {
@@ -78,4 +96,74 @@
         }
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public HrmEmployeeSocialSecurityImportRespVO importEmployeeSocialSecurityList(
+            List<HrmEmployeeSocialSecurityImportExcelVO> importList, HrmEmployeeSocialSecurityImportReqVO importReqVO) {
+        // 1. 鏍¢獙闈炵┖
+        importList = filterList(importList, item -> StrUtil.isNotBlank(item.getEmployeeName()));
+        if (CollUtil.isEmpty(importList)) {
+            throw exception(EMPLOYEE_SOCIAL_SECURITY_IMPORT_LIST_IS_EMPTY);
+        }
+        // 2. 閫愭潯澶勭悊
+        HrmEmployeeSocialSecurityImportRespVO respVO = HrmEmployeeSocialSecurityImportRespVO.builder()
+                .createNames(new ArrayList<>())
+                .updateNames(new ArrayList<>())
+                .failureNames(new LinkedHashMap<>())
+                .build();
+        importList.forEach(importSocialSecurity -> {
+            try {
+                // 2.1 瑙f瀽鍛樺伐
+                HrmEmployeeDO employee = employeeMapper.selectByName(importSocialSecurity.getEmployeeName());
+                if (employee == null) {
+                    throw exception(EMPLOYEE_SOCIAL_SECURITY_EMPLOYEE_NOT_EXISTS, importSocialSecurity.getEmployeeName());
+                }
+                // 2.2 瑙f瀽鏂规
+                Long schemeId = null;
+                if (StrUtil.isNotBlank(importSocialSecurity.getSchemeName())) {
+                    HrmSocialSecuritySchemeDO scheme = schemeMapper.selectByName(importSocialSecurity.getSchemeName());
+                    if (scheme == null) {
+                        throw exception(EMPLOYEE_SOCIAL_SECURITY_SCHEME_NOT_EXISTS, importSocialSecurity.getSchemeName());
+                    }
+                    schemeId = scheme.getId();
+                }
+                // 2.3 鐢熸晥鏃ユ湡蹇呭~
+                if (importSocialSecurity.getEffectiveDate() == null) {
+                    respVO.getFailureNames().put(importSocialSecurity.getEmployeeName(), "鐢熸晥鏃ユ湡涓嶈兘涓虹┖");
+                    return;
+                }
+                // 2.4 鍒ゆ柇鏄惁瀛樺湪锛堟寜鍛樺伐+鐢熸晥鏃ユ湡鍞竴锛�
+                HrmEmployeeSocialSecurityDO existSocialSecurity = employeeSocialSecurityMapper
+                        .selectByUserIdAndEffectiveDate(employee.getId(), importSocialSecurity.getEffectiveDate());
+                if (existSocialSecurity == null) {
+                    // 2.4.1 鏂板
+                    HrmEmployeeSocialSecurityDO socialSecurity = BeanUtils.toBean(importSocialSecurity, HrmEmployeeSocialSecurityDO.class)
+                            .setUserId(employee.getId()).setSocialSecuritySchemeId(schemeId);
+                    if (socialSecurity.getStatus() == null) {
+                        socialSecurity.setStatus(0);
+                    }
+                    employeeSocialSecurityMapper.insert(socialSecurity);
+                    respVO.getCreateNames().add(importSocialSecurity.getEmployeeName());
+                    return;
+                }
+                // 2.4.2 宸插瓨鍦紝鍒ゆ柇鏄惁鍏佽鏇存柊
+                if (!importReqVO.getUpdateSupport()) {
+                    respVO.getFailureNames().put(importSocialSecurity.getEmployeeName(),
+                            StrUtil.format(EMPLOYEE_SOCIAL_SECURITY_EXISTS.getMsg(), importSocialSecurity.getEmployeeName()));
+                    return;
+                }
+                HrmEmployeeSocialSecurityDO updateSocialSecurity = BeanUtils.toBean(importSocialSecurity, HrmEmployeeSocialSecurityDO.class)
+                        .setId(existSocialSecurity.getId()).setUserId(employee.getId()).setSocialSecuritySchemeId(schemeId);
+                if (updateSocialSecurity.getStatus() == null) {
+                    updateSocialSecurity.setStatus(0);
+                }
+                employeeSocialSecurityMapper.updateById(updateSocialSecurity);
+                respVO.getUpdateNames().add(importSocialSecurity.getEmployeeName());
+            } catch (ServiceException ex) {
+                respVO.getFailureNames().put(importSocialSecurity.getEmployeeName(), ex.getMessage());
+            }
+        });
+        return respVO;
+    }
+
 }

--
Gitblit v1.9.3