Merge remote-tracking branch 'origin/test' into dev
# Conflicts: # src/main/java/club/joylink/rtss/services/VirtualRealityIbpService.java
This commit is contained in:
commit
4929e21076
@ -34,31 +34,31 @@ public class SimulationManageServiceImpl implements SimulationManageService {
|
||||
|
||||
@Autowired
|
||||
private GroupSimulationService groupSimulationService;
|
||||
|
||||
@Scheduled(fixedRate = 500)
|
||||
public void deleteUselessSimulation() {
|
||||
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
|
||||
groupSimulationMap.forEach((group, simulation) -> {
|
||||
List<SimulationUser> userList = simulation.getSimulationUsers();
|
||||
boolean hasOnline = false;
|
||||
for (SimulationUser simulationUser : userList) {
|
||||
if (simulationUser.isOnline()) {
|
||||
hasOnline = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
LocalDateTime delBaseTime = simulation.getDelBaseTime();
|
||||
if (hasOnline && Objects.nonNull(delBaseTime)) {
|
||||
simulation.setDelBaseTime(null);
|
||||
} else if (!hasOnline && Objects.isNull(delBaseTime)) {
|
||||
simulation.setDelBaseTime(LocalDateTime.now());
|
||||
} else if (!hasOnline && Objects.nonNull(delBaseTime)) {
|
||||
if (LocalDateTime.now().isAfter(delBaseTime.plusMinutes(3))) {
|
||||
this.destroySimulation(group, simulation.getCreator());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//
|
||||
// @Scheduled(fixedRate = 500)
|
||||
// public void deleteUselessSimulation() {
|
||||
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
|
||||
// groupSimulationMap.forEach((group, simulation) -> {
|
||||
// List<SimulationUser> userList = simulation.getSimulationUsers();
|
||||
// boolean hasOnline = false;
|
||||
// for (SimulationUser simulationUser : userList) {
|
||||
// if (simulationUser.isOnline()) {
|
||||
// hasOnline = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// LocalDateTime delBaseTime = simulation.getDelBaseTime();
|
||||
// if (hasOnline && Objects.nonNull(delBaseTime)) {
|
||||
// simulation.setDelBaseTime(null);
|
||||
// } else if (!hasOnline && Objects.isNull(delBaseTime)) {
|
||||
// simulation.setDelBaseTime(LocalDateTime.now());
|
||||
// } else if (!hasOnline && Objects.nonNull(delBaseTime)) {
|
||||
// if (LocalDateTime.now().isAfter(delBaseTime.plusMinutes(3))) {
|
||||
// this.destroySimulation(group, simulation.getCreator());
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
@Override
|
||||
public PageVO<SimulationVO> pagingQueryExistSimulations(ExistSimulationQueryVO queryVO) {
|
||||
|
@ -56,6 +56,10 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
|
||||
private static final int PAUSE = 0;
|
||||
private static final int ERROR = 4;
|
||||
private static final int DESTROY = 7;
|
||||
/**
|
||||
* 所有用户都没有订阅仿真开始时间
|
||||
*/
|
||||
private LocalDateTime noUserStartTime;
|
||||
/**
|
||||
* 仿真运行发生异常时,保存的异常信息
|
||||
*/
|
||||
@ -329,6 +333,7 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
|
||||
* 仿真销毁时调用,用于清除定时执行逻辑对象
|
||||
*/
|
||||
public void destroy() {
|
||||
log.debug(String.format("仿真[%s]销毁", this.id));
|
||||
this.future.cancel(true);
|
||||
this.updateState(DESTROY);
|
||||
}
|
||||
@ -425,6 +430,9 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
|
||||
}
|
||||
|
||||
public void addSimulationUser(U user) {
|
||||
if (this.simulationUserMap.isEmpty()) {
|
||||
user.creator = true;
|
||||
}
|
||||
this.simulationUserMap.put(user.getId(), user);
|
||||
}
|
||||
|
||||
@ -576,4 +584,8 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
|
||||
this.operationList.add(memberOperation);
|
||||
}
|
||||
}
|
||||
|
||||
public void setNoUserStartTime(LocalDateTime noUserStartTime) {
|
||||
this.noUserStartTime = noUserStartTime;
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,10 @@ public class SimulationCommonController {
|
||||
@GetMapping("/list")
|
||||
public List<SimulationInfoVO> queryInfo() {
|
||||
List<Simulation> simulationList = this.simulationManager.getSimulationList();
|
||||
return simulationList.stream()
|
||||
List<SimulationInfoVO> list = simulationList.stream()
|
||||
.map(Simulation::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
return list;
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/pause")
|
||||
|
@ -5,13 +5,17 @@ import club.joylink.rtss.simulation.event.SimulationFaultInjectEvent;
|
||||
import club.joylink.rtss.simulation.event.SimulationFaultRemoveEvent;
|
||||
import club.joylink.rtss.simulation.event.SimulationMemberPlayChangeEvent;
|
||||
import club.joylink.rtss.simulation.messaging.websocket.DefaultMessageSender;
|
||||
import club.joylink.rtss.simulation.rt.RtSimulation;
|
||||
import club.joylink.rtss.simulation.rt.RtSimulationUser;
|
||||
import club.joylink.rtss.simulation.vo.SimulationFaultVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -27,6 +31,35 @@ public class SimulationManager {
|
||||
@Autowired
|
||||
private DefaultMessageSender defaultMessageSender;
|
||||
|
||||
public static final int Destroy_Time = 180; // RtSimulation无用户时销毁时间,单位s
|
||||
@Scheduled(fixedRate = 5000)
|
||||
public void cleanUselessRtSimulation() {
|
||||
simulationCache.values().stream()
|
||||
.forEach(simulation -> {
|
||||
boolean hasSubUser = false;
|
||||
for (Object su : simulation.getSimulationUsers()) {
|
||||
SimulationUser simulationUser = (SimulationUser) su;
|
||||
if (simulationUser.hasSubscribe()) {
|
||||
hasSubUser = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
LocalDateTime noUserStartTime = simulation.getNoUserStartTime();
|
||||
if (hasSubUser) {
|
||||
if (noUserStartTime != null) {
|
||||
simulation.setNoUserStartTime(null);
|
||||
}
|
||||
} else {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (noUserStartTime == null) {
|
||||
simulation.setNoUserStartTime(now);
|
||||
} else if (noUserStartTime.plusSeconds(Destroy_Time).isBefore(now)) {
|
||||
this.destroy(simulation.getId());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Simulation save(Simulation simulation) {
|
||||
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(simulationCache.containsKey(simulation.getId()),
|
||||
String.format("已经存在id为[%s]的仿真[%s]", simulation.getId(), simulation.debugStr()));
|
||||
|
@ -15,6 +15,8 @@ public abstract class SimulationUser {
|
||||
* 仿真用户唯一标识,并且是发布订阅消息时的用户唯一标识
|
||||
*/
|
||||
private String id;
|
||||
private String name;
|
||||
boolean creator;
|
||||
/**
|
||||
* 用户仿真消息订阅
|
||||
* key-wsSessionId
|
||||
@ -24,14 +26,23 @@ public abstract class SimulationUser {
|
||||
|
||||
private String memberId; // 扮演的成员id
|
||||
|
||||
public SimulationUser(String id) {
|
||||
public SimulationUser(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
public String getMemberId() {
|
||||
return memberId;
|
||||
}
|
||||
@ -65,6 +76,10 @@ public abstract class SimulationUser {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasSubscribe() {
|
||||
return !this.wsSubscribeMap.isEmpty();
|
||||
}
|
||||
|
||||
public void disconnect(String wsSessionId) {
|
||||
this.wsSubscribeMap.remove(wsSessionId);
|
||||
log.debug(String.format("用户[%s]断开了连接[%s]", this.id, wsSessionId));
|
||||
|
@ -13,6 +13,7 @@ import club.joylink.rtss.simulation.cbtc.conversation.Conversation;
|
||||
import club.joylink.rtss.simulation.cbtc.conversation.ConversationMember;
|
||||
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
|
||||
import club.joylink.rtss.simulation.cbtc.data.vo.OldSimulationInfoVO;
|
||||
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.DeviceQueryFuture;
|
||||
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
|
||||
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
|
||||
@ -391,7 +392,7 @@ public class Simulation extends club.joylink.rtss.simulation.Simulation<Simulati
|
||||
|
||||
@Override
|
||||
public SimulationInfoVO buildVO() {
|
||||
return null;
|
||||
return new OldSimulationInfoVO(this);
|
||||
}
|
||||
|
||||
public void addLog(SimulationLog log) {
|
||||
|
@ -0,0 +1,20 @@
|
||||
package club.joylink.rtss.simulation.cbtc.data.vo;
|
||||
|
||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||
import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams;
|
||||
import club.joylink.rtss.simulation.vo.SimulationInfoVO;
|
||||
import club.joylink.rtss.vo.map.MapVO;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class OldSimulationInfoVO extends SimulationInfoVO {
|
||||
private String prodType;
|
||||
private MapVO map;
|
||||
|
||||
public OldSimulationInfoVO(Simulation simulation) {
|
||||
super(simulation);
|
||||
SimulationBuildParams buildParams = simulation.getBuildParams();
|
||||
this.prodType = buildParams.getProdType().getCode();
|
||||
this.map = buildParams.getMap().buildBasicInfo();
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@ public class SimulationUser extends club.joylink.rtss.simulation.SimulationUser
|
||||
private SimulationMember playedMember;
|
||||
|
||||
public SimulationUser(Simulation simulation, LoginUserInfoVO loginUserInfoVO) {
|
||||
super(String.valueOf(loginUserInfoVO.getAccountVO().getId()));
|
||||
super(String.valueOf(loginUserInfoVO.getAccountVO().getId()), loginUserInfoVO.getAccountVO().getNickname());
|
||||
this.group = simulation.getId();
|
||||
this.user = loginUserInfoVO.getAccountVO();
|
||||
this.projectDevice = loginUserInfoVO.getDeviceVO();
|
||||
@ -56,7 +56,7 @@ public class SimulationUser extends club.joylink.rtss.simulation.SimulationUser
|
||||
}
|
||||
|
||||
public SimulationUser(Simulation simulation, AccountVO user) {
|
||||
super(user.getId().toString());
|
||||
super(user.getId().toString(), user.getNickname());
|
||||
this.group = simulation.getId();
|
||||
this.user = user;
|
||||
}
|
||||
|
@ -62,13 +62,13 @@ public class RtSimulationService {
|
||||
public RtSimulation create(AccountVO accountVO, Long mapId, MapPrdTypeEnum prdTypeEnum) {
|
||||
Objects.requireNonNull(mapId);
|
||||
MapVO mapVO = this.mapService.getMapDetail(mapId);
|
||||
RtSimulationUser creator = new RtSimulationUser(accountVO.getId().toString());
|
||||
RtSimulationUser creator = new RtSimulationUser(accountVO.getId().toString(), accountVO.getNickname());
|
||||
RtSimulation rtSimulation = new RtSimulation(SimulationIdGenerator.buildId(), creator, prdTypeEnum);
|
||||
this.simulationManager.save(rtSimulation);
|
||||
try {
|
||||
rtSimulation.mapVO = mapVO;
|
||||
this.loadingMap(rtSimulation, mapVO);
|
||||
this.loadRunPlan(rtSimulation, this.queryUserRunPlan(accountVO.getId(), mapId));
|
||||
this.loadRunPlan(rtSimulation, this.queryUserRunPlan(mapId, accountVO.getId()));
|
||||
this.initSimulationMember(rtSimulation);
|
||||
this.initCreatorPlayMember(rtSimulation, mapVO);
|
||||
} catch (Exception e) {
|
||||
|
@ -4,8 +4,8 @@ import club.joylink.rtss.simulation.SimulationUser;
|
||||
import club.joylink.rtss.simulation.vo.SimulationUserVO;
|
||||
|
||||
public class RtSimulationUser extends SimulationUser {
|
||||
public RtSimulationUser(String id) {
|
||||
super(id);
|
||||
public RtSimulationUser(String id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -185,7 +185,7 @@ public class TlTrain extends TlDevice {
|
||||
// G7(7, 95, 250, 0.41f, 0.29f),
|
||||
// G8(8, 120, 300, 0.35f, 0.21f),
|
||||
// G9(9, 150, 360, 0.26f, 0.16f),
|
||||
G(1, 3, 360, 1.69f, 0.18f)
|
||||
G(1, 3, 350, 1.69f, 0.18f)
|
||||
;
|
||||
|
||||
int gear;
|
||||
|
@ -4,6 +4,7 @@ import club.joylink.rtss.simulation.Simulation;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class SimulationInfoVO {
|
||||
@ -18,6 +19,7 @@ public class SimulationInfoVO {
|
||||
// Integer minute;
|
||||
// Integer second;
|
||||
Integer state;
|
||||
List<SimulationUserVO> userList;
|
||||
|
||||
public SimulationInfoVO(Simulation simulation) {
|
||||
this.id = simulation.getId();
|
||||
@ -34,4 +36,7 @@ public class SimulationInfoVO {
|
||||
// this.second = systemTime.getSecond();
|
||||
}
|
||||
|
||||
public void setUserList(List<SimulationUserVO> userList) {
|
||||
this.userList = userList;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ public class SimulationUserVO {
|
||||
* 仿真用户唯一标识,并且是发布订阅消息时的用户唯一标识
|
||||
*/
|
||||
private String id;
|
||||
private String name;
|
||||
private int creator;
|
||||
/**
|
||||
* 用户仿真消息订阅
|
||||
* key-wsSessionId
|
||||
@ -23,7 +25,18 @@ public class SimulationUserVO {
|
||||
|
||||
public SimulationUserVO(SimulationUser user) {
|
||||
this.id = user.getId();
|
||||
this.name = user.getName();
|
||||
this.creator = convert(user.isCreator());
|
||||
this.wsSubscribeMap = user.getSubscribeMap();
|
||||
this.memberId = user.getMemberId();
|
||||
}
|
||||
|
||||
public int convert(boolean val) {
|
||||
if (val) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user