|
|
@@ -1,5 +1,8 @@
|
|
|
package top.haijunit.train.domain.entity;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import jakarta.persistence.Entity;
|
|
|
import jakarta.persistence.GeneratedValue;
|
|
|
import jakarta.persistence.GenerationType;
|
|
|
@@ -7,9 +10,15 @@ import jakarta.persistence.Id;
|
|
|
import lombok.Data;
|
|
|
import top.haijunit.train.domain.constant.DirectionEnum;
|
|
|
import top.haijunit.train.domain.constant.SignalStateEnum;
|
|
|
+import top.haijunit.train.domain.constant.SwitchStateEnum;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author zhang
|
|
|
@@ -39,4 +48,35 @@ public class RouteEntity implements Serializable {
|
|
|
private BigDecimal trigPosition;
|
|
|
// 进路方向
|
|
|
private DirectionEnum direction;
|
|
|
+
|
|
|
+ public ArrayList<Long> getSelectionList() {
|
|
|
+ if (StrUtil.isBlank(this.getSeleIds())) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return StrUtil.split(this.getSeleIds(), "-").stream().map(item -> Convert.toLong(item, 0L)).collect(Collectors.toCollection(ArrayList::new));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<Long> getSwitchList() {
|
|
|
+ if (StrUtil.isBlank(this.getSwitchId())) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return StrUtil.split(this.getSwitchId(), "-").stream().map(item -> Convert.toLong(item, 0L)).collect(Collectors.toCollection(ArrayList::new));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<SwitchStateEnum> getSwitchStateList() {
|
|
|
+ if (StrUtil.isBlank(this.getSwitchState())) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return StrUtil.split(this.getSwitchState(), "-").stream().map(item -> SwitchStateEnum.getByCode(Convert.toInt(item, SwitchStateEnum.Forward.getCode()))).collect(Collectors.toCollection(ArrayList::new));
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<Long, SwitchStateEnum> getSignalMap() {
|
|
|
+ ArrayList<Long> switchList = this.getSwitchList();
|
|
|
+ ArrayList<SwitchStateEnum> switchStateList = this.getSwitchStateList();
|
|
|
+ Map<Long, SwitchStateEnum> map = new HashMap<>();
|
|
|
+ for (int i = 0; i < switchList.size(); i++) {
|
|
|
+ map.put(switchList.get(i), Optional.of(CollUtil.get(switchStateList, i)).orElse(SwitchStateEnum.Forward));
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|