diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/NewAtsTrainLoadService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/NewAtsTrainLoadService.java index 5a2bdcb89..5a79bf45e 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/NewAtsTrainLoadService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/NewAtsTrainLoadService.java @@ -92,12 +92,12 @@ public class NewAtsTrainLoadService { //重叠检测 SectionPosition headPosition = new SectionPosition(section, tp.getLocation() - section.getKmMin()); // SectionPosition headPosition = new SectionPosition(section, section.getStopPointByDirection(right)); - SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(headPosition, !right, train.getLen(), false); - boolean willOverlap = vrTrainRunningService.willOverlap(simulation, headPosition, tailPosition); - if(willOverlap){ - return; - } - BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(willOverlap, "列车重叠"); +// SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(headPosition, !right, train.getLen(), false); +// boolean willOverlap = vrTrainRunningService.willOverlap(simulation, headPosition, tailPosition); +// if(willOverlap){ +// return; +// } +// BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(willOverlap, "列车重叠"); // 列车上线并构建ATS监控列车信息 manualTrainOnlineAndSupervise(simulation, train, headPosition, right); } diff --git a/src/main/java/club/joylink/rtss/util/test/LogTest.java b/src/main/java/club/joylink/rtss/util/test/LogTest.java index 6d92fea4e..21ce5b09d 100644 --- a/src/main/java/club/joylink/rtss/util/test/LogTest.java +++ b/src/main/java/club/joylink/rtss/util/test/LogTest.java @@ -23,7 +23,10 @@ public class LogTest { LogTest lt = new LogTest(); List list = lt.readFile("d:\\spring.log2"); // lt.query(list,"024"); - lt.queryAll(list); + list = lt.query(list,"015",Section.SectionRoadType.RIGHT); + for (TrainPosition tp : list) { + System.out.println(tp.dateFormat() + " --->" + tp.toString()); + } } public void queryAll(List list){ @@ -43,6 +46,11 @@ public class LogTest { } }); } + + public List query(List list, List groups, Section.SectionRoadType roadType){ + List newList = list.stream().filter(d->groups.contains(d.getGroupNum()) && d.getRoadType() == roadType ).sorted(Comparator.comparing(TrainPosition::getReceiveTime)).collect(Collectors.toList()); + return newList; + } public List query(List list, String groupNum, Section.SectionRoadType roadType){ List newList = list.stream().filter(d->Objects.equals(d.getGroupNum(),groupNum) && d.getRoadType() == roadType ).sorted(Comparator.comparing(TrainPosition::getReceiveTime)).collect(Collectors.toList()); return newList; @@ -51,6 +59,20 @@ public class LogTest { List newList = list.stream().filter(d->Objects.equals(d.getGroupNum(),groupNum)).sorted(Comparator.comparing(TrainPosition::getReceiveTime)).collect(Collectors.toList()); return newList; } + public List readSource(String file){ + List list = Lists.newArrayList(); + try(BufferedReader reader = new BufferedReader(new FileReader(file))){ +// StringBuilder stringBuilder = new StringBuilder(); + String content = null; + while((content = reader.readLine()) != null){ + TrainPosition tp = JsonUtils.read(content, TrainPosition.class); + list.add(tp); + } + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } public List readFile(String file) { List list = Lists.newArrayList(); diff --git a/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java b/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java index 65e72ddb7..e0ffc10b8 100644 --- a/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java +++ b/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java @@ -6,6 +6,11 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + @Data @NoArgsConstructor @@ -28,6 +33,12 @@ public class TrainPosition { public boolean isRight(){ return this.direction == 1; } + + public String dateFormat(){ + Instant instant = Instant.ofEpochMilli(this.receiveTime); + ZoneId zone = ZoneId.systemDefault(); + return LocalDateTime.ofInstant(instant, zone).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + } @Override public String toString(){ return JsonUtils.writeValueNullableFieldAsString(this); diff --git a/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java b/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java index 01c880c37..b5f3a3f8e 100644 --- a/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java +++ b/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java @@ -6,6 +6,7 @@ import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.util.test.LogTest; import club.joylink.rtss.vo.ws.TrainPosition; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.springframework.messaging.simp.stomp.StompSession; import org.springframework.util.concurrent.ListenableFuture; @@ -37,16 +38,18 @@ public class StompClientManager { StompSession stompSession = future.get(); LogTest lt = new LogTest(); List list = lt.readFile("d:\\spring.log2"); +// List list = lt.readSource("d:\\t.txt"); // runToLeft(stompSession,"001"); // runToRight(stompSession,"002"); - list = lt.query(list,"004", Section.SectionRoadType.RIGHT); +// list = lt.query(list,"042",Section.SectionRoadType.RIGHT); +// list = lt.query(list, Lists.newArrayList("015","037"), Section.SectionRoadType.RIGHT); send(stompSession,list); } public static void send(StompSession stompSession,List list){ //48,55,56,65,75,121,127,138,150,155,162。。,183 //128 - for (int i = 183; i < list.size(); i++) { + for (int i = 0; i < list.size(); i++) { TrainPosition tp = list.get(i); String val = JsonUtils.writeValueNullableFieldAsString(tp); Instant instant = Instant.ofEpochMilli(tp.getReceiveTime()); @@ -58,7 +61,10 @@ public class StompClientManager { if(i > 0){ TrainPosition old = list.get(i - 1); try { - long sleepTime = tp.getReceiveTime() - old.getReceiveTime(); + long sleepTime = (tp.getReceiveTime() - old.getReceiveTime()); + if(sleepTime > 10000){ + sleepTime = sleepTime / 1000; + } System.out.println("index:" + i + "sleep:"+sleepTime); TimeUnit.MILLISECONDS.sleep(sleepTime); } catch (InterruptedException e) {