|
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.zksy.common.core.domain.Result;
|
|
import com.zksy.common.core.domain.Result;
|
|
|
import com.zksy.visualization.config.IccConfigProperty;
|
|
import com.zksy.visualization.config.IccConfigProperty;
|
|
|
|
|
+import com.zksy.visualization.domain.request.DeviceSwitchRequest;
|
|
|
import com.zksy.visualization.domain.request.IntelligenceSensorRequest;
|
|
import com.zksy.visualization.domain.request.IntelligenceSensorRequest;
|
|
|
import com.zksy.visualization.domain.request.IntelligentPanelRequest;
|
|
import com.zksy.visualization.domain.request.IntelligentPanelRequest;
|
|
|
import com.zksy.visualization.domain.request.SmartSocketRequest;
|
|
import com.zksy.visualization.domain.request.SmartSocketRequest;
|
|
@@ -76,18 +77,16 @@ public class LightingGatewayController {
|
|
|
String responseString = responseBody.string();
|
|
String responseString = responseBody.string();
|
|
|
JsonNode rootNode = objectMapper.readTree(responseString);
|
|
JsonNode rootNode = objectMapper.readTree(responseString);
|
|
|
JsonNode success = rootNode.path("success");
|
|
JsonNode success = rootNode.path("success");
|
|
|
- if(success.isBoolean() && success.asBoolean()) {
|
|
|
|
|
|
|
+ if("true".equals(success.asText())) {
|
|
|
JsonNode dataNode = rootNode.path("data");
|
|
JsonNode dataNode = rootNode.path("data");
|
|
|
- if (dataNode.isObject()) {
|
|
|
|
|
- IntelligentPanelResponse intelligentPanelResponse = objectMapper.treeToValue(dataNode, IntelligentPanelResponse.class);
|
|
|
|
|
- return Result.ok(intelligentPanelResponse);
|
|
|
|
|
|
|
+ if (dataNode != null) {
|
|
|
|
|
+ return Result.ok(dataNode);
|
|
|
} else {
|
|
} else {
|
|
|
return Result.ok(null);
|
|
return Result.ok(null);
|
|
|
}
|
|
}
|
|
|
}else {
|
|
}else {
|
|
|
- JsonNode errMsgNode = rootNode.path("errMsg");
|
|
|
|
|
- String errMsg = errMsgNode.isTextual() ? errMsgNode.asText() : "未知错误";
|
|
|
|
|
- return Result.error(errMsg);
|
|
|
|
|
|
|
+ JsonNode dataNode = rootNode.path("errMsg");
|
|
|
|
|
+ return Result.error(dataNode.asText());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
@@ -95,6 +94,107 @@ public class LightingGatewayController {
|
|
|
}
|
|
}
|
|
|
return Result.error("请求失败");
|
|
return Result.error("请求失败");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "单个设置面板开关")
|
|
|
|
|
+ @PostMapping("/getSinglePanelSwitch")
|
|
|
|
|
+ public Result getSinglePanelSwitch(DeviceSwitchRequest 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-electricity/"+ iccConfigProperty.getVersion() +"/lightingControl/singleSet/panel")
|
|
|
|
|
+ .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 {
|
|
|
|
|
+ JsonNode dataNode = rootNode.path("errMsg");
|
|
|
|
|
+ return Result.error(dataNode.asText());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("请求失败: {}", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.error("请求失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "批量设置面板开关")
|
|
|
|
|
+ @PostMapping("/getBatchPanelSwitch")
|
|
|
|
|
+ public Result getBatchPanelSwitch(DeviceSwitchRequest 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-electricity/"+ iccConfigProperty.getVersion() +"/lightingControl/batchSet/panel")
|
|
|
|
|
+ .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 {
|
|
|
|
|
+ JsonNode dataNode = rootNode.path("errMsg");
|
|
|
|
|
+ return Result.error(dataNode.asText());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("请求失败: {}", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.error("请求失败");
|
|
|
|
|
+ }
|
|
|
|
|
+/*
|
|
|
@ApiOperation(value = "智能插座分页查询")
|
|
@ApiOperation(value = "智能插座分页查询")
|
|
|
@PostMapping("/getSmartSocketPage")
|
|
@PostMapping("/getSmartSocketPage")
|
|
|
public Result getSmartSocketPage(SmartSocketRequest request) {
|
|
public Result getSmartSocketPage(SmartSocketRequest request) {
|
|
@@ -196,6 +296,6 @@ public class LightingGatewayController {
|
|
|
log.error("请求失败: {}", e);
|
|
log.error("请求失败: {}", e);
|
|
|
}
|
|
}
|
|
|
return Result.error("请求失败");
|
|
return Result.error("请求失败");
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
}
|
|
}
|