#update
This commit is contained in:
@@ -2,6 +2,7 @@ package com.maibu.core.business.device;
|
|||||||
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.maibu.core.business.DevicePlanTask;
|
import com.maibu.core.business.DevicePlanTask;
|
||||||
import com.maibu.core.business.DeviceRunStatistics;
|
import com.maibu.core.business.DeviceRunStatistics;
|
||||||
import com.maibu.core.business.PlanPath;
|
import com.maibu.core.business.PlanPath;
|
||||||
@@ -48,8 +49,10 @@ public class NettyDevice extends Connector {
|
|||||||
|
|
||||||
private boolean executingTask = false;
|
private boolean executingTask = false;
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
private DevicePlanTaskMapper devicePlanTaskMapper = SpringUtils.getBean(DevicePlanTaskMapper.class);
|
private DevicePlanTaskMapper devicePlanTaskMapper = SpringUtils.getBean(DevicePlanTaskMapper.class);
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
private WorkRecordMapper workRecordMapper = SpringUtils.getBean(WorkRecordMapper.class);
|
private WorkRecordMapper workRecordMapper = SpringUtils.getBean(WorkRecordMapper.class);
|
||||||
|
|
||||||
public NettyDevice(String connectorId) {
|
public NettyDevice(String connectorId) {
|
||||||
|
|||||||
@@ -129,6 +129,14 @@ public class DeviceSessionManager {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NettyDevice getCurrentControl(String slaveId) {
|
||||||
|
// 获取所有连接的主机 不区分状态
|
||||||
|
return deviceMap.values().stream()
|
||||||
|
.filter(device -> ObjectUtil.equals(device.getCurrentSlaveId(), slaveId)
|
||||||
|
&& ConnectorStatus.ACTIVE.equals(device.getConnectorStatus()))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 模糊匹配
|
/// 模糊匹配
|
||||||
public NettyDevice getUserControl(String userName) {
|
public NettyDevice getUserControl(String userName) {
|
||||||
|
|||||||
@@ -217,70 +217,33 @@ public class TransferDeviceService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public DeviceControlDTO remoteControl(DeviceBindDTO bindDTO, LoginUser user) {
|
|
||||||
// try {
|
|
||||||
// String slaveId = bindDTO.getDeviceId();
|
|
||||||
// String platform = bindDTO.getPlatform();
|
|
||||||
// String userName = user.getUsername();
|
|
||||||
// String masterId = userName + ":" + platform;
|
|
||||||
// DeviceControlDTO dto = new DeviceControlDTO();
|
|
||||||
// NettyDevice deviceMaster = sessionManager.getDevice(masterId);
|
|
||||||
// log.info("remoteControl deviceMaster:{}", masterId);
|
|
||||||
// if (deviceMaster != null) {
|
|
||||||
// if (ConnectorStatus.ACTIVE.equals(deviceMaster.getConnectorStatus())) {
|
|
||||||
// if (!StringUtils.isEmpty(deviceMaster.getCurrentSlaveId())) {
|
|
||||||
// if (deviceMaster.getCurrentSlaveId().equalsIgnoreCase(slaveId)) {
|
|
||||||
// dto.setRemoteControl(true);
|
|
||||||
// dto.setOwner(platform);
|
|
||||||
// } else {
|
|
||||||
// dto.setRemoteControl(false);
|
|
||||||
// dto.setReason("occupied");
|
|
||||||
// List<NettyDevice> list = sessionManager.getSlaveControl(slaveId);
|
|
||||||
// if (!CollectionUtils.isEmpty(list)) {
|
|
||||||
// dto.setOwner(list.get(0).getConnectorId());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// dto.setRemoteControl(false);
|
|
||||||
// dto.setReason("no control");
|
|
||||||
// List<NettyDevice> list = sessionManager.getSlaveControl(slaveId);
|
|
||||||
// if (!CollectionUtils.isEmpty(list)) {
|
|
||||||
// dto.setOwner(list.get(0).getConnectorId());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// dto.setRemoteControl(false);
|
|
||||||
// dto.setReason("not active");
|
|
||||||
// List<NettyDevice> list = sessionManager.getSlaveControl(slaveId);
|
|
||||||
// if (!CollectionUtils.isEmpty(list)) {
|
|
||||||
// dto.setOwner(list.get(0).getConnectorId());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// dto.setRemoteControl(false);
|
|
||||||
// dto.setReason("not exist");
|
|
||||||
// List<NettyDevice> list = sessionManager.getSlaveControl(slaveId);
|
|
||||||
// if (!CollectionUtils.isEmpty(list)) {
|
|
||||||
// dto.setOwner(list.get(0).getConnectorId());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return dto;
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// log.error(e.getMessage());
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
public DeviceControlDTO remoteControl(DeviceBindDTO bindDTO, LoginUser user) {
|
public DeviceControlDTO remoteControl(DeviceBindDTO bindDTO, LoginUser user) {
|
||||||
try {
|
try {
|
||||||
// String slaveId = bindDTO.getDeviceId();
|
String slaveId = bindDTO.getDeviceId();
|
||||||
String platform = bindDTO.getPlatform();
|
String platform = bindDTO.getPlatform();
|
||||||
String userName = user.getUsername();
|
String userName = user.getUsername();
|
||||||
String masterId = userName + ":" + platform;
|
String masterId = userName + ":" + platform;
|
||||||
DeviceControlDTO dto = new DeviceControlDTO();
|
DeviceControlDTO dto = new DeviceControlDTO();
|
||||||
NettyDevice deviceMaster = sessionManager.getDevice(masterId);
|
NettyDevice deviceMaster = sessionManager.getDevice(masterId);
|
||||||
log.info("remoteControl deviceMaster:{}", masterId);
|
log.info("remoteControl deviceMaster:{}", masterId);
|
||||||
|
|
||||||
|
// //TODO 拓展当前控制不是同一个账号
|
||||||
|
// NettyDevice currentDevice = sessionManager.getCurrentControl(slaveId);
|
||||||
|
// if(currentDevice != null){
|
||||||
|
// if(currentDevice.getConnectorId().equals(masterId)){
|
||||||
|
// dto.setRemoteControl(true);
|
||||||
|
// dto.setOwner(platform);
|
||||||
|
// }else{
|
||||||
|
// dto.setRemoteControl(false);
|
||||||
|
// dto.setOwner(currentDevice.getConnectorId());
|
||||||
|
// }
|
||||||
|
// }else{
|
||||||
|
// dto.setRemoteControl(false);
|
||||||
|
// dto.setOwner(null);
|
||||||
|
// dto.setReason("occupied");
|
||||||
|
// }
|
||||||
|
|
||||||
if (deviceMaster != null) {
|
if (deviceMaster != null) {
|
||||||
if (ConnectorStatus.ACTIVE.equals(deviceMaster.getConnectorStatus())) {
|
if (ConnectorStatus.ACTIVE.equals(deviceMaster.getConnectorStatus())) {
|
||||||
dto.setRemoteControl(true);
|
dto.setRemoteControl(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user