| | |
| | | |
| | | private final RedisSupport redis = RedisSupport.defaultRedisSupport; |
| | | |
| | | public static final Boolean CACHE_CODE_MATRIX = Boolean.TRUE; |
| | | |
| | | private String[][] codeMatrix; |
| | | |
| | | public static final Boolean CACHE_MAP_MATRIX = Boolean.FALSE; |
| | | |
| | | private int[][] mapMatrix; |
| | | |
| | | public static final Boolean CACHE_TURN_MATRIX = Boolean.TRUE; |
| | | |
| | | private int[][] turnMatrix; |
| | | |
| | | public static final Boolean CACHE_CDA_MATRIX = Boolean.TRUE; |
| | | |
| | | private String[][] cdaMatrix; |
| | | |
| | |
| | | |
| | | public String[][] getCdaMatrix(Integer lev) { |
| | | lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); |
| | | String[][] cdaMatrix; |
| | | |
| | | if (!CACHE_CDA_MATRIX) { |
| | | if (null == this.cdaMatrix) { |
| | | cdaMatrix = this.initCdaMatrix(lev); |
| | | setCdaMatrix(lev, cdaMatrix); |
| | | } else { |
| | | cdaMatrix = this.cdaMatrix; |
| | | } |
| | | } else { |
| | | // redis |
| | | if (null == this.cdaMatrix) { |
| | | String cdaMatrixStr = redis.getValue(RedisConstant.AGV_MAP_ASTAR_CDA_FLAG, String.valueOf(lev)); |
| | | if (Cools.isEmpty(cdaMatrixStr)) { |
| | | cdaMatrix = this.initCdaMatrix(lev); |
| | | setCdaMatrix(lev, cdaMatrix); |
| | | } else { |
| | | cdaMatrix = JSON.parseObject(cdaMatrixStr, String[][].class); |
| | | if (!Cools.isEmpty(cdaMatrixStr)) { |
| | | this.cdaMatrix = JSON.parseObject(cdaMatrixStr, String[][].class); |
| | | } |
| | | } |
| | | if (null == cdaMatrix) { |
| | | // init |
| | | if (null == this.cdaMatrix) { |
| | | String[][] initCdaMatrix = this.initCdaMatrix(lev); |
| | | setCdaMatrix(lev, initCdaMatrix); |
| | | } |
| | | // valid |
| | | if (null == this.cdaMatrix) { |
| | | throw new CoolException("the floor " + lev + " cannot found cda matrix !!!"); |
| | | } |
| | | return cdaMatrix; |
| | | return this.cdaMatrix; |
| | | } |
| | | |
| | | public void setCdaMatrix(Integer lev, String[][] cdaMatrix) { |
| | | if (!CACHE_CDA_MATRIX) { |
| | | this.cdaMatrix = cdaMatrix; |
| | | } else { |
| | | redis.setValue(RedisConstant.AGV_MAP_ASTAR_CDA_FLAG, String.valueOf(lev), JSON.toJSONString(cdaMatrix)); |
| | | } |
| | | redis.setValue(RedisConstant.AGV_MAP_ASTAR_CDA_FLAG, String.valueOf(lev), JSON.toJSONString(cdaMatrix)); |
| | | this.cdaMatrix = cdaMatrix; |
| | | } |
| | | |
| | | public int[][] getTurnMatrix(Integer lev) { |
| | | lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); |
| | | int[][] turnMatrix; |
| | | if (!CACHE_TURN_MATRIX) { |
| | | if (null == this.turnMatrix) { |
| | | turnMatrix = this.initTurnMatrix(lev); |
| | | setTurnMatrix(lev, turnMatrix); |
| | | } else { |
| | | turnMatrix = this.turnMatrix; |
| | | } |
| | | } else { |
| | | // redis |
| | | if (null == this.turnMatrix) { |
| | | String turnMatrixStr = redis.getValue(RedisConstant.AGV_MAP_ASTAR_TURN_FLAG, String.valueOf(lev)); |
| | | if (Cools.isEmpty(turnMatrixStr)) { |
| | | turnMatrix = this.initTurnMatrix(lev); |
| | | setTurnMatrix(lev, turnMatrix); |
| | | } else { |
| | | turnMatrix = JSON.parseObject(turnMatrixStr, int[][].class); |
| | | if (!Cools.isEmpty(turnMatrixStr)) { |
| | | this.turnMatrix = JSON.parseObject(turnMatrixStr, int[][].class); |
| | | } |
| | | } |
| | | if (null == turnMatrix) { |
| | | // init |
| | | if (null == this.turnMatrix) { |
| | | int[][] initTurnMatrix = this.initTurnMatrix(lev); |
| | | setTurnMatrix(lev, initTurnMatrix); |
| | | } |
| | | // valid |
| | | if (null == this.turnMatrix) { |
| | | throw new CoolException("the floor " + lev + " cannot found turn matrix !!!"); |
| | | } |
| | | return turnMatrix; |
| | | return this.turnMatrix; |
| | | } |
| | | |
| | | public void setTurnMatrix(Integer lev, int[][] turnMatrix) { |
| | | if (!CACHE_TURN_MATRIX) { |
| | | this.turnMatrix = turnMatrix; |
| | | } else { |
| | | redis.setValue(RedisConstant.AGV_MAP_ASTAR_TURN_FLAG, String.valueOf(lev), JSON.toJSONString(turnMatrix)); |
| | | } |
| | | redis.setValue(RedisConstant.AGV_MAP_ASTAR_TURN_FLAG, String.valueOf(lev), JSON.toJSONString(turnMatrix)); |
| | | this.turnMatrix = turnMatrix; |
| | | } |
| | | |
| | | public int[][] getMapMatrix(Integer lev, List<String> lockNodes) { |
| | | lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); |
| | | int[][] mapMatrix; |
| | | if (!CACHE_MAP_MATRIX) { |
| | | if (null == this.mapMatrix) { |
| | | mapMatrix = this.initMapMatrix(lev); |
| | | setMapMatrix(lev, mapMatrix); |
| | | } else { |
| | | mapMatrix = this.mapMatrix; |
| | | } |
| | | } else { |
| | | // redis |
| | | if (null == this.mapMatrix) { |
| | | String mapMatrixStr = redis.getValue(RedisConstant.AGV_MAP_ASTAR_FLAG, String.valueOf(lev)); |
| | | if (Cools.isEmpty(mapMatrixStr)) { |
| | | mapMatrix = this.initMapMatrix(lev); |
| | | setMapMatrix(lev, mapMatrix); |
| | | } else { |
| | | mapMatrix = JSON.parseObject(mapMatrixStr, int[][].class); |
| | | if (!Cools.isEmpty(mapMatrixStr)) { |
| | | this.mapMatrix = JSON.parseObject(mapMatrixStr, int[][].class); |
| | | } |
| | | } |
| | | if (null == mapMatrix) { |
| | | // init |
| | | if (null == this.mapMatrix) { |
| | | int[][] initMapMatrix = this.initMapMatrix(lev); |
| | | setMapMatrix(lev, initMapMatrix); |
| | | } |
| | | // valid |
| | | if (null == this.mapMatrix) { |
| | | throw new CoolException("the floor " + lev + " cannot found map matrix !!!"); |
| | | } |
| | | if (!Cools.isEmpty(lockNodes)) { |
| | | mapMatrix = filterMapData(mapMatrix, lev, lockNodes); |
| | | } |
| | | return mapMatrix; |
| | | return this.mapMatrix; |
| | | } |
| | | |
| | | public void setMapMatrix(Integer lev, int[][] mapMatrix) { |
| | | if (!CACHE_MAP_MATRIX) { |
| | | this.mapMatrix = mapMatrix; |
| | | } else { |
| | | redis.setValue(RedisConstant.AGV_MAP_ASTAR_FLAG, String.valueOf(lev), JSON.toJSONString(mapMatrix)); |
| | | } |
| | | redis.setValue(RedisConstant.AGV_MAP_ASTAR_FLAG, String.valueOf(lev), JSON.toJSONString(mapMatrix)); |
| | | this.mapMatrix = mapMatrix; |
| | | } |
| | | |
| | | public String[][] getCodeMatrix(Integer lev) { |
| | | lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); |
| | | String[][] codeMatrix; |
| | | if (!CACHE_CODE_MATRIX) { |
| | | if (null == this.codeMatrix) { |
| | | codeMatrix = this.initCodeMatrix(lev); |
| | | setCodeMatrix(lev, codeMatrix); |
| | | } else { |
| | | codeMatrix = this.codeMatrix; |
| | | } |
| | | } else { |
| | | // redis |
| | | if (null == this.codeMatrix) { |
| | | String codeMatrixStr = redis.getValue(RedisConstant.AGV_MAP_ASTAR_CODE_FLAG, String.valueOf(lev)); |
| | | if (Cools.isEmpty(codeMatrixStr)) { |
| | | codeMatrix = this.initCodeMatrix(lev); |
| | | setCodeMatrix(lev, codeMatrix); |
| | | } else { |
| | | codeMatrix = JSON.parseObject(codeMatrixStr, String[][].class); |
| | | if (!Cools.isEmpty(codeMatrixStr)) { |
| | | this.codeMatrix = JSON.parseObject(codeMatrixStr, String[][].class); |
| | | } |
| | | } |
| | | if (null == codeMatrix) { |
| | | // init |
| | | if (null == this.codeMatrix) { |
| | | String[][] initCodeMatrix = this.initCodeMatrix(lev); |
| | | setCodeMatrix(lev, initCodeMatrix); |
| | | } |
| | | // valid |
| | | if (null == this.codeMatrix) { |
| | | throw new CoolException("the floor " + lev + " cannot found code matrix !!!"); |
| | | } |
| | | return codeMatrix; |
| | | return this.codeMatrix; |
| | | } |
| | | |
| | | public void setCodeMatrix(Integer lev, String[][] codeMatrix) { |
| | | if (!CACHE_CODE_MATRIX) { |
| | | this.codeMatrix = codeMatrix; |
| | | } else { |
| | | redis.setValue(RedisConstant.AGV_MAP_ASTAR_CODE_FLAG, String.valueOf(lev), JSON.toJSONString(codeMatrix)); |
| | | } |
| | | redis.setValue(RedisConstant.AGV_MAP_ASTAR_CODE_FLAG, String.valueOf(lev), JSON.toJSONString(codeMatrix)); |
| | | this.codeMatrix = codeMatrix; |
| | | } |
| | | |
| | | public String[][] initWaveMatrix(Integer lev) { |