This commit is contained in:
2026-06-10 16:31:39 +08:00
parent 1ece1b2336
commit 9657fb42f6
11 changed files with 463 additions and 194 deletions

View File

@@ -137,7 +137,7 @@ public class DeviceTaskController extends BaseController {
}
@PostMapping("/recoveryTask")
public AjaxResult recoveryTask(@RequestBody DeviceTaskCommandDTO dto) {
public AjaxResult recoveryTask(@RequestBody DeviceTaskCommandDTO dto) throws InterruptedException {
String deviceId = dto.getDeviceId();
if (StringUtils.isEmpty(deviceId) && dto.getTaskId() == null) {
return AjaxResult.error("deviceId或taskId为空!");

View File

@@ -0,0 +1,18 @@
package com.maibu.dto;
import com.maibu.core.enums.DeviceTaskStaus;
import com.maibu.core.enums.RespondCode;
import lombok.Data;
@Data
public class DeviceTaskReportDTO {
private RespondCode event;
private String deviceId;
private Long taskId;
private DeviceTaskStaus status;
}

View File

@@ -8,7 +8,6 @@ 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.core.enums.DeviceStatus;
import com.maibu.dto.*;
import com.maibu.manager.DeviceSessionManager;
import com.maibu.mapper.DeviceRunStatisticsMapper;
@@ -46,7 +45,7 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
private static final Logger logger = LoggerFactory.getLogger(DeviceConnectHandler.class);
//记录切换控制权请求来源 key 是请求的masterId,value是控制当前设备的主机
// 记录切换控制权请求来源 key 是请求的masterId,value是控制当前设备的主机
private final ConcurrentHashMap<String, String> controlRequestMap = new ConcurrentHashMap<>();
@Autowired
@@ -73,7 +72,7 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
logger.info("Channel active: {}", ctx.channel().remoteAddress());
ctx.fireChannelActive();
//todo 更新单次统计消息
// todo 更新单次统计消息
}
@@ -95,12 +94,12 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
nettyDevice.setCurrentSlaveId(null);
sysUserClientService.updateAliveStatus(deviceId, "", 0);
logger.info("{}: 设备断开 status: {}", deviceId, ConnectorStatus.DISABLED);
// updateLogoutSingle(deviceId);
//todo 自动切换到其他?
// updateLogoutSingle(deviceId);
// todo 自动切换到其他?
}
if (nettyDevice != null && nettyDevice.getDeviceType() == ConnectorType.SLAVE) {
nettyDevice.setOnlineStatus(0);
//推送json 找到设备绑定的主机进行推送
// 推送json 找到设备绑定的主机进行推送
List<NettyDevice> controlMasters = sessionManager.getAllSlaveControl(deviceId);
if (!CollectionUtils.isEmpty(controlMasters)) {
controlMasters.forEach(x -> {
@@ -122,7 +121,7 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
device.setOnlineStatus(DeviceStatus.offline.getType());
device.setUpdateTime(LocalDateTime.now());
deviceService.updateDeviceBySelf(device);
//todo 更新历史作业消息
// todo 更新历史作业消息
}
if (nettyDevice.getLatestStatus() != null) {
nettyDevice.getLatestStatus().setEndTime(LocalDateTime.now());
@@ -153,7 +152,7 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
if (!StringUtils.isEmpty(data)) {
if (data.contains(":")) {
logger.info("上位机连接 data:{}", data);
//判断 是否更新连接了 更新连接就返回失败
// 判断 是否更新连接了 更新连接就返回失败
String[] parts = data.split(":");
if (parts.length == 3) {
String deviceId = parts[0] + ":" + parts[1];
@@ -167,37 +166,41 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
if (sysUser != null) {
sysUserClientService.insertUserClient(sysUser.getUserId(), userName, deviceId, "", 0);
}
//如果 当前角色存在sessionId同时和当前的穿过来不同则下发剔除指令
// 如果 当前角色存在sessionId同时和当前的穿过来不同则下发剔除指令
boolean t = false;
if (StringUtils.isEmpty(sessionId) || sysUser == null) {
t = true;
}
if (sysUser != null && !StringUtils.isEmpty(sessionId) && !StringUtils.isEmpty(sysUser.getSessionId())) {
if (sysUser != null && !StringUtils.isEmpty(sessionId)
&& !StringUtils.isEmpty(sysUser.getSessionId())) {
if (!sysUser.getSessionId().equals(sessionId)) {
t = true;
}
}
if (t) {
//发送已登录状态到客户端
// 发送已登录状态到客户端
if ("web".equals(parts[1])) {
NettyDevice device = sessionManager.getDevice(deviceId);
logger.info("web 上位机连接重连: {}", JsonUtils.toJsonString(device));
if (device != null && !StringUtils.isEmpty(device.getCurrentSlaveId())) {
logger.info("上位机连接重连: {}", deviceId);
} else {
//判断是否账号在控制空 如果在控制设置账号为非active
List<UserClient> userClients = sysUserClientService.selectUserClientByUserName(userName);
// 判断是否账号在控制空 如果在控制设置账号为非active
List<UserClient> userClients = sysUserClientService
.selectUserClientByUserName(userName);
ConnectorStatus status = ConnectorStatus.ACTIVE;
logger.info("web 上位机连接重连2: {}", JsonUtils.toJsonString(userClients));
UserClient nowClient = null;
if (!CollectionUtils.isEmpty(userClients)) {
long count = userClients.stream().filter(x ->
x.getIsAlive() == 1 && !deviceId.equals(x.getClientName())).count();
long count = userClients.stream().filter(
x -> x.getIsAlive() == 1 && !deviceId.equals(x.getClientName()))
.count();
if (count > 0) {
status = ConnectorStatus.RECEIVER;
}
nowClient = userClients.stream().filter(x ->
x.getIsAlive() == 1 && deviceId.equals(x.getClientName())).findFirst().orElse(null);
nowClient = userClients.stream().filter(
x -> x.getIsAlive() == 1 && deviceId.equals(x.getClientName()))
.findFirst().orElse(null);
}
logger.info("web 上位机连接重连3: {}", JsonUtils.toJsonString(status));
if (!ConnectorStatus.ACTIVE.equals(status)) {
@@ -220,22 +223,24 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
ctx.channel().writeAndFlush(buf);
}
} else {
//判断是否账号在控制空 如果在控制设置账号为非active
List<UserClient> userClients = sysUserClientService.selectUserClientByUserName(userName);
// 判断是否账号在控制空 如果在控制设置账号为非active
List<UserClient> userClients = sysUserClientService
.selectUserClientByUserName(userName);
ConnectorStatus status = ConnectorStatus.ACTIVE;
if (!CollectionUtils.isEmpty(userClients)) {
long count = userClients.stream().filter(x ->
x.getIsAlive() == 1 && !deviceId.equals(x.getClientName())).count();
long count = userClients.stream()
.filter(x -> x.getIsAlive() == 1 && !deviceId.equals(x.getClientName()))
.count();
if (count > 0) {
status = ConnectorStatus.RECEIVER;
}
}
logger.info("上位机上线:{}", status);
// if (ConnectorStatus.ACTIVE.equals(status)) {
// //todo 设置当前控制的token
// sysUser.setSessionId(sessionId);
// userService.updateUserProfile(sysUser);
// }
// if (ConnectorStatus.ACTIVE.equals(status)) {
// //todo 设置当前控制的token
// sysUser.setSessionId(sessionId);
// userService.updateUserProfile(sysUser);
// }
handleMasterConnect(ctx, deviceId, null, status);
}
}
@@ -266,7 +271,7 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
if (slaveDevice != null) {
slaveDevice.setOnlineStatus(1);
}
//推送json 找到设备绑定的主机进行推送
// 推送json 找到设备绑定的主机进行推送
List<NettyDevice> controlMasters = sessionManager.getAllSlaveControl(device.getSerialNumber());
if (!CollectionUtils.isEmpty(controlMasters)) {
controlMasters.forEach(x -> {
@@ -304,17 +309,37 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
}
}
} else if (cmdType == CommandConstant.path) {
//路径下发完成
if(bytes.length < 11){
//01 表示完成
// 路径下发完成
if (bytes.length < 11) {
// 01 表示完成
if (bytes[5] == (byte) 0x01) {
Channel channel = ctx.channel();
String deviceId = channel.attr(Constant.ATT_DEVICE_ID).get();
NettyDevice device = sessionManager.getDevice(deviceId);
if(CollectionUtils.isEmpty(device.getLocationQueue())) {
device.finishTask();
}else{
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);
}
});
}
} else {
device.sendNextPoint();
//todo 推送到点给前端
}
}
}
@@ -326,23 +351,23 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
}
/**
* 处理反馈 待扩展
* 处理反馈 待扩展
*/
private void responseDispatch(DeviceRespondDTO respond, byte[] bytes) {
Boolean switchResult = respond.getSwitchResult();
String slaveId = respond.getDeviceId();
//找到请求的 设备 他这个是先记录切换请求做个绑定关系,在同意或者反对时能直接找到对应 请求的设备 直接发送报文
// 找到请求的 设备 他这个是先记录切换请求做个绑定关系,在同意或者反对时能直接找到对应 请求的设备 直接发送报文
String masterId = getRequestMaster(slaveId);
if (switchResult) {
List<NettyDevice> controlList = sessionManager.getSlaveControl(slaveId);
NettyDevice masterDevice = sessionManager.getDevice(masterId);
NettyDevice slaveDevice = sessionManager.getDevice(slaveId);
if (!CollectionUtils.isEmpty(controlList)) {
//如果当前设备有控制
// 如果当前设备有控制
controlList.forEach(c -> {
logger.info("12指令切换权限,c:{}", c.getConnectorId());
if (!c.getConnectorId().equals(masterId)) {
// c.setCurrentSlaveId(null);
// c.setCurrentSlaveId(null);
c.removeConnectedDevice(slaveDevice);
c.setConnectorStatus(ConnectorStatus.RECEIVER);
sysUserClientService.updateAliveStatus(c.getConnectorId(), slaveId, 2);
@@ -367,7 +392,8 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
* 获取当前请求目标设备的主机
*/
private String getRequestMaster(String slaveId) {
return controlRequestMap.keySet().stream().filter(x -> controlRequestMap.get(x).equals(slaveId)).findFirst().orElse(null);
return controlRequestMap.keySet().stream().filter(x -> controlRequestMap.get(x).equals(slaveId)).findFirst()
.orElse(null);
}
/**
@@ -393,7 +419,7 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
String masterId = requestDTO.getUserId() + ":" + requestDTO.getPlatform();
logger.info("转发控制请求 controlList :{}", JsonUtils.toJsonString(controlList));
if (!CollectionUtils.isEmpty(controlList)) {
//如果当前设备有控制
// 如果当前设备有控制
logger.info("转发控制请求 发送报文");
NettyDevice controlDevice = controlList.get(0);
if (controlDevice != null && controlDevice.getChannel() != null && controlDevice.getChannel().isActive()) {
@@ -404,7 +430,7 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
}
} else {
//判断直接给权限 还是 判断是否有该账号其他端的的控制有权限
// 判断直接给权限 还是 判断是否有该账号其他端的的控制有权限
NettyDevice activeDevice = sessionManager.getUserControl(requestDTO.getUserId());
boolean sendMes = true;
if (activeDevice == null) {
@@ -456,13 +482,13 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
sessionManager.registerDevice(slaveId, ctx.channel(), ConnectorType.SLAVE, ConnectorStatus.ACTIVE, null);
}
private void handleMasterConnect(ChannelHandlerContext ctx, String masterId, String slaveId, ConnectorStatus status) {
private void handleMasterConnect(ChannelHandlerContext ctx, String masterId, String slaveId,
ConnectorStatus status) {
ctx.channel().attr(Constant.ATT_DEVICE_ID).set(masterId);
sessionManager.registerDevice(masterId, ctx.channel(), ConnectorType.MASTER, status, slaveId);
// sessionManager.bindConnector(masterId, slaveId);
// sessionManager.bindConnector(masterId, slaveId);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
String deviceId = ctx.channel().attr(Constant.ATT_DEVICE_ID).get();

View File

@@ -230,6 +230,7 @@ public class DevicePlanTaskMonitorService {
DevicePlanTask devicePlanTask = tasks.get(0);
String deviceId = devicePlanTask.getDeviceId();
if (!StringUtils.isEmpty(deviceId) && deviceId.equals(key)) {
devicePlanTask.setTaskStaus(DeviceTaskStaus.EXECUTING);
siteMemory.addDevicePlanExecute(devicePlanTask);
device.setCurrentTaskId(devicePlanTask.getId());
device.setTask(devicePlanTask);

View File

@@ -21,6 +21,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Random;
@@ -42,14 +43,12 @@ public class DeviceTaskService {
@Autowired
private WorkRecordMapper workRecordMapper;
@Autowired
private DeviceSessionManager deviceSessionManager;
@Autowired
private SysSiteMapper sysSiteMapper;
public int insertOrUpdate(DevicePlan devicePlan, LoginUser loginUser) {
Long id = devicePlan.getId();
SiteMemory siteMemory = GlobalMemory.getSiteMemory(devicePlan.getOrgId(), devicePlan.getSiteId());
@@ -116,7 +115,8 @@ public class DeviceTaskService {
}
}
public List<DevicePlan> getSiteDevicePlan(Long siteId, LocalDate startTime, LocalDate endTime, String deviceId, DeviceTaskStaus taskStaus) {
public List<DevicePlan> getSiteDevicePlan(Long siteId, LocalDate startTime, LocalDate endTime, String deviceId,
DeviceTaskStaus taskStaus) {
if (siteId != null) {
LambdaQueryWrapper<DevicePlan> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DevicePlan::getSiteId, siteId);
@@ -206,10 +206,10 @@ public class DeviceTaskService {
List<DevicePlanStatisticsDTO> list = new ArrayList<>();
LocalDate today = LocalDate.now();
LocalDateTime monthStart = LocalDateTime.of(
today.getYear(), // 当前年
today.getMonth(), // 当前月
1, // 当月第一天
0, 0, 0, 0 // 时:分:秒:纳秒(00:00:00.000)
today.getYear(), // 当前年
today.getMonth(), // 当前月
1, // 当月第一天
0, 0, 0, 0 // 时:分:秒:纳秒(00:00:00.000)
);
LocalDate lastDayOfMonth = today.withDayOfMonth(today.lengthOfMonth()); // 获取当月最后一天
LocalDateTime monthEnd = LocalDateTime.of(
@@ -226,7 +226,8 @@ public class DeviceTaskService {
if (!CollectionUtils.isEmpty(devicePlans)) {
List<LocalDate> dates = getMonthDays();
for (LocalDate date : dates) {
List<DevicePlan> plans = devicePlans.stream().filter(x -> x.getCreateTime().toLocalDate().equals(date)).collect(Collectors.toList());
List<DevicePlan> plans = devicePlans.stream().filter(x -> x.getCreateTime().toLocalDate().equals(date))
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(plans)) {
DevicePlanStatisticsDTO dto = new DevicePlanStatisticsDTO();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M.d");
@@ -260,10 +261,10 @@ public class DeviceTaskService {
LocalDate today = LocalDate.now();
// 2. 构造当前月份的起始时间:当月第一天 00:00:00
LocalDateTime monthStart = LocalDateTime.of(
today.getYear(), // 当前年
today.getMonth(), // 当前月
1, // 当月第一天
0, 0, 0, 0 // 时:分:秒:纳秒(00:00:00.000)
today.getYear(), // 当前年
today.getMonth(), // 当前月
1, // 当月第一天
0, 0, 0, 0 // 时:分:秒:纳秒(00:00:00.000)
);
// 3. 构造当前月份的结束时间:当月最后一天 23:59:59.999
LocalDate lastDayOfMonth = today.withDayOfMonth(today.lengthOfMonth()); // 获取当月最后一天
@@ -277,9 +278,11 @@ public class DeviceTaskService {
LambdaQueryWrapper<DevicePlan> query = new LambdaQueryWrapper<>();
query.eq(DevicePlan::getUserId, userId);
List<DevicePlan> devicePlans = transferDevicePlanData(devicePlanMapper.selectList(query));
if (CollectionUtils.isEmpty(devicePlans)) return new ArrayList<>();
if (CollectionUtils.isEmpty(devicePlans))
return new ArrayList<>();
List<Long> planIds = devicePlans.stream().map(DevicePlan::getId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(planIds)) return new ArrayList<>();
if (CollectionUtils.isEmpty(planIds))
return new ArrayList<>();
LambdaQueryWrapper<DevicePlanTask> queryWrapper = new LambdaQueryWrapper<>();
// 核心:筛选 createTime 大于等于起始时间,且小于等于结束时间
@@ -290,16 +293,20 @@ public class DeviceTaskService {
if (!CollectionUtils.isEmpty(devicePlanTasks)) {
List<LocalDate> dates = getMonthDays();
for (LocalDate date : dates) {
List<DevicePlanTask> planTasks = devicePlanTasks.stream().filter(x -> x.getCreateTime().toLocalDate().equals(date)).collect(Collectors.toList());
List<DevicePlanTask> planTasks = devicePlanTasks.stream()
.filter(x -> x.getCreateTime().toLocalDate().equals(date)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(planTasks)) {
DevicePlanTaskStatisticsDTO dto = new DevicePlanTaskStatisticsDTO();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M.d");
dto.setDate(formatter.format(date));
long finishCount = planTasks.stream().filter(x -> DeviceTaskStaus.FINISH.equals(x.getTaskStaus())).count();
long finishCount = planTasks.stream().filter(x -> DeviceTaskStaus.FINISH.equals(x.getTaskStaus()))
.count();
dto.setSuccess((int) finishCount);
long failedCount = planTasks.stream().filter(x -> DeviceTaskStaus.FAILED.equals(x.getTaskStaus())).count();
long failedCount = planTasks.stream().filter(x -> DeviceTaskStaus.FAILED.equals(x.getTaskStaus()))
.count();
dto.setFailed((int) failedCount);
long pauseCount = planTasks.stream().filter(x -> DeviceTaskStaus.PAUSE.equals(x.getTaskStaus())).count();
long pauseCount = planTasks.stream().filter(x -> DeviceTaskStaus.PAUSE.equals(x.getTaskStaus()))
.count();
dto.setPaused((int) pauseCount);
list.add(dto);
}
@@ -308,7 +315,6 @@ public class DeviceTaskService {
return list;
}
public WorkRecord concurrentDevicePlanTask(String deviceId) {
LambdaQueryWrapper<DevicePlanTask> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DevicePlanTask::getDeviceId, deviceId)
@@ -318,9 +324,8 @@ public class DeviceTaskService {
return routId == null ? null : workRecordMapper.selectById(routId);
}
public List<DeviceWorkStatisticsDTO> workStatistics(Long userId) {
//todo update
// todo update
List<DeviceWorkStatisticsDTO> result = new ArrayList<>();
Random random = new Random();
@@ -341,7 +346,6 @@ public class DeviceTaskService {
return result;
}
public List<DevicePlanTask> deviceTaskPool(DeviceTaskQueryDTO dto) {
List<DevicePlanTask> list = new ArrayList<>();
if (dto.getOrgId() == null) {
@@ -394,9 +398,9 @@ public class DeviceTaskService {
return transferDeviceTaskData(devicePlanTaskMapper.selectList(queryWrapper));
}
public List<DevicePlan> transferDevicePlanData(List<DevicePlan> list) {
if (CollectionUtils.isEmpty(list)) return list;
if (CollectionUtils.isEmpty(list))
return list;
list.forEach(x -> {
DeviceTaskStaus taskStaus = x.getTaskStaus();
x.setTaskStausTranslate(taskStaus.getDescription());
@@ -405,11 +409,17 @@ public class DeviceTaskService {
}
public List<DevicePlanTask> transferDeviceTaskData(List<DevicePlanTask> list) {
if (CollectionUtils.isEmpty(list)) return list;
if (CollectionUtils.isEmpty(list))
return list;
list.forEach(x -> {
DeviceTaskStaus taskStaus = x.getTaskStaus();
x.setTaskStausTranslate(taskStaus.getDescription());
});
list.sort(
Comparator.comparing(DevicePlanTask::getFinishTime,
Comparator.nullsLast(Comparator.reverseOrder()))
.thenComparing(DevicePlanTask::getCreateTime,
Comparator.nullsLast(Comparator.reverseOrder())));
return list;
}
@@ -443,8 +453,8 @@ public class DeviceTaskService {
}
} else {
Long taskId = dto.getTaskId();
// Long siteId = dto.getSiteId();
// Long orgId = dto.getOrgId();
// Long siteId = dto.getSiteId();
// Long orgId = dto.getOrgId();
DevicePlanTask devicePlanTask = devicePlanTaskMapper.selectById(taskId);
if (devicePlanTask != null) {
NettyDevice device = deviceSessionManager.getDevice(devicePlanTask.getDeviceId());
@@ -456,7 +466,7 @@ public class DeviceTaskService {
return false;
}
//todo 完善
// todo 完善
public boolean pauseTask(DeviceTaskCommandDTO dto, String username) {
if (!StringUtils.isEmpty(dto.getDeviceId())) {
NettyDevice device = deviceSessionManager.getDevice(dto.getDeviceId());
@@ -467,18 +477,17 @@ public class DeviceTaskService {
Long taskId = dto.getTaskId();
DevicePlanTask devicePlanTask = devicePlanTaskMapper.selectById(taskId);
if (devicePlanTask != null) {
devicePlanTask.setUpdateTime(LocalDateTime.now());
devicePlanTask.setTaskStaus(DeviceTaskStaus.PAUSE);
devicePlanTask.setUpdateBy(username);
devicePlanTaskMapper.saveOrUpdate(devicePlanTask);
NettyDevice device = deviceSessionManager.getDevice(devicePlanTask.getDeviceId());
if (device != null) {
return device.pauseTask();
}
}
}
return false;
}
//todo 完善
public boolean recoveryTask(DeviceTaskCommandDTO dto, String username) {
// todo 完善
public boolean recoveryTask(DeviceTaskCommandDTO dto, String username) throws InterruptedException {
if (!StringUtils.isEmpty(dto.getDeviceId())) {
NettyDevice device = deviceSessionManager.getDevice(dto.getDeviceId());
if (device != null) {
@@ -486,16 +495,12 @@ public class DeviceTaskService {
}
} else {
Long taskId = dto.getTaskId();
Long siteId = dto.getSiteId();
Long orgId = dto.getOrgId();
DevicePlanTask devicePlanTask = devicePlanTaskMapper.selectById(taskId);
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
DevicePlanTask executeTask = siteMemory.getDeviceExecuteTask(devicePlanTask.getDeviceId());
if (Objects.equals(devicePlanTask.getId(), executeTask.getId())) {
devicePlanTask.setUpdateTime(LocalDateTime.now());
devicePlanTask.setTaskStaus(DeviceTaskStaus.EXECUTING);
devicePlanTask.setUpdateBy(username);
devicePlanTaskMapper.saveOrUpdate(devicePlanTask);
if (devicePlanTask != null) {
NettyDevice device = deviceSessionManager.getDevice(devicePlanTask.getDeviceId());
if (device != null) {
return device.recoveryTask();
}
}
}
return false;