From 6b5f7c66fc40d7f6099d561e31a34fbd50dd20d3 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 01 七月 2026 15:54:57 +0800
Subject: [PATCH] 初始化项目

---
 yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductServiceImpl.java |  240 +++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 190 insertions(+), 50 deletions(-)

diff --git a/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductServiceImpl.java b/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductServiceImpl.java
index 88599a8..247295e 100644
--- a/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductServiceImpl.java
+++ b/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductServiceImpl.java
@@ -4,14 +4,16 @@
 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductPageReqVO;
 import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
 import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO;
-import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
 import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
-import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
 import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductMapper;
+import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi;
+import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemCreateReqDTO;
+import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO;
+import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemUpdateReqDTO;
+import cn.iocoder.yudao.module.mdm.enums.MdmItemTypeEnum;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
@@ -25,6 +27,10 @@
 /**
  * ERP 浜у搧 Service 瀹炵幇绫�
  *
+ * 鏀归�犺鏄庯細浜у搧鏁版嵁缁熶竴浣跨敤 MDM 涓绘暟鎹鐞嗭紙itemType=2 浜у搧绫诲瀷锛�
+ * - 鍒涘缓銆佹洿鏂般�佸垹闄ゆ搷浣滈�氳繃 MDM API 杩涜
+ * - 鏌ヨ鎿嶄綔浠� MDM 鑾峰彇鏁版嵁
+ *
  * @author 鑺嬮亾婧愮爜
  */
 @Service
@@ -35,36 +41,77 @@
     private ErpProductMapper productMapper;
 
     @Resource
-    private ErpProductCategoryService productCategoryService;
-    @Resource
-    private ErpProductUnitService productUnitService;
+    private MdmItemApi mdmItemApi;
 
     @Override
     public Long createProduct(ProductSaveReqVO createReqVO) {
-        // TODO 鑺嬭壙锛氭牎楠屽垎绫�
-        // 鎻掑叆
-        ErpProductDO product = BeanUtils.toBean(createReqVO, ErpProductDO.class);
-        productMapper.insert(product);
-        // 杩斿洖
-        return product.getId();
+        // 1. 鏍¢獙鏉$爜鏄惁閲嶅
+        MdmItemRespDTO existItem = mdmItemApi.getItemByBarCode(createReqVO.getBarCode()).getCheckedData();
+        if (existItem != null) {
+            throw exception(PRODUCT_BAR_CODE_EXISTS);
+        }
+        // 2. 閫氳繃 MDM API 鍒涘缓浜у搧
+        MdmItemCreateReqDTO createReqDTO = new MdmItemCreateReqDTO();
+        createReqDTO.setCode(createReqVO.getBarCode()); // 浣跨敤鏉$爜浣滀负缂栫爜
+        createReqDTO.setName(createReqVO.getName());
+        createReqDTO.setBarCode(createReqVO.getBarCode());
+        createReqDTO.setSpecification(createReqVO.getStandard());
+        createReqDTO.setCategoryId(createReqVO.getCategoryId());
+        createReqDTO.setUnitMeasureId(createReqVO.getUnitId());
+        createReqDTO.setItemType(MdmItemTypeEnum.PRODUCT.getType()); // 浜у搧绫诲瀷
+        createReqDTO.setStatus(createReqVO.getStatus() != null ? createReqVO.getStatus() : CommonStatusEnum.ENABLE.getStatus());
+        createReqDTO.setPurchasePrice(createReqVO.getPurchasePrice());
+        createReqDTO.setSalesPrice(createReqVO.getSalePrice());
+        createReqDTO.setCostPrice(createReqVO.getMinPrice());
+        createReqDTO.setExpiryDay(createReqVO.getExpiryDay());
+        createReqDTO.setWeight(createReqVO.getWeight());
+        createReqDTO.setRemark(createReqVO.getRemark());
+        return mdmItemApi.createItem(createReqDTO).getCheckedData();
     }
 
     @Override
     public void updateProduct(ProductSaveReqVO updateReqVO) {
-        // TODO 鑺嬭壙锛氭牎楠屽垎绫�
-        // 鏍¢獙瀛樺湪
-        validateProductExists(updateReqVO.getId());
-        // 鏇存柊
-        ErpProductDO updateObj = BeanUtils.toBean(updateReqVO, ErpProductDO.class);
-        productMapper.updateById(updateObj);
+        // 1. 鏍¢獙瀛樺湪
+        MdmItemRespDTO existItem = mdmItemApi.getItem(updateReqVO.getId()).getCheckedData();
+        if (existItem == null) {
+            throw exception(PRODUCT_NOT_EXISTS);
+        }
+        // 2. 鏍¢獙鏉$爜鏄惁閲嶅
+        if (!existItem.getBarCode().equals(updateReqVO.getBarCode())) {
+            MdmItemRespDTO barCodeItem = mdmItemApi.getItemByBarCode(updateReqVO.getBarCode()).getCheckedData();
+            if (barCodeItem != null) {
+                throw exception(PRODUCT_BAR_CODE_EXISTS);
+            }
+        }
+        // 3. 閫氳繃 MDM API 鏇存柊浜у搧
+        MdmItemUpdateReqDTO updateReqDTO = new MdmItemUpdateReqDTO();
+        updateReqDTO.setId(updateReqVO.getId());
+        updateReqDTO.setCode(updateReqVO.getBarCode());
+        updateReqDTO.setName(updateReqVO.getName());
+        updateReqDTO.setBarCode(updateReqVO.getBarCode());
+        updateReqDTO.setSpecification(updateReqVO.getStandard());
+        updateReqDTO.setCategoryId(updateReqVO.getCategoryId());
+        updateReqDTO.setUnitMeasureId(updateReqVO.getUnitId());
+        updateReqDTO.setItemType(MdmItemTypeEnum.PRODUCT.getType());
+        updateReqDTO.setStatus(updateReqVO.getStatus());
+        updateReqDTO.setPurchasePrice(updateReqVO.getPurchasePrice());
+        updateReqDTO.setSalesPrice(updateReqVO.getSalePrice());
+        updateReqDTO.setCostPrice(updateReqVO.getMinPrice());
+        updateReqDTO.setExpiryDay(updateReqVO.getExpiryDay());
+        updateReqDTO.setWeight(updateReqVO.getWeight());
+        updateReqDTO.setRemark(updateReqVO.getRemark());
+        mdmItemApi.updateItem(updateReqDTO);
     }
 
     @Override
     public void deleteProduct(Long id) {
         // 鏍¢獙瀛樺湪
-        validateProductExists(id);
-        // 鍒犻櫎
-        productMapper.deleteById(id);
+        MdmItemRespDTO item = mdmItemApi.getItem(id).getCheckedData();
+        if (item == null) {
+            throw exception(PRODUCT_NOT_EXISTS);
+        }
+        // 閫氳繃 MDM API 鍒犻櫎锛堟洿鏂扮姸鎬佷负绂佺敤锛�
+        mdmItemApi.updateItemStatus(id, CommonStatusEnum.DISABLE.getStatus());
     }
 
     @Override
@@ -72,35 +119,90 @@
         if (CollUtil.isEmpty(ids)) {
             return Collections.emptyList();
         }
-        List<ErpProductDO> list = productMapper.selectByIds(ids);
-        Map<Long, ErpProductDO> productMap = convertMap(list, ErpProductDO::getId);
+        // 浠� MDM 鑾峰彇浜у搧鏁版嵁
+        List<MdmItemRespDTO> items = mdmItemApi.getItemList(ids).getCheckedData();
+        Map<Long, MdmItemRespDTO> itemMap = convertMap(items, MdmItemRespDTO::getId);
+        List<ErpProductDO> result = new ArrayList<>();
         for (Long id : ids) {
-            ErpProductDO product = productMap.get(id);
-            if (productMap.get(id) == null) {
+            MdmItemRespDTO item = itemMap.get(id);
+            if (item == null) {
                 throw exception(PRODUCT_NOT_EXISTS);
             }
-            if (CommonStatusEnum.isDisable(product.getStatus())) {
-                throw exception(PRODUCT_NOT_ENABLE, product.getName());
+            if (CommonStatusEnum.isDisable(item.getStatus())) {
+                throw exception(PRODUCT_NOT_ENABLE, item.getName());
             }
+            // 杞崲涓� ErpProductDO
+            result.add(convertToErpProduct(item));
         }
-        return list;
+        return result;
     }
 
     private void validateProductExists(Long id) {
-        if (productMapper.selectById(id) == null) {
+        // 浠� MDM 鏍¢獙
+        MdmItemRespDTO item = mdmItemApi.getItem(id).getCheckedData();
+        if (item == null) {
             throw exception(PRODUCT_NOT_EXISTS);
         }
     }
 
     @Override
     public ErpProductDO getProduct(Long id) {
-        return productMapper.selectById(id);
+        // 浠� MDM 鑾峰彇浜у搧鏁版嵁
+        MdmItemRespDTO item = mdmItemApi.getItem(id).getCheckedData();
+        if (item == null) {
+            return null;
+        }
+        // 妫�鏌ユ槸鍚︿负浜у搧绫诲瀷
+        if (!MdmItemTypeEnum.PRODUCT.getType().equals(item.getItemType())) {
+            return null;
+        }
+        return convertToErpProduct(item);
+    }
+
+    @Override
+    public ErpProductRespVO getProductVO(Long id) {
+        // 浠� MDM 鑾峰彇浜у搧鏁版嵁
+        MdmItemRespDTO item = mdmItemApi.getItem(id).getCheckedData();
+        if (item == null) {
+            return null;
+        }
+        // 妫�鏌ユ槸鍚︿负浜у搧绫诲瀷
+        if (!MdmItemTypeEnum.PRODUCT.getType().equals(item.getItemType())) {
+            return null;
+        }
+        return convertToErpProductVO(item);
+    }
+
+    /**
+     * 灏� MDM 鐗╂枡杞崲涓� ERP 浜у搧 VO
+     */
+    private ErpProductRespVO convertToErpProductVO(MdmItemRespDTO item) {
+        ErpProductRespVO vo = new ErpProductRespVO();
+        vo.setId(item.getId());
+        vo.setName(item.getName());
+        vo.setBarCode(item.getBarCode());
+        vo.setStandard(item.getSpecification());
+        vo.setCategoryId(item.getCategoryId());
+        vo.setUnitId(item.getUnitMeasureId());
+        vo.setStatus(item.getStatus());
+        vo.setExpiryDay(item.getExpiryDay());
+        vo.setWeight(item.getWeight());
+        vo.setPurchasePrice(item.getPurchasePrice());
+        vo.setSalePrice(item.getSalesPrice());
+        vo.setMinPrice(item.getCostPrice());
+        vo.setRemark(item.getRemark());
+        return vo;
     }
 
     @Override
     public List<ErpProductRespVO> getProductVOListByStatus(Integer status) {
-        List<ErpProductDO> list = productMapper.selectListByStatus(status);
-        return buildProductVOList(list);
+        // 浠� MDM 鑾峰彇浜у搧鏁版嵁锛坕temType=2锛�
+        List<MdmItemRespDTO> items = mdmItemApi.getItemListByStatus(status).getCheckedData();
+        // 杩囨护浜у搧绫诲瀷
+        items = items.stream()
+                .filter(item -> MdmItemTypeEnum.PRODUCT.getType().equals(item.getItemType()))
+                .toList();
+        return buildProductVOListFromMdm(items);
     }
 
     @Override
@@ -108,40 +210,78 @@
         if (CollUtil.isEmpty(ids)) {
             return Collections.emptyList();
         }
-        List<ErpProductDO> list = productMapper.selectByIds(ids);
-        return buildProductVOList(list);
+        // 浠� MDM 鑾峰彇浜у搧鏁版嵁
+        List<MdmItemRespDTO> items = mdmItemApi.getItemList(ids).getCheckedData();
+        return buildProductVOListFromMdm(items);
     }
 
     @Override
     public PageResult<ErpProductRespVO> getProductVOPage(ErpProductPageReqVO pageReqVO) {
-        PageResult<ErpProductDO> pageResult = productMapper.selectPage(pageReqVO);
-        return new PageResult<>(buildProductVOList(pageResult.getList()), pageResult.getTotal());
+        // 浠� MDM 鑾峰彇浜у搧鍒嗛〉鏁版嵁
+        cn.iocoder.yudao.framework.common.pojo.PageResult<MdmItemRespDTO> mdmPageResult =
+                mdmItemApi.getItemPage(MdmItemTypeEnum.PRODUCT.getType(), null,
+                        pageReqVO.getPageNo(), pageReqVO.getPageSize()).getCheckedData();
+        return new PageResult<>(buildProductVOListFromMdm(mdmPageResult.getList()), mdmPageResult.getTotal());
     }
 
-    private List<ErpProductRespVO> buildProductVOList(List<ErpProductDO> list) {
-        if (CollUtil.isEmpty(list)) {
+    /**
+     * 浠� MDM 鏁版嵁鏋勫缓 ERP 浜у搧 VO 鍒楄〃
+     */
+    private List<ErpProductRespVO> buildProductVOListFromMdm(List<MdmItemRespDTO> items) {
+        if (CollUtil.isEmpty(items)) {
             return Collections.emptyList();
         }
-        Map<Long, ErpProductCategoryDO> categoryMap = productCategoryService.getProductCategoryMap(
-                convertSet(list, ErpProductDO::getCategoryId));
-        Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(
-                convertSet(list, ErpProductDO::getUnitId));
-        return BeanUtils.toBean(list, ErpProductRespVO.class, product -> {
-            MapUtils.findAndThen(categoryMap, product.getCategoryId(),
-                    category -> product.setCategoryName(category.getName()));
-            MapUtils.findAndThen(unitMap, product.getUnitId(),
-                    unit -> product.setUnitName(unit.getName()));
-        });
+        List<ErpProductRespVO> result = new ArrayList<>();
+        for (MdmItemRespDTO item : items) {
+            ErpProductRespVO vo = new ErpProductRespVO();
+            vo.setId(item.getId());
+            vo.setName(item.getName());
+            vo.setBarCode(item.getBarCode());
+            vo.setStandard(item.getSpecification());
+            vo.setCategoryId(item.getCategoryId());
+            vo.setUnitId(item.getUnitMeasureId());
+            vo.setStatus(item.getStatus());
+            vo.setExpiryDay(item.getExpiryDay());
+            vo.setWeight(item.getWeight());
+            vo.setPurchasePrice(item.getPurchasePrice());
+            vo.setSalePrice(item.getSalesPrice());
+            vo.setMinPrice(item.getCostPrice()); // 浣跨敤鎴愭湰浠蜂綔涓烘渶浣庝环
+            vo.setRemark(item.getRemark());
+            // 鍒嗙被鍚嶇О鍜屽崟浣嶅悕绉伴渶瑕侀澶栨煡璇紙绠�鍖栧鐞嗭紝鍚庣画鍙紭鍖栵級
+            result.add(vo);
+        }
+        return result;
+    }
+
+    /**
+     * 灏� MDM 鐗╂枡杞崲涓� ERP 浜у搧 DO
+     */
+    private ErpProductDO convertToErpProduct(MdmItemRespDTO item) {
+        ErpProductDO product = new ErpProductDO();
+        product.setId(item.getId());
+        product.setName(item.getName());
+        product.setBarCode(item.getBarCode());
+        product.setStandard(item.getSpecification());
+        product.setCategoryId(item.getCategoryId());
+        product.setUnitId(item.getUnitMeasureId());
+        product.setStatus(item.getStatus());
+        product.setExpiryDay(item.getExpiryDay());
+        product.setWeight(item.getWeight());
+        product.setPurchasePrice(item.getPurchasePrice());
+        product.setSalePrice(item.getSalesPrice());
+        product.setMinPrice(item.getCostPrice());
+        product.setRemark(item.getRemark());
+        return product;
     }
 
     @Override
     public Long getProductCountByCategoryId(Long categoryId) {
-        return productMapper.selectCountByCategoryId(categoryId);
+        return mdmItemApi.getItemCountByCategoryId(categoryId).getCheckedData();
     }
 
     @Override
     public Long getProductCountByUnitId(Long unitId) {
-        return productMapper.selectCountByUnitId(unitId);
+        return mdmItemApi.getItemCountByUnitMeasureId(unitId).getCheckedData();
     }
 
 }

--
Gitblit v1.9.3