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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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.MesPdServicePackagePageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pd.basedata.vo.MesPdServicePackageRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pd.basedata.vo.MesPdServicePackageSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pd.basedata.MesPdServicePackageDO;
import cn.iocoder.yudao.module.mes.dal.mysql.pd.basedata.MesPdServicePackageMapper;
import cn.iocoder.yudao.module.mes.enums.md.autocode.MesMdAutoCodeRuleCodeEnum;
import cn.iocoder.yudao.module.mes.service.md.autocode.MesMdAutoCodeRecordService;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
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_SERVICE_PACKAGE_NOT_EXISTS;
 
/**
 * MES 服务套餐基础信息 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class MesPdServicePackageServiceImpl implements MesPdServicePackageService {
 
    @Resource
    private MesPdServicePackageMapper servicePackageMapper;
 
    @Resource
    @Lazy
    private MesMdAutoCodeRecordService autoCodeRecordService;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long createServicePackage(MesPdServicePackageSaveReqVO createReqVO) {
        MesPdServicePackageDO entity = BeanUtils.toBean(createReqVO, MesPdServicePackageDO.class);
        entity.setCode(autoCodeRecordService.generateAutoCode(MesMdAutoCodeRuleCodeEnum.PD_PACKAGE_CODE.getCode()));
        servicePackageMapper.insert(entity);
        return entity.getId();
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateServicePackage(MesPdServicePackageSaveReqVO updateReqVO) {
        MesPdServicePackageDO packageDO = validateServicePackageExists(updateReqVO.getId());
        MesPdServicePackageDO entity = BeanUtils.toBean(updateReqVO, MesPdServicePackageDO.class);
        entity.setCode(packageDO.getCode());
        servicePackageMapper.updateById(entity);
    }
 
    @Override
    public void deleteServicePackage(Long id) {
        validateServicePackageExists(id);
        servicePackageMapper.deleteById(id);
    }
 
    @Override
    public MesPdServicePackageRespVO getServicePackage(Long id) {
        MesPdServicePackageDO entity = servicePackageMapper.selectById(id);
        return entity == null ? null : BeanUtils.toBean(entity, MesPdServicePackageRespVO.class);
    }
 
    @Override
    public PageResult<MesPdServicePackageRespVO> getServicePackagePage(MesPdServicePackagePageReqVO pageReqVO) {
        return BeanUtils.toBean(servicePackageMapper.selectPage(pageReqVO), MesPdServicePackageRespVO.class);
    }
 
    @Override
    public List<MesPdServicePackageDO> getServicePackageList() {
        return servicePackageMapper.selectList();
    }
 
    @Override
    public MesPdServicePackageDO validateServicePackageExists(Long id) {
        MesPdServicePackageDO entity = servicePackageMapper.selectById(id);
        if (entity == null) {
            throw exception(PD_SERVICE_PACKAGE_NOT_EXISTS);
        }
        return entity;
    }
 
}