| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- package com.zksy.visualization.controller;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.JsonNode;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.zksy.common.core.domain.Result;
- import com.zksy.visualization.config.IccConfigProperty;
- import com.zksy.visualization.domain.request.*;
- import com.zksy.visualization.domain.response.AnalogQuantityResponse;
- import com.zksy.visualization.domain.response.EventStatisticsResponse;
- import com.zksy.visualization.domain.response.FireEquipmentResponse;
- import com.zksy.visualization.domain.response.FirefightingComponentsResponse;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import okhttp3.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.io.IOException;
- /**
- * @author Administrator
- * @version 1.0
- * @project dh-server-micro
- * @description 消防业务
- * @date 2024/12/19 15:17:52
- */
- @RestController
- @Api(tags = "消防业务", description = "消防业务")
- @RequestMapping("/fireFighting")
- @Slf4j
- public class FireFightingController {
- @Autowired
- private OkHttpClient httpClient;
- @Autowired
- private IccConfigProperty iccConfigProperty;
- @Autowired
- private RedisTemplate<String,String> redisTemplate;
- private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
- @ApiOperation(value = "消防物联设备分页查询")
- @PostMapping("/queryFireEquipment")
- public Result queryFireEquipment(FireEquipmentRequest request){
- ObjectMapper objectMapper = new ObjectMapper();
- String jsonParams = null;
- String authorization = redisTemplate
- .opsForValue()
- .get("Authorization:" + iccConfigProperty.getUsername());
- try {
- jsonParams = objectMapper.writeValueAsString(request);
- } catch (JsonProcessingException e) {
- log.error("JSON序列化失败: {}", e);
- return Result.error("请求失败");
- }
- // 创建请求体
- RequestBody body = RequestBody.create(jsonParams, JSON);
- // 构建请求
- Request requestHttp = new Request.Builder()
- .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-fdbu/"+ iccConfigProperty.getVersion() +"/device/subsystem/page")
- .addHeader("Authorization", authorization)
- .post(body)
- .build();
- // 发送请求
- try (Response response = httpClient.newCall(requestHttp).execute()) {
- if (!response.isSuccessful()) {
- return Result.error("请求失败");
- }
- ResponseBody responseBody = response.body();
- if (responseBody != null) {
- String responseString = responseBody.string();
- JsonNode rootNode = objectMapper.readTree(responseString);
- JsonNode success = rootNode.path("success");
- if("true".equals(success.asText())) {
- JsonNode dataNode = rootNode.path("data");
- if (dataNode.isObject()) {
- FireEquipmentResponse fireEquipmentResponse = objectMapper.treeToValue(dataNode, FireEquipmentResponse.class);
- return Result.ok(fireEquipmentResponse);
- } else {
- return Result.ok(null);
- }
- }else {
- return Result.error("消防物联设备分页查询失败");
- }
- }
- } catch (IOException e) {
- log.error("请求失败: {}", e);
- }
- return Result.error("请求失败");
- }
- @ApiOperation(value = "消防探测器分页查询")
- @PostMapping("/analogQuantity")
- public Result analogQuantity(FirefightingComponentsRequest request){
- ObjectMapper objectMapper = new ObjectMapper();
- String jsonParams = null;
- String authorization = redisTemplate
- .opsForValue()
- .get("Authorization:" + iccConfigProperty.getUsername());
- try {
- jsonParams = objectMapper.writeValueAsString(request);
- } catch (JsonProcessingException e) {
- log.error("JSON序列化失败: {}", e);
- return Result.error("请求失败");
- }
- // 创建请求体
- RequestBody body = RequestBody.create(jsonParams, JSON);
- // 构建请求
- Request requestHttp = new Request.Builder()
- .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-fdbu/"+ iccConfigProperty.getVersion() +"/detector/subsystem/page")
- .addHeader("Authorization", authorization)
- .post(body)
- .build();
- // 发送请求
- try (Response response = httpClient.newCall(requestHttp).execute()) {
- if (!response.isSuccessful()) {
- return Result.error("请求失败");
- }
- ResponseBody responseBody = response.body();
- if (responseBody != null) {
- String responseString = responseBody.string();
- JsonNode rootNode = objectMapper.readTree(responseString);
- JsonNode success = rootNode.path("success");
- if("true".equals(success.asText())) {
- JsonNode dataNode = rootNode.path("data");
- if (dataNode.isObject()) {
- FirefightingComponentsResponse firefightingComponentsResponse = objectMapper.treeToValue(dataNode, FirefightingComponentsResponse.class);
- return Result.ok(firefightingComponentsResponse);
- } else {
- return Result.ok(null);
- }
- }else {
- return Result.error("消防探测器分页查询失败");
- }
- }
- } catch (IOException e) {
- log.error("请求失败: {}", e);
- }
- return Result.error("请求失败");
- }
- @ApiOperation(value = "分页查询消防最新模拟量信息")
- @PostMapping("/fireSimulation")
- public Result fireSimulation(AnalogQuantityRequest request){
- ObjectMapper objectMapper = new ObjectMapper();
- String jsonParams = null;
- String authorization = redisTemplate
- .opsForValue()
- .get("Authorization:" + iccConfigProperty.getUsername());
- try {
- jsonParams = objectMapper.writeValueAsString(request);
- } catch (JsonProcessingException e) {
- log.error("JSON序列化失败: {}", e);
- return Result.error("请求失败");
- }
- // 创建请求体
- RequestBody body = RequestBody.create(jsonParams, JSON);
- // 构建请求
- Request requestHttp = new Request.Builder()
- .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-fdbu/"+ iccConfigProperty.getVersion() +"/analog/subsystem/page")
- .addHeader("Authorization", authorization)
- .post(body)
- .build();
- // 发送请求
- try (Response response = httpClient.newCall(requestHttp).execute()) {
- if (!response.isSuccessful()) {
- return Result.error("请求失败");
- }
- ResponseBody responseBody = response.body();
- if (responseBody != null) {
- String responseString = responseBody.string();
- JsonNode rootNode = objectMapper.readTree(responseString);
- JsonNode success = rootNode.path("success");
- if("true".equals(success.asText())) {
- JsonNode dataNode = rootNode.path("data");
- if (dataNode.isObject()) {
- AnalogQuantityResponse analogQuantityResponse = objectMapper.treeToValue(dataNode, AnalogQuantityResponse.class);
- return Result.ok(analogQuantityResponse);
- } else {
- return Result.ok(null);
- }
- }else {
- return Result.error("分页查询消防最新模拟量信息失败");
- }
- }
- } catch (IOException e) {
- log.error("请求失败: {}", e);
- }
- return Result.error("请求失败");
- }
- @ApiOperation(value = "消防事件统计")
- @PostMapping("/queryEventStatistics")
- public Result queryEventStatistics(EventStatisticsRequest request){
- ObjectMapper objectMapper = new ObjectMapper();
- String jsonParams = null;
- String authorization = redisTemplate
- .opsForValue()
- .get("Authorization:" + iccConfigProperty.getUsername());
- try {
- jsonParams = objectMapper.writeValueAsString(request);
- } catch (JsonProcessingException e) {
- log.error("JSON序列化失败: {}", e);
- return Result.error("请求失败");
- }
- // 创建请求体
- RequestBody body = RequestBody.create(jsonParams, JSON);
- // 构建请求
- Request requestHttp = new Request.Builder()
- .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-event/"+ iccConfigProperty.getVersion() +"/alarm-record/count-num")
- .addHeader("Authorization", authorization)
- .post(body)
- .build();
- // 发送请求
- try (Response response = httpClient.newCall(requestHttp).execute()) {
- if (!response.isSuccessful()) {
- return Result.error("请求失败");
- }
- ResponseBody responseBody = response.body();
- if (responseBody != null) {
- String responseString = responseBody.string();
- JsonNode rootNode = objectMapper.readTree(responseString);
- JsonNode success = rootNode.path("success");
- if("true".equals(success.asText())) {
- JsonNode dataNode = rootNode.path("data");
- if (dataNode.isObject()) {
- EventStatisticsResponse fireEquipmentResponse = objectMapper.treeToValue(dataNode, EventStatisticsResponse.class);
- return Result.ok(fireEquipmentResponse);
- } else {
- return Result.ok(null);
- }
- }else {
- return Result.error("消防事件统计失败");
- }
- }
- } catch (IOException e) {
- log.error("请求失败: {}", e);
- }
- return Result.error("请求失败");
- }
- @ApiOperation(value = "alarm事件分页查询")
- @PostMapping("/queryEventStatisticsPage")
- public Result queryEventStatisticsPage(EventStatisticsPageRequest request){
- ObjectMapper objectMapper = new ObjectMapper();
- String jsonParams = null;
- String authorization = redisTemplate
- .opsForValue()
- .get("Authorization:" + iccConfigProperty.getUsername());
- try {
- jsonParams = objectMapper.writeValueAsString(request);
- } catch (JsonProcessingException e) {
- log.error("JSON序列化失败: {}", e);
- return Result.error("请求失败");
- }
- // 创建请求体
- RequestBody body = RequestBody.create(jsonParams, JSON);
- // 构建请求
- Request requestHttp = new Request.Builder()
- .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-event/"+ iccConfigProperty.getVersion() +"/alarm-record/page")
- .addHeader("Authorization", authorization)
- .post(body)
- .build();
- // 发送请求
- try (Response response = httpClient.newCall(requestHttp).execute()) {
- if (!response.isSuccessful()) {
- return Result.error("请求失败");
- }
- ResponseBody responseBody = response.body();
- if (responseBody != null) {
- String responseString = responseBody.string();
- JsonNode rootNode = objectMapper.readTree(responseString);
- JsonNode success = rootNode.path("success");
- if("true".equals(success.asText())) {
- JsonNode dataNode = rootNode.path("data");
- if (dataNode != null) {
- return Result.ok(dataNode);
- } else {
- return Result.ok(null);
- }
- }else {
- return Result.error("消防事件统计失败");
- }
- }
- } catch (IOException e) {
- log.error("请求失败: {}", e);
- }
- return Result.error("请求失败");
- }
- }
|