xiaoyi
3 天以前 abf1c0a35d85d38239ff5d2ed746a4e4b797c9d1
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.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;
    }
 
}