From 2576d9132f2f05ac1b8a7bb5aa768cbe93b8671d Mon Sep 17 00:00:00 2001 From: liyongde <1419499670@qq.com> Date: Wed, 14 Jun 2023 16:12:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AF=B9=E6=8E=A5acs=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/common/utils/PointUpdateUtil.java | 4 +- .../wms/cockpit/service/enums/DeviceEnum.java | 19 ++- .../service/enums/DeviceStatusEnum.java | 16 +- .../service/impl/BigScreenServiceImpl.java | 145 +++++++++++++++--- .../org/nl/wms/cockpit/wql/COCKPIT_DEVICE.wql | 15 ++ .../wql/COCKPIT_PROCESS_PRODUCTION.wql | 2 +- 6 files changed, 166 insertions(+), 35 deletions(-) diff --git a/lms/nladmin-system/src/main/java/org/nl/modules/common/utils/PointUpdateUtil.java b/lms/nladmin-system/src/main/java/org/nl/modules/common/utils/PointUpdateUtil.java index eab7ed0..9d4eca7 100644 --- a/lms/nladmin-system/src/main/java/org/nl/modules/common/utils/PointUpdateUtil.java +++ b/lms/nladmin-system/src/main/java/org/nl/modules/common/utils/PointUpdateUtil.java @@ -64,6 +64,7 @@ public class PointUpdateUtil { /** * 访问acs获取点位数据更新点位信息: * 分拣呼叫空托盘、空钢托盘叠盘架 + * * @param pointCodes * @deprecated 只更新点位状态和载具类型 */ @@ -136,11 +137,12 @@ public class PointUpdateUtil { /** * 查找设备状态 + * * @return */ public static JSONObject getDevicesStatus(JSONArray deviceCode) { WmsToAcsServiceImpl wmsToAcsService = new WmsToAcsServiceImpl(); JSONObject deviceStatus = wmsToAcsService.getDeviceStatus(deviceCode); - return ObjectUtil.isNotEmpty(deviceStatus)?deviceStatus:null; + return ObjectUtil.isNotEmpty(deviceStatus) ? deviceStatus : null; } } diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/enums/DeviceEnum.java b/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/enums/DeviceEnum.java index 6ec7748..a45a8a9 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/enums/DeviceEnum.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/enums/DeviceEnum.java @@ -11,11 +11,12 @@ import lombok.Getter; @Getter @AllArgsConstructor public enum DeviceEnum { - HL(0, "混料"), - YZ(1, "压制"), - GZ(2, "干燥"), - BZ(3, "包装"); + HL(0, "HL", "混料"), + YZ(1, "YZ", "压制"), + GZ(2, "SZ", "干燥"), + BZ(3, "FJ", "包装"); private final int index; + private final String code; private final String device_name; public static DeviceEnum getDeviceEnumByIndex(int index) { @@ -27,4 +28,14 @@ public enum DeviceEnum { } return null; // 如果没有找到对应的枚举常量,可以根据需要返回null或者抛出异常 } + + public static DeviceEnum getDeviceEnumByCode(String code) { + DeviceEnum[] enums = DeviceEnum.values(); + for (DeviceEnum deviceEnum : enums) { + if (deviceEnum.getCode().equals(code)) { + return deviceEnum; + } + } + return null; // 如果没有找到对应的枚举常量,可以根据需要返回null或者抛出异常 + } } diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/enums/DeviceStatusEnum.java b/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/enums/DeviceStatusEnum.java index 8949f2a..11fc4b3 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/enums/DeviceStatusEnum.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/enums/DeviceStatusEnum.java @@ -6,11 +6,12 @@ package org.nl.wms.cockpit.service.enums; * @Date: 2023/3/10 */ public enum DeviceStatusEnum { - STANDBY(1, "待机"), - RUNNING(2, "运行中"), - FAILURE(3, "故障"), - SHUTDOWN(0, "关机"); + STANDBY(1, "standby", "待机"), + RUNNING(2, "running", "运行中"), + FAILURE(3, "failure", "故障"), + SHUTDOWN(0, "shutdown", "关机"); private final Integer code; + private final String name; private final String description; public static DeviceStatusEnum getDeviceStatusEnumByCode(int index) { @@ -23,8 +24,9 @@ public enum DeviceStatusEnum { return null; // 如果没有找到对应的枚举常量,可以根据需要返回null或者抛出异常 } - DeviceStatusEnum(Integer code, String description) { + DeviceStatusEnum(Integer code, String name, String description) { this.code = code; + this.name = name; this.description = description; } @@ -32,6 +34,10 @@ public enum DeviceStatusEnum { return code; } + public String getName() { + return name; + } + public String getDescription() { return description; } diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/impl/BigScreenServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/impl/BigScreenServiceImpl.java index 19df591..1d792d1 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/impl/BigScreenServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/service/impl/BigScreenServiceImpl.java @@ -4,9 +4,11 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.config.thread.ThreadPoolExecutorUtil; +import org.nl.modules.common.utils.PointUpdateUtil; import org.nl.modules.wql.WQL; import org.nl.modules.wql.core.bean.WQLObject; import org.nl.wms.cockpit.service.BigScreenService; @@ -114,17 +116,46 @@ public class BigScreenServiceImpl implements BigScreenService { map.put("CPDayList", null); return null; }); - // TODO: 4、设备运行情况 + // 4、设备运行情况 CompletableFuture> deviceConditionTask = CompletableFuture.supplyAsync(() -> { List res = new ArrayList<>(); - for (int i = 0; i < 4; i++) { - DeviceEnum deviceEnumByIndex = DeviceEnum.getDeviceEnumByIndex(i); + // 获取所有设备 + JSONArray result = WQL.getWO("COCKPIT_DEVICE") + .addParam("flag", "4") + .process() + .getResultJSONArray(0); + // TODO: 打开ACS系统对接数据 +// JSONObject devicesStatus = PointUpdateUtil.getDevicesStatus(result); +// JSONArray data = ObjectUtil.isNotEmpty( +// devicesStatus.getJSONArray("data")) ? devicesStatus.getJSONArray("data") : result; + JSONArray data = result; + // 初始化数据 数组下标:0关机 1待机 2生产中 3故障 + JSONObject total = new JSONObject(); + DeviceEnum[] values = DeviceEnum.values(); + for (int i = 0; i < values.length; i++) { + total.put(values[i].getCode(), new int[4]); + } + // 遍历判断 + for (int i = 0; i < data.size(); i++) { + JSONObject device = data.getJSONObject(i); + Integer devicesStatus1 = ObjectUtil.isNotEmpty(device.getInteger("devices_status")) + ? device.getInteger("devices_status") + : 0; + String regionCode = device.getString("region_code"); + DeviceEnum deviceEnumByCode = DeviceEnum.getDeviceEnumByCode(regionCode); // 获取属于哪种设备 + int[] ints = (int[]) total.get(deviceEnumByCode.getCode()); + ints[devicesStatus1] = ints[devicesStatus1] + 1; + total.put(deviceEnumByCode.getCode(), ints); + } + // 返回输出值 + for (int i = 0; i < values.length; i++) { // 4个 + int[] ints = (int[]) total.get(values[i].getCode()); OperationConditionDto dto = new OperationConditionDto(); - dto.setDevice_name(deviceEnumByIndex.getDevice_name()); - dto.setRunning(3); - dto.setFailure(5); - dto.setShutdown(2); - dto.setStandby(6); + dto.setDevice_name(values[i].getDevice_name()); // 列名 + dto.setRunning(ints[2]); + dto.setFailure(ints[3]); + dto.setShutdown(ints[0]); + dto.setStandby(ints[1]); res.add(dto); } return res; @@ -182,21 +213,24 @@ public class BigScreenServiceImpl implements BigScreenService { .addParamMap(MapOf.of("flag", "5", "region_code", "YZ")) .process() .getResultJSONArray(0); - return res; - }, pool); - stackingPositionTask.thenAccept(result -> { // TODO: 颜色、实时数量请求acs系统 - for (int i = 0; i < result.size(); i++) { - JSONObject jsonObject = result.getJSONObject(i); +// JSONObject devicesStatus = PointUpdateUtil.getDevicesStatus(res); +// JSONArray data = ObjectUtil.isNotEmpty( +// devicesStatus.getJSONArray("data")) ? devicesStatus.getJSONArray("data") : res; + for (int i = 0; i < res.size(); i++) { + JSONObject jsonObject = res.getJSONObject(i); jsonObject.put("color_status", ColorEnum.RED.getIndex()); } + return res; + }, pool); + stackingPositionTask.thenAccept(result -> { map.put("StackingPositionList", result); }).exceptionally((e) -> { log.error("码垛位情况显示: {}", e.getMessage(), e); map.put("StackingPositionList", null); return null; }); - // 8、压机信息显示 todo: 压机的状态,请求acs + // 8、压机信息显示 CompletableFuture pressMachineTask = CompletableFuture.supplyAsync(() -> { JSONArray res = WQL.getWO("COCKPIT_PROCESS_PRODUCTION") .addParamMap(MapOf.of("flag", "10")) @@ -207,6 +241,10 @@ public class BigScreenServiceImpl implements BigScreenService { jsonObject.put("device_status", DeviceStatusEnum.STANDBY.getCode()); jsonObject.put("open_time", DateUtil.now()); } + // todo: 打开ACS系统对接数据 +// JSONObject devicesStatus = PointUpdateUtil.getDevicesStatus(res); +// JSONArray data = ObjectUtil.isNotEmpty( +// devicesStatus.getJSONArray("data")) ? devicesStatus.getJSONArray("data") : res; return res; }, pool); pressMachineTask.thenAccept(result -> { @@ -216,7 +254,7 @@ public class BigScreenServiceImpl implements BigScreenService { map.put("PressMachineList", null); return null; }); - // 9、混料机信息显示 todo: 设备状态,请求acs + // 9、混料机信息显示 CompletableFuture mixMachineTask = CompletableFuture.supplyAsync(() -> { JSONArray res = WQL.getWO("COCKPIT_PROCESS_PRODUCTION") .addParamMap(MapOf.of("flag", "11")) @@ -227,6 +265,10 @@ public class BigScreenServiceImpl implements BigScreenService { jsonObject.put("device_status", DeviceStatusEnum.STANDBY.getCode()); jsonObject.put("open_time", DateUtil.now()); } + // todo: 打开ACS系统对接数据 +// JSONObject devicesStatus = PointUpdateUtil.getDevicesStatus(res); +// JSONArray data = ObjectUtil.isNotEmpty( +// devicesStatus.getJSONArray("data")) ? devicesStatus.getJSONArray("data") : res; return res; }, pool); mixMachineTask.thenAccept(result -> { @@ -302,11 +344,14 @@ public class BigScreenServiceImpl implements BigScreenService { .addParamMap(MapOf.of("flag", "13")) .process() .getResultJSONArray(0); - // TODO: 颜色、实时数量请求acs系统 for (int i = 0; i < res.size(); i++) { JSONObject jsonObject = res.getJSONObject(i); jsonObject.put("color_status", ColorEnum.RED.getIndex()); } + // TODO: 打开ACS系统对接数据 +// JSONObject devicesStatus = PointUpdateUtil.getDevicesStatus(res); +// JSONArray data = ObjectUtil.isNotEmpty( +// devicesStatus.getJSONArray("data")) ? devicesStatus.getJSONArray("data") : res; return res; }, pool); sortAndPalletizingTask.thenAccept(result -> { @@ -340,6 +385,7 @@ public class BigScreenServiceImpl implements BigScreenService { /** * 工序生产 + * * @return */ @Override @@ -375,7 +421,7 @@ public class BigScreenServiceImpl implements BigScreenService { BigDecimal.valueOf(sumPlanDay / 1000).setScale(2, RoundingMode.HALF_UP).toString()); res.put("hl_real_day", BigDecimal.valueOf(sumRealDay / 1000).setScale(2, RoundingMode.HALF_UP).toString()); - res.put("hl_productivity", (int)((sumRealDay / sumPlanDay)*100)); + res.put("hl_productivity", (int) ((sumRealDay / sumPlanDay) * 100)); res.put("HLDayList", result); if (map.containsKey("HL")) { // 如果存在 JSONObject hl = (JSONObject) map.get("HL"); @@ -475,7 +521,7 @@ public class BigScreenServiceImpl implements BigScreenService { BigDecimal.valueOf(sumPlanDay / 10000).setScale(2, RoundingMode.HALF_UP).toString()); res.put("yz_real_day", BigDecimal.valueOf(sumRealDay / 10000).setScale(2, RoundingMode.HALF_UP).toString()); - res.put("yz_productivity", (int)((sumRealDay / sumPlanDay)*100)); + res.put("yz_productivity", (int) ((sumRealDay / sumPlanDay) * 100)); res.put("YZDayList", result); if (map.containsKey("YZ")) { // 如果存在 JSONObject yz = (JSONObject) map.get("YZ"); @@ -572,7 +618,7 @@ public class BigScreenServiceImpl implements BigScreenService { } res.put("bz_plan_day", BigDecimal.valueOf(sumPlanDay / 10000).setScale(2, RoundingMode.HALF_UP).toString()); res.put("bz_real_day", BigDecimal.valueOf(sumRealDay / 10000).setScale(2, RoundingMode.HALF_UP).toString()); - res.put("bz_productivity", (int)((sumRealDay / sumPlanDay)*100)); + res.put("bz_productivity", (int) ((sumRealDay / sumPlanDay) * 100)); res.put("BZDayList", result); if (map.containsKey("BZ")) { // 如果存在 JSONObject bz = (JSONObject) map.get("BZ"); @@ -736,10 +782,22 @@ public class BigScreenServiceImpl implements BigScreenService { CompletableFuture mixDevicePopoverInformationTask = CompletableFuture.supplyAsync(() -> { JSONArray res = WQL.getWO("COCKPIT_MIX_AND_TRAP").addParamMap(MapOf.of("flag", "2")) .process().getResultJSONArray(0); + // todo: 打开ACS系统对接数据 +// JSONObject devicesStatus = PointUpdateUtil.getDevicesStatus(res); +// JSONArray data = ObjectUtil.isNotEmpty( +// devicesStatus.getJSONArray("data")) ? devicesStatus.getJSONArray("data") : res; +// for (int i = 0; i < data.size(); i++) { +// JSONObject device = data.getJSONObject(i); +// Integer devicesStatus1 = ObjectUtil.isNotEmpty(device.getInteger("devices_status")) +// ? device.getInteger("devices_status") +// : 0; +// DeviceStatusEnum deviceStatusEnumByCode = DeviceStatusEnum.getDeviceStatusEnumByCode(devicesStatus1); +// device.put("device_status_name", deviceStatusEnumByCode.getDescription()); +// } return res; }, pool); mixDevicePopoverInformationTask.thenAccept(result -> { - //todo: 请求acs设置开机状态等等信息 + //todo: 以下代码去掉 for (int i = 0; i < result.size(); i++) { JSONObject device = result.getJSONObject(i); if (!device.getString("material_code").equals("-")) { @@ -869,10 +927,21 @@ public class BigScreenServiceImpl implements BigScreenService { CompletableFuture pressPopoverTask = CompletableFuture.supplyAsync(() -> { JSONArray res = WQL.getWO("COCKPIT_MOLDING_INFO").addParamMap(MapOf.of("flag", "4")) .process().getResultJSONArray(0); + // todo: 打开ACS系统对接数据 +// JSONObject devicesStatus = PointUpdateUtil.getDevicesStatus(res); +// JSONArray data = ObjectUtil.isNotEmpty( +// devicesStatus.getJSONArray("data")) ? devicesStatus.getJSONArray("data") : res; +// for (int i = 0; i < data.size(); i++) { +// JSONObject device = data.getJSONObject(i); +// Integer devicesStatus1 = ObjectUtil.isNotEmpty(device.getInteger("devices_status")) +// ? device.getInteger("devices_status") +// : 0; +// DeviceStatusEnum deviceStatusEnumByCode = DeviceStatusEnum.getDeviceStatusEnumByCode(devicesStatus1); +// device.put("device_status_name", deviceStatusEnumByCode.getDescription()); return res; }, pool); pressPopoverTask.thenAccept(result -> { - //todo: 请求acs获取开机状态等等信息 + //todo: 以下代码去掉 for (int i = 0; i < result.size(); i++) { JSONObject device = result.getJSONObject(i); if (!device.getString("material_code").equals("-")) { @@ -897,10 +966,13 @@ public class BigScreenServiceImpl implements BigScreenService { return null; }); // 2、码盘工位弹出框 - CompletableFuture trayStationPopoverTask = CompletableFuture.supplyAsync(() -> { + CompletableFuture trayStationPopoverTask = CompletableFuture.supplyAsync(() -> { JSONArray res = WQL.getWO("COCKPIT_MOLDING_INFO").addParamMap(MapOf.of("flag", "5")) .process().getResultJSONArray(0); // todo: request acs to find device status and other information +// JSONObject devicesStatus = PointUpdateUtil.getDevicesStatus(res); +// JSONArray data = ObjectUtil.isNotEmpty( +// devicesStatus.getJSONArray("data")) ? devicesStatus.getJSONArray("data") : res; return res; }, pool); trayStationPopoverTask.thenAccept(result -> { @@ -910,10 +982,22 @@ public class BigScreenServiceImpl implements BigScreenService { map.put("TrayStationPopoverList", null); return null; }); - // 3、机械手状态 todo + // 3、机械手状态 CompletableFuture manipulatorConditionTask = CompletableFuture.supplyAsync(() -> { JSONArray res = WQL.getWO("COCKPIT_MOLDING_INFO").addParamMap(MapOf.of("flag", "6")) .process().getResultJSONArray(0); +// JSONObject devicesStatus = PointUpdateUtil.getDevicesStatus(res); +// JSONArray data = ObjectUtil.isNotEmpty( +// devicesStatus.getJSONArray("data")) ? devicesStatus.getJSONArray("data") : res; +// for (int i = 0; i < data.size(); i++) { +// JSONObject device = data.getJSONObject(i); +// Integer devicesStatus1 = ObjectUtil.isNotEmpty(device.getInteger("devices_status")) +// ? device.getInteger("devices_status") +// : 0; +// DeviceStatusEnum deviceStatusEnumByCode = DeviceStatusEnum.getDeviceStatusEnumByCode(devicesStatus1); +// device.put("device_status_name", deviceStatusEnumByCode.getDescription()); +// } + // todo 去掉以下代码 for (int i = 0; i < res.size(); i++) { JSONObject device = res.getJSONObject(i); device.put("device_status", DeviceStatusEnum.RUNNING.getCode()); @@ -1172,7 +1256,7 @@ public class BigScreenServiceImpl implements BigScreenService { return res; }, pool); manufacturedProductsDayProductionTask.thenAccept((result) -> { - map.put("CPDayList", result); + map.put("CPDayList", result); }).exceptionally((e) -> { log.error("当日成品生产: {}", e.getMessage(), e); map.put("CPDayList", null); @@ -1215,6 +1299,19 @@ public class BigScreenServiceImpl implements BigScreenService { JSONArray res = WQL.getWO("COCKPIT_SORTE_AND_PACKAGE").addParamMap(MapOf.of("flag", "5")) .process().getResultJSONArray(0); // todo: 向acs申请获取 +// JSONObject devicesStatus = PointUpdateUtil.getDevicesStatus(res); +// JSONArray data = ObjectUtil.isNotEmpty( +// devicesStatus.getJSONArray("data")) ? devicesStatus.getJSONArray("data") : res; +// for (int i = 0; i < data.size(); i++) { +// JSONObject device = data.getJSONObject(i); +// Integer devicesStatus1 = ObjectUtil.isNotEmpty(device.getInteger("devices_status")) +// ? device.getInteger("devices_status") +// : 0; +// DeviceStatusEnum deviceStatusEnumByCode = DeviceStatusEnum.getDeviceStatusEnumByCode(devicesStatus1); +// device.put("device_status_name", deviceStatusEnumByCode.getDescription()); +// resObj.put(device.getString("device_code"), device); +// } + // todo 去掉以下代码 for (int i = 0; i < res.size(); i++) { JSONObject device = res.getJSONObject(i); device.put("device_status", DeviceStatusEnum.RUNNING.getCode()); diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/wql/COCKPIT_DEVICE.wql b/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/wql/COCKPIT_DEVICE.wql index 2d56dd0..60505b6 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/wql/COCKPIT_DEVICE.wql +++ b/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/wql/COCKPIT_DEVICE.wql @@ -87,3 +87,18 @@ ENDSELECT ENDPAGEQUERY ENDIF + + IF 输入.flag = "4" + PAGEQUERY + SELECT + d.device_code, + d.device_name, + d.region_code, + 0 AS devices_status + FROM + `pdm_bi_device` d + WHERE d.region_code IN ('YZ','HL','SZ','FJ') + ORDER BY d.region_code, d.device_code + ENDSELECT + ENDPAGEQUERY + ENDIF diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/wql/COCKPIT_PROCESS_PRODUCTION.wql b/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/wql/COCKPIT_PROCESS_PRODUCTION.wql index 80595a9..75de032 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/wql/COCKPIT_PROCESS_PRODUCTION.wql +++ b/lms/nladmin-system/src/main/java/org/nl/wms/cockpit/wql/COCKPIT_PROCESS_PRODUCTION.wql @@ -126,7 +126,7 @@ IF 输入.flag = "5" PAGEQUERY SELECT - point_code, + point_code AS device_code, point_name, region_code FROM