更新路径规划任务推送消息

This commit is contained in:
2026-06-11 17:12:55 +08:00
parent 9657fb42f6
commit 3879cd0067
24 changed files with 257 additions and 68 deletions

View File

@@ -1,5 +1,6 @@
package com.maibu.controller;
import com.github.pagehelper.PageHelper;
import com.maibu.core.business.DevicePlan;
import com.maibu.core.controller.BaseController;
import com.maibu.core.domain.AjaxResult;
@@ -87,13 +88,13 @@ public class DeviceTaskController extends BaseController {
@PostMapping("/deviceTaskPool")
public TableDataInfo deviceTaskPool(@RequestBody DeviceTaskQueryDTO dto) {
startPage();
startPostPage(dto.getPageNum(),dto.getPageSize());
return getDataTable(deviceTaskService.deviceTaskPool(dto));
}
@PostMapping("/getSiteDeviceTaskHistory")
public TableDataInfo getSiteDeviceTaskHistory(@RequestBody DeviceTaskQueryDTO dto) {
startPage();
startPostPage(dto.getPageNum(),dto.getPageSize());
return getDataTable(deviceTaskService.getSiteDeviceTaskHistory(dto));
}

View File

@@ -1,12 +1,14 @@
package com.maibu.dto;
import com.maibu.core.domain.BaseEntity;
import com.maibu.core.enums.DeviceTaskStaus;
import lombok.Data;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
public class DeviceTaskQueryDTO {
@EqualsAndHashCode(callSuper = true)
public class DeviceTaskQueryDTO extends BaseEntity {
private Long userId;
// private LocalDateTime startTime;

View File

@@ -1,5 +1,6 @@
package com.maibu.dto;
import com.maibu.core.business.path.LatAndLngEntity;
import com.maibu.core.enums.DeviceTaskStaus;
import com.maibu.core.enums.RespondCode;
import lombok.Data;
@@ -15,4 +16,6 @@ public class DeviceTaskReportDTO {
private DeviceTaskStaus status;
private LatAndLngEntity entity;
}

View File

@@ -0,0 +1,20 @@
package com.maibu.dto;
import com.maibu.core.business.path.LatAndLngEntity;
import com.maibu.core.enums.MesType;
import lombok.Data;
@Data
public class DeviceTaskStatusMessageDTO {
private MesType type;
private String deviceId;
private Long taskId;
private String status;
private LatAndLngEntity entity;
}

View File

@@ -1,14 +1,46 @@
package com.maibu.netty.handler;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Resource;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import com.maibu.common.CommandConstant;
import com.maibu.common.Constant;
import com.maibu.core.business.Device;
import com.maibu.core.business.device.NettyDevice;
import com.maibu.core.business.inter.DeviceWebSocketInterace;
import com.maibu.core.business.inter.WebsocketMesDispather;
import com.maibu.core.business.path.LatAndLngEntity;
import com.maibu.core.domain.entity.SysUser;
import com.maibu.core.domain.entity.UserClient;
import com.maibu.core.enums.*;
import com.maibu.dto.*;
import com.maibu.core.enums.CommandRequestType;
import com.maibu.core.enums.ConnectionCloseReason;
import com.maibu.core.enums.ConnectorStatus;
import com.maibu.core.enums.ConnectorType;
import com.maibu.core.enums.DeviceStatus;
import com.maibu.core.enums.DeviceTaskStaus;
import com.maibu.core.enums.MesType;
import com.maibu.core.enums.RespondCode;
import com.maibu.dto.DeviceLoginResponseDTO;
import com.maibu.dto.DeviceRequestDTO;
import com.maibu.dto.DeviceRespondDTO;
import com.maibu.dto.DeviceStatusChangeDTO;
import com.maibu.dto.DeviceTaskReportDTO;
import com.maibu.dto.DeviceTaskStatusMessageDTO;
import com.maibu.manager.DeviceSessionManager;
import com.maibu.mapper.DeviceRunStatisticsMapper;
import com.maibu.service.IDeviceService;
@@ -16,28 +48,14 @@ import com.maibu.service.ISysUserClientService;
import com.maibu.service.ISysUserService;
import com.maibu.utils.CommandUtils;
import com.maibu.utils.json.JsonUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.AttributeKey;
import io.netty.util.CharsetUtil;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
@Component
@ChannelHandler.Sharable
@@ -63,6 +81,9 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
@Autowired
private DeviceRunStatisticsMapper deviceRunStatisticsMapper;
@Resource
private WebsocketMesDispather websocketMesDispather;
public DeviceConnectHandler(DeviceSessionManager sessionManager) {
this.sessionManager = sessionManager;
}
@@ -317,29 +338,13 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
String deviceId = channel.attr(Constant.ATT_DEVICE_ID).get();
NettyDevice device = sessionManager.getDevice(deviceId);
if (CollectionUtils.isEmpty(device.getLocationQueue())) {
Long taskId = device.finishTask();
// todo 推送信息给前端
DeviceTaskReportDTO changeDTO = new DeviceTaskReportDTO();
changeDTO.setDeviceId(deviceId);
changeDTO.setStatus(DeviceTaskStaus.FINISH);
changeDTO.setEvent(RespondCode.device_task_change);
changeDTO.setTaskId(taskId);
// ByteBuf buf = ctx.alloc().buffer();
ByteBuf buf = Unpooled.buffer();
CommandUtils.buildCommand(buf, changeDTO, CommandConstant.interaction);
List<NettyDevice> controlMasters = sessionManager
.getAllSlaveControl(deviceId);
if (!CollectionUtils.isEmpty(controlMasters)) {
controlMasters.forEach(x -> {
if (x.getChannel() != null && x.getChannel().isActive()) {
x.getChannel().writeAndFlush(buf);
logger.info("任务完成状态推送 task:{},device:{}", taskId, deviceId);
}
});
}
// 推送到点
pushArriveData(device, deviceId);
// 推送完成+执行结束更新内存
pushFinishData(device, deviceId);
} else {
pushArriveData(device, deviceId);
device.sendNextPoint();
//todo 推送到点给前端
}
}
}
@@ -350,6 +355,65 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
}
}
public void pushFinishData(NettyDevice device, String deviceId) {
Long taskId = device.finishTask();
// todo 推送信息给前端
DeviceTaskStatusMessageDTO changeDTO = new DeviceTaskStatusMessageDTO();
changeDTO.setDeviceId(deviceId);
changeDTO.setStatus(DeviceTaskStaus.FINISH.toString());
changeDTO.setType(MesType.device_task_change);
changeDTO.setTaskId(taskId);
// ByteBuf buf = ctx.alloc().buffer();
// ByteBuf buf = Unpooled.buffer();
// CommandUtils.buildCommand(buf, changeDTO, CommandConstant.interaction);
List<NettyDevice> controlMasters = sessionManager
.getAllSlaveControl(deviceId);
if (!CollectionUtils.isEmpty(controlMasters)) {
controlMasters.forEach(x -> {
websocketMesDispather.dispather(x.getConnectorId(),
JsonUtils.toJsonString(changeDTO));
// String content = buf.toString(CharsetUtil.UTF_8);
logger.info("任务完成状态推送 task:{},device:{},content:{}", taskId, deviceId,
JsonUtils.toJsonString(changeDTO));
// if (x.getChannel() != null && x.getChannel().isActive()) {
// x.getChannel().writeAndFlush(buf);
// String content = buf.toString(CharsetUtil.UTF_8);
// logger.info("任务完成状态推送 task:{},device:{},content:{}", taskId, deviceId,
// content);
// }
});
}
}
public void pushArriveData(NettyDevice device, String deviceId) {
Long taskId = device.getTask() == null ? null : device.getTask().getId();
// todo 推送信息给前端
DeviceTaskStatusMessageDTO reportDTO = new DeviceTaskStatusMessageDTO();
reportDTO.setDeviceId(deviceId);
reportDTO.setTaskId(taskId);
reportDTO.setEntity(device.getCurrentPoint());
reportDTO.setType(MesType.device_task_arrive_point);
// ByteBuf buf = ctx.alloc().buffer();
// ByteBuf buf = Unpooled.buffer();
// CommandUtils.buildCommand(buf, reportDTO, CommandConstant.interaction);
List<NettyDevice> controlMasters = sessionManager
.getAllSlaveControl(deviceId);
if (!CollectionUtils.isEmpty(controlMasters)) {
controlMasters.forEach(x -> {
websocketMesDispather.dispather(x.getConnectorId(),
JsonUtils.toJsonString(reportDTO));
logger.info("任务点位到达推送 task:{},device:{},content:{}", taskId, deviceId,
JsonUtils.toJsonString(reportDTO));
// if (x.getChannel() != null && x.getChannel().isActive()) {
// x.getChannel().writeAndFlush(buf);
// String content = buf.toString(CharsetUtil.UTF_8);
// logger.info("任务点位到达推送 task:{},device:{},content:{}", taskId, deviceId,
// content);
// }
});
}
}
/**
* 处理反馈 待扩展
*/