#
vincentlu
4 天以前 1ce8c694a364916fa45c60cabedb7a9215003055
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/astart/MapDataDispatcher.java
@@ -7,6 +7,7 @@
import com.zy.acs.framework.common.Cools;
import com.zy.acs.framework.exception.CoolException;
import com.zy.acs.manager.common.utils.MapDataUtils;
import com.zy.acs.manager.core.domain.PathDto;
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;
@@ -16,9 +17,10 @@
import com.zy.acs.manager.manager.service.RouteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.stereotype.Service;
import com.zy.acs.common.utils.News;
import javax.annotation.PostConstruct;
import java.util.*;
/**
@@ -51,7 +53,7 @@
    @Autowired
    private RouteService routeService;
    @EventListener(ApplicationReadyEvent.class)
    @PostConstruct
    public void init() {
        String[][] codeMatrix = this.getCodeMatrix(null);
        this.initRouteMap(null);
@@ -228,7 +230,7 @@
    }
    public synchronized DynamicNode[][] initDynamicMatrix(Integer lev) {
        log.info("There is initializing Dynamic Matrix......");
        News.info("There is initializing Dynamic Matrix......");
        lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV);
        String[][] codeMatrix = getCodeMatrix(lev);
@@ -251,7 +253,7 @@
    }
    public synchronized String[][] initCdaMatrix(Integer lev) {
        log.info("There is initializing Cda Matrix......");
        News.info("There is initializing Cda Matrix......");
        lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV);
        if (Cools.isEmpty(xIdxList, yIdxList)) {
@@ -287,7 +289,7 @@
    }
    public synchronized int[][] initTurnMatrix(Integer lev) {
        log.info("There is initializing Turn Matrix......");
        News.info("There is initializing Turn Matrix......");
        lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV);
        String[][] codeMatrix = getCodeMatrix(lev);
@@ -336,7 +338,7 @@
    
    public synchronized int[][] initMapMatrix(Integer lev) {
        log.info("There is initializing Map Matrix......");
        News.info("There is initializing Map Matrix......");
        lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV);
        String[][] codeMatrix = getCodeMatrix(lev);
@@ -369,7 +371,7 @@
    }
    public synchronized void initRouteMap(Integer lev) {
        log.info("There is initializing Route Map......");
        News.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);
@@ -403,7 +405,7 @@
    }
    public synchronized String[][] initCodeMatrix(Integer lev) {
        log.info("There is initializing Code Matrix......");
        News.info("There is initializing Code Matrix......");
        lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV);
        List<Code> codeList = codeService.list(new LambdaQueryWrapper<Code>()
                .eq(Code::getStatus, 1)
@@ -497,11 +499,15 @@
        return codeMatrixIdxList;
    }
    public void modifyDynamicMatrix(Integer lev, List<int[]> codeIdxList, String vehicle) {
        this.modifyDynamicMatrix(lev, codeIdxList, vehicle, false);
    public void modifyDynamicMatrix(Integer lev, List<int[]> codeIdxList, String vehicle, List<PathDto> pathTrace) {
        this.modifyDynamicMatrix(lev, codeIdxList, vehicle, false, pathTrace);
    }
    public synchronized void modifyDynamicMatrix(Integer lev, List<int[]> codeIdxList, String vehicle, boolean reset) {
        this.modifyDynamicMatrix(lev, codeIdxList, vehicle, reset, null);
    }
    private synchronized void modifyDynamicMatrix(Integer lev, List<int[]> codeIdxList, String vehicle, boolean reset, List<PathDto> pathTrace) {
        if (Cools.isEmpty(vehicle)) {
            return;
        }
@@ -509,10 +515,15 @@
        DynamicNode[][] dynamicMatrix = getDynamicMatrix(lev);
        if (!reset) {
//            long time = System.currentTimeMillis() / 1000;
            int serial = 1;
            for (int[] codeMatrixIdx : codeIdxList) {
                dynamicMatrix[codeMatrixIdx[0]][codeMatrixIdx[1]] = new DynamicNode(vehicle, serial);
            for (int i = 0; i < codeIdxList.size(); i++) {
                int[] codeMatrixIdx = codeIdxList.get(i);
                PathDto pathDto = (pathTrace != null && i < pathTrace.size()) ? pathTrace.get(i) : null;
                Double direction = pathDto == null ? null : pathDto.getDirection();
                boolean turn = pathDto != null && pathDto.isTurn();
                dynamicMatrix[codeMatrixIdx[0]][codeMatrixIdx[1]] = new DynamicNode(vehicle, serial, direction, turn);
                serial++;
            }
        } else {
@@ -530,7 +541,7 @@
    }
    public void clearDynamicMatrixByCodeList(Integer lev, List<int[]> codeIdxList) {
        this.modifyDynamicMatrix(lev, codeIdxList, DynamicNodeType.ACCESS.val);
        this.modifyDynamicMatrix(lev, codeIdxList, DynamicNodeType.ACCESS.val, false, null);
    }
    public int[][] filterMapData(int[][] mapMatrix, Integer lev, List<String> lockNodes) {
@@ -564,4 +575,4 @@
        }
    }
}
}