RotatingRingController.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package com.zksy.visualization.controller;
  2. import com.fasterxml.jackson.databind.JsonNode;
  3. import com.fasterxml.jackson.databind.ObjectMapper;
  4. import com.zksy.common.core.domain.Result;
  5. import com.zksy.visualization.config.IccConfigProperty;
  6. import com.zksy.visualization.domain.request.ChannelSubtypeRequest;
  7. import com.zksy.visualization.domain.request.RealTimeDataRequest;
  8. import com.zksy.visualization.domain.response.ChannelSubtypeResponse;
  9. import com.zksy.visualization.domain.response.RealTimeDataResponse;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import lombok.extern.slf4j.Slf4j;
  13. import okhttp3.*;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.data.redis.core.RedisTemplate;
  16. import org.springframework.web.bind.annotation.GetMapping;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RestController;
  19. /**
  20. * @author Administrator
  21. * @version 1.0
  22. * @project dh-server-micro
  23. * @description 动环管理
  24. * @date 2024/12/19 16:23:14
  25. */
  26. @RestController
  27. @Api(tags = "动环管理", description = "动环管理")
  28. @RequestMapping("/rotatingRing")
  29. @Slf4j
  30. public class RotatingRingController {
  31. @Autowired
  32. private OkHttpClient httpClient;
  33. @Autowired
  34. private IccConfigProperty iccConfigProperty;
  35. @Autowired
  36. private RedisTemplate<String,String> redisTemplate;
  37. @ApiOperation(value = "通道子类型分页查询")
  38. @GetMapping("/channelSubtype")
  39. public Result ChannelSubtype(ChannelSubtypeRequest channelSubtypeRequest){
  40. String authorization = redisTemplate
  41. .opsForValue()
  42. .get("Authorization:" + iccConfigProperty.getUsername());
  43. HttpUrl url = new HttpUrl.Builder()
  44. .scheme("https")
  45. .host(iccConfigProperty.getHost())
  46. .addPathSegments("/evo-apigw/evo-pmms/dictionary/devChildTypeList")
  47. .addQueryParameter("pageNo", String.valueOf(channelSubtypeRequest.getPageNo()))
  48. .addQueryParameter("pageSize",String.valueOf(channelSubtypeRequest.getPageSize()))
  49. .addQueryParameter("searchKey",String.valueOf(channelSubtypeRequest.getSearchKey()))
  50. .build();
  51. Request request = new Request.Builder()
  52. .url(url)
  53. .addHeader("Authorization", authorization)
  54. .build();
  55. try {
  56. Response response = httpClient.newCall(request).execute();
  57. if(!response.isSuccessful()){
  58. return Result.error("通道子类型分页查询失败");
  59. }
  60. ResponseBody responseBody = response.body();
  61. if (responseBody != null) {
  62. String responseString = responseBody.string();
  63. ObjectMapper objectMapper = new ObjectMapper();
  64. JsonNode rootNode = objectMapper.readTree(responseString);
  65. JsonNode success = rootNode.path("success");
  66. if(success.isBoolean() && success.asBoolean()) {
  67. JsonNode dataNode = rootNode.path("data");
  68. if (dataNode.isObject()) {
  69. ChannelSubtypeResponse channelSubtypeResponse = objectMapper.treeToValue(dataNode, ChannelSubtypeResponse.class);
  70. return Result.ok(channelSubtypeResponse);
  71. } else {
  72. return Result.ok(null);
  73. }
  74. }else{
  75. JsonNode errMsgNode = rootNode.path("errMsg");
  76. String errMsg = errMsgNode.isTextual() ? errMsgNode.asText() : "未知错误";
  77. return Result.error(errMsg);
  78. }
  79. }
  80. } catch (Exception e) {
  81. log.error("通道子类型分页查询失败:{}", e);
  82. }
  83. return Result.error("通道子类型分页查询失败");
  84. }
  85. @ApiOperation(value = "分页查询实时数据信息")
  86. @GetMapping("/realTimeData")
  87. public Result RealTimeData(RealTimeDataRequest realTimeDataRequest){
  88. String authorization = redisTemplate
  89. .opsForValue()
  90. .get("Authorization:" + iccConfigProperty.getUsername());
  91. HttpUrl url = new HttpUrl.Builder()
  92. .scheme("https")
  93. .host(iccConfigProperty.getHost())
  94. .addPathSegments("/evo-apigw/evo-pmms/real/data/nodeId="+realTimeDataRequest.getNodeId()+"" +
  95. "&devChildType="+realTimeDataRequest.getDevChildType()+"&pageNo="+realTimeDataRequest.getPageNo()+"" +
  96. "&pageSize="+realTimeDataRequest.getPageSize())
  97. .build();
  98. Request request = new Request.Builder()
  99. .url(url)
  100. .addHeader("Authorization", authorization)
  101. .build();
  102. try {
  103. Response response = httpClient.newCall(request).execute();
  104. if(!response.isSuccessful()){
  105. return Result.error("分页查询实时数据信息失败");
  106. }
  107. ResponseBody responseBody = response.body();
  108. if (responseBody != null) {
  109. String responseString = responseBody.string();
  110. ObjectMapper objectMapper = new ObjectMapper();
  111. JsonNode rootNode = objectMapper.readTree(responseString);
  112. JsonNode dataNode = rootNode.path("data");
  113. if (dataNode.isObject()) {
  114. RealTimeDataResponse realTimeDataResponse = objectMapper.treeToValue(dataNode, RealTimeDataResponse.class);
  115. return Result.ok(realTimeDataResponse);
  116. } else {
  117. return Result.ok(null);
  118. }
  119. }
  120. } catch (Exception e) {
  121. log.error("分页查询实时数据信息失败:{}", e);
  122. }
  123. return Result.error("分页查询实时数据信息失败");
  124. }
  125. }