|
|
|
|
@ -6,25 +6,26 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
|
import com.sun.jna.Native; |
|
|
|
|
import com.sun.jna.Pointer; |
|
|
|
|
import com.sun.jna.ptr.IntByReference; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.httpclient.HttpClient; |
|
|
|
|
import org.springblade.hospital.hik.CommonMethod.osSelect; |
|
|
|
|
import org.springblade.hospital.hik.NetSDKDemo.HCNetSDK; |
|
|
|
|
import org.springblade.hospital.newalarm.communicationCom.HTTPClientUtil; |
|
|
|
|
import org.springblade.hospital.utils.CornJobUtil; |
|
|
|
|
import org.springblade.hospital.utils.ExternalUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.boot.CommandLineRunner; |
|
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Scanner; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.ScheduledFuture; |
|
|
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author AAA |
|
|
|
|
*/ |
|
|
|
|
@Slf4j |
|
|
|
|
@Component |
|
|
|
|
public class Alarm implements CommandLineRunner { |
|
|
|
|
|
|
|
|
|
@ -41,6 +42,8 @@ public class Alarm implements CommandLineRunner { |
|
|
|
|
public static Map<String, String> portMap; |
|
|
|
|
public static Map<String, String> macMap; |
|
|
|
|
|
|
|
|
|
public static ScheduledThreadPoolExecutor scheduled = new ScheduledThreadPoolExecutor(10); |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
ExternalUtils externalUtils; |
|
|
|
|
|
|
|
|
|
@ -484,57 +487,26 @@ public class Alarm implements CommandLineRunner { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 物联网平台获取报警主机设备信息
|
|
|
|
|
List<Map> list = externalUtils.getList(0, 0, null, null, "105", null); |
|
|
|
|
|
|
|
|
|
// 物联网平台获取的报警主机列表
|
|
|
|
|
if (CollectionUtils.isNotEmpty(list)) { |
|
|
|
|
HTTPClientUtil clientUtil = new HTTPClientUtil(); |
|
|
|
|
for (Map map : list) { |
|
|
|
|
// System.out.println(map.get("tags"));
|
|
|
|
|
String s = JSON.toJSONString(map.get("tags")).replace("\\", ""); |
|
|
|
|
s = s.substring(1, s.length() - 1); |
|
|
|
|
Map tagsMap = JSONObject.parseObject(s, Map.class); |
|
|
|
|
|
|
|
|
|
// 报警主机信息
|
|
|
|
|
String number = tagsMap.get("hostNumber").toString();//序列号
|
|
|
|
|
String ip = tagsMap.get("ip").toString(); |
|
|
|
|
String port = tagsMap.get("port").toString(); |
|
|
|
|
String mac = tagsMap.get("mac").toString(); |
|
|
|
|
|
|
|
|
|
HttpClient client = new HttpClient(); |
|
|
|
|
clientMap.put(number, client); |
|
|
|
|
ipMap.put(number, ip); |
|
|
|
|
portMap.put(number, port); |
|
|
|
|
macMap.put(mac, number); |
|
|
|
|
|
|
|
|
|
new Thread(() -> { |
|
|
|
|
// 登录认证
|
|
|
|
|
String rzUrl = "http://" + ip + ":" + port + "/ISAPI/System/deviceInfo"; |
|
|
|
|
String renzheng = HTTPClientUtil.renzheng(rzUrl, client); |
|
|
|
|
System.out.println("登录信息:" + renzheng); |
|
|
|
|
|
|
|
|
|
if (renzheng.contains(number)) { |
|
|
|
|
// 获取设备系统能力集
|
|
|
|
|
String jtUrl = "http://" + ip + ":" + port + "/ISAPI/System/capabilities"; |
|
|
|
|
HTTPClientUtil.doGet(jtUrl, client); |
|
|
|
|
|
|
|
|
|
// 获取布防订阅能力
|
|
|
|
|
String strUrl = "http://" + ip + ":" + port + "/ISAPI/Event/notification/subscribeEventCap"; |
|
|
|
|
HTTPClientUtil.doGet(strUrl, client); |
|
|
|
|
|
|
|
|
|
// 建立布防订阅连接
|
|
|
|
|
String jlUrl = "http://" + ip + ":" + port + "/ISAPI/Event/notification/subscribeEvent?deployID=1"; |
|
|
|
|
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + |
|
|
|
|
"\n" + |
|
|
|
|
"<SubscribeEvent xmlns=\"http://www.isapi.org/ver20/XMLSchema\" version=\"2.0\">\n" + |
|
|
|
|
" <heartbeat>1</heartbeat>\n" + |
|
|
|
|
" <eventMode>all</eventMode>\n" + |
|
|
|
|
"</SubscribeEvent>"; |
|
|
|
|
System.out.println("jl:" + clientUtil.doPost(jlUrl, xml, number, client, mac)); |
|
|
|
|
AtomicInteger size = new AtomicInteger(0); |
|
|
|
|
List<Thread> threadList = new ArrayList<>(); |
|
|
|
|
ScheduledFuture<?> scheduledFuture = scheduled.scheduleAtFixedRate(() -> { |
|
|
|
|
List<Map> list = externalUtils.getList(0, 0, null, null, "105", null); |
|
|
|
|
log.info("获取报警主机列表数量为:" + list.size()); |
|
|
|
|
if(list.size() != size.get()){ |
|
|
|
|
size.set(list.size()); |
|
|
|
|
if(threadList.size() > 0){ |
|
|
|
|
for(Thread thread : threadList){ |
|
|
|
|
thread.interrupt(); |
|
|
|
|
} |
|
|
|
|
}).start(); |
|
|
|
|
} |
|
|
|
|
threadList.clear(); |
|
|
|
|
// 物联网平台获取的报警主机列表
|
|
|
|
|
getList(list,threadList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, 0, 1, TimeUnit.DAYS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
@ -635,4 +607,57 @@ public class Alarm implements CommandLineRunner { |
|
|
|
|
// //释放SDK
|
|
|
|
|
// hCNetSDK.NET_DVR_Cleanup();
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void getList(List<Map> list,List<Thread> threadList){ |
|
|
|
|
if (CollectionUtils.isNotEmpty(list)) { |
|
|
|
|
HTTPClientUtil clientUtil = new HTTPClientUtil(); |
|
|
|
|
for (Map map : list) { |
|
|
|
|
// System.out.println(map.get("tags"));
|
|
|
|
|
String s = JSON.toJSONString(map.get("tags")).replace("\\", ""); |
|
|
|
|
s = s.substring(1, s.length() - 1); |
|
|
|
|
Map tagsMap = JSONObject.parseObject(s, Map.class); |
|
|
|
|
|
|
|
|
|
// 报警主机信息
|
|
|
|
|
String number = tagsMap.get("hostNumber").toString();//序列号
|
|
|
|
|
String ip = tagsMap.get("ip").toString(); |
|
|
|
|
String port = tagsMap.get("port").toString(); |
|
|
|
|
String mac = tagsMap.get("mac").toString(); |
|
|
|
|
|
|
|
|
|
HttpClient client = new HttpClient(); |
|
|
|
|
clientMap.put(number, client); |
|
|
|
|
ipMap.put(number, ip); |
|
|
|
|
portMap.put(number, port); |
|
|
|
|
macMap.put(mac, number); |
|
|
|
|
|
|
|
|
|
Thread thread = new Thread(() -> { |
|
|
|
|
// 登录认证
|
|
|
|
|
String rzUrl = "http://" + ip + ":" + port + "/ISAPI/System/deviceInfo"; |
|
|
|
|
String renzheng = HTTPClientUtil.renzheng(rzUrl, client); |
|
|
|
|
System.out.println("登录信息:" + renzheng); |
|
|
|
|
|
|
|
|
|
if (renzheng.contains(number)) { |
|
|
|
|
// 获取设备系统能力集
|
|
|
|
|
String jtUrl = "http://" + ip + ":" + port + "/ISAPI/System/capabilities"; |
|
|
|
|
HTTPClientUtil.doGet(jtUrl, client); |
|
|
|
|
|
|
|
|
|
// 获取布防订阅能力
|
|
|
|
|
String strUrl = "http://" + ip + ":" + port + "/ISAPI/Event/notification/subscribeEventCap"; |
|
|
|
|
HTTPClientUtil.doGet(strUrl, client); |
|
|
|
|
|
|
|
|
|
// 建立布防订阅连接
|
|
|
|
|
String jlUrl = "http://" + ip + ":" + port + "/ISAPI/Event/notification/subscribeEvent?deployID=1"; |
|
|
|
|
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + |
|
|
|
|
"\n" + |
|
|
|
|
"<SubscribeEvent xmlns=\"http://www.isapi.org/ver20/XMLSchema\" version=\"2.0\">\n" + |
|
|
|
|
" <heartbeat>1</heartbeat>\n" + |
|
|
|
|
" <eventMode>all</eventMode>\n" + |
|
|
|
|
"</SubscribeEvent>"; |
|
|
|
|
System.out.println("jl:" + clientUtil.doPost(jlUrl, xml, number, client, mac)); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
thread.start(); |
|
|
|
|
threadList.add(thread); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|