|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.service.TaskService; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.entity.Device; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.model.enums.SlaveType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.service.DeviceService; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.thread.ShuttleThread; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class Utils { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final String _LINK = "-"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static Integer getStaByLev(Integer lev) { | 
|---|
|  |  |  | HashMap<Integer, Integer> map = new HashMap<>(); | 
|---|
|  |  |  | map.put(1, 31006); | 
|---|
|  |  |  | map.put(2, 31007); | 
|---|
|  |  |  | map.put(3, 31008); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return map.get(lev); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 通过库位号获取 排 | 
|---|
|  |  |  | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.OFFLINE)) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (shuttleProtocol.getCurrentLocNo() == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (shuttleProtocol.getCurrentLocNo().equals(locNo)) { | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 检测穿梭车是否有任务绑定 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static boolean checkShuttleHasBinding(Device device) { | 
|---|
|  |  |  | public static boolean checkShuttleHasBinding(Device device, String taskNo) { | 
|---|
|  |  |  | TaskService taskService = SpringUtils.getBean(TaskService.class); | 
|---|
|  |  |  | List<Task> tasks = taskService.selectWorkingByShuttle(Integer.parseInt(device.getDeviceNo())); | 
|---|
|  |  |  | List<Task> tasks = taskService.selectWorkingByShuttle(Integer.parseInt(device.getDeviceNo()), taskNo); | 
|---|
|  |  |  | if (tasks.isEmpty()) { | 
|---|
|  |  |  | return false;//无任务绑定 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | * 检测提升机是否有任务绑定 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static boolean checkLiftHasBinding(Integer liftNo) { | 
|---|
|  |  |  | return checkLiftHasBinding(liftNo, null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 检测提升机是否有任务绑定 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static boolean checkLiftHasBinding(Integer liftNo, String taskNo) { | 
|---|
|  |  |  | TaskService taskService = SpringUtils.getBean(TaskService.class); | 
|---|
|  |  |  | List<Task> tasks = taskService.selectWorkingByLift(liftNo); | 
|---|
|  |  |  | List<Task> tasks = taskService.selectWorkingByLift(liftNo, taskNo); | 
|---|
|  |  |  | if (tasks.isEmpty()) { | 
|---|
|  |  |  | return false;//无任务绑定 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return true;//有任务绑定 | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取距离目标库位最近的提升机 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static Device getRecentTransferLift(String locNo, Integer shuttleNo) { | 
|---|
|  |  |  | BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class); | 
|---|
|  |  |  | DeviceService deviceService = SpringUtils.getBean(DeviceService.class); | 
|---|
|  |  |  | if (basLiftService == null) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer distance = Integer.MAX_VALUE; | 
|---|
|  |  |  | Long liftDeviceId = null; | 
|---|
|  |  |  | for (BasLift basLift : basLiftService.list(new LambdaQueryWrapper<BasLift>() | 
|---|
|  |  |  | .eq(BasLift::getStatus, 1) | 
|---|
|  |  |  | .eq(BasLift::getTransfer, 1))) { | 
|---|
|  |  |  | int lev = Utils.getLev(locNo); | 
|---|
|  |  |  | String liftLocNo = Utils.getLocNo(basLift.getRow(), basLift.getBay(), lev); | 
|---|
|  |  |  | List<NavigateNode> nodeList = NavigateUtils.calc(locNo, liftLocNo, NavigationMapType.NONE.id, Utils.getShuttlePoints(shuttleNo, Utils.getLev(locNo))); | 
|---|
|  |  |  | Integer originPathAllDistance = NavigateUtils.getOriginPathAllDistance(nodeList);//总距离 | 
|---|
|  |  |  | if (originPathAllDistance < distance) { | 
|---|
|  |  |  | distance = originPathAllDistance; | 
|---|
|  |  |  | liftDeviceId = basLift.getDeviceId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (liftDeviceId == null) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Device device = deviceService.getById(liftDeviceId); | 
|---|
|  |  |  | if (device == null) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return device; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|