#
luxiaotao1123
2024-11-14 9f19c2ea1a1d4e94460eb2d881b7cf8cc10e66df
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;
@@ -47,14 +48,18 @@
    private AgvDetailService agvDetailService;
    @Autowired
    private TaskService taskService;
//    @Autowired
//    private MainService mainService;
    @Autowired
    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);
@@ -75,30 +80,55 @@
        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 (mainLockWrapService.buildMinorTask(agv, agvDetail, TaskTypeType.MOVE, randomCode.getData())) {
        if (mainLockWrapService.buildMinorTask(agv, agvDetail, TaskTypeType.MOVE, destinationCode.getData())) {
            log.info(agv.getUuid() + "开始走行演示...");
        }
    }
    public Code getRandomCode(AgvDetail agvDetail) {
    /**
     * buildMinorTask 没有设置lane,lane只需要关注起始点(走行只需要关注终点)
     * 4个地方调用了buildMinorTask,在什么时候、哪里设置task的lane
     * (
         * HandlerController, 手动  (手动是否需要判断lane)
         * MaintainScheduler, 自动  (一般不需要考虑 lane)
         * PatrolService,     自动  (需要预处理 lane) ✔
         * TrafficService,    自动  (寻址时已经处理过 lane) ✔
     * )
     * 评估HandlerController没有调用buildMajorTask,手动创建task的可行性
     * patrolOfMove没有判断lane的容量
     * 抢占待机位
     * 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("00000151");
        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);
    }
    // ---------------------------------------------------------------------------