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-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java | 78 +++++++++++++++++++++++++--------------
1 files changed, 50 insertions(+), 28 deletions(-)
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
index e210590..14990a0 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
@@ -2,8 +2,10 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemPageReqVO;
import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemSaveReqVO;
import cn.iocoder.yudao.module.mdm.dal.dataobject.category.MdmItemCategoryDO;
@@ -15,8 +17,12 @@
import cn.iocoder.yudao.module.mdm.service.category.MdmItemCategoryService;
import cn.iocoder.yudao.module.mdm.service.unit.MdmUnitMeasureService;
import cn.iocoder.yudao.module.mes.api.item.MesMdItemApi;
+import cn.iocoder.yudao.module.mes.api.item.MesMdItemTypeApi;
import cn.iocoder.yudao.module.mes.api.item.dto.MesMdItemSyncReqDTO;
+import cn.iocoder.yudao.module.mes.api.item.dto.MesMdItemTypeRespDTO;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -54,6 +60,10 @@
@Resource
private MdmItemBatchConfigMapper itemBatchConfigMapper;
+ @Resource
+ private MesMdItemTypeApi mesMdItemTypeApi;
+
+
@Override
@Transactional(rollbackFor = Exception.class)
public Long createItem(MdmItemSaveReqVO createReqVO) {
@@ -67,10 +77,9 @@
// 淇濆瓨鎵规閰嶇疆锛堝鏋滄湁锛�
saveBatchConfig(item.getId(), createReqVO);
- // 鍚屾鍒� MES锛堝嬀閫� syncMes 鏃讹級
- if (Boolean.TRUE.equals(createReqVO.getSyncMes())) {
- syncItemToMes(createReqVO);
- }
+ // 濮嬬粓鍚屾鍒� MES
+ createReqVO.setId(item.getId());
+ syncItemToMes(createReqVO);
return item.getId();
}
@@ -89,10 +98,8 @@
// 淇濆瓨鎵规閰嶇疆锛堝鏋滄湁锛�
saveBatchConfig(updateReqVO.getId(), updateReqVO);
- // 鍚屾鍒� MES锛堝嬀閫� syncMes 鏃讹級
- if (Boolean.TRUE.equals(updateReqVO.getSyncMes())) {
- syncItemToMes(updateReqVO);
- }
+ // 濮嬬粓鍚屾鍒� MES
+ syncItemToMes(updateReqVO);
}
private void validateItemSaveData(MdmItemSaveReqVO reqVO) {
@@ -120,25 +127,13 @@
// 瑙f瀽鍒嗙被 id -> code锛堜娇鐢� MDM 鏈湴鍒嗙被鏈嶅姟锛�
String itemTypeCode = null;
if (reqVO.getCategoryId() != null) {
- MdmItemCategoryDO category = itemCategoryService.getItemCategory(reqVO.getCategoryId());
- if (category != null) {
- itemTypeCode = category.getCode();
- }
- } else if (reqVO.getItemType() != null) {
- // 鏍规嵁 itemType 鏌ユ壘瀵瑰簲鍒嗙被缂栫爜
- // itemType: 1鍘熸枡, 2鍗婃垚鍝�, 3鎴愬搧, 4杈呮枡
- String itemTypeName = convertItemTypeToName(reqVO.getItemType());
- List<MdmItemCategoryDO> categories = itemCategoryService.getItemCategoryList(
- itemCategoryService.getItemCategoryChildrenList(null).stream().map(MdmItemCategoryDO::getId).collect(Collectors.toSet()));
- itemTypeCode = categories.stream()
- .filter(c -> c.getName() != null && c.getName().equals(itemTypeName))
- .findFirst()
- .map(MdmItemCategoryDO::getCode)
- .orElse(null);
+ CommonResult<MesMdItemTypeRespDTO> itemType = mesMdItemTypeApi.getItemType(reqVO.getCategoryId());
+ itemTypeCode = itemType.getData().getCode();
}
// 缁勮鍚屾 DTO
MesMdItemSyncReqDTO syncReqDTO = new MesMdItemSyncReqDTO();
syncReqDTO.setCode(reqVO.getCode());
+ syncReqDTO.setMdmItemId(reqVO.getId());
syncReqDTO.setName(reqVO.getName());
syncReqDTO.setSpecification(reqVO.getSpecification());
syncReqDTO.setUnitCode(unitCode);
@@ -166,11 +161,14 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public void updateItemStatus(Long id, Integer status) {
// 鏍¢獙瀛樺湪
validateItemExists(id);
// 鏇存柊鐘舵��
itemMapper.updateById(new MdmItemDO().setId(id).setStatus(status));
+ // 鍚屾鐘舵�佸埌 MES
+ mesMdItemApi.updateItemStatus(id, status);
}
@Override
@@ -178,13 +176,37 @@
public void deleteItem(Long id) {
// 鏍¢獙瀛樺湪
MdmItemDO item = validateItemExists(id);
- // 瑙e喅杞垹闄ゅ敮涓�閿啿绐侊細濡傛灉宸插瓨鍦ㄧ浉鍚� code 涓斿凡杞垹闄ょ殑璁板綍锛屽厛鐗╃悊鍒犻櫎瀹�
-// MdmItemDO existingDeleted = itemMapper.selectByCodeAndDeleted(item.getCode(), true);
-// if (existingDeleted != null && !existingDeleted.getId().equals(id)) {
-// itemMapper.physicalDeleteById(existingDeleted.getId());
-// }
+ // 鏍¢獙鐗╂枡鏄惁琚笟鍔″紩鐢�
+ validateItemNoReference(id);
// 杞垹闄ゅ綋鍓嶈褰�
itemMapper.deleteById(id);
+ // 鍚屾鍒犻櫎鍒� MES
+ mesMdItemApi.deleteItem(id);
+ }
+
+ /**
+ * 鏍¢獙鐗╂枡鏈涓氬姟寮曠敤锛堥攢鍞�侀噰璐�佺敓浜с�佽川妫�銆佸簱瀛樼瓑锛�
+ *
+ * @param id 鐗╂枡缂栧彿
+ */
+ private void validateItemNoReference(Long id) {
+ List<Map<String, Object>> references = itemMapper.selectItemReferenceCount(id);
+ if (CollUtil.isNotEmpty(references)) {
+ String refDesc = references.stream()
+ .map(r -> r.get("source") + "(" + r.get("cnt") + ")")
+ .collect(Collectors.joining("銆�"));
+ throw exception(MDM_ITEM_EXISTS_REFERENCE, refDesc);
+ }
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void deleteItemList(Collection<Long> ids) {
+ if (CollUtil.isEmpty(ids)) {
+ return;
+ }
+ // 閫愪釜鍒犻櫎锛堝鐢ㄥ崟鏉″垹闄ら�昏緫锛屼繚鎸佹牎楠岋級
+ ids.forEach(this::deleteItem);
}
@Override
--
Gitblit v1.9.3