diff --git a/pom.xml b/pom.xml index d0dc1b6..d04332a 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,8 @@ 2.0.4 4.4.3 0.4.0 + + 1.0.9 @@ -190,7 +192,7 @@ org.springframework.boot spring-boot-starter-websocket - provided + @@ -204,6 +206,36 @@ hutool-all ${hutool-all.version} + + + 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/controller/FireEventController.java b/src/main/java/com/xkrs/controller/FireEventController.java new file mode 100644 index 0000000..a3578bf --- /dev/null +++ b/src/main/java/com/xkrs/controller/FireEventController.java @@ -0,0 +1,78 @@ +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 org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Locale; + +import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; + + +/** + * ./start.sh + * sudo tail -f nohup.out + * /home/sxy/server/SmartUrbanRural + */ +@RestController +public class FireEventController { + + Locale locale = LocaleContextHolder.getLocale(); + + /** + * 订阅火情事件 + */ + @GetMapping("/subscribeFireEvent") + public String subscribeFireEvent() { + try { + 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()); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, subscribeResponse, locale); + } catch (Exception e) { + e.printStackTrace(); + } + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "订阅火情事件失败", locale); + } + + /** + * 接收火情事件 + */ + @PostMapping("/receiveFireEvent") + public void receiveFireEvent(@RequestBody Object fireEvent) { + try { + String message = outputEncapsulationObject(PromptMessageEnum.SUCCESS, fireEvent, locale); + System.out.println("----接收火情事件----123" + message); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 查询火情事件 + */ + @GetMapping("/selectFireEvent") + public String selectFireEvent() { +// return fireEventService.selectFireEventList(); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "selectFireEvent", locale); + } + +}