| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.common.constant.RedisConstant; |
| | | import com.zy.acs.common.utils.GsonUtils; |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.exception.CoolException; |
| | | import com.zy.acs.manager.core.domain.SortCodeDto; |
| | | import com.zy.acs.manager.core.service.astart.domain.DynamicNode; |
| | | import com.zy.acs.manager.core.utils.RouteGenerator; |
| | | import com.zy.acs.manager.manager.entity.Code; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Created by vincent on 6/6/2024 |
| | |
| | | } |
| | | |
| | | public String[][] initWaveMatrix(Integer lev) { |
| | | log.info("There is initializing Wave Matrix......"); |
| | | lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); |
| | | |
| | | String[][] codeMatrix = getCodeMatrix(lev); |
| | |
| | | cdaArr.add(yIdxList.get(i)); |
| | | cdaMatrix[i][j] = JSON.toJSONString(cdaArr); |
| | | } else { |
| | | Code currCode = codeService.selectByData(codeMatrix[i][j]); |
| | | Code currCode = codeService.getCacheByData(codeMatrix[i][j]); |
| | | if (null != currCode) { |
| | | List<Double> cdaArr = new ArrayList<>(); |
| | | cdaArr.add(currCode.getX()); |
| | |
| | | if (CodeNodeType.NONE.val.equals(codeMatrix[i][j])) { |
| | | turnMatrix[i][j] = TurnNodeType.NONE.val; |
| | | } else { |
| | | Code currCode = codeService.selectByData(codeMatrix[i][j]); |
| | | Code currCode = codeService.getCacheByData(codeMatrix[i][j]); |
| | | List<String> neighborCodeList = routeService.findCodeDataOfSingle(currCode.getId()); |
| | | |
| | | switch (neighborCodeList.size()) { |
| | |
| | | return null; |
| | | } |
| | | |
| | | public List<String> queryCodeListFromDynamicNode(Integer lev, String nodeType) { |
| | | if (Cools.isEmpty(nodeType)) { |
| | | public List<int[]> getCodeMatrixIdxList(Integer lev, List<String> codeDataList) { |
| | | if (Cools.isEmpty(codeDataList)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); |
| | | |
| | | List<SortCodeDto> codeList = new ArrayList<>(); |
| | | DynamicNode[][] dynamicMatrix = getDynamicMatrix(lev); |
| | | String[][] codeMatrix = this.getCodeMatrix(lev); |
| | | |
| | | List<int[]> codeMatrixIdxList = new ArrayList<>(); |
| | | |
| | | Map<String, int[]> map = new HashMap<>(); |
| | | Set<String> codeDataSet = new HashSet<>(codeDataList); |
| | | |
| | | 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())); |
| | | String codeData = codeMatrix[i][j]; |
| | | if (codeDataSet.contains(codeData)) { |
| | | map.put(codeData, new int[]{i, j}); |
| | | } |
| | | } |
| | | } |
| | | codeList.sort(Comparator.comparingInt(SortCodeDto::getSerial)); |
| | | return codeList.stream().map(SortCodeDto::getCode).collect(Collectors.toList()); |
| | | |
| | | for (String codeData : codeDataList) { |
| | | int[] codeMatrixIdx = map.get(codeData); |
| | | if (codeMatrixIdx != null) { |
| | | codeMatrixIdxList.add(codeMatrixIdx); |
| | | } |
| | | } |
| | | return codeMatrixIdxList; |
| | | } |
| | | |
| | | public void modifyDynamicMatrix(Integer lev, List<String> codeList, String vehicle) { |
| | | this.modifyDynamicMatrix(lev, codeList, vehicle, false); |
| | | public void modifyDynamicMatrix(Integer lev, List<int[]> codeIdxList, String vehicle) { |
| | | this.modifyDynamicMatrix(lev, codeIdxList, vehicle, false); |
| | | } |
| | | |
| | | public synchronized void modifyDynamicMatrix(Integer lev, List<String> codeList, String vehicle, boolean reset) { |
| | | public synchronized void modifyDynamicMatrix(Integer lev, List<int[]> codeIdxList, String vehicle, boolean reset) { |
| | | if (Cools.isEmpty(vehicle)) { |
| | | return; |
| | | } |
| | | lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); |
| | | DynamicNode[][] dynamicMatrix = getDynamicMatrix(lev); |
| | | |
| | | if (!reset) { |
| | | if (Cools.isEmpty(codeList, vehicle)) { |
| | | return; |
| | | } |
| | | long time = System.currentTimeMillis() / 1000; |
| | | // long time = System.currentTimeMillis() / 1000; |
| | | int serial = 1; |
| | | for (String code : codeList) { |
| | | int[] node = getCodeMatrixIdx(lev, code); |
| | | dynamicMatrix[node[0]][node[1]] = new DynamicNode(vehicle, serial, time); |
| | | for (int[] codeMatrixIdx : codeIdxList) { |
| | | dynamicMatrix[codeMatrixIdx[0]][codeMatrixIdx[1]] = new DynamicNode(vehicle, serial); |
| | | serial++; |
| | | } |
| | | } else { |
| | | if (Cools.isEmpty(vehicle)) { |
| | | return; |
| | | } |
| | | for (int i = 0; i < dynamicMatrix.length; i++) { |
| | | for (int j = 0; j < dynamicMatrix[i].length; j++) { |
| | | DynamicNode dynamicNode = dynamicMatrix[i][j]; |
| | |
| | | setDynamicMatrix(lev, dynamicMatrix); |
| | | } |
| | | |
| | | public void clearDynamicMatrixByCodeList(Integer lev, List<String> codeList) { |
| | | this.modifyDynamicMatrix(lev, codeList, DynamicNodeType.ACCESS.val); |
| | | public void clearDynamicMatrixByCodeList(Integer lev, List<int[]> codeIdxList) { |
| | | this.modifyDynamicMatrix(lev, codeIdxList, DynamicNodeType.ACCESS.val); |
| | | } |
| | | |
| | | public int[][] filterMapData(int[][] mapMatrix, Integer lev, List<String> lockNodes) { |