jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
package com.ld.igds.io.notify.impl;
 
import java.util.List;
import com.ld.igds.check.service.CoreCheckStandardService;
import com.ld.igds.constant.BizType;
import com.ld.igds.inout.InoutConstant;
import com.ld.igds.check.dto.CheckItemData;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.notify.NotifyCheckMacService;
import com.ld.igds.io.response.ProtocolResponse;
import com.ld.igds.io.sample.data.SampleDto;
import com.ld.igds.m.service.InoutCommonService;
import com.ld.igds.websocket.WebSocketPacket;
import com.ld.igds.websocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
@Slf4j
@Component(NotifyCheckMacService.BEAN_ID)
public class NotifyCheckMacServiceImpl implements NotifyCheckMacService {
 
    @Autowired
    private InoutCommonService inoutManagerService;
    @Autowired
    private CoreCheckStandardService checkStandardService;
 
    @Override
    public void notify(ProtocolResponse<SampleDto> response) {
        log.info("扦样机暂无通知信息!!");
    }
 
    @Override
    public void notifyCheckResult(ProtocolResponse<List<CheckItemData>> response) {
        if (OrderRespEnum.MSG_SUCCESS.getCode().equals(response.getCode())) {
            try {
                int i = 0;
                for (CheckItemData checkItemData : response.getData()) {
                    i = checkStandardService.updateCheckItemByResult(checkItemData);
 
                    notifyToWeb(checkItemData, i);
 
                    Thread.sleep(300);
                }
            } catch (InterruptedException e) {
                log.error("后台推送出现异常,信息={}", e.getMessage());
            }
        }
        log.debug("化验结果信息推送到服务器={}", response.toString());
    }
 
    /**
     * 向前端推送结果信息
     *
     * @param checkItemData
     */
    private void notifyToWeb(CheckItemData checkItemData, int result) {
        if (null == checkItemData.getRemarks()) {
            return;
        }
        // 开始推送
        WebSocketPacket packet = new WebSocketPacket();
        packet.setBizId("IN_CHECK");
        packet.setCompanyId(checkItemData.getCompanyId());
        packet.setBizType(BizType.INOUT_IN.getCode());
        packet.setBizTag(InoutConstant.PROGRESS_CHECK);
        packet.setData("【化验通知】单据号:" + checkItemData.getCheckId() + "\n 项目:"
                + checkItemData.getStandardName() + "\n 值:"
                + checkItemData.getValue() + "\n 结果:"
                + checkItemData.getRemarks());
        WebSocketServer.sendByBizTag(packet);
    }
 
    @Override
    public void onCreate(String address, Integer port) {
        inoutManagerService.updateInoutConfStatus(address, port,
                InoutConstant.MAC_STATUS_NORMAL);
    }
 
    @Override
    public void onDestroy(String address, Integer port) {
        inoutManagerService.updateInoutConfStatus(address, port,
                InoutConstant.MAC_STATUS_NO_SIGNAL);
    }
}