#更新计算累计路程相关
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
package com.maibu.core.business;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.maibu.core.domain.BaseDO;
|
||||
import com.maibu.core.domain.OrgBaseDO;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@TableName("iot_device_task")
|
||||
|
||||
@@ -20,6 +20,8 @@ public class DeviceTaskCommandDTO {
|
||||
|
||||
private Long taskId;
|
||||
|
||||
private Long regionId;
|
||||
|
||||
private boolean forceCancel = false; //强制取消 不等回复
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.maibu.core.business.dto;
|
||||
|
||||
import com.maibu.core.business.path.LatAndLngEntity;
|
||||
import com.maibu.core.enums.MesType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WebDeviceTaskStatusMessageDTO {
|
||||
|
||||
private MesType type;
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private Long taskId;
|
||||
|
||||
private String status;
|
||||
|
||||
private LatAndLngEntity entity;
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.maibu.core.domain.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.maibu.core.domain.BaseDO;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@TableName(value = "sys_region")
|
||||
@@ -29,4 +30,6 @@ public class SysRegion extends BaseDO {
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Long bindRoute;// 绑定的线路id
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.maibu.core.host;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class VehicleMessage {
|
||||
|
||||
private double speed;
|
||||
private double battery_percentage;//电量
|
||||
private double battery_voltage;//电压
|
||||
private String motion;//moving|stopped|blocked
|
||||
private boolean emergency_stop; //急停状态
|
||||
private double battery_percentage;// 电量
|
||||
private double battery_voltage;// 电压
|
||||
private String motion;// moving|stopped|blocked
|
||||
private boolean emergency_stop; // 急停状态
|
||||
|
||||
private double distance; // 里程数
|
||||
|
||||
}
|
||||
|
||||
@@ -53,6 +53,28 @@ public class SiteMemory {
|
||||
// key deviceId execute
|
||||
public static ConcurrentHashMap<String, DevicePlanTask> devicePlanTaskExecuteMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 记录 设备上线后的运行数据 下线后清除并保存到数据库
|
||||
public static ConcurrentHashMap<String, DeviceRunStatistics> deviceRunStatisticsMap = new ConcurrentHashMap<>();
|
||||
|
||||
public void saveRunStatistics(DeviceRunStatistics deviceRunStatistics) {
|
||||
if (deviceRunStatistics != null && !StringUtils.isEmpty(deviceRunStatistics.getDeviceId())) {
|
||||
deviceRunStatisticsMap.put(deviceRunStatistics.getDeviceId(), deviceRunStatistics);
|
||||
}
|
||||
}
|
||||
|
||||
public DeviceRunStatistics getRunStatistics(String deviceId) {
|
||||
if (!StringUtils.isEmpty(deviceId)) {
|
||||
return deviceRunStatisticsMap.get(deviceId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeRunStatistics(String deviceId) {
|
||||
if (!StringUtils.isEmpty(deviceId)) {
|
||||
deviceRunStatisticsMap.remove(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveDevice(Device device) {
|
||||
deviceMap.put(device.getSerialNumber(), device);
|
||||
}
|
||||
@@ -135,7 +157,6 @@ public class SiteMemory {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void saveDeviceRunParam(DeviceRunParam deviceRunParam) {
|
||||
deviceRunParamMap.put(deviceRunParam.getDeviceId(), deviceRunParam);
|
||||
}
|
||||
|
||||
@@ -1,27 +1,37 @@
|
||||
package com.maibu.mqtt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.maibu.constant.Constant;
|
||||
import com.maibu.constant.NettyCacheKey;
|
||||
import com.maibu.core.business.DeviceRunStatistics;
|
||||
import com.maibu.core.business.device.DeviceStatusDetail;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.core.business.dto.WebDeviceTaskStatusMessageDTO;
|
||||
import com.maibu.core.business.dto.WebStatusMessageDTO;
|
||||
import com.maibu.core.business.inter.WebsocketMesDispather;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
import com.maibu.core.enums.MesType;
|
||||
import com.maibu.core.host.*;
|
||||
import com.maibu.core.host.HeartBeatDTO;
|
||||
import com.maibu.core.host.HostLocationRelTimeDTO;
|
||||
import com.maibu.core.host.HostNavigationReplyDTO;
|
||||
import com.maibu.core.host.HostTaskStatusDTO;
|
||||
import com.maibu.core.host.HostVehicleRelTimeDTO;
|
||||
import com.maibu.core.host.LocationMessage;
|
||||
import com.maibu.core.redis.RedisCache;
|
||||
import com.maibu.memory.DeviceSessionManager;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.memory.SiteMemory;
|
||||
import com.maibu.utils.StringUtils;
|
||||
import com.maibu.utils.json.JsonUtils;
|
||||
import com.maibu.utils.spring.SpringUtils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* mqtt相关的 上位机处理器
|
||||
@@ -230,6 +240,26 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
try {
|
||||
HostVehicleRelTimeDTO vehicleRelTimeDTO = JsonUtils.parseObject(payload, HostVehicleRelTimeDTO.class);
|
||||
if (vehicleRelTimeDTO != null) {
|
||||
|
||||
// todo 更新里程数 里程数 * 割幅0.8
|
||||
vehicleRelTimeDTO.getData().getDistance();
|
||||
NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
||||
if (nettyDevice != null) {
|
||||
Long orgId = nettyDevice.getDevice().getOrgId();
|
||||
Long siteId = nettyDevice.getDevice().getSiteId();
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
if (siteMemory != null) {
|
||||
DeviceRunStatistics deviceRunStatistics = siteMemory.getRunStatistics(deviceId);
|
||||
if (deviceRunStatistics == null) {
|
||||
deviceRunStatistics = new DeviceRunStatistics();
|
||||
}
|
||||
deviceRunStatistics.setDeviceId(deviceId);
|
||||
deviceRunStatistics.setDistance(vehicleRelTimeDTO.getData().getDistance());
|
||||
deviceRunStatistics.setWorkArea(vehicleRelTimeDTO.getData().getDistance() * 0.8);
|
||||
siteMemory.saveRunStatistics(deviceRunStatistics);
|
||||
}
|
||||
}
|
||||
|
||||
WebStatusMessageDTO dto = createWebDeviceRealtimeMessage(vehicleRelTimeDTO);
|
||||
List<NettyDevice> controlMasters = deviceSessionManager
|
||||
.getAllSlaveControl(deviceId);
|
||||
@@ -243,10 +273,6 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
// GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||
// String.format(MqttTopic.DEVICE_STATUS_TOPIC, deviceId),
|
||||
// JsonUtils.toJsonString(dto));
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("实时消息解析失败: deviceId={}, payload={}, error={}", deviceId, payload, e.getMessage());
|
||||
@@ -285,7 +311,27 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
if (dto != null && !StringUtils.isEmpty(dto.getStatus())) {
|
||||
NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
||||
if ("completed".equals(dto.getStatus())) {
|
||||
nettyDevice.finishTask();
|
||||
Long taskId = nettyDevice.finishTask();
|
||||
|
||||
WebDeviceTaskStatusMessageDTO sendDto = new WebDeviceTaskStatusMessageDTO();
|
||||
sendDto.setDeviceId(deviceId);
|
||||
sendDto.setTaskId(taskId);
|
||||
sendDto.setStatus(DeviceTaskStaus.FINISH.toString());
|
||||
sendDto.setType(MesType.device_task_change);
|
||||
|
||||
List<NettyDevice> controlMasters = deviceSessionManager
|
||||
.getAllSlaveControl(deviceId);
|
||||
if (!CollectionUtils.isEmpty(controlMasters)) {
|
||||
for (NettyDevice x : controlMasters) {
|
||||
try {
|
||||
websocketMesDispather.dispather(x.getConnectorId(), JsonUtils.toJsonString(sendDto));
|
||||
} catch (Exception e) {
|
||||
log.error("实时数据websocket推送失败: connectorId={}, error={}", x.getConnectorId(),
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if ("cancelled".equals(dto.getStatus())) {
|
||||
nettyDevice.canceledTask();
|
||||
@@ -394,61 +440,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
private double getDouble(JsonNode node, String... names) {
|
||||
for (String name : names) {
|
||||
JsonNode fn = node.get(name);
|
||||
if (fn != null && !fn.isNull()) {
|
||||
if (fn.isNumber())
|
||||
return fn.asDouble();
|
||||
try {
|
||||
return Double.parseDouble(fn.asText());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
private Double getDoubleObj(JsonNode node, String... names) {
|
||||
for (String name : names) {
|
||||
JsonNode fn = node.get(name);
|
||||
if (fn != null && !fn.isNull()) {
|
||||
if (fn.isNumber())
|
||||
return fn.asDouble();
|
||||
try {
|
||||
return Double.parseDouble(fn.asText());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getInt(JsonNode node, String... names) {
|
||||
for (String name : names) {
|
||||
JsonNode fn = node.get(name);
|
||||
if (fn != null && !fn.isNull()) {
|
||||
if (fn.isNumber())
|
||||
return fn.asInt();
|
||||
try {
|
||||
return Integer.parseInt(fn.asText());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private String getString(JsonNode node, String... names) {
|
||||
for (String name : names) {
|
||||
JsonNode fn = node.get(name);
|
||||
if (fn != null && !fn.isNull()) {
|
||||
return fn.asText();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onConnectionLost(String deviceKey, Throwable cause) {
|
||||
log.warn("主机监控连接断开: deviceKey={}, reason={}", deviceKey, cause.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user