From f7273277023f3497ac071bf98f556a569cb4dd25 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 17 九月 2026 16:24:10 +0800
Subject: [PATCH] feat(mes): 重构袋码生成与物料分类功能
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java | 73 +++++++++++++++++++++++++++---------
1 files changed, 55 insertions(+), 18 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java
index 8be526a..437a08f 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java
@@ -5,16 +5,18 @@
import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.MesMdItemSaveReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.batchconfig.MesMdItemBatchConfigSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO;
-import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemTypeDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO;
+import cn.iocoder.yudao.module.mes.dal.mysql.md.item.MesMdItemMapper;
import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemBatchConfigService;
import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService;
-import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemTypeService;
import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
+
+import java.util.Collection;
+import java.util.Set;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
@@ -23,9 +25,9 @@
* MES 鐗╂枡浜у搧 API 瀹炵幇绫�
*
* 渚� MDM 绛夋ā鍧楀悓姝ョ墿鏂欎富鏁版嵁鍒� MES 浣跨敤銆�
- * 鍗曚綅銆佸垎绫绘寜 code 鍦� MES 渚цВ鏋愪负瀵瑰簲 id銆�
+ * 鍗曚綅鎸� code 鍦� MES 渚цВ鏋愪负瀵瑰簲 id銆�
*
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
*/
@Service
@Validated
@@ -35,7 +37,7 @@
@Resource
private MesMdItemService itemService;
@Resource
- private MesMdItemTypeService itemTypeService;
+ private MesMdItemMapper itemMapper;
@Resource
private MesMdUnitMeasureService unitMeasureService;
@Resource
@@ -43,20 +45,36 @@
@Override
public Long createItem(MesMdItemSyncReqDTO syncReqDTO) {
- log.info("[createItem] 鍚屾鍒涘缓 MES 鐗╂枡浜у搧锛宑ode={}", syncReqDTO.getCode());
+ log.info("[createItem] 鍚屾鍒涘缓 MES 鐗╂枡浜у搧锛宑ode={}, mdmItemId={}", syncReqDTO.getCode(), syncReqDTO.getMdmItemId());
MesMdItemSaveReqVO saveReqVO = buildSaveReqVO(syncReqDTO);
+ // 浣跨敤 MDM 鐗╂枡 ID 浣滀负 MES 鐗╂枡 ID
+ if (syncReqDTO.getMdmItemId() != null) {
+ saveReqVO.setId(syncReqDTO.getMdmItemId());
+ }
Long itemId = itemService.createItem(saveReqVO);
// 鍚屾鎵规閰嶇疆
- saveBatchConfig(itemId, syncReqDTO);
+// saveBatchConfig(itemId, syncReqDTO);
return itemId;
}
@Override
public void updateItem(MesMdItemSyncReqDTO syncReqDTO) {
- log.info("[updateItem] 鍚屾鏇存柊 MES 鐗╂枡浜у搧锛宑ode={}", syncReqDTO.getCode());
+ log.info("[updateItem] 鍚屾鏇存柊 MES 鐗╂枡浜у搧锛宑ode={}, mdmItemId={}", syncReqDTO.getCode(), syncReqDTO.getMdmItemId());
MesMdItemSaveReqVO saveReqVO = buildSaveReqVO(syncReqDTO);
- // 鎸� code 鍖归厤锛氬瓨鍦ㄥ垯鏇存柊锛屼笉瀛樺湪鍒欏垱寤猴紙upsert锛�
- MesMdItemDO existItem = itemService.getItemByCode(syncReqDTO.getCode());
+ // 浣跨敤 MDM 鐗╂枡 ID 浣滀负 MES 鐗╂枡 ID
+ if (syncReqDTO.getMdmItemId() != null) {
+ saveReqVO.setId(syncReqDTO.getMdmItemId());
+ }
+ // 鎸� ID 鎴� code 鍖归厤锛氬瓨鍦ㄥ垯鏇存柊锛屼笉瀛樺湪鍒欏垱寤猴紙upsert锛�
+ MesMdItemDO existItem = null;
+ // 浼樺厛鎸� ID 鏌ユ壘
+ if (syncReqDTO.getMdmItemId() != null) {
+ existItem = itemService.getItem(syncReqDTO.getMdmItemId());
+ }
+ // 濡傛灉鎸� ID 鎵句笉鍒帮紝鍐嶆寜 code 鏌ユ壘
+ if (existItem == null) {
+ existItem = itemService.getItemByCode(syncReqDTO.getCode());
+ }
Long itemId;
if (existItem == null) {
itemId = itemService.createItem(saveReqVO);
@@ -66,11 +84,13 @@
itemId = existItem.getId();
}
// 鍚屾鎵规閰嶇疆
- saveBatchConfig(itemId, syncReqDTO);
+// saveBatchConfig(itemId, syncReqDTO);
}
/**
- * 灏嗗悓姝� DTO 杞崲涓� MES 鐗╂枡浜у搧 SaveReqVO锛屽苟鎸� code 瑙f瀽鍗曚綅/鍒嗙被 id
+ * 灏嗗悓姝� DTO 杞崲涓� MES 鐗╂枡浜у搧 SaveReqVO锛屽苟鎸� code 瑙f瀽鍗曚綅 id
+ *
+ * MDM 鍝佺绠$悊宸插幓鎺夈�屽搧绉嶅垎绫汇�嶏紝鍚屾涓嶅啀璁剧疆鐗╂枡鍒嗙被锛坕tem_type_id 鐣欑┖锛屽彲鍦� MES 渚ф墜宸ヨˉ濉級
*/
private MesMdItemSaveReqVO buildSaveReqVO(MesMdItemSyncReqDTO syncReqDTO) {
// 瑙f瀽璁¢噺鍗曚綅 code -> id
@@ -78,18 +98,35 @@
if (unitMeasure == null) {
throw exception(MD_UNIT_MEASURE_NOT_EXISTS);
}
- // 瑙f瀽鐗╂枡鍒嗙被 code -> id
- MesMdItemTypeDO itemType = itemTypeService.getItemTypeByCode(syncReqDTO.getItemTypeCode());
- if (itemType == null) {
- throw exception(MD_ITEM_TYPE_NOT_EXISTS);
- }
// 缁勮锛坈ode/name/specification/safeStockFlag/minStock/maxStock/highValue/batchFlag/remark 鍚屽悕鎷疯礉锛�
MesMdItemSaveReqVO saveReqVO = BeanUtils.toBean(syncReqDTO, MesMdItemSaveReqVO.class);
saveReqVO.setUnitMeasureId(unitMeasure.getId());
- saveReqVO.setItemTypeId(itemType.getId());
return saveReqVO;
}
+ @Override
+ public void deleteItem(Long mdmItemId) {
+ log.info("[deleteItem] 鍚屾鍒犻櫎 MES 鐗╂枡浜у搧锛宮dmItemId={}", mdmItemId);
+ MesMdItemDO existItem = itemService.getItemByMdmItemId(mdmItemId);
+ if (existItem != null) {
+ itemService.deleteItem(existItem.getId());
+ }
+ }
+
+ @Override
+ public void updateItemStatus(Long mdmItemId, Integer status) {
+ log.info("[updateItemStatus] 鍚屾鏇存柊 MES 鐗╂枡浜у搧鐘舵�侊紝mdmItemId={}, status={}", mdmItemId, status);
+ MesMdItemDO existItem = itemService.getItemByMdmItemId(mdmItemId);
+ if (existItem != null) {
+ itemService.updateItemStatus(existItem.getId(), status);
+ }
+ }
+
+ @Override
+ public Set<Long> getSyncedMdmItemIds(Collection<Long> mdmItemIds) {
+ return itemMapper.selectMdmItemIdsByMdmItemIds(mdmItemIds);
+ }
+
/**
* 淇濆瓨鎵规閰嶇疆
*/
--
Gitblit v1.9.3