From 88e384da863bb2f7324cb1e1474885df3b7cce91 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期一, 13 七月 2026 11:27:49 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_business' into dev_business
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesServiceImpl.java | 66 ++++++++++++++++++++++++++++++++
1 files changed, 65 insertions(+), 1 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesServiceImpl.java
index d45aa41..1694b78 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesServiceImpl.java
@@ -20,9 +20,11 @@
import cn.iocoder.yudao.module.mes.enums.wm.MesWmSalesNoticeStatusEnum;
import cn.iocoder.yudao.module.mes.enums.wm.MesWmTransactionTypeEnum;
import cn.iocoder.yudao.module.mes.service.md.client.MesMdClientService;
+import cn.iocoder.yudao.module.mes.service.wm.materialstock.MesWmMaterialStockService;
import cn.iocoder.yudao.module.mes.service.wm.salesnotice.MesWmSalesNoticeService;
import cn.iocoder.yudao.module.mes.service.wm.transaction.MesWmTransactionService;
import cn.iocoder.yudao.module.mes.service.wm.transaction.dto.MesWmTransactionSaveReqDTO;
+import cn.iocoder.yudao.module.erp.api.sale.ErpSaleOrderApi;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -57,6 +59,11 @@
private MesWmSalesNoticeService salesNoticeService;
@Resource
private MesWmTransactionService wmTransactionService;
+ @Resource
+ private MesWmMaterialStockService materialStockService;
+
+ @Resource
+ private ErpSaleOrderApi saleOrderApi;
@Override
public Long createProductSales(MesWmProductSalesSaveReqVO createReqVO) {
@@ -167,12 +174,25 @@
if (ObjUtil.notEqual(MesWmProductSalesStatusEnum.APPROVING.getStatus(), sales.getStatus())) {
throw exception(WM_PRODUCT_SALES_CANNOT_PICK);
}
- // 鏍¢獙姣忚鑷冲皯鏈夋嫞璐ф槑缁�
+ // 鏍¢獙姣忚鑷冲皯鏈夋嫞璐ф槑缁嗭紝骞舵牎楠屽簱瀛樺厖瓒�
List<MesWmProductSalesLineDO> lines = productSalesLineService.getProductSalesLineListBySalesId(id);
for (MesWmProductSalesLineDO line : lines) {
List<MesWmProductSalesDetailDO> details = productSalesDetailService.getProductSalesDetailListByLineId(line.getId());
if (CollUtil.isEmpty(details)) {
throw exception(WM_PRODUCT_SALES_DETAILS_EMPTY);
+ }
+ // 鏍¢獙搴撳瓨鍏呰冻
+ for (MesWmProductSalesDetailDO detail : details) {
+ materialStockService.validateSelectedStock(
+ detail.getMaterialStockId(),
+ detail.getItemId(),
+ detail.getBatchId(),
+ detail.getBatchCode(),
+ detail.getWarehouseId(),
+ detail.getLocationId(),
+ detail.getAreaId(),
+ detail.getQuantity()
+ );
}
}
@@ -213,6 +233,45 @@
// 3. 鏇存柊鍑哄簱鍗曠姸鎬�
productSalesMapper.updateById(new MesWmProductSalesDO()
.setId(id).setStatus(MesWmProductSalesStatusEnum.FINISHED.getStatus()));
+
+ // 4. 鏇存柊鍏宠仈鐨勫彂璐ч�氱煡鍗曠姸鎬�
+ if (sales.getNoticeId() != null) {
+ salesNoticeService.finishSalesNotice(sales.getNoticeId());
+ }
+
+ // 5. 鍥炲啓 ERP 閿�鍞鍗曠殑鍑哄簱鏁伴噺鍜岀姸鎬�
+ updateErpSaleOrderOutCount(sales);
+ }
+
+ /**
+ * 鍥炲啓 ERP 閿�鍞鍗曠殑鍑哄簱鏁伴噺鍜岀姸鎬�
+ */
+ private void updateErpSaleOrderOutCount(MesWmProductSalesDO sales) {
+ // 鑾峰彇鍑哄簱鍗曡
+ List<MesWmProductSalesLineDO> lines = productSalesLineService.getProductSalesLineListBySalesId(sales.getId());
+ if (CollUtil.isEmpty(lines)) {
+ return;
+ }
+ // 鐢ㄤ簬瀛樺偍閿�鍞鍗� ID锛岄伩鍏嶉噸澶嶆洿鏂�
+ Long saleOrderId = null;
+ // 閬嶅巻琛岋紝鎸� saleOrderItemId 鏇存柊鍑哄簱鏁伴噺
+ for (MesWmProductSalesLineDO line : lines) {
+ if (line.getSaleOrderItemId() != null && line.getQuantity() != null) {
+ saleOrderApi.updateOrderItemOutCount(line.getSaleOrderItemId(), line.getQuantity());
+ // 鑾峰彇閿�鍞鍗� ID锛堜粠绗竴涓湁鏁堢殑鏄庣粏椤硅幏鍙栵級
+ if (saleOrderId == null) {
+ cn.iocoder.yudao.module.erp.api.sale.dto.ErpSaleOrderItemRespDTO itemDTO =
+ saleOrderApi.getSaleOrderItem(line.getSaleOrderItemId()).getCheckedData();
+ if (itemDTO != null && itemDTO.getOrderId() != null) {
+ saleOrderId = itemDTO.getOrderId();
+ }
+ }
+ }
+ }
+ // 鏇存柊閿�鍞鍗曠殑鍑哄簱鐘舵��
+ if (saleOrderId != null) {
+ saleOrderApi.updateOrderOutStatus(saleOrderId);
+ }
}
private void createTransactionList(MesWmProductSalesDO sales) {
@@ -306,4 +365,9 @@
}
}
+ @Override
+ public void updateStatus(Long id, Integer status) {
+ productSalesMapper.updateById(new MesWmProductSalesDO().setId(id).setStatus(status));
+ }
+
}
--
Gitblit v1.9.3