Browse Source

物联平台对接接口开发

develop
xiepufeng 11 months ago
parent
commit
ff75c349b6
  1. 5
      ruoyi-admin/src/main/resources/application.yml
  2. 225
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  3. 2
      zc-business/src/main/java/com/zc/business/controller/DcFacilityController.java
  4. 2
      zc-business/src/main/java/com/zc/business/controller/DcProductController.java
  5. 2
      zc-business/src/main/java/com/zc/business/controller/DcRoadController.java
  6. 2
      zc-business/src/main/java/com/zc/business/controller/DcStakeMarkController.java
  7. 39
      zc-business/src/main/java/com/zc/business/request/DeviceGetPropertiesOperateRequest.java
  8. 45
      zc-business/src/main/java/com/zc/business/request/DeviceOperateRequest.java

5
ruoyi-admin/src/main/resources/application.yml

@ -153,3 +153,8 @@ aj:
# 滑动干扰项(0/1/2) # 滑动干扰项(0/1/2)
interference-options: 2 interference-options: 2
# 物联平台ip地址
iot:
address: 127.0.0.1:8080

225
zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java

@ -1,20 +1,34 @@
package com.zc.business.controller; package com.zc.business.controller;
import com.alibaba.fastjson.JSON;
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;
import com.ruoyi.common.core.page.TableDataInfo; 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.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.exception.HttpException;
import com.zc.common.core.httpclient.request.RequestParams;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; 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.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.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 设备Controller * 设备Controller
@ -23,12 +37,15 @@ import java.util.List;
*/ */
@Api("设备") @Api("设备")
@RestController @RestController
@RequestMapping("/iot/device") @RequestMapping("/business/device")
public class DcDeviceController extends BaseController { public class DcDeviceController extends BaseController {
//
@Resource @Resource
private IDcDeviceService dcDeviceService; private IDcDeviceService dcDeviceService;
@Value("${iot.address}")
private String iotAddress;
//*********************************设备增删改查****************************************** //*********************************设备增删改查******************************************
/** /**
@ -113,4 +130,208 @@ public class DcDeviceController extends BaseController {
return toAjax(dcDeviceService.removeDevice(ids)); 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);
}
} }

2
zc-business/src/main/java/com/zc/business/controller/DcFacilityController.java

@ -23,7 +23,7 @@ import java.util.List;
*/ */
@Api("路网设施") @Api("路网设施")
@RestController @RestController
@RequestMapping("/iot/facility") @RequestMapping("/business/facility")
public class DcFacilityController extends BaseController { public class DcFacilityController extends BaseController {
@Resource @Resource
private IDcFacilityService dcFacilityService; private IDcFacilityService dcFacilityService;

2
zc-business/src/main/java/com/zc/business/controller/DcProductController.java

@ -23,7 +23,7 @@ import java.util.List;
*/ */
@Api("产品") @Api("产品")
@RestController @RestController
@RequestMapping("/iot/product") @RequestMapping("/business/product")
public class DcProductController extends BaseController { public class DcProductController extends BaseController {
@Resource @Resource
private IDcProductService dcProdurtService; private IDcProductService dcProdurtService;

2
zc-business/src/main/java/com/zc/business/controller/DcRoadController.java

@ -23,7 +23,7 @@ import java.util.List;
*/ */
@Api("道路信息") @Api("道路信息")
@RestController @RestController
@RequestMapping("/iot/road") @RequestMapping("/business/road")
public class DcRoadController extends BaseController { public class DcRoadController extends BaseController {
@Resource @Resource
private IDcRoadService dcRoadService; private IDcRoadService dcRoadService;

2
zc-business/src/main/java/com/zc/business/controller/DcStakeMarkController.java

@ -23,7 +23,7 @@ import java.util.List;
*/ */
@Api("桩号") @Api("桩号")
@RestController @RestController
@RequestMapping("/iot/stakeMark") @RequestMapping("/business/stakeMark")
public class DcStakeMarkController extends BaseController { public class DcStakeMarkController extends BaseController {
@Resource @Resource
private IDcStakeMarkService dcStakeMarkService; private IDcStakeMarkService dcStakeMarkService;

39
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<String, Object> headers;
/**
* 设备消息体
*/
private List<String> body;
}

45
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<T> {
/**
* 设备消息头
* async true 异步请求默认 false
* true 不等待消息回复立马
* 返回前端消息false等设备
* 回复消息同时返回前端
* 前提条件设备会携带消息id
* sendAndForget 发送既不管(true) 默认 false
* 此参数为true时发送消息不
* 管回复不能确定消息发送是否
* 成功如果设备无法携带
* 消息id应该把此参数设置为
* true,为true时可以不设置
* async参数
*/
private Map<String, Object> headers = new HashMap<>();
/**
* 设备消息体
*/
private T body;
/**
* 设备id
*/
private List<String> deviceIds;
}
Loading…
Cancel
Save