#
vincentlu
2025-01-13 89c7f6e5bcc21b0e8f83a2bc6d680e2ffe431e6f
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/PatrolService.java
@@ -3,17 +3,12 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.acs.common.utils.RedisSupport;
import com.zy.acs.framework.common.R;
import com.zy.acs.manager.manager.entity.Agv;
import com.zy.acs.manager.manager.entity.AgvDetail;
import com.zy.acs.manager.manager.entity.Code;
import com.zy.acs.manager.manager.entity.Task;
import com.zy.acs.manager.manager.entity.*;
import com.zy.acs.manager.manager.enums.StatusType;
import com.zy.acs.manager.manager.enums.TaskStsType;
import com.zy.acs.manager.manager.enums.TaskTypeType;
import com.zy.acs.manager.manager.service.AgvDetailService;
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.manager.enums.TravelStateType;
import com.zy.acs.manager.manager.service.*;
import com.zy.acs.manager.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -34,9 +29,9 @@
@Service
public class PatrolService {
    private static final int SCHEDULE_TIME_INTERVAL = 5;
    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;
@@ -55,7 +50,7 @@
    @Autowired
    private MapService mapService;
    @Autowired
    private LaneService laneService;
    private TravelService travelService;
    @Autowired
    private AllocateService allocateService;
    @Autowired
@@ -66,26 +61,28 @@
    }
    private void patrolOfMove(String agvNo) {
        Agv agv = agvService.selectByUuid(agvNo);
        AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId());
        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) {
        Long agvId = agvService.getAgvId(agvNo);
        if (0 < travelService.count(new LambdaQueryWrapper<Travel>()
                .eq(Travel::getAgvId, agvId)
                .eq(Travel::getState, TravelStateType.RUNNING.toString()))) {
            return;
        }
        if (!agvService.judgeEnable(agv.getId())) {
//        if (taskService.count(new LambdaQueryWrapper<Task>()
//                .eq(Task::getAgvId, agvId)
//                .in(Task::getTaskSts, TaskStsType.ASSIGN.val(), TaskStsType.PROGRESS.val())
//                ) > 0) {
//            return;
//        }
        if (!agvService.judgeEnable(agvId)) {
            return;
        }
        Code destinationCode = this.getDestinationCode(agv, agvDetail);
        AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId);
        Code destinationCode = this.getDestinationCode(agvNo, agvDetail);
        if (null == destinationCode) {
            return;
        }
        if (mainLockWrapService.buildMinorTask(agv, TaskTypeType.MOVE, destinationCode.getData(), null)) {
            log.info(agv.getUuid() + "开始走行演示...");
        if (mainLockWrapService.buildMinorTask(agvId, TaskTypeType.MOVE, destinationCode.getData(), null)) {
            log.info(agvNo + "开始走行演示...");
        }
    }
@@ -100,7 +97,7 @@
     * 评估HandlerController没有调用buildMajorTask,手动创建task的可行性
     * agv地图图标变化
     */
    public Code getDestinationCode(Agv agv, AgvDetail agvDetail) {
    public Code getDestinationCode(String agvNo, AgvDetail agvDetail) {
        Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class);
        Code startCode = codeService.getById(agvDetail.getRecentCode());
@@ -121,13 +118,16 @@
        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)) {
            if (!allocateService.validCapacityOfLane(agvNo, endCode)) {
                continue;
            }
@@ -166,7 +166,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 + " 的跑库任务。");