Junjie
2025-04-18 3dcc70402e27760de274dbc7d50a5f0726ce58cb
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/LiftDispatcher.java
@@ -34,6 +34,63 @@
    private BasLiftService basLiftService;
    @Autowired
    private ShuttleStandbyService shuttleStandbyService;
    @Autowired
    private NavigateUtils navigateUtils;
    /**
     * 根据目标位置搜索提升机
     * transfer: 是否可换层
     */
    public LiftThread searchLift(String locNo, Long hostId, Boolean transfer) {
        LiftThread recentLiftThread = null;
        Integer finalDistance = Integer.MAX_VALUE;
        List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>()
                .eq(Device::getDeviceType, DeviceCtgType.LIFT.val())
                .eq(Device::getHostId, hostId)
                .eq(Device::getStatus, 1));
        for (Device device : list) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getId().intValue());
            if (liftThread == null) {
                continue;
            }
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null) {
                continue;
            }
            if (transfer) {
                BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>().eq(BasLift::getLiftNo, device.getDeviceNo()).eq(BasLift::getHostId, hostId));
                if (basLift == null) {
                    continue;
                }
                if (basLift.getTransfer() != 1) {
                    continue;//提升机被设置成不可换层
                }
            }
            ShuttleStandby standby = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
                    .eq(ShuttleStandby::getDeviceId, device.getId())
                    .eq(ShuttleStandby::getDeviceLev, Utils.getLev(locNo))
                    .eq(ShuttleStandby::getStatus, 1));
            if (standby == null) {
                continue;
            }
            String liftLocNo = Utils.getLocNo(Utils.getRow(standby.getDeviceStandbyLoc()), Utils.getBay(standby.getDeviceStandbyLoc()), Utils.getLev(locNo));
            List<NavigateNode> nodeList = navigateUtils.calc(locNo, liftLocNo, NavigationMapType.NONE.id, null);
            if (nodeList == null) {
                continue;
            }
            Integer originPathAllDistance = navigateUtils.getOriginPathAllDistance(nodeList);//总距离
            if (originPathAllDistance < finalDistance) {
                finalDistance = originPathAllDistance;
                recentLiftThread = liftThread;
            }
        }
        return recentLiftThread;
    }
    /**
     * 根据目标位置搜索空闲提升机
@@ -80,8 +137,11 @@
            }
            String liftLocNo = Utils.getLocNo(Utils.getRow(standby.getDeviceStandbyLoc()), Utils.getBay(standby.getDeviceStandbyLoc()), Utils.getLev(locNo));
            List<NavigateNode> nodeList = NavigateUtils.calc(locNo, liftLocNo, NavigationMapType.NONE.id, null);
            Integer originPathAllDistance = NavigateUtils.getOriginPathAllDistance(nodeList);//总距离
            List<NavigateNode> nodeList = navigateUtils.calc(locNo, liftLocNo, NavigationMapType.NONE.id, null);
            if (nodeList == null) {
                continue;
            }
            Integer originPathAllDistance = navigateUtils.getOriginPathAllDistance(nodeList);//总距离
            if (originPathAllDistance < finalDistance) {
                finalDistance = originPathAllDistance;
                recentLiftThread = liftThread;
@@ -125,6 +185,38 @@
        return liftLocNo;
    }
    /**
     * 获取进提升机待机位位置
     */
    public String getInLiftStandByLocNo(LiftThread liftThread, Integer lev) {
        Device device = liftThread.getDevice();
        ShuttleStandby standby = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
                .eq(ShuttleStandby::getDeviceId, device.getId())
                .eq(ShuttleStandby::getDeviceLev, lev)
                .eq(ShuttleStandby::getStatus, 1));
        if (standby == null) {
            return null;
        }
        return standby.getMemo();
    }
    /**
     * 获取换层需要锁定的路径
     */
    public List<String> getLockPathByLocNo(LiftThread liftThread, Integer lev) {
        Device device = liftThread.getDevice();
        ShuttleStandby standby = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
                .eq(ShuttleStandby::getDeviceId, device.getId())
                .eq(ShuttleStandby::getDeviceLev, lev)
                .eq(ShuttleStandby::getStatus, 1));
        if (standby == null) {
            return null;
        }
        return standby.getLockPath$();
    }
    public Integer getLiftLevOffset(Integer deviceId,Integer lev) {
        BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>().eq(BasLift::getDeviceId, deviceId));
        if (basLift != null) {