648540858
2022-09-01 03d6ad289baddf8feed64ffca5f1b13828bea710
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
package com.genersoft.iot.vmp.gb28181.task.impl;
 
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
 
import javax.sip.DialogState;
import java.util.List;
 
/**
 * 向已经订阅(移动位置)的上级发送MobilePosition消息
 * @author lin
 */
public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
 
    private Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeHandlerTask.class);
 
    private IRedisCatchStorage redisCatchStorage;
    private IVideoManagerStorage storager;
    private ISIPCommanderForPlatform sipCommanderForPlatform;
    private SubscribeHolder subscribeHolder;
    private ParentPlatform platform;
 
    private String sn;
    private String key;
 
    public MobilePositionSubscribeHandlerTask(IRedisCatchStorage redisCatchStorage,
                                              ISIPCommanderForPlatform sipCommanderForPlatform,
                                              IVideoManagerStorage storager,
                                              String platformId,
                                              String sn,
                                              String key,
                                              SubscribeHolder subscribeInfo,
                                              DynamicTask dynamicTask) {
        this.redisCatchStorage = redisCatchStorage;
        this.storager = storager;
        this.platform = storager.queryParentPlatByServerGBId(platformId);
        this.sn = sn;
        this.key = key;
        this.sipCommanderForPlatform = sipCommanderForPlatform;
        this.subscribeHolder = subscribeInfo;
    }
 
    @Override
    public void run() {
 
        if (platform == null) {
            return;
        }
        SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId());
        if (subscribe != null) {
 
            // TODO 暂时只处理视频流的回复,后续增加对国标设备的支持
            List<DeviceChannel> gbStreams = storager.queryGbStreamListInPlatform(platform.getServerGBId());
            if (gbStreams.size() == 0) {
                return;
            }
            for (DeviceChannel deviceChannel : gbStreams) {
                String gbId = deviceChannel.getChannelId();
                GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId);
                // 无最新位置不发送
                if (gpsMsgInfo != null) {
                    // 经纬度都为0不发送
                    if (gpsMsgInfo.getLng() == 0 && gpsMsgInfo.getLat() == 0) {
                        continue;
                    }
                    // 发送GPS消息
                    sipCommanderForPlatform.sendNotifyMobilePosition(platform, gpsMsgInfo, subscribe);
                }
            }
        }
    }
 
    @Override
    public void stop() {
 
    }
 
    @Override
    public DialogState getDialogState() {
        return null;
    }
}