Преглед на файлове

feat:
1、新增播放内容控制,支持上一个下一个。
2、内容控制接入任务中心,支持获取任务状态。

lihao16 преди 5 месеца
родител
ревизия
57d5a6133d

+ 6 - 0
smsb-modules/smsb-device/src/main/java/com/inspur/device/domain/constants/DeviceTaskConstants.java

@@ -38,6 +38,12 @@ public class DeviceTaskConstants {
     /** OTA升级 */
     public static final Integer DEVICE_TASK_OTA = 1014;
 
+    /** 播放下一个资源 */
+    public static final Integer DEVICE_PLAY_NEXT = 1015;
+
+    /** 播放上一个资源 */
+    public static final Integer DEVICE_PLAY_LAST = 1016;
+
     /** 设备任务类型 end */
 
     /** 设备任务状态 begin */

+ 48 - 0
smsb-modules/smsb-netty/src/main/java/com/inspur/netty/controller/DeviceController.java

@@ -305,6 +305,54 @@ public class DeviceController {
 
     }
 
+    /**
+     * 播放下一个
+     *
+     * @param deviceId
+     * @return
+     */
+    @GetMapping("/play/next/{deviceId}")
+    public R<String> playNext(@PathVariable Long deviceId) {
+        // 1 查询设备信息
+        SmsbDeviceVo deviceVo = smsbDeviceService.getDeviceCacheById(deviceId);
+        if (deviceVo == null) {
+            return R.fail("设备不存在");
+        }
+        // 2 任务中心创建任务
+        String taskParam = PushMessageType.CONTROL_PLAY_NEXT.getValue();
+        deviceTaskService.createNewDeviceTask(DeviceTaskConstants.DEVICE_PLAY_NEXT, deviceVo, taskParam);
+
+        // 3 组装长连接命令
+        String screenshotCmd = deviceVo.getIdentifier() + PushMessageType.CONTROL_PLAY_NEXT.getValue() + NettyConstants.DATA_PACK_SEPARATOR;
+        boolean isSend = PushMsgUtil.sendV2(deviceVo.getIdentifier(), screenshotCmd);
+        return isSend ? R.ok() : R.fail("发送失败,设备长连接已断开");
+
+    }
+
+    /**
+     * 播放上一个
+     *
+     * @param deviceId
+     * @return
+     */
+    @GetMapping("/play/last/{deviceId}")
+    public R<String> playLast(@PathVariable Long deviceId) {
+        // 1 查询设备信息
+        SmsbDeviceVo deviceVo = smsbDeviceService.getDeviceCacheById(deviceId);
+        if (deviceVo == null) {
+            return R.fail("设备不存在");
+        }
+        // 2 任务中心创建任务
+        String taskParam = PushMessageType.CONTROL_PLAY_LAST.getValue();
+        deviceTaskService.createNewDeviceTask(DeviceTaskConstants.DEVICE_PLAY_LAST, deviceVo, taskParam);
+
+        // 3 组装长连接命令
+        String screenshotCmd = deviceVo.getIdentifier() + PushMessageType.CONTROL_PLAY_LAST.getValue() + NettyConstants.DATA_PACK_SEPARATOR;
+        boolean isSend = PushMsgUtil.sendV2(deviceVo.getIdentifier(), screenshotCmd);
+        return isSend ? R.ok() : R.fail("发送失败,设备长连接已断开");
+
+    }
+
     /**
      * 新增发布升级
      */

+ 73 - 0
smsb-modules/smsb-netty/src/main/java/com/inspur/netty/handler/TaskPlayControlHandler.java

@@ -0,0 +1,73 @@
+package com.inspur.netty.handler;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.inspur.device.domain.SmsbDeviceTask;
+import com.inspur.device.domain.SmsbDeviceTaskDetail;
+import com.inspur.device.domain.constants.DeviceTaskConstants;
+import com.inspur.device.domain.vo.SmsbDeviceTaskVo;
+import com.inspur.device.domain.vo.SmsbDeviceVo;
+import com.inspur.device.mapper.SmsbDeviceTaskDetailMapper;
+import com.inspur.device.mapper.SmsbDeviceTaskMapper;
+import com.inspur.device.service.ISmsbDeviceService;
+import com.inspur.device.service.impl.SmsbDeviceServiceImpl;
+import com.inspur.netty.message.receive.ReceiveMessageType;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import lombok.extern.slf4j.Slf4j;
+import org.dromara.common.core.utils.SpringUtils;
+
+/**
+ * 播放控制 包括上一个下一个
+ *
+ * @author lihao16
+ */
+@Slf4j
+public class TaskPlayControlHandler extends ChannelInboundHandlerAdapter {
+
+    private static final ISmsbDeviceService smsbDeviceService = SpringUtils.getBean(SmsbDeviceServiceImpl.class);
+
+    private static final SmsbDeviceTaskMapper smsbDeviceTaskMapper = SpringUtils.getBean(SmsbDeviceTaskMapper.class);
+
+    private static final SmsbDeviceTaskDetailMapper smsbDeviceTaskDetailMapper = SpringUtils.getBean(SmsbDeviceTaskDetailMapper.class);
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+        String message = (String) msg;
+        // 处理设置设备亮度 reply消息
+        if (message.contains(ReceiveMessageType.DEVICE_PLAY_NEXT_REPLAY.getValue())
+            || message.contains(ReceiveMessageType.DEVICE_PLAY_LAST_REPLAY.getValue())) {
+            log.info("收到设备播放控制回复消息:{}", message);
+            String identifier = message.split("/")[0];
+            // 1、 查询当前设备最近一条播放控制任务
+            SmsbDeviceVo smsbDeviceVo = smsbDeviceService.getDeviceByIdentifier(identifier);
+            if (null == smsbDeviceVo) {
+                log.error("未查询到设备信息:{}", identifier);
+                return;
+            }
+            LambdaQueryWrapper<SmsbDeviceTask> lqw = Wrappers.lambdaQuery();
+            lqw.eq(SmsbDeviceTask::getIdentifier, identifier);
+            if (message.contains(ReceiveMessageType.DEVICE_PLAY_NEXT_REPLAY.getValue())) {
+                lqw.eq(SmsbDeviceTask::getTaskType, DeviceTaskConstants.DEVICE_PLAY_NEXT);
+            }else {
+                lqw.eq(SmsbDeviceTask::getTaskType, DeviceTaskConstants.DEVICE_PLAY_LAST);
+            }
+            lqw.orderByDesc(SmsbDeviceTask::getCreateTime);
+            lqw.last("limit 1");
+            SmsbDeviceTaskVo smsbDeviceTask = smsbDeviceTaskMapper.selectVoOne(lqw);
+            if (null == smsbDeviceTask) {
+                log.error("未查询到控制设备播放的任务:{}", identifier);
+                return;
+            }
+            // 2、收到回复 认定接收任务
+            SmsbDeviceTaskDetail taskDetail = new SmsbDeviceTaskDetail();
+            taskDetail.setTaskId(smsbDeviceTask.getId());
+            taskDetail.setTaskStatus(DeviceTaskConstants.DEVICE_TASK_STATUS_INIT);
+            taskDetail.setTenantId(smsbDeviceVo.getTenantId());
+            smsbDeviceTaskDetailMapper.insert(taskDetail);
+        } else {
+            ctx.fireChannelRead(message);
+        }
+    }
+
+}

+ 11 - 1
smsb-modules/smsb-netty/src/main/java/com/inspur/netty/message/push/PushMessageType.java

@@ -100,7 +100,17 @@ public enum PushMessageType {
     /**
      * 检查OTA升级
      */
-    DEVICE_CHECK_OTA("/ota/check");
+    DEVICE_CHECK_OTA("/ota/check"),
+
+    /**
+     * 播放下一个资源
+     */
+    CONTROL_PLAY_NEXT("/play/next"),
+
+    /**
+     * 播放上一个
+     */
+    CONTROL_PLAY_LAST("/play/last");
 
     private String value;
 

+ 12 - 0
smsb-modules/smsb-netty/src/main/java/com/inspur/netty/message/receive/ReceiveMessageType.java

@@ -59,6 +59,18 @@ public enum ReceiveMessageType {
      */
     DEVICE_CHECK_OTA_REPLAY("/ota/check/replay"),
 
+    /**
+     * 播放下一个 消息回复
+     * {identifier}/play/next/replay
+     */
+    DEVICE_PLAY_NEXT_REPLAY("/play/next/replay"),
+
+    /**
+     * 播放上一个 消息回复
+     * {identifier}/play/next/replay
+     */
+    DEVICE_PLAY_LAST_REPLAY("/play/last/replay"),
+
     /**
      * 内容下发状态更新
      * {identifier}/content/download/status/{pushId}/{status}

+ 2 - 0
smsb-modules/smsb-netty/src/main/java/com/inspur/netty/server/NettyServer.java

@@ -57,6 +57,7 @@ public class NettyServer {
                             channel.pipeline().addLast(new AuthServerHandler());
                             channel.pipeline().addLast(new ConnectServerHandler());
                             channel.pipeline().addLast(new HeartServerHandler());
+                            channel.pipeline().addLast(new SourcePlayRecordHandler());
                             channel.pipeline().addLast(new TaskRestartAppHandler());
                             channel.pipeline().addLast(new TaskStandbyHandler());
                             channel.pipeline().addLast(new TaskRestartDeviceHandler());
@@ -65,6 +66,7 @@ public class NettyServer {
                             channel.pipeline().addLast(new TaskScreenshotHandler());
                             channel.pipeline().addLast(new TaskStreamStartHandler());
                             channel.pipeline().addLast(new TaskStreamStopHandler());
+                            channel.pipeline().addLast(new TaskPlayControlHandler());
                         }
                     });
             ChannelFuture f = b.bind(8990).sync();