diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index dc5c74d6..593e5a78 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -153,3 +153,8 @@ aj: # 滑动干扰项(0/1/2) interference-options: 2 + +# 物联平台ip地址 +iot: + address: 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 ebc8c31c..e372e786 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,20 +1,34 @@ package com.zc.business.controller; +import com.alibaba.fastjson.JSON; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; 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; +import com.zc.common.core.httpclient.request.RequestParams; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +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.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 @@ -23,12 +37,15 @@ import java.util.List; */ @Api("设备") @RestController -@RequestMapping("/iot/device") +@RequestMapping("/business/device") public class DcDeviceController extends BaseController { - // + @Resource private IDcDeviceService dcDeviceService; + @Value("${iot.address}") + private String iotAddress; + //*********************************设备增删改查****************************************** /** @@ -113,4 +130,208 @@ public class DcDeviceController extends BaseController { return toAjax(dcDeviceService.removeDevice(ids)); } + + //***********************************物联设备接口************************************** + + /** + * 根据物联设备id获取最新属性数据 + * @param deviceId 物联设备id + * @return 获取属性数据操作结果 + */ + @GetMapping("/properties/latest/{deviceId}") + public AjaxResult getDeviceLatestProperties(@PathVariable @Parameter(description = "设备ID") String deviceId) throws HttpException, IOException { + + OkHttp okHttp = new OkHttp(); + Response response // 请求响应 + = okHttp + .url(iotAddress + "/properties/latest/" + deviceId) // 请求地址 + .get(); // 请求方法 + return JSON.parseObject(response.body().string(), AjaxResult.class); + } + + /** + * 查询设备指定属性列表 + * @param deviceId 设备id + * @param propertyId 属性id + * @param queryParam 查询条件 + * @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 { + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("queryParam", queryParam); + + Response response // 请求响应 + = okHttp + .url(iotAddress + "/properties/history/" + deviceId + "/" + propertyId) // 请求地址 + .data(requestParams) + .get(); // 请求方法 + return JSON.parseObject(response.body().string(), AjaxResult.class); + } + + /** + * 根据物联设备id获取最新属性数据 + * @param deviceId 物联设备id + * @param propertyId 属性id + * @return 获取属性数据操作结果 + */ + @GetMapping("/properties/latest/{deviceId}/{propertyId}") + public AjaxResult getDeviceLatestProperty(@PathVariable @Parameter(description = "设备ID") String deviceId, + @PathVariable @Parameter(description = "属性ID") String propertyId) throws HttpException, IOException { + OkHttp okHttp = new OkHttp(); + Response response // 请求响应 + = okHttp + .url(iotAddress + "/properties/latest/" + deviceId + "/" + propertyId) // 请求地址 + .get(); // 请求方法 + return JSON.parseObject(response.body().string(), AjaxResult.class); + } + + /** + * 获取物联设备实时属性值 + * @param deviceId 物联设备id + * @param propertyId 属性 + * @return 属性实时数据 + */ + @GetMapping("/properties/realtime/{deviceId}/{propertyId}") + public AjaxResult getDeviceRealtimeProperty( + @PathVariable String deviceId, + @PathVariable String propertyId, + @RequestParam Map headers) throws HttpException, IOException { + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("headers", headers); + + Response response // 请求响应 + = okHttp + .url(iotAddress + "/properties/realtime/" + deviceId + "/" + propertyId) // 请求地址 + .data(requestParams) + .get(); // 请求方法 + return JSON.parseObject(response.body().string(), AjaxResult.class); + } + + /** + * 批量获取物联设备实时属性 + * @param deviceId 物联设备id + * @param props 属性id集 + * @return 属性实时数据 + */ + @GetMapping("/properties/realtime/{deviceId}") + public AjaxResult getDeviceRealtimeProperties( + @PathVariable String deviceId, + @ModelAttribute DeviceGetPropertiesOperateRequest props) throws HttpException, IOException { + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("props", props); + + Response response // 请求响应 + = okHttp + .url(iotAddress + "/properties/realtime/" + deviceId) // 请求地址 + .data(requestParams) + .get(); // 请求方法 + return JSON.parseObject(response.body().string(), AjaxResult.class); + } + + /** + * 发送设置属性指令到设备 + * @param deviceId 物联设备id + * @param props 参数 + * @return 设备属性操作结果 + */ + @PostMapping("/properties/setting/{deviceId}") + public AjaxResult setDeviceProperties( + @PathVariable String deviceId, + @RequestBody DeviceOperateRequest> props + ) throws HttpException, IOException { + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("props", props); + + Response response // 请求响应 + = okHttp + .url(iotAddress + "/properties/setting/" + deviceId) // 请求地址 + .data(requestParams) + .post(); // 请求方法 + return JSON.parseObject(response.body().string(), AjaxResult.class); + } + + /** + * 设备功能调用 + * @param deviceId 物联设备id + * @param functionId 功能id + * @param props 调用参数 + * @return 调用结果 + */ + @PostMapping("/functions/{deviceId}/{functionId}") + public AjaxResult invokedFunction( + @PathVariable String deviceId, + @PathVariable String functionId, + @RequestBody Map props) throws HttpException, IOException { + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("props", props); + + Response response // 请求响应 + = okHttp + .url(iotAddress + "/functions/" + deviceId + "/" + functionId) // 请求地址 + .data(requestParams) + .post(); // 请求方法 + return JSON.parseObject(response.body().string(), AjaxResult.class); + + } + + /** + * 查询物联设备事件数据 + * @param deviceId 物联设备id + * @param eventId 事件id + * @param queryParam 查询条件 + * @return 查询事件结果 + */ + @GetMapping("/events/history/{deviceId}/{eventId}") + public AjaxResult queryPagerDeviceEvents( + @PathVariable @Parameter(description = "设备ID") String deviceId, + @PathVariable @Parameter(description = "事件ID") String eventId, + @Parameter(hidden = true) Map queryParam + ) throws HttpException, IOException + { + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("queryParam", queryParam); + + Response response // 请求响应 + = okHttp + .url(iotAddress + "/events/history/" + deviceId + "/" + eventId) // 请求地址 + .data(requestParams) + .get(); // 请求方法 + return JSON.parseObject(response.body().string(), AjaxResult.class); + } + + /** + * 获取物联设备物模型 + * @param id 物联设备id + * @return 更新结果 + */ + @GetMapping(value = "/metadata/{id}") + public AjaxResult getMetadata(@PathVariable String id) throws HttpException, IOException { + + OkHttp okHttp = new OkHttp(); + Response response // 请求响应 + = okHttp + .url(iotAddress + "/metadata/" + id) // 请求地址 + .get(); // 请求方法 + return JSON.parseObject(response.body().string(), AjaxResult.class); + } + } diff --git a/zc-business/src/main/java/com/zc/business/controller/DcFacilityController.java b/zc-business/src/main/java/com/zc/business/controller/DcFacilityController.java index 536ffc7b..b599b859 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcFacilityController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcFacilityController.java @@ -23,7 +23,7 @@ import java.util.List; */ @Api("路网设施") @RestController -@RequestMapping("/iot/facility") +@RequestMapping("/business/facility") public class DcFacilityController extends BaseController { @Resource private IDcFacilityService dcFacilityService; diff --git a/zc-business/src/main/java/com/zc/business/controller/DcProductController.java b/zc-business/src/main/java/com/zc/business/controller/DcProductController.java index b6f21eea..2dc3f686 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcProductController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcProductController.java @@ -23,7 +23,7 @@ import java.util.List; */ @Api("产品") @RestController -@RequestMapping("/iot/product") +@RequestMapping("/business/product") public class DcProductController extends BaseController { @Resource private IDcProductService dcProdurtService; diff --git a/zc-business/src/main/java/com/zc/business/controller/DcRoadController.java b/zc-business/src/main/java/com/zc/business/controller/DcRoadController.java index 344dc8bd..e36926cb 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcRoadController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcRoadController.java @@ -23,7 +23,7 @@ import java.util.List; */ @Api("道路信息") @RestController -@RequestMapping("/iot/road") +@RequestMapping("/business/road") public class DcRoadController extends BaseController { @Resource private IDcRoadService dcRoadService; diff --git a/zc-business/src/main/java/com/zc/business/controller/DcStakeMarkController.java b/zc-business/src/main/java/com/zc/business/controller/DcStakeMarkController.java index 0c4ba362..d51e4b00 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcStakeMarkController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcStakeMarkController.java @@ -23,7 +23,7 @@ import java.util.List; */ @Api("桩号") @RestController -@RequestMapping("/iot/stakeMark") +@RequestMapping("/business/stakeMark") public class DcStakeMarkController extends BaseController { @Resource private IDcStakeMarkService dcStakeMarkService; diff --git a/zc-business/src/main/java/com/zc/business/request/DeviceGetPropertiesOperateRequest.java b/zc-business/src/main/java/com/zc/business/request/DeviceGetPropertiesOperateRequest.java new file mode 100644 index 00000000..5eba945e --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/request/DeviceGetPropertiesOperateRequest.java @@ -0,0 +1,39 @@ +package com.zc.business.request; + +import lombok.*; + +import java.util.List; +import java.util.Map; + +/** + * 设备批量获取属性操作请求参数 + * @author xiepufeng + **/ +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Getter +@Setter +public class DeviceGetPropertiesOperateRequest { + /** + * 设备消息头 + * async true 异步请求,默认 false + * true 不等待消息回复立马 + * 返回前端消息,false等设备 + * 回复消息同时返回前端, + * 前提条件设备会携带消息id + * sendAndForget 发送既不管(true) 默认 false + * 此参数为true时发送消息不 + * 管回复,不能确定消息发送是否 + * 成功,如果设备无法携带 + * 消息id应该把此参数设置为 + * true,为true时可以不设置 + * async参数 + */ + private Map headers; + + /** + * 设备消息体 + */ + private List body; +} diff --git a/zc-business/src/main/java/com/zc/business/request/DeviceOperateRequest.java b/zc-business/src/main/java/com/zc/business/request/DeviceOperateRequest.java new file mode 100644 index 00000000..58512c34 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/request/DeviceOperateRequest.java @@ -0,0 +1,45 @@ +package com.zc.business.request; + +import lombok.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 设备操作请求参数 + * @author xiepufeng + **/ +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Getter +@Setter +public class DeviceOperateRequest { + /** + * 设备消息头 + * async true 异步请求,默认 false + * true 不等待消息回复立马 + * 返回前端消息,false等设备 + * 回复消息同时返回前端, + * 前提条件设备会携带消息id + * sendAndForget 发送既不管(true) 默认 false + * 此参数为true时发送消息不 + * 管回复,不能确定消息发送是否 + * 成功,如果设备无法携带 + * 消息id应该把此参数设置为 + * true,为true时可以不设置 + * async参数 + */ + private Map headers = new HashMap<>(); + + /** + * 设备消息体 + */ + private T body; + + /** + * 设备id + */ + private List deviceIds; +}