From c2053d7017625f270577bc0f6c523d04f52db6ea Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 24 七月 2026 14:20:29 +0800
Subject: [PATCH] refactor(crm): 重构文件上传功能,替换原有的fileUrls字段为统一的StorageAttachmentApi
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java | 94 ++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 88 insertions(+), 6 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 230bd63..c314980 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
@@ -3,9 +3,12 @@
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.api.item.dto.MesMdItemSyncReqDTO;
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;
@@ -13,6 +16,9 @@
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.*;
@@ -33,29 +39,56 @@
@Resource
private MesMdItemService itemService;
@Resource
+ private MesMdItemMapper itemMapper;
+ @Resource
private MesMdItemTypeService itemTypeService;
@Resource
private MesMdUnitMeasureService unitMeasureService;
+ @Resource
+ private MesMdItemBatchConfigService itemBatchConfigService;
@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);
- return itemService.createItem(saveReqVO);
+ // 浣跨敤 MDM 鐗╂枡 ID 浣滀负 MES 鐗╂枡 ID
+ if (syncReqDTO.getMdmItemId() != null) {
+ saveReqVO.setId(syncReqDTO.getMdmItemId());
+ }
+ Long itemId = itemService.createItem(saveReqVO);
+ // 鍚屾鎵规閰嶇疆
+// 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) {
- itemService.createItem(saveReqVO);
+ existItem = itemService.getItemByCode(syncReqDTO.getCode());
+ }
+ Long itemId;
+ if (existItem == null) {
+ itemId = itemService.createItem(saveReqVO);
} else {
saveReqVO.setId(existItem.getId());
itemService.updateItem(saveReqVO);
+ itemId = existItem.getId();
}
+ // 鍚屾鎵规閰嶇疆
+// saveBatchConfig(itemId, syncReqDTO);
}
/**
@@ -79,4 +112,53 @@
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);
+ }
+
+ /**
+ * 淇濆瓨鎵规閰嶇疆
+ */
+ private void saveBatchConfig(Long itemId, MesMdItemSyncReqDTO syncReqDTO) {
+ // 妫�鏌ユ槸鍚︽湁鎵规閰嶇疆鏁版嵁
+ if (syncReqDTO.getProduceDateFlag() == null
+ && syncReqDTO.getExpireDateFlag() == null
+ && syncReqDTO.getReceiptDateFlag() == null
+ && syncReqDTO.getVendorFlag() == null
+ && syncReqDTO.getPurchaseOrderCodeFlag() == null
+ && syncReqDTO.getLotNumberFlag() == null
+ && syncReqDTO.getQualityStatusFlag() == null) {
+ return;
+ }
+ MesMdItemBatchConfigSaveReqVO configReqVO = new MesMdItemBatchConfigSaveReqVO();
+ configReqVO.setItemId(itemId);
+ configReqVO.setProduceDateFlag(syncReqDTO.getProduceDateFlag());
+ configReqVO.setExpireDateFlag(syncReqDTO.getExpireDateFlag());
+ configReqVO.setReceiptDateFlag(syncReqDTO.getReceiptDateFlag());
+ configReqVO.setVendorFlag(syncReqDTO.getVendorFlag());
+ configReqVO.setPurchaseOrderCodeFlag(syncReqDTO.getPurchaseOrderCodeFlag());
+ configReqVO.setLotNumberFlag(syncReqDTO.getLotNumberFlag());
+ configReqVO.setQualityStatusFlag(syncReqDTO.getQualityStatusFlag());
+ itemBatchConfigService.saveItemBatchConfig(configReqVO);
+ }
+
}
--
Gitblit v1.9.3