package com.zy.acs.manager.core.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.acs.framework.common.Cools; import com.zy.acs.manager.common.utils.LocUtils; import com.zy.acs.manager.manager.entity.Agv; import com.zy.acs.manager.manager.entity.AgvModel; import com.zy.acs.manager.manager.entity.Task; import com.zy.acs.manager.manager.enums.TaskStsType; import com.zy.acs.manager.manager.service.AgvModelService; import com.zy.acs.manager.manager.service.AgvService; 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; import java.util.Collections; import java.util.List; import java.util.Map; /** * Created by vincent on 8/12/2024 */ @Slf4j @Service public class MissionAssignService { @Autowired private AgvService agvService; @Autowired private AgvModelService agvModelService; @Autowired private ConfigService configService; @Autowired private TaskService taskService; public synchronized Agv execute1(Task task, Map> taskAllot, List taskIds) { String oriLocNo = task.getOriLoc$(); int oriLocRow = LocUtils.getRow(oriLocNo); String destLocNo = task.getDestLoc$(); int destLocRow = LocUtils.getRow(destLocNo); Agv hit = null; List agvList = agvService.list(new LambdaQueryWrapper<>()); Collections.shuffle(agvList); for (Agv agv : agvList) { AgvModel agvModel = agvModelService.getById(agv.getAgvModel()); int allotTaskCount = 0; List allotTaskIds = taskAllot.get(agv.getUuid()); if (!Cools.isEmpty(allotTaskIds)) { allotTaskCount = allotTaskIds.size(); } if (allotTaskCount >= agvModel.getBackpack()) { continue; } if (taskService.count(new LambdaQueryWrapper() .eq(Task::getAgvId, agv.getId()) .notIn(Task::getId, taskIds) .and(i -> { i.eq(Task::getTaskSts, TaskStsType.WAITING.val()) // 已经有waiting任务的车不能再分配 .or().eq(Task::getTaskSts, TaskStsType.ASSIGN.val()) .or().eq(Task::getTaskSts, TaskStsType.PROGRESS.val()); })) > 0) { log.info(agv.getUuid() + "号AGV不可用,已经存在进行中的任务..."); continue; } final Agv finalAgv = agv; if (!agvService.judgeEnable(finalAgv.getId(), agvDetail -> agvDetail.getVol() > finalAgv.getChargeLine())) { log.info(finalAgv.getUuid() + "号AGV不可用," + task.getSeqNum() + "任务无法计算..."); continue; } hit = agv; break; } return hit; } public synchronized Agv execute(Task task, Map> taskAllot, List taskIds) { String oriLocNo = task.getOriLoc$(); int oriLocRow = LocUtils.getRow(oriLocNo); String destLocNo = task.getDestLoc$(); int destLocRow = LocUtils.getRow(destLocNo); Agv agv = null; if (oriLocRow <= 2 && destLocRow <= 2) { agv = agvService.selectByUuid(String.valueOf(1)); } if (oriLocRow > 2 && destLocRow > 2) { agv = agvService.selectByUuid(String.valueOf(2)); } assert agv != null; AgvModel agvModel = agvModelService.getById(agv.getAgvModel()); int allotTaskCount = 0; List allotTaskIds = taskAllot.get(agv.getUuid()); if (!Cools.isEmpty(allotTaskIds)) { allotTaskCount = allotTaskIds.size(); } if (allotTaskCount >= agvModel.getBackpack()) { return null; } if (taskService.count(new LambdaQueryWrapper() .eq(Task::getAgvId, agv.getId()) .notIn(Task::getId, taskIds) .and(i -> { i.eq(Task::getTaskSts, TaskStsType.WAITING.val()) // 已经有waiting任务的车不能再分配 .or().eq(Task::getTaskSts, TaskStsType.ASSIGN.val()) .or().eq(Task::getTaskSts, TaskStsType.PROGRESS.val()); })) > 0) { log.info(agv.getUuid() + "号AGV不可用,已经存在进行中的任务..."); return null; } final Agv finalAgv = agv; if (!agvService.judgeEnable(finalAgv.getId(), agvDetail -> agvDetail.getVol() > finalAgv.getChargeLine())) { log.info(finalAgv.getUuid() + "号AGV不可用," + task.getSeqNum() + "任务无法计算..."); return null; } return agv; } }