diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/nl4/station/NL4StationDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/nl4/station/NL4StationDeviceDriver.java index f5614e3..9b44b8e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/nl4/station/NL4StationDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/nl4/station/NL4StationDeviceDriver.java @@ -212,7 +212,7 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D } @NotNull - public TaskDto creatTask(Device device1, Device device2, Device device3, Device device4, RequestMethodEnum method) { + private TaskDto creatTask(Device device1, Device device2, Device device3, Device device4, RequestMethodEnum method) { JSONObject rpUpdate = new JSONObject(); rpUpdate.put("islock", "1"); rpUpdate.put("update_by", "auto"); @@ -241,6 +241,26 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D return task.toJavaObject(TaskDto.class); } + private Device findHasGoodsDevice(JSONArray deviceCodes) { + for (int i = 0; i < deviceCodes.size(); i++) { + Device device = this.deviceAppService.findDeviceByCode(deviceCodes.getString(i)); + if ("0".equals(device.getIslock()) && 1 == device.getHas_goods()) { + return device; + } + } + return null; + } + + private Device findNotHasGoodsDevice(JSONArray deviceCodes) { + for (int i = 0; i < deviceCodes.size(); i++) { + Device device = this.deviceAppService.findDeviceByCode(deviceCodes.getString(i)); + if ("0".equals(device.getIslock()) && 0 == device.getHas_goods()) { + return device; + } + } + return null; + } + /** * 门架上料完成 */ @@ -268,15 +288,7 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D JSONArray materialDeviceCodes = JSONArray.parseArray(gantryDeviceCode2.toString()); // 查找合适的放空设备 - Device emptyDevice = null; - for (int i = 0; i < emptyDeviceCodes.size(); i++) { - String deviceCode = emptyDeviceCodes.getString(i); - Device device = deviceAppService.findDeviceByCode(deviceCode); - if ("0".equals(device.getIslock()) && 0 == device.getHas_goods()) { - emptyDevice = device; - break; - } - } + Device emptyDevice = this.findNotHasGoodsDevice(emptyDeviceCodes); if (ObjectUtil.isEmpty(emptyDevice)) { String message = "未找到合适的门架上料完成放空设备。"; this.message = message; @@ -286,15 +298,7 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D assert emptyDevice != null; // 查找合适的取满设备 - Device materialDevice = null; - for (int i = 0; i < materialDeviceCodes.size(); i++) { - String deviceCode = materialDeviceCodes.getString(i); - Device device = deviceAppService.findDeviceByCode(deviceCode); - if ("0".equals(device.getIslock()) && 1 == device.getHas_goods()) { - materialDevice = device; - break; - } - } + Device materialDevice = this.findHasGoodsDevice(materialDeviceCodes); if (ObjectUtil.isEmpty(materialDevice)) { String message = "未找到合适的门架上料完成取满设备。"; this.message = message; @@ -343,15 +347,7 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D JSONArray deviceCodes4 = JSONArray.parseArray(channelSteelDeviceCode4.toString()); // 查找合适的取满设备 - Device device1 = null; - for (int i = 0; i < deviceCodes1.size(); i++) { - String deviceCode = deviceCodes1.getString(i); - Device device = deviceAppService.findDeviceByCode(deviceCode); - if ("0".equals(device.getIslock()) && 1 == device.getHas_goods()) { - device1 = device; - break; - } - } + Device device1 = this.findHasGoodsDevice(deviceCodes1); if (ObjectUtil.isEmpty(device1)) { String message = "未找到合适的槽钢上料完成取满设备。"; this.message = message; @@ -361,15 +357,7 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D assert device1 != null; // 查找合适的放满设备 - Device device2 = null; - for (int i = 0; i < deviceCodes2.size(); i++) { - String deviceCode = deviceCodes2.getString(i); - Device device = deviceAppService.findDeviceByCode(deviceCode); - if ("0".equals(device.getIslock()) && 0 == device.getHas_goods()) { - device2 = device; - break; - } - } + Device device2 = this.findNotHasGoodsDevice(deviceCodes2); if (ObjectUtil.isEmpty(device2)) { String message = "未找到合适的槽钢上料完成放满设备。"; this.message = message; @@ -379,15 +367,7 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D assert device2 != null; // 查找合适的放空设备 - Device device4 = null; - for (int i = 0; i < deviceCodes4.size(); i++) { - String deviceCode = deviceCodes4.getString(i); - Device device = deviceAppService.findDeviceByCode(deviceCode); - if ("0".equals(device.getIslock()) && 0 == device.getHas_goods()) { - device4 = device; - break; - } - } + Device device4 = this.findNotHasGoodsDevice(deviceCodes4); if (ObjectUtil.isEmpty(device4)) { String message = "未找到合适的槽钢上料完成放空设备。"; this.message = message; @@ -436,15 +416,7 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D JSONArray deviceCodes4 = JSONArray.parseArray(channelSteelCallMaterialDeviceCode4.toString()); // 查找合适的取满设备 - Device device1 = null; - for (int i = 0; i < deviceCodes1.size(); i++) { - String deviceCode = deviceCodes1.getString(i); - Device device = deviceAppService.findDeviceByCode(deviceCode); - if ("0".equals(device.getIslock()) && 1 == device.getHas_goods()) { - device1 = device; - break; - } - } + Device device1 = this.findHasGoodsDevice(deviceCodes1); if (ObjectUtil.isEmpty(device1)) { String message = "未找到合适的槽钢呼叫满料取满设备。"; this.message = message; @@ -454,15 +426,7 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D assert device1 != null; // 查找合适的取空设备 - Device device3 = null; - for (int i = 0; i < deviceCodes3.size(); i++) { - String deviceCode = deviceCodes3.getString(i); - Device device = deviceAppService.findDeviceByCode(deviceCode); - if ("0".equals(device.getIslock()) && 1 == device.getHas_goods()) { - device3 = device; - break; - } - } + Device device3 = this.findHasGoodsDevice(deviceCodes3); if (ObjectUtil.isEmpty(device3)) { String message = "未找到合适的槽钢呼叫满料取空设备。"; this.message = message; @@ -472,15 +436,7 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D assert device3 != null; // 查找合适的放空设备 - Device device4 = null; - for (int i = 0; i < deviceCodes4.size(); i++) { - String deviceCode = deviceCodes4.getString(i); - Device device = deviceAppService.findDeviceByCode(deviceCode); - if ("0".equals(device.getIslock()) && 0 == device.getHas_goods()) { - device4 = device; - break; - } - } + Device device4 = this.findNotHasGoodsDevice(deviceCodes4); if (ObjectUtil.isEmpty(device4)) { String message = "未找到合适的槽钢呼叫满料放空设备。"; this.message = message; @@ -520,15 +476,7 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D JSONArray deviceCodes3 = JSONArray.parseArray(productionCompletedDeviceCode3.toString()); // 查找合适的放满设备 - Device device2 = null; - for (int i = 0; i < deviceCodes2.size(); i++) { - String deviceCode = deviceCodes2.getString(i); - Device device = deviceAppService.findDeviceByCode(deviceCode); - if ("0".equals(device.getIslock()) && 0 == device.getHas_goods()) { - device2 = device; - break; - } - } + Device device2 = this.findNotHasGoodsDevice(deviceCodes2); if (ObjectUtil.isEmpty(device2)) { String message = "未找到合适的下料完成放满设备。"; this.message = message; @@ -538,15 +486,7 @@ public class NL4StationDeviceDriver extends AbstractOpcDeviceDriver implements D assert device2 != null; // 查找合适的取空设备 - Device device3 = null; - for (int i = 0; i < deviceCodes3.size(); i++) { - String deviceCode = deviceCodes3.getString(i); - Device device = deviceAppService.findDeviceByCode(deviceCode); - if ("0".equals(device.getIslock()) && 1 == device.getHas_goods()) { - device3 = device; - break; - } - } + Device device3 = this.findHasGoodsDevice(deviceCodes3); if (ObjectUtil.isEmpty(device3)) { String message = "未找到合适的下料完成取空设备。"; this.message = message;