Commit d18b8c53d7e12905c7c9ed98bbe943a69ca40da6

Authored by liujun001
1 parent e8fc19d8

优化

Too many changes to show.

To preserve performance only 9 of 11 files are displayed.

src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java
@@ -60,4 +60,8 @@ public class VManageBootstrap extends SpringBootServletInitializer { @@ -60,4 +60,8 @@ public class VManageBootstrap extends SpringBootServletInitializer {
60 sessionCookieConfig.setHttpOnly(true); 60 sessionCookieConfig.setHttpOnly(true);
61 61
62 } 62 }
  63 +
  64 + public static <T> T getBean(Class<T> tClass){
  65 + return context.getBean(tClass);
  66 + }
63 } 67 }
src/main/java/com/genersoft/iot/vmp/conf/StreamProxyTask.java
1 package com.genersoft.iot.vmp.conf; 1 package com.genersoft.iot.vmp.conf;
2 2
  3 +import com.genersoft.iot.vmp.VManageBootstrap;
  4 +import com.genersoft.iot.vmp.service.IMediaServerService;
  5 +import com.genersoft.iot.vmp.service.IStreamProxyService;
3 import com.genersoft.iot.vmp.service.StremProxyService1078; 6 import com.genersoft.iot.vmp.service.StremProxyService1078;
  7 +import com.genersoft.iot.vmp.service.impl.StreamProxyServiceImpl;
4 import org.apache.commons.collections4.CollectionUtils; 8 import org.apache.commons.collections4.CollectionUtils;
5 import org.apache.commons.lang3.StringUtils; 9 import org.apache.commons.lang3.StringUtils;
6 import org.slf4j.Logger; 10 import org.slf4j.Logger;
@@ -17,63 +21,20 @@ import java.util.concurrent.TimeUnit; @@ -17,63 +21,20 @@ import java.util.concurrent.TimeUnit;
17 21
18 @Component 22 @Component
19 public class StreamProxyTask { 23 public class StreamProxyTask {
20 - @Autowired  
21 - private RedisTemplate redisTemplate;  
22 - @Autowired  
23 - private StremProxyService1078 stremProxyService1078;  
24 - private Logger logger = LoggerFactory.getLogger(StreamProxyTask.class);  
25 24
26 public static final Long TIME_OUT = 180L; 25 public static final Long TIME_OUT = 180L;
  26 + @Autowired
  27 + private IStreamProxyService streamProxyService;
27 28
28 @Scheduled(cron = "0 15 * * * ? ") 29 @Scheduled(cron = "0 15 * * * ? ")
29 public void work() { 30 public void work() {
30 - Set<String> keys = redisTemplate.keys("tag:history:port:*");  
31 - if (CollectionUtils.isEmpty(keys)) {  
32 - return;  
33 - }  
34 - Long nowDate = new Date().getTime();  
35 - for (String key : keys) {  
36 - String stream = StringUtils.substringAfter(key, "tag:history:port:");  
37 - if (StringUtils.isEmpty(stream)) {  
38 - continue;  
39 - }  
40 -  
41 - Object value = redisTemplate.opsForValue().get("tag:history:httpPort:time:"+stream);  
42 - if(Objects.isNull(value)){  
43 - sendIORequestStop(stream);  
44 - continue;  
45 - }  
46 - try {  
47 - Long val = (Long) value;  
48 - if(val == 0L){  
49 - sendIORequestStop(stream);  
50 - continue;  
51 - }  
52 -  
53 - Long val1 = (nowDate-val)/1000;  
54 - if(val1 > TIME_OUT){  
55 - sendIORequestStop(stream);  
56 - }  
57 -  
58 - }catch (Exception e){  
59 - logger.error("[{}]停流失败",stream,e);  
60 - }  
61 - } 31 + streamProxyService.choose1078Lister();
62 32
63 // task execution logic 33 // task execution logic
64 } 34 }
65 35
66 - private void sendIORequestStop(String stream){  
67 - try {  
68 - String sim = StringUtils.substringBeforeLast(stream,"-");  
69 - String channel = StringUtils.substringAfterLast(stream,"-");  
70 - Object port = redisTemplate.opsForValue().get("tag:history:port:" + stream);  
71 - Object portHtt = redisTemplate.opsForValue().get("tag:history:httpPort:" + stream);  
72 - stremProxyService1078.sendIORequestStop(sim,channel,stream, (Integer) port, (Integer) portHtt); 36 + private void sendIORequestStop(String stream) {
73 37
74 - }catch (Exception e){  
75 - logger.error("[{}]停流失败",stream,e);  
76 - }  
77 38
78 } 39 }
79 } 40 }
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -132,6 +132,9 @@ public class ZLMHttpHookListener { @@ -132,6 +132,9 @@ public class ZLMHttpHookListener {
132 @Autowired 132 @Autowired
133 private Jt1078OfCarController jt1078OfCarController; 133 private Jt1078OfCarController jt1078OfCarController;
134 134
  135 + @Autowired
  136 + private StremProxyService1078 stremProxyService1078;
  137 +
135 138
136 /** 139 /**
137 * 服务器定时上报时间,上报间隔可配置,默认10s上报一次 140 * 服务器定时上报时间,上报间隔可配置,默认10s上报一次
@@ -558,6 +561,7 @@ public class ZLMHttpHookListener { @@ -558,6 +561,7 @@ public class ZLMHttpHookListener {
558 param.getApp(), param.getStream()); 561 param.getApp(), param.getStream());
559 JSONObject ret = new JSONObject(); 562 JSONObject ret = new JSONObject();
560 ret.put("code", 0); 563 ret.put("code", 0);
  564 + stremProxyService1078.sendIORequestStop(param.getStream());
561 // 国标类型的流 565 // 国标类型的流
562 if ("rtp".equals(param.getApp())) { 566 if ("rtp".equals(param.getApp())) {
563 ret.put("close", userSetting.getStreamOnDemand()); 567 ret.put("close", userSetting.getStreamOnDemand());
@@ -669,6 +673,8 @@ public class ZLMHttpHookListener { @@ -669,6 +673,8 @@ public class ZLMHttpHookListener {
669 } 673 }
670 return ret; 674 return ret;
671 } 675 }
  676 +
  677 +
672 // TODO 推流具有主动性,暂时不做处理 678 // TODO 推流具有主动性,暂时不做处理
673 // StreamPushItem streamPushItem = streamPushService.getPush(app, streamId); 679 // StreamPushItem streamPushItem = streamPushService.getPush(app, streamId);
674 // if (streamPushItem != null) { 680 // if (streamPushItem != null) {
src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java
@@ -45,6 +45,8 @@ public interface IStreamProxyService { @@ -45,6 +45,8 @@ public interface IStreamProxyService {
45 */ 45 */
46 void del(String app, String stream); 46 void del(String app, String stream);
47 47
  48 + void choose1078Lister();
  49 +
48 /** 50 /**
49 * 启用视频代理 51 * 启用视频代理
50 * @param app 52 * @param app
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
@@ -3,9 +3,11 @@ package com.genersoft.iot.vmp.service.impl; @@ -3,9 +3,11 @@ package com.genersoft.iot.vmp.service.impl;
3 import com.alibaba.fastjson2.JSONArray; 3 import com.alibaba.fastjson2.JSONArray;
4 import com.alibaba.fastjson2.JSONObject; 4 import com.alibaba.fastjson2.JSONObject;
5 import com.baomidou.dynamic.datasource.annotation.DS; 5 import com.baomidou.dynamic.datasource.annotation.DS;
  6 +import com.genersoft.iot.vmp.VManageBootstrap;
6 import com.genersoft.iot.vmp.common.GeneralCallback; 7 import com.genersoft.iot.vmp.common.GeneralCallback;
7 import com.genersoft.iot.vmp.common.StreamInfo; 8 import com.genersoft.iot.vmp.common.StreamInfo;
8 import com.genersoft.iot.vmp.conf.DynamicTask; 9 import com.genersoft.iot.vmp.conf.DynamicTask;
  10 +import com.genersoft.iot.vmp.conf.StreamProxyTask;
9 import com.genersoft.iot.vmp.conf.UserSetting; 11 import com.genersoft.iot.vmp.conf.UserSetting;
10 import com.genersoft.iot.vmp.conf.exception.ControllerException; 12 import com.genersoft.iot.vmp.conf.exception.ControllerException;
11 import com.genersoft.iot.vmp.gb28181.event.EventPublisher; 13 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
@@ -419,8 +421,8 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -419,8 +421,8 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
419 result = true; 421 result = true;
420 streamProxy.setEnable(true); 422 streamProxy.setEnable(true);
421 updateStreamProxy(streamProxy); 423 updateStreamProxy(streamProxy);
422 - }else if(jsonObject.getInteger("code") == -1){  
423 - redisTemplate.opsForValue().set("stream:status:"+stream,"1",30, TimeUnit.SECONDS); 424 + } else if (jsonObject.getInteger("code") == -1) {
  425 + redisTemplate.opsForValue().set("stream:status:" + stream, "1", 30, TimeUnit.SECONDS);
424 } else { 426 } else {
425 logger.info("启用代理失败: {}/{}->{}({})", app, stream, jsonObject.getString("msg"), 427 logger.info("启用代理失败: {}/{}->{}({})", app, stream, jsonObject.getString("msg"),
426 streamProxy.getSrcUrl() == null ? streamProxy.getUrl() : streamProxy.getSrcUrl()); 428 streamProxy.getSrcUrl() == null ? streamProxy.getUrl() : streamProxy.getSrcUrl());
@@ -471,6 +473,8 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -471,6 +473,8 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
471 @Override 473 @Override
472 public void zlmServerOnline(String mediaServerId) { 474 public void zlmServerOnline(String mediaServerId) {
473 // 移除开启了无人观看自动移除的流 475 // 移除开启了无人观看自动移除的流
  476 +
  477 + choose1078Lister();
474 List<StreamProxyItem> streamProxyItemList = streamProxyMapper.selectAutoRemoveItemByMediaServerId(mediaServerId); 478 List<StreamProxyItem> streamProxyItemList = streamProxyMapper.selectAutoRemoveItemByMediaServerId(mediaServerId);
475 if (streamProxyItemList.size() > 0) { 479 if (streamProxyItemList.size() > 0) {
476 gbStreamMapper.batchDel(streamProxyItemList); 480 gbStreamMapper.batchDel(streamProxyItemList);
@@ -623,4 +627,59 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -623,4 +627,59 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
623 updateStreamProxy(streamProxyItem); 627 updateStreamProxy(streamProxyItem);
624 } 628 }
625 } 629 }
  630 +
  631 +
  632 + public void choose1078Lister() {
  633 + Set<String> keys = redisTemplate.keys("tag:history:port:*");
  634 + if (org.apache.commons.collections4.CollectionUtils.isEmpty(keys)) {
  635 + return;
  636 + }
  637 + Long nowDate = new Date().getTime();
  638 + for (String key : keys) {
  639 + String stream = StringUtils.substringAfter(key, "tag:history:port:");
  640 + if (StringUtils.isEmpty(stream)) {
  641 + continue;
  642 + }
  643 +
  644 + Object value = redisTemplate.opsForValue().get("tag:history:httpPort:time:" + stream);
  645 + if (Objects.isNull(value)) {
  646 + sendIORequestStop(stream);
  647 + continue;
  648 + }
  649 + try {
  650 + Long val = (Long) value;
  651 + if (val == 0L) {
  652 + sendIORequestStop(stream);
  653 + continue;
  654 + }
  655 +
  656 + Long val1 = (nowDate - val) / 1000;
  657 + if (val1 > StreamProxyTask.TIME_OUT) {
  658 + sendIORequestStop(stream);
  659 + }
  660 +
  661 + } catch (Exception e) {
  662 + logger.error("[{}]停流失败", stream, e);
  663 + }
  664 + }
  665 +
  666 + // task execution logic
  667 + }
  668 +
  669 + private void sendIORequestStop(String stream) {
  670 + try {
  671 + String sim = StringUtils.substringBeforeLast(stream, "-");
  672 + String channel = StringUtils.substringAfterLast(stream, "-");
  673 + Object port = redisTemplate.opsForValue().get("tag:history:port:" + stream);
  674 + Object portHtt = redisTemplate.opsForValue().get("tag:history:httpPort:" + stream);
  675 + stremProxyService1078.sendIORequestStop(sim, channel, stream, (Integer) port, (Integer) portHtt);
  676 +
  677 + del("schedule", stream);
  678 + // VManageBootstrap.getBean(StreamProxyServiceImpl.class).del("schedule", stream);
  679 +
  680 + } catch (Exception e) {
  681 + logger.error("[{}]停流失败", stream, e);
  682 + }
  683 +
  684 + }
626 } 685 }
src/main/java/com/genersoft/iot/vmp/service/impl/StremProxyService1078Impl.java
@@ -32,6 +32,7 @@ public class StremProxyService1078Impl implements StremProxyService1078 { @@ -32,6 +32,7 @@ public class StremProxyService1078Impl implements StremProxyService1078 {
32 @Autowired 32 @Autowired
33 private RedisTemplate<Object, Object> redisTemplate; 33 private RedisTemplate<Object, Object> redisTemplate;
34 34
  35 +
35 private static final Logger log = LoggerFactory.getLogger(StremProxyService1078Impl.class); 36 private static final Logger log = LoggerFactory.getLogger(StremProxyService1078Impl.class);
36 37
37 38
@@ -71,7 +72,7 @@ public class StremProxyService1078Impl implements StremProxyService1078 { @@ -71,7 +72,7 @@ public class StremProxyService1078Impl implements StremProxyService1078 {
71 log.info(entity.getResultStr()); 72 log.info(entity.getResultStr());
72 } 73 }
73 74
74 - 75 +// streamProxyService.del("schedule", stream);
75 resultMap.put("code", "1"); 76 resultMap.put("code", "1");
76 resultMap.put("message", "OK"); 77 resultMap.put("message", "OK");
77 78
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/Jt1078OfCarController.java
@@ -455,7 +455,6 @@ public class Jt1078OfCarController { @@ -455,7 +455,6 @@ public class Jt1078OfCarController {
455 } 455 }
456 } 456 }
457 457
458 - public Map<>  
459 458
460 @PostMapping({"/test"}) 459 @PostMapping({"/test"})
461 public String test(@RequestBody TestEntity test) { 460 public String test(@RequestBody TestEntity test) {
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/config/TuohuaConfigBean.java
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.jt1078.platform.config; @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.jt1078.platform.config;
3 import com.alibaba.fastjson2.JSON; 3 import com.alibaba.fastjson2.JSON;
4 import com.genersoft.iot.vmp.vmanager.jt1078.platform.ben.HttpClientPostEntity; 4 import com.genersoft.iot.vmp.vmanager.jt1078.platform.ben.HttpClientPostEntity;
5 import com.genersoft.iot.vmp.vmanager.jt1078.platform.handler.HttpClientUtil; 5 import com.genersoft.iot.vmp.vmanager.jt1078.platform.handler.HttpClientUtil;
  6 +import com.xiaoleilu.hutool.convert.Convert;
6 import org.apache.commons.collections4.CollectionUtils; 7 import org.apache.commons.collections4.CollectionUtils;
7 import org.apache.commons.lang3.RandomUtils; 8 import org.apache.commons.lang3.RandomUtils;
8 import org.apache.commons.lang3.StringUtils; 9 import org.apache.commons.lang3.StringUtils;
@@ -94,7 +95,7 @@ public class TuohuaConfigBean { @@ -94,7 +95,7 @@ public class TuohuaConfigBean {
94 private final String LINE_URL = "/line/company/{companyId}?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}"; 95 private final String LINE_URL = "/line/company/{companyId}?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}";
95 //private final String LINE_URL = "/line/all?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}"; 96 //private final String LINE_URL = "/line/all?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}";
96 private final String CAR_URL = "/car/company/{companyId}?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}"; 97 private final String CAR_URL = "/car/company/{companyId}?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}";
97 - private final String GPS_URL = "//gps/all?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}"; 98 + private final String GPS_URL = "/gps/all?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}";
98 99
99 public String requestLine(HttpClientUtil httpClientUtil, String companyId) throws Exception { 100 public String requestLine(HttpClientUtil httpClientUtil, String companyId) throws Exception {
100 String nonce = random(5); 101 String nonce = random(5);
@@ -247,15 +248,25 @@ public class TuohuaConfigBean { @@ -247,15 +248,25 @@ public class TuohuaConfigBean {
247 String sim = convertStr(ch.get("sim")); 248 String sim = convertStr(ch.get("sim"));
248 String name = code; 249 String name = code;
249 250
  251 + Integer abnormalStatus = 1;
  252 + long now = new Date().getTime();
  253 +
250 Optional<HashMap> optional = gpsList.stream().filter(g -> Objects.nonNull(g) && Objects.nonNull(g.get("deviceId")) && 254 Optional<HashMap> optional = gpsList.stream().filter(g -> Objects.nonNull(g) && Objects.nonNull(g.get("deviceId")) &&
251 Objects.nonNull(ch.get("equipmentCode")) && Objects.equals(g.get("deviceId").toString(), ch.get("equipmentCode").toString())).findFirst(); 255 Objects.nonNull(ch.get("equipmentCode")) && Objects.equals(g.get("deviceId").toString(), ch.get("equipmentCode").toString())).findFirst();
252 - if (StringUtils.isEmpty(sim) || !optional.isPresent() || Objects.isNull(optional.get().get("abnormalStatus")) || StringUtils.equalsIgnoreCase("offline", optional.get().get("abnormalStatus").toString())) {  
253 - name = "<del>" + name + "</del>"; 256 + if (StringUtils.isEmpty(sim) || !optional.isPresent()) {
  257 + name = "<view style='color:red'>" + name + "</view>";
  258 + abnormalStatus = 10;
  259 + }else if(Objects.isNull(optional.get().get("timestamp")) || now- Convert.toLong(optional.get().get("timestamp"))<=120000){
  260 + name = "<view style='color:#ccc'>" + name + "</view>";
  261 + abnormalStatus =20;
  262 + }else{
  263 + name = "<view style='color:blue'>" + name + "</view>";
254 } 264 }
255 265
256 HashMap<String, Object> hashMap = combationTree(code, "bus1", code, false, name, code, false, "<span><img src='/metronic_v4.5.4/layui/icon/bus1.png' class ='imageIcon' /></span><span>" + code + "</span>", 266 HashMap<String, Object> hashMap = combationTree(code, "bus1", code, false, name, code, false, "<span><img src='/metronic_v4.5.4/layui/icon/bus1.png' class ='imageIcon' /></span><span>" + code + "</span>",
257 "<span><img src='/metronic_v4.5.4/layui/icon/bus1.png' class ='imageIcon' /></span><span>" + code + "</span>", 301); 267 "<span><img src='/metronic_v4.5.4/layui/icon/bus1.png' class ='imageIcon' /></span><span>" + code + "</span>", 301);
258 hashMap.put("sim", formatSim(convertStr(ch.get("sim")))); 268 hashMap.put("sim", formatSim(convertStr(ch.get("sim"))));
  269 + hashMap.put("abnormalStatus",abnormalStatus);
259 270
260 if (StringUtils.equals(profileActive, "local")) { 271 if (StringUtils.equals(profileActive, "local")) {
261 // hashMap.put("sim","123456789011"); 272 // hashMap.put("sim","123456789011");
web_src/config/index.js
@@ -18,7 +18,7 @@ module.exports = { @@ -18,7 +18,7 @@ module.exports = {
18 }, 18 },
19 }, 19 },
20 "/static/snap": { 20 "/static/snap": {
21 - target: "http://10.10.2.22:18089", 21 + target: "http://118.113.164.50:18989",
22 changeOrigin: true, 22 changeOrigin: true,
23 // pathRewrite: { 23 // pathRewrite: {
24 // '^/static/snap': '/static/snap' 24 // '^/static/snap': '/static/snap'