| | |
| | | @Transactional |
| | | public void publishAction(String actionGroupId) { |
| | | try { |
| | | List<Action> actionList = listPrepareActions(actionGroupId); |
| | | // action |
| | | List<Action> actionList = actionService.list(new LambdaQueryWrapper<Action>() |
| | | .eq(Action::getGroupId, actionGroupId) |
| | | .eq(Action::getActionSts, ActionStsType.PREPARE.val()) |
| | | .orderByDesc(Action::getPriority)); |
| | | if (Cools.isEmpty(actionList)) { |
| | | return; |
| | | } |
| | | |
| | | Long agvId = actionList.get(0).getAgvId(); |
| | | AgvModel agvModel = agvModelService.getByAgvId(agvId); |
| | | if (hikOrderPublishService.support(agvModel)) { |
| | | publishActionForHik(actionGroupId); |
| | | return; |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | String agvNo = agvService.getAgvNo(agvId); |
| | | if (!agvService.judgeOnline(agvId)) { |
| | | return; |
| | | } |
| | | |
| | | markActionAndTaskIssued(actionGroupId, actionList, now); |
| | | |
| | | AgvAction agvAction = new AgvAction(agvNo, actionGroupId); |
| | | Date now = new Date(); |
| | | long actionIssuedSts = ActionStsType.ISSUED.val(); |
| | | for (Action action : actionList) { |
| | | switch (Objects.requireNonNull(ActionTypeType.get(action.getActionTypeEl()))) { |
| | | case TurnCorner: |
| | | agvAction.add(new AgvActionItem<>(TurnCornerAction.class) |
| | | .setQrCode(action.getCode()) |
| | | .setVal(Optional.ofNullable(action.getVal()).orElse(0D).intValue()) |
| | | .bodySync(body -> body.setAngle((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case StraightBackUnturnable: |
| | | break; |
| | | case StraightBackTurnable: |
| | | agvAction.add(new AgvActionItem<>(StraightBackTurnableAction.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setDistance((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case StraightAheadUnturnable: |
| | | break; |
| | | case StraightAheadTurnable: |
| | | agvAction.add(new AgvActionItem<>(StraightAheadTurnableAction.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setDistance((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case ReadyTakeFromShelvesLoc: |
| | | agvAction.add(new AgvActionItem<>(ReadyTakeFromShelvesLoc.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyTakeFromConveyorSta: |
| | | agvAction.add(new AgvActionItem<>(ReadyTakeFromConveyorSta.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyTakeFromAgvSite: |
| | | agvAction.add(new AgvActionItem<>(ReadyTakeFromAgvSite.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setDepth((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case ReadyReleaseToShelvesLoc: |
| | | agvAction.add(new AgvActionItem<>(ReadyReleaseToShelvesLoc.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyReleaseToConveyorSta: |
| | | agvAction.add(new AgvActionItem<>(ReadyReleaseToConveyorSta.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyReleaseToAgvSite: |
| | | agvAction.add(new AgvActionItem<>(ReadyReleaseToAgvSite.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setDepth((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case LoadPlatformLift: |
| | | agvAction.add(new AgvActionItem<>(LoadPlatformLift.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case FinishPath: |
| | | agvAction.add(new AgvActionItem<>(FinishPathAction.class) |
| | | .setQrCode(action.getCode()) |
| | | ); |
| | | break; |
| | | case DockingCharge: |
| | | agvAction.add(new AgvActionItem<>(DockingChargeAction.class) |
| | | .setQrCode(action.getCode()) |
| | | ); |
| | | break; |
| | | case UndockingCharge: |
| | | agvAction.add(new AgvActionItem<>(UndockingChargeAction.class) |
| | | .setQrCode(action.getCode()) |
| | | ); |
| | | break; |
| | | default: |
| | | break; |
| | | action.setActionSts(actionIssuedSts); |
| | | action.setStartTime(now); |
| | | action.setIoTime(now); |
| | | action.setUpdateTime(now); |
| | | } |
| | | if (!actionService.updateBatchById(actionList)) { |
| | | throw new BusinessException("failed to update action batch !!!"); |
| | | } |
| | | |
| | | // task |
| | | List<Long> taskIds = actionService.selectTaskIdsByGroupId(actionGroupId); |
| | | long taskAssignSts = TaskStsType.ASSIGN.val(); |
| | | long taskProgressSts = TaskStsType.PROGRESS.val(); |
| | | for (Long taskId : taskIds) { |
| | | Task task = taskService.getById(taskId); |
| | | if (task.getTaskSts().equals(taskAssignSts)) { |
| | | task.setTaskSts(taskProgressSts); |
| | | task.setUpdateTime(now); |
| | | if (!taskService.updateById(task)) { |
| | | throw new BusinessException(task.getSeqNum() + "任务更新失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | String agvNo = agvService.getAgvNo(agvId); |
| | | AgvModel agvModel = agvModelService.getByAgvId(agvId); |
| | | |
| | | // hik robot |
| | | if (hikOrderPublishService.support(agvModel)) { |
| | | |
| | | hikOrderPublishService.publish(actionGroupId, agvNo, agvModel, actionList); |
| | | News.info("海康任务组 [{}] order 已下发 ===>> 指令数量:{}", actionGroupId, actionList.size()); |
| | | |
| | | // zoneyung robot |
| | | } else { |
| | | AgvAction agvAction = new AgvAction(agvNo, actionGroupId); |
| | | for (Action action : actionList) { |
| | | switch (Objects.requireNonNull(ActionTypeType.get(action.getActionTypeEl()))) { |
| | | case TurnCorner: |
| | | agvAction.add(new AgvActionItem<>(TurnCornerAction.class) |
| | | .setQrCode(action.getCode()) |
| | | .setVal(Optional.ofNullable(action.getVal()).orElse(0D).intValue()) |
| | | .bodySync(body -> body.setAngle((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case StraightBackUnturnable: |
| | | break; |
| | | case StraightBackTurnable: |
| | | agvAction.add(new AgvActionItem<>(StraightBackTurnableAction.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setDistance((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case StraightAheadUnturnable: |
| | | break; |
| | | case StraightAheadTurnable: |
| | | agvAction.add(new AgvActionItem<>(StraightAheadTurnableAction.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setDistance((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case ReadyTakeFromShelvesLoc: |
| | | agvAction.add(new AgvActionItem<>(ReadyTakeFromShelvesLoc.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyTakeFromConveyorSta: |
| | | agvAction.add(new AgvActionItem<>(ReadyTakeFromConveyorSta.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyTakeFromAgvSite: |
| | | agvAction.add(new AgvActionItem<>(ReadyTakeFromAgvSite.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setDepth((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case ReadyReleaseToShelvesLoc: |
| | | agvAction.add(new AgvActionItem<>(ReadyReleaseToShelvesLoc.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyReleaseToConveyorSta: |
| | | agvAction.add(new AgvActionItem<>(ReadyReleaseToConveyorSta.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyReleaseToAgvSite: |
| | | agvAction.add(new AgvActionItem<>(ReadyReleaseToAgvSite.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setDepth((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case LoadPlatformLift: |
| | | agvAction.add(new AgvActionItem<>(LoadPlatformLift.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case FinishPath: |
| | | agvAction.add(new AgvActionItem<>(FinishPathAction.class) |
| | | .setQrCode(action.getCode()) |
| | | ); |
| | | break; |
| | | case DockingCharge: |
| | | agvAction.add(new AgvActionItem<>(DockingChargeAction.class) |
| | | .setQrCode(action.getCode()) |
| | | ); |
| | | break; |
| | | case UndockingCharge: |
| | | agvAction.add(new AgvActionItem<>(UndockingChargeAction.class) |
| | | .setQrCode(action.getCode()) |
| | | ); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | BaseResult<?> result = agvCmdService.executeAgvActionCmd(agvAction); |
| | | if (result.success()) { |
| | | News.info("任务组 [{}] 动作指令已下发 ===>> 指令数量:{}", actionGroupId, actionList.size()); |
| | | } else { |
| | | News.error("任务组 [{}] 动作指令下发失败 !!!", actionGroupId); |
| | | throw new CoolException("任务组 [{" + actionGroupId + "}] 动作指令下发失败 !!!"); |
| | | } |
| | | } |
| | | |
| | | BaseResult<?> result = agvCmdService.executeAgvActionCmd(agvAction); |
| | | if (result.success()) { |
| | | News.info("任务组 [{}] 动作指令已下发 ===>> 指令数量:{}", actionGroupId, actionList.size()); |
| | | } else { |
| | | News.error("任务组 [{}] 动作指令下发失败 !!!", actionGroupId); |
| | | throw new CoolException("任务组 [{" + actionGroupId + "}] 动作指令下发失败 !!!"); |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("mainService.publishAction", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Transactional |
| | | public void publishActionForHik(String actionGroupId) { |
| | | try { |
| | | List<Action> actionList = listPrepareActions(actionGroupId); |
| | | if (Cools.isEmpty(actionList)) { |
| | | return; |
| | | } |
| | | |
| | | Long agvId = actionList.get(0).getAgvId(); |
| | | String agvNo = agvService.getAgvNo(agvId); |
| | | if (!agvService.judgeOnline(agvId)) { |
| | | return; |
| | | } |
| | | |
| | | AgvModel agvModel = agvModelService.getByAgvId(agvId); |
| | | if (!hikOrderPublishService.support(agvModel)) { |
| | | throw new CoolException("agv [" + agvNo + "] protocol is not hik"); |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | markActionAndTaskIssued(actionGroupId, actionList, now); |
| | | |
| | | hikOrderPublishService.publish(actionGroupId, agvNo, agvModel, actionList); |
| | | News.info("海康任务组 [{}] order 已下发 ===>> 指令数量:{}", actionGroupId, actionList.size()); |
| | | } catch (Exception e) { |
| | | News.error("mainService.publishActionForHik", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } |
| | | |
| | | private List<Action> listPrepareActions(String actionGroupId) { |
| | | return actionService.list(new LambdaQueryWrapper<Action>() |
| | | .eq(Action::getGroupId, actionGroupId) |
| | | .eq(Action::getActionSts, ActionStsType.PREPARE.val()) |
| | | .orderByDesc(Action::getPriority)); |
| | | } |
| | | |
| | | private void markActionAndTaskIssued(String actionGroupId, List<Action> actionList, Date now) { |
| | | long actionIssuedSts = ActionStsType.ISSUED.val(); |
| | | for (Action action : actionList) { |
| | | action.setActionSts(actionIssuedSts); |
| | | action.setStartTime(now); |
| | | action.setIoTime(now); |
| | | action.setUpdateTime(now); |
| | | } |
| | | if (!actionService.updateBatchById(actionList)) { |
| | | throw new BusinessException("failed to update action batch !!!"); |
| | | } |
| | | |
| | | List<Long> taskIds = actionService.selectTaskIdsByGroupId(actionGroupId); |
| | | long taskAssignSts = TaskStsType.ASSIGN.val(); |
| | | long taskProgressSts = TaskStsType.PROGRESS.val(); |
| | | for (Long taskId : taskIds) { |
| | | Task task = taskService.getById(taskId); |
| | | if (task != null && task.getTaskSts().equals(taskAssignSts)) { |
| | | task.setTaskSts(taskProgressSts); |
| | | task.setUpdateTime(now); |
| | | if (!taskService.updateById(task)) { |
| | | throw new BusinessException(task.getSeqNum() + "任务更新失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Transactional |