#
Junjie
2024-05-18 a7d5e6c4a45ca1f7bb1560ef4e76f4c1680c41db
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java
@@ -10,7 +10,6 @@
import com.zy.asrs.wcs.core.kernel.AnalyzeService;
import com.zy.asrs.wcs.core.model.NavigateNode;
import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
import com.zy.asrs.wcs.core.model.enums.LiftCodeType;
import com.zy.asrs.wcs.core.model.enums.NavigationMapType;
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
import com.zy.asrs.wcs.core.service.*;
@@ -53,85 +52,6 @@
    private TaskCtgService taskCtgService;
    @Autowired
    private ShuttleStandbyService shuttleStandbyService;
    public ShuttleThread queryShuttleWhichConvenient(Task task, Integer liftNo) {
        String locNo = taskService.judgeInbound(task) ? task.getDestLoc() : task.getOriginLoc();
        ShuttleThread resThread = null;
        Integer finalDistance = ShuttleDispatcher.INF;
        List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>()
                .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val())
                .eq(Device::getHostId, task.getHostId())
                .eq(Device::getStatus, 1));
        for (Device device : list) {
            if (taskService.hasBusyOutboundByShuttle(Integer.parseInt(device.getDeviceNo()))) {
                continue;
            }
            //获取四向穿梭车线程
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
            if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
                continue;
            }
            if (!shuttleThread.isIdle()) {
                continue;
            }
            //检测是否存在充电任务
            Task taskCharge = taskService.selectChargeWorking(Integer.valueOf(device.getDeviceNo()));
            if (taskCharge != null) {
                continue;
            }
            // 有没有被其他任务调度
            int currentLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//小车当前层高
            String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车当前库位号
            if (currentLocNo.equals(locNo)) {
                resThread = shuttleThread;
                break;
            }
            String targetLocNo = LiftCodeType.getStandbyLocNo(liftNo, currentLev);//默认到提升机待机位
            // 同楼层直接计算到目标库位
            if (currentLev == Utils.getLev(locNo)) {
                targetLocNo = locNo;
            }
            //当前穿梭车线程到当前车子所在楼层的提升机口距离
            List<NavigateNode> currentShuttlePath = NavigateUtils.calc(
                    currentLocNo
                    , targetLocNo
                    , NavigationMapType.NORMAL.id
                    , Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), currentLev)
            );//搜索空闲穿梭车,使用正常通道地图
            if (currentShuttlePath == null) {
                continue;
            }
            Integer currDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离
            // 不同楼层权重
            if (currentLev != Utils.getLev(locNo)) {
                currDistance += WEIGHT;
            }
            // 挂载任务权重
            List<Task> tasks = taskService.selectWorkingByShuttle(Integer.valueOf(device.getDeviceNo()));
            if (!Cools.isEmpty(tasks)) {
                currDistance += tasks.size() * WEIGHT;
            }
            if (currDistance < finalDistance) {
                finalDistance = currDistance;
                resThread = shuttleThread;
            }
        }
        return resThread;
    }
    public synchronized ShuttleThread searchIdleShuttle(Task task) {
        String locNo = taskService.judgeInbound(task) ? task.getDestLoc() : task.getOriginLoc();
@@ -244,9 +164,6 @@
            return null;
        }
        //获取避让位置
        String standByLocNo = this.searchStandByLocNo(Integer.valueOf(device.getDeviceNo()), device.getHostId(), shuttleThread.getStatus().getCurrentLocNo());
        Task task = new Task();
        task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
        task.setTaskNo(String.valueOf(Utils.getTaskNo("MOVE")));
@@ -256,7 +173,7 @@
        task.setOriginSite(null);
        task.setOriginLoc(null);
        task.setDestSite(null);
        task.setDestLoc(standByLocNo); // 避让位置
        task.setDestLoc(locNo); // 迁移位置
        task.setIoTime(new Date());
        task.setStartTime(new Date());
        task.setHostId(device.getHostId());
@@ -269,7 +186,7 @@
            News.error("保存{}号四向穿梭车迁移任务失败!!!", device.getDeviceNo());
            return null;
        }
        motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo()));
        motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo()), device.getHostId());
        task.setTaskSts(TaskStsType.ANALYZE_MOVE.sts);