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