From eccad5a129106377a275be4f7cdc58e99e9b95d4 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 21 七月 2026 13:45:14 +0800
Subject: [PATCH] feat(mes): 实现库存移库功能
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesServiceImpl.java | 93 +++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 82 insertions(+), 11 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 1694b78..fff9c10 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
@@ -14,18 +14,25 @@
import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesDetailDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesLineDO;
import cn.iocoder.yudao.module.mes.dal.mysql.wm.productsales.MesWmProductSalesMapper;
+import cn.iocoder.yudao.module.mes.dal.mysql.wm.productsales.MesWmProductSalesLineMapper;
import cn.iocoder.yudao.module.mes.enums.MesBizTypeConstants;
import cn.iocoder.yudao.module.mes.enums.wm.MesWmProductSalesStatusEnum;
import cn.iocoder.yudao.module.mes.enums.wm.MesWmQualityStatusEnum;
import cn.iocoder.yudao.module.mes.enums.wm.MesWmSalesNoticeStatusEnum;
+import cn.iocoder.yudao.module.mes.enums.wm.MesWmStockReserveBizTypeEnum;
import cn.iocoder.yudao.module.mes.enums.wm.MesWmTransactionTypeEnum;
-import cn.iocoder.yudao.module.mes.service.md.client.MesMdClientService;
+import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi;
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.stockreserve.MesWmStockReserveService;
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.mes.service.qc.oqc.MesQcOqcService;
import cn.iocoder.yudao.module.erp.api.sale.ErpSaleOrderApi;
+import cn.iocoder.yudao.module.erp.api.sale.enums.ErpSaleOrderOutStatusEnum;
import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -44,23 +51,31 @@
*/
@Service
@Validated
+@Slf4j
public class MesWmProductSalesServiceImpl implements MesWmProductSalesService {
@Resource
private MesWmProductSalesMapper productSalesMapper;
+ @Resource
+ private MesWmProductSalesLineMapper productSalesLineMapper;
@Resource
private MesWmProductSalesLineService productSalesLineService;
@Resource
private MesWmProductSalesDetailService productSalesDetailService;
@Resource
- private MesMdClientService clientService;
+ private CrmCustomerApi customerApi;
@Resource
private MesWmSalesNoticeService salesNoticeService;
@Resource
private MesWmTransactionService wmTransactionService;
@Resource
private MesWmMaterialStockService materialStockService;
+ @Resource
+ private MesWmStockReserveService stockReserveService;
+ @Resource
+ @Lazy
+ private MesQcOqcService oqcService;
@Resource
private ErpSaleOrderApi saleOrderApi;
@@ -109,7 +124,8 @@
@Override
public PageResult<MesWmProductSalesDO> getProductSalesPage(MesWmProductSalesPageReqVO pageReqVO) {
- return productSalesMapper.selectPage(pageReqVO);
+ List<Long> permittedClientIds = customerApi.getPermittedCustomerIds();
+ return productSalesMapper.selectPage(pageReqVO, permittedClientIds);
}
@Override
@@ -129,10 +145,26 @@
}
}
+ // 鑾峰彇鍑哄簱鍗曚俊鎭�
+ MesWmProductSalesDO sales = productSalesMapper.selectById(id);
+
// 妫�鏌ユ墍鏈夎鐨� oqcCheckFlag锛氬鏋滄湁闇�瑕� OQC 妫�楠岀殑琛岋紝杩涘叆寰呮娴嬬姸鎬�
boolean needOqc = CollectionUtils.anyMatch(lines,
line -> Boolean.TRUE.equals(line.getOqcCheckFlag()));
if (needOqc) {
+ // 涓洪渶瑕� OQC 妫�楠屼笖灏氭湭鍒涘缓妫�楠屽崟鐨勬槑缁嗗垱寤� OQC 妫�楠屽崟
+ List<MesWmProductSalesLineDO> oqcLines = CollectionUtils.filterList(lines,
+ line -> Boolean.TRUE.equals(line.getOqcCheckFlag()) && line.getOqcId() == null);
+ for (MesWmProductSalesLineDO line : oqcLines) {
+ // 鐩存帴璋冪敤锛岃寮傚父鎶涘嚭锛屼繚璇佹暟鎹竴鑷存��
+ Long oqcId = oqcService.createOqcFromProductSales(
+ sales.getId(), line, sales.getCode(), sales.getClientId());
+ // 鏇存柊鍑哄簱鏄庣粏鐨� oqcId
+ productSalesLineMapper.updateById(new MesWmProductSalesLineDO()
+ .setId(line.getId())
+ .setOqcId(oqcId));
+ }
+
// 鎵归噺鍒濆鍖� OQC 琛岀殑璐ㄩ噺鐘舵�佷负"寰呮楠�"
List<Long> oqcLineIds = convertList(
CollectionUtils.filterList(lines, line -> Boolean.TRUE.equals(line.getOqcCheckFlag())),
@@ -181,7 +213,7 @@
if (CollUtil.isEmpty(details)) {
throw exception(WM_PRODUCT_SALES_DETAILS_EMPTY);
}
- // 鏍¢獙搴撳瓨鍏呰冻
+ // 鏍¢獙搴撳瓨鍏呰冻骞跺垱寤哄崰鐢�
for (MesWmProductSalesDetailDO detail : details) {
materialStockService.validateSelectedStock(
detail.getMaterialStockId(),
@@ -193,12 +225,28 @@
detail.getAreaId(),
detail.getQuantity()
);
+ // 鍒涘缓搴撳瓨鍗犵敤
+ stockReserveService.createReserve(
+ detail.getMaterialStockId(),
+ MesWmStockReserveBizTypeEnum.PRODUCT_SALES.getType(),
+ id,
+ sales.getCode(),
+ detail.getId(),
+ detail.getItemId(),
+ detail.getQuantity()
+ );
}
}
// 鎵ц鎷h揣锛堝緟鎷h揣 鈫� 寰呭~鍐欒繍鍗曪級
productSalesMapper.updateById(new MesWmProductSalesDO()
.setId(id).setStatus(MesWmProductSalesStatusEnum.SHIPPING.getStatus()));
+
+ // 鍥炲啓 ERP 閿�鍞鍗曞嚭搴撶姸鎬佷负"閮ㄥ垎鍑哄簱"锛堣〃绀哄凡鎷h揣/鍗犵敤锛�
+ if (sales.getSaleOrderId() != null) {
+ saleOrderApi.updateOrderOutStatusTo(sales.getSaleOrderId(),
+ ErpSaleOrderOutStatusEnum.PART_OUT.getStatus());
+ }
}
@Override
@@ -227,20 +275,40 @@
throw exception(WM_PRODUCT_SALES_CANNOT_FINISH);
}
- // 2. 閬嶅巻鎵�鏈夋槑缁嗭紝鍒涘缓搴撳瓨浜嬪姟锛堟墸鍑忓簱瀛� + 璁板綍娴佹按锛�
+ // 2. 纭鍗犵敤杞嚭搴擄紙閲婃斁鍗犵敤閲忥級
+ stockReserveService.confirmReserveToOutbound(MesWmStockReserveBizTypeEnum.PRODUCT_SALES.getType(), id);
+
+ // 3. 閬嶅巻鎵�鏈夋槑缁嗭紝鍒涘缓搴撳瓨浜嬪姟锛堟墸鍑忓簱瀛� + 璁板綍娴佹按锛�
createTransactionList(sales);
- // 3. 鏇存柊鍑哄簱鍗曠姸鎬�
+ // 4. 鏇存柊鍑哄簱鍗曠姸鎬�
productSalesMapper.updateById(new MesWmProductSalesDO()
.setId(id).setStatus(MesWmProductSalesStatusEnum.FINISHED.getStatus()));
- // 4. 鏇存柊鍏宠仈鐨勫彂璐ч�氱煡鍗曠姸鎬�
+ // 5. 鏇存柊鍏宠仈鐨勫彂璐ч�氱煡鍗曞嚭搴撴暟閲忓拰鐘舵��
if (sales.getNoticeId() != null) {
- salesNoticeService.finishSalesNotice(sales.getNoticeId());
+ updateSalesNoticeOutCount(sales);
}
- // 5. 鍥炲啓 ERP 閿�鍞鍗曠殑鍑哄簱鏁伴噺鍜岀姸鎬�
+ // 6. 鍥炲啓 ERP 閿�鍞鍗曠殑鍑哄簱鏁伴噺鍜岀姸鎬�
updateErpSaleOrderOutCount(sales);
+ }
+
+ /**
+ * 鏇存柊鍙戣揣閫氱煡鍗曠殑鍑哄簱鏁伴噺鍜岀姸鎬�
+ */
+ private void updateSalesNoticeOutCount(MesWmProductSalesDO sales) {
+ // 鑾峰彇鍑哄簱鍗曡
+ List<MesWmProductSalesLineDO> lines = productSalesLineService.getProductSalesLineListBySalesId(sales.getId());
+ if (CollUtil.isEmpty(lines)) {
+ return;
+ }
+ // 閬嶅巻琛岋紝鎸� noticeLineId 鏇存柊鍑哄簱鏁伴噺
+ for (MesWmProductSalesLineDO line : lines) {
+ if (line.getNoticeLineId() != null && line.getQuantity() != null) {
+ salesNoticeService.updateSalesNoticeLineOutCount(line.getNoticeLineId(), line.getQuantity());
+ }
+ }
}
/**
@@ -282,7 +350,8 @@
.setBatchId(detail.getBatchId()).setBatchCode(detail.getBatchCode())
.setWarehouseId(detail.getWarehouseId()).setLocationId(detail.getLocationId()).setAreaId(detail.getAreaId())
.setBizType(MesBizTypeConstants.WM_PRODUCT_SALES).setBizId(sales.getId())
- .setBizCode(sales.getCode()).setBizLineId(detail.getLineId())));
+ .setBizCode(sales.getCode()).setBizLineId(detail.getLineId())
+ .setMaterialStockId(detail.getMaterialStockId()))); // 鎸囧畾搴撳瓨璁板綍ID锛岄伩鍏嶉噸鏂板尮閰�
}
@Override
@@ -296,6 +365,8 @@
MesWmProductSalesStatusEnum.CANCELED.getStatus())) {
throw exception(WM_PRODUCT_SALES_CANNOT_CANCEL);
}
+ // 閲婃斁搴撳瓨鍗犵敤
+ stockReserveService.releaseReserve(MesWmStockReserveBizTypeEnum.PRODUCT_SALES.getType(), id);
// 鍙栨秷
productSalesMapper.updateById(new MesWmProductSalesDO()
.setId(id).setStatus(MesWmProductSalesStatusEnum.CANCELED.getStatus()));
@@ -322,7 +393,7 @@
// 鏍¢獙缂栫爜鍞竴
validateCodeUnique(id, reqVO.getCode());
// 鏍¢獙瀹㈡埛瀛樺湪
- clientService.validateClientExistsAndEnable(reqVO.getClientId());
+ customerApi.validateCustomer(reqVO.getClientId());
// 鏍¢獙鍙戣揣閫氱煡鍗�
if (reqVO.getNoticeId() != null) {
MesWmSalesNoticeDO notice = salesNoticeService.validateSalesNoticeExists(reqVO.getNoticeId());
--
Gitblit v1.9.3