StremProxyService1078Impl.java
3.85 KB
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
package com.genersoft.iot.vmp.service.impl;
import com.genersoft.iot.vmp.VManageBootstrap;
import com.genersoft.iot.vmp.service.IStreamProxyService;
import com.genersoft.iot.vmp.service.StremProxyService1078;
import com.genersoft.iot.vmp.vmanager.jt1078.platform.ben.HttpClientPostEntity;
import com.genersoft.iot.vmp.vmanager.jt1078.platform.config.Jt1078ConfigBean;
import com.genersoft.iot.vmp.vmanager.jt1078.platform.handler.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Service
public class StremProxyService1078Impl implements StremProxyService1078 {
@Autowired
private Jt1078ConfigBean jt1078ConfigBean;
@Autowired
private HttpClientUtil httpClientUtil;
@Autowired
private RedisTemplate<Object, Object> redisTemplate;
private static final Logger log = LoggerFactory.getLogger(StremProxyService1078Impl.class);
@Override
public Map<String, Object> sendIORequestStop(String sim, String channel, String stream, Integer port, Integer httpPort) {
Map<String, Object> resultMap = new HashMap<>();
if (StringUtils.isBlank(sim)) {
resultMap.put("code", "-100");
resultMap.put("message", "sim 不能为空");
return resultMap;
}
if (StringUtils.isBlank(channel)) {
resultMap.put("code", "-100");
resultMap.put("message", "channel 不能为空");
return resultMap;
}
String msg = jt1078ConfigBean.formatMessageStop(sim, channel);
String url = null;
try {
url = StringUtils.replace(this.jt1078ConfigBean.getJt1078Url(), "{0}", this.jt1078ConfigBean.getStopSendPort());
HttpClientPostEntity entity = httpClientUtil.doPost(url, msg, null);
IStreamProxyService streamProxyService = VManageBootstrap.getBean(IStreamProxyService.class);
if(Objects.nonNull(streamProxyService)){
streamProxyService.stop1("schedule",stream);
}
log.info("port:[{}]",port);
if(Objects.nonNull(port)){
// VideoServerApp.stopServer(port,httpPort);
}
if (Objects.isNull(entity)) {
log.info("HttpClientPostEntity is null");
} else {
log.info(entity.getResultStr());
}
redisTemplate.opsForValue().set("jt1078:count:"+stream,20000,300,TimeUnit.SECONDS);
resultMap.put("code", "1");
resultMap.put("message", "OK");
return resultMap;
} catch (Exception e) {
log.error("发送停止推流指令异常;[{}],[{}]", url, msg, e);
resultMap.put("code", "-20");
resultMap.put("message", "发送停止推流指令异常");
return resultMap;
}
}
@Override
public Map<String, Object> sendIORequestStop(String stream) {
String sim = StringUtils.substringBefore(stream, "-");
String channel = StringUtils.substringAfterLast(stream, "-");
Object port = this.redisTemplate.opsForValue().get("tag:history:port:" + stream);
Object httpPort = this.redisTemplate.opsForValue().get("tag:history:httpPort:" + stream);
return sendIORequestStop(sim, channel, stream, (Integer) port, (Integer) httpPort);
}
@Override
public Integer stopCount(String stream) {
Object countVal = redisTemplate.opsForValue().get("jt1078:count:" + stream);
return Objects.nonNull(countVal)?(Integer) countVal:null;
}
}