eight
2024-09-11 02856700ce4cc57cf9447134a9f0c6860d85b802
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
package cn.lihu.jh.module.ecg.service.devrent;
 
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
import cn.lihu.jh.module.ecg.controller.admin.devrent.vo.*;
import cn.lihu.jh.module.ecg.dal.dataobject.devrent.DevRentDO;
import cn.lihu.jh.framework.common.pojo.PageResult;
import cn.lihu.jh.framework.common.pojo.PageParam;
import cn.lihu.jh.framework.common.util.object.BeanUtils;
 
import cn.lihu.jh.module.ecg.dal.mysql.devrent.DevRentMapper;
 
import javax.annotation.Resource;
 
import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
 
/**
 * 装机拆机 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class DevRentServiceImpl implements DevRentService {
 
    @Resource
    private DevRentMapper devRentMapper;
 
    @Override
    public Long createDevRent(DevRentSaveReqVO createReqVO) {
        //
 
        // 插入
        DevRentDO devRent = BeanUtils.toBean(createReqVO, DevRentDO.class);
        devRentMapper.insert(devRent);
        // 返回
        return devRent.getId();
    }
 
    @Override
    public void updateDevRent(DevRentSaveReqVO updateReqVO) {
        // 校验存在
        validateDevRentExists(updateReqVO.getId());
        // 更新
        DevRentDO updateObj = BeanUtils.toBean(updateReqVO, DevRentDO.class);
        devRentMapper.updateById(updateObj);
    }
 
    @Override
    public void deleteDevRent(Long id) {
        // 校验存在
        validateDevRentExists(id);
        // 删除
        devRentMapper.deleteById(id);
    }
 
    private void validateDevRentExists(Long id) {
        if (devRentMapper.selectById(id) == null) {
            throw exception(DEV_RENT_NOT_EXISTS);
        }
    }
 
    @Override
    public DevRentDO getDevRent(Long id) {
        return devRentMapper.selectById(id);
    }
 
    @Override
    public PageResult<DevRentDO> getDevRentPage(DevRentPageReqVO pageReqVO) {
        return devRentMapper.selectPage(pageReqVO);
    }
 
    @Override
    public DevRentDO getLatestRent(String devId) {
        return devRentMapper.getLatestRent(devId);
    }
 
}