Browse Source

Merge remote-tracking branch 'origin/develop' into develop

develop
mengff 10 months ago
parent
commit
3c46852fe7
  1. 9
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  2. 23
      zc-business/src/main/java/com/zc/business/message/device/OfflineMessageListener.java

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

@ -136,6 +136,7 @@ public class DcDeviceController extends BaseController {
* @param deviceId 物联设备id * @param deviceId 物联设备id
* @return 获取属性数据操作结果 * @return 获取属性数据操作结果
*/ */
@ApiOperation("获取设备最新属性数据")
@GetMapping("/properties/latest/{deviceId}") @GetMapping("/properties/latest/{deviceId}")
public AjaxResult getDeviceLatestProperties(@PathVariable @Parameter(description = "设备ID") String deviceId) throws HttpException, IOException { public AjaxResult getDeviceLatestProperties(@PathVariable @Parameter(description = "设备ID") String deviceId) throws HttpException, IOException {
@ -155,6 +156,7 @@ public class DcDeviceController extends BaseController {
* @param props 查询条件 * @param props 查询条件
* @return 属性列表 * @return 属性列表
*/ */
@ApiOperation("获取设备历史属性列表")
@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,
@ -178,6 +180,7 @@ public class DcDeviceController extends BaseController {
* @param propertyId 属性id * @param propertyId 属性id
* @return 获取属性数据操作结果 * @return 获取属性数据操作结果
*/ */
@ApiOperation("获取设备指定属性最新数据")
@GetMapping("/properties/latest/{deviceId}/{propertyId}") @GetMapping("/properties/latest/{deviceId}/{propertyId}")
public AjaxResult getDeviceLatestProperty(@PathVariable @Parameter(description = "设备ID") String deviceId, public AjaxResult getDeviceLatestProperty(@PathVariable @Parameter(description = "设备ID") String deviceId,
@PathVariable @Parameter(description = "属性ID") String propertyId) throws HttpException, IOException { @PathVariable @Parameter(description = "属性ID") String propertyId) throws HttpException, IOException {
@ -196,6 +199,7 @@ public class DcDeviceController extends BaseController {
* @param propertyId 属性 * @param propertyId 属性
* @return 属性实时数据 * @return 属性实时数据
*/ */
@ApiOperation("获取设备指定属性实时数据")
@GetMapping("/properties/realtime/{deviceId}/{propertyId}") @GetMapping("/properties/realtime/{deviceId}/{propertyId}")
public AjaxResult getDeviceRealtimeProperty( public AjaxResult getDeviceRealtimeProperty(
@PathVariable String deviceId, @PathVariable String deviceId,
@ -221,6 +225,7 @@ public class DcDeviceController extends BaseController {
* @param props 属性id集 * @param props 属性id集
* @return 属性实时数据 * @return 属性实时数据
*/ */
@ApiOperation("获取设备属性实时数据")
@PostMapping("/properties/realtime/{deviceId}") @PostMapping("/properties/realtime/{deviceId}")
public AjaxResult getDeviceRealtimeProperties( public AjaxResult getDeviceRealtimeProperties(
@PathVariable String deviceId, @PathVariable String deviceId,
@ -249,6 +254,7 @@ public class DcDeviceController extends BaseController {
* @param props 参数 * @param props 参数
* @return 设备属性操作结果 * @return 设备属性操作结果
*/ */
@ApiOperation("设置设备属性值")
@PostMapping("/properties/setting/{deviceId}") @PostMapping("/properties/setting/{deviceId}")
public AjaxResult setDeviceProperties( public AjaxResult setDeviceProperties(
@PathVariable String deviceId, @PathVariable String deviceId,
@ -274,6 +280,7 @@ public class DcDeviceController extends BaseController {
* @param props 调用参数 * @param props 调用参数
* @return 调用结果 * @return 调用结果
*/ */
@ApiOperation("设备功能调用")
@PostMapping("/functions/{deviceId}/{functionId}") @PostMapping("/functions/{deviceId}/{functionId}")
public AjaxResult invokedFunction( public AjaxResult invokedFunction(
@PathVariable String deviceId, @PathVariable String deviceId,
@ -302,6 +309,7 @@ public class DcDeviceController extends BaseController {
* @param queryParam 查询条件 * @param queryParam 查询条件
* @return 查询事件结果 * @return 查询事件结果
*/ */
@ApiOperation("查询事件历史数据列表")
@GetMapping("/events/history/{deviceId}/{eventId}") @GetMapping("/events/history/{deviceId}/{eventId}")
public AjaxResult queryPagerDeviceEvents( public AjaxResult queryPagerDeviceEvents(
@PathVariable @Parameter(description = "设备ID") String deviceId, @PathVariable @Parameter(description = "设备ID") String deviceId,
@ -327,6 +335,7 @@ public class DcDeviceController extends BaseController {
* @param id 物联设备id * @param id 物联设备id
* @return 更新结果 * @return 更新结果
*/ */
@ApiOperation("获取设备物模型")
@GetMapping(value = "/metadata/{id}") @GetMapping(value = "/metadata/{id}")
public AjaxResult getMetadata(@PathVariable String id) throws HttpException, IOException { public AjaxResult getMetadata(@PathVariable String id) throws HttpException, IOException {

23
zc-business/src/main/java/com/zc/business/message/device/OfflineMessageListener.java

@ -1,14 +1,18 @@
package com.zc.business.message.device; package com.zc.business.message.device;
import com.alibaba.fastjson.JSON;
import com.zc.common.core.redis.stream.RedisStream; import com.zc.common.core.redis.stream.RedisStream;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.stream.ObjectRecord; import org.springframework.data.redis.connection.stream.ObjectRecord;
import org.springframework.data.redis.connection.stream.RecordId; import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.stream.StreamListener; import org.springframework.data.redis.stream.StreamListener;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
/** /**
* 离线消息监听 * 离线消息监听
*/ */
@ -17,15 +21,30 @@ public class OfflineMessageListener implements StreamListener<String, ObjectReco
{ {
private static final Logger log = LoggerFactory.getLogger(OfflineMessageListener.class); private static final Logger log = LoggerFactory.getLogger(OfflineMessageListener.class);
@Autowired @Resource
private RedisStream redisStream; private RedisStream redisStream;
@Resource
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Override @Override
public void onMessage(ObjectRecord<String, String> message) { public void onMessage(ObjectRecord<String, String> message) {
String streamKay = message.getStream(); String streamKay = message.getStream();
RecordId recordId = message.getId(); RecordId recordId = message.getId();
threadPoolTaskExecutor.execute(() -> {
List<String> list = JSON.parseArray(message.getValue(), String.class);
this.handle(list);
});
// 消费完后直接删除消息 // 消费完后直接删除消息
redisStream.del(streamKay, String.valueOf(recordId)); redisStream.del(streamKay, String.valueOf(recordId));
} }
/**
* 处理离线消息
*/
private void handle(List<String> msg) {
System.out.println(msg);
}
} }

Loading…
Cancel
Save