From 616a6b2e9a7824da8d11a4e11730fd2f9b615299 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 06 十一月 2026 09:46:53 +0800
Subject: [PATCH] fix(qc): 修复巡检记录校验缺少租户隔离问题
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java | 81 ++++++++++++++++++++++++++++++++--------
1 files changed, 64 insertions(+), 17 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 a1ec2f7..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;
@@ -17,6 +18,7 @@
import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.wm.salesnotice.MesWmSalesNoticeLineDO;
import cn.iocoder.yudao.module.mes.service.wm.salesnotice.MesWmSalesNoticeLineService;
+import cn.iocoder.yudao.module.mes.service.qc.oqc.MesQcOqcService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
@@ -34,7 +36,7 @@
/**
* MES 閿�鍞嚭搴撳崟琛� Service 瀹炵幇绫�
*
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
*/
@Service
@Validated
@@ -56,16 +58,47 @@
@Resource
@Lazy
private MesWmSalesNoticeLineService salesNoticeLineService;
+ @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
@@ -74,11 +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);
+
+ // 鎻愪氦鍑哄簱鍗曞悗鐢辫川妫�浜哄憳閫夋嫨宸插畬鎴愮殑鍑哄巶妫�楠屽崟銆�
}
@Override
@@ -149,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;
}
/**
@@ -166,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) {
@@ -175,7 +225,8 @@
}
MesWmSalesNoticeLineDO noticeLine = salesNoticeLineService.validateSalesNoticeLineExists(
noticeLineId, sales.getNoticeId());
- // 鏍¢獙鍏抽敭瀛楁涓�鑷存�э細鐗╂枡銆佹暟閲忋�佹壒娆″彿銆丱QC 妫�楠屾爣璇�
+ // 鏍¢獙鍏抽敭瀛楁涓�鑷存�э細鐗╂枡銆佹暟閲忋�佹壒娆″彿
+ // 娉細OQC 妫�楠屾爣璇嗗厑璁稿湪鍑哄簱鏃剁嫭绔嬭缃紝涓嶅己鍒朵笌閫氱煡鍗曚竴鑷�
if (ObjUtil.notEqual(reqVO.getItemId(), noticeLine.getItemId())) {
throw exception(WM_PRODUCT_SALES_LINE_NOTICE_LINE_ITEM_MISMATCH);
}
@@ -187,24 +238,21 @@
&& ObjUtil.notEqual(reqVO.getBatchCode(), noticeLine.getBatchCode())) {
throw exception(WM_PRODUCT_SALES_LINE_NOTICE_LINE_BATCH_MISMATCH);
}
- if (noticeLine.getOqcCheckFlag() != null
- && ObjUtil.notEqual(reqVO.getOqcCheckFlag(), noticeLine.getOqcCheckFlag())) {
- throw exception(WM_PRODUCT_SALES_LINE_NOTICE_LINE_OQC_MISMATCH);
- }
- return;
+ return noticeLine;
}
// 鎯呭喌浜岋細濡傛灉鍑哄簱鍗曟病鏈夊叧鑱斿彂璐ч�氱煡鍗曪紝鍒欎笉鍏佽鍏宠仈鍙戣揣閫氱煡鍗曡
if (noticeLineId != null) {
throw exception(WM_PRODUCT_SALES_LINE_SALES_NOTICE_LINE_NOT_ALLOWED);
}
+ return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateProductSalesLineWhenOqcFinish(Long id, Long oqcId, Integer checkResult) {
// 1. 鏇存柊琛岀殑 oqcId + qualityStatus
- Integer qualityStatus = Objects.equals(checkResult, MesQcCheckResultEnum.PASS.getType())
+ Integer qualityStatus = Objects.equals(checkResult, MesQcCheckResultEnum.QUALIFIED.getType())
? MesWmQualityStatusEnum.PASS.getStatus() : MesWmQualityStatusEnum.FAIL.getStatus();
productSalesLineMapper.updateById(new MesWmProductSalesLineDO()
.setId(id).setOqcId(oqcId).setQualityStatus(qualityStatus));
@@ -217,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