| | |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.manager.common.utils.MapDataUtils; |
| | | import com.zy.acs.manager.core.constant.MapDataConstant; |
| | | import com.zy.acs.manager.core.domain.SortCodeDto; |
| | | import com.zy.acs.manager.core.domain.UnlockPathTask; |
| | | import com.zy.acs.manager.core.service.astart.*; |
| | | import com.zy.acs.manager.core.service.astart.domain.AStarNavigateNode; |
| | | import com.zy.acs.manager.core.service.astart.domain.DynamicNode; |
| | | import com.zy.acs.manager.core.service.floyd.FloydNavigateService; |
| | | import com.zy.acs.manager.manager.entity.Code; |
| | | import com.zy.acs.manager.manager.entity.Loc; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.IntStream; |
| | | |
| | | /** |
| | | * Created by vincent on 2023/6/14 |
| | |
| | | return turnMatrixNode == TurnNodeType.TURN.val; |
| | | } |
| | | |
| | | public List<String> queryCodeListFromDynamicNode(Integer lev, String nodeType) { |
| | | if (Cools.isEmpty(nodeType)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | lev = Optional.ofNullable(lev).orElse(MapDataDispatcher.MAP_DEFAULT_LEV); |
| | | |
| | | DynamicNode[][] dynamicMatrix = mapDataDispatcher.getDynamicMatrix(lev); |
| | | String[][] codeMatrix = mapDataDispatcher.getCodeMatrix(lev); |
| | | |
| | | // concurrent |
| | | ConcurrentLinkedQueue<SortCodeDto> codeList = new ConcurrentLinkedQueue<>(); |
| | | IntStream.range(0, codeMatrix.length).parallel().forEach(i -> { |
| | | for (int j = 0; j < codeMatrix[i].length; j++) { |
| | | DynamicNode dynamicNode = dynamicMatrix[i][j]; |
| | | if (nodeType.equals(dynamicNode.getVehicle())) { |
| | | codeList.add(new SortCodeDto(codeMatrix[i][j], dynamicNode.getSerial())); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | // synchronize |
| | | // List<SortCodeDto> codeList = new ArrayList<>(); |
| | | // for (int i = 0; i < codeMatrix.length; i++) { |
| | | // for (int j = 0; j < codeMatrix[i].length; j++) { |
| | | // DynamicNode dynamicNode = dynamicMatrix[i][j]; |
| | | // if (nodeType.equals(dynamicNode.getVehicle())) { |
| | | // codeList.add(new SortCodeDto(codeMatrix[i][j], dynamicNode.getSerial())); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | return codeList.stream() |
| | | .sorted(Comparator.comparingInt(SortCodeDto::getSerial)) |
| | | .map(SortCodeDto::getCode) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | public Map<String, List<String>> queryCodeListFromDynamicNode(Integer lev, Set<String> vehicles) { |
| | | if (Cools.isEmpty(vehicles)) { |
| | | return new HashMap<>(); |
| | | } |
| | | lev = Optional.ofNullable(lev).orElse(MapDataDispatcher.MAP_DEFAULT_LEV); |
| | | |
| | | DynamicNode[][] dynamicMatrix = mapDataDispatcher.getDynamicMatrix(lev); |
| | | String[][] codeMatrix = mapDataDispatcher.getCodeMatrix(lev); |
| | | |
| | | Map<String, List<SortCodeDto>> map = new HashMap<>(vehicles.size()); |
| | | |
| | | for (int i = 0; i < codeMatrix.length; i++) { |
| | | for (int j = 0; j < codeMatrix[i].length; j++) { |
| | | DynamicNode dynamicNode = dynamicMatrix[i][j]; |
| | | String vehicle = dynamicNode.getVehicle(); |
| | | |
| | | if (vehicles.contains(vehicle)) { |
| | | int serial = dynamicNode.getSerial(); |
| | | map.computeIfAbsent(vehicle, k -> new ArrayList<>()).add(new SortCodeDto(codeMatrix[i][j], serial)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | Map<String, List<String>> result = new HashMap<>(vehicles.size()); |
| | | for (Map.Entry<String, List<SortCodeDto>> entry : map.entrySet()) { |
| | | List<String> codeDataList = entry.getValue().stream() |
| | | .sorted(Comparator.comparingInt(SortCodeDto::getSerial)) |
| | | .map(SortCodeDto::getCode) |
| | | .collect(Collectors.toList()); |
| | | result.put(entry.getKey(), codeDataList); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | } |