From 39ea504f164a5491596501af50343ba864177876 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Fri, 4 Mar 2022 16:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E9=98=85=E5=A4=A7=E5=8D=8E=E7=81=AB?= =?UTF-8?q?=E6=83=85=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 36 +++++++- .../com/xkrs/SmartUrbanRuralApplication.java | 1 + .../com/xkrs/controller/FireController.java | 89 ++++++++++++++----- 3 files changed, 102 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 1251320..46d070f 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,8 @@ 2.0.4 4.4.3 0.4.0 + + 1.0.9 @@ -94,8 +96,8 @@ postgresql - mysql - mysql-connector-java + mysql + mysql-connector-java io.jsonwebtoken @@ -199,6 +201,36 @@ jedis 3.7.0 + + + org.projectlombok + lombok + true + + + + com.dahuatech.icc + java-sdk-oauth + ${icc.sdk.version} + + + + com.dahuatech.icc + java-sdk-brm + ${icc.sdk.version} + + + + com.dahuatech.icc + java-sdk-event + ${icc.sdk.version} + + + + com.dahuatech.icc + java-sdk-h8900 + ${icc.sdk.version} + diff --git a/src/main/java/com/xkrs/SmartUrbanRuralApplication.java b/src/main/java/com/xkrs/SmartUrbanRuralApplication.java index bb6377e..7fedc13 100644 --- a/src/main/java/com/xkrs/SmartUrbanRuralApplication.java +++ b/src/main/java/com/xkrs/SmartUrbanRuralApplication.java @@ -6,6 +6,7 @@ import org.springframework.jms.annotation.EnableJms; /** * 启动类 + * * @author XinYi Song **/ @SpringBootApplication diff --git a/src/main/java/com/xkrs/controller/FireController.java b/src/main/java/com/xkrs/controller/FireController.java index 5ca617b..9559f50 100644 --- a/src/main/java/com/xkrs/controller/FireController.java +++ b/src/main/java/com/xkrs/controller/FireController.java @@ -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> 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> 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 stringObjectMap = fireDao.selectProcessed(street, month); BigInteger processed = (BigInteger) stringObjectMap.get("processed"); Map stringObjectMap1 = fireDao.selectNotProcessed(street, month); BigInteger notprocessed = (BigInteger) stringObjectMap1.get("notprocessed"); - Map map = new HashMap<>(3); - map.put("processed",processed); - map.put("notProcessed",notprocessed); - return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale); + Map 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(); + } } }