订阅大华火情事件

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> <dysmsapi20170525.version>2.0.4</dysmsapi20170525.version>
<hutool-all.version>4.4.3</hutool-all.version> <hutool-all.version>4.4.3</hutool-all.version>
<tus-client.version>0.4.0</tus-client.version> <tus-client.version>0.4.0</tus-client.version>
<!-- ICCSDK版本 -->
<icc.sdk.version>1.0.9</icc.sdk.version>
</properties> </properties>
<dependencies> <dependencies>
@ -94,8 +96,8 @@
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId> mysql</groupId> <groupId>mysql</groupId>
<artifactId> mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.jsonwebtoken</groupId> <groupId>io.jsonwebtoken</groupId>
@ -199,6 +201,36 @@
<artifactId>jedis</artifactId> <artifactId>jedis</artifactId>
<version>3.7.0</version> <version>3.7.0</version>
</dependency> </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> </dependencies>
<build> <build>

View File

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

View File

@ -1,17 +1,17 @@
package com.xkrs.controller; 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.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.EquipmentDao; import com.xkrs.dao.EquipmentDao;
import com.xkrs.dao.FireDao; import com.xkrs.dao.FireDao;
import com.xkrs.model.entity.Fire;
import com.xkrs.service.FireService; 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.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -40,92 +40,137 @@ public class FireController {
/** /**
* 根据设备编号获取火情信息 * 根据设备编号获取火情信息
*
* @param code * @param code
* @return * @return
*/ */
@GetMapping("/getFireInformation") @GetMapping("/getFireInformation")
public String getFireInformation(@RequestParam("code") String code){ public String getFireInformation(@RequestParam("code") String code) {
return fireService.getFireInformation(code); return fireService.getFireInformation(code);
} }
/** /**
* 根据设备编码和时间段查询火情信息 * 根据设备编码和时间段查询火情信息
*
* @param code * @param code
* @param startTime * @param startTime
* @param endTime * @param endTime
* @return * @return
*/ */
@GetMapping("/selectFireBetweenTime") @GetMapping("/selectFireBetweenTime")
public String selectFireBetweenTime(@RequestParam("code") String code, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime){ public String selectFireBetweenTime(@RequestParam("code") String code, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
return fireService.selectFireBetweenTime(code,startTime,endTime); return fireService.selectFireBetweenTime(code, startTime, endTime);
} }
/** /**
* 查询最新的300条火情信息 * 查询最新的300条火情信息
*
* @return * @return
*/ */
@GetMapping("/findThreeHundredData") @GetMapping("/findThreeHundredData")
public String findThreeHundredData(){ public String findThreeHundredData() {
return fireService.findThreeHundredData(); return fireService.findThreeHundredData();
} }
/** /**
* 查询一个月中每一天各个街道的火情数量 * 查询一个月中每一天各个街道的火情数量
*
* @param beginTime * @param beginTime
* @param endTime * @param endTime
* @return * @return
*/ */
@GetMapping("/selectEveryDayCount") @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); List<Map<String, Object>> maps = equipmentDao.selectEveryDayCount(beginTime, endTime);
if(maps == null || maps.size() == 0){ if (maps == null || maps.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"该月暂时没有火情信息!",locale); return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "该月暂时没有火情信息!", locale);
} }
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, maps, locale);
} }
/** /**
* 查询一年中每个月的各个街道的火情数量 * 查询一年中每个月的各个街道的火情数量
*
* @param beginTime * @param beginTime
* @param endTime * @param endTime
* @return * @return
*/ */
@GetMapping("/selectEveryMonthCount") @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); List<Map<String, Object>> maps = equipmentDao.selectEveryMonthCount(beginTime, endTime);
if(maps == null || maps.size() == 0){ if (maps == null || maps.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"该年暂时没有火情信息!",locale); return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "该年暂时没有火情信息!", locale);
} }
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, maps, locale);
} }
/** /**
* 修改火点状态 * 修改火点状态
*
* @param map * @param map
* @return * @return
*/ */
@PostMapping("/updateFireState") @PostMapping("/updateFireState")
public String updateFireState(@RequestBody Map map){ public String updateFireState(@RequestBody Map map) {
String alarmCode = (String) map.get("alarmCode"); String alarmCode = (String) map.get("alarmCode");
return fireService.updateFireState(alarmCode); return fireService.updateFireState(alarmCode);
} }
/** /**
* 查询已处理和未处理的火点的数量 * 查询已处理和未处理的火点的数量
*
* @param street * @param street
* @param month * @param month
* @return * @return
*/ */
@GetMapping("/selectProcessedNum") @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); Map<String, Object> stringObjectMap = fireDao.selectProcessed(street, month);
BigInteger processed = (BigInteger) stringObjectMap.get("processed"); BigInteger processed = (BigInteger) stringObjectMap.get("processed");
Map<String, Object> stringObjectMap1 = fireDao.selectNotProcessed(street, month); Map<String, Object> stringObjectMap1 = fireDao.selectNotProcessed(street, month);
BigInteger notprocessed = (BigInteger) stringObjectMap1.get("notprocessed"); BigInteger notprocessed = (BigInteger) stringObjectMap1.get("notprocessed");
Map<String,Object> map = new HashMap<>(3); Map<String, Object> map = new HashMap<>(3);
map.put("processed",processed); map.put("processed", processed);
map.put("notProcessed",notprocessed); map.put("notProcessed", notprocessed);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale); 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();
}
} }
} }