From 63ba72f5d65a3a4dcd56d9228582042448af61d7 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 26 十月 2026 19:09:47 +0800
Subject: [PATCH] feat(mdm): 统一物料分类管理并迁移至MDM模块
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java | 239 +++++++++++++++++++++------------------
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApi.java | 30 +++++
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategoryRespDTO.java | 8 +
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApiImpl.java | 27 ++++
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategorySaveReqDTO.java | 37 ++++++
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryServiceImpl.java | 5
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryService.java | 7 +
7 files changed, 244 insertions(+), 109 deletions(-)
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApi.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApi.java
index b861b55..b9655ef 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApi.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApi.java
@@ -2,6 +2,7 @@
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategoryRespDTO;
+import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategorySaveReqDTO;
import java.util.Collection;
import java.util.List;
@@ -55,4 +56,33 @@
*/
CommonResult<MdmItemCategoryRespDTO> getItemCategoryByItemOrProduct(String itemOrProduct);
+ /**
+ * 鑾峰彇鍏ㄩ儴鍒嗙被鍒楄〃锛堝惈绂佺敤锛�
+ *
+ * @return 鍒嗙被鍒楄〃
+ */
+ CommonResult<List<MdmItemCategoryRespDTO>> getItemCategoryAllList();
+
+ /**
+ * 鍒涘缓鐗╂枡鍒嗙被
+ *
+ * @param createReqDTO 鍒涘缓淇℃伅
+ * @return 鍒嗙被缂栧彿
+ */
+ CommonResult<Long> createItemCategory(MdmItemCategorySaveReqDTO createReqDTO);
+
+ /**
+ * 鏇存柊鐗╂枡鍒嗙被
+ *
+ * @param updateReqDTO 鏇存柊淇℃伅
+ */
+ CommonResult<Boolean> updateItemCategory(MdmItemCategorySaveReqDTO updateReqDTO);
+
+ /**
+ * 鍒犻櫎鐗╂枡鍒嗙被
+ *
+ * @param id 鍒嗙被缂栧彿
+ */
+ CommonResult<Boolean> deleteItemCategory(Long id);
+
}
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApiImpl.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApiImpl.java
index c5195ef..44022cc 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApiImpl.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApiImpl.java
@@ -3,6 +3,8 @@
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategoryRespDTO;
+import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategorySaveReqDTO;
+import cn.iocoder.yudao.module.mdm.controller.admin.category.vo.MdmItemCategorySaveReqVO;
import cn.iocoder.yudao.module.mdm.dal.dataobject.category.MdmItemCategoryDO;
import cn.iocoder.yudao.module.mdm.service.category.MdmItemCategoryService;
import jakarta.annotation.Resource;
@@ -58,4 +60,29 @@
return success(BeanUtils.toBean(itemCategory, MdmItemCategoryRespDTO.class));
}
+ @Override
+ public CommonResult<List<MdmItemCategoryRespDTO>> getItemCategoryAllList() {
+ List<MdmItemCategoryDO> list = itemCategoryService.getItemCategoryAllList();
+ return success(BeanUtils.toBean(list, MdmItemCategoryRespDTO.class));
+ }
+
+ @Override
+ public CommonResult<Long> createItemCategory(MdmItemCategorySaveReqDTO createReqDTO) {
+ MdmItemCategorySaveReqVO reqVO = BeanUtils.toBean(createReqDTO, MdmItemCategorySaveReqVO.class);
+ return success(itemCategoryService.createItemCategory(reqVO));
+ }
+
+ @Override
+ public CommonResult<Boolean> updateItemCategory(MdmItemCategorySaveReqDTO updateReqDTO) {
+ MdmItemCategorySaveReqVO reqVO = BeanUtils.toBean(updateReqDTO, MdmItemCategorySaveReqVO.class);
+ itemCategoryService.updateItemCategory(reqVO);
+ return success(true);
+ }
+
+ @Override
+ public CommonResult<Boolean> deleteItemCategory(Long id) {
+ itemCategoryService.deleteItemCategory(id);
+ return success(true);
+ }
+
}
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategoryRespDTO.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategoryRespDTO.java
index a1913ce..dc4626d 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategoryRespDTO.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategoryRespDTO.java
@@ -3,6 +3,8 @@
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
+import java.time.LocalDateTime;
+
@Schema(description = "RPC 鏈嶅姟 - MDM 鐗╂枡鍒嗙被 Response DTO")
@Data
public class MdmItemCategoryRespDTO {
@@ -31,4 +33,10 @@
@Schema(description = "鐘舵��", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
private Integer status;
+ @Schema(description = "澶囨敞", example = "澶囨敞淇℃伅")
+ private String remark;
+
+ @Schema(description = "鍒涘缓鏃堕棿")
+ private LocalDateTime createTime;
+
}
\ No newline at end of file
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategorySaveReqDTO.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategorySaveReqDTO.java
new file mode 100644
index 0000000..7d7a533
--- /dev/null
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategorySaveReqDTO.java
@@ -0,0 +1,37 @@
+package cn.iocoder.yudao.module.mdm.api.category.dto;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Schema(description = "RPC 鏈嶅姟 - MDM 鐗╂枡鍒嗙被鏂板/淇敼 Request DTO")
+@Data
+public class MdmItemCategorySaveReqDTO {
+
+ @Schema(description = "鍒嗙被缂栧彿锛堟柊澧炴椂涓虹┖锛�", example = "1")
+ private Long id;
+
+ @Schema(description = "鐖跺垎绫荤紪鍙凤紙鏍硅妭鐐�=0锛�", example = "0")
+ private Long parentId;
+
+ @Schema(description = "鍒嗙被缂栫爜", requiredMode = Schema.RequiredMode.REQUIRED, example = "CAT001")
+ private String code;
+
+ @Schema(description = "鍒嗙被鍚嶇О", requiredMode = Schema.RequiredMode.REQUIRED, example = "浜旈噾閰嶄欢")
+ private String name;
+
+ @Schema(description = "鐗╂枡绫诲瀷锛�1鐗╂枡銆�2浜у搧銆�3鍗婃垚鍝併�丯ULL鍏ㄩ儴", example = "1")
+ private Integer itemType;
+
+ @Schema(description = "鐗╂枡/浜у搧鏍囪瘑(鍏煎MES)", example = "ITEM")
+ private String itemOrProduct;
+
+ @Schema(description = "鎺掑簭", example = "1")
+ private Integer sort;
+
+ @Schema(description = "鐘舵�侊細0鍚敤銆�1绂佺敤", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
+ private Integer status;
+
+ @Schema(description = "澶囨敞", example = "澶囨敞淇℃伅")
+ private String remark;
+
+}
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryService.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryService.java
index 9dd0b7c..b12c54d 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryService.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryService.java
@@ -90,6 +90,13 @@
List<MdmItemCategoryDO> getItemCategoryList(Collection<Long> ids);
/**
+ * 鑾峰緱鍏ㄩ儴鍒嗙被鍒楄〃锛堝惈绂佺敤锛�
+ *
+ * @return 鍒嗙被鍒楄〃
+ */
+ List<MdmItemCategoryDO> getItemCategoryAllList();
+
+ /**
* 鑾峰緱鐗╂枡鍒嗙被 Map
*
* @param ids 缂栧彿鏁扮粍
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryServiceImpl.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryServiceImpl.java
index 9f4854e..9875923 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryServiceImpl.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryServiceImpl.java
@@ -133,6 +133,11 @@
}
@Override
+ public List<MdmItemCategoryDO> getItemCategoryAllList() {
+ return itemCategoryMapper.selectList(new MdmItemCategoryDO());
+ }
+
+ @Override
public List<MdmItemCategoryDO> getItemCategoryChildrenList(Long id) {
List<MdmItemCategoryDO> result = new ArrayList<>();
// 娣诲姞鑷繁
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java
index fee17b9..0ab3f9d 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java
@@ -4,16 +4,16 @@
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mdm.api.category.MdmItemCategoryApi;
import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategoryRespDTO;
+import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategorySaveReqDTO;
import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeImportExcelVO;
import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeImportRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeListReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemTypeDO;
-import cn.iocoder.yudao.module.mes.dal.mysql.md.item.MesMdItemTypeMapper;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@@ -29,8 +29,8 @@
/**
* MES 鐗╂枡浜у搧鍒嗙被 Service 瀹炵幇绫�
*
- * 鍏煎灞傚疄鐜帮細鏁版嵁瀛樺偍鍦� mes_md_item_type 琛紝浣嗕紭鍏堜粠 MDM 鍒嗙被 API 鑾峰彇
- * 瀹為檯鍒嗙被鏁版嵁宸茶縼绉诲埌 mdm_item_category 琛�
+ * 鐗╂枡鍒嗙被宸茬粺涓�鐢� MDM 绠$悊锛屾暟鎹瓨鍌ㄥ湪 mdm_item_category 琛ㄣ��
+ * 鏈湇鍔′繚鐣� MES 鐨勫垎绫绘帴鍙o紝搴曞眰鍏ㄩ儴閫氳繃 {@link MdmItemCategoryApi} 璇诲啓 MDM 鍒嗙被銆�
*
* @author 瓒呯骇绠$悊鍛�
*/
@@ -38,73 +38,82 @@
@Validated
public class MesMdItemTypeServiceImpl implements MesMdItemTypeService {
- @Resource
- private MdmItemCategoryApi mdmItemCategoryApi;
+ /** MDM 鐗╂枡绫诲瀷锛氱墿鏂� */
+ private static final Integer MDM_ITEM_TYPE_MATERIAL = 1;
+ /** MDM 鐗╂枡绫诲瀷锛氫骇鍝� */
+ private static final Integer MDM_ITEM_TYPE_PRODUCT = 2;
+ /** MES 鐗╂枡/浜у搧鏍囪瘑锛氫骇鍝� */
+ private static final String ITEM_OR_PRODUCT_PRODUCT = "PRODUCT";
@Resource
- private MesMdItemTypeMapper itemTypeMapper;
+ private MdmItemCategoryApi mdmItemCategoryApi;
@Resource
@Lazy
private MesMdItemService itemService;
@Override
+ @Transactional(rollbackFor = Exception.class)
public Long createItemType(MesMdItemTypeSaveReqVO createReqVO) {
- // 鏍¢獙鏁版嵁
- validateItemTypeSaveData(createReqVO);
-
- // 鎻掑叆鍒版湰鍦拌〃锛堜繚鎸佸吋瀹癸級
- MesMdItemTypeDO itemType = BeanUtils.toBean(createReqVO, MesMdItemTypeDO.class);
- itemTypeMapper.insert(itemType);
- return itemType.getId();
+ // 鏍¢獙鐖跺垎绫�
+ validateParentItemType(createReqVO.getId(), createReqVO.getParentId());
+ // 鍐欏叆 MDM 鍒嗙被琛�
+ CommonResult<Long> result = mdmItemCategoryApi.createItemCategory(buildSaveDTO(createReqVO));
+ return result.getData();
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public void updateItemType(MesMdItemTypeSaveReqVO updateReqVO) {
// 鏍¢獙瀛樺湪
validateItemTypeExists(updateReqVO.getId());
- // 鏍¢獙鏁版嵁
- validateItemTypeSaveData(updateReqVO);
-
- // 鏇存柊鏈湴琛�
- MesMdItemTypeDO updateObj = BeanUtils.toBean(updateReqVO, MesMdItemTypeDO.class);
- itemTypeMapper.updateById(updateObj);
+ // 鏍¢獙鐖跺垎绫�
+ validateParentItemType(updateReqVO.getId(), updateReqVO.getParentId());
+ // 鏇存柊 MDM 鍒嗙被琛�
+ MdmItemCategorySaveReqDTO updateDTO = buildSaveDTO(updateReqVO);
+ updateDTO.setId(updateReqVO.getId());
+ mdmItemCategoryApi.updateItemCategory(updateDTO);
}
- private void validateItemTypeSaveData(MesMdItemTypeSaveReqVO reqVO) {
- // 鏍¢獙鐖跺垎绫荤紪鍙风殑鏈夋晥鎬�
- validateParentItemType(reqVO.getId(), reqVO.getParentId());
- // 鏍¢獙鍒嗙被鍚嶇О鐨勫敮涓�鎬�
- validateItemTypeNameUnique(reqVO.getId(), reqVO.getParentId(), reqVO.getName());
- // 鏍¢獙鍒嗙被缂栫爜鐨勫敮涓�鎬�
- validateItemTypeCodeUnique(reqVO.getId(), reqVO.getParentId(), reqVO.getCode());
+ private MdmItemCategorySaveReqDTO buildSaveDTO(MesMdItemTypeSaveReqVO reqVO) {
+ MdmItemCategorySaveReqDTO dto = new MdmItemCategorySaveReqDTO();
+ dto.setParentId(ObjUtil.defaultIfNull(reqVO.getParentId(), MesMdItemTypeDO.PARENT_ID_ROOT));
+ dto.setCode(reqVO.getCode());
+ dto.setName(reqVO.getName());
+ dto.setItemOrProduct(reqVO.getItemOrProduct());
+ dto.setItemType(convertMdmItemType(reqVO.getItemOrProduct()));
+ dto.setSort(ObjUtil.defaultIfNull(reqVO.getSort(), 0));
+ dto.setStatus(ObjUtil.defaultIfNull(reqVO.getStatus(), CommonStatusEnum.ENABLE.getStatus()));
+ dto.setRemark(reqVO.getRemark());
+ return dto;
+ }
+
+ /**
+ * MES 鐗╂枡/浜у搧鏍囪瘑 -> MDM 鐗╂枡绫诲瀷
+ */
+ private Integer convertMdmItemType(String itemOrProduct) {
+ if (StrUtil.isBlank(itemOrProduct)) {
+ return null;
+ }
+ return ITEM_OR_PRODUCT_PRODUCT.equalsIgnoreCase(itemOrProduct)
+ ? MDM_ITEM_TYPE_PRODUCT : MDM_ITEM_TYPE_MATERIAL;
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public void deleteItemType(Long id) {
// 1.1 鏍¢獙瀛樺湪
validateItemTypeExists(id);
- // 1.2 鏍¢獙鏄惁鏈夊瓙鍒嗙被
- if (itemTypeMapper.selectCountByParentId(id) > 0) {
- throw exception(MD_ITEM_TYPE_EXITS_CHILDREN);
- }
- // 1.3 鏍¢獙鏄惁鏈夌墿鏂�
+ // 1.2 鏍¢獙鏄惁鏈夌墿鏂�
if (itemService.getItemCountByItemTypeId(id) > 0) {
throw exception(MD_ITEM_TYPE_EXITS_ITEM);
}
-
- // 2. 鍒犻櫎
- itemTypeMapper.deleteById(id);
+ // 2. 鍒犻櫎锛堝瓙鍒嗙被銆丮DM 鐗╂枡寮曠敤鐢� MDM 渚ф牎楠岋級
+ mdmItemCategoryApi.deleteItemCategory(id);
}
private void validateItemTypeExists(Long id) {
- // 浼樺厛浠� MDM 鑾峰彇
- CommonResult<MdmItemCategoryRespDTO> result = mdmItemCategoryApi.getItemCategory(id);
- if (result.isSuccess() && result.getData() != null) {
- return;
- }
- // 鍥為��鍒版湰鍦拌〃
- if (itemTypeMapper.selectById(id) == null) {
+ if (getItemType(id) == null) {
throw exception(MD_ITEM_TYPE_NOT_EXISTS);
}
}
@@ -117,14 +126,8 @@
if (Objects.equals(id, parentId)) {
throw exception(MD_ITEM_TYPE_PARENT_ERROR);
}
- // 2. 鐖跺垎绫讳笉瀛樺湪 - 浼樺厛浠� MDM 鑾峰彇
- CommonResult<MdmItemCategoryRespDTO> result = mdmItemCategoryApi.getItemCategory(parentId);
- MesMdItemTypeDO parentItemType = null;
- if (result.isSuccess() && result.getData() != null) {
- parentItemType = convertToMesDO(result.getData());
- } else {
- parentItemType = itemTypeMapper.selectById(parentId);
- }
+ // 2. 鐖跺垎绫讳笉瀛樺湪
+ MesMdItemTypeDO parentItemType = getItemType(parentId);
if (parentItemType == null) {
throw exception(MD_ITEM_TYPE_PARENT_NOT_EXITS);
}
@@ -140,60 +143,35 @@
if (parentId == null || MesMdItemTypeDO.PARENT_ID_ROOT.equals(parentId)) {
break;
}
- // 缁х画鏌ユ壘鐖剁骇
- CommonResult<MdmItemCategoryRespDTO> parentResult = mdmItemCategoryApi.getItemCategory(parentId);
- if (parentResult.isSuccess() && parentResult.getData() != null) {
- parentItemType = convertToMesDO(parentResult.getData());
- } else {
- parentItemType = itemTypeMapper.selectById(parentId);
- }
+ parentItemType = getItemType(parentId);
if (parentItemType == null) {
break;
}
}
}
- private void validateItemTypeNameUnique(Long id, Long parentId, String name) {
- MesMdItemTypeDO itemType = itemTypeMapper.selectByParentIdAndName(parentId, name);
- if (itemType == null) {
- return;
- }
- if (ObjUtil.notEqual(itemType.getId(), id)) {
- throw exception(MD_ITEM_TYPE_NAME_DUPLICATE);
- }
- }
-
- private void validateItemTypeCodeUnique(Long id, Long parentId, String code) {
- MesMdItemTypeDO itemType = itemTypeMapper.selectByParentIdAndCode(parentId, code);
- if (itemType == null) {
- return;
- }
- if (ObjUtil.notEqual(itemType.getId(), id)) {
- throw exception(MD_ITEM_TYPE_CODE_DUPLICATE);
- }
- }
-
@Override
public MesMdItemTypeDO getItemType(Long id) {
- // 浼樺厛浠� MDM 鑾峰彇
CommonResult<MdmItemCategoryRespDTO> result = mdmItemCategoryApi.getItemCategory(id);
- if (result.isSuccess() && result.getData() != null) {
- return convertToMesDO(result.getData());
- }
- // 鍥為��鍒版湰鍦拌〃
- return itemTypeMapper.selectById(id);
+ return result.isSuccess() ? convertToMesDO(result.getData()) : null;
}
@Override
public MesMdItemTypeDO getItemTypeByCode(String code) {
- // 浠庢湰鍦拌〃鏌�
- return itemTypeMapper.selectByCode(code);
+ CommonResult<MdmItemCategoryRespDTO> result = mdmItemCategoryApi.getItemCategoryByCode(code);
+ return result.isSuccess() ? convertToMesDO(result.getData()) : null;
}
@Override
public List<MesMdItemTypeDO> getItemTypeList(MesMdItemTypeListReqVO listReqVO) {
- // 浠庢湰鍦拌〃鏌�
- return itemTypeMapper.selectList(listReqVO);
+ List<MesMdItemTypeDO> list = getAllItemTypeList();
+ return list.stream()
+ .filter(itemType -> StrUtil.isBlank(listReqVO.getName())
+ || StrUtil.contains(itemType.getName(), listReqVO.getName()))
+ .filter(itemType -> listReqVO.getStatus() == null
+ || Objects.equals(listReqVO.getStatus(), itemType.getStatus()))
+ .sorted(Comparator.comparing(itemType -> ObjUtil.defaultIfNull(itemType.getSort(), 0)))
+ .toList();
}
@Override
@@ -201,12 +179,25 @@
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
- return itemTypeMapper.selectByIds(ids);
+ CommonResult<List<MdmItemCategoryRespDTO>> result = mdmItemCategoryApi.getItemCategoryList(ids);
+ return convertToMesDOList(result.isSuccess() ? result.getData() : null);
+ }
+
+ private List<MesMdItemTypeDO> getAllItemTypeList() {
+ CommonResult<List<MdmItemCategoryRespDTO>> result = mdmItemCategoryApi.getItemCategoryAllList();
+ return convertToMesDOList(result.isSuccess() ? result.getData() : null);
+ }
+
+ private List<MesMdItemTypeDO> convertToMesDOList(List<MdmItemCategoryRespDTO> list) {
+ if (CollUtil.isEmpty(list)) {
+ return new ArrayList<>();
+ }
+ return new ArrayList<>(list.stream().map(this::convertToMesDO).toList());
}
@Override
public List<MesMdItemTypeDO> getItemTypeChildrenList(Long parentId) {
- List<MesMdItemTypeDO> allList = itemTypeMapper.selectList();
+ List<MesMdItemTypeDO> allList = getAllItemTypeList();
List<MesMdItemTypeDO> result = new ArrayList<>();
collectItemTypeChildren(result, parentId, allList);
return result;
@@ -225,6 +216,9 @@
* 杞崲 MDM 鍒嗙被 DTO 涓� MES DO
*/
private MesMdItemTypeDO convertToMesDO(MdmItemCategoryRespDTO dto) {
+ if (dto == null) {
+ return null;
+ }
MesMdItemTypeDO mesDO = new MesMdItemTypeDO();
mesDO.setId(dto.getId());
mesDO.setCode(dto.getCode());
@@ -233,6 +227,8 @@
mesDO.setItemOrProduct(dto.getItemOrProduct());
mesDO.setSort(dto.getSort());
mesDO.setStatus(dto.getStatus());
+ mesDO.setRemark(dto.getRemark());
+ mesDO.setCreateTime(dto.getCreateTime());
return mesDO;
}
@@ -249,6 +245,7 @@
MesMdItemTypeImportRespVO respVO = MesMdItemTypeImportRespVO.builder()
.createCodes(new ArrayList<>()).updateCodes(new ArrayList<>())
.failureCodes(new LinkedHashMap<>()).build();
+ List<MesMdItemTypeDO> allList = getAllItemTypeList();
AtomicInteger index = new AtomicInteger(1);
importItemTypeList.forEach(importItem -> {
int currentIndex = index.getAndIncrement();
@@ -268,7 +265,9 @@
// 2.1 瑙f瀽鐖跺垎绫伙紙涓虹┖鍒欓粯璁や负鏍瑰垎绫伙級
Long parentId = MesMdItemTypeDO.PARENT_ID_ROOT;
if (StrUtil.isNotBlank(importItem.getParentCode())) {
- MesMdItemTypeDO parentItemType = itemTypeMapper.selectByCode(importItem.getParentCode());
+ MesMdItemTypeDO parentItemType = allList.stream()
+ .filter(itemType -> Objects.equals(importItem.getParentCode(), itemType.getCode()))
+ .findFirst().orElse(null);
if (parentItemType == null) {
respVO.getFailureCodes().put(key, "鐖跺垎绫荤紪鐮乕" + importItem.getParentCode() + "]涓嶅瓨鍦�");
return;
@@ -276,27 +275,49 @@
parentId = parentItemType.getId();
}
// 2.2 鍒ゆ柇鏄惁瀛樺湪锛堝悓涓�鐖跺垎绫讳笅缂栫爜鍞竴锛�
- MesMdItemTypeDO existItemType = itemTypeMapper.selectByParentIdAndCode(parentId, importItem.getCode());
- if (existItemType == null) {
- // 2.2.1 鏂板
- MesMdItemTypeDO itemType = BeanUtils.toBean(importItem, MesMdItemTypeDO.class);
- itemType.setParentId(parentId);
- itemType.setSort(ObjUtil.defaultIfNull(importItem.getSort(), 0));
- itemType.setStatus(ObjUtil.defaultIfNull(importItem.getStatus(), CommonStatusEnum.ENABLE.getStatus()));
- itemTypeMapper.insert(itemType);
- respVO.getCreateCodes().add(importItem.getCode());
- } else if (updateSupport) {
- // 2.2.2 鏇存柊
- MesMdItemTypeDO updateObj = BeanUtils.toBean(importItem, MesMdItemTypeDO.class);
- updateObj.setId(existItemType.getId());
- updateObj.setParentId(parentId);
- itemTypeMapper.updateById(updateObj);
- respVO.getUpdateCodes().add(importItem.getCode());
- } else {
- respVO.getFailureCodes().put(key, "鍒嗙被缂栫爜宸插瓨鍦�");
+ Long finalParentId = parentId;
+ MesMdItemTypeDO existItemType = allList.stream()
+ .filter(itemType -> Objects.equals(finalParentId, itemType.getParentId())
+ && Objects.equals(importItem.getCode(), itemType.getCode()))
+ .findFirst().orElse(null);
+ try {
+ MdmItemCategorySaveReqDTO dto = new MdmItemCategorySaveReqDTO();
+ dto.setParentId(parentId);
+ dto.setCode(importItem.getCode());
+ dto.setName(importItem.getName());
+ dto.setItemOrProduct(importItem.getItemOrProduct());
+ dto.setItemType(convertMdmItemType(importItem.getItemOrProduct()));
+ dto.setSort(ObjUtil.defaultIfNull(importItem.getSort(), 0));
+ dto.setStatus(ObjUtil.defaultIfNull(importItem.getStatus(), CommonStatusEnum.ENABLE.getStatus()));
+ dto.setRemark(importItem.getRemark());
+ if (existItemType == null) {
+ // 2.2.1 鏂板
+ dto.setId(null);
+ Long id = mdmItemCategoryApi.createItemCategory(dto).getData();
+ MesMdItemTypeDO created = new MesMdItemTypeDO();
+ created.setId(id);
+ created.setParentId(parentId);
+ created.setCode(importItem.getCode());
+ created.setName(importItem.getName());
+ created.setItemOrProduct(importItem.getItemOrProduct());
+ created.setSort(dto.getSort());
+ created.setStatus(dto.getStatus());
+ created.setRemark(importItem.getRemark());
+ allList.add(created);
+ respVO.getCreateCodes().add(importItem.getCode());
+ } else if (updateSupport) {
+ // 2.2.2 鏇存柊
+ dto.setId(existItemType.getId());
+ mdmItemCategoryApi.updateItemCategory(dto);
+ respVO.getUpdateCodes().add(importItem.getCode());
+ } else {
+ respVO.getFailureCodes().put(key, "鍒嗙被缂栫爜宸插瓨鍦�");
+ }
+ } catch (ServiceException e) {
+ respVO.getFailureCodes().put(key, e.getMessage());
}
});
return respVO;
}
-}
\ No newline at end of file
+}
--
Gitblit v1.9.3