| | |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | | import com.zy.asrs.wcs.core.entity.BasShuttle; |
| | | import com.zy.asrs.wcs.core.entity.Task; |
| | | import com.zy.asrs.wcs.core.entity.*; |
| | | import com.zy.asrs.wcs.core.kernel.AnalyzeService; |
| | | import com.zy.asrs.wcs.core.model.NavigateNode; |
| | | import com.zy.asrs.wcs.core.model.enums.LiftCodeType; |
| | | import com.zy.asrs.wcs.core.model.enums.DeviceCtgType; |
| | | import com.zy.asrs.wcs.core.model.enums.NavigationMapType; |
| | | import com.zy.asrs.wcs.core.service.BasShuttleService; |
| | | import com.zy.asrs.wcs.core.service.TaskService; |
| | | import com.zy.asrs.wcs.core.model.enums.TaskStsType; |
| | | import com.zy.asrs.wcs.core.service.*; |
| | | import com.zy.asrs.wcs.rcs.News; |
| | | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; |
| | | import com.zy.asrs.wcs.rcs.entity.Device; |
| | | import com.zy.asrs.wcs.rcs.entity.DeviceType; |
| | | 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.service.DeviceTypeService; |
| | | import com.zy.asrs.wcs.core.service.MotionService; |
| | | import com.zy.asrs.wcs.rcs.thread.ShuttleThread; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Created by vincent on 2023/10/12 |
| | |
| | | private LiftDispatcher liftDispatcher; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | // @Autowired |
| | | // private CommonService commonService; |
| | | @Autowired |
| | | private AnalyzeService analyzeService; |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private DeviceService deviceService; |
| | | @Autowired |
| | | private DeviceTypeService deviceTypeService; |
| | | @Autowired |
| | | private BasShuttleService basShuttleService; |
| | | @Autowired |
| | | private TaskCtgService taskCtgService; |
| | | @Autowired |
| | | private ShuttleStandbyService shuttleStandbyService; |
| | | |
| | | public ShuttleThread queryShuttleWhichConvenient(Task task, Integer liftNo) { |
| | | public synchronized ShuttleThread searchIdleShuttle(Task task) { |
| | | String locNo = taskService.judgeInbound(task) ? task.getDestLoc() : task.getOriginLoc(); |
| | | ShuttleThread resThread = null; |
| | | Integer finalDistance = ShuttleDispatcher.INF; |
| | | |
| | | DeviceType deviceType = deviceTypeService.getOne(new LambdaQueryWrapper<DeviceType>() |
| | | .eq(DeviceType::getHostId, task.getHostId()) |
| | | .eq(DeviceType::getStatus, 1) |
| | | .eq(DeviceType::getFlag, String.valueOf(SlaveType.Shuttle))); |
| | | if (deviceType == null) { |
| | | throw new CoolException("设备类型不存在"); |
| | | } |
| | | |
| | | List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>() |
| | | .eq(Device::getDeviceType, deviceType.getId()) |
| | | .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()) |
| | | .eq(Device::getHostId, task.getHostId()) |
| | | .eq(Device::getStatus, 1)); |
| | | |
| | |
| | | break; |
| | | } |
| | | |
| | | String targetLocNo = LiftCodeType.getStandbyLocNo(liftNo, currentLev);//默认到提升机待机位 |
| | | String targetLocNo = null;//默认到提升机待机位 |
| | | // 同楼层直接计算到目标库位 |
| | | if (currentLev == Utils.getLev(locNo)) { |
| | | targetLocNo = locNo; |
| | | }else { |
| | | Device recentTransferLift = Utils.getRecentTransferLift(locNo, Integer.parseInt(device.getDeviceNo())); |
| | | if (recentTransferLift == null) { |
| | | continue; |
| | | } |
| | | |
| | | //获取小车楼层提升机待机位 |
| | | ShuttleStandby shuttleStandby = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>() |
| | | .eq(ShuttleStandby::getDeviceId, recentTransferLift.getId()) |
| | | .eq(ShuttleStandby::getDeviceLev, currentLev) |
| | | .eq(ShuttleStandby::getStatus, 1)); |
| | | targetLocNo = shuttleStandby.getDeviceLoc(); |
| | | } |
| | | |
| | | //当前穿梭车线程到当前车子所在楼层的提升机口距离 |
| | |
| | | return resThread; |
| | | } |
| | | |
| | | //生成迁移任务 |
| | | public synchronized Task generateMoveTask(Device device, String locNo) { |
| | | // 已有迁移任务 |
| | | if (taskService.selectMoveWorking(Integer.valueOf(device.getDeviceNo())) != null) { |
| | | return null; |
| | | } |
| | | |
| | | //获取迁移任务类型 |
| | | TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>() |
| | | .eq(TaskCtg::getFlag, "MOVE") |
| | | .eq(TaskCtg::getStatus, 1)); |
| | | if (taskCtg == null) { |
| | | return null; |
| | | } |
| | | |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); |
| | | if (shuttleThread == null) { |
| | | return null; |
| | | } |
| | | |
| | | //获取避让位置 |
| | | String standByLocNo = this.searchStandByLocNo(Integer.valueOf(device.getDeviceNo()), device.getHostId(), shuttleThread.getStatus().getCurrentLocNo()); |
| | | |
| | | Task task = new Task(); |
| | | task.setUuid(String.valueOf(snowflakeIdWorker.nextId())); |
| | | task.setTaskNo(String.valueOf(Utils.getTaskNo("MOVE"))); |
| | | task.setTaskSts(TaskStsType.NEW_MOVE.sts); |
| | | task.setTaskCtg(taskCtg.getId()); |
| | | task.setPriority(10); |
| | | task.setOriginSite(null); |
| | | task.setOriginLoc(null); |
| | | task.setDestSite(null); |
| | | task.setDestLoc(standByLocNo); // 避让位置 |
| | | task.setIoTime(new Date()); |
| | | task.setStartTime(new Date()); |
| | | task.setHostId(device.getHostId()); |
| | | task.setStatus(1); |
| | | task.setShuttleNo(Integer.valueOf(device.getDeviceNo())); |
| | | |
| | | // generate motion list |
| | | List<Motion> motionList = analyzeService.generateShuttleMoveMotion(task); |
| | | if (Cools.isEmpty(motionList)) { |
| | | News.error("保存{}号四向穿梭车迁移任务失败!!!", device.getDeviceNo()); |
| | | return null; |
| | | } |
| | | motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo())); |
| | | |
| | | task.setTaskSts(TaskStsType.ANALYZE_MOVE.sts); |
| | | |
| | | if (!taskService.save(task)) { |
| | | News.error("保存{}号四向穿梭车迁移任务失败!!!", device.getDeviceNo()); |
| | | return null; |
| | | } |
| | | |
| | | return task; |
| | | } |
| | | |
| | | /** |
| | | * 搜索避让库位,通过小车号和目标库位 |
| | | */ |