!5 优化通道更新逻辑以及添加去重保证数据存入
Merge pull request !5 from panll/temp2
| | |
| | | |
| | | @Override |
| | | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) { |
| | | logger.debug("用户需要登录,访问[{}]失败,AuthenticationException=[{}]", request.getRequestURI(), e.getMessage()); |
| | | // logger.debug("用户需要登录,访问[{}]失败,AuthenticationException=[{}]", request.getRequestURI(), e.getMessage()); |
| | | // 允许跨域 |
| | | response.setHeader("Access-Control-Allow-Origin", "*"); |
| | | // 允许自定义请求头token(允许head跨域) |
| | |
| | | continue; |
| | | } |
| | | Element eventElement = itemDevice.element("Event"); |
| | | DeviceChannel channel = channelContentHander(itemDevice); |
| | | DeviceChannel channel = XmlUtil.channelContentHander(itemDevice); |
| | | channel.setDeviceId(device.getDeviceId()); |
| | | logger.debug("收到来自设备【{}】的通道: {}【{}】", device.getDeviceId(), channel.getName(), channel.getChannelId()); |
| | | switch (eventElement.getText().toUpperCase()) { |
| | | case "ON" : // 上线 |
| | | logger.info("收到来自设备【{}】的通道【{}】上线通知", device.getDeviceId(), channel.getChannelId()); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public DeviceChannel channelContentHander(Element itemDevice){ |
| | | Element channdelNameElement = itemDevice.element("Name"); |
| | | String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim().toString() : ""; |
| | | Element statusElement = itemDevice.element("Status"); |
| | | String status = statusElement != null ? statusElement.getTextTrim().toString() : "ON"; |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setName(channelName); |
| | | Element channdelIdElement = itemDevice.element("DeviceID"); |
| | | String channelId = channdelIdElement != null ? channdelIdElement.getTextTrim().toString() : ""; |
| | | deviceChannel.setChannelId(channelId); |
| | | // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理 |
| | | if (status.equals("ON") || status.equals("On") || status.equals("ONLINE")) { |
| | | deviceChannel.setStatus(1); |
| | | } |
| | | if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) { |
| | | deviceChannel.setStatus(0); |
| | | } |
| | | |
| | | deviceChannel.setManufacture(XmlUtil.getText(itemDevice, "Manufacturer")); |
| | | deviceChannel.setModel(XmlUtil.getText(itemDevice, "Model")); |
| | | deviceChannel.setOwner(XmlUtil.getText(itemDevice, "Owner")); |
| | | deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode")); |
| | | deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block")); |
| | | deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address")); |
| | | if (XmlUtil.getText(itemDevice, "Parental") == null |
| | | || XmlUtil.getText(itemDevice, "Parental") == "") { |
| | | deviceChannel.setParental(0); |
| | | } else { |
| | | deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental"))); |
| | | } |
| | | deviceChannel.setParentId(XmlUtil.getText(itemDevice, "ParentID")); |
| | | if (XmlUtil.getText(itemDevice, "SafetyWay") == null |
| | | || XmlUtil.getText(itemDevice, "SafetyWay") == "") { |
| | | deviceChannel.setSafetyWay(0); |
| | | } else { |
| | | deviceChannel.setSafetyWay(Integer.parseInt(XmlUtil.getText(itemDevice, "SafetyWay"))); |
| | | } |
| | | if (XmlUtil.getText(itemDevice, "RegisterWay") == null |
| | | || XmlUtil.getText(itemDevice, "RegisterWay") == "") { |
| | | deviceChannel.setRegisterWay(1); |
| | | } else { |
| | | deviceChannel.setRegisterWay(Integer.parseInt(XmlUtil.getText(itemDevice, "RegisterWay"))); |
| | | } |
| | | deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum")); |
| | | if (XmlUtil.getText(itemDevice, "Certifiable") == null |
| | | || XmlUtil.getText(itemDevice, "Certifiable") == "") { |
| | | deviceChannel.setCertifiable(0); |
| | | } else { |
| | | deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable"))); |
| | | } |
| | | if (XmlUtil.getText(itemDevice, "ErrCode") == null |
| | | || XmlUtil.getText(itemDevice, "ErrCode") == "") { |
| | | deviceChannel.setErrCode(0); |
| | | } else { |
| | | deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode"))); |
| | | } |
| | | deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime")); |
| | | deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy")); |
| | | deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress")); |
| | | if (XmlUtil.getText(itemDevice, "Port") == null || XmlUtil.getText(itemDevice, "Port") == "") { |
| | | deviceChannel.setPort(0); |
| | | } else { |
| | | deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port"))); |
| | | } |
| | | deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password")); |
| | | if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Longitude"))) { |
| | | deviceChannel.setLongitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Longitude"))); |
| | | } else { |
| | | deviceChannel.setLongitude(0.00); |
| | | } |
| | | if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Latitude"))) { |
| | | deviceChannel.setLatitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Latitude"))); |
| | | } else { |
| | | deviceChannel.setLatitude(0.00); |
| | | } |
| | | if (XmlUtil.getText(itemDevice, "PTZType") == null |
| | | || XmlUtil.getText(itemDevice, "PTZType") == "") { |
| | | deviceChannel.setPTZType(0); |
| | | } else { |
| | | deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType"))); |
| | | } |
| | | deviceChannel.setHasAudio(true); // 默认含有音频,播放时再检查是否有音频及是否AAC |
| | | return deviceChannel; |
| | | } |
| | | |
| | | |
| | | |
| | | public void setCmder(SIPCommander cmder) { |
| | | } |
| | |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; |
| | | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| | | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| | | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
| | | import org.dom4j.DocumentException; |
| | |
| | | if (channelDeviceElement == null) { |
| | | continue; |
| | | } |
| | | String channelDeviceId = channelDeviceElement.getText(); |
| | | Element channdelNameElement = itemDevice.element("Name"); |
| | | String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim().toString() : ""; |
| | | Element statusElement = itemDevice.element("Status"); |
| | | String status = statusElement != null ? statusElement.getText().toString() : "ON"; |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setName(channelName); |
| | | DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice); |
| | | deviceChannel.setDeviceId(device.getDeviceId()); |
| | | String now = this.format.format(new Date(System.currentTimeMillis())); |
| | | deviceChannel.setCreateTime(now); |
| | | deviceChannel.setUpdateTime(now); |
| | | deviceChannel.setChannelId(channelDeviceId); |
| | | // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理 |
| | | if (status.equals("ON") || status.equals("On") || status.equals("ONLINE")) { |
| | | deviceChannel.setStatus(1); |
| | | } |
| | | if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) { |
| | | deviceChannel.setStatus(0); |
| | | } |
| | | |
| | | deviceChannel.setManufacture(getText(itemDevice, "Manufacturer")); |
| | | deviceChannel.setModel(getText(itemDevice, "Model")); |
| | | deviceChannel.setOwner(getText(itemDevice, "Owner")); |
| | | deviceChannel.setCivilCode(getText(itemDevice, "CivilCode")); |
| | | deviceChannel.setBlock(getText(itemDevice, "Block")); |
| | | deviceChannel.setAddress(getText(itemDevice, "Address")); |
| | | if (getText(itemDevice, "Parental") == null || getText(itemDevice, "Parental") == "") { |
| | | deviceChannel.setParental(0); |
| | | } else { |
| | | deviceChannel.setParental(Integer.parseInt(getText(itemDevice, "Parental"))); |
| | | } |
| | | deviceChannel.setParentId(getText(itemDevice, "ParentID")); |
| | | if (getText(itemDevice, "SafetyWay") == null || getText(itemDevice, "SafetyWay") == "") { |
| | | deviceChannel.setSafetyWay(0); |
| | | } else { |
| | | deviceChannel.setSafetyWay(Integer.parseInt(getText(itemDevice, "SafetyWay"))); |
| | | } |
| | | if (getText(itemDevice, "RegisterWay") == null || getText(itemDevice, "RegisterWay") == "") { |
| | | deviceChannel.setRegisterWay(1); |
| | | } else { |
| | | deviceChannel.setRegisterWay(Integer.parseInt(getText(itemDevice, "RegisterWay"))); |
| | | } |
| | | deviceChannel.setCertNum(getText(itemDevice, "CertNum")); |
| | | if (getText(itemDevice, "Certifiable") == null || getText(itemDevice, "Certifiable") == "") { |
| | | deviceChannel.setCertifiable(0); |
| | | } else { |
| | | deviceChannel.setCertifiable(Integer.parseInt(getText(itemDevice, "Certifiable"))); |
| | | } |
| | | if (getText(itemDevice, "ErrCode") == null || getText(itemDevice, "ErrCode") == "") { |
| | | deviceChannel.setErrCode(0); |
| | | } else { |
| | | deviceChannel.setErrCode(Integer.parseInt(getText(itemDevice, "ErrCode"))); |
| | | } |
| | | deviceChannel.setEndTime(getText(itemDevice, "EndTime")); |
| | | deviceChannel.setSecrecy(getText(itemDevice, "Secrecy")); |
| | | deviceChannel.setIpAddress(getText(itemDevice, "IPAddress")); |
| | | if (getText(itemDevice, "Port") == null || getText(itemDevice, "Port") == "") { |
| | | deviceChannel.setPort(0); |
| | | } else { |
| | | deviceChannel.setPort(Integer.parseInt(getText(itemDevice, "Port"))); |
| | | } |
| | | deviceChannel.setPassword(getText(itemDevice, "Password")); |
| | | if (NumericUtil.isDouble(getText(itemDevice, "Longitude"))) { |
| | | deviceChannel.setLongitude(Double.parseDouble(getText(itemDevice, "Longitude"))); |
| | | } else { |
| | | deviceChannel.setLongitude(0.00); |
| | | } |
| | | if (NumericUtil.isDouble(getText(itemDevice, "Latitude"))) { |
| | | deviceChannel.setLatitude(Double.parseDouble(getText(itemDevice, "Latitude"))); |
| | | } else { |
| | | deviceChannel.setLatitude(0.00); |
| | | } |
| | | Element InfoNode = channelDeviceElement.element("Info"); |
| | | if (getText(InfoNode, "PTZType") == null || getText(InfoNode, "PTZType") == "") { |
| | | deviceChannel.setPTZType(0); |
| | | } else { |
| | | deviceChannel.setPTZType(Integer.parseInt(getText(InfoNode, "PTZType"))); |
| | | } |
| | | deviceChannel.setHasAudio(true); // 默认含有音频,播放时再检查是否有音频及是否AAC |
| | | logger.debug("收到来自设备【{}】的通道: {}【{}】", device.getDeviceId(), deviceChannel.getName(), deviceChannel.getChannelId()); |
| | | channelList.add(deviceChannel); |
| | | } |
| | | |
| | |
| | |
|
| | | import com.alibaba.fastjson.JSONArray;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
| | | import org.dom4j.Attribute;
|
| | | import org.dom4j.Document;
|
| | | import org.dom4j.DocumentException;
|
| | |
| | | Document xml = reader.read(new ByteArrayInputStream(content));
|
| | | return xml.getRootElement();
|
| | | }
|
| | |
|
| | | public static DeviceChannel channelContentHander(Element itemDevice){
|
| | | Element channdelNameElement = itemDevice.element("Name");
|
| | | String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim().toString() : "";
|
| | | Element statusElement = itemDevice.element("Status");
|
| | | String status = statusElement != null ? statusElement.getTextTrim().toString() : "ON";
|
| | | DeviceChannel deviceChannel = new DeviceChannel();
|
| | | deviceChannel.setName(channelName);
|
| | | Element channdelIdElement = itemDevice.element("DeviceID");
|
| | | String channelId = channdelIdElement != null ? channdelIdElement.getTextTrim().toString() : "";
|
| | | deviceChannel.setChannelId(channelId);
|
| | | // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理
|
| | | if (status.equals("ON") || status.equals("On") || status.equals("ONLINE")) {
|
| | | deviceChannel.setStatus(1);
|
| | | }
|
| | | if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) {
|
| | | deviceChannel.setStatus(0);
|
| | | }
|
| | |
|
| | | deviceChannel.setManufacture(XmlUtil.getText(itemDevice, "Manufacturer"));
|
| | | deviceChannel.setModel(XmlUtil.getText(itemDevice, "Model"));
|
| | | deviceChannel.setOwner(XmlUtil.getText(itemDevice, "Owner"));
|
| | | deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode"));
|
| | | deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block"));
|
| | | deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address"));
|
| | | if (XmlUtil.getText(itemDevice, "Parental") == null
|
| | | || XmlUtil.getText(itemDevice, "Parental") == "") {
|
| | | deviceChannel.setParental(0);
|
| | | } else {
|
| | | deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental")));
|
| | | }
|
| | | deviceChannel.setParentId(XmlUtil.getText(itemDevice, "ParentID"));
|
| | | if (XmlUtil.getText(itemDevice, "SafetyWay") == null
|
| | | || XmlUtil.getText(itemDevice, "SafetyWay") == "") {
|
| | | deviceChannel.setSafetyWay(0);
|
| | | } else {
|
| | | deviceChannel.setSafetyWay(Integer.parseInt(XmlUtil.getText(itemDevice, "SafetyWay")));
|
| | | }
|
| | | if (XmlUtil.getText(itemDevice, "RegisterWay") == null
|
| | | || XmlUtil.getText(itemDevice, "RegisterWay") == "") {
|
| | | deviceChannel.setRegisterWay(1);
|
| | | } else {
|
| | | deviceChannel.setRegisterWay(Integer.parseInt(XmlUtil.getText(itemDevice, "RegisterWay")));
|
| | | }
|
| | | deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum"));
|
| | | if (XmlUtil.getText(itemDevice, "Certifiable") == null
|
| | | || XmlUtil.getText(itemDevice, "Certifiable") == "") {
|
| | | deviceChannel.setCertifiable(0);
|
| | | } else {
|
| | | deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable")));
|
| | | }
|
| | | if (XmlUtil.getText(itemDevice, "ErrCode") == null
|
| | | || XmlUtil.getText(itemDevice, "ErrCode") == "") {
|
| | | deviceChannel.setErrCode(0);
|
| | | } else {
|
| | | deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode")));
|
| | | }
|
| | | deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime"));
|
| | | deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy"));
|
| | | deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress"));
|
| | | if (XmlUtil.getText(itemDevice, "Port") == null || XmlUtil.getText(itemDevice, "Port") == "") {
|
| | | deviceChannel.setPort(0);
|
| | | } else {
|
| | | deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port")));
|
| | | }
|
| | | deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password"));
|
| | | if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Longitude"))) {
|
| | | deviceChannel.setLongitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Longitude")));
|
| | | } else {
|
| | | deviceChannel.setLongitude(0.00);
|
| | | }
|
| | | if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Latitude"))) {
|
| | | deviceChannel.setLatitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Latitude")));
|
| | | } else {
|
| | | deviceChannel.setLatitude(0.00);
|
| | | }
|
| | | if (XmlUtil.getText(itemDevice, "PTZType") == null
|
| | | || XmlUtil.getText(itemDevice, "PTZType") == "") {
|
| | | deviceChannel.setPTZType(0);
|
| | | } else {
|
| | | deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType")));
|
| | | }
|
| | | deviceChannel.setHasAudio(true); // 默认含有音频,播放时再检查是否有音频及是否AAC
|
| | | return deviceChannel;
|
| | | }
|
| | | }
|
| | |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @description:视频设备数据存储-jdbc实现 |
| | |
| | | @Override |
| | | public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) { |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | // 数据去重 |
| | | List<DeviceChannel> channels = new ArrayList<>(); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | if (deviceChannelList.size() > 1) { |
| | | // 数据去重 |
| | | Set<String> gbIdSet = new HashSet<>(); |
| | | for (DeviceChannel deviceChannel : deviceChannelList) { |
| | | if (!gbIdSet.contains(deviceChannel.getChannelId())) { |
| | | gbIdSet.add(deviceChannel.getChannelId()); |
| | | channels.add(deviceChannel); |
| | | }else { |
| | | stringBuilder.append(deviceChannel.getChannelId() + ","); |
| | | } |
| | | } |
| | | }else { |
| | | channels = deviceChannelList; |
| | | } |
| | | if (stringBuilder.length() > 0) { |
| | | logger.debug("[目录查询]收到的数据存在重复: {}" , stringBuilder); |
| | | } |
| | | try { |
| | | int cleanChannelsResult = deviceChannelMapper.cleanChannelsByDeviceId(deviceId); |
| | | int limitCount = 300; |
| | | boolean result = cleanChannelsResult <0; |
| | | if (!result && deviceChannelList.size() > 0) { |
| | | if (deviceChannelList.size() > limitCount) { |
| | | for (int i = 0; i < deviceChannelList.size(); i += limitCount) { |
| | | if (!result && channels.size() > 0) { |
| | | if (channels.size() > limitCount) { |
| | | for (int i = 0; i < channels.size(); i += limitCount) { |
| | | int toIndex = i + limitCount; |
| | | if (i + limitCount > deviceChannelList.size()) { |
| | | toIndex = deviceChannelList.size(); |
| | | if (i + limitCount > channels.size()) { |
| | | toIndex = channels.size(); |
| | | } |
| | | result = result || deviceChannelMapper.batchAdd(deviceChannelList.subList(i, toIndex)) < 0; |
| | | result = result || deviceChannelMapper.batchAdd(channels.subList(i, toIndex)) < 0; |
| | | } |
| | | }else { |
| | | result = result || deviceChannelMapper.batchAdd(deviceChannelList) < 0; |
| | | result = result || deviceChannelMapper.batchAdd(channels) < 0; |
| | | } |
| | | } |
| | | if (result) { |
| | |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId; |
| | | String uuid = UUID.randomUUID().toString(); |
| | | DeferredResult<ResponseEntity<Device>> result = new DeferredResult<ResponseEntity<Device>>(15*1000L); |
| | | // 默认超时时间为30分钟 |
| | | DeferredResult<ResponseEntity<Device>> result = new DeferredResult<ResponseEntity<Device>>(30*60*1000L); |
| | | result.onTimeout(()->{ |
| | | logger.warn("设备[{}]通道信息同步超时", deviceId); |
| | | // 释放rtpserver |
| | |
| | | wvpResult.setMsg("更新超时"); |
| | | msg.setData(wvpResult); |
| | | resultHolder.invokeAllResult(msg); |
| | | |
| | | }); |
| | | // 等待其他相同请求返回时一起返回 |
| | | if (resultHolder.exist(key, null)) { |
| | |
| | | that.$refs[itemData.deviceId + 'refbtn' ].loading = false; |
| | | }).catch(function(e) { |
| | | console.error(e) |
| | | that.$message({ |
| | | showClose: true, |
| | | message: e, |
| | | type: 'error' |
| | | }); |
| | | that.$refs[itemData.deviceId + 'refbtn' ].loading = false; |
| | | });; |
| | | }); |
| | | }, |
| | | //通知设备上传媒体流 |
| | | sendDevicePush: function(itemData) { |