Merge branch 'dev_control' into dev_new_connect
# Conflicts: # .idea/workspace.xml
This commit is contained in:
@@ -58,8 +58,8 @@ public class NettyDevice extends Connector {
|
||||
// todo 注册的时候更新 siteId
|
||||
private Device device;
|
||||
|
||||
//todo 假如设置一个当前控制的token
|
||||
private String currentControlToken;
|
||||
//todo 当前登录的账号的token 以token为控制的权限
|
||||
private String token;
|
||||
|
||||
@JsonIgnore
|
||||
private DevicePlanTaskMapper devicePlanTaskMapper = SpringUtils.getBean(DevicePlanTaskMapper.class);
|
||||
|
||||
@@ -30,6 +30,9 @@ public class DeviceSessionManager {
|
||||
// 设备ID -> 设备对象(业务实体)
|
||||
private final ConcurrentHashMap<String, NettyDevice> deviceMap = new ConcurrentHashMap<>();
|
||||
|
||||
//当前设备的控制权在哪 登录的账号 deviceId(下位机) -> token key 唯一保证一个deviceId 只有一个控制权
|
||||
private final ConcurrentHashMap<String, String> controllerMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 设备ID -> Channel(通信通道)
|
||||
private final ConcurrentHashMap<String, Channel> channelMap = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -105,6 +108,64 @@ public class DeviceSessionManager {
|
||||
return deviceMap.get(deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取有控制权的 客户端
|
||||
*/
|
||||
public String getMaster(String deviceId) {
|
||||
return controllerMap.get(deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户端当前 控制的设备
|
||||
*/
|
||||
public String getControl(String token) {
|
||||
for (String key : controllerMap.keySet()) {
|
||||
if (controllerMap.get(key).equals(token)) {
|
||||
return controllerMap.get(token);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void lock(String deviceId, String token) {
|
||||
if (!StringUtils.isEmpty(deviceId) && !StringUtils.isEmpty(token)) {
|
||||
controllerMap.put(deviceId, token);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean unLock(String token) {
|
||||
if (!StringUtils.isEmpty(token)) {
|
||||
Iterator<String> iterator = controllerMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String key = iterator.next();
|
||||
if (controllerMap.get(key).equals(token)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean unLock(String deviceId, String token, boolean force) {
|
||||
if (!StringUtils.isEmpty(deviceId)) {
|
||||
if (force) {
|
||||
controllerMap.remove(deviceId);
|
||||
return true;
|
||||
} else {
|
||||
String nowToken = controllerMap.get(deviceId);
|
||||
if (!StringUtils.isEmpty(token) && nowToken.equals(token)) {
|
||||
controllerMap.remove(deviceId);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 模糊匹配
|
||||
public List<NettyDevice> getDevicesLike(String query) {
|
||||
return deviceMap.values().stream()
|
||||
|
||||
Reference in New Issue
Block a user