灯光模式 5

This commit is contained in:
2025-11-10 10:37:03 +08:00
parent 92df1c8668
commit 1be80be309
8 changed files with 234 additions and 75 deletions

View File

@ -31,6 +31,7 @@ public class AppDeviceBJQController extends BaseController {
private final DeviceBJQBizService appDeviceService; private final DeviceBJQBizService appDeviceService;
/** /**
* 获取设备详细信息 * 获取设备详细信息
* *
@ -86,7 +87,6 @@ public class AppDeviceBJQController extends BaseController {
} }
/** /**
* 灯光模式 * 灯光模式
* 0关灯1强光模式2弱光模式, 3爆闪模式, 4泛光模式 * 0关灯1强光模式2弱光模式, 3爆闪模式, 4泛光模式

View File

@ -11,7 +11,6 @@ import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation
import com.fuyuanshen.common.web.core.BaseController; import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo; import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService; import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService;
import com.fuyuanshen.web.service.device.DeviceBJQBizService;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -27,7 +26,6 @@ import org.springframework.web.multipart.MultipartFile;
@RequestMapping("/app/bjq6075/device") @RequestMapping("/app/bjq6075/device")
public class AppDeviceBJQ6075Controller extends BaseController { public class AppDeviceBJQ6075Controller extends BaseController {
private final DeviceBJQBizService appDeviceService;
private final DeviceBJQ6075BizService appDeviceService6075; private final DeviceBJQ6075BizService appDeviceService6075;
@ -44,33 +42,36 @@ public class AppDeviceBJQ6075Controller extends BaseController {
/** /**
* 人员信息登记 * 人员信息登记 1
*/ */
@PostMapping(value = "/registerPersonInfo") @PostMapping(value = "/registerPersonInfo")
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) { public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
return toAjax(appDeviceService.registerPersonInfo(bo)); return toAjax(appDeviceService6075.registerPersonInfo(bo));
} }
/** /**
* 发送信息 * 发送信息 2
*/ */
@PostMapping(value = "/sendMessage") @PostMapping(value = "/sendMessage")
@FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40) @FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) { public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService.sendMessage(bo)); return toAjax(appDeviceService6075.sendMessage(bo));
} }
/** /**
* 发送报警信息 * 发送报警信息 3
*/ */
@PostMapping(value = "/sendAlarmMessage") @PostMapping(value = "/sendAlarmMessage")
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10) @FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) { public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService.sendAlarmMessage(bo)); return toAjax(appDeviceService6075.sendAlarmMessage(bo));
} }
/** /**
* 上传设备logo图片 * 上传设备logo图片 4
*/ */
@PostMapping("/uploadLogo") @PostMapping("/uploadLogo")
@FunctionAccessAnnotation("uploadLogo") @FunctionAccessAnnotation("uploadLogo")
@ -80,61 +81,62 @@ public class AppDeviceBJQ6075Controller extends BaseController {
if (file.getSize() > 1024 * 1024 * 2) { if (file.getSize() > 1024 * 1024 * 2) {
return R.warn("图片不能大于2M"); return R.warn("图片不能大于2M");
} }
appDeviceService.uploadDeviceLogo(bo); appDeviceService6075.uploadDeviceLogo(bo);
return R.ok(); return R.ok();
} }
/** /**
* 灯光模式 * 灯光模式 5
* (主光模式) * (主光模式)
* 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS * 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS
*/ */
@PostMapping("/lightModeSettings") @PostMapping("/lightModeSettings")
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) { public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.lightModeSettings(params); appDeviceService6075.lightModeSettings(params);
return R.ok(); return R.ok();
} }
/** /**
* 灯光模式 * 灯光模式 6
* (辅光模式) * (辅光模式)
* 0关闭灯光1泛光2泛光爆闪, 3警示灯, 4警示灯/泛光) * 0关闭灯光1泛光2泛光爆闪, 3警示灯, 4警示灯/泛光)
*/ */
@PostMapping("/auxiliaryLightModeSettings") @PostMapping("/auxiliaryLightModeSettings")
public R<Void> auxiliaryLightModeSettings(@RequestBody DeviceInstructDto params) { public R<Void> auxiliaryLightModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.lightModeSettings(params); appDeviceService6075.lightModeSettings(params);
return R.ok(); return R.ok();
} }
/** /**
* 灯光亮度设置 * 灯光亮度设置 7
*/ */
@PostMapping("/lightBrightnessSettings") @PostMapping("/lightBrightnessSettings")
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) { public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.lightBrightnessSettings(params); appDeviceService6075.lightBrightnessSettings(params);
return R.ok(); return R.ok();
} }
/** /**
* 激光模式设置 * 激光模式设置 8
*/ */
@PostMapping("/laserModeSettings") @PostMapping("/laserModeSettings")
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) { public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.laserModeSettings(params); appDeviceService6075.laserModeSettings(params);
return R.ok(); return R.ok();
} }
/** /**
* 声光报警模式设置 * 声光报警模式设置 9
* Sound and light alarm * Sound and light alarm
*/ */
@PostMapping("/salaModeSettings") @PostMapping("/salaModeSettings")
public R<Void> salaModeSettings(@RequestBody DeviceInstructDto params) { public R<Void> salaModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.laserModeSettings(params); appDeviceService6075.laserModeSettings(params);
return R.ok(); return R.ok();
} }

View File

@ -9,6 +9,7 @@ import java.util.List;
*/ */
@Data @Data
public class MqttMessage { public class MqttMessage {
/** /**
* 请求ID用于匹配请求和响应 * 请求ID用于匹配请求和响应
*/ */
@ -27,7 +28,7 @@ public class MqttMessage {
/** /**
* 功能类型 * 功能类型
*/ */
private String funcType; private Integer funcType;
/** /**
* 数据内容 * 数据内容
@ -43,4 +44,5 @@ public class MqttMessage {
* 批量数据(设备上报时使用) * 批量数据(设备上报时使用)
*/ */
private List<SensorData> batch; private List<SensorData> batch;
} }

View File

@ -0,0 +1,82 @@
package com.fuyuanshen.global.mqtt.enums;
/**
* 设备功能类型枚举
* 基于AppDeviceBJQ6075Controller中的功能注释1-9设计
*/
public enum DeviceFunctionType6075 {
/**
* 人员信息登记
*/
REGISTER_PERSON_INFO(1, "REGISTER_PERSON_INFO", "人员信息登记"),
/**
* 发送信息
*/
SEND_MESSAGE(2, "SEND_MESSAGE", "发送信息"),
/**
* 发送报警信息
*/
SEND_ALARM_MESSAGE(3, "SEND_ALARM_MESSAGE", "发送报警信息"),
/**
* 上传设备logo图片
*/
UPLOAD_LOGO(4, "UPLOAD_LOGO", "上传设备logo图片"),
/**
* 灯光模式(主光模式)
* 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS
*/
LIGHT_MODE(5, "LIGHT_MODE", "灯光模式"),
/**
* 灯光模式(辅光模式)
* 0关闭灯光1泛光2泛光爆闪, 3警示灯, 4警示灯/泛光)
*/
AUXILIARY_LIGHT_MODE(6, "AUXILIARY_LIGHT_MODE", "辅光模式"),
/**
* 灯光亮度设置
*/
LIGHT_BRIGHTNESS(7, "LIGHT_BRIGHTNESS", "灯光亮度设置"),
/**
* 激光模式设置
*/
LASER_MODE(8, "LASER_MODE", "激光模式设置"),
/**
* 声光报警模式设置
*/
SOUND_AND_LIGHT_ALARM(9, "SOUND_AND_LIGHT_ALARM", "声光报警模式设置");
private final int number;
private final String code;
private final String description;
DeviceFunctionType6075(int number, String code, String description) {
this.number = number;
this.code = code;
this.description = description;
}
public int getNumber() {
return number;
}
public String getCode() {
return code;
}
public String getDescription() {
return description;
}
@Override
public String toString() {
return code;
}
}

View File

@ -1,6 +1,7 @@
package com.fuyuanshen.global.mqtt.service; package com.fuyuanshen.global.mqtt.service;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.global.mqtt.base.MqttMessage;
/** /**
* 通用IoT设备MQTT协议服务接口 * 通用IoT设备MQTT协议服务接口
@ -10,15 +11,17 @@ public interface IotMqttService {
/** /**
* 构建下发指令主题 * 构建下发指令主题
*
* @param tenantCode 租户编码 * @param tenantCode 租户编码
* @param deviceType 设备类型 * @param deviceType 设备类型
* @param imei 设备IMEI * @param imei 设备IMEI
* @return 指令主题 * @return 指令主题
*/ */
String buildCommandTopic(String tenantCode, String deviceType, String imei); String buildCommandTopic(String tenantCode, Long deviceType, String imei);
/** /**
* 构建响应数据主题 * 构建响应数据主题
*
* @param tenantCode 租户编码 * @param tenantCode 租户编码
* @param deviceType 设备类型 * @param deviceType 设备类型
* @param imei 设备IMEI * @param imei 设备IMEI
@ -28,6 +31,7 @@ public interface IotMqttService {
/** /**
* 构建设备上报数据主题 * 构建设备上报数据主题
*
* @param tenantCode 租户编码 * @param tenantCode 租户编码
* @param deviceType 设备类型 * @param deviceType 设备类型
* @param imei 设备IMEI * @param imei 设备IMEI
@ -37,15 +41,17 @@ public interface IotMqttService {
/** /**
* 发送指令到设备 * 发送指令到设备
*
* @param tenantCode 租户编码 * @param tenantCode 租户编码
* @param deviceType 设备类型 * @param deviceType 设备类型
* @param imei 设备IMEI * @param imei 设备IMEI
* @param message 指令消息 (JSON格式) * @param message 指令消息 (JSON格式)
*/ */
void sendCommand(String tenantCode, String deviceType, String imei, JSONObject message); void sendCommand(String tenantCode, Long deviceType, String imei, MqttMessage message);
/** /**
* 发送响应消息到设备 * 发送响应消息到设备
*
* @param tenantCode 租户编码 * @param tenantCode 租户编码
* @param deviceType 设备类型 * @param deviceType 设备类型
* @param imei 设备IMEI * @param imei 设备IMEI
@ -55,6 +61,7 @@ public interface IotMqttService {
/** /**
* 发送设备上报数据的确认消息 * 发送设备上报数据的确认消息
*
* @param tenantCode 租户编码 * @param tenantCode 租户编码
* @param deviceType 设备类型 * @param deviceType 设备类型
* @param imei 设备IMEI * @param imei 设备IMEI
@ -64,6 +71,7 @@ public interface IotMqttService {
/** /**
* 处理设备上报的单个传感器数据 * 处理设备上报的单个传感器数据
*
* @param tenantCode 租户编码 * @param tenantCode 租户编码
* @param deviceType 设备类型 * @param deviceType 设备类型
* @param imei 设备IMEI * @param imei 设备IMEI
@ -76,6 +84,7 @@ public interface IotMqttService {
/** /**
* 处理设备上报的批量传感器数据 * 处理设备上报的批量传感器数据
*
* @param tenantCode 租户编码 * @param tenantCode 租户编码
* @param deviceType 设备类型 * @param deviceType 设备类型
* @param imei 设备IMEI * @param imei 设备IMEI
@ -87,6 +96,7 @@ public interface IotMqttService {
/** /**
* 处理设备对指令的响应 * 处理设备对指令的响应
*
* @param tenantCode 租户编码 * @param tenantCode 租户编码
* @param deviceType 设备类型 * @param deviceType 设备类型
* @param imei 设备IMEI * @param imei 设备IMEI

View File

@ -2,6 +2,7 @@ package com.fuyuanshen.global.mqtt.service.impl;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.global.mqtt.base.MqttMessage;
import com.fuyuanshen.global.mqtt.service.IotMqttService; import com.fuyuanshen.global.mqtt.service.IotMqttService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -27,7 +28,7 @@ public class IotMqttServiceImpl implements IotMqttService {
private static final String REPORT_PREFIX = "report"; private static final String REPORT_PREFIX = "report";
@Override @Override
public String buildCommandTopic(String tenantCode, String deviceType, String imei) { public String buildCommandTopic(String tenantCode, Long deviceType, String imei) {
return String.format("%s/%s/%s/%s", COMMAND_PREFIX, tenantCode, deviceType, imei); return String.format("%s/%s/%s/%s", COMMAND_PREFIX, tenantCode, deviceType, imei);
} }
@ -42,9 +43,9 @@ public class IotMqttServiceImpl implements IotMqttService {
} }
@Override @Override
public void sendCommand(String tenantCode, String deviceType, String imei, JSONObject message) { public void sendCommand(String tenantCode, Long deviceType, String imei, MqttMessage message) {
String topic = buildCommandTopic(tenantCode, deviceType, imei); String topic = buildCommandTopic(tenantCode, deviceType, imei);
String payload = message.toJSONString(); String payload = JSON.toJSONString(message);
sendMqttMessage(topic, 1, payload); sendMqttMessage(topic, 1, payload);
log.info("发送指令到设备: topic={}, payload={}", topic, payload); log.info("发送指令到设备: topic={}, payload={}", topic, payload);
} }
@ -93,6 +94,7 @@ public class IotMqttServiceImpl implements IotMqttService {
/** /**
* 通过反射方式发送MQTT消息 * 通过反射方式发送MQTT消息
*
* @param topic 主题 * @param topic 主题
* @param qos 服务质量等级 * @param qos 服务质量等级
* @param payload 消息内容 * @param payload 消息内容

View File

@ -78,9 +78,9 @@ public interface DeviceBJQ6075BizService {
/** /**
* 灯光模式 * 灯光模式
* 0关灯1强光模式2弱光模式, 3爆闪模式, 4光模式) * (主光模式)
* 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS
*/ */
public void lightModeSettings(DeviceInstructDto params); public void lightModeSettings(DeviceInstructDto params);
// 灯光亮度设置 // 灯光亮度设置

View File

@ -27,9 +27,12 @@ import com.fuyuanshen.equipment.enums.LightModeEnum;
import com.fuyuanshen.equipment.mapper.DeviceLogMapper; import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
import com.fuyuanshen.equipment.mapper.DeviceMapper; import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper; import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
import com.fuyuanshen.global.mqtt.base.MqttMessage;
import com.fuyuanshen.global.mqtt.config.MqttGateway; import com.fuyuanshen.global.mqtt.config.MqttGateway;
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants; import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
import com.fuyuanshen.global.mqtt.constants.MqttConstants; import com.fuyuanshen.global.mqtt.constants.MqttConstants;
import com.fuyuanshen.global.mqtt.enums.DeviceFunctionType6075;
import com.fuyuanshen.global.mqtt.service.IotMqttService;
import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService; import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -60,6 +63,8 @@ public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
private final MqttGateway mqttGateway; private final MqttGateway mqttGateway;
private final DeviceLogMapper deviceLogMapper; private final DeviceLogMapper deviceLogMapper;
private final IotMqttService iotMqttService;
/** /**
* 获取设备详情 * 获取设备详情
@ -396,12 +401,67 @@ public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
} }
} }
/** /**
* 灯光模式 * 灯光模式
* 0关灯1强光模式2弱光模式, 3爆闪模式, 4光模式) * (主光模式)
* 0关闭灯光1强光2超强光, 3工作光, 4节能光5爆闪6SOS
*/ */
@Override @Override
public void lightModeSettings(DeviceInstructDto params) { public void lightModeSettings(DeviceInstructDto params) {
try {
Long deviceId = params.getDeviceId();
Device device = deviceMapper.selectById(deviceId);
if (device == null) {
throw new ServiceException("设备不存在");
}
if (getDeviceStatus(device.getDeviceImei())) {
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
}
String deviceImei = device.getDeviceImei();
Long deviceType = device.getDeviceType();
String tenantCode = device.getTenantId();
// 构建发送强光模式的MqttMessage对象
MqttMessage message = new MqttMessage();
message.setRequestId(UUID.randomUUID().toString()); // 生成唯一的请求ID
message.setImei(device.getDeviceImei()); // 设备IMEI
message.setTimestamp(System.currentTimeMillis()); // 当前时间戳
message.setFuncType(DeviceFunctionType6075.LIGHT_MODE.getNumber()); // 功能类型,这里假设为灯光模式
// 构建数据内容 - 强光模式参数
Map<String, Object> lightData = new HashMap<>();
lightData.put("mode", 1); // 1表示强光模式
lightData.put("type", "mainLight"); // 主灯类型
// 可以根据需要添加更多参数
lightData.put("brightness", 100); // 亮度设置为100%
message.setData(lightData);
// 调用sendCommand方法发送指令
iotMqttService.sendCommand(tenantCode, deviceType, deviceImei, message);
Integer instructValue = Integer.parseInt(params.getInstructValue());
ArrayList<Integer> intData = new ArrayList<>();
intData.add(1);
intData.add(instructValue);
intData.add(0);
intData.add(0);
intData.add(0);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
LightModeEnum modeEnum = LightModeEnum.getByCode(instructValue);
recordDeviceLog(device.getId(), device.getDeviceName(), "灯光模式", modeEnum != null ? modeEnum.getName() : null, AppLoginHelper.getUserId());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException("发送指令失败");
}
}
public void lightModeSettings1(DeviceInstructDto params) {
try { try {
Long deviceId = params.getDeviceId(); Long deviceId = params.getDeviceId();
Device device = deviceMapper.selectById(deviceId); Device device = deviceMapper.selectById(deviceId);
@ -430,6 +490,7 @@ public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
} }
} }
// 灯光亮度设置 // 灯光亮度设置
@Override @Override
public void lightBrightnessSettings(DeviceInstructDto params) { public void lightBrightnessSettings(DeviceInstructDto params) {