| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | destSta = staService.getById(task.getDestSta()); |
| | | if (locStaStatusCheck && !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 (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); |
| | |
| | | break; |
| | | case STA_TO_STA: |
| | | oriSta = staService.getById(task.getOriSta()); |
| | | 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); |
| | |
| | | } |
| | | |
| | | destSta = staService.getById(task.getDestSta()); |
| | | if (locStaStatusCheck && !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); |
| | | 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); |
| | |
| | | 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()); |
| | |
| | | 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; |
| | | } |
| | | } |