diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 593e5a78..192c04f7 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -156,5 +156,5 @@ aj: # 物联平台ip地址 iot: - address: 127.0.0.1:8080 + address: http://127.0.0.1:8080 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 e372e786..871475b3 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 @@ -1,6 +1,7 @@ package com.zc.business.controller; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; @@ -8,7 +9,6 @@ import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.zc.business.domain.DcDevice; import com.zc.business.request.DeviceGetPropertiesOperateRequest; -import com.zc.business.request.DeviceOperateRequest; import com.zc.business.service.IDcDeviceService; import com.zc.common.core.httpclient.OkHttp; import com.zc.common.core.httpclient.exception.HttpException; @@ -20,15 +20,12 @@ import okhttp3.Response; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; import javax.annotation.Resource; import javax.validation.Valid; import java.io.IOException; import java.util.HashMap; import java.util.List; -import java.util.Map; /** * 设备Controller @@ -135,6 +132,7 @@ public class DcDeviceController extends BaseController { /** * 根据物联设备id获取最新属性数据 + * * @param deviceId 物联设备id * @return 获取属性数据操作结果 */ @@ -144,30 +142,30 @@ public class DcDeviceController extends BaseController { OkHttp okHttp = new OkHttp(); Response response // 请求响应 = okHttp - .url(iotAddress + "/properties/latest/" + deviceId) // 请求地址 + .url(iotAddress + "/api/iot/device/properties/latest/" + deviceId) // 请求地址 .get(); // 请求方法 return JSON.parseObject(response.body().string(), AjaxResult.class); } /** * 查询设备指定属性列表 - * @param deviceId 设备id + * + * @param deviceId 设备id * @param propertyId 属性id - * @param queryParam 查询条件 + * @param props 查询条件 * @return 属性列表 */ @GetMapping("/properties/history/{deviceId}/{propertyId}") public AjaxResult queryDeviceProperties(@PathVariable @Parameter(description = "设备ID") String deviceId, @PathVariable @Parameter(description = "属性ID") String propertyId, - @Parameter(hidden = true) Map queryParam) throws HttpException, IOException { + @Parameter(hidden = true) HashMap props) throws HttpException, IOException { OkHttp okHttp = new OkHttp(); - RequestParams requestParams = new RequestParams(); - requestParams.put("queryParam", queryParam); + RequestParams requestParams = new RequestParams(props); Response response // 请求响应 = okHttp - .url(iotAddress + "/properties/history/" + deviceId + "/" + propertyId) // 请求地址 + .url(iotAddress + "/api/iot/device/properties/history/" + deviceId + "/" + propertyId) // 请求地址 .data(requestParams) .get(); // 请求方法 return JSON.parseObject(response.body().string(), AjaxResult.class); @@ -175,7 +173,8 @@ public class DcDeviceController extends BaseController { /** * 根据物联设备id获取最新属性数据 - * @param deviceId 物联设备id + * + * @param deviceId 物联设备id * @param propertyId 属性id * @return 获取属性数据操作结果 */ @@ -185,14 +184,15 @@ public class DcDeviceController extends BaseController { OkHttp okHttp = new OkHttp(); Response response // 请求响应 = okHttp - .url(iotAddress + "/properties/latest/" + deviceId + "/" + propertyId) // 请求地址 + .url(iotAddress + "/api/iot/device/properties/latest/" + deviceId + "/" + propertyId) // 请求地址 .get(); // 请求方法 return JSON.parseObject(response.body().string(), AjaxResult.class); } /** * 获取物联设备实时属性值 - * @param deviceId 物联设备id + * + * @param deviceId 物联设备id * @param propertyId 属性 * @return 属性实时数据 */ @@ -200,16 +200,15 @@ public class DcDeviceController extends BaseController { public AjaxResult getDeviceRealtimeProperty( @PathVariable String deviceId, @PathVariable String propertyId, - @RequestParam Map headers) throws HttpException, IOException { + @RequestParam HashMap props) throws HttpException, IOException { OkHttp okHttp = new OkHttp(); - RequestParams requestParams = new RequestParams(); - requestParams.put("headers", headers); + RequestParams requestParams = new RequestParams(props); Response response // 请求响应 = okHttp - .url(iotAddress + "/properties/realtime/" + deviceId + "/" + propertyId) // 请求地址 + .url(iotAddress + "/api/iot/device/properties/realtime/" + deviceId + "/" + propertyId) // 请求地址 .data(requestParams) .get(); // 请求方法 return JSON.parseObject(response.body().string(), AjaxResult.class); @@ -217,47 +216,51 @@ public class DcDeviceController extends BaseController { /** * 批量获取物联设备实时属性 + * * @param deviceId 物联设备id - * @param props 属性id集 + * @param props 属性id集 * @return 属性实时数据 */ - @GetMapping("/properties/realtime/{deviceId}") + @PostMapping("/properties/realtime/{deviceId}") public AjaxResult getDeviceRealtimeProperties( @PathVariable String deviceId, - @ModelAttribute DeviceGetPropertiesOperateRequest props) throws HttpException, IOException { + @RequestBody DeviceGetPropertiesOperateRequest props) throws HttpException, IOException { OkHttp okHttp = new OkHttp(); - RequestParams requestParams = new RequestParams(); - requestParams.put("props", props); + + String string = JSON.toJSONString(props); + JSONObject jsonObject = JSON.parseObject(string); + RequestParams requestParams = new RequestParams(jsonObject); + Response response // 请求响应 = okHttp - .url(iotAddress + "/properties/realtime/" + deviceId) // 请求地址 + .url(iotAddress + "/api/iot/device/properties/realtime/" + deviceId) // 请求地址 .data(requestParams) - .get(); // 请求方法 + .post(); // 请求方法 return JSON.parseObject(response.body().string(), AjaxResult.class); } /** * 发送设置属性指令到设备 + * * @param deviceId 物联设备id - * @param props 参数 + * @param props 参数 * @return 设备属性操作结果 */ @PostMapping("/properties/setting/{deviceId}") public AjaxResult setDeviceProperties( @PathVariable String deviceId, - @RequestBody DeviceOperateRequest> props + @RequestBody HashMap props ) throws HttpException, IOException { OkHttp okHttp = new OkHttp(); - RequestParams requestParams = new RequestParams(); - requestParams.put("props", props); + RequestParams requestParams = new RequestParams(props); Response response // 请求响应 = okHttp - .url(iotAddress + "/properties/setting/" + deviceId) // 请求地址 + .url(iotAddress + "/api/iot/device/properties/setting/" + deviceId) // 请求地址 .data(requestParams) .post(); // 请求方法 return JSON.parseObject(response.body().string(), AjaxResult.class); @@ -265,25 +268,26 @@ public class DcDeviceController extends BaseController { /** * 设备功能调用 - * @param deviceId 物联设备id + * + * @param deviceId 物联设备id * @param functionId 功能id - * @param props 调用参数 + * @param props 调用参数 * @return 调用结果 */ @PostMapping("/functions/{deviceId}/{functionId}") public AjaxResult invokedFunction( @PathVariable String deviceId, @PathVariable String functionId, - @RequestBody Map props) throws HttpException, IOException { + @RequestBody HashMap props) throws HttpException, IOException { OkHttp okHttp = new OkHttp(); - RequestParams requestParams = new RequestParams(); - requestParams.put("props", props); + RequestParams requestParams = new RequestParams(props); + Response response // 请求响应 = okHttp - .url(iotAddress + "/functions/" + deviceId + "/" + functionId) // 请求地址 + .url(iotAddress + "/api/iot/device/functions/" + deviceId + "/" + functionId) // 请求地址 .data(requestParams) .post(); // 请求方法 return JSON.parseObject(response.body().string(), AjaxResult.class); @@ -292,8 +296,9 @@ public class DcDeviceController extends BaseController { /** * 查询物联设备事件数据 - * @param deviceId 物联设备id - * @param eventId 事件id + * + * @param deviceId 物联设备id + * @param eventId 事件id * @param queryParam 查询条件 * @return 查询事件结果 */ @@ -301,18 +306,16 @@ public class DcDeviceController extends BaseController { public AjaxResult queryPagerDeviceEvents( @PathVariable @Parameter(description = "设备ID") String deviceId, @PathVariable @Parameter(description = "事件ID") String eventId, - @Parameter(hidden = true) Map queryParam - ) throws HttpException, IOException - { + @Parameter(hidden = true) HashMap queryParam + ) throws HttpException, IOException { OkHttp okHttp = new OkHttp(); - RequestParams requestParams = new RequestParams(); - requestParams.put("queryParam", queryParam); + RequestParams requestParams = new RequestParams(queryParam); Response response // 请求响应 = okHttp - .url(iotAddress + "/events/history/" + deviceId + "/" + eventId) // 请求地址 + .url(iotAddress + "/api/iot/device/events/history/" + deviceId + "/" + eventId) // 请求地址 .data(requestParams) .get(); // 请求方法 return JSON.parseObject(response.body().string(), AjaxResult.class); @@ -320,6 +323,7 @@ public class DcDeviceController extends BaseController { /** * 获取物联设备物模型 + * * @param id 物联设备id * @return 更新结果 */ @@ -329,7 +333,7 @@ public class DcDeviceController extends BaseController { OkHttp okHttp = new OkHttp(); Response response // 请求响应 = okHttp - .url(iotAddress + "/metadata/" + id) // 请求地址 + .url(iotAddress + "/api/iot/device/metadata/" + id) // 请求地址 .get(); // 请求方法 return JSON.parseObject(response.body().string(), AjaxResult.class); }