FireFightingController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. package com.zksy.visualization.controller;
  2. import com.fasterxml.jackson.core.JsonProcessingException;
  3. import com.fasterxml.jackson.databind.JsonNode;
  4. import com.fasterxml.jackson.databind.ObjectMapper;
  5. import com.zksy.common.core.domain.Result;
  6. import com.zksy.visualization.config.IccConfigProperty;
  7. import com.zksy.visualization.domain.request.*;
  8. import com.zksy.visualization.domain.response.AnalogQuantityResponse;
  9. import com.zksy.visualization.domain.response.EventStatisticsResponse;
  10. import com.zksy.visualization.domain.response.FireEquipmentResponse;
  11. import com.zksy.visualization.domain.response.FirefightingComponentsResponse;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiOperation;
  14. import lombok.extern.slf4j.Slf4j;
  15. import okhttp3.*;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.data.redis.core.RedisTemplate;
  18. import org.springframework.web.bind.annotation.PostMapping;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RestController;
  21. import java.io.IOException;
  22. /**
  23. * @author Administrator
  24. * @version 1.0
  25. * @project dh-server-micro
  26. * @description 消防业务
  27. * @date 2024/12/19 15:17:52
  28. */
  29. @RestController
  30. @Api(tags = "消防业务", description = "消防业务")
  31. @RequestMapping("/fireFighting")
  32. @Slf4j
  33. public class FireFightingController {
  34. @Autowired
  35. private OkHttpClient httpClient;
  36. @Autowired
  37. private IccConfigProperty iccConfigProperty;
  38. @Autowired
  39. private RedisTemplate<String,String> redisTemplate;
  40. private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
  41. @ApiOperation(value = "消防物联设备分页查询")
  42. @PostMapping("/queryFireEquipment")
  43. public Result queryFireEquipment(FireEquipmentRequest request){
  44. ObjectMapper objectMapper = new ObjectMapper();
  45. String jsonParams = null;
  46. String authorization = redisTemplate
  47. .opsForValue()
  48. .get("Authorization:" + iccConfigProperty.getUsername());
  49. try {
  50. jsonParams = objectMapper.writeValueAsString(request);
  51. } catch (JsonProcessingException e) {
  52. log.error("JSON序列化失败: {}", e);
  53. return Result.error("请求失败");
  54. }
  55. // 创建请求体
  56. RequestBody body = RequestBody.create(jsonParams, JSON);
  57. // 构建请求
  58. Request requestHttp = new Request.Builder()
  59. .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-fdbu/"+ iccConfigProperty.getVersion() +"/device/subsystem/page")
  60. .addHeader("Authorization", authorization)
  61. .post(body)
  62. .build();
  63. // 发送请求
  64. try (Response response = httpClient.newCall(requestHttp).execute()) {
  65. if (!response.isSuccessful()) {
  66. return Result.error("请求失败");
  67. }
  68. ResponseBody responseBody = response.body();
  69. if (responseBody != null) {
  70. String responseString = responseBody.string();
  71. JsonNode rootNode = objectMapper.readTree(responseString);
  72. JsonNode success = rootNode.path("success");
  73. if("true".equals(success.asText())) {
  74. JsonNode dataNode = rootNode.path("data");
  75. if (dataNode.isObject()) {
  76. FireEquipmentResponse fireEquipmentResponse = objectMapper.treeToValue(dataNode, FireEquipmentResponse.class);
  77. return Result.ok(fireEquipmentResponse);
  78. } else {
  79. return Result.ok(null);
  80. }
  81. }else {
  82. return Result.error("消防物联设备分页查询失败");
  83. }
  84. }
  85. } catch (IOException e) {
  86. log.error("请求失败: {}", e);
  87. }
  88. return Result.error("请求失败");
  89. }
  90. @ApiOperation(value = "消防探测器分页查询")
  91. @PostMapping("/analogQuantity")
  92. public Result analogQuantity(FirefightingComponentsRequest request){
  93. ObjectMapper objectMapper = new ObjectMapper();
  94. String jsonParams = null;
  95. String authorization = redisTemplate
  96. .opsForValue()
  97. .get("Authorization:" + iccConfigProperty.getUsername());
  98. try {
  99. jsonParams = objectMapper.writeValueAsString(request);
  100. } catch (JsonProcessingException e) {
  101. log.error("JSON序列化失败: {}", e);
  102. return Result.error("请求失败");
  103. }
  104. // 创建请求体
  105. RequestBody body = RequestBody.create(jsonParams, JSON);
  106. // 构建请求
  107. Request requestHttp = new Request.Builder()
  108. .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-fdbu/"+ iccConfigProperty.getVersion() +"/detector/subsystem/page")
  109. .addHeader("Authorization", authorization)
  110. .post(body)
  111. .build();
  112. // 发送请求
  113. try (Response response = httpClient.newCall(requestHttp).execute()) {
  114. if (!response.isSuccessful()) {
  115. return Result.error("请求失败");
  116. }
  117. ResponseBody responseBody = response.body();
  118. if (responseBody != null) {
  119. String responseString = responseBody.string();
  120. JsonNode rootNode = objectMapper.readTree(responseString);
  121. JsonNode success = rootNode.path("success");
  122. if("true".equals(success.asText())) {
  123. JsonNode dataNode = rootNode.path("data");
  124. if (dataNode.isObject()) {
  125. FirefightingComponentsResponse firefightingComponentsResponse = objectMapper.treeToValue(dataNode, FirefightingComponentsResponse.class);
  126. return Result.ok(firefightingComponentsResponse);
  127. } else {
  128. return Result.ok(null);
  129. }
  130. }else {
  131. return Result.error("消防探测器分页查询失败");
  132. }
  133. }
  134. } catch (IOException e) {
  135. log.error("请求失败: {}", e);
  136. }
  137. return Result.error("请求失败");
  138. }
  139. @ApiOperation(value = "分页查询消防最新模拟量信息")
  140. @PostMapping("/fireSimulation")
  141. public Result fireSimulation(AnalogQuantityRequest request){
  142. ObjectMapper objectMapper = new ObjectMapper();
  143. String jsonParams = null;
  144. String authorization = redisTemplate
  145. .opsForValue()
  146. .get("Authorization:" + iccConfigProperty.getUsername());
  147. try {
  148. jsonParams = objectMapper.writeValueAsString(request);
  149. } catch (JsonProcessingException e) {
  150. log.error("JSON序列化失败: {}", e);
  151. return Result.error("请求失败");
  152. }
  153. // 创建请求体
  154. RequestBody body = RequestBody.create(jsonParams, JSON);
  155. // 构建请求
  156. Request requestHttp = new Request.Builder()
  157. .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-fdbu/"+ iccConfigProperty.getVersion() +"/analog/subsystem/page")
  158. .addHeader("Authorization", authorization)
  159. .post(body)
  160. .build();
  161. // 发送请求
  162. try (Response response = httpClient.newCall(requestHttp).execute()) {
  163. if (!response.isSuccessful()) {
  164. return Result.error("请求失败");
  165. }
  166. ResponseBody responseBody = response.body();
  167. if (responseBody != null) {
  168. String responseString = responseBody.string();
  169. JsonNode rootNode = objectMapper.readTree(responseString);
  170. JsonNode success = rootNode.path("success");
  171. if("true".equals(success.asText())) {
  172. JsonNode dataNode = rootNode.path("data");
  173. if (dataNode.isObject()) {
  174. AnalogQuantityResponse analogQuantityResponse = objectMapper.treeToValue(dataNode, AnalogQuantityResponse.class);
  175. return Result.ok(analogQuantityResponse);
  176. } else {
  177. return Result.ok(null);
  178. }
  179. }else {
  180. return Result.error("分页查询消防最新模拟量信息失败");
  181. }
  182. }
  183. } catch (IOException e) {
  184. log.error("请求失败: {}", e);
  185. }
  186. return Result.error("请求失败");
  187. }
  188. @ApiOperation(value = "消防事件统计")
  189. @PostMapping("/queryEventStatistics")
  190. public Result queryEventStatistics(EventStatisticsRequest request){
  191. ObjectMapper objectMapper = new ObjectMapper();
  192. String jsonParams = null;
  193. String authorization = redisTemplate
  194. .opsForValue()
  195. .get("Authorization:" + iccConfigProperty.getUsername());
  196. try {
  197. jsonParams = objectMapper.writeValueAsString(request);
  198. } catch (JsonProcessingException e) {
  199. log.error("JSON序列化失败: {}", e);
  200. return Result.error("请求失败");
  201. }
  202. // 创建请求体
  203. RequestBody body = RequestBody.create(jsonParams, JSON);
  204. // 构建请求
  205. Request requestHttp = new Request.Builder()
  206. .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-event/"+ iccConfigProperty.getVersion() +"/alarm-record/count-num")
  207. .addHeader("Authorization", authorization)
  208. .post(body)
  209. .build();
  210. // 发送请求
  211. try (Response response = httpClient.newCall(requestHttp).execute()) {
  212. if (!response.isSuccessful()) {
  213. return Result.error("请求失败");
  214. }
  215. ResponseBody responseBody = response.body();
  216. if (responseBody != null) {
  217. String responseString = responseBody.string();
  218. JsonNode rootNode = objectMapper.readTree(responseString);
  219. JsonNode success = rootNode.path("success");
  220. if("true".equals(success.asText())) {
  221. JsonNode dataNode = rootNode.path("data");
  222. if (dataNode.isObject()) {
  223. EventStatisticsResponse fireEquipmentResponse = objectMapper.treeToValue(dataNode, EventStatisticsResponse.class);
  224. return Result.ok(fireEquipmentResponse);
  225. } else {
  226. return Result.ok(null);
  227. }
  228. }else {
  229. return Result.error("消防事件统计失败");
  230. }
  231. }
  232. } catch (IOException e) {
  233. log.error("请求失败: {}", e);
  234. }
  235. return Result.error("请求失败");
  236. }
  237. @ApiOperation(value = "alarm事件分页查询")
  238. @PostMapping("/queryEventStatisticsPage")
  239. public Result queryEventStatisticsPage(EventStatisticsPageRequest request){
  240. ObjectMapper objectMapper = new ObjectMapper();
  241. String jsonParams = null;
  242. String authorization = redisTemplate
  243. .opsForValue()
  244. .get("Authorization:" + iccConfigProperty.getUsername());
  245. try {
  246. jsonParams = objectMapper.writeValueAsString(request);
  247. } catch (JsonProcessingException e) {
  248. log.error("JSON序列化失败: {}", e);
  249. return Result.error("请求失败");
  250. }
  251. // 创建请求体
  252. RequestBody body = RequestBody.create(jsonParams, JSON);
  253. // 构建请求
  254. Request requestHttp = new Request.Builder()
  255. .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/evo-event/"+ iccConfigProperty.getVersion() +"/alarm-record/page")
  256. .addHeader("Authorization", authorization)
  257. .post(body)
  258. .build();
  259. // 发送请求
  260. try (Response response = httpClient.newCall(requestHttp).execute()) {
  261. if (!response.isSuccessful()) {
  262. return Result.error("请求失败");
  263. }
  264. ResponseBody responseBody = response.body();
  265. if (responseBody != null) {
  266. String responseString = responseBody.string();
  267. JsonNode rootNode = objectMapper.readTree(responseString);
  268. JsonNode success = rootNode.path("success");
  269. if("true".equals(success.asText())) {
  270. JsonNode dataNode = rootNode.path("data");
  271. if (dataNode != null) {
  272. return Result.ok(dataNode);
  273. } else {
  274. return Result.ok(null);
  275. }
  276. }else {
  277. return Result.error("消防事件统计失败");
  278. }
  279. }
  280. } catch (IOException e) {
  281. log.error("请求失败: {}", e);
  282. }
  283. return Result.error("请求失败");
  284. }
  285. }