| | |
| | | import com.zy.acs.common.utils.GsonUtils; |
| | | import com.zy.acs.common.utils.Utils; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.common.R; |
| | | import com.zy.acs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.acs.framework.exception.CoolException; |
| | | import com.zy.acs.manager.common.domain.TaskDto; |
| | |
| | | import com.zy.acs.manager.core.domain.TaskPosDto; |
| | | import com.zy.acs.manager.core.service.astart.MapDataDispatcher; |
| | | import com.zy.acs.manager.core.utils.HttpHandler; |
| | | import com.zy.acs.manager.manager.controller.param.LocSiteParams; |
| | | import com.zy.acs.manager.manager.controller.param.OpenBusSubmitParam; |
| | | import com.zy.acs.manager.manager.entity.*; |
| | | import com.zy.acs.manager.manager.enums.*; |
| | | import com.zy.acs.manager.manager.service.*; |
| | | import com.zy.acs.manager.manager.service.impl.LocStsServiceImpl; |
| | | import com.zy.acs.manager.manager.service.impl.WebsocketServiceImpl; |
| | | import com.zy.acs.manager.manager.utils.ActionSorter; |
| | | import com.zy.acs.manager.system.service.ConfigService; |
| | |
| | | private TaskReportService taskReportService; |
| | | @Autowired |
| | | private AgvDurationService agvDurationService; |
| | | @Autowired |
| | | private LocStsService locStsService; |
| | | |
| | | @SuppressWarnings("all") |
| | | @Transactional |
| | |
| | | break; |
| | | case STA_TO_LOC: |
| | | oriSta = staService.getById(task.getOriSta()); |
| | | if (oriSta.getStaTypeIsCheck() != 1) { |
| | | if (locStaStatusCheck && !oriSta.getStaSts().equals(StaStsType.STOCK.val())) { |
| | | throw new BusinessException("oriSta:" + task.getOriSta$() + " is not in STOCK status"); |
| | | } |
| | | } |
| | | // if (oriSta.getStaTypeIsCheck() != 1) { |
| | | // if (locStaStatusCheck && !oriSta.getStaSts().equals(StaStsType.STOCK.val())) { |
| | | // throw new BusinessException("oriSta:" + task.getOriSta$() + " is not in STOCK status"); |
| | | // } |
| | | // } |
| | | oriSta.setStaSts(StaStsType.READY_TAKE.val()); |
| | | oriSta.setUpdateTime(now); |
| | | if (!staService.updateById(oriSta)) { |
| | |
| | | |
| | | // 需要走行 |
| | | if (!lastCode.getData().equals(code.getData())) { |
| | | |
| | | // 走行路径节点 |
| | | // List<String> pathList = mapService.checkoutPath(agv.getUuid(), lastCode, code); |
| | | List<String> pathListPart = pathList.subList(pathList.indexOf(lastCode.getData()), pathList.indexOf(code.getData()) + 1); |
| | |
| | | // 第一步:如果下一个方向正好是作业方向的相反方向,则重置下一个方向为作业方向,标记 reverse = true |
| | | boolean reverse = false; |
| | | if (nextDirection.equals((workDirection + 180) % 360)) { |
| | | nextDirection = workDirection; |
| | | reverse = true; |
| | | List<String> list = Arrays.asList("00000050", "00000051", "00000052", "00000053", "00000054"); |
| | | if ((Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())).equals(TaskPosDto.PosType.ORI_STA) |
| | | || Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.DEST_STA)) && list.contains(lastCode.getData())) { |
| | | reverse = false; |
| | | lastDirection = nextDirection; |
| | | } else { |
| | | nextDirection = workDirection; |
| | | reverse = true; |
| | | } |
| | | } |
| | | |
| | | // 第二步:判断当前节点是否可以旋转 |
| | |
| | | nextDirection = lastDirection; |
| | | reverse = true; |
| | | } else { |
| | | if ((Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.ORI_STA) || Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.DEST_STA)) && lastCode.getData().equals("00000050")) { |
| | | // turn |
| | | reverse = false; |
| | | actionList.add(new Action( |
| | | null, // 编号s |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(180), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | } else { |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号s |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(nextDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | } |
| | | lastDirection = nextDirection; |
| | | } |
| | | } else { |
| | | if ((Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.ORI_STA) || Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.DEST_STA)) && lastCode.getData().equals("00000050")) { |
| | | // turn |
| | | reverse = false; |
| | | actionList.add(new Action( |
| | | null, // 编号s |
| | | task.getBusId(), // 总线 |
| | |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(nextDirection), // 动作参数 |
| | | String.valueOf(180), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | lastDirection = nextDirection; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 第一个动作一定是 turn |
| | | if (actionList.isEmpty()) { |
| | | if (actionList.isEmpty() && lastCode.getCornerBool()) { |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | |
| | | lastCode = nextCode; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | // 初始方向值补丁 |
| | | if (first) { |
| | | if (Cools.isEmpty(actionList) || !actionList.get(0).getActionType().equals(ActionTypeType.TurnCorner.val())) { |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(workDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | lastDirection = workDirection; |
| | | |
| | | Double turnDirection = workDirection; |
| | | List<String> list = Arrays.asList("00000051", "00000052", "00000053", "00000054"); |
| | | if ((Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())).equals(TaskPosDto.PosType.ORI_STA) |
| | | || Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.DEST_STA)) && list.contains(lastCode.getData())) { |
| | | turnDirection = workDirection + 180.0; |
| | | } |
| | | if (lastCode.getCornerBool()) { |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(turnDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | lastDirection = workDirection; |
| | | } |
| | | } |
| | | first = false; |
| | | } |
| | |
| | | assert backpackType != null; |
| | | // 检验方向 |
| | | if (!lastDirection.equals(workDirection)) { |
| | | throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | lastDirection = workDirection; |
| | | // throw new CoolException(agvNo agvNo+ "号小车方向错误,请推至转弯点手动调整"); |
| | | } |
| | | // 货架取货 |
| | | Loc oriLoc = locService.getById(task.getOriLoc()); |
| | |
| | | Sta oriSta = staService.getById(task.getOriSta()); |
| | | Double oriStaWorkDirection = mapService.getStaAngle(oriSta, workDirection); |
| | | // 检验方向 |
| | | if (!lastDirection.equals(oriStaWorkDirection)) { |
| | | if (!lastCode.getCornerBool()) { |
| | | throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | } |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性값 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(oriStaWorkDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | lastDirection = oriStaWorkDirection; |
| | | } |
| | | // if (!lastDirection.equals(oriStaWorkDirection)) { |
| | | // if (!lastCode.getCornerBool()) { |
| | | // throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | // } |
| | | // // turn |
| | | // actionList.add(new Action( |
| | | // null, // 编号 |
| | | // task.getBusId(), // 总线 |
| | | // task.getId(), // 任务 |
| | | // null, // 动作号 |
| | | // null, // 优先级 |
| | | // ActionTypeType.TurnCorner.desc, // 名称 |
| | | // mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性값 |
| | | // lastCode.getData(), // 地面码 |
| | | // String.valueOf(oriStaWorkDirection), // 动作参数 |
| | | // ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | // actionPrepareSts, // 动作进度 |
| | | // agvId, // AGV |
| | | // now // 工作时间 |
| | | // )); |
| | | // lastDirection = oriStaWorkDirection; |
| | | // } |
| | | // 计算货叉工作方向 |
| | | staWorkDirection = mapService.calculateAgvWorkDirectionByStation(oriStaWorkDirection, lastDirection); |
| | | actionList.add(new Action( |
| | |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.ReadyTakeFromConveyorSta.desc, // 名称 |
| | | staWorkDirection, // 属性值 |
| | | ActionTypeType.ReadyTakeFromShelvesLoc.desc, // 名称 |
| | | Double.parseDouble("0"), // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(oriSta.getOffset()), // 动作参数 |
| | | ActionTypeType.ReadyTakeFromConveyorSta.val(), // 动作类型 |
| | | ActionTypeType.ReadyTakeFromShelvesLoc.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now, // 工作时间 |
| | |
| | | // 站点放货 |
| | | Sta destSta = staService.getById(task.getDestSta()); |
| | | Double destStaWorkDirection = mapService.getStaAngle(destSta, workDirection); |
| | | // CodeGap gap = codeGapService.findByCodeOfBoth(lastCode.getId(), nextCode.getId()); |
| | | |
| | | // 检验方向 |
| | | if (!lastDirection.equals(destStaWorkDirection)) { |
| | | if (!lastCode.getCornerBool()) { |
| | | throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | } |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性값 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(destStaWorkDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | lastDirection = destStaWorkDirection; |
| | | } |
| | | // if (!lastDirection.equals(destStaWorkDirection)) { |
| | | // if (!lastCode.getCornerBool()) { |
| | | // throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | // } |
| | | // |
| | | // actionList.add(new Action( |
| | | // null, // 编号 |
| | | // task.getBusId(), // 总线 |
| | | // task.getId(), // 任务 |
| | | // null, // 动作号 |
| | | // null, // 优先级 |
| | | // actionType.desc, // 名称 |
| | | // (double) agvSpeedType.val, // 属性值 |
| | | // lastCode.getData(), // 地面码 |
| | | // String.valueOf(gap.getDistance()), // 动作参数 |
| | | // actionType.val(), // 动作类型 |
| | | // actionPrepareSts, // 动作进度 |
| | | // agvId, // AGV |
| | | // now // 工作时间 |
| | | // )); |
| | | // // turn |
| | | // actionList.add(new Action( |
| | | // null, // 编号 |
| | | // task.getBusId(), // 总线 |
| | | // task.getId(), // 任务 |
| | | // null, // 动作号 |
| | | // null, // 优先级 |
| | | // ActionTypeType.TurnCorner.desc, // 名称 |
| | | // mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性값 |
| | | // lastCode.getData(), // 地面码 |
| | | // String.valueOf(destStaWorkDirection), // 动作参数 |
| | | // ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | // actionPrepareSts, // 动作进度 |
| | | // agvId, // AGV |
| | | // now // 工作时间 |
| | | // )); |
| | | // lastDirection = destStaWorkDirection; |
| | | // } |
| | | // 暂存点取货 |
| | | assert backpackType != null; |
| | | actionList.add(new Action( |
| | |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.ReadyReleaseToConveyorSta.desc, // 名称 |
| | | staWorkDirection, // 属性값 |
| | | ActionTypeType.ReadyReleaseToShelvesLoc.desc, // 名称 |
| | | Double.parseDouble("0"), // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(destSta.getOffset()), // 动作参数 |
| | | ActionTypeType.ReadyReleaseToConveyorSta.val(), // 动作类型 |
| | | ActionTypeType.ReadyReleaseToShelvesLoc.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now, // 工作时间 |
| | |
| | | // 检验方向 |
| | | FuncSta chargeFuncSta = funcStaService.query(lastCode.getId(), FuncStaType.CHARGE.toString()); |
| | | Double chargeDirection = Double.parseDouble(chargeFuncSta.getAngle()); |
| | | if (!lastDirection.equals(chargeDirection)) { |
| | | if (!lastDirection.equals(chargeDirection) && lastCode.getCornerBool()) { |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | null, // 总线 |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据分片生成动作 ( 车辆可能已经做过一些任务了,正在等待下一段任务 ) |
| | | */ |
| | |
| | | throw new CoolException("AGV[" + agvNo + "]定位偏移..."); |
| | | } |
| | | |
| | | String lastCorner = null; |
| | | for (int i = pathList.size(); i <0; i++) { |
| | | Code nextCode = codeService.getCacheByData(pathList.get(i - 1)); |
| | | if (nextCode!=null&&nextCode.getCornerBool()){ |
| | | lastCorner =pathList.get(i - 1); |
| | | //String lastCorner = null; |
| | | Integer index = -1; |
| | | boolean corner = false; |
| | | for (int i = pathList.size(); i < 0; i++) { |
| | | Code nextCode = codeService.getCacheByData(pathList.get(i)); |
| | | if (nextCode != null && nextCode.getCornerBool()) { |
| | | //lastCorner = pathList.get(i); |
| | | index = i; |
| | | } |
| | | } |
| | | |
| | |
| | | if (i == 0) { |
| | | continue; |
| | | } |
| | | |
| | | String next = pathListPart.get(i); |
| | | |
| | | Code nextCode = codeService.getCacheByData(next); |
| | | Double nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal); |
| | | Double nextDirection; |
| | | |
| | | boolean reverse = false; |
| | | if (lastCorner.equals(lastCode)){ |
| | | // DOTO |
| | | if (index >= i) { |
| | | // DOTO 添加转弯 |
| | | Code endCode = codeService.getCacheByData(pathList.get(pathList.size() - 1)); |
| | | nextDirection = mapService.calculateDirection(lastCode, endCode, angleOffsetVal); |
| | | reverse = true; |
| | | } else { |
| | | nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal); |
| | | |
| | | }else { |
| | | // 第一步:如果下一个方向正好是作业方向的相反方向,则重置下一个方向为作业方向,标记 reverse = true |
| | | if (nextDirection.equals((workDirection + 180) % 360)) { |
| | | if (!nextDirection.equals((workDirection + 180) % 360)) { |
| | | nextDirection = workDirection; |
| | | reverse = true; |
| | | } |
| | |
| | | // 检验方向 |
| | | FuncSta chargeFuncSta = funcStaService.query(lastCode.getId(), FuncStaType.CHARGE.toString()); |
| | | Double chargeDirection = Double.parseDouble(chargeFuncSta.getAngle()); |
| | | if (!lastDirection.equals(chargeDirection)) { |
| | | if (!lastDirection.equals(chargeDirection) && lastCode.getCornerBool()) { |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | null, // 总线 |
| | |
| | | |
| | | log.info("{}号Agv动作组装完成,指令数量:{}", agvNo, newActionList.size()); |
| | | } catch (Exception e) { |
| | | log.error("mainService.generateAction", e); |
| | | log.error("mainService.generateActionV2", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | |
| | | if (!Cools.isEmpty(pathList)) { |
| | |
| | | mapDataDispatcher.clearDynamicMatrixByCodeList(null, codeMatrixIdxList); |
| | | } |
| | | |
| | | throw new RuntimeException("generateAction method caught an exception, rolling back transaction.", e); |
| | | throw new RuntimeException("generateActionV2 method caught an exception, rolling back transaction.", e); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/11/10 |
| | | * @description: 修改库位状态 |
| | | * @version 1.0 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R modifyStatus(LocSiteParams params) { |
| | | if (Objects.isNull(params.getStatus())) { |
| | | return R.error("修改状态不能为空!!"); |
| | | } |
| | | LocSts locSts = locStsService.getOne(new LambdaQueryWrapper<LocSts>().eq(LocSts::getUuid, params.getStatus())); |
| | | if (Objects.isNull(locSts)) { |
| | | return R.error("数据错误,未找到对应工作状态!!"); |
| | | } |
| | | if (!params.getType().equals("loc")) { |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, params.getCode())); |
| | | if (Objects.isNull(loc)) { |
| | | return R.error("库位信息不存在!!"); |
| | | } |
| | | loc.setLocSts(locSts.getId()); |
| | | if (!locService.updateById(loc)) { |
| | | return R.ok("库位状态修改失败!!"); |
| | | } |
| | | } else { |
| | | Sta sta = staService.getOne(new LambdaQueryWrapper<Sta>().eq(Sta::getStaNo, params.getCode())); |
| | | if (Objects.isNull(sta)) { |
| | | return R.error("站点信息不存在!!"); |
| | | } |
| | | sta.setStatus(locSts.getStatus()); |
| | | if (!staService.updateById(sta)) { |
| | | return R.error("站点状态修改失败!!"); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |