|
@@ -1,15 +1,164 @@
|
|
|
package com.zksy.screen.controller;
|
|
package com.zksy.screen.controller;
|
|
|
|
|
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
|
|
+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.screen.domain.request.InvokeBuild;
|
|
|
|
|
+import com.zksy.screen.domain.request.TopWebPage;
|
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import okhttp3.*;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+
|
|
|
@RestController
|
|
@RestController
|
|
|
|
|
+@Api(tags = "灯杆大屏", description = "灯杆大屏")
|
|
|
@RequestMapping("/test")
|
|
@RequestMapping("/test")
|
|
|
|
|
+@Slf4j
|
|
|
public class TestController {
|
|
public class TestController {
|
|
|
-
|
|
|
|
|
- @GetMapping("/a")
|
|
|
|
|
- public String a(){
|
|
|
|
|
- return "性与暴力";
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OkHttpClient httpClient;
|
|
|
|
|
+ private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
|
+ @ApiOperation(value = "清屏,清除顶层网页内容")
|
|
|
|
|
+ @PostMapping("/clearTopWebPage")
|
|
|
|
|
+ public Result clearTopWebPage(@ApiParam(value = "设备编码",required = true) @RequestParam(value = "deviceCode",defaultValue = "")String deviceCode,
|
|
|
|
|
+ @ApiParam(value = "入参类型",required = true) @RequestParam(value = "type",defaultValue = "clear")String type) {
|
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
+ String jsonParams = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ jsonParams = objectMapper.writeValueAsString(type);
|
|
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
|
|
+ log.error("JSON序列化失败: {}", e);
|
|
|
|
|
+ return Result.error("请求失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 创建请求体
|
|
|
|
|
+ RequestBody body = RequestBody.create(jsonParams, JSON);
|
|
|
|
|
+ // 构建请求
|
|
|
|
|
+ Request requestHttp = new Request.Builder()
|
|
|
|
|
+ .url("http://172.16.102.52:8016/command/"+deviceCode)
|
|
|
|
|
+ .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("请求失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ @ApiOperation(value = "加载顶层网页")
|
|
|
|
|
+ @PostMapping("/getTopWebPage")
|
|
|
|
|
+ public Result getTopWebPage(TopWebPage request,@ApiParam(value = "设备编码",required = true) @RequestParam(value = "deviceCode",defaultValue = "") String deviceCode) {
|
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
+ String jsonParams = null;
|
|
|
|
|
+ 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("http://172.16.102.52:8016/command/"+deviceCode)
|
|
|
|
|
+ .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("请求失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ @ApiOperation(value = "滚动文字")
|
|
|
|
|
+ @PostMapping("/getInvokeBuild")
|
|
|
|
|
+ public Result getInvokeBuild(InvokeBuild request,
|
|
|
|
|
+ @ApiParam(value = "设备编码",required = true) @RequestParam(value = "deviceCode",defaultValue = "") String deviceCode) {
|
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
+ String jsonParams = null;
|
|
|
|
|
+ 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("http://172.16.102.52:8016/command/"+deviceCode)
|
|
|
|
|
+ .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("请求失败");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|