From 7bd10d34e8a8dc2437ec8551eb511e37634d7306 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 02 十一月 2026 16:51:52 +0800
Subject: [PATCH] feat(mes): 生产计划审批改走协同办公,修复工单领料与产成品入库校验
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/materialstock/MesWmMaterialStockServiceImpl.java | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 108 insertions(+), 10 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/materialstock/MesWmMaterialStockServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/materialstock/MesWmMaterialStockServiceImpl.java
index 4f368d9..1f93da2 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/materialstock/MesWmMaterialStockServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/materialstock/MesWmMaterialStockServiceImpl.java
@@ -8,6 +8,7 @@
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
+import cn.iocoder.yudao.framework.operatelog.core.util.OperateLogUtils;
import cn.iocoder.yudao.module.mes.controller.admin.wm.materialstock.vo.MesWmMaterialStockAdjustReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.wm.materialstock.vo.MesWmMaterialStockFreezeReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.wm.materialstock.vo.MesWmMaterialStockImportExcelVO;
@@ -38,8 +39,10 @@
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.wm.warehouse.MesWmWarehouseAreaService;
+import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseDefaultService;
import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseLocationService;
import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseService;
+import com.mzt.logapi.starter.annotation.LogRecord;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@@ -57,6 +60,7 @@
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
+import static cn.iocoder.yudao.module.mes.enums.LogRecordConstants.*;
/**
* MES 搴撳瓨鍙拌处 Service 瀹炵幇绫�
@@ -82,6 +86,9 @@
@Resource
@Lazy
private MesWmWarehouseService warehouseService;
+ @Resource
+ @Lazy
+ private MesWmWarehouseDefaultService warehouseDefaultService;
@Resource
@Lazy
private MesWmTransactionService wmTransactionService;
@@ -242,6 +249,10 @@
@Override
public void checkAreaMixingRule(Long areaId, Long itemId, Long batchId) {
+ // 鏈寚瀹氬簱浣嶏紙瀹㈡埛鏈惎鐢ㄥ簱鍖�/搴撲綅绠$悊锛夋椂涓嶆牎楠屾贩鏀撅紝鍚庣画鍏ュ簱浜嬪姟浼氳惤鍒颁粨搴撻粯璁ゅ簱浣�
+ if (areaId == null) {
+ return;
+ }
// 1.1 鏍¢獙搴撲綅蹇呴』瀛樺湪
MesWmWarehouseAreaDO area = areaService.validateWarehouseAreaExists(areaId);
@@ -278,20 +289,87 @@
throw exception(WM_MATERIAL_STOCK_REQUIRED);
}
MesWmMaterialStockDO stock = validateMaterialStockExists(materialStockId);
- // 2. 鏍¢獙搴撳瓨璁板綍鐨勭墿鏂欍�佹壒娆°�佷粨搴撱�佸簱鍖恒�佸簱浣嶇瓑淇℃伅涓庡墠绔�夋嫨鐨勪竴鑷达紝閬垮厤涓插崟鎴栬秺鏉冩彁浜�
- if (ObjUtil.notEqual(stock.getItemId(), itemId)
- || ObjUtil.notEqual(stock.getBatchId(), batchId)
- || (batchCode != null && ObjUtil.notEqual(stock.getBatchCode(), batchCode))
- || ObjUtil.notEqual(stock.getWarehouseId(), warehouseId)
- || ObjUtil.notEqual(stock.getLocationId(), locationId)
- || ObjUtil.notEqual(stock.getAreaId(), areaId)) {
- throw exception(WM_MATERIAL_STOCK_SELECTION_MISMATCH);
+ // 2. 鏍¢獙搴撳瓨璁板綍鐨勭墿鏂欍�佹壒娆°�佷粨搴撱�佸簱鍖恒�佸簱浣嶇瓑淇℃伅涓庡崟鎹竴鑷达紝閬垮厤涓插崟鎴栬秺鏉冩彁浜ゃ��
+ // 閫愪釜缁村害姣斿锛屽懡涓椂鎻愮ず鍏蜂綋宸紓锛堝簱瀛樹晶 vs 鍗曟嵁渚э級骞剁粰鍑哄鐞嗗姙娉曪紝閬垮厤绗肩粺鎶�"淇℃伅涓嶄竴鑷�"
+ String mismatch = buildSelectedStockMismatch(
+ stock, itemId, batchId, batchCode, warehouseId, locationId, areaId);
+ if (mismatch != null) {
+ throw new ServiceException(WM_MATERIAL_STOCK_SELECTION_MISMATCH.getCode(),
+ "鎵�閫夊簱瀛樿褰曚笌鍗曟嵁涓嶄竴鑷达細" + mismatch + "銆傝閲嶆柊閫夋嫨璇ョ墿鏂欐纭殑搴撳瓨锛涜嫢浠撳簱/搴撳尯/搴撲綅/鎵规琚鐢ㄦ棤娉曚慨鏀癸紝璇峰垹闄ゆ湰鏉℃槑缁嗗悗閲嶆柊娣诲姞銆�");
}
// 3. 鏍¢獙搴撳瓨鏁伴噺鍏呰冻锛堝鏋滃墠绔紶浜� quantity锛屽垯蹇呴』淇濊瘉搴撳瓨鏁伴噺 >= quantity锛�
if (quantity != null && stock.getQuantity() != null && stock.getQuantity().compareTo(quantity) < 0) {
throw exception(WM_MATERIAL_STOCK_INSUFFICIENT);
}
return stock;
+ }
+
+ /**
+ * 閫愮淮搴︽瘮瀵瑰緟閫夊簱瀛樹笌鍗曟嵁浼犲叆鐨勪俊鎭紝杩斿洖绗竴涓笉涓�鑷寸淮搴︾殑鍙鎻忚堪锛涘叏閮ㄤ竴鑷磋繑鍥� null
+ */
+ private String buildSelectedStockMismatch(MesWmMaterialStockDO stock, Long itemId, Long batchId, String batchCode,
+ Long warehouseId, Long locationId, Long areaId) {
+ if (ObjUtil.notEqual(stock.getItemId(), itemId)) {
+ return "鎵�閫夊簱瀛樺綊灞炵墿鏂橻" + itemIdText(itemId) + "]锛屽崟鎹墿鏂欎负[" + itemIdText(stock.getItemId()) + "]";
+ }
+ if (ObjUtil.notEqual(stock.getBatchId(), batchId)) {
+ return "鎵�閫夊簱瀛樻壒娆" + batchText(stock.getBatchId(), stock.getBatchCode())
+ + "]锛屽崟鎹壒娆′负[" + batchText(batchId, batchCode) + "]";
+ }
+ if (batchCode != null && ObjUtil.notEqual(stock.getBatchCode(), batchCode)) {
+ return "鎵�閫夊簱瀛樻壒娆″彿[" + stock.getBatchCode() + "]锛屽崟鎹壒娆″彿涓篬" + batchCode + "]";
+ }
+ if (ObjUtil.notEqual(stock.getWarehouseId(), warehouseId)) {
+ return "鎵�閫夊簱瀛樹粨搴揫" + warehouseText(stock.getWarehouseId())
+ + "]锛屽崟鎹粨搴撲负[" + warehouseText(warehouseId) + "]";
+ }
+ if (ObjUtil.notEqual(stock.getLocationId(), locationId)) {
+ return "鎵�閫夊簱瀛樺簱鍖篬" + locationText(stock.getLocationId())
+ + "]锛屽崟鎹簱鍖轰负[" + locationText(locationId) + "]";
+ }
+ if (ObjUtil.notEqual(stock.getAreaId(), areaId)) {
+ return "鎵�閫夊簱瀛樺簱浣峓" + areaText(stock.getAreaId())
+ + "]锛屽崟鎹簱浣嶄负[" + areaText(areaId) + "]";
+ }
+ return null;
+ }
+
+ private String itemIdText(Long itemId) {
+ return itemId == null ? "鏈�夋嫨" : ("鐗╂枡ID=" + itemId);
+ }
+
+ private String batchText(Long batchId, String batchCode) {
+ if (StrUtil.isNotBlank(batchCode)) {
+ return batchCode;
+ }
+ return batchId == null ? "鏈�夋嫨" : ("鎵规ID=" + batchId);
+ }
+
+ private String warehouseText(Long warehouseId) {
+ if (warehouseId == null) {
+ return "鏈�夋嫨";
+ }
+ MesWmWarehouseDO warehouse = warehouseService.getWarehouse(warehouseId);
+ return warehouse != null && StrUtil.isNotBlank(warehouse.getName())
+ ? warehouse.getName() : ("浠撳簱ID=" + warehouseId);
+ }
+
+ private String locationText(Long locationId) {
+ if (locationId == null) {
+ return "鏈�夋嫨";
+ }
+ MesWmWarehouseLocationDO location = locationService.getWarehouseLocation(locationId);
+ return location != null && StrUtil.isNotBlank(location.getName())
+ ? location.getName() : ("搴撳尯ID=" + locationId);
+ }
+
+ private String areaText(Long areaId) {
+ if (areaId == null) {
+ return "鏈�夋嫨";
+ }
+ MesWmWarehouseAreaDO area = areaService.getWarehouseArea(areaId);
+ return area != null && StrUtil.isNotBlank(area.getName())
+ ? area.getName() : ("搴撲綅ID=" + areaId);
}
@Override
@@ -333,7 +411,14 @@
}
}
- // 3. 鏍¢獙搴撲綅娣锋斁瑙勫垯
+ // 3. 鏈寚瀹氬簱鍖�/搴撲綅鏃讹紝钀藉埌浠撳簱榛樿搴撳尯/搴撲綅锛堝鎴锋湭鍚敤搴撳尯/搴撲綅绠$悊锛�
+ if (reqVO.getWarehouseId() != null
+ && (reqVO.getLocationId() == null || reqVO.getAreaId() == null)) {
+ MesWmWarehouseAreaDO defaultArea = warehouseDefaultService.getOrCreateDefaultArea(reqVO.getWarehouseId());
+ reqVO.setLocationId(defaultArea.getLocationId());
+ reqVO.setAreaId(defaultArea.getId());
+ }
+ // 3.1 鏍¢獙搴撲綅娣锋斁瑙勫垯
checkAreaMixingRule(reqVO.getAreaId(), reqVO.getItemId(), batchId);
// 4. 鑾峰彇鎴栧垱寤哄簱瀛樿褰�
@@ -470,7 +555,16 @@
throw exception(WM_MATERIAL_STOCK_FROZEN);
}
- // 4. 鏍¢獙鐩爣搴撲綅娣锋斁瑙勫垯
+ // 4. 鐩爣搴撳尯/搴撲綅鏈寚瀹氭椂锛岃惤鍒扮洰鏍囦粨搴撶殑榛樿搴撳尯/搴撲綅锛堝鎴锋湭鍚敤搴撳尯/搴撲綅绠$悊锛�
+ if (reqVO.getToWarehouseId() == null) {
+ reqVO.setToWarehouseId(sourceStock.getWarehouseId());
+ }
+ if ((reqVO.getToLocationId() == null || reqVO.getToAreaId() == null)) {
+ MesWmWarehouseAreaDO defaultArea = warehouseDefaultService.getOrCreateDefaultArea(reqVO.getToWarehouseId());
+ reqVO.setToLocationId(defaultArea.getLocationId());
+ reqVO.setToAreaId(defaultArea.getId());
+ }
+ // 4.1 鏍¢獙鐩爣搴撲綅娣锋斁瑙勫垯
checkAreaMixingRule(reqVO.getToAreaId(), sourceStock.getItemId(), sourceStock.getBatchId());
// 5. 鐢熸垚绉诲簱鍗曞彿
@@ -526,6 +620,8 @@
}
@Override
+ @LogRecord(type = MES_WM_MATERIAL_STOCK_TYPE, subType = MES_WM_MATERIAL_STOCK_IMPORT_SUB_TYPE, bizNo = "0",
+ success = MES_WM_MATERIAL_STOCK_IMPORT_SUCCESS)
public MesWmMaterialStockImportRespVO importMaterialStockList(List<MesWmMaterialStockImportExcelVO> importList) {
// 鎿嶄綔绫诲瀷鍙栧�硷細澧炲姞 / 鍑忓皯 / 瑕嗙洊
final String OP_ADD = "澧炲姞";
@@ -688,6 +784,8 @@
respVO.getFailureNames().put(key, ex.getMessage());
}
}
+ // 璁板綍瀵煎叆缁撴灉姹囨�伙紝渚� @LogRecord 鐨� success 鏂囨寮曠敤
+ OperateLogUtils.putImportSummary(respVO.getCreateNames(), respVO.getUpdateNames(), respVO.getFailureNames());
return respVO;
}
--
Gitblit v1.9.3