| | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi; |
| | | import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO; |
| | | import cn.iocoder.yudao.module.mdm.enums.MdmItemTypeEnum; |
| | | import cn.iocoder.yudao.module.wms.controller.admin.md.item.vo.item.WmsItemListReqVO; |
| | | import cn.iocoder.yudao.module.wms.controller.admin.md.item.vo.item.WmsItemPageReqVO; |
| | | import cn.iocoder.yudao.module.wms.controller.admin.md.item.vo.item.WmsItemSaveReqVO; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | |
| | | /** |
| | | * WMS 商品 Service 实现类 |
| | | * |
| | | * 改造说明:商品基础数据从 MDM 模块获取(itemType=1 物料类型) |
| | | * WMS 特有功能(SKU、库存等)仍保留 WMS 管理 |
| | | * |
| | | * @author 芋道源码 |
| | | */ |
| | | @Service |
| | |
| | | |
| | | @Resource |
| | | private WmsItemMapper itemMapper; |
| | | |
| | | @Resource |
| | | private MdmItemApi mdmItemApi; |
| | | |
| | | @Resource |
| | | @Lazy // 延迟加载,避免循环依赖 |
| | | private WmsItemCategoryService categoryService; |
| | |
| | | // 校验数据 |
| | | validateItemSaveData(createReqVO); |
| | | |
| | | // 插入商品 |
| | | // 插入商品(暂时保留原逻辑,后续可完全迁移到 MDM) |
| | | WmsItemDO item = BeanUtils.toBean(createReqVO, WmsItemDO.class); |
| | | itemMapper.insert(item); |
| | | // 插入 SKU |
| | |
| | | // 校验数据 |
| | | validateItemSaveData(updateReqVO); |
| | | |
| | | // 更新商品 |
| | | // 更新商品(暂时保留原逻辑) |
| | | WmsItemDO updateObj = BeanUtils.toBean(updateReqVO, WmsItemDO.class); |
| | | itemMapper.updateById(updateObj); |
| | | // 更新 SKU |
| | |
| | | } |
| | | |
| | | private void validateItemCodeUnique(Long id, String code) { |
| | | WmsItemDO item = itemMapper.selectByCode(code); |
| | | if (item == null) { |
| | | return; |
| | | } |
| | | if (id == null || ObjectUtil.notEqual(item.getId(), id)) { |
| | | // 检查 MDM 中编码唯一性 |
| | | MdmItemRespDTO item = mdmItemApi.getItemByCode(code).getCheckedData(); |
| | | if (item != null && ObjectUtil.notEqual(item.getId(), id)) { |
| | | throw exception(ITEM_CODE_DUPLICATE); |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public WmsItemDO validateItemExists(Long id) { |
| | | WmsItemDO item = itemMapper.selectById(id); |
| | | // 从 MDM 校验物料存在 |
| | | MdmItemRespDTO item = mdmItemApi.validateItemExists(id).getCheckedData(); |
| | | if (item == null) { |
| | | throw exception(ITEM_NOT_EXISTS); |
| | | // 如果 MDM 中不存在,检查本地表 |
| | | WmsItemDO localItem = itemMapper.selectById(id); |
| | | if (localItem == null) { |
| | | throw exception(ITEM_NOT_EXISTS); |
| | | } |
| | | return localItem; |
| | | } |
| | | return item; |
| | | return convertToWmsItem(item); |
| | | } |
| | | |
| | | @Override |
| | | public WmsItemDO getItem(Long id) { |
| | | return itemMapper.selectById(id); |
| | | // 从 MDM 获取物料数据(注意 WMS ID 偏移 30000) |
| | | MdmItemRespDTO item = mdmItemApi.getItem(id).getCheckedData(); |
| | | if (item == null) { |
| | | // 如果 MDM 中不存在,查询本地表 |
| | | return itemMapper.selectById(id); |
| | | } |
| | | return convertToWmsItem(item); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<WmsItemDO> getItemPage(WmsItemPageReqVO pageReqVO) { |
| | | return itemMapper.selectPage(pageReqVO, |
| | | categoryService.getSelfAndChildItemCategoryIdList(pageReqVO.getCategoryId())); |
| | | // 从 MDM 获取物料分页数据(itemType=1 物料类型) |
| | | cn.iocoder.yudao.framework.common.pojo.PageResult<MdmItemRespDTO> mdmPageResult = |
| | | mdmItemApi.getItemPage(MdmItemTypeEnum.MATERIAL.getType(), null, |
| | | pageReqVO.getPageNo(), pageReqVO.getPageSize()).getCheckedData(); |
| | | |
| | | // 转换为 WMS 商品 DO |
| | | List<WmsItemDO> list = new ArrayList<>(); |
| | | for (MdmItemRespDTO item : mdmPageResult.getList()) { |
| | | list.add(convertToWmsItem(item)); |
| | | } |
| | | return new PageResult<>(list, mdmPageResult.getTotal()); |
| | | } |
| | | |
| | | @Override |
| | | public List<WmsItemDO> getItemList(WmsItemListReqVO listReqVO) { |
| | | return itemMapper.selectList(listReqVO, |
| | | categoryService.getSelfAndChildItemCategoryIdList(listReqVO.getCategoryId())); |
| | | // 从 MDM 获取物料列表(itemType=1 物料类型) |
| | | List<MdmItemRespDTO> items = mdmItemApi.getItemListByStatus(null).getCheckedData(); |
| | | |
| | | List<WmsItemDO> result = new ArrayList<>(); |
| | | for (MdmItemRespDTO item : items) { |
| | | // 只返回物料类型 |
| | | if (MdmItemTypeEnum.MATERIAL.getType().equals(item.getItemType())) { |
| | | result.add(convertToWmsItem(item)); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (CollUtil.isEmpty(ids)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return itemMapper.selectByIds(ids); |
| | | // 从 MDM 获取物料列表 |
| | | List<MdmItemRespDTO> items = mdmItemApi.getItemList(ids).getCheckedData(); |
| | | List<WmsItemDO> result = new ArrayList<>(); |
| | | for (MdmItemRespDTO item : items) { |
| | | result.add(convertToWmsItem(item)); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 将 MDM 物料转换为 WMS 商品 DO |
| | | */ |
| | | private WmsItemDO convertToWmsItem(MdmItemRespDTO item) { |
| | | WmsItemDO wmsItem = new WmsItemDO(); |
| | | wmsItem.setId(item.getId()); |
| | | wmsItem.setCode(item.getCode()); |
| | | wmsItem.setName(item.getName()); |
| | | // MDM categoryId 映射到 WMS categoryId(注意 ID 偏移) |
| | | wmsItem.setCategoryId(item.getCategoryId() != null ? item.getCategoryId() - 20000 : null); |
| | | wmsItem.setBrandId(item.getBrandId()); |
| | | // 单位名称需要从 MDM 单位表获取,这里暂时留空 |
| | | wmsItem.setRemark(item.getRemark()); |
| | | return wmsItem; |
| | | } |
| | | |
| | | @Override |
| | | public long getItemCountByCategoryId(Long categoryId) { |
| | | return itemMapper.selectCountByCategoryId(categoryId); |
| | | // 从 MDM 获取分类物料数量(注意 ID 偏移) |
| | | return mdmItemApi.getItemCountByCategoryId(categoryId + 20000).getCheckedData(); |
| | | } |
| | | |
| | | @Override |
| | | public long getItemCountByBrandId(Long brandId) { |
| | | // 从 MDM 获取品牌物料数量 |
| | | // 注意:MDM 目前没有按品牌统计的 API,暂时返回本地数据 |
| | | return itemMapper.selectCountByBrandId(brandId); |
| | | } |
| | | |
| | | } |
| | | } |