#
Junjie
2025-04-07 901f9ca15fb0ce3bcf2ebf956c569c260050c561
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/LiftDispatcher.java
@@ -34,6 +34,70 @@
    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));
            if (locNo.equals(liftLocNo)) {
                finalDistance = 100;
                recentLiftThread = liftThread;
                continue;
            }
            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,11 +144,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);
            List<NavigateNode> nodeList = navigateUtils.calc(locNo, liftLocNo, NavigationMapType.NONE.id, null);
            if (nodeList == null) {
                continue;
            }
            Integer originPathAllDistance = NavigateUtils.getOriginPathAllDistance(nodeList);//总距离
            Integer originPathAllDistance = navigateUtils.getOriginPathAllDistance(nodeList);//总距离
            if (originPathAllDistance < finalDistance) {
                finalDistance = originPathAllDistance;
                recentLiftThread = liftThread;
@@ -144,15 +208,15 @@
        return standby.getLockPath$();
    }
    public Integer getLiftLevOffset(Integer deviceId,Integer lev) {
    public Integer getLiftLevOffset(Integer deviceId, Integer lev) {
        BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>().eq(BasLift::getDeviceId, deviceId));
        if (basLift != null) {
            if(Cools.isEmpty(basLift.getLevOffset())) {
            if (Cools.isEmpty(basLift.getLevOffset())) {
                return lev;
            }
            List<BasLiftLevOffsetDto> levOffsetDtos = JSON.parseArray(basLift.getLevOffset(), BasLiftLevOffsetDto.class);
            for (BasLiftLevOffsetDto offsetDto : levOffsetDtos) {
                if(lev == offsetDto.getLogicLev()){
                if (lev == offsetDto.getLogicLev()) {
                    return offsetDto.getRealLev();
                }
            }
@@ -160,4 +224,20 @@
        return lev;
    }
    public Integer getLiftLevLogic(Integer deviceId, Integer lev) {
        BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>().eq(BasLift::getDeviceId, deviceId));
        if (basLift != null) {
            if (Cools.isEmpty(basLift.getLevOffset())) {
                return lev;
            }
            List<BasLiftLevOffsetDto> levOffsetDtos = JSON.parseArray(basLift.getLevOffset(), BasLiftLevOffsetDto.class);
            for (BasLiftLevOffsetDto offsetDto : levOffsetDtos) {
                if (lev == offsetDto.getRealLev()) {
                    return offsetDto.getLogicLev();
                }
            }
        }
        return lev;
    }
}