forked from dyf/fys-Multi-tenant
修改在线上报状态
This commit is contained in:
@ -1,318 +1,318 @@
|
||||
package com.fuyuanshen.web.handler.mqtt;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceLog;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
|
||||
import com.fuyuanshen.equipment.utils.map.LngLonUtil;
|
||||
import com.fuyuanshen.global.mqtt.constants.TenantsConstant;
|
||||
import com.fuyuanshen.web.enums.InstructType6170;
|
||||
import com.fuyuanshen.web.enums.LightModeEnum6170;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 定义监听主题消息的处理器
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-08-0110:19
|
||||
*/
|
||||
@Component
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class DeviceReceiverMessageHandler implements MessageHandler {
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
|
||||
// 使用Jackson解析JSON
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
/**
|
||||
* 处理接收的消息
|
||||
*
|
||||
* @param message
|
||||
* @throws MessagingException
|
||||
*/
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
// System.out.println("接收到的消息:" + message.getPayload());
|
||||
MessageHeaders headers = message.getHeaders();
|
||||
String receivedTopicName = (String) headers.get("mqtt_receivedTopic");
|
||||
System.out.println("消息来自主题:" + receivedTopicName);
|
||||
|
||||
// String tenantId = LoginHelper.getTenantId();
|
||||
String tenantId = TenantsConstant.FU_YUAN_SHENG;
|
||||
String payload = message.getPayload().toString();
|
||||
|
||||
if (receivedTopicName != null) {
|
||||
// 1. 提取设备ID (从主题中获取)
|
||||
String deviceImei = extractDeviceId(receivedTopicName);
|
||||
Device device = deviceMapper.selectOne(new QueryWrapper<Device>()
|
||||
.eq("tenant_id", tenantId)
|
||||
.eq("device_imei", deviceImei));
|
||||
if (device == null) {
|
||||
log.info("不存在的设备IMEI: {}", deviceImei);
|
||||
} else {
|
||||
|
||||
try {
|
||||
JsonNode root = objectMapper.readTree(payload);
|
||||
|
||||
DeviceLog record = new DeviceLog();
|
||||
// 手动设置租户ID
|
||||
record.setTenantId(device.getTenantId()); // 从设备信息中获取租户ID
|
||||
// 设备ID
|
||||
record.setDeviceId(device.getId());
|
||||
// 设备名称
|
||||
record.setDeviceName(device.getDeviceName());
|
||||
|
||||
// 2. 处理instruct消息
|
||||
if (root.has("instruct")) {
|
||||
JsonNode instructNode = root.get("instruct");
|
||||
if (instructNode.isArray()) {
|
||||
boolean b = receivedTopicName.startsWith("B/");
|
||||
record = parseInstruct(device, instructNode, b);
|
||||
// 根据不同主题进行不同处理
|
||||
if (receivedTopicName.startsWith("A/")) {
|
||||
// 处理A主题的消息(设备上传)
|
||||
record.setDataSource("设备上报");
|
||||
} else if (receivedTopicName.startsWith("B/")) {
|
||||
// 处理B主题的消息 (手动上传)
|
||||
record.setDataSource("客户端操作");
|
||||
}
|
||||
}
|
||||
// 确保在插入前设置tenantId和deviceId
|
||||
record.setTenantId(device.getTenantId());
|
||||
record.setDeviceId(device.getId());
|
||||
deviceLogMapper.insert(record);
|
||||
}
|
||||
|
||||
// 2. 处理 state 消息
|
||||
if (root.has("state")) {
|
||||
JsonNode instructNode = root.get("state");
|
||||
if (instructNode.isArray()) {
|
||||
boolean b = receivedTopicName.startsWith("B/");
|
||||
record = parseState(device, instructNode, b);
|
||||
// 根据不同主题进行不同处理
|
||||
if (receivedTopicName.startsWith("A/")) {
|
||||
// 处理A主题的消息(设备上传)
|
||||
record.setDataSource("设备上报");
|
||||
} else if (receivedTopicName.startsWith("B/")) {
|
||||
// 处理B主题的消息 (手动上传)
|
||||
record.setDataSource("客户端操作");
|
||||
}
|
||||
}
|
||||
// 确保在插入前设置tenantId和deviceId
|
||||
record.setTenantId(device.getTenantId());
|
||||
record.setDeviceId(device.getId());
|
||||
deviceLogMapper.insert(record);
|
||||
}
|
||||
|
||||
if (root.has("imei")) {
|
||||
// 设备行为
|
||||
record.setDeviceAction(InstructType6170.fromCode(0).getDescription());
|
||||
record.setDataSource("设备上报");
|
||||
record.setContent("设备启动");
|
||||
// 确保在插入前设置tenantId和deviceId
|
||||
record.setTenantId(device.getTenantId());
|
||||
record.setDeviceId(device.getId());
|
||||
deviceLogMapper.insert(record);
|
||||
}
|
||||
|
||||
|
||||
// 3. 处理state消息
|
||||
// else if (root.has("state")) {
|
||||
// JsonNode stateNode = root.get("state");
|
||||
// if (stateNode.isArray()) {
|
||||
// StateRecord record = parseState(device, stateNode);
|
||||
// stateRepo.save(record);
|
||||
// }
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
log.error("消息解析失败: {}", payload, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从主题中提取设备ID(IMEI)
|
||||
*
|
||||
* @param topic
|
||||
* @return
|
||||
*/
|
||||
private String extractDeviceId(String topic) {
|
||||
// 处理 A/# 或 B/# 格式的主题,例如 B/861556078765285 或 A/861556078765285
|
||||
String[] segments = topic.split("/");
|
||||
if (segments.length >= 2) {
|
||||
// 返回第二个段,即 / 后面的部分
|
||||
return segments[1];
|
||||
}
|
||||
// 如果格式不符合预期,返回原主题
|
||||
return topic;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析instruct消息
|
||||
*
|
||||
* @param device
|
||||
* @param array
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
private DeviceLog parseInstruct(Device device, JsonNode array, boolean b) {
|
||||
DeviceLog record = new DeviceLog();
|
||||
record.setDeviceName(device.getDeviceName());
|
||||
// 设备行为
|
||||
record.setDeviceAction(InstructType6170.fromCode(array.get(0).asInt()).getDescription());
|
||||
|
||||
switch (array.get(0).asInt()) {
|
||||
case 1: // 灯光模式
|
||||
LightModeEnum6170 lightModeEnum6170 = LightModeEnum6170.fromCode(array.get(1).asInt());
|
||||
record.setContent(lightModeEnum6170.getDescription());
|
||||
break;
|
||||
|
||||
case 2: // 单位/姓名/职位
|
||||
byte[] unitBytes = new byte[480];
|
||||
for (int i = 1; i <= 480; i++) {
|
||||
unitBytes[i - 1] = (byte) array.get(i).asInt();
|
||||
}
|
||||
// record.setUnitData(unitBytes);
|
||||
break;
|
||||
|
||||
case 3: // 开机图片
|
||||
// record.setImagePage(array.get(1).asInt());
|
||||
byte[] imageBytes = new byte[512];
|
||||
for (int i = 2; i <= 513; i++) {
|
||||
imageBytes[i - 2] = (byte) array.get(i).asInt();
|
||||
}
|
||||
// record.setImageData(imageBytes);
|
||||
break;
|
||||
|
||||
case 4: // 激光灯
|
||||
int anInt = array.get(1).asInt();
|
||||
if (anInt == 0) {
|
||||
record.setContent("关闭激光灯");
|
||||
} else if (anInt == 1) {
|
||||
record.setContent("开启激光灯");
|
||||
} else {
|
||||
record.setContent("未知操作");
|
||||
}
|
||||
break;
|
||||
|
||||
case 5: // 亮度调节
|
||||
record.setContent(+array.get(1).asInt() + "%");
|
||||
break;
|
||||
|
||||
case 11: // 定位数据
|
||||
if (b) {
|
||||
break;
|
||||
}
|
||||
int i1 = array.get(1).asInt();
|
||||
int i2 = array.get(2).asInt();
|
||||
int i3 = array.get(3).asInt();
|
||||
int i4 = array.get(4).asInt();
|
||||
|
||||
// 优雅的转换方式 Longitude and latitude
|
||||
double latitude = i1 + i2 / 10.0;
|
||||
double Longitude = i3 + i4 / 10.0;
|
||||
// 84 ==》 高德
|
||||
double[] doubles = LngLonUtil.gps84_To_Gcj02(latitude, Longitude);
|
||||
String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
|
||||
record.setContent(address);
|
||||
break;
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析 state 消息
|
||||
*
|
||||
* @param device
|
||||
* @param array
|
||||
* @return
|
||||
*/
|
||||
private DeviceLog parseState(Device device, JsonNode array, boolean b) {
|
||||
DeviceLog record = new DeviceLog();
|
||||
record.setDeviceName(device.getDeviceName());
|
||||
// 设备行为
|
||||
record.setDeviceAction(InstructType6170.fromCode(array.get(0).asInt()).getDescription());
|
||||
|
||||
switch (array.get(0).asInt()) {
|
||||
case 1: // 灯光模式
|
||||
LightModeEnum6170 lightModeEnum6170 = LightModeEnum6170.fromCode(array.get(1).asInt());
|
||||
record.setContent(lightModeEnum6170.getDescription());
|
||||
break;
|
||||
|
||||
case 2: // 单位/姓名/职位
|
||||
byte[] unitBytes = new byte[480];
|
||||
for (int i = 1; i <= 480; i++) {
|
||||
unitBytes[i - 1] = (byte) array.get(i).asInt();
|
||||
}
|
||||
// record.setUnitData(unitBytes);
|
||||
break;
|
||||
|
||||
case 3: // 开机图片
|
||||
// record.setImagePage(array.get(1).asInt());
|
||||
byte[] imageBytes = new byte[512];
|
||||
for (int i = 2; i <= 513; i++) {
|
||||
imageBytes[i - 2] = (byte) array.get(i).asInt();
|
||||
}
|
||||
// record.setImageData(imageBytes);
|
||||
break;
|
||||
|
||||
case 4: // 激光灯
|
||||
int anInt = array.get(1).asInt();
|
||||
if (anInt == 0) {
|
||||
record.setContent("关闭激光灯");
|
||||
} else if (anInt == 1) {
|
||||
record.setContent("开启激光灯");
|
||||
} else {
|
||||
record.setContent("未知操作");
|
||||
}
|
||||
break;
|
||||
|
||||
case 5: // 亮度调节
|
||||
record.setContent(+array.get(1).asInt() + "%");
|
||||
break;
|
||||
|
||||
case 11: // 定位数据
|
||||
if (b) {
|
||||
break;
|
||||
}
|
||||
int i1 = array.get(1).asInt();
|
||||
int i2 = array.get(2).asInt();
|
||||
int i3 = array.get(3).asInt();
|
||||
int i4 = array.get(4).asInt();
|
||||
|
||||
// 优雅的转换方式 Longitude and latitude
|
||||
double latitude = i1 + i2 / 10.0;
|
||||
double Longitude = i3 + i4 / 10.0;
|
||||
// 84 ==》 高德
|
||||
double[] doubles = LngLonUtil.gps84_To_Gcj02(latitude, Longitude);
|
||||
String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
|
||||
record.setContent(address);
|
||||
break;
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
}
|
||||
//package com.fuyuanshen.web.handler.mqtt;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.fasterxml.jackson.databind.JsonNode;
|
||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
//import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
//import com.fuyuanshen.equipment.domain.Device;
|
||||
//import com.fuyuanshen.equipment.domain.DeviceLog;
|
||||
//import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
|
||||
//import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
//import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
|
||||
//import com.fuyuanshen.equipment.utils.map.LngLonUtil;
|
||||
//import com.fuyuanshen.global.mqtt.constants.TenantsConstant;
|
||||
//import com.fuyuanshen.web.enums.InstructType6170;
|
||||
//import com.fuyuanshen.web.enums.LightModeEnum6170;
|
||||
//import lombok.AllArgsConstructor;
|
||||
//import lombok.Data;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.messaging.Message;
|
||||
//import org.springframework.messaging.MessageHandler;
|
||||
//import org.springframework.messaging.MessageHeaders;
|
||||
//import org.springframework.messaging.MessagingException;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
///**
|
||||
// * 定义监听主题消息的处理器
|
||||
// *
|
||||
// * @author: 默苍璃
|
||||
// * @date: 2025-08-0110:19
|
||||
// */
|
||||
//@Component
|
||||
//@Data
|
||||
//@AllArgsConstructor
|
||||
//@Slf4j
|
||||
//public class DeviceReceiverMessageHandler implements MessageHandler {
|
||||
//
|
||||
// private final DeviceMapper deviceMapper;
|
||||
// private final DeviceLogMapper deviceLogMapper;
|
||||
//
|
||||
// // 使用Jackson解析JSON
|
||||
// private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 处理接收的消息
|
||||
// *
|
||||
// * @param message
|
||||
// * @throws MessagingException
|
||||
// */
|
||||
// @Override
|
||||
// public void handleMessage(Message<?> message) throws MessagingException {
|
||||
// // System.out.println("接收到的消息:" + message.getPayload());
|
||||
// MessageHeaders headers = message.getHeaders();
|
||||
// String receivedTopicName = (String) headers.get("mqtt_receivedTopic");
|
||||
// System.out.println("消息来自主题:" + receivedTopicName);
|
||||
//
|
||||
// // String tenantId = LoginHelper.getTenantId();
|
||||
// String tenantId = TenantsConstant.FU_YUAN_SHENG;
|
||||
// String payload = message.getPayload().toString();
|
||||
//
|
||||
// if (receivedTopicName != null) {
|
||||
// // 1. 提取设备ID (从主题中获取)
|
||||
// String deviceImei = extractDeviceId(receivedTopicName);
|
||||
// Device device = deviceMapper.selectOne(new QueryWrapper<Device>()
|
||||
// .eq("tenant_id", tenantId)
|
||||
// .eq("device_imei", deviceImei));
|
||||
// if (device == null) {
|
||||
// log.info("不存在的设备IMEI: {}", deviceImei);
|
||||
// } else {
|
||||
//
|
||||
// try {
|
||||
// JsonNode root = objectMapper.readTree(payload);
|
||||
//
|
||||
// DeviceLog record = new DeviceLog();
|
||||
// // 手动设置租户ID
|
||||
// record.setTenantId(device.getTenantId()); // 从设备信息中获取租户ID
|
||||
// // 设备ID
|
||||
// record.setDeviceId(device.getId());
|
||||
// // 设备名称
|
||||
// record.setDeviceName(device.getDeviceName());
|
||||
//
|
||||
// // 2. 处理instruct消息
|
||||
// if (root.has("instruct")) {
|
||||
// JsonNode instructNode = root.get("instruct");
|
||||
// if (instructNode.isArray()) {
|
||||
// boolean b = receivedTopicName.startsWith("B/");
|
||||
// record = parseInstruct(device, instructNode, b);
|
||||
// // 根据不同主题进行不同处理
|
||||
// if (receivedTopicName.startsWith("A/")) {
|
||||
// // 处理A主题的消息(设备上传)
|
||||
// record.setDataSource("设备上报");
|
||||
// } else if (receivedTopicName.startsWith("B/")) {
|
||||
// // 处理B主题的消息 (手动上传)
|
||||
// record.setDataSource("客户端操作");
|
||||
// }
|
||||
// }
|
||||
// // 确保在插入前设置tenantId和deviceId
|
||||
// record.setTenantId(device.getTenantId());
|
||||
// record.setDeviceId(device.getId());
|
||||
// deviceLogMapper.insert(record);
|
||||
// }
|
||||
//
|
||||
// // 2. 处理 state 消息
|
||||
// if (root.has("state")) {
|
||||
// JsonNode instructNode = root.get("state");
|
||||
// if (instructNode.isArray()) {
|
||||
// boolean b = receivedTopicName.startsWith("B/");
|
||||
// record = parseState(device, instructNode, b);
|
||||
// // 根据不同主题进行不同处理
|
||||
// if (receivedTopicName.startsWith("A/")) {
|
||||
// // 处理A主题的消息(设备上传)
|
||||
// record.setDataSource("设备上报");
|
||||
// } else if (receivedTopicName.startsWith("B/")) {
|
||||
// // 处理B主题的消息 (手动上传)
|
||||
// record.setDataSource("客户端操作");
|
||||
// }
|
||||
// }
|
||||
// // 确保在插入前设置tenantId和deviceId
|
||||
// record.setTenantId(device.getTenantId());
|
||||
// record.setDeviceId(device.getId());
|
||||
// deviceLogMapper.insert(record);
|
||||
// }
|
||||
//
|
||||
// if (root.has("imei")) {
|
||||
// // 设备行为
|
||||
// record.setDeviceAction(InstructType6170.fromCode(0).getDescription());
|
||||
// record.setDataSource("设备上报");
|
||||
// record.setContent("设备启动");
|
||||
// // 确保在插入前设置tenantId和deviceId
|
||||
// record.setTenantId(device.getTenantId());
|
||||
// record.setDeviceId(device.getId());
|
||||
// deviceLogMapper.insert(record);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // 3. 处理state消息
|
||||
// // else if (root.has("state")) {
|
||||
// // JsonNode stateNode = root.get("state");
|
||||
// // if (stateNode.isArray()) {
|
||||
// // StateRecord record = parseState(device, stateNode);
|
||||
// // stateRepo.save(record);
|
||||
// // }
|
||||
// // }
|
||||
// } catch (Exception e) {
|
||||
// log.error("消息解析失败: {}", payload, e);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 从主题中提取设备ID(IMEI)
|
||||
// *
|
||||
// * @param topic
|
||||
// * @return
|
||||
// */
|
||||
// private String extractDeviceId(String topic) {
|
||||
// // 处理 A/# 或 B/# 格式的主题,例如 B/861556078765285 或 A/861556078765285
|
||||
// String[] segments = topic.split("/");
|
||||
// if (segments.length >= 2) {
|
||||
// // 返回第二个段,即 / 后面的部分
|
||||
// return segments[1];
|
||||
// }
|
||||
// // 如果格式不符合预期,返回原主题
|
||||
// return topic;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 解析instruct消息
|
||||
// *
|
||||
// * @param device
|
||||
// * @param array
|
||||
// * @param b
|
||||
// * @return
|
||||
// */
|
||||
// private DeviceLog parseInstruct(Device device, JsonNode array, boolean b) {
|
||||
// DeviceLog record = new DeviceLog();
|
||||
// record.setDeviceName(device.getDeviceName());
|
||||
// // 设备行为
|
||||
// record.setDeviceAction(InstructType6170.fromCode(array.get(0).asInt()).getDescription());
|
||||
//
|
||||
// switch (array.get(0).asInt()) {
|
||||
// case 1: // 灯光模式
|
||||
// LightModeEnum6170 lightModeEnum6170 = LightModeEnum6170.fromCode(array.get(1).asInt());
|
||||
// record.setContent(lightModeEnum6170.getDescription());
|
||||
// break;
|
||||
//
|
||||
// case 2: // 单位/姓名/职位
|
||||
// byte[] unitBytes = new byte[480];
|
||||
// for (int i = 1; i <= 480; i++) {
|
||||
// unitBytes[i - 1] = (byte) array.get(i).asInt();
|
||||
// }
|
||||
// // record.setUnitData(unitBytes);
|
||||
// break;
|
||||
//
|
||||
// case 3: // 开机图片
|
||||
// // record.setImagePage(array.get(1).asInt());
|
||||
// byte[] imageBytes = new byte[512];
|
||||
// for (int i = 2; i <= 513; i++) {
|
||||
// imageBytes[i - 2] = (byte) array.get(i).asInt();
|
||||
// }
|
||||
// // record.setImageData(imageBytes);
|
||||
// break;
|
||||
//
|
||||
// case 4: // 激光灯
|
||||
// int anInt = array.get(1).asInt();
|
||||
// if (anInt == 0) {
|
||||
// record.setContent("关闭激光灯");
|
||||
// } else if (anInt == 1) {
|
||||
// record.setContent("开启激光灯");
|
||||
// } else {
|
||||
// record.setContent("未知操作");
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case 5: // 亮度调节
|
||||
// record.setContent(+array.get(1).asInt() + "%");
|
||||
// break;
|
||||
//
|
||||
// case 11: // 定位数据
|
||||
// if (b) {
|
||||
// break;
|
||||
// }
|
||||
// int i1 = array.get(1).asInt();
|
||||
// int i2 = array.get(2).asInt();
|
||||
// int i3 = array.get(3).asInt();
|
||||
// int i4 = array.get(4).asInt();
|
||||
//
|
||||
// // 优雅的转换方式 Longitude and latitude
|
||||
// double latitude = i1 + i2 / 10.0;
|
||||
// double Longitude = i3 + i4 / 10.0;
|
||||
// // 84 ==》 高德
|
||||
// double[] doubles = LngLonUtil.gps84_To_Gcj02(latitude, Longitude);
|
||||
// String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
|
||||
// record.setContent(address);
|
||||
// break;
|
||||
// }
|
||||
// return record;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 解析 state 消息
|
||||
// *
|
||||
// * @param device
|
||||
// * @param array
|
||||
// * @return
|
||||
// */
|
||||
// private DeviceLog parseState(Device device, JsonNode array, boolean b) {
|
||||
// DeviceLog record = new DeviceLog();
|
||||
// record.setDeviceName(device.getDeviceName());
|
||||
// // 设备行为
|
||||
// record.setDeviceAction(InstructType6170.fromCode(array.get(0).asInt()).getDescription());
|
||||
//
|
||||
// switch (array.get(0).asInt()) {
|
||||
// case 1: // 灯光模式
|
||||
// LightModeEnum6170 lightModeEnum6170 = LightModeEnum6170.fromCode(array.get(1).asInt());
|
||||
// record.setContent(lightModeEnum6170.getDescription());
|
||||
// break;
|
||||
//
|
||||
// case 2: // 单位/姓名/职位
|
||||
// byte[] unitBytes = new byte[480];
|
||||
// for (int i = 1; i <= 480; i++) {
|
||||
// unitBytes[i - 1] = (byte) array.get(i).asInt();
|
||||
// }
|
||||
// // record.setUnitData(unitBytes);
|
||||
// break;
|
||||
//
|
||||
// case 3: // 开机图片
|
||||
// // record.setImagePage(array.get(1).asInt());
|
||||
// byte[] imageBytes = new byte[512];
|
||||
// for (int i = 2; i <= 513; i++) {
|
||||
// imageBytes[i - 2] = (byte) array.get(i).asInt();
|
||||
// }
|
||||
// // record.setImageData(imageBytes);
|
||||
// break;
|
||||
//
|
||||
// case 4: // 激光灯
|
||||
// int anInt = array.get(1).asInt();
|
||||
// if (anInt == 0) {
|
||||
// record.setContent("关闭激光灯");
|
||||
// } else if (anInt == 1) {
|
||||
// record.setContent("开启激光灯");
|
||||
// } else {
|
||||
// record.setContent("未知操作");
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case 5: // 亮度调节
|
||||
// record.setContent(+array.get(1).asInt() + "%");
|
||||
// break;
|
||||
//
|
||||
// case 11: // 定位数据
|
||||
// if (b) {
|
||||
// break;
|
||||
// }
|
||||
// int i1 = array.get(1).asInt();
|
||||
// int i2 = array.get(2).asInt();
|
||||
// int i3 = array.get(3).asInt();
|
||||
// int i4 = array.get(4).asInt();
|
||||
//
|
||||
// // 优雅的转换方式 Longitude and latitude
|
||||
// double latitude = i1 + i2 / 10.0;
|
||||
// double Longitude = i3 + i4 / 10.0;
|
||||
// // 84 ==》 高德
|
||||
// double[] doubles = LngLonUtil.gps84_To_Gcj02(latitude, Longitude);
|
||||
// String address = GetAddressFromLatUtil.getAdd(String.valueOf(doubles[1]), String.valueOf(doubles[0]));
|
||||
// record.setContent(address);
|
||||
// break;
|
||||
// }
|
||||
// return record;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
Reference in New Issue
Block a user