eight
2025-03-31 030979c08b23b917a942eed09f0d6a9134c45ee1
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package cn.lihu.jh.module.ecg.service.room;
 
import java.util.*;
import javax.annotation.Resource;
 
import cn.lihu.jh.framework.common.pojo.PageResult;
import cn.lihu.jh.module.ecg.controller.admin.room.vo.MonitorInfoVO;
import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomDO;
import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomProfile;
import cn.lihu.jh.module.ecg.enums.RoomCallingScreenEnum;
import cn.lihu.jh.module.ecg.service.queue.QueueService;
import cn.lihu.jh.module.system.api.oauth2.OAuth2TokenApi;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
 
import cn.lihu.jh.module.ecg.controller.admin.room.vo.RoomPageReqVO;
import cn.lihu.jh.module.ecg.controller.admin.room.vo.RoomSaveReqVO;
import cn.lihu.jh.module.ecg.dal.mysql.room.RoomMapper;
import cn.lihu.jh.module.ecg.enums.BedStatusEnum;
import cn.lihu.jh.framework.common.util.object.BeanUtils;
 
import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.ROOM_NOT_EXISTS;
 
/**
 * 诊室和诊疗床 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class RoomServiceImpl implements RoomService {
 
    @Resource
    private RoomMapper roomMapper;
 
    @Resource
    private OAuth2TokenApi oAuth2TokenApi;
 
    @Resource
    QueueService queueService;
 
    @Override
    public Integer createRoom(RoomSaveReqVO createReqVO) {
        // 插入
        RoomDO room = BeanUtils.toBean(createReqVO, RoomDO.class);
        roomMapper.insert(room);
        // 返回
        return room.getId();
    }
 
    @Override
    public void updateRoom(RoomSaveReqVO updateReqVO) {
        // 校验存在
        validateRoomExists(updateReqVO.getId());
        // 更新
        RoomDO updateObj = BeanUtils.toBean(updateReqVO, RoomDO.class);
        roomMapper.updateById(updateObj);
    }
 
    @Override
    public void deleteRoom(Integer id) {
        // 校验存在
        validateRoomExists(id);
        // 删除
        roomMapper.deleteById(id);
    }
 
    private void validateRoomExists(Integer id) {
        if (roomMapper.selectById(id) == null) {
            throw exception(ROOM_NOT_EXISTS);
        }
    }
 
    @Override
    public RoomDO getRoom(Integer id) {
        return roomMapper.selectById(id);
    }
 
    @Override
    public RoomProfile getRoomByIP(String ip) {
        List<RoomDO> roomDOList = roomMapper.queueByIp(ip);
 
        RoomProfile roomProfile = new RoomProfile();
        roomProfile.setBedNum( 0 );
        roomProfile.setCallingScreenType( RoomCallingScreenEnum.NONE.getCallingScreenType() );
 
        for (RoomDO roomDO : roomDOList) {
            roomProfile.setRoomId(roomDO.getRoomId());
            roomProfile.setRoomName(roomDO.getRoomName());
            roomProfile.setBedNum( roomProfile.getBedNum() + 1);
 
            // 0 检查 1 领用 2 装机
 
            // 计算 诊间屏类型
            if (roomProfile.getCallingScreenType() == RoomCallingScreenEnum.NONE.getCallingScreenType()) {
                if ( roomDO.getOpType() == 0 ) {
                    roomProfile.setCallingScreenType(RoomCallingScreenEnum.CHECK_ONLY.getCallingScreenType());
                } else if ( roomDO.getOpType() == 1 ) {
                    roomProfile.setCallingScreenType( RoomCallingScreenEnum.RECEIVE_ONLY.getCallingScreenType());
                } else if ( roomDO.getOpType() == 2 ) {
                    roomProfile.setCallingScreenType( RoomCallingScreenEnum.INSTALL_ONLY.getCallingScreenType());
                }
            } else if (roomProfile.getCallingScreenType() == RoomCallingScreenEnum.CHECK_ONLY.getCallingScreenType()) {
                if ( roomDO.getOpType() == 0 || roomDO.getOpType() == 1 ) {
                    // do nothing
                } else if ( roomDO.getOpType() == 2 ) {
                    roomProfile.setCallingScreenType( RoomCallingScreenEnum.CHECK_INSTALL.getCallingScreenType());
                }
            } else if (roomProfile.getCallingScreenType() == RoomCallingScreenEnum.RECEIVE_ONLY.getCallingScreenType()) {
                if ( roomDO.getOpType() == 0 || roomDO.getOpType() == 1 ) {
                    // do nothing
                } else if ( roomDO.getOpType() == 2 ) {
                    roomProfile.setCallingScreenType( RoomCallingScreenEnum.RECEIVE_INSTALL.getCallingScreenType());
                }
            } else if (roomProfile.getCallingScreenType() == RoomCallingScreenEnum.INSTALL_ONLY.getCallingScreenType()) {
                if ( roomDO.getOpType() == 0 ) {
                    roomProfile.setCallingScreenType( RoomCallingScreenEnum.CHECK_INSTALL.getCallingScreenType());
                } else if ( roomDO.getOpType() == 1 ) {
                    roomProfile.setCallingScreenType( RoomCallingScreenEnum.RECEIVE_INSTALL.getCallingScreenType());
                } else if ( roomDO.getOpType() == 2 ) {
                    // do nothing
                }
            } else if (roomProfile.getCallingScreenType() == RoomCallingScreenEnum.RECEIVE_INSTALL.getCallingScreenType()) {
                // do nothing
            } else if (roomProfile.getCallingScreenType() == RoomCallingScreenEnum.CHECK_INSTALL.getCallingScreenType()) {
                // do nothing
            }
        }
 
        return roomProfile;
    }
 
    @Override
    public PageResult<RoomDO> getRoomPage(RoomPageReqVO pageReqVO) {
        return roomMapper.selectPage(pageReqVO);
    }
 
    @Override
    public List<RoomDO> simpleRoomList() {
        List<BedStatusEnum> bedStatusEnumList = new ArrayList<BedStatusEnum>();
        bedStatusEnumList.add(BedStatusEnum.OPENING);
        bedStatusEnumList.add(BedStatusEnum.DOCTOR_ON);
        bedStatusEnumList.add(BedStatusEnum.PAUSE);
        return  roomMapper.simpleRoomList(bedStatusEnumList);
    }
 
    @Override
    public void resetRoom(Boolean needCloseBed) {
        queueService.startResetRoom(needCloseBed);
    }
 
    @Override
    public MonitorInfoVO getMonitorInfo() {
        return queueService.getMonitorInfo();
    }
}