Commit c2e26291ceb940892b266852a671deda8f2cd952
1 parent
55ee6f5f
修复WVP作为下级平台接受recordinfo指令上报上级平台的问题
Showing
4 changed files
with
45 additions
and
12 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/bean/RecordInfo.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.bean; |
| 2 | 2 | |
| 3 | +import lombok.Data; | |
| 4 | + | |
| 3 | 5 | import java.time.Instant; |
| 4 | 6 | import java.util.List; |
| 5 | 7 | |
| ... | ... | @@ -8,6 +10,7 @@ import java.util.List; |
| 8 | 10 | * @author: swwheihei |
| 9 | 11 | * @date: 2020年5月8日 下午2:05:56 |
| 10 | 12 | */ |
| 13 | +@Data | |
| 11 | 14 | public class RecordInfo { |
| 12 | 15 | |
| 13 | 16 | private String deviceId; |
| ... | ... | @@ -20,6 +23,8 @@ public class RecordInfo { |
| 20 | 23 | |
| 21 | 24 | private int sumNum; |
| 22 | 25 | |
| 26 | + private int count; | |
| 27 | + | |
| 23 | 28 | private Instant lastTime; |
| 24 | 29 | |
| 25 | 30 | private List<RecordItem> recordList; | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/record/RecordEndEventListener.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.event.record; |
| 2 | 2 | |
| 3 | 3 | import com.genersoft.iot.vmp.gb28181.bean.RecordInfo; |
| 4 | +import com.genersoft.iot.vmp.utils.redis.RedisUtil; | |
| 4 | 5 | import org.slf4j.Logger; |
| 5 | 6 | import org.slf4j.LoggerFactory; |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 6 | 8 | import org.springframework.context.ApplicationListener; |
| 7 | 9 | import org.springframework.stereotype.Component; |
| 8 | 10 | |
| ... | ... | @@ -20,25 +22,46 @@ public class RecordEndEventListener implements ApplicationListener<RecordEndEven |
| 20 | 22 | |
| 21 | 23 | private final static Logger logger = LoggerFactory.getLogger(RecordEndEventListener.class); |
| 22 | 24 | |
| 25 | + private Map<String, RecordEndEventHandler> handlerMap = new ConcurrentHashMap<>(); | |
| 23 | 26 | public interface RecordEndEventHandler{ |
| 24 | 27 | void handler(RecordInfo recordInfo); |
| 25 | 28 | } |
| 26 | 29 | |
| 27 | - private Map<String, RecordEndEventHandler> handlerMap = new ConcurrentHashMap<>(); | |
| 28 | - | |
| 29 | 30 | @Override |
| 30 | 31 | public void onApplicationEvent(RecordEndEvent event) { |
| 31 | - logger.info("录像查询完成事件触发,deviceId:{}, channelId: {}, 录像数量{}条", event.getRecordInfo().getDeviceId(), | |
| 32 | - event.getRecordInfo().getChannelId(), event.getRecordInfo().getSumNum() ); | |
| 32 | + String deviceId = event.getRecordInfo().getDeviceId(); | |
| 33 | + String channelId = event.getRecordInfo().getChannelId(); | |
| 34 | + int count = event.getRecordInfo().getCount(); | |
| 35 | + int sumNum = event.getRecordInfo().getSumNum(); | |
| 36 | + logger.info("录像查询完成事件触发,deviceId:{}, channelId: {}, 录像数量{}/{}条", event.getRecordInfo().getDeviceId(), | |
| 37 | + event.getRecordInfo().getChannelId(), count,sumNum); | |
| 33 | 38 | if (handlerMap.size() > 0) { |
| 34 | - for (RecordEndEventHandler recordEndEventHandler : handlerMap.values()) { | |
| 35 | - recordEndEventHandler.handler(event.getRecordInfo()); | |
| 39 | + RecordEndEventHandler handler = handlerMap.get(deviceId + channelId); | |
| 40 | + if (handler !=null){ | |
| 41 | + handler.handler(event.getRecordInfo()); | |
| 42 | + if (count ==sumNum){ | |
| 43 | + handlerMap.remove(deviceId + channelId); | |
| 44 | + } | |
| 36 | 45 | } |
| 37 | 46 | } |
| 38 | - handlerMap.clear(); | |
| 39 | 47 | } |
| 40 | 48 | |
| 49 | + /** | |
| 50 | + * 添加 | |
| 51 | + * @param device | |
| 52 | + * @param channelId | |
| 53 | + * @param recordEndEventHandler | |
| 54 | + */ | |
| 41 | 55 | public void addEndEventHandler(String device, String channelId, RecordEndEventHandler recordEndEventHandler) { |
| 42 | 56 | handlerMap.put(device + channelId, recordEndEventHandler); |
| 43 | 57 | } |
| 58 | + /** | |
| 59 | + * 添加 | |
| 60 | + * @param device | |
| 61 | + * @param channelId | |
| 62 | + */ | |
| 63 | + public void delEndEventHandler(String device, String channelId) { | |
| 64 | + handlerMap.remove(device + channelId); | |
| 65 | + } | |
| 66 | + | |
| 44 | 67 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/session/RecordDataCatch.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.session; |
| 2 | 2 | |
| 3 | 3 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 4 | +import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEventListener; | |
| 4 | 5 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| 5 | 6 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| 6 | 7 | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
| ... | ... | @@ -23,14 +24,17 @@ public class RecordDataCatch { |
| 23 | 24 | |
| 24 | 25 | @Autowired |
| 25 | 26 | private DeferredResultHolder deferredResultHolder; |
| 27 | + @Autowired | |
| 28 | + private RecordEndEventListener recordEndEventListener; | |
| 26 | 29 | |
| 27 | 30 | |
| 28 | - public int put(String deviceId, String sn, int sumNum, List<RecordItem> recordItems) { | |
| 31 | + public int put(String deviceId,String channelId, String sn, int sumNum, List<RecordItem> recordItems) { | |
| 29 | 32 | String key = deviceId + sn; |
| 30 | 33 | RecordInfo recordInfo = data.get(key); |
| 31 | 34 | if (recordInfo == null) { |
| 32 | 35 | recordInfo = new RecordInfo(); |
| 33 | 36 | recordInfo.setDeviceId(deviceId); |
| 37 | + recordInfo.setChannelId(channelId); | |
| 34 | 38 | recordInfo.setSn(sn.trim()); |
| 35 | 39 | recordInfo.setSumNum(sumNum); |
| 36 | 40 | recordInfo.setRecordList(Collections.synchronizedList(new ArrayList<>())); |
| ... | ... | @@ -67,6 +71,7 @@ public class RecordDataCatch { |
| 67 | 71 | msg.setKey(msgKey); |
| 68 | 72 | msg.setData(recordInfo); |
| 69 | 73 | deferredResultHolder.invokeAllResult(msg); |
| 74 | + recordEndEventListener.delEndEventHandler(recordInfo.getDeviceId(),recordInfo.getChannelId()); | |
| 70 | 75 | data.remove(key); |
| 71 | 76 | } |
| 72 | 77 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java
| ... | ... | @@ -102,8 +102,9 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent |
| 102 | 102 | Element recordListElement = rootElementForCharset.element("RecordList"); |
| 103 | 103 | if (recordListElement == null || sumNum == 0) { |
| 104 | 104 | logger.info("无录像数据"); |
| 105 | + int count = recordDataCatch.put(take.getDevice().getDeviceId(),channelId, sn, sumNum, new ArrayList<>()); | |
| 106 | + recordInfo.setCount(count); | |
| 105 | 107 | eventPublisher.recordEndEventPush(recordInfo); |
| 106 | - recordDataCatch.put(take.getDevice().getDeviceId(), sn, sumNum, new ArrayList<>()); | |
| 107 | 108 | releaseRequest(take.getDevice().getDeviceId(), sn); |
| 108 | 109 | } else { |
| 109 | 110 | Iterator<Element> recordListIterator = recordListElement.elementIterator(); |
| ... | ... | @@ -137,12 +138,11 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent |
| 137 | 138 | recordList.add(record); |
| 138 | 139 | } |
| 139 | 140 | recordInfo.setRecordList(recordList); |
| 141 | + int count = recordDataCatch.put(take.getDevice().getDeviceId(),channelId, sn, sumNum, recordList);recordInfo.setCount(count); | |
| 142 | + logger.info("[国标录像], {}->{}: {}/{}", take.getDevice().getDeviceId(), sn, count, sumNum); | |
| 140 | 143 | // 发送消息,如果是上级查询此录像,则会通过这里通知给上级 |
| 141 | 144 | eventPublisher.recordEndEventPush(recordInfo); |
| 142 | - int count = recordDataCatch.put(take.getDevice().getDeviceId(), sn, sumNum, recordList); | |
| 143 | - logger.info("[国标录像], {}->{}: {}/{}", take.getDevice().getDeviceId(), sn, count, sumNum); | |
| 144 | 145 | } |
| 145 | - | |
| 146 | 146 | if (recordDataCatch.isComplete(take.getDevice().getDeviceId(), sn)){ |
| 147 | 147 | releaseRequest(take.getDevice().getDeviceId(), sn); |
| 148 | 148 | } | ... | ... |