hby100japp功能

This commit is contained in:
2026-02-04 15:27:43 +08:00
parent 696bbb4aa4
commit 2db37a75d2
34 changed files with 1638 additions and 87 deletions

View File

@ -1,23 +1,16 @@
package com.fuyuanshen.app.controller.device.bjq;
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
import com.fuyuanshen.app.domain.vo.AppDeviceHBY100JDetailVo;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
import com.fuyuanshen.web.service.device.DeviceBJQBizService;
import com.fuyuanshen.web.service.device.DeviceHBY100JBizService;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* HBY100J设备控制类
@ -25,7 +18,7 @@ import org.springframework.web.multipart.MultipartFile;
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/hby100/device")
@RequestMapping("/app/hby100j/device")
public class AppDeviceHBY100JController extends BaseController {
private final DeviceHBY100JBizService deviceHBY100JBizService;
@ -46,8 +39,8 @@ public class AppDeviceHBY100JController extends BaseController {
* 更新语音
*/
@PostMapping("/updateVoice")
public R<Void> updateVoice(Long id) {
deviceHBY100JBizService.updateVoice(id);
public R<Void> updateVoice(@RequestBody HBY100JUpdateVoiceDto dto) {
deviceHBY100JBizService.updateVoice(dto);
return R.ok();
}
@ -57,10 +50,142 @@ public class AppDeviceHBY100JController extends BaseController {
*/
@PostMapping("/forceAlarmActivation")
public R<Void> forceAlarmActivation(@RequestBody AppDeviceSendMsgBo bo) {
public R<Void> forceAlarmActivation(@RequestBody HBY100JForceAlarmActivationDto bo) {
deviceHBY100JBizService.forceAlarmActivation(bo);
return R.ok();
}
/**
* 爆闪模式
*/
@PostMapping("/strobeMode")
public R<Void> strobeMode(@RequestBody HBY100JStrobeModeDto params) {
deviceHBY100JBizService.strobeMode(params);
return R.ok();
}
/**
* 灯光调节
*/
@PostMapping("/lightAdjustment")
public R<Void> lightAdjustment(@RequestBody HBY100JLightAdjustmentDto params) {
deviceHBY100JBizService.lightAdjustment(params);
return R.ok();
}
/**
* 爆闪频率
*/
@PostMapping("/strobeFrequency")
public R<Void> strobeFrequency(@RequestBody HBY100JStrobeFrequencyDto params) {
deviceHBY100JBizService.strobeFrequency(params);
return R.ok();
}
/**
* 修改音量
*/
@PostMapping("/updateVolume")
public R<Void> updateVolume(@RequestBody HBY100JUpdateVolumeDto params) {
deviceHBY100JBizService.updateVolume(params);
return R.ok();
}
@Data
public static class HBY100JUpdateVoiceDto {
private Long id;
}
@Data
public static class HBY100JForceAlarmActivationDto {
/**
* 设备ID
*/
List<Long> deviceIds;
/**
* 0 关闭, 1开启
*/
private Integer voiceStrobeAlarm;
/**
* 0 公安,1消防,2应急,3交警4 市政5 铁路6 医疗7部队8 水利,9 语音
*/
private Integer mode;
}
@Data
public static class HBY100JUpdateVolumeDto{
/**
* 设备ID
*/
private Long deviceId;
/**
* "volume": 1-100(app端可根据需求把40作为低音量, 70作为中音量100作为高音量)
*/
private Integer volume;
}
@Data
public static class HBY100JStrobeFrequencyDto{
/**
* 设备ID
*/
private Long deviceId;
/**
* "frequency": 1-12
*/
private Integer frequency;
}
@Data
public static class HBY100JLightAdjustmentDto{
/**
* 设备ID
*/
private Long deviceId;
/**
* 亮度值0-100
*/
private Integer brightness;
// /**
// * 红色LED亮度值0-100
// */
// private Integer red;
//
// /**
// * 蓝色LED亮度值0-100
// */
// private Integer blue;
//
// /**
// * 黄色LED亮度值0-100
// */
// private Integer yellow;
}
@Data
public static class HBY100JStrobeModeDto{
/**
* 设备ID
*/
private Long deviceId;
/**
* 0 关闭 1 开启
*/
private Integer enable;
/**
* 0 红色爆闪1 蓝色爆闪2 黄色爆闪3红色顺时针旋转爆闪4黄色顺时针旋转爆闪5红蓝顺时针旋转爆闪6 红蓝交替爆闪
*/
private Integer mode;
}
}

View File

@ -13,4 +13,5 @@ public interface MqttConstants {
*/
String GLOBAL_SUB_KEY = "A/";
String GLOBAL_PUB_KEY2 = "command/";
}

View File

@ -51,48 +51,27 @@ public class NewReceiverMessageHandler implements MessageHandler {
}
String imei = payloadDict.getStr("imei");
String funcType = payloadDict.getStr("funcType");
RedissonClient client = RedisUtils.getClient();
String lockKey = "mqtt:consumer:lock:";
String KEY = GlobalConstants.GLOBAL_REDIS_KEY + lockKey + imei;
log.info("MQTT2获取锁开始{}", KEY);
RLock lock = client.getLock(KEY);
// 执行业务逻辑
if(StringUtils.isNotBlank(imei)){
String queueKey = MqttMessageQueueConstants.MQTT_MESSAGE_QUEUE_KEY;
String dedupKey = MqttMessageQueueConstants.MQTT_MESSAGE_DEDUP_KEY;
RedisUtils.offerDeduplicated(queueKey,dedupKey,imei, Duration.ofSeconds(900));
//在线状态
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ imei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1", Duration.ofSeconds(360));
}
try {
// 尝试获取锁,
boolean isLocked = lock.tryLock(60, 3000, TimeUnit.MILLISECONDS);
if (isLocked) {
// 执行业务逻辑
if(StringUtils.isNotBlank(imei)){
String queueKey = MqttMessageQueueConstants.MQTT_MESSAGE_QUEUE_KEY;
String dedupKey = MqttMessageQueueConstants.MQTT_MESSAGE_DEDUP_KEY;
RedisUtils.offerDeduplicated(queueKey,dedupKey,imei, Duration.ofSeconds(900));
//在线状态
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ imei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "1", Duration.ofSeconds(360));
}
String[] topicArr = receivedTopic.split("/");
String[] topicArr = receivedTopic.split("/");
NewMqttRuleContext context = new NewMqttRuleContext();
context.setCommandType(topicArr[2]+"_"+funcType);
context.setDeviceImei(imei);
context.setPayloadDict(payloadDict);
NewMqttRuleContext context = new NewMqttRuleContext();
context.setCommandType(topicArr[2]+"_"+funcType);
context.setDeviceImei(imei);
context.setPayloadDict(payloadDict);
boolean ruleExecuted = newRuleEngine.executeRule(context);
boolean ruleExecuted = newRuleEngine.executeRule(context);
if (!ruleExecuted) {
log.warn("未找到匹配的规则来处理命令类型: {}", topicArr[2] + " : " +funcType);
}
}else{
log.warn("MQTT2获取锁失败请稍后再试");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
// 释放锁
if (lock.isHeldByCurrentThread()) {
lock.unlock();
}
if (!ruleExecuted) {
log.warn("未找到匹配的规则来处理命令类型: {}", topicArr[2] + " : " +funcType);
}
// final LockInfo lockInfo = lockTemplate.lock(GlobalConstants.GLOBAL_REDIS_KEY + lockKey + imei, 100L, 3000L, RedissonLockExecutor.class);
// if (null == lockInfo) {

View File

@ -0,0 +1,43 @@
package com.fuyuanshen.global.mqtt.rule.hby100j;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
/**
* 爆闪模式开启/关闭
*/
@Slf4j
@Component
public class FuncType10StrobeMode implements NewMqttMessageRule {
@Override
public String getCommandType() {
return "HBY100_10";
}
@Override
public void execute(NewMqttRuleContext context) {
log.info("HBY100J爆闪模式开启/关闭,消息负载:{}", context.getPayloadDict());
try {
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
context.getDeviceImei() + ":strobeMode";
Map<String, Object> payloadDict = context.getPayloadDict();
if (payloadDict != null) {
RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
}
} catch (Exception e) {
log.error("HBY100J爆闪模式开启/关闭失败", e);
}
}
}

View File

@ -0,0 +1,43 @@
package com.fuyuanshen.global.mqtt.rule.hby100j;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
/**
* 修改警示灯爆闪频率
*/
@Slf4j
@Component
public class FuncType11Frequency implements NewMqttMessageRule {
@Override
public String getCommandType() {
return "HBY100_11";
}
@Override
public void execute(NewMqttRuleContext context) {
log.info("HBY100J修改警示灯爆闪频率消息负载{}", context.getPayloadDict());
try {
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
context.getDeviceImei() + ":frequency";
Map<String, Object> payloadDict = context.getPayloadDict();
if (payloadDict != null) {
RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
}
} catch (Exception e) {
log.error("HBY100J修改警示灯爆闪频率失败", e);
}
}
}

View File

@ -0,0 +1,45 @@
package com.fuyuanshen.global.mqtt.rule.hby100j;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
/**
* 强制声光报警开启/关闭
*/
@Slf4j
@Component
public class FuncType12ForceAudio implements NewMqttMessageRule {
@Override
public String getCommandType() {
return "HBY100_12";
}
@Override
public void execute(NewMqttRuleContext context) {
log.info("HBY100J强制声光报警开启/关闭,消息负载:{}", context.getPayloadDict());
try {
// 构建强制声光报警开关的Redis键
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
context.getDeviceImei() + ":forceAudio";
Map<String, Object> payloadDict = context.getPayloadDict();
if (payloadDict != null) {
// 存储强制声光报警开关状态到Redis
RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
}
} catch (Exception e) {
log.error("HBY100J强制声光报警开启/关闭失败", e);
}
}
}

View File

@ -0,0 +1,43 @@
package com.fuyuanshen.global.mqtt.rule.hby100j;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
/**
* 警示灯LED亮度调节
*/
@Slf4j
@Component
public class FuncType13Brightness implements NewMqttMessageRule {
@Override
public String getCommandType() {
return "HBY100_13";
}
@Override
public void execute(NewMqttRuleContext context) {
log.info("HBY100J警示灯LED亮度调节消息负载{}", context.getPayloadDict());
try {
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
context.getDeviceImei() + ":brightness";
Map<String, Object> payloadDict = context.getPayloadDict();
if (payloadDict != null) {
RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
}
} catch (Exception e) {
log.error("HBY100J警示灯LED亮度调节失败", e);
}
}
}

View File

@ -0,0 +1,43 @@
package com.fuyuanshen.global.mqtt.rule.hby100j;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
/**
* 获取警示灯的当前工作方式(设备下发返回响应数据、设备定时主动上报)
*/
@Slf4j
@Component
public class FuncType14Report implements NewMqttMessageRule {
@Override
public String getCommandType() {
return "HBY100_14";
}
@Override
public void execute(NewMqttRuleContext context) {
log.info("HBY100J设备定时主动上报消息负载{}", context.getPayloadDict());
try {
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
context.getDeviceImei() + ":report";
Map<String, Object> payloadDict = context.getPayloadDict();
if (payloadDict != null) {
RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
}
} catch (Exception e) {
log.error("HBY100J设备定时主动上报失败", e);
}
}
}

View File

@ -0,0 +1,46 @@
//package com.fuyuanshen.global.mqtt.rule.hby100j;
//
//import com.alibaba.fastjson2.JSONObject;
//import com.fuyuanshen.common.core.constant.GlobalConstants;
//import com.fuyuanshen.common.redis.utils.RedisUtils;
//import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
//import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
//
//import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
//
///**
// * 设备复位
// */
//@Slf4j
//@Component
//public class FuncType1Rest implements NewMqttMessageRule {
//
// @Override
// public String getCommandType() {
// return "HBY100_1";
// }
//
// @Override
// public void execute(NewMqttRuleContext context) {
// log.info("开始处理设备复位,消息负载:{}", context.getPayloadDict());
//
// try {
// // 构建强制声光报警开关的Redis键
//// String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
//// context.getDeviceImei() + ":force_audio_visual_alarm_switch";
////
//// Map<String, Object> payloadDict = context.getPayloadDict();
//// if (payloadDict != null) {
//// // 存储强制声光报警开关状态到Redis
//// RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
//// }
// log.info("设备复位设备ID{}", context.getDeviceImei());
// } catch (Exception e) {
// log.error("处理设备复位失败", e);
// }
// }
//}

View File

@ -0,0 +1,46 @@
//package com.fuyuanshen.global.mqtt.rule.hby100j;
//
//import com.alibaba.fastjson2.JSONObject;
//import com.fuyuanshen.common.core.constant.GlobalConstants;
//import com.fuyuanshen.common.redis.utils.RedisUtils;
//import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
//import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
//
//import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
//
///**
// * 获取设备基础信息
// */
//@Slf4j
//@Component
//public class FuncType2BaseInfo implements NewMqttMessageRule {
//
// @Override
// public String getCommandType() {
// return "HBY100_2";
// }
//
// @Override
// public void execute(NewMqttRuleContext context) {
// log.info("开始处理强制声光报警开关,消息负载:{}", context.getPayloadDict());
//
// try {
// // 构建强制声光报警开关的Redis键
// String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
// context.getDeviceImei() + ":force_audio_visual_alarm_switch";
//
// Map<String, Object> payloadDict = context.getPayloadDict();
// if (payloadDict != null) {
// // 存储强制声光报警开关状态到Redis
// RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
// }
// log.info("强制声光报警开关处理完成设备ID{}", context.getDeviceImei());
// } catch (Exception e) {
// log.error("处理强制声光报警开关失败", e);
// }
// }
//}

View File

@ -0,0 +1,43 @@
package com.fuyuanshen.global.mqtt.rule.hby100j;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
/**
* 获取设备位置信息(设备下发返回响应数据、设备定时主动上报)
*/
@Slf4j
@Component
public class FuncType3Location implements NewMqttMessageRule {
@Override
public String getCommandType() {
return "HBY100_3";
}
@Override
public void execute(NewMqttRuleContext context) {
log.info("HBY100J获取设备位置信息消息负载{}", context.getPayloadDict());
try {
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
context.getDeviceImei() + ":location";
Map<String, Object> payloadDict = context.getPayloadDict();
if (payloadDict != null) {
RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
}
} catch (Exception e) {
log.error("HBY100J获取设备位置信息失败", e);
}
}
}

View File

@ -0,0 +1,43 @@
package com.fuyuanshen.global.mqtt.rule.hby100j;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
/**
* 获取设备电源状态(设备下发返回响应数据、设备定时主动上报)
*/
@Slf4j
@Component
public class FuncType4PowerStatus implements NewMqttMessageRule {
@Override
public String getCommandType() {
return "HBY100_4";
}
@Override
public void execute(NewMqttRuleContext context) {
log.info("HBY100J获取设备电源状态消息负载{}", context.getPayloadDict());
try {
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
context.getDeviceImei() + ":powerStatus";
Map<String, Object> payloadDict = context.getPayloadDict();
if (payloadDict != null) {
RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
}
} catch (Exception e) {
log.error("HBY100J获取设备电源状态失败", e);
}
}
}

View File

@ -0,0 +1,43 @@
package com.fuyuanshen.global.mqtt.rule.hby100j;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
/**
* 更新语音
*/
@Slf4j
@Component
public class FuncType5UpdateVoice implements NewMqttMessageRule {
@Override
public String getCommandType() {
return "HBY100_5";
}
@Override
public void execute(NewMqttRuleContext context) {
log.info("HBY100J更新语音消息负载{}", context.getPayloadDict());
try {
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
context.getDeviceImei() + ":updateVoice";
Map<String, Object> payloadDict = context.getPayloadDict();
if (payloadDict != null) {
RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
}
} catch (Exception e) {
log.error("HBY100J更新语音失败", e);
}
}
}

View File

@ -0,0 +1,43 @@
package com.fuyuanshen.global.mqtt.rule.hby100j;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
/**
* 语音播报开启/关闭
*/
@Slf4j
@Component
public class FuncType6VoicePlay implements NewMqttMessageRule {
@Override
public String getCommandType() {
return "HBY100_9";
}
@Override
public void execute(NewMqttRuleContext context) {
log.info("HBY100J语音播报开启/关闭,消息负载:{}", context.getPayloadDict());
try {
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
context.getDeviceImei() + ":VoicePlay";
Map<String, Object> payloadDict = context.getPayloadDict();
if (payloadDict != null) {
RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
}
} catch (Exception e) {
log.error("HBY100J语音播报开启/关闭失败", e);
}
}
}

View File

@ -0,0 +1,43 @@
package com.fuyuanshen.global.mqtt.rule.hby100j;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.NewMqttMessageRule;
import com.fuyuanshen.global.mqtt.base.NewMqttRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
/**
* 修改音量
*/
@Slf4j
@Component
public class FuncType9UpdateVolume implements NewMqttMessageRule {
@Override
public String getCommandType() {
return "HBY100_9";
}
@Override
public void execute(NewMqttRuleContext context) {
log.info("HBY100J修改音量消息负载{}", context.getPayloadDict());
try {
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
context.getDeviceImei() + ":updateVolume";
Map<String, Object> payloadDict = context.getPayloadDict();
if (payloadDict != null) {
RedisUtils.setCacheObject(redisKey, JSONObject.toJSONString(payloadDict));
}
} catch (Exception e) {
log.error("HBY100J修改音量失败", e);
}
}
}

View File

@ -0,0 +1,58 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 爆闪模式开启/关闭
* 对应 funcType="10"
* mode:
* 0 红色爆闪1 蓝色爆闪2 黄色爆闪3红色顺时针旋转爆闪4黄色顺时针旋转爆闪5红蓝顺时针旋转爆闪6 红蓝交替爆闪
*/
@Data
public class FuncType10StrobeModeRequest {
/**
* 请求唯一标识符(用于链路追踪或幂等处理)
*/
@JsonProperty("requestId")
private String requestId;
/**
* 设备IMEI号国际移动设备识别码
*/
private String imei;
/**
* 功能类型编码
*/
private String funcType;
/**
* 时间戳毫秒级Unix时间戳
*/
private Long timestamp;
/**
* 语音配置数据
*/
private Data data;
/**
* 语音配置详情内部类
*/
@lombok.Data
public static class Data {
/**
* 爆闪模式是否启用
* 0 - 禁用
* 1 - 启用
*/
private Integer enable;
/**
* 爆闪模式类型 0 红色爆闪1 蓝色爆闪2 黄色爆闪3红色顺时针旋转爆闪4黄色顺时针旋转爆闪5红蓝顺时针旋转爆闪6 红蓝交替爆闪
**/
private Integer mode;
}
}

View File

@ -0,0 +1,47 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 修改警示灯爆闪频率
* 对应 funcType="11"
*/
@Data
public class FuncType11FrequencyRequest {
/**
* 请求唯一标识符(用于链路追踪或幂等处理)
*/
@JsonProperty("requestId")
private String requestId;
/**
* 设备IMEI号国际移动设备识别码
*/
private String imei;
/**
* 功能类型编码
*/
private String funcType;
/**
* 时间戳毫秒级Unix时间戳
*/
private Long timestamp;
/**
* 语音配置数据
*/
private Data data;
/**
* 语音配置详情内部类
*/
@lombok.Data
public static class Data {
//"frequency": 1-12
private Integer frequency;
}
}

View File

@ -0,0 +1,51 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 强制声光报警开启/关闭
* 对应 funcType="12"
*/
@Data
public class FuncType12ForceAudioRequest {
/**
* 请求唯一标识符(用于链路追踪或幂等处理)
*/
@JsonProperty("requestId")
private String requestId;
/**
* 设备IMEI号国际移动设备识别码
*/
private String imei;
/**
* 功能类型编码
*/
private String funcType;
/**
* 时间戳毫秒级Unix时间戳
*/
private Long timestamp;
/**
* 语音配置数据
*/
private Data data;
/**
* 语音配置详情内部类
*/
@lombok.Data
public static class Data {
/**
* 语音报警0关闭,1开启
*/
private Integer voiceStrobeAlarm;
//语音模式0公安,1消防,2应急,3交警4市政5铁路6医疗7部队8水利
private Integer mode;
}
}

View File

@ -0,0 +1,59 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 警示灯LED亮度调节
* 对应 funcType="13"
*/
@Data
public class FuncType13BrightnessRequest {
/**
* 请求唯一标识符(用于链路追踪或幂等处理)
*/
@JsonProperty("requestId")
private String requestId;
/**
* 设备IMEI号国际移动设备识别码
*/
private String imei;
/**
* 功能类型编码
*/
private String funcType;
/**
* 时间戳毫秒级Unix时间戳
*/
private Long timestamp;
/**
* 语音配置数据
*/
private Data data;
/**
* 语音配置详情内部类
*/
@lombok.Data
public static class Data {
/**
* 红色LED亮度值0-100
*/
private Integer red;
/**
* 蓝色LED亮度值0-100
*/
private Integer blue;
/**
* 黄色LED亮度值0-100
*/
private Integer yellow;
}
}

View File

@ -0,0 +1,143 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 设备状态上报数据DTO
* 对应MQTT消息中设备上报的完整状态数据结构
*/
@Data
public class FuncType14StatusReport {
/**
* 设备IMEI号国际移动设备识别码
*/
private String imei;
/**
* 功能类型编码(如"14"表示特定功能指令)
*/
private String funcType;
/**
* 响应状态码(如"200"表示成功)
*/
private String status;
/**
* 时间戳毫秒级Unix时间戳
*/
private Long timestamp;
/**
* 设备详细状态数据
*/
private Data data;
/**
* 设备详细状态数据内部类
*/
@lombok.Data
public static class Data {
/**
* 语音播报开关0-关闭1-开启
*/
@JsonProperty("voice_broadcast")
private Integer voiceBroadcast;
/**
* 警报器(警笛)设置
*/
@JsonProperty("siren_alarm")
private SirenAlarm sirenAlarm;
/**
* LED爆闪设置
*/
@JsonProperty("led_strobe")
private LedStrobe ledStrobe;
/**
* 音量设置0-100范围
*/
@JsonProperty("volume")
private Integer volume;
/**
* 亮度设置RGB三色亮度值
*/
@JsonProperty("brightness")
private Brightness brightness;
}
/**
* 警报器(警笛)设置
*/
@lombok.Data
public static class SirenAlarm {
/**
* 是否启用0-禁用1-启用
*/
@JsonProperty("enable")
private Integer enable;
/**
* 工作模式0-默认模式,其他值表示不同报警模式
*/
@JsonProperty("mode")
private Integer mode;
}
/**
* LED爆闪设置
*/
@lombok.Data
public static class LedStrobe {
/**
* 是否启用0-禁用1-启用
*/
@JsonProperty("enable")
private Integer enable;
/**
* 工作模式0-默认模式,其他值表示不同爆闪模式
*/
@JsonProperty("mode")
private Integer mode;
/**
* 爆闪频率单位Hz或自定义单位
*/
@JsonProperty("frequency")
private Integer frequency;
}
/**
* 亮度设置RGB三色
*/
@lombok.Data
public static class Brightness {
/**
* 红色通道亮度值0-255或百分比
*/
@JsonProperty("red")
private Integer red;
/**
* 绿色通道亮度值0-255或百分比
*/
@JsonProperty("green")
private Integer green;
/**
* 蓝色通道亮度值0-255或百分比
*/
@JsonProperty("blue")
private Integer blue;
}
}

View File

@ -0,0 +1,59 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 更新设备语音
*/
@Data
public class FuncType5UpdateVoiceReport {
/**
* 设备IMEI号国际移动设备识别码
*/
private String imei;
/**
* 功能类型编码("5" 表示操作状态上报)
*/
private String funcType;
/**
* 响应状态码("200" 表示请求成功)
*/
private String status;
/**
* 时间戳毫秒级Unix时间戳
*/
private Long timestamp;
/**
* 操作详细状态数据
*/
private Data data;
/**
* 操作状态数据内部类
*/
@lombok.Data
public static class Data {
/**
* 操作执行状态:
* 0 - 未开始 / 失败
* 1 - 执行中
* 2 - 成功完成
* (具体含义需结合业务协议定义)
*/
@JsonProperty("status")
private Integer status;
/**
* 操作进度百分比0-100仅在 status=1执行中时有效
*/
@JsonProperty("progress")
private Integer progress;
}
}

View File

@ -0,0 +1,60 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 语音资源配置请求DTO
* 对应 funcType="5" 的语音资源下发指令(如语音播报文件配置)
*/
@Data
public class FuncType5UpdateVoiceRequest {
/**
* 请求唯一标识符(用于链路追踪或幂等处理)
*/
@JsonProperty("requestId")
private String requestId;
/**
* 设备IMEI号国际移动设备识别码
*/
private String imei;
/**
* 功能类型编码("5" 表示语音资源配置)
*/
private String funcType;
/**
* 时间戳毫秒级Unix时间戳
*/
private Long timestamp;
/**
* 语音配置数据
*/
private Data data;
/**
* 语音配置详情内部类
*/
@lombok.Data
public static class Data {
/**
* 语音类型:
* 0 - 默认语音(如标准提示音)
* 1 - 自定义语音
* 2 - 紧急语音
* (具体含义需依据设备协议定义)
*/
private Integer voiceType;
/**
* 语音资源URLMP3等音频文件地址
* 示例http://8.129.5.250:10001/voice/01.mp3
*/
private String voiceResource;
}
}

View File

@ -0,0 +1,49 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 语音播报开启/关闭
* 对应 funcType="6"
*/
@Data
public class FuncType6VoicePlayRequest {
/**
* 请求唯一标识符(用于链路追踪或幂等处理)
*/
@JsonProperty("requestId")
private String requestId;
/**
* 设备IMEI号国际移动设备识别码
*/
private String imei;
/**
* 功能类型编码
*/
private String funcType;
/**
* 时间戳毫秒级Unix时间戳
*/
private Long timestamp;
/**
* 语音配置数据
*/
private Data data;
/**
* 语音配置详情内部类
*/
@lombok.Data
public static class Data {
/**
* 语音报警0关闭,1开启
*/
private Integer voiceBroadcast;
}
}

View File

@ -0,0 +1,47 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 修改音量
* 对应 funcType="9"
*/
@Data
public class FuncType9UpdateVolumeRequest {
/**
* 请求唯一标识符(用于链路追踪或幂等处理)
*/
@JsonProperty("requestId")
private String requestId;
/**
* 设备IMEI号国际移动设备识别码
*/
private String imei;
/**
* 功能类型编码
*/
private String funcType;
/**
* 时间戳毫秒级Unix时间戳
*/
private Long timestamp;
/**
* 语音配置数据
*/
private Data data;
/**
* 语音配置详情内部类
*/
@lombok.Data
public static class Data {
//"volume": 1-100(app端可根据需求把40作为低音量, 70作为中音量100作为高音量)
private Integer volume;
}
}

View File

@ -0,0 +1,56 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 设备位置上报DTO
* 对应MQTT消息中设备上报的地理位置数据
*/
@Data
public class FunctionType3LocationReport {
/**
* 设备IMEI号国际移动设备识别码
*/
private String imei;
/**
* 功能类型编码(如"3"表示位置上报)
*/
private String funcType;
/**
* 响应状态码(如"200"表示成功)
*/
private String status;
/**
* 时间戳毫秒级Unix时间戳
*/
private Long timestamp;
/**
* 位置详细数据
*/
private Data data;
/**
* 位置详细数据内部类
*/
@lombok.Data
public static class Data {
/**
* 经度WGS-84坐标系如22.543100
*/
@JsonProperty("longitude")
private Double longitude;
/**
* 纬度WGS-84坐标系如114.057900
*/
@JsonProperty("latitude")
private Double latitude;
}
}

View File

@ -0,0 +1,74 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 设备电源状态上报DTO
* 对应MQTT消息中设备上报的电源相关状态数据
*/
@Data
public class FunctionType4PowerStatusReport {
/**
* 设备IMEI号国际移动设备识别码
*/
private String imei;
/**
* 功能类型编码(如"4"表示电源状态上报)
*/
private String funcType;
/**
* 响应状态码(如"200"表示成功)
*/
private String status;
/**
* 时间戳毫秒级Unix时间戳
*/
private Long timestamp;
/**
* 电源详细状态数据
*/
private Data data;
/**
* 电源详细状态数据内部类
*/
@lombok.Data
public static class Data {
/**
* 电池容量(如"5000mAh"
*/
@JsonProperty("capacity")
private String capacity;
/**
* 电压值单位V0表示未检测或无电
*/
@JsonProperty("voltage")
private Integer voltage;
/**
* 电量百分比0-1000表示低电量或未检测
*/
@JsonProperty("level")
private Integer level;
/**
* 充电状态0-未充电1-正在充电
*/
@JsonProperty("charge")
private Integer charge;
/**
* 12V电源状态0-关闭/无输出1-开启/有输出
*/
@JsonProperty("12v_power")
private Integer twelveVPower;
}
}

View File

@ -0,0 +1,35 @@
package com.fuyuanshen.global.mqtt.rule.hby100j.domin;
import com.alibaba.fastjson2.JSONObject;
public class Test {
public static void main(String[] args) {
String a = "{\n" +
"\"imei\":\"868108070185303\",\n" +
"\"funcType\":\"14\",\n" +
"\"status\":\"200\",\n" +
"\"timestamp\":1770169375000,\n" +
"\"data\":{\n" +
"\"voice_broadcast\":0,\n" +
"\"siren_alarm\":{\n" +
"\"enable\":0,\n" +
"\"mode\":0\n" +
"},\n" +
"\"led_strobe\":{\n" +
"\"enable\":1,\n" +
"\"mode\":0,\n" +
"\"frequency\":0\n" +
"},\n" +
"\"volume\":0,\n" +
"\"brightness\":{\n" +
"\"red\":0,\n" +
"\"green\":0,\n" +
"\"blue\":0\n" +
"}\n" +
"}\n" +
"}";
FuncType14StatusReport deviceStatusReport = JSONObject.parseObject(a, FuncType14StatusReport.class);
System.out.println(deviceStatusReport);
System.out.println("hello world");
}
}

View File

@ -0,0 +1,24 @@
package com.fuyuanshen.global.mqtt.utils;
import java.util.Random;
import java.util.UUID;
public class GenerateIdUtil {
/**
* 生成数字唯一ID - 基于UUID
*/
public static String generateNumericId() {
UUID uuid = UUID.randomUUID();
return Math.abs(uuid.toString().hashCode()) + "";
}
/**
* 生成数字唯一ID - 基于时间戳+随机数
*/
public static long generateTimestampBasedId() {
long timestamp = System.currentTimeMillis();
int random = new Random().nextInt(1000); // 0-999随机数
return timestamp * 1000 + random;
}
}

View File

@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fuyuanshen.app.controller.device.bjq.AppDeviceHBY100JController;
import com.fuyuanshen.app.domain.AppBusinessFile;
import com.fuyuanshen.app.domain.AppPersonnelInfo;
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
@ -21,10 +22,12 @@ import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
import com.fuyuanshen.app.mapper.AppPersonnelInfoRecordsMapper;
import com.fuyuanshen.app.service.IAppBusinessFileService;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.domain.model.LoginUser;
import com.fuyuanshen.common.core.exception.ServiceException;
import com.fuyuanshen.common.core.utils.*;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
@ -35,6 +38,11 @@ import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
import com.fuyuanshen.global.mqtt.config.MqttGateway;
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
import com.fuyuanshen.global.mqtt.rule.hby100j.domin.*;
import com.fuyuanshen.global.mqtt.utils.GenerateIdUtil;
import com.fuyuanshen.system.domain.SysOss;
import com.fuyuanshen.system.domain.vo.SysOssVo;
import com.fuyuanshen.system.mapper.SysOssMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
@ -63,8 +71,10 @@ public class DeviceHBY100JBizService {
private final DeviceLogMapper deviceLogMapper;
private final IAppBusinessFileService appBusinessFileService;
private final AppBusinessFileMapper appBusinessFileMapper;
private final SysOssMapper sysOssMapper;
private static final String DEVICE_TYPE = "HBY100/";
/**
* 记录设备操作日志
*
@ -141,16 +151,16 @@ public class DeviceHBY100JBizService {
// 获取经度纬度
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
String locationInfo = RedisUtils.getCacheObject(locationKey);
if (StringUtils.isNotBlank(locationInfo)) {
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
vo.setLongitude(jsonObject.get("longitude").toString());
vo.setLatitude(jsonObject.get("latitude").toString());
vo.setAddress((String) jsonObject.get("address"));
}
// if (StringUtils.isNotBlank(locationInfo)) {
// JSONObject jsonObject = JSONObject.parseObject(locationInfo);
// vo.setLongitude(jsonObject.get("longitude").toString());
// vo.setLatitude(jsonObject.get("latitude").toString());
// vo.setAddress((String) jsonObject.get("address"));
// }
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
if (StringUtils.isNotBlank(alarmStatus)) {
vo.setAlarmStatus(alarmStatus);
vo.setVoiceStrobeAlarm(alarmStatus);
}
String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
@ -168,26 +178,163 @@ public class DeviceHBY100JBizService {
}
public void forceAlarmActivation(AppDeviceSendMsgBo bo) {
public void forceAlarmActivation(AppDeviceHBY100JController.HBY100JForceAlarmActivationDto bo) {
List<Long> deviceIds = bo.getDeviceIds();
if (deviceIds == null || deviceIds.isEmpty()) {
throw new ServiceException("请选择设备");
}
LoginUser loginUser = LoginHelper.getLoginUser();
bo.getDeviceIds().forEach(deviceId -> {
Device deviceObj = deviceMapper.selectById(deviceId);
// if (getDeviceStatus(deviceObj.getDeviceImei())) {
// throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
// }
// 语音播报
if(bo.getMode() == 9){
FuncType6VoicePlayRequest request = new FuncType6VoicePlayRequest();
request.setRequestId(GenerateIdUtil.generateNumericId());
request.setImei(deviceObj.getDeviceImei());
request.setFuncType("12");
request.setTimestamp(System.currentTimeMillis());
FuncType6VoicePlayRequest.Data data = new FuncType6VoicePlayRequest.Data();
data.setVoiceBroadcast(bo.getVoiceStrobeAlarm());
request.setData(data);
log.info("HBY100J更新语音参数{}", request);
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
}else{
FuncType12ForceAudioRequest request = new FuncType12ForceAudioRequest();
request.setRequestId(GenerateIdUtil.generateNumericId());
request.setImei(deviceObj.getDeviceImei());
request.setFuncType("12");
request.setTimestamp(System.currentTimeMillis());
FuncType12ForceAudioRequest.Data data = new FuncType12ForceAudioRequest.Data();
data.setVoiceStrobeAlarm(bo.getVoiceStrobeAlarm());
data.setMode(bo.getMode());
request.setData(data);
log.info("HBY100J更新语音参数{}", request);
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
}
// recordDeviceLog(deviceId, deviceObj.getDeviceName(), "强制报警激活", "强制报警激活", loginUser.getUserId());
});
}
public void updateVoice(Long id) {
AppBusinessFileVo appBusinessFileVo = appBusinessFileMapper.selectVoById(id);
public void updateVoice(AppDeviceHBY100JController.HBY100JUpdateVoiceDto dto) {
AppBusinessFileVo appBusinessFileVo = appBusinessFileMapper.selectVoById(dto.getId());
if(appBusinessFileVo == null){
throw new ServiceException("文件不存在");
}
Device deviceObj = deviceMapper.selectById(appBusinessFileVo.getBusinessId());
// if (getDeviceStatus(deviceObj.getDeviceImei())) {
// throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
// }
LoginUser loginUser = LoginHelper.getLoginUser();
SysOssVo sysOssVo = sysOssMapper.selectVoById(appBusinessFileVo.getFileId());
FuncType5UpdateVoiceRequest request = new FuncType5UpdateVoiceRequest();
request.setRequestId(GenerateIdUtil.generateNumericId());
request.setImei(deviceObj.getDeviceImei());
request.setFuncType("5");
request.setTimestamp(System.currentTimeMillis());
FuncType5UpdateVoiceRequest.Data data = new FuncType5UpdateVoiceRequest.Data();
data.setVoiceResource(sysOssVo.getUrl());
data.setVoiceType(0);
request.setData(data);
log.info("HBY100J更新语音参数{}", request);
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
UpdateWrapper<AppBusinessFile> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("business_id", appBusinessFileVo.getBusinessId());
updateWrapper.set("use_status", 0);
appBusinessFileMapper.update(updateWrapper);
AppBusinessFileBo bo = new AppBusinessFileBo();
bo.setId(id);
bo.setUseStatus(1);
appBusinessFileService.updateByBo(bo);
UpdateWrapper<AppBusinessFile> updateWrapper2 = new UpdateWrapper<>();
updateWrapper2.eq("id", appBusinessFileVo.getId());
updateWrapper2.set("use_status", 1);
appBusinessFileMapper.update(updateWrapper2);
}
private String buildMqttTopic(String deviceImei) {
String tenantId = LoginHelper.getTenantId();
return MqttConstants.GLOBAL_PUB_KEY2 +tenantId + "/" + DEVICE_TYPE + deviceImei;
}
public void strobeMode(AppDeviceHBY100JController.HBY100JStrobeModeDto params) {
log.info("HBY100J爆闪模式开启/关闭,请求参数:{}", params);
Device deviceObj = deviceMapper.selectById(params.getDeviceId());
// if (getDeviceStatus(deviceObj.getDeviceImei())) {
// throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
// }
FuncType10StrobeModeRequest request = new FuncType10StrobeModeRequest();
request.setRequestId(GenerateIdUtil.generateNumericId());
request.setImei(deviceObj.getDeviceImei());
request.setFuncType("10");
request.setTimestamp(System.currentTimeMillis());
FuncType10StrobeModeRequest.Data data = new FuncType10StrobeModeRequest.Data();
data.setMode(params.getMode());
data.setEnable(params.getEnable());
request.setData(data);
log.info("HBY100J爆闪模式开启/关闭,下发设备参数:{}", request);
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
}
public void lightAdjustment(AppDeviceHBY100JController.HBY100JLightAdjustmentDto params) {
log.info("HBY100J灯光调节请求参数{}", params);
Device deviceObj = deviceMapper.selectById(params.getDeviceId());
// if (getDeviceStatus(deviceObj.getDeviceImei())) {
// throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
// }
FuncType13BrightnessRequest request = new FuncType13BrightnessRequest();
request.setRequestId(GenerateIdUtil.generateNumericId());
request.setImei(deviceObj.getDeviceImei());
request.setFuncType("13");
request.setTimestamp(System.currentTimeMillis());
FuncType13BrightnessRequest.Data data = new FuncType13BrightnessRequest.Data();
data.setRed(params.getBrightness());
data.setBlue(params.getBrightness());
data.setYellow(params.getBrightness());
request.setData(data);
log.info("HBY100J灯光调节下发设备参数{}", request);
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
}
public void strobeFrequency(AppDeviceHBY100JController.HBY100JStrobeFrequencyDto params) {
log.info("HBY100J爆闪频率请求参数{}", params);
Device deviceObj = deviceMapper.selectById(params.getDeviceId());
// if (getDeviceStatus(deviceObj.getDeviceImei())) {
// throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
// }
FuncType11FrequencyRequest request = new FuncType11FrequencyRequest();
request.setRequestId(GenerateIdUtil.generateNumericId());
request.setImei(deviceObj.getDeviceImei());
request.setFuncType("11");
request.setTimestamp(System.currentTimeMillis());
FuncType11FrequencyRequest.Data data = new FuncType11FrequencyRequest.Data();
data.setFrequency(params.getFrequency());
request.setData(data);
log.info("HBY100J灯光调节下发设备参数{}", request);
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
}
public void updateVolume(AppDeviceHBY100JController.HBY100JUpdateVolumeDto params) {
log.info("HBY100J更新音量请求参数{}", params);
Device deviceObj = deviceMapper.selectById(params.getDeviceId());
// if (getDeviceStatus(deviceObj.getDeviceImei())) {
// throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
// }
FuncType9UpdateVolumeRequest request = new FuncType9UpdateVolumeRequest();
request.setRequestId(GenerateIdUtil.generateNumericId());
request.setImei(deviceObj.getDeviceImei());
request.setFuncType("9");
request.setTimestamp(System.currentTimeMillis());
FuncType9UpdateVolumeRequest.Data data = new FuncType9UpdateVolumeRequest.Data();
data.setVolume(params.getVolume());
request.setData(data);
log.info("HBY100J更新音量下发设备参数{}", JSON.toJSONString(request));
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
}
}