订阅大华火情事件

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

36
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>
@ -94,8 +96,8 @@
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId> mysql</groupId>
<artifactId> mysql-connector-java</artifactId>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
@ -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,92 +40,137 @@ public class FireController {
/**
* 根据设备编号获取火情信息
*
* @param code
* @return
*/
@GetMapping("/getFireInformation")
public String getFireInformation(@RequestParam("code") String code){
public String getFireInformation(@RequestParam("code") String code) {
return fireService.getFireInformation(code);
}
/**
* 根据设备编码和时间段查询火情信息
*
* @param code
* @param startTime
* @param endTime
* @return
*/
@GetMapping("/selectFireBetweenTime")
public String selectFireBetweenTime(@RequestParam("code") String code, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime){
return fireService.selectFireBetweenTime(code,startTime,endTime);
public String selectFireBetweenTime(@RequestParam("code") String code, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
return fireService.selectFireBetweenTime(code, startTime, endTime);
}
/**
* 查询最新的300条火情信息
*
* @return
*/
@GetMapping("/findThreeHundredData")
public String findThreeHundredData(){
public String findThreeHundredData() {
return fireService.findThreeHundredData();
}
/**
* 查询一个月中每一天各个街道的火情数量
*
* @param beginTime
* @param endTime
* @return
*/
@GetMapping("/selectEveryDayCount")
public String selectEveryDayCount(@RequestParam("beginTime") String beginTime,@RequestParam("endTime") String endTime){
public String selectEveryDayCount(@RequestParam("beginTime") String beginTime, @RequestParam("endTime") String endTime) {
List<Map<String, Object>> maps = equipmentDao.selectEveryDayCount(beginTime, endTime);
if(maps == null || maps.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"该月暂时没有火情信息!",locale);
if (maps == null || maps.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "该月暂时没有火情信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, maps, locale);
}
/**
* 查询一年中每个月的各个街道的火情数量
*
* @param beginTime
* @param endTime
* @return
*/
@GetMapping("/selectEveryMonthCount")
public String selectEveryMonthCount(@RequestParam("beginTime") String beginTime,@RequestParam("endTime") String endTime){
public String selectEveryMonthCount(@RequestParam("beginTime") String beginTime, @RequestParam("endTime") String endTime) {
List<Map<String, Object>> maps = equipmentDao.selectEveryMonthCount(beginTime, endTime);
if(maps == null || maps.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"该年暂时没有火情信息!",locale);
if (maps == null || maps.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "该年暂时没有火情信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, maps, locale);
}
/**
* 修改火点状态
*
* @param map
* @return
*/
@PostMapping("/updateFireState")
public String updateFireState(@RequestBody Map map){
public String updateFireState(@RequestBody Map map) {
String alarmCode = (String) map.get("alarmCode");
return fireService.updateFireState(alarmCode);
}
/**
* 查询已处理和未处理的火点的数量
*
* @param street
* @param month
* @return
*/
@GetMapping("/selectProcessedNum")
public String selectProcessedNum(@RequestParam("street") String street,@RequestParam("month") String month){
public String selectProcessedNum(@RequestParam("street") String street, @RequestParam("month") String month) {
Map<String, Object> stringObjectMap = fireDao.selectProcessed(street, month);
BigInteger processed = (BigInteger) stringObjectMap.get("processed");
Map<String, Object> stringObjectMap1 = fireDao.selectNotProcessed(street, month);
BigInteger notprocessed = (BigInteger) stringObjectMap1.get("notprocessed");
Map<String,Object> map = new HashMap<>(3);
map.put("processed",processed);
map.put("notProcessed",notprocessed);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale);
Map<String, Object> map = new HashMap<>(3);
map.put("processed", processed);
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();
}
}
}