From dd935964238082bb5389a1bcce59e7b2bbda5f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E7=8E=AE?= Date: Thu, 12 Oct 2023 18:03:44 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E8=87=AA=E5=8A=A8=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=BB=99=E5=B7=A5AGV=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nl/acs/agv/server/XianGongAgvService.java | 2 +- .../server/impl/XianGongAgvServiceImpl.java | 8 +- .../quartz/task/QueryXZAgvTaskStatus.java | 84 +++++++++++++++++++ 3 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java index a391330..f3c2056 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java @@ -45,7 +45,7 @@ public interface XianGongAgvService { */ public HttpResponse queryXZAgvDeviceStatus(); - public HttpResponse queryXZAgvInstStatus(String instCode); + public HttpResponse queryXZAgvInstStatus(); /** * 删除先知任务 diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java index 0252675..f393f11 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java @@ -180,19 +180,17 @@ public class XianGongAgvServiceImpl implements XianGongAgvService { @LokiLog(type = LokiLogType.AGV) @Override - public HttpResponse queryXZAgvInstStatus(String instCode) { - + public HttpResponse queryXZAgvInstStatus() { if (StrUtil.equals(paramService.findByCode(AcsConfig.FORKAGV).getValue(), "1")) { String agvurl = paramService.findByCode(AcsConfig.AGVURL).getValue(); String agvport = paramService.findByCode(AcsConfig.AGVPORT).getValue(); - agvurl = agvurl + ":" + agvport + "/api/route/transportOrders/" + instCode; + agvurl = agvurl + ":" + agvport + "/orders?page=1&size=9999"; HttpResponse result = HttpRequest.get(agvurl) .timeout(20000)//超时,毫秒 .execute(); - System.out.println("查询agv指令数据:" + result.body()); - + log.info("queryXZAgvInstStatus----查询agv指令数据:{}" + result.body()); return result; } else { diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java new file mode 100644 index 0000000..27556e7 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java @@ -0,0 +1,84 @@ +package org.nl.modules.quartz.task; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.XianGongAgvService; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.task.service.TaskService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 查询AGV任务状态 + */ +@Slf4j +@Component +public class QueryXZAgvTaskStatus { + + @Autowired + InstructionService instructionService; + + @Autowired + XianGongAgvService agvService; + + @Autowired + AcsToWmsService acsToWmsService; + + @Autowired + TaskService taskService; + + public void run() throws Exception { + + HttpResponse response = agvService.queryXZAgvInstStatus(); + JSONObject jo = JSONArray.parseObject(response.body()); + + JSONArray ja = JSONArray.parseArray(jo.getString("list")); + for (int i = 0; i < ja.size(); i++) { + JSONObject one = (JSONObject) ja.get(i); + String inst_code = one.getString("id"); + Instruction inst = instructionService.findByCodeFromCache(inst_code); + if (ObjectUtil.isEmpty(inst)) + continue; + + String state = one.getString("state"); + if (!StrUtil.isEmpty(one.getString("vehicle"))) { + String carno = one.getString("vehicle"); + inst.setCarno(carno); + } + +// 已创建=CREATED, +// 待分配=TOBEDISPATCHED, +// 正在执行=RUNNING, +// 完成=FINISHED, +// 失败=FAILED(主动失败), +// 终止=STOPPED(被人为终止), +// 无法执行=Error(参数错误), +// 等待=WAITING + + //执行中 + if ("RUNNING".equals(state) || "CREATED".equals(state) || "TOBEDISPATCHED".equals(state) || "WAITING".equals(state)) { + if (inst != null) { + inst.setInstruction_status("1"); + instructionService.update(inst); + } + } else if ("FINISHED".equals(state)) { + if (inst != null) { + inst.setInstruction_status("2"); + instructionService.finish(inst); + } + } else if ("STOPPED".equals(state) || "FAILED".equals(state) || "Error".equals(state)) { + if (inst != null) { + inst.setInstruction_status("1"); + instructionService.update(inst); + } + } + } + + } +}