czt
2024-07-13 bd01ba57ed8526a0ee94a50e1f52034251bb54f6
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
package com.ld.igds.weather.notify;
 
import lombok.extern.slf4j.Slf4j;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
import com.ld.igds.constant.BizType;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.models.WeatherInfo;
import com.ld.igds.weather.CoreWeatherService;
import com.ld.igds.websocket.WebSocketPacket;
import com.ld.igds.websocket.WebSocketServer;
 
@Slf4j
@Repository(NotifyWeatherService.BEAN_ID)
public class NotifyWeatherServiceImpl implements NotifyWeatherService {
 
    @Autowired
    private WebSocketServer socketServer;
    @Autowired
    private CoreWeatherService weatherService;
 
    @SuppressWarnings("static-access")
    @Override
    public void notify(WeatherInfo weather) {
 
        if (null == weather) return;
 
        log.debug("气象站信息推送=={}", weather.toString());
 
        WebSocketPacket packet = new WebSocketPacket();
        packet.setCompanyId(weather.getCompanyId());
        packet.setDeptId(weather.getDeptId());
        packet.setBizType(BizType.SCREEN.getCode());
        packet.setBizId(BizType.WEATHER.getCode());
        packet.setOrderResp(OrderRespEnum.MSG_SUCCESS.getCode());
        packet.setData(weather);
 
        socketServer.sendByPocket(packet);
 
        //更新气象缓存
        weatherService.updateCacheAndSave(weather);
 
        //推送到出入库大屏和化验大屏
        try {
            Thread.sleep(500);
 
            packet.setBizType(BizType.SCREEN_INOUT.getCode());
            socketServer.sendByPocket(packet);
 
            Thread.sleep(500);
            packet.setBizType(BizType.SCREEN_CHECK.getCode());
            socketServer.sendByPocket(packet);
            
        } catch (InterruptedException e) {
            log.error("气象信息推送出现异常:{}", e.getMessage());
        }
 
    }
 
    @Override
    public void onCreate(String address, Integer port) {
        weatherService.onCreate(address, port);
    }
 
    @Override
    public void onDestroy(String address, Integer port) {
        weatherService.onDestroy(address, port);
    }
 
}