#
luxiaotao1123
2024-12-11 1e400eaffd9de4dc13c6b45cf6b805a3b26da3c0
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/PatrolService.java
@@ -14,6 +14,7 @@
import com.zy.acs.manager.manager.service.AgvService;
import com.zy.acs.manager.manager.service.CodeService;
import com.zy.acs.manager.manager.service.TaskService;
import com.zy.acs.manager.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -48,11 +49,17 @@
    @Autowired
    private TaskService taskService;
    @Autowired
    private MainService mainService;
    private MainLockWrapService mainLockWrapService;
    @Autowired
    private CodeService codeService;
    @Autowired
    private MapService mapService;
    @Autowired
    private LaneService laneService;
    @Autowired
    private AllocateService allocateService;
    @Autowired
    private ConfigService configService;
    private void executePatrolLogic(String agvNo) {
        this.patrolOfMove(agvNo);
@@ -73,30 +80,69 @@
        if (!agvService.judgeEnable(agv.getId())) {
            return;
        }
        Code randomCode = this.getRandomCode(agvDetail);
        if (null == randomCode) {
        Code destinationCode = this.getDestinationCode(agv, agvDetail);
        if (null == destinationCode) {
            return;
        }
        if (mainService.buildMinorTask(agv, agvDetail, TaskTypeType.MOVE, randomCode.getData())) {
        if (mainLockWrapService.buildMinorTask(agv, TaskTypeType.MOVE, destinationCode.getData(), null)) {
            log.info(agv.getUuid() + "开始走行演示...");
        }
    }
    public Code getRandomCode(AgvDetail agvDetail) {
    /**
     * 4个地方调用了buildMinorTask,在什么时候、哪里设置task的lane
     * (
         * HandlerController, 手动  (手动是否需要判断lane)
         * MaintainScheduler, 自动  (一般不需要考虑 lane)
         * PatrolService,     自动  (需要预处理 lane) ✔
         * TrafficService,    自动  (寻址时已经处理过 lane) ✔
     * )
     * 评估HandlerController没有调用buildMajorTask,手动创建task的可行性
     * agv地图图标变化
     */
    public Code getDestinationCode(Agv agv, AgvDetail agvDetail) {
        Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class);
        Code startCode = codeService.getById(agvDetail.getRecentCode());
        List<String> notInCodeList = new ArrayList<>();
        notInCodeList.add("00000061");
        notInCodeList.add("00000301");
        notInCodeList.add("00000302");
        notInCodeList.add("00000303");
        notInCodeList.add("00000351");
        notInCodeList.add("00000353");
        notInCodeList.add("00000401");
        notInCodeList.add("00000402");
        notInCodeList.add("00000311");
        notInCodeList.add("00000312");
        notInCodeList.add("00000313");
        notInCodeList.add("00000361");
        notInCodeList.add("00000363");
        notInCodeList.add("00000411");
        notInCodeList.add("00000412");
        notInCodeList.add("00000046");
        notInCodeList.add("00000047");
        List<Code> list = codeService.list(new LambdaQueryWrapper<Code>().notIn(Code::getData, notInCodeList));
        Collections.shuffle(list);
        for (Code endCode : list) {
            // valid lane
            if (!allocateService.validCapacityOfLane(agv, endCode)) {
                continue;
            }
            // valid path length
            List<String> pathList = mapService.validFeasibility(startCode, endCode);
            if (pathList.size() >= 5) {
                return endCode;
            }
        }
        return list.stream().findFirst().orElse(null);
    }
    // ---------------------------------------------------------------------------