|
|
@ -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<String, Object> 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<String, Object> 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<Map<String, Object>> 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<String, Object> 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<String, Object> 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); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|