eight
2024-12-18 14f87cf04b519fd33ef6f76ea5e2926f30fab419
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package cn.lihu.jh.module.ecg.service.devmanage;
 
import cn.lihu.jh.module.ecg.dal.dataobject.devmanage.DeviceStatisticDO;
import cn.lihu.jh.module.infra.api.config.ConfigApi;
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.devmanage.vo.*;
import cn.lihu.jh.module.ecg.dal.dataobject.devmanage.DeviceDO;
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.devmanage.DeviceMapper;
 
import javax.annotation.Resource;
 
import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.lihu.jh.module.ecg.Constants.DEV_CODE_CHOICE;
import static cn.lihu.jh.module.ecg.Constants.ECG_SCREEN_PANE_PASSED_KEY;
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
 
/**
 * 设备 Service 实现类
 *
 * @author majianbo
 */
@Service
@Validated
public class DeviceServiceImpl implements DeviceService {
    @Resource
    private ConfigApi configApi;
 
    @Resource
    private DeviceMapper deviceMapper;
 
    @Override
    public Integer createDevice(DeviceSaveReqVO createReqVO) {
        // 读取 设备编号选择 系统配置
        Integer devCodeChoice = Integer.valueOf(configApi.getConfigValueByKey(DEV_CODE_CHOICE));
        if (0 == devCodeChoice)
            createReqVO.setDevId( createReqVO.getDevCodeIntrinsic() );
        else if (1 == devCodeChoice)
            createReqVO.setDevId( createReqVO.getDevCodeHosp() );
        else if (2 == devCodeChoice)
            createReqVO.setDevId( createReqVO.getDevCodeDept() );
        else
            createReqVO.setDevId( createReqVO.getDevCodeDept() );
 
        // 插入
        DeviceDO device = BeanUtils.toBean(createReqVO, DeviceDO.class);
        deviceMapper.insert(device);
        // 返回
        return device.getId();
    }
 
    @Override
    public void updateDevice(DeviceSaveReqVO updateReqVO) {
        // 校验存在
        validateDeviceExists(updateReqVO.getId());
 
        // 读取 设备编号选择 系统配置
        Integer devCodeChoice = Integer.valueOf(configApi.getConfigValueByKey(DEV_CODE_CHOICE));
        if (0 == devCodeChoice)
            updateReqVO.setDevId( updateReqVO.getDevCodeIntrinsic() );
        else if (1 == devCodeChoice)
            updateReqVO.setDevId( updateReqVO.getDevCodeHosp() );
        else if (2 == devCodeChoice)
            updateReqVO.setDevId( updateReqVO.getDevCodeDept() );
        else
            updateReqVO.setDevId( updateReqVO.getDevCodeDept() );
 
        // 更新
        DeviceDO updateObj = BeanUtils.toBean(updateReqVO, DeviceDO.class);
        deviceMapper.updateById(updateObj);
    }
 
    @Override
    public Integer updateDeviceState(DeviceSaveReqVO updateReqVO) {
        // 校验存在
        validateDeviceExists(updateReqVO.getId());
        // 更新
        DeviceDO updateObj = BeanUtils.toBean(updateReqVO, DeviceDO.class);
        return deviceMapper.updateDevState(updateObj.getDevId(), updateObj.getState(), updateObj.getStateDate(), updateObj.getComment());
    }
 
    @Override
    public void deleteDevice(Integer id) {
        // 校验存在
        validateDeviceExists(id);
        // 删除
        deviceMapper.deleteById(id);
    }
 
    private void validateDeviceExists(Integer id) {
        if (deviceMapper.selectById(id) == null) {
            throw exception(DEVICE_NOT_EXISTS);
        }
    }
 
    @Override
    public DeviceDO getDevice(Integer id) {
        return deviceMapper.selectById(id);
    }
 
    @Override
    public DeviceDO getDevice(String devId) {
        return deviceMapper.getDeviceByDevId(devId);
    }
 
    @Override
    public PageResult<DeviceDO> getDevicePage(DevicePageReqVO pageReqVO) {
        return deviceMapper.selectPage(pageReqVO);
    }
 
    @Override
    public List<DeviceStatisticDO> getDeviceStatistic(DevicePageReqVO pageReqVO) {
        return deviceMapper.getDevStatistic(pageReqVO);
    }
 
}