From 481d8165f26fc7e37f0e87f6444ac0340bb563a3 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期二, 03 十一月 2026 18:53:22 +0800
Subject: [PATCH] fix: 移植长辉已验证的四类接口 500/体验问题(不含物料颜色字段)

---
 yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/supplier/SrmSupplierServiceImpl.java |  116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 114 insertions(+), 2 deletions(-)

diff --git a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/supplier/SrmSupplierServiceImpl.java b/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/supplier/SrmSupplierServiceImpl.java
index de712dc..805774f 100644
--- a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/supplier/SrmSupplierServiceImpl.java
+++ b/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/supplier/SrmSupplierServiceImpl.java
@@ -1,21 +1,40 @@
 package cn.iocoder.yudao.module.srm.service.supplier;
 
+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.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.module.srm.controller.admin.supplier.vo.SrmSupplierImportExcelVO;
+import cn.iocoder.yudao.module.srm.controller.admin.supplier.vo.SrmSupplierImportReqVO;
+import cn.iocoder.yudao.module.srm.controller.admin.supplier.vo.SrmSupplierImportRespVO;
 import cn.iocoder.yudao.module.srm.controller.admin.supplier.vo.SrmSupplierPageReqVO;
 import cn.iocoder.yudao.module.srm.controller.admin.supplier.vo.SrmSupplierSaveReqVO;
-import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierDO;
+import cn.iocoder.yudao.module.srm.dal.dataobject.*;
+import cn.iocoder.yudao.module.srm.dal.mysql.SrmBidAwardMapper;
+import cn.iocoder.yudao.module.srm.dal.mysql.SrmBidEvaluationMapper;
+import cn.iocoder.yudao.module.srm.dal.mysql.SrmSupplierApplyMapper;
 import cn.iocoder.yudao.module.srm.dal.mysql.SrmSupplierCategoryMapper;
 import cn.iocoder.yudao.module.srm.dal.mysql.SrmSupplierContactMapper;
+import cn.iocoder.yudao.module.srm.dal.mysql.SrmSupplierCertificateMapper;
 import cn.iocoder.yudao.module.srm.dal.mysql.SrmSupplierMapper;
+import cn.iocoder.yudao.module.srm.dal.mysql.SrmTenderBidMapper;
 import cn.iocoder.yudao.module.srm.enums.ErrorCodeConstants;
 import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
+import org.springframework.transaction.annotation.Transactional;
 
+import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
+
+import cn.hutool.core.collection.CollUtil;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
 
 @Service
 @Validated
@@ -29,6 +48,21 @@
 
     @Resource
     private SrmSupplierCategoryMapper supplierCategoryMapper;
+
+    @Resource
+    private SrmSupplierApplyMapper supplierApplyMapper;
+
+    @Resource
+    private SrmSupplierCertificateMapper supplierCertificateMapper;
+
+    @Resource
+    private SrmTenderBidMapper tenderBidMapper;
+
+    @Resource
+    private SrmBidEvaluationMapper bidEvaluationMapper;
+
+    @Resource
+    private SrmBidAwardMapper bidAwardMapper;
 
     @Override
     public Long createSupplier(SrmSupplierSaveReqVO createReqVO) {
@@ -52,10 +86,13 @@
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void deleteSupplier(Long id) {
         // 鏍¢獙瀛樺湪鎬�
         validateSupplierExists(id);
-        // 鍒犻櫎鍏宠仈鏁版嵁
+        // 鍏宠仈鏁版嵁瀛樺湪鏃讹紝涓嶅厑璁稿垹闄�
+        validateNoReference(id);
+        // 鍙洿鎺ユ竻鐞嗙殑鍏宠仈鏁版嵁
         supplierContactMapper.deleteBySupplierId(id);
         supplierCategoryMapper.deleteBySupplierId(id);
         // 閫昏緫鍒犻櫎
@@ -78,8 +115,72 @@
     }
 
     @Override
+    public List<SrmSupplierDO> getSupplierAllList() {
+        return supplierMapper.selectList(new LambdaQueryWrapperX<SrmSupplierDO>()
+                .orderByAsc(SrmSupplierDO::getId));
+    }
+
+    @Override
     public List<SrmSupplierDO> getSupplierList(Collection<Long> ids) {
+        if (CollUtil.isEmpty(ids)) {
+            return Collections.emptyList();
+        }
         return supplierMapper.selectBatchIds(ids);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public SrmSupplierImportRespVO importSupplierList(List<SrmSupplierImportExcelVO> importSuppliers,
+                                                     SrmSupplierImportReqVO importReqVO) {
+        // 1. 鏍¢獙闈炵┖
+        importSuppliers = CollectionUtils.filterList(importSuppliers,
+                item -> StrUtil.isNotBlank(item.getName()));
+        if (CollUtil.isEmpty(importSuppliers)) {
+            throw ServiceExceptionUtil.exception(ErrorCodeConstants.SUPPLIER_IMPORT_LIST_IS_EMPTY);
+        }
+
+        // 2. 閫愭潯澶勭悊
+        SrmSupplierImportRespVO respVO = SrmSupplierImportRespVO.builder()
+                .createSupplierNames(new ArrayList<>())
+                .updateSupplierNames(new ArrayList<>())
+                .failureSupplierNames(new LinkedHashMap<>())
+                .build();
+        importSuppliers.forEach(importSupplier -> {
+            try {
+                // 2.1 鏍¢獙缂栫爜
+                if (StrUtil.isBlank(importSupplier.getCode())) {
+                    throw ServiceExceptionUtil.exception(ErrorCodeConstants.SUPPLIER_IMPORT_CODE_REQUIRED);
+                }
+                // 2.2 鍒ゆ柇鏄惁瀛樺湪
+                SrmSupplierDO existSupplier = supplierMapper.selectByCode(importSupplier.getCode());
+                if (existSupplier == null) {
+                    // 2.2.1 鏂板
+                    SrmSupplierDO supplier = BeanUtils.toBean(importSupplier, SrmSupplierDO.class);
+                    if (supplier.getStatus() == null) {
+                        supplier.setStatus(0);
+                    }
+                    supplierMapper.insert(supplier);
+                    respVO.getCreateSupplierNames().add(importSupplier.getName());
+                    return;
+                }
+                // 2.2.2 宸插瓨鍦紝鍒ゆ柇鏄惁鍏佽鏇存柊
+                if (!importReqVO.getUpdateSupport()) {
+                    respVO.getFailureSupplierNames().put(importSupplier.getName(),
+                            StrUtil.format(ErrorCodeConstants.SUPPLIER_IMPORT_CODE_EXISTS.getMsg(), importSupplier.getCode()));
+                    return;
+                }
+                SrmSupplierDO updateSupplier = BeanUtils.toBean(importSupplier, SrmSupplierDO.class)
+                        .setId(existSupplier.getId());
+                if (updateSupplier.getStatus() == null) {
+                    updateSupplier.setStatus(existSupplier.getStatus());
+                }
+                supplierMapper.updateById(updateSupplier);
+                respVO.getUpdateSupplierNames().add(importSupplier.getName());
+            } catch (ServiceException ex) {
+                respVO.getFailureSupplierNames().put(importSupplier.getName(), ex.getMessage());
+            }
+        });
+        return respVO;
     }
 
     // ========== 鏍¢獙鏂规硶 ==========
@@ -97,4 +198,15 @@
         }
     }
 
+    private void validateNoReference(Long id) {
+        boolean hasReference = supplierApplyMapper.existsApprovedBySupplierId(id)
+                || supplierCertificateMapper.selectCount(SrmSupplierCertificateDO::getSupplierId, id) > 0
+                || tenderBidMapper.selectCount(SrmTenderBidDO::getSupplierId, id) > 0
+                || bidEvaluationMapper.selectCount(SrmBidEvaluationDO::getSupplierId, id) > 0
+                || bidAwardMapper.selectCount(SrmBidAwardDO::getSupplierId, id) > 0;
+        if (hasReference) {
+            throw ServiceExceptionUtil.exception(ErrorCodeConstants.SUPPLIER_EXISTS_REFERENCE);
+        }
+    }
+
 }

--
Gitblit v1.9.3