| | |
| | | package com.zy.asrs.wcs.core.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.SnowflakeIdWorker; |
| | |
| | | import com.zy.asrs.wcs.system.service.DictService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | |
| | |
| | | private DictService dictService; |
| | | @Autowired |
| | | private NavigateUtils navigateUtils; |
| | | |
| | | /** |
| | | * 调度车辆 |
| | | */ |
| | | public Device dispatchShuttle(Task task, String locNo) { |
| | | ArrayList<ShuttleThread> sameLev = new ArrayList<>();//相同楼层的穿梭车 |
| | | ArrayList<ShuttleThread> diffLev = new ArrayList<>();//不同楼层的穿梭车 |
| | | |
| | | ShuttleThread resThread = null; |
| | | int lev = Utils.getLev(locNo); |
| | | List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>() |
| | | .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()) |
| | | .eq(Device::getHostId, task.getHostId()) |
| | | .eq(Device::getStatus, 1)); |
| | | //获取同层小车 |
| | | List<Device> currentLevDevices = new ArrayList<>(); |
| | | //获取跨层小车 |
| | | HashMap<Integer, List<Device>> diffLevDeviceMap = new HashMap<>(); |
| | | for (Device device : list) { |
| | | //获取四向穿梭车线程 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { |
| | | continue; |
| | | } |
| | | |
| | | int shuttleLev = Utils.getLev(shuttleProtocol.getCurrentLocNo()); |
| | | if (shuttleLev == lev) { |
| | | currentLevDevices.add(device); |
| | | } else { |
| | | List<Device> devices = null; |
| | | if (diffLevDeviceMap.containsKey(shuttleLev)) { |
| | | devices = diffLevDeviceMap.get(shuttleLev); |
| | | } else { |
| | | devices = new ArrayList<>(); |
| | | } |
| | | devices.add(device); |
| | | diffLevDeviceMap.put(shuttleLev, devices); |
| | | } |
| | | } |
| | | |
| | | //搜索同层 |
| | | resThread = this.searchCurrentLevShuttle(currentLevDevices, locNo); |
| | | |
| | | //同层没有搜索到合适小车,跨楼层搜索 |
| | | if (resThread == null) { |
| | | resThread = this.searchDiffLevShuttle(diffLevDeviceMap, locNo, task); |
| | | } |
| | | |
| | | Task result = generateMoveTask(resThread.getDevice(), locNo); |
| | | if (result != null) { |
| | | return resThread.getDevice(); |
| | | } |
| | | |
| | | News.info("{}目标库位没有搜索到可用穿梭车", locNo); |
| | | return null; |
| | | } |
| | | |
| | | public synchronized ShuttleThread searchIdleShuttle(Task task) { |
| | | String locNo = taskService.judgeInbound(task) ? task.getDestLoc() : task.getOriginLoc(); |
| | |
| | | return null; |
| | | } |
| | | |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null) { |
| | | return null; |
| | | } |
| | | |
| | | Task task = new Task(); |
| | | task.setUuid(String.valueOf(snowflakeIdWorker.nextId())); |
| | | task.setTaskNo(String.valueOf(Utils.getTaskNo("MOVE"))); |
| | |
| | | task.setTaskCtg(taskCtg.getId()); |
| | | task.setPriority(10); |
| | | task.setOriginSite(null); |
| | | task.setOriginLoc(null); |
| | | task.setOriginLoc(shuttleProtocol.getCurrentLocNo()); |
| | | task.setDestSite(null); |
| | | task.setDestLoc(locNo); // 迁移位置 |
| | | task.setIoTime(new Date()); |
| | |
| | | return lastPathStartLoc; |
| | | } |
| | | |
| | | //获取小车坐标 |
| | | public String findShuttleLocNo(Integer shuttleNo, Long hostId) { |
| | | Device device = deviceService.getOne(new LambdaQueryWrapper<Device>() |
| | | .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()) |
| | | .eq(Device::getDeviceNo, shuttleNo) |
| | | .eq(Device::getHostId, hostId) |
| | | .eq(Device::getStatus, 1)); |
| | | if(device == null) { |
| | | return null; |
| | | } |
| | | |
| | | //获取四向穿梭车线程 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { |
| | | return null; |
| | | } |
| | | |
| | | return shuttleProtocol.getCurrentLocNo(); |
| | | } |
| | | |
| | | |
| | | } |