订阅大华火情事件

This commit is contained in:
liuchengqian 2022-03-04 16:40:48 +08:00
parent b9204a9221
commit 39ea504f16
3 changed files with 102 additions and 24 deletions

32
pom.xml
View File

@ -31,6 +31,8 @@
<dysmsapi20170525.version>2.0.4</dysmsapi20170525.version>
<hutool-all.version>4.4.3</hutool-all.version>
<tus-client.version>0.4.0</tus-client.version>
<!-- ICCSDK版本 -->
<icc.sdk.version>1.0.9</icc.sdk.version>
</properties>
<dependencies>
@ -199,6 +201,36 @@
<artifactId>jedis</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- ICC鉴权 -->
<dependency>
<groupId>com.dahuatech.icc</groupId>
<artifactId>java-sdk-oauth</artifactId>
<version>${icc.sdk.version}</version>
</dependency>
<!-- ICC基础资源SDK -->
<dependency>
<groupId>com.dahuatech.icc</groupId>
<artifactId>java-sdk-brm</artifactId>
<version>${icc.sdk.version}</version>
</dependency>
<!-- ICC 事件中心sdk -->
<dependency>
<groupId>com.dahuatech.icc</groupId>
<artifactId>java-sdk-event</artifactId>
<version>${icc.sdk.version}</version>
</dependency>
<!-- h8900sdk -->
<dependency>
<groupId>com.dahuatech.icc</groupId>
<artifactId>java-sdk-h8900</artifactId>
<version>${icc.sdk.version}</version>
</dependency>
</dependencies>
<build>

View File

@ -6,6 +6,7 @@ import org.springframework.jms.annotation.EnableJms;
/**
* 启动类
*
* @author XinYi Song
**/
@SpringBootApplication

View File

@ -1,17 +1,17 @@
package com.xkrs.controller;
import com.dahuatech.icc.event.model.v202011.EventSubscribeRequest;
import com.dahuatech.icc.event.model.v202011.EventSubscribeResponse;
import com.dahuatech.icc.oauth.http.DefaultClient;
import com.dahuatech.icc.oauth.http.IClient;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.EquipmentDao;
import com.xkrs.dao.FireDao;
import com.xkrs.model.entity.Fire;
import com.xkrs.service.FireService;
import com.xkrs.util.Query;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
@ -40,6 +40,7 @@ public class FireController {
/**
* 根据设备编号获取火情信息
*
* @param code
* @return
*/
@ -50,6 +51,7 @@ public class FireController {
/**
* 根据设备编码和时间段查询火情信息
*
* @param code
* @param startTime
* @param endTime
@ -62,6 +64,7 @@ public class FireController {
/**
* 查询最新的300条火情信息
*
* @return
*/
@GetMapping("/findThreeHundredData")
@ -71,6 +74,7 @@ public class FireController {
/**
* 查询一个月中每一天各个街道的火情数量
*
* @param beginTime
* @param endTime
* @return
@ -86,6 +90,7 @@ public class FireController {
/**
* 查询一年中每个月的各个街道的火情数量
*
* @param beginTime
* @param endTime
* @return
@ -101,6 +106,7 @@ public class FireController {
/**
* 修改火点状态
*
* @param map
* @return
*/
@ -113,6 +119,7 @@ public class FireController {
/**
* 查询已处理和未处理的火点的数量
*
* @param street
* @param month
* @return
@ -128,4 +135,42 @@ public class FireController {
map.put("notProcessed", notprocessed);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale);
}
/**
* 订阅火情事件
*/
@GetMapping("/subscribeFireEvent")
public void subscribeFireEvent() {
try {
//118.24.27.47:6820
String host = "111.53.13.180:4433";
String username = "system";
String password = "Admin@123";
String clientId = "xkrszhcx";
String clientSecret = "eac429df-950a-4cba-aa50-76e47b0a74d8";
System.out.println("----开始执行----{}------事件订阅");
IClient iClient = new DefaultClient(host, username, password, clientId, clientSecret);
EventSubscribeRequest subscribeRequest = new EventSubscribeRequest();
// 接收事件地址
String receiveUrl = "http://118.24.27.47:6820/receiveFireEvent";
String mqinfo = "{\"param\":{\"monitors\":[{\"monitor\":\"" + receiveUrl + "\",\"monitorType\":\"url\",\"events\":[{\"category\":\"business\",\"subscribeAll\":1,\"domainSubscribe\":2,\"authorities\":[{}]},{\"category\":\"alarm\",\"subscribeAll\":1,\"domainSubscribe\":2,\"authorities\":[{}]},{\"category\":\"state\",\"subscribeAll\":1,\"domainSubscribe\":2,\"authorities\":[{}]}]}],\"subsystem\":{\"subsystemType\":0,\"name\":\"118.24.27.47_6820\",\"magic\":\"118.24.27.47_6820\"}}}";
subscribeRequest.body(mqinfo);
EventSubscribeResponse subscribeResponse = iClient.doAction(subscribeRequest, subscribeRequest.getResponseClass());
System.out.println("----结束执行----{}------事件订阅" + subscribeResponse.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 接收火情事件
*/
@PostMapping("/receiveFireEvent")
public void receiveFireEvent(@RequestBody Object fireEvent) {
try {
System.out.println("----接收火情事件----{}------" + fireEvent.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}