设备行为
This commit is contained in:
@ -6,7 +6,7 @@ package com.fuyuanshen.web.enums;
|
||||
*/
|
||||
public enum InstructType6170 {
|
||||
|
||||
EQUIPMENT_REPORTING(0, "设备上报"),
|
||||
EQUIPMENT_REPORTING(0, "设备启动"),
|
||||
LIGHT_MODE(1, "灯光模式"),
|
||||
/**
|
||||
* 设备信息
|
||||
|
@ -7,6 +7,8 @@ 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.web.enums.InstructType6170;
|
||||
import com.fuyuanshen.web.enums.LightModeEnum6170;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -63,16 +65,20 @@ public class DeviceReceiverMessageHandler implements MessageHandler {
|
||||
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()) {
|
||||
DeviceLog record = parseInstruct(device, instructNode);
|
||||
// 手动设置租户ID
|
||||
record.setTenantId(device.getTenantId()); // 从设备信息中获取租户ID
|
||||
// 设备ID
|
||||
record.setDeviceId(device.getId());
|
||||
|
||||
boolean b = receivedTopicName.startsWith("B/");
|
||||
record = parseInstruct(device, instructNode, b);
|
||||
// 根据不同主题进行不同处理
|
||||
if (receivedTopicName.startsWith("A/")) {
|
||||
// 处理A主题的消息(设备上传)
|
||||
@ -81,10 +87,19 @@ public class DeviceReceiverMessageHandler implements MessageHandler {
|
||||
// 处理B主题的消息 (手动上传)
|
||||
record.setDataSource("客户端操作");
|
||||
}
|
||||
|
||||
deviceLogMapper.insert(record);
|
||||
}
|
||||
deviceLogMapper.insert(record);
|
||||
}
|
||||
|
||||
if (root.has("imei")) {
|
||||
// 设备行为
|
||||
record.setDeviceAction(InstructType6170.fromCode(0).getDescription());
|
||||
record.setDataSource("设备上报");
|
||||
record.setContent("设备启动");
|
||||
deviceLogMapper.insert(record);
|
||||
}
|
||||
|
||||
|
||||
// 3. 处理state消息
|
||||
// else if (root.has("state")) {
|
||||
// JsonNode stateNode = root.get("state");
|
||||
@ -126,9 +141,10 @@ public class DeviceReceiverMessageHandler implements MessageHandler {
|
||||
*
|
||||
* @param device
|
||||
* @param array
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
private DeviceLog parseInstruct(Device device, JsonNode array) {
|
||||
private DeviceLog parseInstruct(Device device, JsonNode array, boolean b) {
|
||||
DeviceLog record = new DeviceLog();
|
||||
record.setDeviceName(device.getDeviceName());
|
||||
// 设备行为
|
||||
@ -173,10 +189,21 @@ public class DeviceReceiverMessageHandler implements MessageHandler {
|
||||
break;
|
||||
|
||||
case 11: // 定位数据
|
||||
// record.setLatitudeDeg(array.get(1).asInt());
|
||||
// record.setLatitudeMin(new BigDecimal(array.get(2).asDouble()));
|
||||
// record.setLongitudeDeg(array.get(3).asInt());
|
||||
// record.setLongitudeMin(new BigDecimal(array.get(4).asDouble()));
|
||||
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