From defe1e1c3ade87de0a7990f565f08f93aeb2decc Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期日, 08 十一月 2026 19:31:46 +0800
Subject: [PATCH] fix(bpm): 统一审批标题单号并收紧各模块提交校验
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java | 94 ++++++++++++++++++++++++++++-------------------
1 files changed, 56 insertions(+), 38 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java
index 590df99..14fc6b1 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java
@@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.mes.service.wm.productsales;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
+import cn.iocoder.yudao.module.erp.api.sale.ErpSaleOrderApi;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ObjUtil;
@@ -35,7 +36,7 @@
/**
* MES 閿�鍞嚭搴撳崟琛� Service 瀹炵幇绫�
*
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
*/
@Service
@Validated
@@ -60,16 +61,44 @@
@Resource
@Lazy
private MesQcOqcService oqcService;
+ @Resource
+ private ErpSaleOrderApi saleOrderApi;
@Override
public Long createProductSalesLine(MesWmProductSalesLineSaveReqVO createReqVO) {
// 鏍¢獙鏁版嵁
- validateLineSaveData(createReqVO);
+ MesWmSalesNoticeLineDO noticeLine = validateLineSaveData(createReqVO);
// 鏂板
MesWmProductSalesLineDO line = BeanUtils.toBean(createReqVO, MesWmProductSalesLineDO.class);
+ if (noticeLine != null) {
+ line.setSaleOrderItemId(noticeLine.getSaleOrderItemId());
+ }
+ fillProductSalesLinePrice(line);
productSalesLineMapper.insert(line);
return line.getId();
+ }
+
+ /**
+ * 鎸夐攢鍞鍗曡鍗曚环鍥炲~鍑哄簱琛岄噾棰濓紝渚涘紑绁�/瀵硅处浣跨敤
+ */
+ private void fillProductSalesLinePrice(MesWmProductSalesLineDO line) {
+ if (line.getSaleOrderItemId() == null) {
+ return;
+ }
+ try {
+ var item = saleOrderApi.getSaleOrderItem(line.getSaleOrderItemId()).getData();
+ if (item == null || item.getProductPrice() == null) {
+ return;
+ }
+ line.setPrice(item.getProductPrice());
+ if (line.getQuantity() != null) {
+ line.setTotalPrice(item.getProductPrice().multiply(line.getQuantity()));
+ }
+ } catch (Exception ex) {
+ // 浠锋牸鍙槸蹇収锛岃鍗曡鍙栦笉鍒版椂涓嶉樆鏂紑鍗�
+ log.warn("[fillProductSalesLinePrice][閿�鍞鍗曡({}) 浠锋牸蹇収澶辫触]", line.getSaleOrderItemId(), ex);
+ }
}
@Override
@@ -78,39 +107,17 @@
MesWmProductSalesLineDO oldLine = validateProductSalesLineExists(updateReqVO.getId());
// 鏍¢獙鏁版嵁
updateReqVO.setSalesId(oldLine.getSalesId());
- validateLineSaveData(updateReqVO);
+ MesWmSalesNoticeLineDO noticeLine = validateLineSaveData(updateReqVO);
// 鏇存柊
MesWmProductSalesLineDO updateObj = BeanUtils.toBean(updateReqVO, MesWmProductSalesLineDO.class);
+ if (noticeLine != null) {
+ updateObj.setSaleOrderItemId(noticeLine.getSaleOrderItemId());
+ }
+ fillProductSalesLinePrice(updateObj);
productSalesLineMapper.updateById(updateObj);
- // 妫�鏌ユ槸鍚﹂渶瑕佸垱寤� OQC 妫�楠屽崟锛氫粠涓嶉渶瑕佹楠屽彉涓洪渶瑕佹楠�
- if (Boolean.TRUE.equals(updateReqVO.getOqcCheckFlag())
- && !Boolean.TRUE.equals(oldLine.getOqcCheckFlag())) {
- // 鑾峰彇鍑哄簱鍗曚俊鎭�
- MesWmProductSalesDO sales = productSalesService.getProductSales(updateReqVO.getSalesId());
- if (sales == null) {
- log.warn("[updateProductSalesLine] 鍑哄簱鍗曚笉瀛樺湪锛宻alesId={}", updateReqVO.getSalesId());
- return;
- }
-
- // 鏋勫缓鍑哄簱鏄庣粏 DO
- MesWmProductSalesLineDO line = new MesWmProductSalesLineDO();
- line.setId(updateReqVO.getId());
- line.setItemId(updateReqVO.getItemId());
- line.setBatchCode(updateReqVO.getBatchCode());
- line.setQuantity(updateReqVO.getQuantity());
-
- // 鍒涘缓 OQC 妫�楠屽崟锛岃寮傚父鎶涘嚭
- Long oqcId = oqcService.createOqcFromProductSales(
- sales.getId(), line, sales.getCode(), sales.getClientId());
-
- // 鏇存柊鍑哄簱鏄庣粏鐨� oqcId 鍜岃川閲忕姸鎬�
- productSalesLineMapper.updateById(new MesWmProductSalesLineDO()
- .setId(updateReqVO.getId())
- .setOqcId(oqcId)
- .setQualityStatus(MesWmQualityStatusEnum.PENDING.getStatus()));
- }
+ // 鎻愪氦鍑哄簱鍗曞悗鐢辫川妫�浜哄憳閫夋嫨宸插畬鎴愮殑鍑哄巶妫�楠屽崟銆�
}
@Override
@@ -181,15 +188,26 @@
/**
* 鏍¢獙淇濆瓨鏃剁殑鍏宠仈鏁版嵁
*/
- private void validateLineSaveData(MesWmProductSalesLineSaveReqVO reqVO) {
+ private MesWmSalesNoticeLineDO validateLineSaveData(MesWmProductSalesLineSaveReqVO reqVO) {
// 鏍¢獙涓诲崟瀛樺湪涓斾负鑽夌鐘舵��
MesWmProductSalesDO sales = productSalesService.validateProductSalesExistsAndDraft(reqVO.getSalesId());
// 鏍¢獙鐗╂枡瀛樺湪
mdmItemService.validateItemExistsAndEnable(reqVO.getItemId());
// 鏍¢獙鍏宠仈鍙戣揣閫氱煡鍗曡锛堝瓨鍦ㄦ�� + 褰掑睘 + 瀛楁涓�鑷存�э級
- validateSalesNoticeLine(sales, reqVO);
+ MesWmSalesNoticeLineDO noticeLine = validateSalesNoticeLine(sales, reqVO);
+ if (noticeLine == null && sales.getSaleOrderId() != null) {
+ if (reqVO.getSaleOrderItemId() == null) {
+ throw exception(WM_SALES_NOTICE_SALE_ORDER_ITEM_EMPTY);
+ }
+ var item = saleOrderApi.getSaleOrderItem(reqVO.getSaleOrderItemId()).getCheckedData();
+ if (item == null || !Objects.equals(item.getOrderId(), sales.getSaleOrderId())
+ || !Objects.equals(item.getProductId(), reqVO.getItemId())) {
+ throw exception(WM_SALES_NOTICE_LINE_SALE_ITEM_MISMATCH);
+ }
+ }
// 鏍规嵁 batchCode 瑙f瀽 batchId
fillBatchId(reqVO);
+ return noticeLine;
}
/**
@@ -198,7 +216,7 @@
* @param sales 鍑哄簱鍗�
* @param reqVO 鍑哄簱琛岃姹�
*/
- private void validateSalesNoticeLine(MesWmProductSalesDO sales, MesWmProductSalesLineSaveReqVO reqVO) {
+ private MesWmSalesNoticeLineDO validateSalesNoticeLine(MesWmProductSalesDO sales, MesWmProductSalesLineSaveReqVO reqVO) {
Long noticeLineId = reqVO.getNoticeLineId();
// 鎯呭喌涓�锛氬鏋滃嚭搴撳崟鍏宠仈浜嗗彂璐ч�氱煡鍗曪紝鍒欏繀椤诲叧鑱斿彂璐ч�氱煡鍗曡
if (sales.getNoticeId() != null) {
@@ -220,13 +238,14 @@
&& ObjUtil.notEqual(reqVO.getBatchCode(), noticeLine.getBatchCode())) {
throw exception(WM_PRODUCT_SALES_LINE_NOTICE_LINE_BATCH_MISMATCH);
}
- return;
+ return noticeLine;
}
// 鎯呭喌浜岋細濡傛灉鍑哄簱鍗曟病鏈夊叧鑱斿彂璐ч�氱煡鍗曪紝鍒欎笉鍏佽鍏宠仈鍙戣揣閫氱煡鍗曡
if (noticeLineId != null) {
throw exception(WM_PRODUCT_SALES_LINE_SALES_NOTICE_LINE_NOT_ALLOWED);
}
+ return null;
}
@Override
@@ -246,19 +265,18 @@
Long salesId = currentLine.getSalesId();
List<MesWmProductSalesLineDO> allLines = productSalesLineMapper.selectListBySalesId(salesId);
- // 2.1 妫�鏌ユ槸鍚︽湁涓嶅悎鏍艰 鈫� 鍙栨秷鍑哄簱鍗�
+ // 涓嶅悎鏍艰鐣欏緟鍚庣画澶勭疆锛屼笉鑳藉洜涓烘楠岀粨鏋滆嚜鍔ㄥ彇娑堟暣寮犲嚭搴撳崟銆�
boolean hasNg = CollectionUtils.anyMatch(allLines,
line -> Boolean.TRUE.equals(line.getOqcCheckFlag())
&& Objects.equals(line.getQualityStatus(), MesWmQualityStatusEnum.FAIL.getStatus()));
if (hasNg) {
- log.info("[updateProductSalesLineWhenOqcFinish][閿�鍞嚭搴撳崟({}) 瀛樺湪璐ㄦ涓嶅悎鏍艰锛屽彇娑堝嚭搴撳崟]", salesId);
- productSalesService.cancelProductSales(salesId);
+ log.info("[updateProductSalesLineWhenOqcFinish][閿�鍞嚭搴撳崟({}) 瀛樺湪璐ㄦ涓嶅悎鏍艰锛岀瓑寰呭悗缁缃甝", salesId);
return;
}
// 2.2 妫�鏌ユ槸鍚︽墍鏈� OQC 琛岄兘宸插畬鎴愶紝鑷姩娴佽浆 CONFIRMED 鈫� APPROVING
boolean hasUnchecked = CollectionUtils.anyMatch(allLines,
- line -> Boolean.TRUE.equals(line.getOqcCheckFlag()) && line.getOqcId() == null);
+ line -> Boolean.TRUE.equals(line.getOqcCheckFlag()) && !Objects.equals(line.getQualityStatus(), MesWmQualityStatusEnum.PASS.getStatus()));
if (!hasUnchecked) {
log.info("[updateProductSalesLineWhenOqcFinish][閿�鍞嚭搴撳崟({}) 鎵�鏈� OQC 琛屾楠屽畬鎴愶紝娴佽浆鍒板緟鎷h揣]", salesId);
productSalesService.confirmProductSales(salesId);
--
Gitblit v1.9.3