2026-06-29 940c8481d2fdcf51341db4ccd6fd6fcc2d43debb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package cn.iocoder.yudao.module.mdm.api.item;
 
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.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.controller.admin.item.vo.MdmItemPageReqVO;
import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemSaveReqVO;
import cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemDO;
import cn.iocoder.yudao.module.mdm.dal.mysql.item.MdmItemMapper;
import cn.iocoder.yudao.module.mdm.service.item.MdmItemService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Collection;
import java.util.List;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
/**
 * MDM 物料 API 实现类
 *
 * @author 芋道源码
 */
@RestController
@RequestMapping(MdmItemApi.PREFIX)
@Validated
public class MdmItemApiImpl implements MdmItemApi {
 
    @Resource
    private MdmItemService itemService;
 
    @Resource
    private MdmItemMapper itemMapper;
 
    @Override
    public CommonResult<Long> createItem(MdmItemCreateReqDTO createReqDTO) {
        MdmItemSaveReqVO saveReqVO = BeanUtils.toBean(createReqDTO, MdmItemSaveReqVO.class);
        // 设置默认状态
        if (saveReqVO.getStatus() == null) {
            saveReqVO.setStatus(0);
        }
        return success(itemService.createItem(saveReqVO));
    }
 
    @Override
    public CommonResult<Boolean> updateItem(MdmItemUpdateReqDTO updateReqDTO) {
        MdmItemSaveReqVO saveReqVO = BeanUtils.toBean(updateReqDTO, MdmItemSaveReqVO.class);
        itemService.updateItem(saveReqVO);
        return success(true);
    }
 
    @Override
    public CommonResult<MdmItemRespDTO> getItem(Long id) {
        MdmItemDO item = itemService.getItem(id);
        return success(BeanUtils.toBean(item, MdmItemRespDTO.class));
    }
 
    @Override
    public CommonResult<List<MdmItemRespDTO>> getItemList(Collection<Long> ids) {
        List<MdmItemDO> list = itemService.getItemList(ids);
        return success(BeanUtils.toBean(list, MdmItemRespDTO.class));
    }
 
    @Override
    public CommonResult<PageResult<MdmItemRespDTO>> getItemPage(Integer itemType, Integer status, Integer pageNo, Integer pageSize) {
        MdmItemPageReqVO pageReqVO = new MdmItemPageReqVO();
        pageReqVO.setItemType(itemType);
        pageReqVO.setStatus(status);
        pageReqVO.setPageNo(pageNo);
        pageReqVO.setPageSize(pageSize);
        PageResult<MdmItemDO> pageResult = itemService.getItemPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, MdmItemRespDTO.class));
    }
 
    @Override
    public CommonResult<List<MdmItemRespDTO>> getItemListByStatus(Integer status) {
        MdmItemPageReqVO pageReqVO = new MdmItemPageReqVO();
        pageReqVO.setStatus(status);
        pageReqVO.setPageNo(1);
        pageReqVO.setPageSize(Integer.MAX_VALUE);
        PageResult<MdmItemDO> pageResult = itemService.getItemPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult.getList(), MdmItemRespDTO.class));
    }
 
    @Override
    public CommonResult<MdmItemRespDTO> validateItemExists(Long id) {
        MdmItemDO item = itemService.validateItemExists(id);
        return success(BeanUtils.toBean(item, MdmItemRespDTO.class));
    }
 
    @Override
    public CommonResult<MdmItemRespDTO> validateItemExistsAndEnable(Long id) {
        MdmItemDO item = itemService.validateItemExistsAndEnable(id);
        return success(BeanUtils.toBean(item, MdmItemRespDTO.class));
    }
 
    @Override
    public CommonResult<MdmItemRespDTO> getItemByCode(String code) {
        MdmItemDO item = itemService.getItemByCode(code);
        return success(BeanUtils.toBean(item, MdmItemRespDTO.class));
    }
 
    @Override
    public CommonResult<MdmItemRespDTO> getItemByBarCode(String barCode) {
        MdmItemDO item = itemMapper.selectByBarCode(barCode);
        return success(BeanUtils.toBean(item, MdmItemRespDTO.class));
    }
 
    @Override
    public CommonResult<Long> getItemCountByCategoryId(Long categoryId) {
        return success(itemService.getItemCountByCategoryId(categoryId));
    }
 
    @Override
    public CommonResult<Long> getItemCountByUnitMeasureId(Long unitMeasureId) {
        return success(itemService.getItemCountByUnitMeasureId(unitMeasureId));
    }
 
    @Override
    public CommonResult<Boolean> updateItemStatus(Long id, Integer status) {
        itemService.updateItemStatus(id, status);
        return success(true);
    }
 
}