package cn.iocoder.yudao.module.mes.service.pd.reel;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.module.mes.controller.admin.pd.reel.vo.ProductCtcReelPageReqVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.pd.reel.vo.ProductCtcReelSaveReqVO;
|
import cn.iocoder.yudao.module.mes.dal.dataobject.pd.ctc.ProductCtcDO;
|
import cn.iocoder.yudao.module.mes.dal.dataobject.pd.reel.ProductCtcReelDO;
|
import cn.iocoder.yudao.module.mes.dal.mysql.pd.reel.ProductCtcReelMapper;
|
import cn.iocoder.yudao.module.mes.service.pd.ctc.ProductCtcService;
|
import jakarta.annotation.Resource;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
import org.springframework.validation.annotation.Validated;
|
|
import java.util.List;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PD_CTC_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PD_CTC_REEL_NOT_EXISTS;
|
|
/**
|
* MES 换位导线盘具计算 Service 实现类
|
*
|
* @author 超级管理员
|
*/
|
@Service
|
@Validated
|
public class ProductCtcReelServiceImpl implements ProductCtcReelService {
|
|
@Resource
|
private ProductCtcReelMapper reelMapper;
|
|
@Resource
|
@Lazy
|
private ProductCtcService ctcService;
|
|
@Override
|
public Long createReel(ProductCtcReelSaveReqVO createReqVO) {
|
// 校验换位导线产品存在
|
validateCtcExists(createReqVO.getCtcId());
|
// 插入
|
ProductCtcReelDO reel = BeanUtils.toBean(createReqVO, ProductCtcReelDO.class);
|
reelMapper.insert(reel);
|
return reel.getId();
|
}
|
|
@Override
|
public void updateReel(ProductCtcReelSaveReqVO updateReqVO) {
|
// 校验存在
|
validateReelExists(updateReqVO.getId());
|
// 校验换位导线产品存在
|
validateCtcExists(updateReqVO.getCtcId());
|
// 更新
|
ProductCtcReelDO updateObj = BeanUtils.toBean(updateReqVO, ProductCtcReelDO.class);
|
reelMapper.updateById(updateObj);
|
}
|
|
@Override
|
public void deleteReel(Long id) {
|
// 校验存在
|
validateReelExists(id);
|
// 删除
|
reelMapper.deleteById(id);
|
}
|
|
@Override
|
public ProductCtcReelDO getReel(Long id) {
|
return reelMapper.selectById(id);
|
}
|
|
@Override
|
public PageResult<ProductCtcReelDO> getReelPage(ProductCtcReelPageReqVO pageReqVO) {
|
return reelMapper.selectPage(pageReqVO);
|
}
|
|
@Override
|
public List<ProductCtcReelDO> getReelListByCtcId(Long ctcId) {
|
return reelMapper.selectListByCtcId(ctcId);
|
}
|
|
@Override
|
public void deleteByCtcId(Long ctcId) {
|
reelMapper.deleteByCtcId(ctcId);
|
}
|
|
private void validateCtcExists(Long ctcId) {
|
ProductCtcDO ctc = ctcService.getCtc(ctcId);
|
if (ctc == null) {
|
throw exception(PD_CTC_NOT_EXISTS);
|
}
|
}
|
|
private ProductCtcReelDO validateReelExists(Long id) {
|
ProductCtcReelDO reel = reelMapper.selectById(id);
|
if (reel == null) {
|
throw exception(PD_CTC_REEL_NOT_EXISTS);
|
}
|
return reel;
|
}
|
|
}
|