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/certificate/SrmSupplierCertificateServiceImpl.java |   93 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/certificate/SrmSupplierCertificateServiceImpl.java b/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/certificate/SrmSupplierCertificateServiceImpl.java
index 7dddd49..795baab 100644
--- a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/certificate/SrmSupplierCertificateServiceImpl.java
+++ b/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/certificate/SrmSupplierCertificateServiceImpl.java
@@ -1,46 +1,81 @@
 package cn.iocoder.yudao.module.srm.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.collection.CollectionUtils;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.srm.controller.admin.certificate.vo.SrmSupplierCertificateImportExcelVO;
+import cn.iocoder.yudao.module.srm.controller.admin.certificate.vo.SrmSupplierCertificateImportReqVO;
+import cn.iocoder.yudao.module.srm.controller.admin.certificate.vo.SrmSupplierCertificateImportRespVO;
 import cn.iocoder.yudao.module.srm.controller.admin.certificate.vo.SrmSupplierCertificatePageReqVO;
 import cn.iocoder.yudao.module.srm.controller.admin.certificate.vo.SrmSupplierCertificateSaveReqVO;
 import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierCertificateDO;
+import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierDO;
 import cn.iocoder.yudao.module.srm.dal.mysql.SrmSupplierCertificateMapper;
+import cn.iocoder.yudao.module.srm.dal.mysql.SrmSupplierMapper;
 import cn.iocoder.yudao.module.srm.enums.ErrorCodeConstants;
 import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
+import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
 import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
 
 @Service
 @Validated
 public class SrmSupplierCertificateServiceImpl implements SrmSupplierCertificateService {
 
+    /**
+     * 璧勮川璇佷功闄勪欢鐨勪笟鍔¤褰曠被鍨嬶紝瀵瑰簲 {@link cn.iocoder.yudao.module.system.enums.storage.StorageRecordTypeEnum#SRM_SUPPLIER_CERTIFICATE}
+     */
+    public static final String CERTIFICATE_RECORD_TYPE = "srm_supplier_certificate";
+
     @Resource
     private SrmSupplierCertificateMapper certificateMapper;
 
+    @Resource
+    private SrmSupplierMapper supplierMapper;
+
+    @Resource
+    private StorageAttachmentApi storageAttachmentApi;
+
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Long createCertificate(SrmSupplierCertificateSaveReqVO createReqVO) {
         SrmSupplierCertificateDO certificate = BeanUtils.toBean(createReqVO, SrmSupplierCertificateDO.class);
         updateStatus(certificate);
         certificateMapper.insert(certificate);
+        // 缁戝畾璇佷功闄勪欢
+        if (CollUtil.isNotEmpty(createReqVO.getBlobIds())) {
+            storageAttachmentApi.bindAttachments("file", CERTIFICATE_RECORD_TYPE, certificate.getId(), createReqVO.getBlobIds());
+        }
         return certificate.getId();
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void updateCertificate(SrmSupplierCertificateSaveReqVO updateReqVO) {
         validateCertificateExists(updateReqVO.getId());
         SrmSupplierCertificateDO updateObj = BeanUtils.toBean(updateReqVO, SrmSupplierCertificateDO.class);
         updateStatus(updateObj);
         certificateMapper.updateById(updateObj);
+        // 澧為噺鏇存柊璇佷功闄勪欢
+        storageAttachmentApi.updateAttachments("file", CERTIFICATE_RECORD_TYPE, updateReqVO.getId(), updateReqVO.getBlobIds());
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void deleteCertificate(Long id) {
         validateCertificateExists(id);
+        // 鍒犻櫎璇佷功闄勪欢
+        storageAttachmentApi.deleteAttachmentsByRecord(CERTIFICATE_RECORD_TYPE, id);
         certificateMapper.deleteById(id);
     }
 
@@ -65,6 +100,64 @@
         return certificateMapper.selectExpiringList(now, now.plusDays(30));
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public SrmSupplierCertificateImportRespVO importCertificateList(List<SrmSupplierCertificateImportExcelVO> importCertificates,
+                                                                    SrmSupplierCertificateImportReqVO importReqVO) {
+        // 1. 鏍¢獙闈炵┖
+        importCertificates = CollectionUtils.filterList(importCertificates,
+                item -> StrUtil.isNotBlank(item.getCertificateName()));
+        if (CollUtil.isEmpty(importCertificates)) {
+            throw ServiceExceptionUtil.exception(ErrorCodeConstants.CERTIFICATE_IMPORT_LIST_IS_EMPTY);
+        }
+
+        // 2. 閫愭潯澶勭悊
+        SrmSupplierCertificateImportRespVO respVO = SrmSupplierCertificateImportRespVO.builder()
+                .createCertificateNames(new ArrayList<>())
+                .updateCertificateNames(new ArrayList<>())
+                .failureCertificateNames(new LinkedHashMap<>())
+                .build();
+        importCertificates.forEach(importCertificate -> {
+            try {
+                // 2.1 瑙f瀽渚涘簲鍟�
+                if (StrUtil.isBlank(importCertificate.getSupplierName())) {
+                    throw ServiceExceptionUtil.exception(ErrorCodeConstants.CERTIFICATE_IMPORT_SUPPLIER_NAME_REQUIRED);
+                }
+                SrmSupplierDO supplier = supplierMapper.selectByName(importCertificate.getSupplierName());
+                if (supplier == null) {
+                    throw ServiceExceptionUtil.exception(ErrorCodeConstants.CERTIFICATE_IMPORT_SUPPLIER_NOT_EXISTS,
+                            importCertificate.getSupplierName());
+                }
+                // 2.2 鍒ゆ柇鏄惁瀛樺湪
+                SrmSupplierCertificateDO existCertificate = certificateMapper.selectBySupplierIdAndCertificateName(
+                        supplier.getId(), importCertificate.getCertificateName());
+                if (existCertificate == null) {
+                    // 2.2.1 鏂板
+                    SrmSupplierCertificateDO certificate = BeanUtils.toBean(importCertificate, SrmSupplierCertificateDO.class)
+                            .setSupplierId(supplier.getId());
+                    updateStatus(certificate);
+                    certificateMapper.insert(certificate);
+                    respVO.getCreateCertificateNames().add(importCertificate.getCertificateName());
+                    return;
+                }
+                // 2.2.2 宸插瓨鍦紝鍒ゆ柇鏄惁鍏佽鏇存柊
+                if (!importReqVO.getUpdateSupport()) {
+                    respVO.getFailureCertificateNames().put(importCertificate.getCertificateName(),
+                            StrUtil.format(ErrorCodeConstants.CERTIFICATE_IMPORT_NAME_EXISTS.getMsg(), importCertificate.getCertificateName()));
+                    return;
+                }
+                SrmSupplierCertificateDO updateCertificate = BeanUtils.toBean(importCertificate, SrmSupplierCertificateDO.class)
+                        .setId(existCertificate.getId()).setSupplierId(supplier.getId());
+                updateStatus(updateCertificate);
+                certificateMapper.updateById(updateCertificate);
+                respVO.getUpdateCertificateNames().add(importCertificate.getCertificateName());
+            } catch (ServiceException ex) {
+                respVO.getFailureCertificateNames().put(importCertificate.getCertificateName(), ex.getMessage());
+            }
+        });
+        return respVO;
+    }
+
     private void validateCertificateExists(Long id) {
         if (certificateMapper.selectById(id) == null) {
             throw ServiceExceptionUtil.exception(ErrorCodeConstants.CERTIFICATE_NOT_EXISTS);

--
Gitblit v1.9.3