package com.zy.core.dispatcher; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.zy.asrs.entity.DeviceConfig; import com.zy.asrs.service.DeviceConfigService; import com.zy.asrs.utils.Utils; import com.zy.common.model.NavigateNode; import com.zy.common.model.enums.NavigationMapType; import com.zy.common.utils.LiftUtils; import com.zy.common.utils.NavigateUtils; import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.SlaveType; import com.zy.core.model.protocol.LiftProtocol; import com.zy.core.model.protocol.LiftStaProtocol; import com.zy.core.model.protocol.ShuttleProtocol; import com.zy.core.thread.LiftThread; import com.zy.core.thread.ShuttleThread; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; /** * 提升机调度工具 */ @Component public class LiftDispatchUtils { @Autowired private DeviceConfigService deviceConfigService; @Autowired private NavigateUtils navigateUtils; /** * 获取穿梭车最近且无故障提升机输送站点 */ public LiftStaProtocol getRecentLiftStation(Integer shuttleNo, Integer targetLev) { //获取四向穿梭车线程 ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); if (shuttleThread == null) { return null; } ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); if (shuttleProtocol == null) { return null; } List liftList = deviceConfigService.selectList(new EntityWrapper() .eq("device_type", String.valueOf(SlaveType.Lift))); //获取小车同一楼层的站点 ArrayList list = new ArrayList<>(); int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//小车楼层 for (DeviceConfig device : liftList) { LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getDeviceNo()); if (liftThread == null) { continue; } LiftProtocol liftProtocol = liftThread.getStatus(); if (liftProtocol == null) { continue; } if (liftProtocol.getErrorCode() > 0) { continue; } //判断目标楼层站点是否无托盘 LiftStaProtocol targetLiftStaProtocol = LiftUtils.getLiftStaByLev(device.getDeviceNo(), targetLev); if (targetLiftStaProtocol == null) { continue; } //目标层有小车 if (targetLiftStaProtocol.getHasCar()) { continue; } list.add(targetLiftStaProtocol); } if (list.isEmpty()) { return null; } String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车位置 Integer recentAllDistance = 9999999; LiftStaProtocol recentSta = null;//最近站点 //搜索距离小车最近的站点 for (LiftStaProtocol liftStaProtocol : list) { Integer staNo = liftStaProtocol.getStaNo();//站点号 String locNo = liftStaProtocol.getLocNo();//站点库位号 //当前穿梭车线程到目标地点距离 List currentShuttlePath = navigateUtils.calc(currentLocNo, locNo, NavigationMapType.getMapTypes(NavigationMapType.NORMAL), Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)), null);//使用正常通道地图 if (currentShuttlePath == null) { continue; } Integer currentAllDistance = navigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离 if (currentAllDistance < recentAllDistance) { //如果当前楼层的车路径更小,则更新最近站点 recentSta = liftStaProtocol; recentAllDistance = currentAllDistance; } } return recentSta; } }