package cn.iocoder.yudao.module.mes.service.pd.basedata;
|
|
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.basedata.vo.MesPdTieredPricePageReqVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.pd.basedata.vo.MesPdTieredPriceRespVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.pd.basedata.vo.MesPdTieredPriceSaveReqVO;
|
import cn.iocoder.yudao.module.mes.dal.dataobject.pd.basedata.MesPdTieredPriceDO;
|
import cn.iocoder.yudao.module.mes.dal.mysql.pd.basedata.MesPdTieredPriceMapper;
|
import jakarta.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
import org.springframework.validation.annotation.Validated;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PD_TIERED_PRICE_NOT_EXISTS;
|
|
/**
|
* MES 阶梯电价 Service 实现类
|
*
|
* @author 超级管理员
|
*/
|
@Service
|
@Validated
|
public class MesPdTieredPriceServiceImpl implements MesPdTieredPriceService {
|
|
@Resource
|
private MesPdTieredPriceMapper tieredPriceMapper;
|
|
@Override
|
public Long createTieredPrice(MesPdTieredPriceSaveReqVO createReqVO) {
|
MesPdTieredPriceDO entity = BeanUtils.toBean(createReqVO, MesPdTieredPriceDO.class);
|
tieredPriceMapper.insert(entity);
|
return entity.getId();
|
}
|
|
@Override
|
public void updateTieredPrice(MesPdTieredPriceSaveReqVO updateReqVO) {
|
validateTieredPriceExists(updateReqVO.getId());
|
MesPdTieredPriceDO entity = BeanUtils.toBean(updateReqVO, MesPdTieredPriceDO.class);
|
tieredPriceMapper.updateById(entity);
|
}
|
|
@Override
|
public void deleteTieredPrice(Long id) {
|
validateTieredPriceExists(id);
|
tieredPriceMapper.deleteById(id);
|
}
|
|
@Override
|
public MesPdTieredPriceRespVO getTieredPrice(Long id) {
|
MesPdTieredPriceDO entity = tieredPriceMapper.selectById(id);
|
return entity == null ? null : BeanUtils.toBean(entity, MesPdTieredPriceRespVO.class);
|
}
|
|
@Override
|
public PageResult<MesPdTieredPriceRespVO> getTieredPricePage(MesPdTieredPricePageReqVO pageReqVO) {
|
return BeanUtils.toBean(tieredPriceMapper.selectPage(pageReqVO), MesPdTieredPriceRespVO.class);
|
}
|
|
@Override
|
public MesPdTieredPriceDO validateTieredPriceExists(Long id) {
|
MesPdTieredPriceDO entity = tieredPriceMapper.selectById(id);
|
if (entity == null) {
|
throw exception(PD_TIERED_PRICE_NOT_EXISTS);
|
}
|
return entity;
|
}
|
|
}
|