feat:设备广播表

This commit is contained in:
dzc committed 2025-04-02 16:37:08 +08:00
1 parent 2ab0e85767
commit de435721cd
4 files changed
+104 -1

No files matched your search

+27 -1
View File
@@ -221,4 +221,30 @@ CREATE TABLE hard_after_sale_log
del_flag char(1) COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '删除标记',
tenant_id bigint DEFAULT NULL COMMENT '租户ID',
PRIMARY KEY (id)
) ENGINE = InnoDB COMMENT ='售后订单日志';
) ENGINE = InnoDB COMMENT ='售后订单日志';
-- ----------------------------
-- Table structure for hard_broadcast
-- ----------------------------
DROP TABLE IF EXISTS hard_broadcast;
CREATE TABLE hard_broadcast
(
id bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
user_id bigint NOT NULL COMMENT '预定用户',
hard_id bigint NOT NULL COMMENT '硬件id',
topic varchar(128) NOT NULL COMMENT 'mq主题',
biz_id varchar(64) NOT NULL COMMENT '关联业务编号',
title varchar(64) NOT NULL COMMENT '预定标题',
unique_code varchar(16) NOT NULL COMMENT '广播唯一编号',
broadcast_count int DEFAULT 0 NOT NULL COMMENT '广播次数',
is_broadcast char(1) DEFAULT '0' COMMENT '是否广播语音',
is_done char(1) DEFAULT '0' COMMENT '是否完成',
is_done_time datetime DEFAULT NULL COMMENT '完成时间',
create_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
create_time datetime DEFAULT NULL COMMENT '创建时间',
update_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修改人',
update_time datetime DEFAULT NULL COMMENT '修改时间',
del_flag char(1) COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '删除标记',
tenant_id bigint DEFAULT NULL COMMENT '租户ID',
PRIMARY KEY (id)
) ENGINE = InnoDB COMMENT ='设备广播';
@@ -0,0 +1,74 @@
package com.bsd.pjcloud.mqtt.broadcast;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
* 硬件语音广播
*/
@Service
@Slf4j
public class BroadcastVideoService {
private ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
// 用于管理定时任务
private ScheduledFuture<?> scheduledFuture;
// 用于管理自动停止任务
private ScheduledFuture<?> autoStopFuture;
private final int interval = 60;
private final int autoInterval = 60 * 5;
/**
* 启动广播
*/
public void startBroadcast() {
if (scheduledFuture == null || scheduledFuture.isDone()) {
scheduledFuture = executorService.scheduleAtFixedRate(() -> {
playAudio();
}, 0, interval, TimeUnit.SECONDS);
log.info("广播已启动");
startAutoStopTask();
}
}
/**
* 停止广播
*/
public void stopBroadcast() {
if (scheduledFuture == null) return;
scheduledFuture.cancel(false);
scheduledFuture = null;
if (autoStopFuture != null) {
autoStopFuture.cancel(false);
autoStopFuture = null;
}
log.info("广播已停止");
}
/**
* 自动关闭广播任务
*/
private void startAutoStopTask() {
autoStopFuture = executorService.schedule(() -> {
if (scheduledFuture != null && !scheduledFuture.isDone()) {
log.info("{}秒内未收到消息,自动停止广播", autoInterval);
stopBroadcast();
}
}, autoInterval, TimeUnit.MINUTES);
}
/**
* 播放音频
*/
private void playAudio() {
}
}
@@ -36,6 +36,7 @@ public class MqttEventController {
@GetMapping("/send-config-change-msg")
public R<Boolean> sendConfigChangeMsg(@RequestParam Long deptId) {
MqttBaseDto dto = new MqttBaseDto<>();
mqttEventService.getTopicParamsByUserDeptId(dto, deptId);
dto.setAction(MqttActionEnum.CONFIG);
dto.setMerchantDeptId(deptId);
return R.ok(mqttEventService.defaultAction(dto));
@@ -4,7 +4,9 @@ import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ZipUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;