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
package cn.iocoder.yudao.module.mdm.api.item;
 
import cn.hutool.core.util.ObjUtil;
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.item.dto.MdmItemModelRespDTO;
import cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemModelDO;
import cn.iocoder.yudao.module.mdm.service.item.MdmItemModelService;
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;
import static cn.iocoder.yudao.module.mdm.enums.ErrorCodeConstants.MDM_ITEM_MODEL_UNIT_MISMATCH;
 
/**
 * MDM 物料型号 API 实现类
 *
 * @author 超级管理员
 */
@RestController
@RequestMapping(MdmItemModelApi.PREFIX)
@Validated
public class MdmItemModelApiImpl implements MdmItemModelApi {
 
    @Resource
    private MdmItemModelService itemModelService;
 
    @Override
    public CommonResult<MdmItemModelRespDTO> getItemModel(Long id) {
        MdmItemModelDO itemModel = itemModelService.getItemModel(id);
        return success(BeanUtils.toBean(itemModel, MdmItemModelRespDTO.class));
    }
 
    @Override
    public CommonResult<List<MdmItemModelRespDTO>> getItemModelList(Collection<Long> ids) {
        List<MdmItemModelDO> list = itemModelService.getItemModelList(ids);
        return success(BeanUtils.toBean(list, MdmItemModelRespDTO.class));
    }
 
    @Override
    public CommonResult<List<MdmItemModelRespDTO>> getItemModelListByItemId(Long itemId) {
        List<MdmItemModelDO> list = itemModelService.getItemModelListByItemId(itemId);
        return success(BeanUtils.toBean(list, MdmItemModelRespDTO.class));
    }
 
    @Override
    public CommonResult<MdmItemModelRespDTO> validateItemModelExists(Long id) {
        MdmItemModelDO itemModel = itemModelService.validateItemModelExists(id);
        return success(BeanUtils.toBean(itemModel, MdmItemModelRespDTO.class));
    }
 
    @Override
    public CommonResult<MdmItemModelRespDTO> validateItemModelExistsAndEnable(Long id, Long itemId) {
        MdmItemModelDO itemModel = itemModelService.validateItemModelExistsAndEnable(id);
        if (ObjUtil.notEqual(itemModel.getItemId(), itemId)) {
            throw new ServiceException(MDM_ITEM_MODEL_UNIT_MISMATCH.getCode(),
                    String.format("所选型号[%s](ID=%d)不属于当前物料(ID=%d),请重新选择该物料的型号",
                            itemModel.getModel(), itemModel.getId(), itemId));
        }
        return success(BeanUtils.toBean(itemModel, MdmItemModelRespDTO.class));
    }
 
}