From a726fc05188c1b3881d517410a4aad163064960c Mon Sep 17 00:00:00 2001 From: xiepufeng <1072271977@qq.com> Date: Tue, 27 Feb 2024 09:33:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=89=A9=E8=81=94=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0api=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0=E7=89=A9?= =?UTF-8?q?=E8=81=94=E8=AE=BE=E5=A4=87id=E9=9D=9E=E7=A9=BA=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcDeviceController.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index 2b408d49..c70181c8 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -19,6 +19,7 @@ import io.swagger.v3.oas.annotations.Parameter; import okhttp3.Response; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -166,6 +167,10 @@ public class DcDeviceController extends BaseController { @GetMapping("/properties/latest/{deviceId}") public AjaxResult getDeviceLatestProperties(@PathVariable @Parameter(description = "设备ID") String deviceId) throws HttpException, IOException { + if (!StringUtils.hasText(deviceId)) { + return AjaxResult.error("设备未接入"); + } + OkHttp okHttp = new OkHttp(); Response response // 请求响应 = okHttp @@ -187,6 +192,11 @@ public class DcDeviceController extends BaseController { public AjaxResult queryDeviceProperties(@PathVariable @Parameter(description = "设备ID") String deviceId, @PathVariable @Parameter(description = "属性ID") String propertyId, @Parameter(hidden = true) HashMap props) throws HttpException, IOException { + + if (!StringUtils.hasText(deviceId) || !StringUtils.hasText(propertyId)) { + return AjaxResult.error("设备未接入"); + } + OkHttp okHttp = new OkHttp(); RequestParams requestParams = new RequestParams(props); @@ -210,6 +220,11 @@ public class DcDeviceController extends BaseController { @GetMapping("/properties/latest/{deviceId}/{propertyId}") public AjaxResult getDeviceLatestProperty(@PathVariable @Parameter(description = "设备ID") String deviceId, @PathVariable @Parameter(description = "属性ID") String propertyId) throws HttpException, IOException { + + if (!StringUtils.hasText(deviceId) || !StringUtils.hasText(propertyId)) { + return AjaxResult.error("设备未接入"); + } + OkHttp okHttp = new OkHttp(); Response response // 请求响应 = okHttp @@ -232,6 +247,10 @@ public class DcDeviceController extends BaseController { @PathVariable String propertyId, @RequestParam HashMap props) throws HttpException, IOException { + if (!StringUtils.hasText(deviceId) || !StringUtils.hasText(propertyId)) { + return AjaxResult.error("设备未接入"); + } + OkHttp okHttp = new OkHttp(); RequestParams requestParams = new RequestParams(props); @@ -257,6 +276,10 @@ public class DcDeviceController extends BaseController { @PathVariable String deviceId, @RequestBody DeviceGetPropertiesOperateRequest props) throws HttpException, IOException { + if (!StringUtils.hasText(deviceId)) { + return AjaxResult.error("设备未接入"); + } + OkHttp okHttp = new OkHttp(); @@ -286,6 +309,11 @@ public class DcDeviceController extends BaseController { @PathVariable String deviceId, @RequestBody HashMap props ) throws HttpException, IOException { + + if (!StringUtils.hasText(deviceId)) { + return AjaxResult.error("设备未接入"); + } + OkHttp okHttp = new OkHttp(); RequestParams requestParams = new RequestParams(props); @@ -313,6 +341,10 @@ public class DcDeviceController extends BaseController { @PathVariable String functionId, @RequestBody HashMap props) throws HttpException, IOException { + if (!StringUtils.hasText(deviceId) || !StringUtils.hasText(functionId)) { + return AjaxResult.error("设备未接入"); + } + OkHttp okHttp = new OkHttp(); RequestParams requestParams = new RequestParams(props); @@ -343,6 +375,10 @@ public class DcDeviceController extends BaseController { @Parameter(hidden = true) HashMap queryParam ) throws HttpException, IOException { + if (!StringUtils.hasText(deviceId) || !StringUtils.hasText(eventId)) { + return AjaxResult.error("设备未接入"); + } + OkHttp okHttp = new OkHttp(); RequestParams requestParams = new RequestParams(queryParam);