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));
|
}
|
|
}
|