| | |
| | | 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; |
| | |
| | | |
| | | boolean first = true; |
| | | for (Segment segment : segmentList) { |
| | | |
| | | // 分段所属的Task |
| | | Task task = taskService.getById(segment.getTaskId()); |
| | | TaskPosDto.PosType posType = Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())); |
| | | boolean isStation = posType.equals(TaskPosDto.PosType.ORI_STA) || posType.equals(TaskPosDto.PosType.DEST_STA); |
| | | boolean isLoc = posType.equals(TaskPosDto.PosType.ORI_LOC) || posType.equals(TaskPosDto.PosType.DEST_LOC); |
| | | // 目标是否为站点 |
| | | boolean isStation = posType == TaskPosDto.PosType.ORI_STA || posType == TaskPosDto.PosType.DEST_STA; |
| | | // 目标是否为库位 |
| | | boolean isLoc = posType == TaskPosDto.PosType.ORI_LOC || posType == TaskPosDto.PosType.DEST_LOC; |
| | | // 站点地码 |
| | | List<String> turnCodes = Arrays.asList("00000050", "00000051", "00000052", "00000053", "00000054"); |
| | | // 库位地码 |
| | | List<String> locTurnCodes = Arrays.asList("00000080", "00000081", "00000082", "00000083", "00000084"); |
| | | // 节点条码 |
| | | Code code = codeService.getCacheById(segment.getEndNode()); |
| | | |
| | |
| | | // 第一步:如果下一个方向正好是作业方向的相反方向,则重置下一个方向为作业方向,标记 reverse = true |
| | | boolean reverse = false; |
| | | if (nextDirection.equals((workDirection + 180) % 360)) { |
| | | List<String> list = Arrays.asList("00000050", "00000051", "00000052", "00000053", "00000054", "00000080", "00000081", "00000082", "00000083", "00000084"); |
| | | if ((isStation && list.contains("00000050")) || (isLoc && list.contains("00000080"))) { |
| | | if ((isStation && turnCodes.contains(lastCode.getData())) || (isLoc && locTurnCodes.contains(lastCode.getData()))) { |
| | | reverse = false; |
| | | lastDirection = nextDirection; |
| | | } else { |
| | |
| | | nextDirection, |
| | | 180); |
| | | } else { |
| | | List<String> list = Arrays.asList("00000051", "00000052", "00000053", "00000054"); |
| | | Double turnDirection = nextDirection; |
| | | if ((isStation && list.contains("00000050")) || (isLoc && list.contains("00000080"))) { |
| | | if (turnCodes.contains(nextCode.getData()) && lastCode.getData().equals("00000050")) { |
| | | turnDirection = 180.0; |
| | | } |
| | | // turn |
| | |
| | | lastDirection = nextDirection; |
| | | } |
| | | } else { |
| | | // if (isStation && lastCode.getData().equals("00000050")) { |
| | | if ((isStation && lastCode.getData().equals("00000050")) || (isLoc && lastCode.getData().equals("00000080"))) { |
| | | // turn |
| | | reverse = false; |
| | |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | reverse = false; |
| | | log.info("3TurnCorner posType={}, code={}, corner={}, nextDirection={}, finalAngle={}", |
| | | posType, |
| | | lastCode.getData(), |
| | |
| | | if (first) { |
| | | if (Cools.isEmpty(actionList) || !actionList.get(0).getActionType().equals(ActionTypeType.TurnCorner.val())) { |
| | | Double turnDirection = workDirection; |
| | | List<String> list = Arrays.asList("00000050","00000051", "00000052", "00000053", "00000054", "00000080", "00000081", "00000082", "00000083", "00000084"); |
| | | if ((isStation && list.contains("00000050")) || (isLoc && list.contains("00000080"))) { |
| | | // if (isStation && turnCodes.contains(lastCode.getData())) { |
| | | if ((isStation && turnCodes.contains(lastCode.getData())) || (isLoc && locTurnCodes.contains(lastCode.getData()))) { |
| | | turnDirection = workDirection + 180.0; |
| | | } |
| | | if (lastCode.getCornerBool()) { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据分片生成动作 ( 车辆可能已经做过一些任务了,正在等待下一段任务 ) |
| | | */ |
| | | @Transactional |
| | | public synchronized void generateActionV2(Long agvId, List<Segment> segmentList, List<String> pathList, Date algoStartTime) { |
| | | public synchronized void generateActionV2(Long agvId, List<Segment> segmentList, List<String> pathList, |
| | | Date algoStartTime) { |
| | | try { |
| | | if (Cools.isEmpty(agvId, segmentList)) { |
| | | return; |
| | | } |
| | | Date now = new Date(); |
| | | long actionPrepareSts = ActionStsType.PREPARE.val(); |
| | | // JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class); |
| | | // JSONObject storeDirection = configService.getVal("storeDirection", |
| | | // JSONObject.class); |
| | | int angleOffsetVal = configService.getVal("mapAngleOffsetVal", Integer.class); |
| | | String agvNo = agvService.getAgvNo(agvId); |
| | | // if (!agvService.judgeEnable(agvId)) { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // 第一个动作一定是 turn |
| | | if (actionList.isEmpty()) { |
| | | // turn |
| | |
| | | |
| | | // 初始方向值补丁 |
| | | if (first) { |
| | | if (Cools.isEmpty(actionList) || !actionList.get(0).getActionType().equals(ActionTypeType.TurnCorner.val())) { |
| | | if (Cools.isEmpty(actionList) |
| | | || !actionList.get(0).getActionType().equals(ActionTypeType.TurnCorner.val())) { |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | |
| | | |
| | | )); |
| | | // 计算货叉工作方向 |
| | | staWorkDirection = mapService.calculateAgvWorkDirectionByStation(destStaWorkDirection, lastDirection); |
| | | staWorkDirection = mapService.calculateAgvWorkDirectionByStation(destStaWorkDirection, |
| | | lastDirection); |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | |
| | | agvId, // AGV |
| | | now, // 工作时间 |
| | | destSta.getStaTypeIsCheck() == 1 ? 2 : 0, |
| | | destSta.getStaNo() |
| | | )); |
| | | destSta.getStaNo())); |
| | | break; |
| | | case TO_CHARGE: |
| | | // 检验方向 |
| | |
| | | if (agv_11_up.getCompleteType().equals(AgvCompleteType.RELEASE_FROM_SHELVES_COMPLETE)) { |
| | | WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode(); |
| | | |
| | | // Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, String.valueOf(Integer.parseInt(agv_11_up.getLocCode())))); |
| | | // Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, |
| | | // String.valueOf(Integer.parseInt(agv_11_up.getLocCode())))); |
| | | // if (null == loc) { |
| | | // log.warn("Agv [{}] 上报往货架放货完成时,库位码[{}]无效。", protocol.getAgvNo(), agv_11_up.getLocCode()); |
| | | // log.warn("Agv [{}] 上报往货架放货完成时,库位码[{}]无效。", protocol.getAgvNo(), |
| | | // agv_11_up.getLocCode()); |
| | | // } else { |
| | | // List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | // for (Long taskId : taskIds) { |
| | |
| | | // action.setEndTime(now); |
| | | // action.setUpdateTime(now); |
| | | // if (!actionService.updateById(action)) { |
| | | // log.error("Action [{}] 更新失败 !!!", action.getPriority() + " - " + action.getName()); |
| | | // log.error("Action [{}] 更新失败 !!!", action.getPriority() + " - " + |
| | | // action.getName()); |
| | | // } |
| | | // } |
| | | // //插入一条 |
| | |
| | | if (agv_11_up.getCompleteType().equals(AgvCompleteType.TAKE_FROM_SHELVES_COMPLETE)) { |
| | | WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode(); |
| | | |
| | | // Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, String.valueOf(Integer.parseInt(agv_11_up.getLocCode())))); |
| | | // Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, |
| | | // String.valueOf(Integer.parseInt(agv_11_up.getLocCode())))); |
| | | // if (null == loc) { |
| | | // log.warn("Agv [{}] 上报从货架取货完成,库位码[{}]无效。", protocol.getAgvNo(), agv_11_up.getLocCode()); |
| | | // log.warn("Agv [{}] 上报从货架取货完成,库位码[{}]无效。", protocol.getAgvNo(), |
| | | // agv_11_up.getLocCode()); |
| | | // } else { |
| | | // |
| | | // List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | |
| | | // action.setEndTime(now); |
| | | // action.setUpdateTime(now); |
| | | // if (!actionService.updateById(action)) { |
| | | // log.error("Action [{}] 更新失败 !!!", action.getPriority() + " - " + action.getName()); |
| | | // log.error("Action [{}] 更新失败 !!!", action.getPriority() + " - " + |
| | | // action.getName()); |
| | | // } |
| | | // } |
| | | // report(task, TaskReportStsType.OTBIN); |
| | |
| | | |
| | | } |
| | | //从输送线取货完成 |
| | | // if (agv_11_up.getCompleteType().equals(AgvCompleteType.TAKE_FROM_STA_COMPLETE)) { |
| | | // if |
| | | // (agv_11_up.getCompleteType().equals(AgvCompleteType.TAKE_FROM_STA_COMPLETE)) |
| | | // { |
| | | // WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode(); |
| | | // List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | // for (Long taskId : taskIds) { |
| | |
| | | // } |
| | | // } |
| | | //往输送线放货完成 |
| | | // if (agv_11_up.getCompleteType().equals(AgvCompleteType.RELEASE_FROM_STA_COMPLETE)) { |
| | | // if |
| | | // (agv_11_up.getCompleteType().equals(AgvCompleteType.RELEASE_FROM_STA_COMPLETE)) |
| | | // { |
| | | // WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode(); |
| | | // List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | // for (Long taskId : taskIds) { |
| | |
| | | List<Segment> segmentList = segmentService.list(new LambdaQueryWrapper<Segment>() |
| | | .eq(Segment::getGroupId, serialNo) |
| | | // .eq(Segment::getState, SegmentStateType.RUNNING.toString()) |
| | | .orderByAsc(Segment::getSerial) |
| | | ); |
| | | .orderByAsc(Segment::getSerial)); |
| | | |
| | | // settlement |
| | | this.settleSegmentList(segmentList, serialNo); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | public void settleSegmentList(List<Segment> segmentList, String serialNo) { |
| | | if (Cools.isEmpty(segmentList)) { |
| | |
| | | for (Segment segment : segmentList) { |
| | | boolean taskComplete = false; |
| | | boolean otbin = false; |
| | | |
| | | |
| | | Task task = taskService.getById(segment.getTaskId()); |
| | | assert null != task; |
| | |
| | | report(task, null, TaskReportStsType.OTBIN); |
| | | } |
| | | |
| | | |
| | | if (taskComplete) { |
| | | locService.taskCallBackEnd(task); |
| | | |
| | |
| | | if (!Cools.isEmpty(serialNo)) { |
| | | List<Action> actionList = actionService.list(new LambdaQueryWrapper<Action>() |
| | | .eq(Action::getGroupId, serialNo) |
| | | .eq(Action::getActionSts, ActionStsType.ISSUED.val()) |
| | | ); |
| | | .eq(Action::getActionSts, ActionStsType.ISSUED.val())); |
| | | for (Action action : actionList) { |
| | | action.setActionSts(ActionStsType.FINISH.val()); |
| | | action.setEndTime(now); |
| | |
| | | if (task.getBusId() == null) { |
| | | return; |
| | | } |
| | | List<TaskReport> list = taskReportService.list(new LambdaQueryWrapper<TaskReport>().eq(TaskReport::getSeqNum, task.getSeqNum()).eq(TaskReport::getBusNo, task.getBusId$()).eq(TaskReport::getTaskSts, taskReportStsType.status)); |
| | | List<TaskReport> list = taskReportService.list(new LambdaQueryWrapper<TaskReport>() |
| | | .eq(TaskReport::getSeqNum, task.getSeqNum()).eq(TaskReport::getBusNo, task.getBusId$()) |
| | | .eq(TaskReport::getTaskSts, taskReportStsType.status)); |
| | | if (!Cools.isEmpty(list)) { |
| | | log.info("TaskReport [{},{}] 已重复,不再插入 ==========>> ", taskReportStsType, JSON.toJSONString(task)); |
| | | return; |