eight
2024-09-19 a940b56e9781e2b4e56dbe05a896dba33a6905c6
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
package cn.lihu.jh.module.ecg.service.call;
 
import org.springframework.stereotype.Service;
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 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 CallServiceImpl implements CallService {
 
    @Resource
    private CallMapper callMapper;
 
    @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 PageResult<CallDO> getCallPage(CallPageReqVO pageReqVO) {
        return callMapper.selectPage(pageReqVO);
    }
 
    @Override
    public Integer callAgain(CallSaveReqVO createReqVO) {
        CallDO callDO = callMapper.getLatestPatientCall(createReqVO.getPatId());
        if (null != callDO && callDO.getCalled() == 0)
            return 0;
 
        return createCall(createReqVO);
    }
}