From fbaeeeff5704f210bc6347454c0f16d255001822 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 04 十一月 2026 16:32:09 +0800
Subject: [PATCH] refactor(srm): 重构供应商采购域,新增询价比价与保证金管理
---
yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/supplier/SrmSupplierServiceImpl.java | 231 ++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 195 insertions(+), 36 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 5cc8fc5..a7e42c9 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
@@ -9,26 +9,26 @@
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.operatelog.core.util.OperateLogUtils;
-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.*;
-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.controller.admin.supplier.vo.*;
+import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierBankDO;
+import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierContactDO;
+import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierDO;
+import cn.iocoder.yudao.module.erp.api.purchase.ErpSupplierReferenceApi;
+import cn.iocoder.yudao.module.srm.dal.mysql.SrmBidBondMapper;
+import cn.iocoder.yudao.module.srm.dal.mysql.SrmInquiryOrderMapper;
+import cn.iocoder.yudao.module.srm.dal.mysql.SrmInquiryQuoteMapper;
+import cn.iocoder.yudao.module.srm.dal.mysql.SrmInquirySupplierMapper;
+import cn.iocoder.yudao.module.srm.dal.mysql.SrmSupplierBankMapper;
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.module.srm.enums.SupplierTypeEnum;
import com.mzt.logapi.starter.annotation.LogRecord;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
-import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.validation.annotation.Validated;
import java.math.BigDecimal;
import java.util.ArrayList;
@@ -36,7 +36,7 @@
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
+import java.util.Objects;
import static cn.iocoder.yudao.module.srm.enums.LogRecordConstants.*;
@@ -51,34 +51,43 @@
private SrmSupplierContactMapper supplierContactMapper;
@Resource
+ private SrmSupplierBankMapper supplierBankMapper;
+
+ @Resource
private SrmSupplierCategoryMapper supplierCategoryMapper;
@Resource
- private SrmSupplierApplyMapper supplierApplyMapper;
+ private SrmInquirySupplierMapper inquirySupplierMapper;
@Resource
- private SrmSupplierCertificateMapper supplierCertificateMapper;
+ private SrmInquiryQuoteMapper inquiryQuoteMapper;
@Resource
- private SrmTenderBidMapper tenderBidMapper;
+ private SrmInquiryOrderMapper inquiryOrderMapper;
@Resource
- private SrmBidEvaluationMapper bidEvaluationMapper;
+ private SrmBidBondMapper bidBondMapper;
@Resource
- private SrmBidAwardMapper bidAwardMapper;
+ private ErpSupplierReferenceApi erpSupplierReferenceApi;
@Override
+ @Transactional(rollbackFor = Exception.class)
public Long createSupplier(SrmSupplierSaveReqVO createReqVO) {
// 鏍¢獙渚涘簲鍟嗙紪鐮佸敮涓�鎬�
validateCodeUnique(createReqVO.getCode(), null);
// 鎻掑叆
SrmSupplierDO supplier = BeanUtils.toBean(createReqVO, SrmSupplierDO.class);
+ fillDefaultContactAndBankFromFlatFields(createReqVO);
supplierMapper.insert(supplier);
+ saveContacts(supplier.getId(), createReqVO.getContacts());
+ saveBanks(supplier.getId(), createReqVO.getBanks());
+ syncSupplierDefaultFields(supplier.getId(), createReqVO.getContacts(), createReqVO.getBanks());
return supplier.getId();
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public void updateSupplier(SrmSupplierSaveReqVO updateReqVO) {
// 鏍¢獙瀛樺湪鎬�
validateSupplierExists(updateReqVO.getId());
@@ -87,17 +96,47 @@
// 鏇存柊
SrmSupplierDO updateObj = BeanUtils.toBean(updateReqVO, SrmSupplierDO.class);
supplierMapper.updateById(updateObj);
+ // 鍒楄〃浼� null 琛ㄧず涓嶄慨鏀癸紱浼犵┖鍒楄〃琛ㄧず娓呯┖
+ if (updateReqVO.getContacts() != null) {
+ saveContacts(updateReqVO.getId(), updateReqVO.getContacts());
+ }
+ if (updateReqVO.getBanks() != null) {
+ saveBanks(updateReqVO.getId(), updateReqVO.getBanks());
+ }
+ syncSupplierDefaultFields(updateReqVO.getId(), updateReqVO.getContacts(), updateReqVO.getBanks());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteSupplier(Long id) {
// 鏍¢獙瀛樺湪鎬�
- validateSupplierExists(id);
- // 鍏宠仈鏁版嵁瀛樺湪鏃讹紝涓嶅厑璁稿垹闄�
- validateNoReference(id);
+ SrmSupplierDO supplier = validateSupplierExists(id);
+ // 鏍¢獙涓氬姟寮曠敤锛氳浠枫�佷繚璇侀噾銆丒RP 閲囪喘/浠樻绛夊崟鎹�
+ List<String> references = new ArrayList<>();
+ if (inquirySupplierMapper.selectCountBySupplierId(id) > 0) {
+ references.add("SRM璇环鍗�");
+ }
+ if (inquiryQuoteMapper.selectCountBySupplierId(id) > 0) {
+ references.add("SRM璇环鎶ヤ环");
+ }
+ if (inquiryOrderMapper.selectCountBySupplierId(id) > 0) {
+ references.add("SRM璇环杞噰璐鍗曡褰�");
+ }
+ if (bidBondMapper.selectCountBySupplierId(id) > 0) {
+ references.add("SRM鎶曟爣淇濊瘉閲�");
+ }
+ List<String> erpSources = erpSupplierReferenceApi.getSupplierReferenceSources(id).getCheckedData();
+ if (CollUtil.isNotEmpty(erpSources)) {
+ references.addAll(erpSources);
+ }
+ if (!references.isEmpty()) {
+ throw new ServiceException(ErrorCodeConstants.SUPPLIER_EXISTS_REFERENCE.getCode(),
+ "渚涘簲鍟嗐��" + supplier.getName() + "銆戝凡琚笟鍔″紩鐢紙" + String.join("銆�", references)
+ + "锛夛紝鏃犳硶鍒犻櫎銆傝鍏堝鐞嗙浉鍏冲崟鎹紝鎴栧皢渚涘簲鍟嗙姸鎬佹敼涓哄仠鐢ㄣ��");
+ }
// 鍙洿鎺ユ竻鐞嗙殑鍏宠仈鏁版嵁
supplierContactMapper.deleteBySupplierId(id);
+ supplierBankMapper.deleteBySupplierId(id);
supplierCategoryMapper.deleteBySupplierId(id);
// 閫昏緫鍒犻櫎
supplierMapper.deleteById(id);
@@ -106,6 +145,16 @@
@Override
public SrmSupplierDO getSupplier(Long id) {
return supplierMapper.selectById(id);
+ }
+
+ @Override
+ public List<SrmSupplierContactDO> getSupplierContactList(Long supplierId) {
+ return supplierContactMapper.selectListBySupplierId(supplierId);
+ }
+
+ @Override
+ public List<SrmSupplierBankDO> getSupplierBankList(Long supplierId) {
+ return supplierBankMapper.selectListBySupplierId(supplierId);
}
@Override
@@ -162,13 +211,14 @@
@Override
public List<SrmSupplierDO> getSupplierSimpleList() {
- return supplierMapper.selectApprovedList();
+ // 鍑嗗叆鍔熻兘宸茬Щ闄わ紝涓嬫媺閫夋嫨缁熶竴杩斿洖鍚敤鐨勪緵搴斿晢
+ return supplierMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus());
}
@Override
public List<SrmSupplierDO> getSupplierAllList() {
return supplierMapper.selectList(new LambdaQueryWrapperX<SrmSupplierDO>()
- // 杩囨护鍋滅敤渚涘簲鍟嗭紝淇濈暀鏈缃姸鎬佷笌鍚敤鐘舵�佺殑妗f渚涘簲鍟嗭紙浠呯敤浜庢嫑鎶曟爣鍦烘櫙锛�
+ // 杩囨护鍋滅敤渚涘簲鍟嗭紝淇濈暀鏈缃姸鎬佷笌鍚敤鐘舵�佺殑妗f渚涘簲鍟�
.and(w -> w.isNull(SrmSupplierDO::getStatus)
.or()
.ne(SrmSupplierDO::getStatus, CommonStatusEnum.DISABLE.getStatus()))
@@ -181,6 +231,124 @@
return Collections.emptyList();
}
return supplierMapper.selectBatchIds(ids);
+ }
+
+ // ========== 鑱旂郴浜� / 閾惰璐︽埛 ==========
+
+ /**
+ * 瀵煎叆鍦烘櫙娌℃湁鑱旂郴浜哄垪琛ㄦ椂锛岀敤涓昏〃鎵佸钩瀛楁鐢熸垚涓�鏉¢粯璁よ仈绯讳汉
+ */
+ private void fillDefaultContactAndBankFromFlatFields(SrmSupplierSaveReqVO reqVO) {
+ if (reqVO.getContacts() == null && StrUtil.isNotBlank(reqVO.getContactName())) {
+ SrmSupplierContactSaveReqVO contact = new SrmSupplierContactSaveReqVO();
+ contact.setName(reqVO.getContactName());
+ contact.setMobile(reqVO.getContactMobile());
+ contact.setEmail(reqVO.getContactEmail());
+ contact.setIsDefault(Boolean.TRUE);
+ reqVO.setContacts(Collections.singletonList(contact));
+ }
+ if (reqVO.getBanks() == null
+ && (StrUtil.isNotBlank(reqVO.getBankName()) || StrUtil.isNotBlank(reqVO.getBankAccount()))) {
+ SrmSupplierBankSaveReqVO bank = new SrmSupplierBankSaveReqVO();
+ bank.setBankName(reqVO.getBankName());
+ bank.setBankAccount(reqVO.getBankAccount());
+ bank.setIsDefault(Boolean.TRUE);
+ reqVO.setBanks(Collections.singletonList(bank));
+ }
+ }
+
+ private void saveContacts(Long supplierId, List<SrmSupplierContactSaveReqVO> contacts) {
+ supplierContactMapper.deleteBySupplierId(supplierId);
+ if (CollUtil.isEmpty(contacts)) {
+ return;
+ }
+ for (int i = 0; i < contacts.size(); i++) {
+ SrmSupplierContactSaveReqVO vo = contacts.get(i);
+ if (StrUtil.isBlank(vo.getName())) {
+ throw new ServiceException(ErrorCodeConstants.SUPPLIER_CONTACT_NAME_REQUIRED.getCode(),
+ "绗� " + (i + 1) + " 涓仈绯讳汉鐨勫鍚嶄笉鑳戒负绌猴紝璇峰~鍐欒仈绯讳汉濮撳悕鍚庨噸鏂颁繚瀛�");
+ }
+ }
+ int defaultIndex = resolveDefaultIndex(contacts.size(),
+ contacts.stream().map(SrmSupplierContactSaveReqVO::getIsDefault).toList());
+ for (int i = 0; i < contacts.size(); i++) {
+ SrmSupplierContactDO contact = BeanUtils.toBean(contacts.get(i), SrmSupplierContactDO.class);
+ contact.setId(null);
+ contact.setSupplierId(supplierId);
+ contact.setSort(i);
+ contact.setIsDefault(i == defaultIndex);
+ supplierContactMapper.insert(contact);
+ }
+ }
+
+ private void saveBanks(Long supplierId, List<SrmSupplierBankSaveReqVO> banks) {
+ supplierBankMapper.deleteBySupplierId(supplierId);
+ if (CollUtil.isEmpty(banks)) {
+ return;
+ }
+ for (int i = 0; i < banks.size(); i++) {
+ SrmSupplierBankSaveReqVO vo = banks.get(i);
+ if (StrUtil.isBlank(vo.getBankName()) || StrUtil.isBlank(vo.getBankAccount())) {
+ throw new ServiceException(ErrorCodeConstants.SUPPLIER_BANK_INFO_INCOMPLETE.getCode(),
+ "绗� " + (i + 1) + " 涓摱琛岃处鎴风殑寮�鎴疯鎴栭摱琛岃处鍙蜂负绌猴紝璇疯ˉ鍏ㄥ紑鎴疯鍜岄摱琛岃处鍙峰悗閲嶆柊淇濆瓨");
+ }
+ }
+ int defaultIndex = resolveDefaultIndex(banks.size(),
+ banks.stream().map(SrmSupplierBankSaveReqVO::getIsDefault).toList());
+ for (int i = 0; i < banks.size(); i++) {
+ SrmSupplierBankDO bank = BeanUtils.toBean(banks.get(i), SrmSupplierBankDO.class);
+ bank.setId(null);
+ bank.setSupplierId(supplierId);
+ bank.setSort(i);
+ bank.setIsDefault(i == defaultIndex);
+ supplierBankMapper.insert(bank);
+ }
+ }
+
+ /**
+ * 瑙f瀽榛樿椤癸細浼樺厛鍙栨爣璁颁簡榛樿鐨勭涓�鏉★紝鍚﹀垯鍙栫涓�鏉�
+ */
+ private int resolveDefaultIndex(int size, List<Boolean> defaults) {
+ for (int i = 0; i < size; i++) {
+ if (Boolean.TRUE.equals(defaults.get(i))) {
+ return i;
+ }
+ }
+ return 0;
+ }
+
+ /**
+ * 鎶婇粯璁よ仈绯讳汉/榛樿閾惰鍥炲啓涓昏〃鎵佸钩瀛楁锛屽吋瀹瑰垪琛ㄣ�佹悳绱笌瀵煎叆瀵煎嚭
+ */
+ private void syncSupplierDefaultFields(Long supplierId, List<SrmSupplierContactSaveReqVO> contacts,
+ List<SrmSupplierBankSaveReqVO> banks) {
+ SrmSupplierDO updateObj = new SrmSupplierDO();
+ updateObj.setId(supplierId);
+ boolean changed = false;
+ if (contacts != null) {
+ SrmSupplierContactSaveReqVO defaultContact = pickDefault(contacts, SrmSupplierContactSaveReqVO::getIsDefault);
+ updateObj.setContactName(defaultContact == null ? null : defaultContact.getName());
+ updateObj.setContactMobile(defaultContact == null ? null : defaultContact.getMobile());
+ updateObj.setContactEmail(defaultContact == null ? null : defaultContact.getEmail());
+ changed = true;
+ }
+ if (banks != null) {
+ SrmSupplierBankSaveReqVO defaultBank = pickDefault(banks, SrmSupplierBankSaveReqVO::getIsDefault);
+ updateObj.setBankName(defaultBank == null ? null : defaultBank.getBankName());
+ updateObj.setBankAccount(defaultBank == null ? null : defaultBank.getBankAccount());
+ changed = true;
+ }
+ if (changed) {
+ supplierMapper.updateById(updateObj);
+ }
+ }
+
+ private <T> T pickDefault(List<T> list, java.util.function.Function<T, Boolean> isDefault) {
+ if (CollUtil.isEmpty(list)) {
+ return null;
+ }
+ return list.stream().filter(item -> Boolean.TRUE.equals(isDefault.apply(item)))
+ .findFirst().orElse(list.get(0));
}
// ========== 瀵煎叆杈呭姪鏂规硶 ==========
@@ -243,27 +411,18 @@
// ========== 鏍¢獙鏂规硶 ==========
- private void validateSupplierExists(Long id) {
- if (supplierMapper.selectById(id) == null) {
+ private SrmSupplierDO validateSupplierExists(Long id) {
+ SrmSupplierDO supplier = supplierMapper.selectById(id);
+ if (supplier == null) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.SUPPLIER_NOT_EXISTS);
}
+ return supplier;
}
private void validateCodeUnique(String code, Long id) {
SrmSupplierDO existing = supplierMapper.selectByCode(code);
- if (existing != null && !existing.getId().equals(id)) {
+ if (existing != null && !Objects.equals(existing.getId(), id)) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.SUPPLIER_CODE_EXISTS);
- }
- }
-
- 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