OSD通过国标码判断通道、数据中心车辆人脸在线率离线时间点
| | |
| | | //公安部前缀 |
| | | public final static String Dept = "Dept_"; |
| | | |
| | | //海康访问OSD路径 |
| | | public final static String HK_OSD_PATH = "/ISAPI/System/Video/inputs/channels/1/overlays"; |
| | | //海康访问OSD路径 通道1 |
| | | public final static String HK_OSD_PATH_1 = "/ISAPI/System/Video/inputs/channels/1/overlays"; |
| | | //海康访问OSD路径 通道2 |
| | | public final static String HK_OSD_PATH_2 = "/ISAPI/System/Video/inputs/channels/2/overlays"; |
| | | //海康访问时间路径 |
| | | public final static String HK_OSD_TIME = "/ISAPI/System/time"; |
| | | |
| | | //国标码通道索引 |
| | | public final static Integer SerialNumber_Channel = 13; |
| | | //国标码设备类型索引 |
| | | public final static Integer SerialNumber_Category = 17; |
| | | //国标全景标识 |
| | | public final static char SerialNumber_All = '0'; |
| | | //国标细节标识 |
| | | public final static char SerialNumber_Detail = '1'; |
| | | |
| | | //标签常量 |
| | | public final static Integer TRUE = 1; |
| | | public final static Integer FALSE = 0; |
| | |
| | | import com.ycl.api.DH.lib.structure.*; |
| | | import com.ycl.platform.domain.result.OSDResult; |
| | | import com.ycl.utils.StringUtils; |
| | | import constant.ApiConstants; |
| | | import enumeration.DeviceType; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | |
| | | return bRet; |
| | | } |
| | | |
| | | public static OSDResult getOsd(LLong loginId) { |
| | | public static OSDResult getOsd(String serialNumber,LLong loginId) { |
| | | OSDResult osdResult = new OSDResult(); |
| | | NetSDKLib.NET_TIME deviceTime = new NetSDKLib.NET_TIME(); |
| | | if (!netsdk.CLIENT_QueryDeviceTime(loginId, deviceTime, 3000)) { |
| | |
| | | |
| | | NET_CFG_GBMODE_INFO osdInfo = new NET_CFG_GBMODE_INFO(); |
| | | osdInfo.write(); |
| | | boolean b = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_GBMODE, 0, osdInfo.getPointer(), osdInfo.size(), 3000, reserve.getPointer()); |
| | | boolean b = false; |
| | | /** |
| | | * 通过国标倒数第七位判断通道 0/全景 1/细节 |
| | | * 对于海康来说: 国标倒7: 0/全景/通道2 1/细节/通道1 |
| | | * 对于大华来说: 国标倒7: 0/全景/通道1 1/细节/通道2 |
| | | * 宇视单通道不考虑 |
| | | */ |
| | | if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_All ) { |
| | | b = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_GBMODE, 0, osdInfo.getPointer(), osdInfo.size(), 3000, reserve.getPointer()); |
| | | }else if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_Detail){ |
| | | b = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_GBMODE, 1, osdInfo.getPointer(), osdInfo.size(), 3000, reserve.getPointer()); |
| | | } |
| | | |
| | | if (!b) { |
| | | // log.error("CLIENT_GetConfig Failed!" + ToolKits.getErrorCodePrint()); |
| | | return null; |
| | |
| | | @Slf4j |
| | | public class DHApi { |
| | | |
| | | public static OSDResult getOsd(String ip, String userName, String password){ |
| | | public static OSDResult getOsd(String serialNumber,String ip, String userName, String password){ |
| | | NetSDKLib.LLong loginId = LoginModule.login(ip, 80, userName, password); |
| | | if(loginId.longValue() ==0){ |
| | | return null; |
| | | } |
| | | OSDResult osd = LoginModule.getOsd(loginId); |
| | | OSDResult osd = LoginModule.getOsd(serialNumber,loginId); |
| | | LoginModule.logout(loginId); |
| | | return osd; |
| | | } |
| | |
| | | |
| | | @Slf4j |
| | | public class HKApi { |
| | | public static OSDResult getOsdByIP(String ip, String userName, String password) { |
| | | public static OSDResult getOsdByIP(String serialNumber, String ip, String userName, String password) { |
| | | OSDResult osdResult = new OSDResult(); |
| | | String hostUrl = "http://" + ip; |
| | | try { |
| | | //获取OSD |
| | | String OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH, userName, password); |
| | | /** |
| | | * 通过国标倒数第七位判断通道 0/全景 1/细节 |
| | | * 对于海康来说: 国标倒7 0/全景/通道2 1/细节/通道1 |
| | | * 对于大华来说: 国标倒7 0/全景/通道1 1/细节/通道2 |
| | | * 宇视单通道不考虑 |
| | | */ |
| | | String OSDString = null; |
| | | if(StringUtils.isEmpty(serialNumber)) return null; |
| | | if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_All ) { |
| | | OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_2, userName, password); |
| | | }else if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_Detail){ |
| | | OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_1, userName, password); |
| | | } |
| | | //通过设备类型判断(弃用) |
| | | // if(serialNumber.charAt(ApiConstants.SerialNumber_Category) == 1 ){ |
| | | // //枪机 |
| | | // if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 1){ |
| | | // OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_1, userName, password); |
| | | // }else if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 0){ |
| | | // OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_2, userName, password); |
| | | // } |
| | | // }else if(serialNumber.charAt(ApiConstants.SerialNumber_Category) == 2){ |
| | | // //球机 |
| | | // if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 0){ |
| | | // OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_1, userName, password); |
| | | // }else if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 1){ |
| | | // OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_2, userName, password); |
| | | // } |
| | | // }else if(serialNumber.charAt(ApiConstants.SerialNumber_Category) == 3){ |
| | | // //卡口 单通道 |
| | | // OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_1, userName, password); |
| | | // }else if(serialNumber.charAt(ApiConstants.SerialNumber_Category) == 4){ |
| | | // //高空 |
| | | // if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 0){ |
| | | // OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_1, userName, password); |
| | | // }else if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 1){ |
| | | // OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_2, userName, password); |
| | | // } |
| | | // } |
| | | if (OSDString == null) return null; |
| | | |
| | | //解析xml |
| | |
| | | query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | } |
| | | Sort sort = Sort.by( |
| | | Sort.Order.asc("pingOnline") // 首先按照 pingOnline 升序排序 |
| | | Sort.Order.asc("pingOnline"), // 首先按照 pingOnline 升序排序 |
| | | Sort.Order.desc("offLineCount") // 首先按照 pingOnline 升序排序 |
| | | ); |
| | | // 通过pingOnline字段排序,为false的排在前面 |
| | | query.with(sort); |
| | |
| | | if (params.getOption() != null) { |
| | | query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | } |
| | | Sort sort = Sort.by( |
| | | Sort.Order.asc("pingOnline"), // 首先按照 pingOnline 升序排序 |
| | | Sort.Order.desc("offLineCount") // 首先按照 pingOnline 升序排序 |
| | | ); |
| | | // 通过pingOnline字段排序,为false的排在前面 |
| | | query.with(Sort.by(Sort.Order.asc("pingOnline"))); |
| | | query.with(sort); |
| | | //分页数量 |
| | | long total = mongoTemplate.count(query, TMonitorResult.class); |
| | | MongoUtil.setPage(query, params, TIME_FIELD); |
| | |
| | | item.setOnlineStr("离线"); |
| | | } else { |
| | | item.setOnlineStr("未知"); |
| | | } |
| | | List<String> offLineTime = item.getOffLineTimeStr(); |
| | | if(!CollectionUtils.isEmpty(offLineTime)) { |
| | | //后续可以改成配置的离线次数(提取前n次,n为配置的离线次数) |
| | | if (offLineTime.size() > 1) { |
| | | offLineTime = offLineTime.subList(0, 2); |
| | | } |
| | | item.setOffLineTimeStr(offLineTime); |
| | | } |
| | | }); |
| | | |
| | |
| | | if (params.getOption() != null) { |
| | | query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | } |
| | | Sort sort = Sort.by( |
| | | Sort.Order.asc("pingOnline"), // 首先按照 pingOnline 升序排序 |
| | | Sort.Order.desc("offLineCount") // 首先按照 pingOnline 升序排序 |
| | | ); |
| | | // 通过pingOnline字段排序,为false的排在前面 |
| | | query.with(Sort.by(Sort.Order.asc("pingOnline"))); |
| | | query.with(sort); |
| | | //分页数量 |
| | | long total = mongoTemplate.count(query, TMonitorResult.class); |
| | | MongoUtil.setPage(query, params, TIME_FIELD); |
| | |
| | | } else { |
| | | item.setOnlineStr("未知"); |
| | | } |
| | | List<String> offLineTime = item.getOffLineTimeStr(); |
| | | if(!CollectionUtils.isEmpty(offLineTime)) { |
| | | //后续可以改成配置的离线次数(提取前n次,n为配置的离线次数) |
| | | if (offLineTime.size() > 1) { |
| | | offLineTime = offLineTime.subList(0, 2); |
| | | } |
| | | item.setOffLineTimeStr(offLineTime); |
| | | } |
| | | }); |
| | | params.setDeptTag(-1); |
| | | params.setDeviceType(3); |
| | | |
| | | // 统计设备数量 |
| | | // 统计设备数量 |
| | | //卡片统计 |
| | | int totalCount = 0; |
| | | int onlineCount = 0; |
| | |
| | | */ |
| | | public void getOSD() throws ExecutionException, InterruptedException { |
| | | log.info("开始获取OSD"); |
| | | // //海康设备测试 |
| | | // //全景 |
| | | // OSDResult osd1 = HKApi.getOsdByIP("51031140001320359101","51.95.99.112", HKUserName, HKPassword); |
| | | // log.info("海康全景:{}",osd1); |
| | | // //细节 |
| | | // OSDResult osd2 = HKApi.getOsdByIP("51031140001321359101","51.95.99.112", HKUserName, HKPassword); |
| | | // log.info("海康细节:{}",osd2); |
| | | // //大华设备测试 |
| | | // OSDResult osd3 = DHApi.getOsd("51030244001320120201","51.95.4.3", DHUserName, DHPassword); |
| | | // log.info("大华全景:{}",osd3); |
| | | // OSDResult osd4 = DHApi.getOsd("51030244001321120201","51.95.4.3", DHUserName, DHPassword); |
| | | // log.info("大华细节:{}",osd4); |
| | | //查一机一档monitor |
| | | Query query = new Query(Criteria.where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | List<MonitorQualifyResult> oneMachineFileResults = mongoTemplate.find(query, MonitorQualifyResult.class); |
| | |
| | | osdCheckResult.setOsdTimeCorrect(ApiConstants.OSD_Unknown); |
| | | } |
| | | //检查通道名是否正确 |
| | | //校验规则,这里暂时不比较全景和细节两字。 |
| | | if (!StringUtils.isEmpty(osdResult.getName()) && !StringUtils.isEmpty(monitor.getName())) { |
| | | if (monitor.getName().equals(osdResult.getName()) || monitor.getName().replace("全景", "细节").equals(osdResult.getName()) || monitor.getName().replace("细节", "全景").equals(osdResult.getName())) { |
| | | if (monitor.getName().equals(osdResult.getName())) { |
| | | osdCheckResult.setOsdNameCorrect(ApiConstants.OSD_Correct); |
| | | osdCheckResult.setOsdName(osdResult.getName()); |
| | | } else { |
| | |
| | | public OSDResult call() throws Exception { |
| | | if (DeviceType.HK.getType().equals(monitor.getDeviceType())) { |
| | | //海康 |
| | | OSDResult osd = HKApi.getOsdByIP(monitor.getIp(), HKUserName, HKPassword); |
| | | OSDResult osd = HKApi.getOsdByIP(monitor.getSerialNumber(),monitor.getIp(), HKUserName, HKPassword); |
| | | OSDResult osdResult = checkSuccess(monitor, osd); |
| | | if (osdResult!=null) { |
| | | return osd; |
| | |
| | | } |
| | | } else if (DeviceType.DH.getType().equals(monitor.getDeviceType())) { |
| | | //大华 |
| | | OSDResult osd = DHApi.getOsd(monitor.getIp(), DHUserName, DHPassword); |
| | | OSDResult osd = DHApi.getOsd(monitor.getSerialNumber(),monitor.getIp(), DHUserName, DHPassword); |
| | | OSDResult osdResult = checkSuccess(monitor, osd); |
| | | if (osdResult!=null) { |
| | | return osd; |
| | |
| | | |
| | | private OSDResult tryAllApi(TMonitor monitor) { |
| | | //尝试海康的api |
| | | OSDResult hkosd = HKApi.getOsdByIP(monitor.getIp(), HKUserName, HKPassword); |
| | | OSDResult hkosd = HKApi.getOsdByIP(monitor.getSerialNumber(),monitor.getIp(), HKUserName, HKPassword); |
| | | if (hkosd != null) { |
| | | hkosd.setSerialNumber(monitor.getSerialNumber()); |
| | | return hkosd; |
| | | } |
| | | //尝试大华的api |
| | | OSDResult dhosd = DHApi.getOsd(monitor.getIp(), DHUserName, DHPassword); |
| | | OSDResult dhosd = DHApi.getOsd(monitor.getSerialNumber(),monitor.getIp(), DHUserName, DHPassword); |
| | | if (dhosd != null) { |
| | | dhosd.setSerialNumber(monitor.getSerialNumber()); |
| | | return dhosd; |