修改限制一个人只能创建一个仿真的逻辑
This commit is contained in:
parent
b55a7d78e2
commit
9b54fb9f78
@ -18,6 +18,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -30,12 +31,6 @@ public class SimulationManager {
|
|||||||
|
|
||||||
public static final Map<String, Simulation> simulationCache = new ConcurrentHashMap<>();
|
public static final Map<String, Simulation> simulationCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户与仿真。
|
|
||||||
* 为解决一个用户创建多个仿真的问题,限制一个用户只能创建一个仿真(运行图测试等没有用户交互的仿真不算)
|
|
||||||
*/
|
|
||||||
public static final Map<String, Simulation> userSimulationMap = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public static final int Destroy_Time = 180; // RtSimulation无用户时销毁时间,单位s
|
public static final int Destroy_Time = 180; // RtSimulation无用户时销毁时间,单位s
|
||||||
@Scheduled(fixedRate = 5000)
|
@Scheduled(fixedRate = 5000)
|
||||||
public void cleanUselessRtSimulation() {
|
public void cleanUselessRtSimulation() {
|
||||||
@ -73,12 +68,10 @@ public class SimulationManager {
|
|||||||
public Simulation save(Simulation simulation) {
|
public Simulation save(Simulation simulation) {
|
||||||
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(simulationCache.containsKey(simulation.getId()),
|
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(simulationCache.containsKey(simulation.getId()),
|
||||||
String.format("已经存在id为[%s]的仿真[%s]", simulation.getId(), simulation.debugStr()));
|
String.format("已经存在id为[%s]的仿真[%s]", simulation.getId(), simulation.debugStr()));
|
||||||
String creatorId = simulation.getCreatorId();
|
|
||||||
Simulation oldSimulation = userSimulationMap.put(creatorId, simulation);
|
|
||||||
simulationCache.put(simulation.getId(), simulation);
|
simulationCache.put(simulation.getId(), simulation);
|
||||||
simulation.setMessageSender(this.defaultMessageSender); // 设置默认的消息发布器
|
simulation.setMessageSender(this.defaultMessageSender); // 设置默认的消息发布器
|
||||||
simulation.loadModule(); // 加载通用模块
|
simulation.loadModule(); // 加载通用模块
|
||||||
return oldSimulation;
|
return simulation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Simulation queryById(String id) {
|
public Simulation queryById(String id) {
|
||||||
@ -218,4 +211,10 @@ public class SimulationManager {
|
|||||||
this.applicationContext.publishEvent(new SimulationFaultRemoveEvent(this, simulation, deviceFault));
|
this.applicationContext.publishEvent(new SimulationFaultRemoveEvent(this, simulation, deviceFault));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Simulation queryByCreatorId(String creatorId) {
|
||||||
|
return simulationCache.values().stream()
|
||||||
|
.filter(simulation -> Objects.equals(simulation.getCreatorId(), creatorId))
|
||||||
|
.findAny().orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,12 +154,14 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic
|
|||||||
params.getMap().setIscsSystemResourceList(resourceList);
|
params.getMap().setIscsSystemResourceList(resourceList);
|
||||||
|
|
||||||
Simulation simulation = SimulationBuilder.build(group, params);
|
Simulation simulation = SimulationBuilder.build(group, params);
|
||||||
// 缓存
|
// 查询该用户是否已有创建的仿真
|
||||||
club.joylink.rtss.simulation.Simulation needDestroySimulation = simulationManager.save(simulation);
|
club.joylink.rtss.simulation.Simulation oldSimulation = simulationManager.queryByCreatorId(simulation.getCreatorId());
|
||||||
if (needDestroySimulation != null) {
|
if (oldSimulation != null) {
|
||||||
groupSimulationService.clearSimulation(needDestroySimulation.getId());
|
groupSimulationService.clearSimulation(oldSimulation.getId());
|
||||||
log.info(String.format("仿真[%s]因用户创建新仿真而销毁", needDestroySimulation.getId()));
|
log.info(String.format("仿真[%s]因用户创建新仿真而销毁", oldSimulation.getId()));
|
||||||
}
|
}
|
||||||
|
// 缓存
|
||||||
|
simulationManager.save(simulation);
|
||||||
// TODO: 2021/9/10 暂时放在这里
|
// TODO: 2021/9/10 暂时放在这里
|
||||||
simulation.addMessagePublisher(new IscsStatusPublisher(simulation));
|
simulation.addMessagePublisher(new IscsStatusPublisher(simulation));
|
||||||
// 初始化设备状态
|
// 初始化设备状态
|
||||||
|
Loading…
Reference in New Issue
Block a user