From 323868302dc3c3c1fd8b5387d924dacf4703fcb2 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Tue, 18 Nov 2025 16:28:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=BA=E6=A2=B0=E6=89=8B=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/task/DashboardPushTask.java | 179 +++++++++++++++++- 1 file changed, 176 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gaotao/modules/dashboard/task/DashboardPushTask.java b/src/main/java/com/gaotao/modules/dashboard/task/DashboardPushTask.java index c69defe..3d8f11e 100644 --- a/src/main/java/com/gaotao/modules/dashboard/task/DashboardPushTask.java +++ b/src/main/java/com/gaotao/modules/dashboard/task/DashboardPushTask.java @@ -598,9 +598,8 @@ public class DashboardPushTask { Map storageUtilization = getInventoryStatsFromWcs(); log.debug("库位利用率数据: {}", storageUtilization); - // 查询机器人状态数据 - //List> robotStatus = dashboardDao.queryWarehouseRobotStatus(); - List> robotStatus = new ArrayList<>(); + // 查询机器人状态数据(从WMS Dashboard API获取) + List> robotStatus = getRobotSortingInfoFromWms(); log.debug("查询到机器人状态数据: {}条", robotStatus != null ? robotStatus.size() : 0); // 查询AGV状态数据(从TUSK系统获取) @@ -1163,5 +1162,179 @@ public class DashboardPushTask { return (receiveList == null || receiveList.isEmpty()) && (inboundList == null || inboundList.isEmpty()); } + + /** + * 从WMS Dashboard API获取机械臂分拣信息 + * + *

数据转换说明:

+ *
    + *
  • 从WMS获取原始机械臂分拣状态
  • + *
  • 转换为看板需要的格式
  • + *
  • 映射工作模式和设备状态枚举值
  • + *
  • 1071=机械手1, 1060=机械手2
  • + *
+ * + * @return 机械臂分拣状态列表 + */ + private List> getRobotSortingInfoFromWms() { + List> robotList = new ArrayList<>(); + + try { + // 调用WMS Dashboard API(使用配置文件中的URL) + String url = wcsBoardApi + "WmsDashboard/robot-sorting-info"; + log.debug("调用WMS机械臂分拣API: {}", url); + + String wmsResponse = HttpUtils.doGet(url, null, null); + log.debug("WMS API返回数据: {}", wmsResponse); + + // 解析JSON数据 + ObjectMapper mapper = new ObjectMapper(); + JsonNode rootNode = mapper.readTree(wmsResponse); + + // 检查返回码 + int resCode = rootNode.get("resCode").asInt(); + if (resCode != 200) { + String resMsg = rootNode.has("resMsg") ? rootNode.get("resMsg").asText() : "未知错误"; + log.warn("WMS机械臂分拣API返回错误: code={}, msg={}", resCode, resMsg); + return robotList; + } + + // 获取resData.sortingStations数组 + if (!rootNode.has("resData") || !rootNode.get("resData").has("sortingStations")) { + log.warn("WMS返回数据中没有sortingStations"); + return robotList; + } + + JsonNode sortingStations = rootNode.get("resData").get("sortingStations"); + if (!sortingStations.isArray()) { + log.warn("sortingStations不是数组格式"); + return robotList; + } + + // 转换数据为看板格式 + for (JsonNode station : sortingStations) { + Map robot = new HashMap<>(); + + // 分拣站编号 + String sortingStation = station.has("sortingStation") ? station.get("sortingStation").asText() : ""; + robot.put("id", sortingStation); + + // 机械手名称映射:1071=机械手1, 1060=机械手2 + String robotName; + if ("1071".equals(sortingStation)) { + robotName = "机械手 1"; + } else if ("1060".equals(sortingStation)) { + robotName = "机械手 2"; + } else { + robotName = "机械手 " + sortingStation; + } + robot.put("name", robotName); + + // 待处理物料数量(任务数) + int pendingMaterialCount = station.has("pendingMaterialCount") ? station.get("pendingMaterialCount").asInt() : 0; + robot.put("tasks", pendingMaterialCount); + + // 工作模式(OperationMode枚举) + int workModel = station.has("workModel") ? station.get("workModel").asInt() : 0; + robot.put("workModel", workModel); + robot.put("workModelText", getWorkModelText(workModel)); + + // 设备状态(DeviceStatus枚举) + int workStatus = station.has("workStatus") ? station.get("workStatus").asInt() : 0; + robot.put("workStatus", workStatus); + robot.put("workStatusText", getWorkStatusText(workStatus)); + + // 转换为标准状态(working/idle/error/maintenance) + String status = convertRobotStatus(workModel, workStatus); + robot.put("status", status); + robot.put("statusText", getWorkStatusText(workStatus)); + + robotList.add(robot); + } + + log.info("从WMS获取到{}个机械臂分拣站状态", robotList.size()); + + } catch (Exception e) { + log.error("从WMS获取机械臂分拣数据失败", e); + } + + return robotList; + } + + /** + * 获取工作模式文本 + * + * @param workModel 工作模式枚举值 + * @return 工作模式文本 + */ + private String getWorkModelText(int workModel) { + switch (workModel) { + case 1: + return "自动模式"; + case 2: + return "半自动模式"; + case 3: + return "手动模式"; + case 4: + return "报警模式"; + case 5: + return "维护模式"; + default: + return "未定义"; + } + } + + /** + * 获取设备状态文本 + * + * @param workStatus 设备状态枚举值 + * @return 设备状态文本 + */ + private String getWorkStatusText(int workStatus) { + switch (workStatus) { + case 1: + return "空闲"; + case 2: + return "取货中"; + case 3: + return "RFID检测中"; + case 4: + return "放货中"; + case 5: + return "等待上位反馈完成"; + case 6: + return "等待流线托盘到位"; + default: + return "未定义"; + } + } + + /** + * 转换机械臂状态为标准状态 + * + * @param workModel 工作模式 + * @param workStatus 设备状态 + * @return 标准状态 (working/idle/error/maintenance) + */ + private String convertRobotStatus(int workModel, int workStatus) { + // 报警模式 + if (workModel == 4) { + return "error"; + } + + // 维护模式 + if (workModel == 5) { + return "maintenance"; + } + + // 根据设备状态判断 + if (workStatus == 1) { + return "idle"; // 空闲 + } else if (workStatus >= 2 && workStatus <= 6) { + return "working"; // 工作中 + } + + return "idle"; + } }