From 50de7480237de2ba9d140a219d48a9b72211b8d2 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 03 九月 2026 17:27:43 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_business' into dev_business
---
yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/supplier/SrmSupplierServiceImpl.java | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 116 insertions(+), 4 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 c9d5858..129d4fa 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,9 +1,15 @@
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.enums.CommonStatusEnum;
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
+import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
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.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.*;
@@ -16,18 +22,19 @@
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 cn.iocoder.yudao.module.srm.enums.SupplierTypeEnum;
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.math.BigDecimal;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
@Service
@Validated
@@ -103,6 +110,49 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
+ public SrmSupplierImportRespVO importSupplierList(List<SrmSupplierImportExcelVO> importList, Boolean updateSupport) {
+ if (CollUtil.isEmpty(importList)) {
+ throw ServiceExceptionUtil.exception(ErrorCodeConstants.SUPPLIER_IMPORT_LIST_IS_EMPTY);
+ }
+ SrmSupplierImportRespVO respVO = SrmSupplierImportRespVO.builder()
+ .createList(new ArrayList<>())
+ .updateList(new ArrayList<>())
+ .failureList(new LinkedHashMap<>())
+ .build();
+ // 閫愯瀵煎叆锛氬崟琛屽け璐ヨ褰曞埌 failureList锛屼笉褰卞搷鍏跺畠琛�
+ for (SrmSupplierImportExcelVO importVO : importList) {
+ String code = StrUtil.trim(importVO.getCode());
+ String name = StrUtil.trim(importVO.getName());
+ if (StrUtil.isBlank(code) || StrUtil.isBlank(name)) {
+ respVO.getFailureList().put(StrUtil.blankToDefault(name, code), "渚涘簲鍟嗙紪鐮佸拰渚涘簲鍟嗗悕绉颁笉鑳戒负绌�");
+ continue;
+ }
+ SrmSupplierSaveReqVO saveReqVO = toSaveReqVO(importVO);
+ try {
+ SrmSupplierDO existByCode = supplierMapper.selectByCode(code);
+ if (existByCode != null) {
+ if (!Boolean.TRUE.equals(updateSupport)) {
+ respVO.getFailureList().put(name, "渚涘簲鍟嗙紪鐮佸凡瀛樺湪");
+ continue;
+ }
+ saveReqVO.setId(existByCode.getId());
+ updateSupplier(saveReqVO);
+ respVO.getUpdateList().add(name);
+ } else {
+ createSupplier(saveReqVO);
+ respVO.getCreateList().add(name);
+ }
+ } catch (Exception ex) {
+ // 鍗曟潯澶辫触锛岃褰曞苟缁х画
+ String reason = ex instanceof ServiceException ? ((ServiceException) ex).getMessage() : ex.getMessage();
+ respVO.getFailureList().put(name, reason == null ? "瀵煎叆澶辫触" : reason);
+ }
+ }
+ return respVO;
+ }
+
+ @Override
public List<SrmSupplierDO> getSupplierSimpleList() {
return supplierMapper.selectApprovedList();
}
@@ -110,6 +160,10 @@
@Override
public List<SrmSupplierDO> getSupplierAllList() {
return supplierMapper.selectList(new LambdaQueryWrapperX<SrmSupplierDO>()
+ // 杩囨护鍋滅敤渚涘簲鍟嗭紝淇濈暀鏈缃姸鎬佷笌鍚敤鐘舵�佺殑妗f渚涘簲鍟嗭紙浠呯敤浜庢嫑鎶曟爣鍦烘櫙锛�
+ .and(w -> w.isNull(SrmSupplierDO::getStatus)
+ .or()
+ .ne(SrmSupplierDO::getStatus, CommonStatusEnum.DISABLE.getStatus()))
.orderByAsc(SrmSupplierDO::getId));
}
@@ -121,6 +175,64 @@
return supplierMapper.selectBatchIds(ids);
}
+ // ========== 瀵煎叆杈呭姪鏂规硶 ==========
+
+ /**
+ * 瀵煎叆 VO -> 淇濆瓨 VO锛屽鐢� create/update 閫昏緫锛�
+ * 绫诲瀷鏀寔涓枃鍚嶇О鎴栫紪鐮侊紙1~4锛夛紝鐘舵�佺暀绌洪粯璁ゅ惎鐢�
+ */
+ private SrmSupplierSaveReqVO toSaveReqVO(SrmSupplierImportExcelVO importVO) {
+ SrmSupplierSaveReqVO saveReqVO = new SrmSupplierSaveReqVO();
+ saveReqVO.setCode(StrUtil.trim(importVO.getCode()));
+ saveReqVO.setName(StrUtil.trim(importVO.getName()));
+ saveReqVO.setShortName(StrUtil.trimToNull(importVO.getShortName()));
+ saveReqVO.setType(parseTypeCode(importVO.getType()));
+ saveReqVO.setCompanyNature(StrUtil.trimToNull(importVO.getCompanyNature()));
+ saveReqVO.setRegisteredCapital(importVO.getRegisteredCapital());
+ saveReqVO.setBusinessLicenseNo(StrUtil.trimToNull(importVO.getBusinessLicenseNo()));
+ saveReqVO.setTaxNo(StrUtil.trimToNull(importVO.getTaxNo()));
+ saveReqVO.setLegalPerson(StrUtil.trimToNull(importVO.getLegalPerson()));
+ saveReqVO.setAddress(StrUtil.trimToNull(importVO.getAddress()));
+ saveReqVO.setWebsite(StrUtil.trimToNull(importVO.getWebsite()));
+ saveReqVO.setContactName(StrUtil.trimToNull(importVO.getContactName()));
+ saveReqVO.setContactMobile(StrUtil.trimToNull(importVO.getContactMobile()));
+ saveReqVO.setContactEmail(StrUtil.trimToNull(importVO.getContactEmail()));
+ saveReqVO.setBankName(StrUtil.trimToNull(importVO.getBankName()));
+ saveReqVO.setBankAccount(StrUtil.trimToNull(importVO.getBankAccount()));
+ saveReqVO.setStatus(importVO.getStatus() != null ? importVO.getStatus() : CommonStatusEnum.ENABLE.getStatus());
+ saveReqVO.setRemark(StrUtil.trimToNull(importVO.getRemark()));
+ return saveReqVO;
+ }
+
+ /**
+ * 渚涘簲鍟嗙被鍨嬭В鏋愶細涓枃鍚嶇О鎴栫紪鐮侊紙1~4锛夊潎杞崲涓虹紪鐮佸瓧绗︿覆锛�
+ * 鏃犳硶璇嗗埆鏃朵繚鐣欏師鍊硷紝閬垮厤瀵煎叆琚樆濉�
+ */
+ private String parseTypeCode(String type) {
+ String t = StrUtil.trimToNull(type);
+ if (t == null) {
+ return null;
+ }
+ for (SupplierTypeEnum e : SupplierTypeEnum.values()) {
+ if (t.equalsIgnoreCase(e.getName()) || t.equals(String.valueOf(e.getCode()))) {
+ return String.valueOf(e.getCode());
+ }
+ }
+ // 鍏煎 Excel 鏁板瓧鍗曞厓鏍艰璇绘垚 "1.0" 绛夊甫灏忔暟褰㈠紡
+ try {
+ BigDecimal bd = new BigDecimal(t);
+ if (bd.stripTrailingZeros().scale() <= 0) {
+ int i = bd.intValueExact();
+ if (i >= 1 && i <= 4) {
+ return String.valueOf(i);
+ }
+ }
+ } catch (NumberFormatException ignored) {
+ // 蹇界暐锛氫繚鎸佸師鍊�
+ }
+ return t;
+ }
+
// ========== 鏍¢獙鏂规硶 ==========
private void validateSupplierExists(Long id) {
--
Gitblit v1.9.3