From 35de964169cbaeba6628f5fcefce535572655b30 Mon Sep 17 00:00:00 2001 From: "zangch@mesnac.com" Date: Wed, 5 Nov 2025 17:08:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(oa/crm):=E4=BC=98=E5=8C=96=E6=8A=A5?= =?UTF-8?q?=E4=BB=B7=E5=8D=95=E7=89=A9=E6=96=99=E6=98=8E=E7=BB=86=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入差异更新机制,避免全量删除插入 - 子表更新时保留未变更数据,提升性能 - 增加删除标记条件过滤,确保数据准确性 -优化导入包结构,统一使用 java.util.* - 明细为空时清空子表,保证数据一致性 - 添加排序和删除标记查询条件 - 使用 insertOrUpdate 简化新增与修改操作 - 回写主表金额汇总逻辑保持不变 --- .../service/impl/CrmQuoteInfoServiceImpl.java | 36 ++++++++++++++----- .../impl/CrmQuoteMaterialServiceImpl.java | 12 ++++--- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmQuoteInfoServiceImpl.java b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmQuoteInfoServiceImpl.java index 62301fa3..8ad536e4 100644 --- a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmQuoteInfoServiceImpl.java +++ b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmQuoteInfoServiceImpl.java @@ -25,11 +25,10 @@ import org.dromara.oa.crm.service.ICrmQuoteInfoService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Collection; +import java.util.*; import java.math.BigDecimal; import java.math.RoundingMode; -import java.util.List; -import java.util.Map; +import java.util.stream.Collectors; /** * 报价单信息Service业务层处理 @@ -59,6 +58,7 @@ public class CrmQuoteInfoServiceImpl implements ICrmQuoteInfoService { List items = quoteMaterialMapper.selectVoList( JoinWrappers.lambda(CrmQuoteMaterial.class) .selectAll(CrmQuoteMaterial.class) + .eq("t.del_flag", "0") .eq(CrmQuoteMaterial::getQuoteId, quoteId) .orderByAsc(CrmQuoteMaterial::getItemNo) ); @@ -98,6 +98,7 @@ public class CrmQuoteInfoServiceImpl implements ICrmQuoteInfoService { MPJLambdaWrapper lqw = JoinWrappers.lambda(CrmQuoteInfo.class) // 主表全部字段 .selectAll(CrmQuoteInfo.class) + .eq(CrmQuoteInfo::getDelFlag, "0") // 客户方联系人(CrmCustomerContact,别名:CustomerContact) .selectAs("CustomerContact", CrmCustomerContact::getContactName, CrmQuoteInfo::getCustomerContactRealName) .leftJoin(CrmCustomerContact.class, "CustomerContact", CrmCustomerContact::getContactId, CrmQuoteInfo::getCustomerContactId) @@ -194,23 +195,42 @@ public class CrmQuoteInfoServiceImpl implements ICrmQuoteInfoService { validEntityBeforeSave(update); boolean ok = baseMapper.updateById(update) > 0; if (!ok) return false; - // 全量覆盖子表:先删后增(保持简单一致性) + // 差异更新子表:存在则更新,不存在则插入;并删除前端未提交的旧记录 Long qid = bo.getQuoteId(); - quoteMaterialMapper.delete(Wrappers.lambdaQuery().eq(CrmQuoteMaterial::getQuoteId, qid)); + List oldItems = quoteMaterialMapper.selectList( + Wrappers.lambdaQuery().eq(CrmQuoteMaterial::getQuoteId, qid) + ); + List itemsBo = bo.getItemsBo(); if (itemsBo != null && !itemsBo.isEmpty()) { for (int i = 0; i < itemsBo.size(); i++) { CrmQuoteMaterialBo itemBo = itemsBo.get(i); CrmQuoteMaterial entity = MapstructUtils.convert(itemBo, CrmQuoteMaterial.class); - // 避免主键冲突:子表使用自增主键,插入前显式置空 - entity.setQuoteMaterialId(null); + // 统一归属报价ID entity.setQuoteId(qid); + // 若未指定序号则按顺序回填 if (entity.getItemNo() == null) { entity.setItemNo((long) (i + 1)); } - quoteMaterialMapper.insert(entity); + // 使用 insertOrUpdate 简化增改逻辑,参考合同物料实现 + quoteMaterialMapper.insertOrUpdate(entity); } + + // 删除旧记录中未在本次提交集合内的记录 + Set incomingIds = itemsBo.stream() + .map(CrmQuoteMaterialBo::getQuoteMaterialId) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + for (CrmQuoteMaterial old : oldItems) { + if (!incomingIds.contains(old.getQuoteMaterialId())) { + quoteMaterialMapper.deleteById(old.getQuoteMaterialId()); + } + } + } else { + // 当前未提交明细则清空子表 + quoteMaterialMapper.delete(Wrappers.lambdaQuery().eq(CrmQuoteMaterial::getQuoteId, qid)); } + // 回写主表金额汇总 this.recalcTotals(qid); return true; diff --git a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmQuoteMaterialServiceImpl.java b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmQuoteMaterialServiceImpl.java index 0d8754e4..1472676c 100644 --- a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmQuoteMaterialServiceImpl.java +++ b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/crm/service/impl/CrmQuoteMaterialServiceImpl.java @@ -74,11 +74,13 @@ public class CrmQuoteMaterialServiceImpl implements ICrmQuoteMaterialService { Map params = bo.getParams(); MPJLambdaWrapper lqw = JoinWrappers.lambda(CrmQuoteMaterial.class) .selectAll(CrmQuoteMaterial.class) - // 联表选择:SAP物料名称 & 销售物料名称 - .select(BaseMaterialInfo::getMaterialName) - .select(BaseRelationMaterial::getSaleMaterialName) - .leftJoin(BaseMaterialInfo.class, BaseMaterialInfo::getMaterialId, CrmQuoteMaterial::getMaterialId) - .leftJoin(BaseRelationMaterial.class, BaseRelationMaterial::getRelationMaterialId, CrmQuoteMaterial::getRelationMaterialId) + .eq(CrmQuoteMaterial::getDelFlag, "0") + // 联表选择:SAP物料名称 & 销售物料名称 + .select(BaseMaterialInfo::getMaterialName) + .select(BaseRelationMaterial::getSaleMaterialName) + .leftJoin(BaseMaterialInfo.class, BaseMaterialInfo::getMaterialId, CrmQuoteMaterial::getMaterialId) + .leftJoin(BaseRelationMaterial.class, BaseRelationMaterial::getRelationMaterialId, CrmQuoteMaterial::getRelationMaterialId) + .eq(bo.getQuoteId() != null, CrmQuoteMaterial::getQuoteId, bo.getQuoteId()) .eq(bo.getItemNo() != null, CrmQuoteMaterial::getItemNo, bo.getItemNo()) .like(StringUtils.isNotBlank(bo.getProductName()), CrmQuoteMaterial::getProductName, bo.getProductName())