| | |
| | | package com.zy.acs.manager.core.service; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.common.domain.AgvAction; |
| | | import com.zy.acs.common.domain.AgvActionItem; |
| | |
| | | import com.zy.acs.manager.core.domain.Lane; |
| | | 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.OpenBusSubmitParam; |
| | | import com.zy.acs.manager.manager.entity.*; |
| | | import com.zy.acs.manager.manager.enums.*; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | if (!busService.save(bus)) { |
| | | throw new BusinessException("Internal Server Error!"); |
| | | } |
| | | Boolean locStaStatusCheck = configService.getVal("LOC_STA_STATUS_CHECK", Boolean.class, true); |
| | | |
| | | |
| | | // 保存任务 |
| | | for (Task task : taskList) { |
| | |
| | | switch (TaskTypeType.get(task.getTaskTypeEl())) { |
| | | case LOC_TO_LOC: |
| | | oriLoc = locService.getById(task.getOriLoc()); |
| | | if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) { |
| | | if (locStaStatusCheck && !oriLoc.getLocSts().equals(LocStsType.STOCK.val())) { |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " is not in STOCK status"); |
| | | } |
| | | oriLoc.setLocSts(LocStsType.PAKOUT.val()); |
| | |
| | | } |
| | | |
| | | destLoc = locService.getById(task.getDestLoc()); |
| | | if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) { |
| | | if (locStaStatusCheck && !destLoc.getLocSts().equals(LocStsType.IDLE.val())) { |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " is not in IDLE status"); |
| | | } |
| | | destLoc.setLocSts(LocStsType.PAKIN.val()); |
| | |
| | | break; |
| | | case LOC_TO_STA: |
| | | oriLoc = locService.getById(task.getOriLoc()); |
| | | if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) { |
| | | if (locStaStatusCheck && !oriLoc.getLocSts().equals(LocStsType.STOCK.val())) { |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " is not in STOCK status"); |
| | | } |
| | | oriLoc.setLocSts(LocStsType.PAKOUT.val()); |
| | |
| | | } |
| | | |
| | | destSta = staService.getById(task.getDestSta()); |
| | | if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status"); |
| | | if (destSta.getStaTypeIsCheck() != 1) { |
| | | if (locStaStatusCheck && !destSta.getStaSts().equals(StaStsType.IDLE.val())) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status"); |
| | | } |
| | | } |
| | | destSta.setStaSts(StaStsType.READY_RELEASE.val()); |
| | | destSta.setUpdateTime(now); |
| | |
| | | break; |
| | | case STA_TO_LOC: |
| | | oriSta = staService.getById(task.getOriSta()); |
| | | if (!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); |
| | |
| | | } |
| | | |
| | | destLoc = locService.getById(task.getDestLoc()); |
| | | if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) { |
| | | if (locStaStatusCheck && !destLoc.getLocSts().equals(LocStsType.IDLE.val())) { |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " is not in IDLE status"); |
| | | } |
| | | destLoc.setLocSts(LocStsType.PAKIN.val()); |
| | |
| | | break; |
| | | case STA_TO_STA: |
| | | oriSta = staService.getById(task.getOriSta()); |
| | | if (!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); |
| | |
| | | } |
| | | |
| | | destSta = staService.getById(task.getDestSta()); |
| | | if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status"); |
| | | if (destSta.getStaTypeIsCheck() != 1) { |
| | | if (locStaStatusCheck && !destSta.getStaSts().equals(StaStsType.IDLE.val())) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status"); |
| | | } |
| | | } |
| | | destSta.setStaSts(StaStsType.READY_RELEASE.val()); |
| | | destSta.setUpdateTime(now); |
| | |
| | | if (!taskService.updateById(task)) { |
| | | throw new BusinessException("seqNum: " + task.getSeqNum() + " failed to update"); |
| | | } |
| | | report(task, null, TaskReportStsType.START); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("mainService.infuseAgvForTask", e); |
| | |
| | | ActionTypeType.ReadyTakeFromConveyorSta.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | now, // 工作时间 |
| | | oriSta.getStaTypeIsCheck() == 1 ? 1 : 0, |
| | | oriSta.getStaNo() |
| | | )); |
| | | // 暂存点放货 |
| | | assert backpackType != null; |
| | |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | now // 工作时间 |
| | | )); |
| | | lastDirection = destStaWorkDirection; |
| | | } |
| | |
| | | ActionTypeType.ReadyTakeFromAgvSite.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | now, // 工作时间 |
| | | destSta.getStaTypeIsCheck() == 1 ? 2 : 0, |
| | | destSta.getStaNo() |
| | | )); |
| | | // 计算货叉工作方向 |
| | | staWorkDirection = mapService.calculateAgvWorkDirectionByStation(destStaWorkDirection, lastDirection); |
| | |
| | | runToWaitHeight = "800"; |
| | | } |
| | | Double runToWaitHeightValue = configService.getVal("RunToWaitHeightValue", Double.class); |
| | | if (Cools.isEmpty(runToWaitHeight) || runToWaitHeightValue == 0) { |
| | | if (runToWaitHeightValue == 0) { |
| | | runToWaitHeightValue = 1D; |
| | | } |
| | | // 修复空指针异常:检查lastCode是否为null |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | public void publishAction(String actionGroupId) { |
| | | try { |
| | | Date now = new Date(); |
| | | |
| | | boolean flag = true; |
| | | // action |
| | | List<Action> actionList = actionService.list(new LambdaQueryWrapper<Action>() |
| | | .eq(Action::getGroupId, actionGroupId).eq(Action::getActionSts, ActionStsType.PREPARE.val()) |
| | |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | if (!Cools.isEmpty(action.getAskType()) && (action.getAskType() == 1 || action.getAskType() == 2)) { |
| | | flag = askSta(action.getAskType(), action.getAskSta()); |
| | | } |
| | | } |
| | | |
| | | if (!flag) { |
| | | log.error("任务组 [{}] 动作指令下发失败 ,向输送线询问报错!!!", actionGroupId); |
| | | throw new CoolException("任务组 [{" + actionGroupId + "}] 动作指令下发失败 !!!"); |
| | | } |
| | | BaseResult<?> result = agvCmdService.executeAgvActionCmd(agvAction); |
| | | if (result.success()) { |
| | | log.info("任务组 [{}] 动作指令已下发 ===>> 指令数量:{}", actionGroupId, actionList.size()); |
| | |
| | | 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())))); |
| | | if (null == loc) { |
| | | log.warn("Agv [{}] 上报往货架放货完成时,库位码[{}]无效。", protocol.getAgvNo(), agv_11_up.getLocCode()); |
| | | } else { |
| | | List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | for (Long taskId : taskIds) { |
| | | Task task = taskService.getById(taskId); |
| | | if (task.getDestLoc().equals(loc.getId())) { |
| | | // 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()); |
| | | // } else { |
| | | // List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | // for (Long taskId : taskIds) { |
| | | // Task task = taskService.getById(taskId); |
| | | // if (task.getDestLoc().equals(loc.getId())) { |
| | | // |
| | | // Action action = actionService.getOne(new LambdaQueryWrapper<Action>() |
| | | // .eq(Action::getTaskId, task.getId()) |
| | | // .eq(Action::getActionType, ActionTypeType.ReadyReleaseToShelvesLoc.val()) |
| | | // .eq(Action::getActionSts, ActionStsType.ISSUED.val()) |
| | | // ); |
| | | // |
| | | // if (null != action) { |
| | | // action.setActionSts(ActionStsType.FINISH.val()); |
| | | // action.setEndTime(now); |
| | | // action.setUpdateTime(now); |
| | | // if (!actionService.updateById(action)) { |
| | | // log.error("Action [{}] 更新失败 !!!", action.getPriority() + " - " + action.getName()); |
| | | // } |
| | | // } |
| | | // //插入一条 |
| | | // report(task, TaskReportStsType.END); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | Action action = actionService.getOne(new LambdaQueryWrapper<Action>() |
| | | .eq(Action::getTaskId, task.getId()) |
| | | .eq(Action::getActionType, ActionTypeType.ReadyReleaseToShelvesLoc.val()) |
| | | .eq(Action::getActionSts, ActionStsType.ISSUED.val()) |
| | | ); |
| | | |
| | | if (null != action) { |
| | | action.setActionSts(ActionStsType.FINISH.val()); |
| | | action.setEndTime(now); |
| | | action.setUpdateTime(now); |
| | | if (!actionService.updateById(action)) { |
| | | log.error("Action [{}] 更新失败 !!!", action.getPriority() + " - " + action.getName()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | for (Long taskId : taskIds) { |
| | | Task task = taskService.getById(taskId); |
| | | report(task, agv_11_up.getQrCode(), TaskReportStsType.END); |
| | | } |
| | | } |
| | | |
| | |
| | | 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())))); |
| | | if (null == loc) { |
| | | log.warn("Agv [{}] 上报从货架取货完成,库位码[{}]无效。", protocol.getAgvNo(), agv_11_up.getLocCode()); |
| | | } else { |
| | | // 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()); |
| | | // } else { |
| | | // |
| | | // List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | // for (Long taskId : taskIds) { |
| | | // Task task = taskService.getById(taskId); |
| | | // if (task.getOriLoc().equals(loc.getId())) { |
| | | // |
| | | // Action action = actionService.getOne(new LambdaQueryWrapper<Action>() |
| | | // .eq(Action::getTaskId, task.getId()) |
| | | // .eq(Action::getActionType, ActionTypeType.ReadyTakeFromShelvesLoc.val()) |
| | | // .eq(Action::getActionSts, ActionStsType.ISSUED.val()) |
| | | // ); |
| | | // if (null != action) { |
| | | // action.setActionSts(ActionStsType.FINISH.val()); |
| | | // action.setEndTime(now); |
| | | // action.setUpdateTime(now); |
| | | // if (!actionService.updateById(action)) { |
| | | // log.error("Action [{}] 更新失败 !!!", action.getPriority() + " - " + action.getName()); |
| | | // } |
| | | // } |
| | | // report(task, TaskReportStsType.OTBIN); |
| | | // } |
| | | // } |
| | | // } |
| | | List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | for (Long taskId : taskIds) { |
| | | Task task = taskService.getById(taskId); |
| | | report(task, agv_11_up.getQrCode(), TaskReportStsType.OTBIN); |
| | | } |
| | | |
| | | List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | for (Long taskId : taskIds) { |
| | | Task task = taskService.getById(taskId); |
| | | if (task.getOriLoc().equals(loc.getId())) { |
| | | |
| | | Action action = actionService.getOne(new LambdaQueryWrapper<Action>() |
| | | .eq(Action::getTaskId, task.getId()) |
| | | .eq(Action::getActionType, ActionTypeType.ReadyTakeFromShelvesLoc.val()) |
| | | .eq(Action::getActionSts, ActionStsType.ISSUED.val()) |
| | | ); |
| | | if (null != action) { |
| | | action.setActionSts(ActionStsType.FINISH.val()); |
| | | action.setEndTime(now); |
| | | action.setUpdateTime(now); |
| | | if (!actionService.updateById(action)) { |
| | | log.error("Action [{}] 更新失败 !!!", action.getPriority() + " - " + action.getName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //从输送线取货完成 |
| | | 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) { |
| | | Task task = taskService.getById(taskId); |
| | | report(task, agv_11_up.getQrCode(), TaskReportStsType.OTBIN); |
| | | } |
| | | } |
| | | //往输送线放货完成 |
| | | 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) { |
| | | Task task = taskService.getById(taskId); |
| | | report(task, agv_11_up.getQrCode(), TaskReportStsType.END); |
| | | } |
| | | } |
| | | |
| | |
| | | log.info("Agv [{}] 料仓信息包 ===>> {}", protocol.getAgvNo(), JSON.toJSONString(agv_70_up)); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | public void settleSegmentList(List<Segment> segmentList, String serialNo) { |
| | |
| | | task.setUpdateTime(now); |
| | | if (!taskService.updateById(task)) { |
| | | log.error("Task [{}] 更新失败 !!!", task.getSeqNum()); |
| | | } else { |
| | | log.info("Task [{}] 作业完毕 ==========>> ", task.getSeqNum()); |
| | | // TODO 插入一条上报记录 |
| | | TaskReport taskReport = new TaskReport(); |
| | | taskReport.setAgvId(task.getAgvId()); |
| | | taskReport.setBusNo(task.getBusId$()); |
| | | taskReport.setCreateTime(new Date()); |
| | | taskReport.setDestLoc(task.getDestLoc()); |
| | | taskReport.setDestSta(task.getDestSta()); |
| | | taskReport.setSeqNum(task.getSeqNum()); |
| | | taskReport.setTaskSts(task.getTaskSts()); |
| | | taskReport.setOriLoc(task.getOriLoc()); |
| | | taskReport.setOriSta(task.getOriSta()); |
| | | taskReport.setZpallet(task.getZpallet()); |
| | | if (!taskReportService.save(taskReport)) { |
| | | log.info("TaskReport [{}] 插入失败 ==========>> ", JSON.toJSONString(taskReport)); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | segmentService.processNext(segmentList); |
| | | } |
| | | |
| | | /** |
| | | * 上报给上游系统,就是插入一条数据到上报表 |
| | | */ |
| | | private void report(Task task, String qrCode, TaskReportStsType taskReportStsType) { |
| | | // TODO 插入一条上报记录 |
| | | 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)); |
| | | if (!Cools.isEmpty(list)) { |
| | | log.info("TaskReport [{}] 已重复,不再插入 ==========>> ", JSON.toJSONString(task)); |
| | | return; |
| | | } |
| | | TaskReport taskReport = new TaskReport(); |
| | | taskReport.setAgvId(task.getAgvId()); |
| | | taskReport.setBusNo(task.getBusId$()); |
| | | taskReport.setCreateTime(new Date()); |
| | | taskReport.setQrCode(qrCode); |
| | | taskReport.setReportTimes(0); |
| | | taskReport.setTaskSts(taskReportStsType.status); |
| | | taskReport.setSeqNum(task.getSeqNum()); |
| | | taskReport.setZpallet(task.getZpallet()); |
| | | if (!taskReportService.save(taskReport)) { |
| | | log.info("TaskReport [{}] 插入失败 ==========>> ", JSON.toJSONString(taskReport)); |
| | | } else { |
| | | log.info("Task [{}] 状态记录插入数据库 ==========>> ", task.getSeqNum()); |
| | | } |
| | | } |
| | | |
| | | private boolean askSta(Integer askType, String askSta) { |
| | | log.info("来询问输送线了,{},{}", askType, askSta); |
| | | String wmsUrl = configService.getVal("WMS_URL", String.class); |
| | | String wmsPath = configService.getVal("WMS_STA", String.class); |
| | | if (Cools.isEmpty(wmsPath) || Cools.isEmpty(wmsUrl)) { |
| | | return true; |
| | | } |
| | | Integer time = configService.getVal("TIMEOUT", Integer.class, 5); |
| | | //Integer times = configService.getVal("REPORT_TIMES", Integer.class, 2); |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("askType", askType); |
| | | data.put("askSta", askSta); |
| | | String response = null; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath(wmsPath) |
| | | .setTimeout(time, TimeUnit.SECONDS) |
| | | .setJson(JSON.toJSONString(data)) |
| | | .build() |
| | | .doPost(); |
| | | log.info("返回参数:{}", response); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | return true; |
| | | } |
| | | } catch (IOException e) { |
| | | log.info("报错了,{}", e); |
| | | } |
| | | return false; |
| | | } |
| | | } |