yxh
7 天以前 68ff33beff11310e830b0615b5a81f83fad0f683
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
package cn.lihu.jh.module.ecg.service.call;
 
import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueDO;
import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomDO;
import cn.lihu.jh.module.ecg.dal.mysql.room.RoomMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
 
import cn.lihu.jh.module.ecg.controller.admin.call.vo.*;
import cn.lihu.jh.module.ecg.dal.dataobject.call.CallDO;
import cn.lihu.jh.framework.common.pojo.PageResult;
import cn.lihu.jh.framework.common.util.object.BeanUtils;
 
import cn.lihu.jh.module.ecg.dal.mysql.call.CallMapper;
 
import javax.annotation.Resource;
 
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
 
import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
 
/**
 * 叫号 Service 实现类
 *
 * @author 马剑波
 */
@Service
@Validated
@lombok.extern.slf4j.Slf4j
public class CallServiceImpl implements CallService {
 
    @Resource
    private CallMapper callMapper;
 
    @Resource
    private RoomMapper roomMapper;
 
    @Override
    public Integer createCall(CallSaveReqVO createReqVO) {
        // 插入
        CallDO call = BeanUtils.toBean(createReqVO, CallDO.class);
        callMapper.insert(call);
        // 返回
        return call.getId();
    }
 
    @Override
    public void updateCall(CallSaveReqVO updateReqVO) {
        // 校验存在
        validateCallExists(updateReqVO.getId());
        // 更新
        CallDO updateObj = BeanUtils.toBean(updateReqVO, CallDO.class);
        callMapper.updateById(updateObj);
    }
 
    @Override
    public void deleteCall(Integer id) {
        // 校验存在
        validateCallExists(id);
        // 删除
        callMapper.deleteById(id);
    }
 
    private void validateCallExists(Integer id) {
        if (callMapper.selectById(id) == null) {
            throw exception(CALL_NOT_EXISTS);
        }
    }
 
    @Override
    public CallDO getCall(Integer id) {
        return callMapper.selectById(id);
    }
 
    @Override
    public CallDO getNextCall() {
        CallDO callDO = callMapper.getNextCall(); // 大屏
        return callDO;
    }
 
    @Override
    public CallDO getNextInstallCall(String reqIp) {
        List<RoomDO> roomDOList = roomMapper.queueByIp(reqIp);
        Optional<RoomDO> optionalQueueDO = roomDOList.stream().filter(item -> StringUtils.hasLength(item.getIp())).findFirst();
        if (!optionalQueueDO.isPresent()) {
            return  null;
        }
 
        Long roomId = optionalQueueDO.get().getRoomId();
        CallDO callDO = callMapper.getNextInstallCall( roomId ); // 诊间屏
        return callDO;
    }
 
    @Override
    public PageResult<CallDO> getCallPage(CallPageReqVO pageReqVO) {
        return callMapper.selectPage(pageReqVO);
    }
 
    /**
     * 重叫:再生成一条叫号记录,让大屏 / 诊间屏重新播报。
     *
     * <p>【本次修复】原实现:
     * <pre>
     *   CallDO callDO = callMapper.getLatestPatientCall(patId);
     *   if (null != callDO &amp;&amp; callDO.getCalled() == 0) return 0;   // ← 永远成立
     *   return createCall(createReqVO);
     * </pre>
     * 而**全项目没有任何地方把 {@code called} 置为 1**({@code getNextCall} /
     * {@code getNextInstallCall} 只查 {@code called = 0})⇒ 该守卫每次都命中 ⇒
     * <b>重叫从不写入新记录</b>,两块屏也就完全没有反应(现场反馈即此)。
     *
     * <p>现在只做"防连点":同一患者 **3 秒内**的重复重叫忽略,其余情况一律正常新建。
     */
    @Override
    public Integer callAgain(CallSaveReqVO createReqVO) {
        CallDO latest = callMapper.getLatestPatientCall(createReqVO.getPatId());
        if (null != latest && null != latest.getCreateTime()) {
            long seconds = Duration.between(latest.getCreateTime(), LocalDateTime.now()).getSeconds();
            if (seconds >= 0 && seconds < 3) {
                log.info("[callAgain] 3 秒内重复重叫,忽略. patId={} 上次={}", createReqVO.getPatId(), latest.getCreateTime());
                return 0;
            }
        }
        return createCall(createReqVO);
    }
}