jiazx0107@163.com
2023-08-11 be175fe739e687cd1d45da58f2cb7dd0c36d001f
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
package com.ld.igds.io.impl;
 
import com.ld.igds.constant.BizType;
import com.ld.igds.gas.dto.GasProgressData;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.notify.NotifyWebInvoker;
import com.ld.igds.order.ExeOrderService;
import com.ld.igds.order.data.ExeRequest;
import com.ld.igds.order.data.OrderProgress;
import com.ld.igds.pest.dto.PestProgressData;
import com.ld.igds.quantity.dto.QuantityProgressData;
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
public class NotifyWebInvokerImpl implements NotifyWebInvoker {
 
    @Autowired
    private ExeOrderService exeOrderService;
 
    @Override
    public void notifyWeb(String companyId, OrderRespEnum orderResp,
                          BizType bizType, String notifyMsg) {
        // 通知前端
        WebSocketPacket packet = new WebSocketPacket();
        packet.setBizType(bizType.getCode());
        packet.setCompanyId(companyId);
        packet.setOrderResp(orderResp.getCode());
        packet.setData(notifyMsg);
        WebSocketServer.sendByPocket(packet);
    }
 
    @Override
    public void notifyWeb(String companyId, String deptId, String userId, OrderRespEnum orderResp,
                          BizType bizType, String notifyMsg) {
        // 通知前端
        WebSocketPacket packet = new WebSocketPacket();
        packet.setBizType(bizType.getCode());
        packet.setCompanyId(companyId);
        packet.setOrderResp(orderResp.getCode());
        packet.setData(notifyMsg);
        packet.setDeptId(deptId);
        packet.setUserId(userId);
        WebSocketServer.sendByUser(packet);
    }
 
    @Override
    public void notifyGasProgress(GasProgressData progress) {
        // 通知前端进度信息
        WebSocketPacket packet = new WebSocketPacket();
        packet.setBizType(BizType.GAS.getCode());
        packet.setCompanyId(progress.getCompanyId());
        packet.setOrderResp(OrderRespEnum.ORDER_INPROGRESS.getCode());
        packet.setData(progress);
        WebSocketServer.sendByPocket(packet);
    }
 
    @Override
    public void notifyPestProgress(PestProgressData progress) {
        // 通知前端进度信息
        WebSocketPacket packet = new WebSocketPacket();
        packet.setBizType(BizType.PEST.getCode());
        packet.setCompanyId(progress.getCompanyId());
        packet.setOrderResp(OrderRespEnum.ORDER_INPROGRESS.getCode());
        packet.setData(progress);
        WebSocketServer.sendByPocket(packet);
    }
 
    @Override
    public void notifyAnalysisStatusSuccess(String companyId, String serId, OrderRespEnum orderResp, String notifyMsg) {
        try {
            // 通知前端
            WebSocketPacket packet = new WebSocketPacket();
            packet.setCompanyId(companyId);
            packet.setOrderResp(orderResp.getCode());
            packet.setData(notifyMsg);
            packet.setBizId("DEVICE_STATS");
 
            ExeRequest request = exeOrderService.getControlCache(companyId, serId);
            if (null == request) {
                return;
            }
            // 设备状态跟新后开始通知前端
            packet.setBizType(request.getBizType());
            packet.setDeptId(request.getDeptId());
 
            WebSocketServer.sendByPocket(packet);
 
        } catch (Exception e) {
            log.error("后台推送设备状态查询,执行失败:" + e);
        }
 
    }
 
 
    @Override
    public void notifyWebOrderProgress(String companyId, String bizType, OrderProgress progress) {
        WebSocketPacket packet = new WebSocketPacket();
        packet.setBizType(bizType);
        packet.setCompanyId(companyId);
        packet.setOrderResp(OrderRespEnum.ORDER_INPROGRESS.getCode());
        packet.setData(progress);
        WebSocketServer.sendByPocket(packet);
    }
 
    @Override
    public void notifyQuantityProgress(QuantityProgressData progress) {
        // 通知前端进度信息
        WebSocketPacket packet = new WebSocketPacket();
        packet.setBizType(BizType.QUANTITY.getCode());
        packet.setCompanyId(progress.getCompanyId());
        packet.setOrderResp(OrderRespEnum.ORDER_INPROGRESS.getCode());
        packet.setData(progress);
        packet.setDeptId(progress.getDeptId());
        WebSocketServer.sendByPocket(packet);
    }
 
}