#
luxiaotao1123
2025-01-08 aa6f20d98b5d8e18ae56f9562a78d403a5417b48
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;
@@ -33,9 +34,9 @@
@Service
public class PatrolService {
    private static final int SCHEDULE_TIME_INTERVAL = 1;
    private static final int SCHEDULE_TIME_INTERVAL = 100;
    private static final Map<String, ScheduledFuture<?>> AGV_PATROL_MAP = new ConcurrentHashMap<>();
    public static final Map<String, ScheduledFuture<?>> AGV_PATROL_MAP = new ConcurrentHashMap<>();
    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
@@ -48,55 +49,98 @@
    @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);
    }
    private void patrolOfMove(String agvNo) {
        Agv agv = agvService.selectByUuid(agvNo);
        AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId());
        Long agvId = agvService.getAgvId(agvNo);
        AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId);
        if (taskService.count(new LambdaQueryWrapper<Task>()
                .eq(Task::getAgvId, agv.getId())
                .and(i -> {
                    i.eq(Task::getTaskSts, TaskStsType.WAITING.val())
                            .or().eq(Task::getTaskSts, TaskStsType.ASSIGN.val())
                            .or().eq(Task::getTaskSts, TaskStsType.PROGRESS.val());
                })) > 0) {
                .eq(Task::getAgvId, agvId)
                .in(Task::getTaskSts, TaskStsType.ASSIGN.val(), TaskStsType.PROGRESS.val())
                ) > 0) {
            return;
        }
        if (!agvService.judgeEnable(agv.getId())) {
        if (!agvService.judgeEnable(agvId)) {
            return;
        }
        Code randomCode = this.getRandomCode(agvDetail);
        if (null == randomCode) {
        Agv agv = agvService.getById(agvId);
        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);
    }
    // ---------------------------------------------------------------------------
@@ -123,7 +167,7 @@
            }
        };
        ScheduledFuture<?> scheduledFuture = scheduler.scheduleAtFixedRate(patrolTask, 0, SCHEDULE_TIME_INTERVAL, TimeUnit.SECONDS);
        ScheduledFuture<?> scheduledFuture = scheduler.scheduleAtFixedRate(patrolTask, 0, SCHEDULE_TIME_INTERVAL, TimeUnit.MILLISECONDS);
        AGV_PATROL_MAP.put(agvNo, scheduledFuture);
        log.info("已启动AGV " + agvNo + " 的跑库任务。");