| | |
| | | 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 com.zy.acs.manager.manager.entity.Route; |
| | | import com.zy.acs.manager.manager.enums.StatusType; |
| | | import com.zy.acs.manager.manager.service.CodeService; |
| | | import com.zy.acs.manager.manager.service.RouteService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | private final RedisSupport redis = RedisSupport.defaultRedisSupport; |
| | | |
| | | List<Double> xIdxList; |
| | | List<Double> yIdxList; |
| | | |
| | | private String[][] codeMatrix; |
| | | |
| | | private int[][] mapMatrix; |
| | |
| | | private int[][] turnMatrix; |
| | | |
| | | private String[][] cdaMatrix; |
| | | |
| | | public Map<String, Boolean> routeCdaMap = new HashMap<>(); |
| | | |
| | | private final CodeService codeService; |
| | | |
| | |
| | | log.info("There is initializing Cda Matrix......"); |
| | | lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); |
| | | |
| | | if (Cools.isEmpty(xIdxList, yIdxList)) { |
| | | this.initCodeMatrix(lev); |
| | | } |
| | | |
| | | String[][] codeMatrix = getCodeMatrix(lev); |
| | | String[][] cdaMatrix = new String[codeMatrix.length][codeMatrix[0].length]; |
| | | |
| | | for (int i = 0; i < codeMatrix.length; i++) { |
| | | for (int j = 0; j < codeMatrix[i].length; j++) { |
| | | if (CodeNodeType.NONE.val.equals(codeMatrix[i][j])) { |
| | | cdaMatrix[i][j] = CdaNodeType.DISABLE.val; |
| | | List<Double> cdaArr = new ArrayList<>(); |
| | | cdaArr.add(xIdxList.get(j)); |
| | | cdaArr.add(yIdxList.get(i)); |
| | | cdaMatrix[i][j] = JSON.toJSONString(cdaArr); |
| | | } else { |
| | | Code currCode = codeService.selectByData(codeMatrix[i][j]); |
| | | if (null != currCode) { |
| | |
| | | return mapMatrix; |
| | | } |
| | | |
| | | public boolean validRouteCdaKey(String routeCdaKey) { |
| | | if (Cools.isEmpty(routeCdaKey)) { |
| | | return false; |
| | | } |
| | | Boolean result = this.routeCdaMap.get(routeCdaKey); |
| | | if (null == result) { |
| | | return false; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public synchronized void initRouteMap(Integer lev) { |
| | | log.info("There is initializing Route Map......"); |
| | | lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); |
| | | Set<String> routeKeys = redis.getMapKeys(RedisConstant.AGV_MAP_ROUTE_HASH_FLAG); |
| | | Set<String> routeCdaKeys = redis.getMapKeys(RedisConstant.AGV_MAP_ROUTE_CDA_HASH_FLAG); |
| | | |
| | | List<Route> routeList = routeService.list(new LambdaQueryWrapper<Route>().eq(Route::getStatus, StatusType.ENABLE.val)); |
| | | if (routeKeys.size() == routeList.size() && routeKeys.size() == routeCdaKeys.size()) { |
| | | for (String routeCdaKey : routeCdaKeys) { |
| | | this.routeCdaMap.put(routeCdaKey, Boolean.TRUE); |
| | | } |
| | | return; |
| | | } |
| | | for (Route route : routeList) { |
| | | Code startCode = codeService.getById(route.getStartCode()); |
| | | int[] startCodeIdx = getCodeMatrixIdx(lev, startCode.getData()); |
| | | Code endCode = codeService.getById(route.getEndCode()); |
| | | int[] codeMatrixIdx = getCodeMatrixIdx(lev, endCode.getData()); |
| | | |
| | | String routeKey = RouteGenerator.generateRouteKey(startCode.getData(), endCode.getData()); |
| | | if (Cools.isEmpty(routeKey)) { |
| | | continue; |
| | | } |
| | | redis.setMap(RedisConstant.AGV_MAP_ROUTE_HASH_FLAG, routeKey, Boolean.TRUE); |
| | | |
| | | String routeCdaKey = RouteGenerator.generateRouteCdaKey(startCodeIdx, codeMatrixIdx); |
| | | if (Cools.isEmpty(routeCdaKey)) { |
| | | continue; |
| | | } |
| | | redis.setMap(RedisConstant.AGV_MAP_ROUTE_CDA_HASH_FLAG, routeCdaKey, Boolean.TRUE); |
| | | this.routeCdaMap.put(routeCdaKey, Boolean.TRUE); |
| | | } |
| | | } |
| | | |
| | | public synchronized String[][] initCodeMatrix(Integer lev) { |
| | | log.info("There is initializing Code Matrix......"); |
| | | lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); |
| | |
| | | .orderByAsc(Code::getY) |
| | | .orderByAsc(Code::getX) |
| | | ); |
| | | // int xCount = codeService.selectDistinctCountFromX(); |
| | | // int yCount = codeService.selectDistinctCountFromY(); |
| | | // // [][] 第一个是排的数量 第二个是列的数量 |
| | | // String[][] codeMatrix = new String[yCount][xCount]; |
| | | |
| | | List<Double> xIdxList = new ArrayList<>(); |
| | | List<Double> yIdxList = new ArrayList<>(); |
| | | xIdxList = new ArrayList<>(); |
| | | yIdxList = new ArrayList<>(); |
| | | for (Code code : codeList) { |
| | | Double x = code.getX(); |
| | | Double y = code.getY(); |
| | |
| | | // [][] 第一个是排的数量 第二个是列的数量 |
| | | String[][] codeMatrix = new String[yIdxList.size()][xIdxList.size()]; |
| | | |
| | | int idxX = -1; |
| | | int idxY = -1; |
| | | double lastX = -1; |
| | | double lastY = -1; |
| | | for (Code code : codeList) { |
| | | Double x = code.getX(); |
| | | Double y = code.getY(); |
| | | // if (y != lastY) { |
| | | // idxY ++; |
| | | // idxX = 0; |
| | | // lastY = y; |
| | | // lastX = x; |
| | | // } |
| | | // if (x != lastX) { |
| | | // idxX++; |
| | | // lastX = x; |
| | | // } |
| | | // codeMatrix[idxY][idxX] = code.getData(); |
| | | |
| | | codeMatrix[yIdxList.indexOf(y)][xIdxList.indexOf(x)] = code.getData(); |
| | | } |