Forráskód Böngészése

1、增加亮度调节功能 回调任务状态
2、截图功能 图片上传接口,广播式发布

lihao16 5 hónapja
szülő
commit
6c7d4af9ef

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

@@ -32,6 +32,9 @@ public class DeviceTaskConstants {
     /** APP重启 */
     public static final Integer DEVICE_TASK_RESTART_APP = 1008;
 
+    /** 亮度调节 */
+    public static final Integer DEVICE_TASK_BRIGHTNESS = 1009;
+
     /** 设备任务类型 end */
 
     /** 设备任务状态 begin */

+ 15 - 6
smsb-modules/smsb-device/src/main/java/com/inspur/device/service/impl/SmsbDeviceServiceImpl.java

@@ -318,13 +318,13 @@ public class SmsbDeviceServiceImpl implements ISmsbDeviceService {
     public R<Void> screenshotUpload(String identifier, Long timestamp, MultipartFile file) {
         // 根据identifier获取设备信息
         SmsbDeviceVo smsbDeviceVo = getDeviceByIdentifier(identifier);
-        String redisKey = DeviceConstants.REDIS_SCREENSHOT_KEY + smsbDeviceVo.getId() + ":" + timestamp;
+        // String redisKey = DeviceConstants.REDIS_SCREENSHOT_KEY + smsbDeviceVo.getId() + ":" + timestamp;
         // 根据key获取存储的userId
-        String redisValue = RedisUtils.getCacheObject(redisKey);
+        /*String redisValue = RedisUtils.getCacheObject(redisKey);
         if (StringUtils.isEmpty(redisValue)) {
             return R.ok("超过一分钟,暂不处理");
-        }
-        Long userId = Long.parseLong(redisValue);
+        }*/
+        // Long userId = Long.parseLong(redisValue);
         // 文件上传
         String originalfileName = file.getOriginalFilename();
         String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
@@ -337,12 +337,21 @@ public class SmsbDeviceServiceImpl implements ISmsbDeviceService {
         }
         String imageUrl = uploadResult.getUrl();
         // 保存到redis
-        RedisUtils.setObjectIfExists(redisKey, imageUrl, Duration.ofMinutes(1));
+        // RedisUtils.setObjectIfExists(redisKey, imageUrl, Duration.ofMinutes(1));
         // 发送sse消息,前端展示
-        sendSseMessage(userId, imageUrl);
+        // sendSseMessage(userId, imageUrl);
+        sendSseMessage(imageUrl);
         return R.ok();
     }
 
+    private void sendSseMessage(String imageUrl) {
+        SseMessageContentDto messageContentDto = new SseMessageContentDto();
+        messageContentDto.setMsgType(SseMessageContentTypeDto.SCREENSHOT);
+        messageContentDto.setMsgData(imageUrl);
+        String message = JSON.toJSONString(messageContentDto);
+        SseMessageUtils.sendMessage(message);
+    }
+
     private void sendSseMessage(Long userId, String imageUrl) {
         SseMessageContentDto messageContentDto = new SseMessageContentDto();
         messageContentDto.setMsgType(SseMessageContentTypeDto.SCREENSHOT);

+ 26 - 3
smsb-modules/smsb-netty/src/main/java/com/inspur/netty/controller/DeviceController.java

@@ -149,10 +149,33 @@ public class DeviceController {
             return R.fail("设备不存在");
         }
         // 2 任务中心创建任务
-        String taskParam = PushMessageType.CONTROL_STANDBY.getValue() + "/" + volumeValue;
-        deviceTaskService.createNewDeviceTask(DeviceTaskConstants.DEVICE_TASK_STANDBY, deviceVo, taskParam);
+        String taskParam = PushMessageType.CONTROL_VOLUME.getValue() + "/" + volumeValue;
+        deviceTaskService.createNewDeviceTask(DeviceTaskConstants.DEVICE_TASK_VOICE, deviceVo, taskParam);
+        // 3 组装待机命令 发送长连接
+        String standbyCmd = deviceVo.getIdentifier() + PushMessageType.CONTROL_VOLUME.getValue() + "/" + volumeValue + NettyConstants.DATA_PACK_SEPARATOR;
+        boolean isSend = PushMsgUtil.sendV2(deviceVo.getIdentifier(), standbyCmd);
+        return isSend ? R.ok() : R.fail("长连接发送失败,设备长连接已断开");
+    }
+
+    /**
+     * 亮度设置
+     *
+     * @param deviceId
+     * @param handleBrightness 亮度大小
+     * @return
+     */
+    @GetMapping("/brightSet/{deviceId}/{handleBrightness}")
+    public R<String> brightSet(@PathVariable("deviceId") Long deviceId,@PathVariable("handleBrightness") Integer handleBrightness) {
+        // 1 查询设备信息
+        SmsbDeviceVo deviceVo = smsbDeviceService.getDeviceCacheById(deviceId);
+        if (deviceVo == null) {
+            return R.fail("设备不存在");
+        }
+        // 2 任务中心创建任务
+        String taskParam = PushMessageType.CONTROL_BRIGHTNESS.getValue() + "/" + handleBrightness;
+        deviceTaskService.createNewDeviceTask(DeviceTaskConstants.DEVICE_TASK_BRIGHTNESS, deviceVo, taskParam);
         // 3 组装待机命令 发送长连接
-        String standbyCmd = deviceVo.getIdentifier() + PushMessageType.CONTROL_STANDBY.getValue() + "/" + volumeValue + NettyConstants.DATA_PACK_SEPARATOR;
+        String standbyCmd = deviceVo.getIdentifier() + PushMessageType.CONTROL_BRIGHTNESS.getValue() + "/" + handleBrightness + NettyConstants.DATA_PACK_SEPARATOR;
         boolean isSend = PushMsgUtil.sendV2(deviceVo.getIdentifier(), standbyCmd);
         return isSend ? R.ok() : R.fail("长连接发送失败,设备长连接已断开");
     }

+ 69 - 0
smsb-modules/smsb-netty/src/main/java/com/inspur/netty/handler/TaskBrightSetHandler.java

@@ -0,0 +1,69 @@
+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 TaskBrightSetHandler 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.TASK_CONTROL_BRIGHT_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);
+            lqw.eq(SmsbDeviceTask::getTaskType, DeviceTaskConstants.DEVICE_TASK_BRIGHTNESS);
+            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);
+        }
+    }
+
+}

+ 2 - 2
smsb-modules/smsb-netty/src/main/java/com/inspur/netty/handler/TaskRestartDeviceHandler.java

@@ -18,7 +18,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.dromara.common.core.utils.SpringUtils;
 
 /**
- * APP 重启回复
+ * 设备重启回复
  *
  * @author lihao16
  */
@@ -38,7 +38,7 @@ public class TaskRestartDeviceHandler extends ChannelInboundHandlerAdapter {
         if (message.contains(ReceiveMessageType.TASK_RESTART_REPLAY.getValue())) {
             log.info("收到设备重启回复消息:{}", message);
             String identifier = message.split("/")[0];
-            // 1、 查询当前设备最近一条重启APP任务
+            // 1、 查询当前设备最近一条重启设备任务
             SmsbDeviceVo smsbDeviceVo = smsbDeviceService.getDeviceByIdentifier(identifier);
             if (null == smsbDeviceVo) {
                 log.error("未查询到设备信息:{}", identifier);

+ 2 - 2
smsb-modules/smsb-netty/src/main/java/com/inspur/netty/handler/TaskStandbyHandler.java

@@ -18,7 +18,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.dromara.common.core.utils.SpringUtils;
 
 /**
- * APP 重启回复
+ * 设备待机 息屏亮屏回复
  *
  * @author lihao16
  */
@@ -34,7 +34,7 @@ public class TaskStandbyHandler extends ChannelInboundHandlerAdapter {
     @Override
     public void channelRead(ChannelHandlerContext ctx, Object msg) {
         String message = (String) msg;
-        // 处理重启APP reply消息
+        // 处理设备待机reply消息
         if (message.contains(ReceiveMessageType.TASK_STANDBY_REPLAY.getValue())) {
             log.info("收到设备待机回复消息:{}", message);
             String identifier = message.split("/")[0];

+ 69 - 0
smsb-modules/smsb-netty/src/main/java/com/inspur/netty/handler/TaskVolumeSetHandler.java

@@ -0,0 +1,69 @@
+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 TaskVolumeSetHandler 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.TASK_CONTROL_VOLUME_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);
+            lqw.eq(SmsbDeviceTask::getTaskType, DeviceTaskConstants.DEVICE_TASK_VOICE);
+            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);
+        }
+    }
+
+}

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

@@ -65,12 +65,12 @@ public enum PushMessageType {
     /**
      * 调节设备音量
      */
-    CONTROL_VOLUME("/volumecontrol"),
+    CONTROL_VOLUME("/volumeControl"),
 
     /**
      * 调整设备亮度
      */
-    CONTROL_BRIGHTNESS("/brightness"),
+    CONTROL_BRIGHTNESS("/brightnessControl"),
 
     /**
      * 开始推流

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

@@ -28,6 +28,21 @@ public enum ReceiveMessageType {
      */
     TASK_RESTART_REPLAY("/restartDevice/reply"),
 
+    /**
+     * 音量设置回复
+     */
+    TASK_CONTROL_VOLUME_REPLAY("/volumeControl/reply"),
+
+    /**
+     * 亮度设置回复
+     */
+    TASK_CONTROL_BRIGHT_REPLAY("/brightnessControl/reply"),
+
+    /**
+     * 设备截屏
+     */
+    CONTROL_SCREENSHOT_REPLAY("/start/screenshot/reply"),
+
     /**
      * 检查OTA 消息回复
      * {identifier}/ota/check/replay/{OTAId}/{status}

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

@@ -59,6 +59,8 @@ public class NettyServer {
                             channel.pipeline().addLast(new HeartServerHandler());
                             channel.pipeline().addLast(new TaskRestartAppHandler());
                             channel.pipeline().addLast(new TaskStandbyHandler());
+                            channel.pipeline().addLast(new TaskRestartDeviceHandler());
+                            channel.pipeline().addLast(new TaskVolumeSetHandler());
                         }
                     });
             ChannelFuture f = b.bind(8990).sync();

+ 6 - 0
smsb-plus-ui/src/api/smsb/device/device.ts

@@ -123,6 +123,12 @@ export const volumeSet = (id: string | number, volumeValue: number) => {
   });
 };
 
+export const brightSet = (id: string | number, brightnessValue: number) => {
+  return request({
+    url: '/netty/device/brightSet/' + id + "/" + brightnessValue,
+    method: 'get'
+  });
+};
 export const startStream = (id: string | number) => {
   return request({
     url: '/stream/start/' + id,

+ 40 - 9
smsb-plus-ui/src/views/smsb/device/index.vue

@@ -281,9 +281,7 @@
           <el-button :loading="buttonLoading" type="primary" @click="handleControl('standby/true')">设备亮屏</el-button>
           <el-button :loading="buttonLoading" type="primary" @click="handleControl('standby/false')">设备息屏</el-button>
           <el-button :loading="buttonLoading" type="primary" @click="handleVoice">音量调节</el-button>
-<!--
           <el-button :loading="buttonLoading" type="primary" @click="handleBrightness">亮度调节</el-button>
--->
         </el-tab-pane>
         <el-tab-pane label="报警信息" name="alarm">
           <div class="table-content">
@@ -341,6 +339,16 @@
         </div>
       </template>
     </el-dialog>
+    <!--亮度调节弹窗-->
+    <el-dialog v-model="brightDialog.visible" :title="brightDialog.title" width="600px" append-to-body>
+      <el-slider style="margin: 20px" v-model="brightnessValue" :min="0" :max="100" :step="10" show-stops />
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button :loading="buttonLoading" type="primary" @click="brightSubmit">确 定</el-button>
+          <el-button @click="brightCancel">关 闭</el-button>
+        </div>
+      </template>
+    </el-dialog>
   </div>
 </template>
 
@@ -358,7 +366,7 @@ import {
   standby,
   startStream,
   stopStream,
-  updateDevice, volumeSet
+  updateDevice, volumeSet,brightSet
 } from '@/api/smsb/device/device';
 import { DeviceForm, DeviceQuery, DeviceStatisticsVo, DeviceVO } from '@/api/smsb/device/device_type';
 import { ProductVO } from '@/api/smsb/device/product_types';
@@ -401,6 +409,7 @@ const offlineNum = ref(0);
 const streamDeviceId = ref<string | number>();
 const initNum = ref(0);
 const volumeValue = ref(0);
+const brightnessValue = ref(0);
 const deviceRunInfo = reactive<DeviceRunInfoVO>({
   deviceBase: undefined,
   id: undefined,
@@ -433,6 +442,10 @@ const voiceDialog = reactive<DialogOption>({
   visible: false,
   title: ''
 });
+const brightDialog = reactive<DialogOption>({
+  visible: false,
+  title: ''
+});
 // 播放器实例引用
 const flvPlayer = ref<flvjs.Player | null>(null);
 const flvPlayerRef = ref<HTMLVideoElement | null>(null);
@@ -530,21 +543,39 @@ const getDeviceStatistics = async () => {
 const volumeSubmit = async () => {
   buttonLoading.value = true;
   const deviceId = deviceRunInfo.deviceId;
-  await volumeSet(deviceId,volumeValue.value);
+  await volumeSet(deviceId,volumeValue.value).finally(() => buttonLoading.value = false);
   buttonLoading.value = false;
   proxy?.$modal.msgSuccess('音量设置成功');
   voiceDialog.visible = false;
 }
+const brightSubmit = async () => {
+  buttonLoading.value = true;
+  const deviceId = deviceRunInfo.deviceId;
+  await brightSet(deviceId,brightnessValue.value).finally(() => buttonLoading.value = false);
+  buttonLoading.value = false;
+  proxy?.$modal.msgSuccess('亮度设置成功');
+  brightDialog.visible = false;
+}
 const volumeCancel = () => {
   voiceDialog.visible = false;
   buttonLoading.value = false;
 }
+const brightCancel = () => {
+  voiceDialog.visible = false;
+  buttonLoading.value = false;
+}
 const handleVoice = () => {
   // console.log("volume num = " + deviceRunInfo.volume)
   voiceDialog.visible = true;
   voiceDialog.title = '音量设置';
   volumeValue.value = deviceRunInfo.volume;
 }
+const handleBrightness = () => {
+  // console.log("volume num = " + deviceRunInfo.volume)
+  brightDialog.visible = true;
+  brightDialog.title = '亮度设置';
+  brightnessValue.value = deviceRunInfo.bright;
+}
 const getManufacturerList = async () => {
   const queryParams = {
     pageNum: 1,
@@ -674,17 +705,17 @@ const handleInfo = async (row?: DeviceVO) => {
 const handleControl = async (type: string) => {
   buttonLoading.value = true;
   if (type === 'reboot') {
-    const res = await reboot(deviceId.value);
+    const res = await reboot(deviceId.value).finally(() => buttonLoading.value = false);
   } else if (type === 'restartApp') {
-    const res = await restartApp(deviceId.value);
+    const res = await restartApp(deviceId.value).finally(() => buttonLoading.value = false);
   } else if (type === 'shutdown') {
-    const res = await shutdown(deviceId.value);
+    const res = await shutdown(deviceId.value).finally(() => buttonLoading.value = false);
   } else if (type === 'standby/true') {
     const action = true;
-    const res = await standby(deviceId.value,action);
+    const res = await standby(deviceId.value,action).finally(() => buttonLoading.value = false);
   }else {
     const action = false;
-    const res = await standby(deviceId.value,action);
+    const res = await standby(deviceId.value,action).finally(() => buttonLoading.value = false);
   }
   buttonLoading.value = false;
   proxy?.$modal.msgSuccess('指令下发成功');