灯光模式 5
This commit is contained in:
@ -78,9 +78,9 @@ public interface DeviceBJQ6075BizService {
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
||||
* (主光模式)
|
||||
* 0(关闭灯光),1(强光),2(超强光), 3(工作光), 4(节能光),5(爆闪),6(SOS)
|
||||
*/
|
||||
|
||||
public void lightModeSettings(DeviceInstructDto params);
|
||||
|
||||
// 灯光亮度设置
|
||||
|
||||
@ -27,9 +27,12 @@ import com.fuyuanshen.equipment.enums.LightModeEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
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.constants.DeviceRedisKeyConstants;
|
||||
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 lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -60,6 +63,8 @@ public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
|
||||
private final MqttGateway mqttGateway;
|
||||
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(爆闪),6(SOS)
|
||||
*/
|
||||
@Override
|
||||
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 {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
@ -430,6 +490,7 @@ public class DeviceBJQ6075BizServiceImpl implements DeviceBJQ6075BizService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 灯光亮度设置
|
||||
@Override
|
||||
public void lightBrightnessSettings(DeviceInstructDto params) {
|
||||
|
||||
Reference in New Issue
Block a user