| | |
| | | import com.zy.acs.manager.common.exception.BusinessException; |
| | | import com.zy.acs.manager.core.service.*; |
| | | import com.zy.acs.manager.core.service.astart.MapDataDispatcher; |
| | | import com.zy.acs.manager.core.service.astart.domain.DynamicNode; |
| | | import com.zy.acs.manager.manager.entity.*; |
| | | import com.zy.acs.manager.manager.enums.*; |
| | | import com.zy.acs.manager.manager.service.*; |
| | |
| | | private AvoidWaveCalculator avoidWaveCalculator; |
| | | @Autowired |
| | | private PatrolService patrolService; |
| | | @Autowired |
| | | private StaReserveService staReserveService; |
| | | |
| | | @PreAuthorize("hasAuthority('manager:agv:update')") |
| | | @OperationLog("Locate All Agv") |
| | |
| | | @PostMapping("/patrol/batch/startup") |
| | | public synchronized R patrolBatchStartup() { |
| | | List<Agv> list = agvService.list(new LambdaQueryWrapper<Agv>().eq(Agv::getStatus, StatusType.ENABLE.val)); |
| | | DynamicNode[][] dynamicMatrix = mapDataDispatcher.getDynamicMatrix(MapDataDispatcher.MAP_DEFAULT_LEV); |
| | | int result = 0; |
| | | for (Agv agv : list) { |
| | | patrolService.startupPatrol(agv.getUuid()); |
| | | result++; |
| | | String agvNo = agv.getUuid(); |
| | | |
| | | boolean inMap = false; |
| | | label: for (int i = 0; i < dynamicMatrix.length; i++) { |
| | | for (int j = 0; j < dynamicMatrix[i].length; j++) { |
| | | DynamicNode dynamicNode = dynamicMatrix[i][j]; |
| | | String vehicle = dynamicNode.getVehicle(); |
| | | if (agvNo.equals(vehicle)) { |
| | | inMap = true; |
| | | break label; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (inMap) { |
| | | patrolService.startupPatrol(agvNo); |
| | | result++; |
| | | } |
| | | } |
| | | return R.ok().add(result); |
| | | } |
| | |
| | | .eq(Task::getTaskSts, TaskStsType.ASSIGN.val()) |
| | | .or().eq(Task::getTaskSts, TaskStsType.PROGRESS.val()); |
| | | })) > 0) { |
| | | log.info(agv.getUuid() + "号AGV不可用,已经存在进行中的任务..."); |
| | | log.info("{}号AGV不可用,已经存在进行中的任务...", agv.getUuid()); |
| | | return R.error(); |
| | | } |
| | | if (!agvService.judgeEnable(agv.getId())) { |
| | | log.info(agv.getUuid() + "号AGV不可用,任务无法计算..."); |
| | | log.info("{}号AGV不可用,任务无法计算...", agv.getUuid()); |
| | | return R.error(); |
| | | } |
| | | |
| | | Task task = new Task(); |
| | | task.setAgvId(agv.getId()); |
| | | task.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); |
| | | List<Task> lastTasks = taskService.list(new LambdaQueryWrapper<Task>().orderByDesc(Task::getId)); |
| | | task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks)?null:lastTasks.get(0).getSeqNum())); |
| | | |
| | | task.setTaskType(param.getTaskMode().val()); |
| | | task.setTaskSts(TaskStsType.WAITING.val()); |
| | | |
| | | task.setPriority(999); |
| | | task.setIoTime(now); |
| | | task.setStartTime(now); |
| | | task.setMemo("AUTO"); |
| | | if (!taskService.save(task)) { |
| | | throw new BusinessException(task.getSeqNum() + "任务保存失败"); |
| | | } |
| | | |
| | | // generate |
| | |
| | | Loc destLoc = null; |
| | | Sta oriSta = null; |
| | | Sta destSta = null; |
| | | Task task = null; |
| | | switch (param.getTaskMode()) { |
| | | case MOVE: |
| | | Code endCode = null; |
| | |
| | | if (null == endCode) { |
| | | return R.error(); |
| | | } |
| | | if (!taskService.removeById(task.getId())) { |
| | | throw new BusinessException("failed to remove task"); |
| | | } |
| | | task = null; |
| | | if (!mainLockWrapService.buildMinorTask(agv.getId(), param.getTaskMode(), endCode.getData(), null)) { |
| | | return R.error(); |
| | | } |
| | | break; |
| | | case TO_CHARGE: |
| | | case TO_STANDBY: |
| | | if (!taskService.removeById(task.getId())) { |
| | | throw new BusinessException("failed to remove task"); |
| | | } |
| | | task = null; |
| | | if (!mainLockWrapService.buildMinorTask(agv.getId(), param.getTaskMode(), null, null)) { |
| | | return R.error(); |
| | | } |
| | |
| | | oriLoc = locService.getById(param.getStartLocNo()); |
| | | } |
| | | if (!Cools.isEmpty(param.getStartLocNoStr())) { |
| | | oriLoc = locService.selecatByLocNo(param.getStartLocNoStr()); |
| | | oriLoc = locService.selectByLocNo(param.getStartLocNoStr()); |
| | | } |
| | | if (null == oriLoc) { |
| | | return R.error(); |
| | |
| | | destLoc = locService.getById(param.getEndLocNo()); |
| | | } |
| | | if (!Cools.isEmpty(param.getEndLocNoStr())) { |
| | | destLoc = locService.selecatByLocNo(param.getEndLocNoStr()); |
| | | destLoc = locService.selectByLocNo(param.getEndLocNoStr()); |
| | | } |
| | | if (null == destLoc) { |
| | | return R.error(); |
| | |
| | | } |
| | | |
| | | // task |
| | | task = new Task(); |
| | | |
| | | task.setOriLoc(oriLoc.getId()); |
| | | task.setOriCode(oriLoc.getCode()); |
| | | task.setDestLoc(destLoc.getId()); |
| | |
| | | oriLoc = locService.getById(param.getStartLocNo()); |
| | | } |
| | | if (!Cools.isEmpty(param.getStartLocNoStr())) { |
| | | oriLoc = locService.selecatByLocNo(param.getStartLocNoStr()); |
| | | oriLoc = locService.selectByLocNo(param.getStartLocNoStr()); |
| | | } |
| | | if (null == oriLoc) { |
| | | return R.error(); |
| | |
| | | if (null == destSta) { |
| | | return R.error(); |
| | | } |
| | | if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) { |
| | | throw new BusinessException("destSta:" + destSta.getStaNo() + " 不是无货状态"); |
| | | if (null == staReserveService.reserveStaIn(destSta, task, 1)) { |
| | | throw new BusinessException("destSta:" + destSta.getStaNo() + " 预约失败"); |
| | | } |
| | | destSta.setStaSts(StaStsType.READY_RELEASE.val()); |
| | | destSta.setUpdateTime(now); |
| | | if (!staService.updateById(destSta)) { |
| | | throw new BusinessException("destSta:" + destSta.getStaNo() + " 修改站点状态失败"); |
| | | } |
| | | |
| | | // task |
| | | task = new Task(); |
| | | |
| | | task.setOriLoc(oriLoc.getId()); |
| | | task.setOriCode(oriLoc.getCode()); |
| | | task.setDestSta(destSta.getId()); |
| | | task.setDestCode(destSta.getCode()); |
| | | |
| | | staReserveService.allocateCallBack(task, agv.getId()); |
| | | break; |
| | | case STA_TO_LOC: |
| | | // oriSta |
| | |
| | | if (null == oriSta) { |
| | | return R.error(); |
| | | } |
| | | if (!oriSta.getStaSts().equals(StaStsType.STOCK.val())) { |
| | | throw new BusinessException("oriSta:" + oriSta.getStaNo() + " 不是有货状态"); |
| | | } |
| | | oriSta.setStaSts(StaStsType.READY_TAKE.val()); |
| | | oriSta.setUpdateTime(now); |
| | | if (!staService.updateById(oriSta)) { |
| | | throw new BusinessException("oriSta:" + oriSta.getStaNo() + " 修改站点状态失败"); |
| | | if (null == staReserveService.reserveStaOut(oriSta, task, 1)) { |
| | | throw new BusinessException("oriSta:" + oriSta.getStaNo() + " 预约失败"); |
| | | } |
| | | |
| | | // destLoc |
| | |
| | | destLoc = locService.getById(param.getEndLocNo()); |
| | | } |
| | | if (!Cools.isEmpty(param.getEndLocNoStr())) { |
| | | destLoc = locService.selecatByLocNo(param.getEndLocNoStr()); |
| | | destLoc = locService.selectByLocNo(param.getEndLocNoStr()); |
| | | } |
| | | if (null == destLoc) { |
| | | return R.error(); |
| | |
| | | } |
| | | |
| | | // task |
| | | task = new Task(); |
| | | |
| | | task.setOriSta(oriSta.getId()); |
| | | task.setOriCode(oriSta.getCode()); |
| | | task.setDestLoc(destLoc.getId()); |
| | | task.setDestCode(destLoc.getCode()); |
| | | |
| | | staReserveService.allocateCallBack(task, agv.getId()); |
| | | break; |
| | | case STA_TO_STA: |
| | | // oriSta |
| | |
| | | if (null == oriSta) { |
| | | return R.error(); |
| | | } |
| | | if (!oriSta.getStaSts().equals(StaStsType.STOCK.val())) { |
| | | throw new BusinessException("oriSta:" + oriSta.getStaNo() + " 不是有货状态"); |
| | | if (null == staReserveService.reserveStaOut(oriSta, task, 1)) { |
| | | throw new BusinessException("oriSta:" + oriSta.getStaNo() + " 预约失败"); |
| | | } |
| | | oriSta.setStaSts(StaStsType.READY_TAKE.val()); |
| | | oriSta.setUpdateTime(now); |
| | | if (!staService.updateById(oriSta)) { |
| | | throw new BusinessException("oriSta:" + oriSta.getStaNo() + " 修改站点状态失败"); |
| | | } |
| | | |
| | | |
| | | // destSta |
| | | if (!Cools.isEmpty(param.getEndStaNo())) { |
| | |
| | | if (null == destSta) { |
| | | return R.error(); |
| | | } |
| | | if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) { |
| | | throw new BusinessException("destSta:" + destSta.getStaNo() + " 不是无货状态"); |
| | | } |
| | | destSta.setStaSts(StaStsType.READY_RELEASE.val()); |
| | | destSta.setUpdateTime(now); |
| | | if (!staService.updateById(destSta)) { |
| | | throw new BusinessException("destSta:" + destSta.getStaNo() + " 修改站点状态失败"); |
| | | if (null == staReserveService.reserveStaIn(destSta, task, 1)) { |
| | | throw new BusinessException("destSta:" + destSta.getStaNo() + " 预约失败"); |
| | | } |
| | | |
| | | // task |
| | | task = new Task(); |
| | | |
| | | task.setOriSta(oriSta.getId()); |
| | | task.setOriCode(oriSta.getCode()); |
| | | task.setDestSta(destSta.getId()); |
| | | task.setDestCode(destSta.getCode()); |
| | | |
| | | staReserveService.allocateCallBack(task, agv.getId()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | if (null != task) { |
| | | task.setAgvId(agv.getId()); |
| | | task.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); |
| | | List<Task> lastTasks = taskService.list(new LambdaQueryWrapper<Task>().orderByDesc(Task::getId)); |
| | | task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks)?null:lastTasks.get(0).getSeqNum())); |
| | | |
| | | task.setTaskType(param.getTaskMode().val()); |
| | | task.setTaskSts(TaskStsType.WAITING.val()); |
| | | |
| | | task.setPriority(999); |
| | | task.setIoTime(now); |
| | | task.setStartTime(now); |
| | | if (!taskService.save(task)) { |
| | | throw new BusinessException(task.getSeqNum() + "任务保存失败"); |
| | | if (!taskService.updateById(task)) { |
| | | throw new BusinessException("任务更新失败"); |
| | | } |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |