diff --git a/acs/nladmin-system/pom.xml b/acs/nladmin-system/pom.xml index 264114491..e02d8fb42 100644 --- a/acs/nladmin-system/pom.xml +++ b/acs/nladmin-system/pom.xml @@ -34,6 +34,11 @@ + + org.bouncycastle + bcprov-jdk15on + 1.50 + org.apache.commons diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java b/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java index e8d2c827e..6eb984a81 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java @@ -11,6 +11,7 @@ import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.instruction.service.impl.InstructionServiceImpl; +import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.opc.Device; import org.nl.acs.opc.DeviceAppService; import org.nl.modules.system.service.ParamService; @@ -74,6 +75,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { NDCAgvService NDCAgvService = SpringContextHolder.getBean(NDCAgvService.class); DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class); + DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); ip = paramService.findByCode(AcsConfig.AGVURL).getValue(); port = Integer.parseInt(paramService.findByCode(AcsConfig.AGVPORT).getValue()); @@ -129,6 +131,9 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { } if (ikey != 0) { inst = instructionService.findByCodeFromCache(String.valueOf(ikey)); + if (ObjectUtil.isEmpty(inst)){ + inst = instructionService.findByCode(String.valueOf(ikey)); + } } if (!ObjectUtil.isEmpty(link_inst)) { link_flag = true; @@ -209,6 +214,9 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { } catch (Exception e) { System.out.println("OneAgv链接异常"); log.info("OneAgv链接异常"); + log.error("agv连接出现异常:{}", e); + logServer.deviceExecuteLog("1","","","agv异常"+e.getMessage()); + logServer.deviceExecuteLog("1","","","agv异常" + e); if(ObjectUtil.isNotEmpty(s)){ s.close(); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/ScannerDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/ScannerDeviceDriver.java index ea21637c1..05d69619c 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/ScannerDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/ScannerDeviceDriver.java @@ -1,9 +1,9 @@ package org.nl.acs.device_driver; public interface ScannerDeviceDriver extends DeviceDriver { - void writeBarcode(String var1) throws Exception; + void writeBarcode(String var1) ; - void cleanBarcode() throws Exception; + void cleanBarcode() ; - String readBarcode() throws Exception; + String readBarcode(); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java index d201b6924..7db1b27aa 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java @@ -90,6 +90,9 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic } if (ikey != 0) { inst = instructionService.findByCodeFromCache(String.valueOf(ikey)); + if (ObjectUtil.isEmpty(inst)){ + inst = instructionService.findByCode(String.valueOf(ikey)); + } } if (!ObjectUtil.isEmpty(link_inst)) { link_flag = true; diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/box_palletizing_manipulator/BoxPalletizingManipulatorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/box_palletizing_manipulator/BoxPalletizingManipulatorDeviceDriver.java index a347f2f0c..88363cbfe 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/box_palletizing_manipulator/BoxPalletizingManipulatorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/box_palletizing_manipulator/BoxPalletizingManipulatorDeviceDriver.java @@ -194,25 +194,25 @@ public class BoxPalletizingManipulatorDeviceDriver extends AbstractOpcDeviceDriv String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_param, value); // itemMap.put(to_param, Integer.parseInt(value)); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void executing(Server server, Map itemMap) { - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int command) { - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); - ReadUtil.write(itemMap, server); + this.control(itemMap); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/CargoLiftConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/CargoLiftConveyorDeviceDriver.java index 2b566d890..73f6ad54c 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/CargoLiftConveyorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/CargoLiftConveyorDeviceDriver.java @@ -97,7 +97,7 @@ public class CargoLiftConveyorDeviceDriver extends AbstractOpcDeviceDriver imple Boolean requireSucess = false; @Override - public void execute() throws Exception { + public void execute() { String message = null; device_code = this.getDeviceCode(); @@ -183,7 +183,7 @@ public class CargoLiftConveyorDeviceDriver extends AbstractOpcDeviceDriver imple } } - public synchronized boolean instruction_require() throws Exception { + public synchronized boolean instruction_require(){ Date date = new Date(); if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); @@ -264,7 +264,13 @@ public class CargoLiftConveyorDeviceDriver extends AbstractOpcDeviceDriver imple instdto.setPriority(priority); instdto.setInstruction_status("0"); instdto.setExecute_device_code(start_point_code); - instructionService.create(instdto); + try { + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("指令创建失败!",e.getMessage()); + return false; + } //创建指令后修改任务状态 task.setTask_status("1"); taskserver.update(task); @@ -281,11 +287,11 @@ public class CargoLiftConveyorDeviceDriver extends AbstractOpcDeviceDriver imple public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int type, int command) { @@ -295,8 +301,8 @@ public class CargoLiftConveyorDeviceDriver extends AbstractOpcDeviceDriver imple + "." + ItemProtocol.item_to_target; String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); if (type == 1) { itemMap.put(to_command, command); @@ -310,7 +316,7 @@ public class CargoLiftConveyorDeviceDriver extends AbstractOpcDeviceDriver imple log.info("设备:" + device_code + ",下发PLC信号" + to_task + ",value:" + command); } - ReadUtil.write(itemMap, server); + this.control(itemMap); } @Override diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/EmptyVehicleStackingPositionDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/EmptyVehicleStackingPositionDeviceDriver.java index a02e553a1..02651d076 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/EmptyVehicleStackingPositionDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/EmptyVehicleStackingPositionDeviceDriver.java @@ -177,21 +177,21 @@ public class EmptyVehicleStackingPositionDeviceDriver extends AbstractOpcDeviceD public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(String key, String value) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + key; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, value); - ReadUtil.write(itemMap, server); + this.control(itemMap); } @Override diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDeviceDriver.java index c18c2d9f2..7cf39de57 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDeviceDriver.java @@ -209,21 +209,21 @@ public class HailiangSmartplcTestDeviceDriver extends AbstractOpcDeviceDriver im public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(String key, String value) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + key; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, value); - ReadUtil.write(itemMap, server); + this.control(itemMap); } @Override diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/HongXiangStationDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/HongXiangStationDeviceDriver.java index b6f15f566..886c2d855 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/HongXiangStationDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/HongXiangStationDeviceDriver.java @@ -145,11 +145,11 @@ public class HongXiangStationDeviceDriver extends AbstractOpcDeviceDriver implem public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_command; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } //将扩展表中的字符串数据转换成集合 @@ -172,13 +172,13 @@ public class HongXiangStationDeviceDriver extends AbstractOpcDeviceDriver implem String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_param, value); // itemMap.put(to_param, Integer.parseInt(value)); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int type, int command) { @@ -188,8 +188,8 @@ public class HongXiangStationDeviceDriver extends AbstractOpcDeviceDriver implem + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_target; String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); if (type == 1) { itemMap.put(to_command, command); @@ -203,7 +203,7 @@ public class HongXiangStationDeviceDriver extends AbstractOpcDeviceDriver implem log.info("设备:" + device_code + ",下发PLC信号" + to_task + ",value:" + command); } - ReadUtil.write(itemMap, server); + this.control(itemMap); } @Override diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java index 010b952ca..c0ff06909 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java @@ -221,11 +221,11 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_command; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } //将扩展表中的字符串数据转换成集合 @@ -248,13 +248,13 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_param, Integer.parseInt(value)); // itemMap.put(to_param, Integer.parseInt(value)); - ReadUtil.write(itemMap, server); + this.control(itemMap); logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); } @@ -266,8 +266,8 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_target; String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); if (type == 1) { itemMap.put(to_command, command); @@ -281,7 +281,7 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple log.info("设备:" + device_code + ",下发PLC信号" + to_task + ",value:" + command); } - ReadUtil.write(itemMap, server); + this.control(itemMap); } @Override diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java index dea3c7767..03e42ab96 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java @@ -140,7 +140,7 @@ public class ItemProtocol { setIsonline(true); return value; } - return 0; + return 0L; } @@ -183,6 +183,10 @@ public class ItemProtocol { return list; } + @Override + public String toString() { + return ""; + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/ItemProtocol.java index bfde080d9..c963542a9 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/ItemProtocol.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/ItemProtocol.java @@ -118,5 +118,9 @@ public class ItemProtocol { return list; } + @Override + public String toString() { + return ""; + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDeviceDriver.java index 56ec1dcfd..7fb11d31d 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDeviceDriver.java @@ -164,7 +164,7 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i inst1.setInstruction_status("1"); inst1.setExecute_device_code(this.device_code); instructionService.update(inst1); -// TaskDto taskDto = taskserver.findByCodeFromCache(inst1.getTask_code()); +// TaskDto tas未反馈电气信号原因kDto = taskserver.findByCodeFromCache(inst1.getTask_code()); // if (ObjectUtil.isNotEmpty(taskDto)) { // if (StrUtil.isNotEmpty(taskDto.getExt_task_id())) { // JSONArray array = new JSONArray(); @@ -408,15 +408,15 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i } catch (Exception var17) { feedMessage = var17.getMessage(); logServer.deviceExecuteLog(this.getDevice_code(), "", "", "读取信号值时出现异常:" + var17.getMessage()); - return; } - if (!this.itemProtocol.getIsonline()) { - this.setIsonline(false); - this.setIserror(true); - message = "信号量同步异常"; - //未联机 - } else if (mode == 0) { +// if (!this.itemProtocol.getIsonline()) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "信号量同步异常"; +// //未联机 +// } else + if (mode == 0) { this.setIsonline(false); this.setIserror(true); message = "未联机"; @@ -647,18 +647,18 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_param, Integer.parseInt(value)); // itemMap.put(to_param, Integer.parseInt(value)); - ReadUtil.write(itemMap, server); + this.control(itemMap); logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); } public void executing(Server server, Map itemMap) { - ReadUtil.write(itemMap, server); + this.control(itemMap); } //判断取货位或放货位为烘箱设备时关联的同一列烘箱设备是否有开门 @@ -728,10 +728,10 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i } public void writing(int command) { - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); - ReadUtil.write(itemMap, server); + this.control(itemMap); } @@ -844,7 +844,7 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i // if (type == 2) { // itemMap.put(to_material_code, command); // } -// ReadUtil.write(itemMap, server); +// this.control(itemMap); // // } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDeviceDriver.java index a90ec800e..64bca6768 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDeviceDriver.java @@ -242,21 +242,21 @@ public class PaintConveyorDeviceDriver extends AbstractOpcDeviceDriver implement public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(String key, String value) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + key; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, value); - ReadUtil.write(itemMap, server); + this.control(itemMap); } @Override diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java index 99f7bedf8..68656c285 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java @@ -152,6 +152,10 @@ public class ItemProtocol { return list; } + @Override + public String toString() { + return ""; + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDeviceDriver.java index e79566627..a46c5200e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDeviceDriver.java @@ -148,8 +148,8 @@ public class PlugPullDeviceSiteDeviceDriver extends AbstractOpcDeviceDriver impl public void writing(List list) { - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); for (int i = 0; i < list.size(); i++) { Object ob = list.get(i); @@ -161,7 +161,7 @@ public class PlugPullDeviceSiteDeviceDriver extends AbstractOpcDeviceDriver impl } } logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); - ReadUtil.write(itemMap, server); + this.control(itemMap); } //将扩展表中的字符串数据转换成集合 @@ -226,13 +226,13 @@ public class PlugPullDeviceSiteDeviceDriver extends AbstractOpcDeviceDriver impl String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_param, value); // itemMap.put(to_param, Integer.parseInt(value)); - ReadUtil.write(itemMap, server); + this.control(itemMap); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java index 10e992eb4..c7a1d51e5 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java @@ -4,11 +4,13 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.nl.acs.AcsConfig; @@ -90,6 +92,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme int task = 0; int last_task = 0; int agvphase = 0; + String task_code = null; int phase = 0; int index = 0; @@ -105,17 +108,19 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme private Date require_empty_in_time = new Date(); private Date require_empty_out_time = new Date(); - private int instruction_require_time_out; + private int instruction_require_time_out = 3000; //行架机械手申请任务成功标识 boolean requireSucess = false; boolean requireApplyLabelingSuccess = false; boolean requireApplyLaStrangulationSuccess = false; boolean requireEmptyInSuccess = false; boolean requireEmptyOutSuccess = false; + boolean requiresShipDeviceUpdate = true; private int instruction_finished_time_out; int branchProtocol = 0; String inst_message; + String last_inst_message; //当前指令 @@ -125,7 +130,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme String device_code; String vehicle_code; - + String last_vehicle_code; @Override public Device getDevice() { @@ -134,8 +139,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme @Override - public void execute() throws Exception { - String message = null; + public void execute() { try { device_code = this.getDeviceCode(); mode = this.itemProtocol.getMode(); @@ -156,11 +160,18 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); } if (move != last_move) { - if (move == 0 && mode == 2) { - message = null; + message = null; + if (move == 0 ) { inst_message = null; this.clearWrite(); } + if(move == 0 && last_move == 1 ){ + last_vehicle_code = vehicle_code; + last_inst_message = inst_message; + } + if (move == 0 && last_move == 1 && "06".equals(this.device.getRegion())) { + this.requiresShipDeviceUpdate = false; + } logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); } @@ -178,38 +189,43 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme } if (move != 0 && task > 0) { +// logServer.deviceExecuteLog(device_code, "", "", "输送线任务开始反馈任务状态,指令号:" + task); //inst_message inst = instructionService.findByCodeFromCache(String.valueOf(task)); if (inst != null) { inst_message = "当前指令号:" + inst.getInstruction_code() + " " + inst.getStart_point_code() + "->" + inst.getNext_point_code() + " 载具号:" + inst.getVehicle_code(); - if (mode == 2) { - if (StrUtil.equals(inst.getInstruction_status(), "1")) { - if (StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { - vehicle_code = inst.getVehicle_code(); - inst.setExecute_device_code(this.device_code); - finish_instruction(); - } else { - if (!StrUtil.equals(inst.getExecute_code(), this.device_code)) { - inst.setExecute_device_code(this.device_code); - instructionService.update(inst); - } - } - - } - } else { - if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { - inst.setInstruction_status("1"); - inst.setExecute_device_code(this.device_code); - instructionService.update(inst); - } + vehicle_code = inst.getVehicle_code(); + task_code = inst.getTask_code(); + if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { + inst.setInstruction_status("1"); + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task); } + if (StrUtil.equals(inst.getInstruction_status(), "1")) { + if (StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { + vehicle_code = inst.getVehicle_code(); + inst.setExecute_device_code(this.device_code); + finish_instruction(); + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task); + } else { + if (!StrUtil.equals(inst.getExecute_code(), this.device_code)) { + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + } + } + + } + } else { +// logServer.deviceExecuteLog(device_code, "", "", "输送线任务开始反馈任务状态,反馈失败,查询不到指令号:" + task); + message = "输送线任务反馈状态,查询不到指令号:" + task +"指令已完成"; + inst_message = null; } } } catch (Exception var17) { inst_message = var17.getMessage(); logServer.deviceExecuteLog(this.getDevice_code(), "", "", "读取信号值时出现异常:" + var17.getMessage()); - return; } // if (!this.itemProtocol.getIsonline()) { @@ -231,13 +247,9 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme } else { this.setIsonline(true); this.setIserror(false); - message = ""; +// message = ""; Instruction instruction = null; List toInstructions; - if (last_move == 1 && move == 0) { - // 有货变无货请求lms - this.shipDeviceUpdate(); - } // if (mode == 2 && move != 0 && task > 0) { @@ -264,16 +276,21 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme if (move > 0 && !requireSucess) { instruction_require(); } + if (!requiresShipDeviceUpdate && move == 0) { + this.shipDeviceUpdate(); + } else { + this.requiresShipDeviceUpdate = true; + } break; case 4: //申请捆扎 - if (move > 0 && !requireApplyLaStrangulationSuccess) { + if (move > 0 && !requireSucess) { applyLaStrangulation(); } break; case 5: //申请贴标 - if (move > 0 && !requireApplyLabelingSuccess) { + if (move > 0 && !requireSucess) { applyLabeling(); } @@ -289,7 +306,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme break; case 7: //空盘出库申请 - if (move == 0 && !requireEmptyOutSuccess) { + if (move == 0 && !requireSucess) { emptyOut(); } break; @@ -314,7 +331,10 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme put("device_code", device_code); }}; - acsToWmsService.shipDeviceUpdate(param); + HttpResponse response = acsToWmsService.shipDeviceUpdate(param); + if (response == null || response.getStatus() == 200) { + this.requiresShipDeviceUpdate = true; + } } @@ -383,26 +403,26 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_param, Integer.parseInt(value)); // itemMap.put(to_param, Integer.parseInt(value)); - ReadUtil.write(itemMap, server); + this.control(itemMap); logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); } public void executing(Server server, Map itemMap) { - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int command) { - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); - ReadUtil.write(itemMap, server); + this.control(itemMap); } @@ -452,13 +472,18 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme if (this.requireSucess) { requireSucess = "1"; } - jo.put("device_name", this.getDevice().getDevice_name()); jo.put("mode", mode); jo.put("move", move); jo.put("carrier_direction", carrier_direction); jo.put("task", task); + jo.put("last_task", last_task); + jo.put("task_code", task_code); + +// jo.put("barcode", barcode); +// jo.put("last_task", last_task); jo.put("inst_message", this.inst_message); + jo.put("last_inst_message", this.last_inst_message); jo.put("isOnline", this.getIsonline()); jo.put("error", this.getError()); jo.put("isError", this.getIserror()); @@ -481,8 +506,8 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme public void writing(List list) { - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); +// String opcservcerid = this.getDevice().getOpc_server_id(); +// Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); for (int i = 0; i < list.size(); i++) { Object ob = list.get(i); @@ -494,7 +519,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme } } logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); - ReadUtil.write(itemMap, server); + this.control(itemMap); } @@ -502,7 +527,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme /** * 请求指令 */ - public synchronized boolean instruction_require() throws Exception { + public synchronized boolean instruction_require() { Date date = new Date(); if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); @@ -545,6 +570,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme this.writing(list); if (task != Integer.parseInt(inst.getInstruction_code())) { this.writing(list); + message = "重新下发电气信号"; logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); } message = "下发电气任务号成功"; @@ -622,7 +648,13 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme instdto.setPriority(priority); instdto.setInstruction_status("0"); instdto.setExecute_device_code(start_point_code); - instructionService.create(instdto); + try { + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("指令创建失败!",e.getMessage()); + return false; + } //创建指令后修改任务状态 taskdto.setTask_status("1"); taskserver.update(taskdto); @@ -645,6 +677,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme this.writing(list); if (task != Integer.parseInt(inst.getInstruction_code())) { this.writing(list); + message = "重新下发电气信号"; logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); } } else { @@ -735,6 +768,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme } //申请捆扎 + @SneakyThrows public synchronized void applyLaStrangulation() { Date date = new Date(); if (date.getTime() - this.require_apply_strangulation_time.getTime() < (long) this.instruction_require_time_out) { @@ -745,6 +779,10 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme String vehicle_code = ""; if (task > 0) { Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); + if(ObjectUtil.isEmpty(instruction)){ + message = "申请捆扎电气设备任务号:" + task + "未找到对应指令"; + throw new RuntimeException("该电气任务号未找到对应指令!"); + } vehicle_code = instruction.getVehicle_code(); } else { logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "异常"); @@ -797,9 +835,10 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme map5.put("value", "4"); list.add(map5); this.writing(list); - this.writing(list); +// this.writing(list); + message = "申请捆扎成功"; - requireApplyLaStrangulationSuccess = true; + requireSucess = true; } else { message = "未返回尺寸信息"; } @@ -828,12 +867,13 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme JSONObject jo = JSON.parseObject(str); if (ObjectUtil.isEmpty(jo)) { message = "申请空盘入库接口不通"; + requireEmptyInSuccess = true; } else { if (jo.getInteger("status") == 200) { message = "申请空盘入库成功"; requireEmptyInSuccess = true; } else { - requireEmptyInSuccess = false; + requireEmptyInSuccess = true; message = "申请空盘入库失败," + jo.get("message").toString(); } } @@ -860,12 +900,13 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme JSONObject jo = JSON.parseObject(str); if (ObjectUtil.isEmpty(jo)) { message = "申请AGV搬运任务接口不通"; + requireSucess = true; } else { if (jo.getInteger("status") == 200) { message = "申请AGV搬运任务成功"; requireSucess = true; } else { - requireSucess = false; + requireSucess = true; message = "申请AGV搬运任务失败," + jo.get("message").toString(); } } @@ -890,12 +931,13 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme JSONObject jo = JSON.parseObject(str); if (ObjectUtil.isEmpty(jo)) { message = "申请空盘出库接口不通"; + requireSucess = true; } else { if (jo.getInteger("status") == 200) { message = "申请空盘出库成功"; - requireEmptyOutSuccess = true; + requireSucess = true; } else { - requireEmptyOutSuccess = false; + requireSucess = true; message = "申请空盘出库失败," + jo.get("message").toString(); } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java index 1602f5927..33eadc17a 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java @@ -39,833 +39,890 @@ import org.springframework.beans.factory.annotation.Autowired; import java.util.*; -/** - * 西门子-输送机驱动-贴标 - */ +/** 西门子-输送机驱动-贴标 */ @Slf4j @Data @RequiredArgsConstructor -public class SiemensConveyorLabelingDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - @Autowired - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - @Autowired - DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); - @Autowired - RouteLineService routelineserver = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - @Autowired - DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); - @Autowired - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - @Autowired - AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); - @Autowired - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - @Autowired - NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); - //当前指令 - Instruction inst = null; +public class SiemensConveyorLabelingDeviceDriver extends AbstractOpcDeviceDriver + implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { + protected ItemProtocol itemProtocol = new ItemProtocol(this); - //工作模式 - int mode = 0; - int last_mode = 0; - //光电信号 - int move = 0; - int last_move = 0; - //托盘方向 - int carrier_direction = 0; - int last_carrier_direction = 0; - //报警信号 - int error = 0; - int last_error = 0; - //任务号 - int task = 0; - int weight = 0; - int last_task = 0; - int agvphase = 0; + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - int phase = 0; - int index = 0; - Boolean isonline = true; - int hasGoods = 0; + @Autowired DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired RouteLineService routelineserver = SpringContextHolder.getBean(RouteLineService.class); + @Autowired TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + + @Autowired ParamService paramService = SpringContextHolder.getBean(ParamService.class); + @Autowired AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); + + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + + @Autowired NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); + // 当前指令 + Instruction inst = null; + + // 工作模式 + int mode = 0; + int last_mode = 0; + // 光电信号 + int move = 0; + int last_move = 0; + // 托盘方向 + int carrier_direction = 0; + int last_carrier_direction = 0; + // 报警信号 + int error = 0; + int last_error = 0; + // 任务号 + int task = 0; + int weight = 0; + int last_task = 0; + int agvphase = 0; + + int phase = 0; + int index = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date require_apply_labeling_time = new Date(); + private Date require_apply_strangulation_time = new Date(); + private Date require_empty_in_time = new Date(); + private Date require_empty_out_time = new Date(); + + private int instruction_require_time_out; + // 行架机械手申请任务成功标识 + boolean requireSucess = false; + boolean requireApplyLabelingSuccess = false; + boolean requireApplyLaStrangulationSuccess = false; + boolean requireEmptyInSuccess = false; + boolean requireEmptyOutSuccess = false; + private int instruction_finished_time_out; + + int branchProtocol = 0; + String inst_message; + + // 当前指令 + + // 暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String device_code; + + String vehicle_code; + + @Override + public Device getDevice() { + return this.device; + } + + @Override + public void execute() { String message = null; - Boolean iserror = false; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + move = this.itemProtocol.getMove(); + carrier_direction = this.itemProtocol.getCarrier_direction(); + error = this.itemProtocol.getError(); + task = this.itemProtocol.getTask(); + weight = this.itemProtocol.getWeight(); + if (mode != last_mode) { + if (mode == 2) { + requireSucess = false; + requireApplyLabelingSuccess = false; + requireApplyLaStrangulationSuccess = false; + requireEmptyInSuccess = false; + requireEmptyOutSuccess = false; + logServer.deviceExecuteLog(this.device_code, "", "", "复位请求标记成功!"); + } + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + if (move == 0 && mode == 2) { + this.clearWrite(); + } + logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); + } + if (carrier_direction != last_carrier_direction) { + logServer.deviceItemValue( + this.device_code, "carrier_direction", String.valueOf(carrier_direction)); + logServer.deviceExecuteLog( + this.device_code, + "", + "", + "信号carrier_direction:" + last_carrier_direction + "->" + carrier_direction); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + logServer.deviceExecuteLog( + this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); + } - Integer heartbeat_tag; - private Date instruction_require_time = new Date(); - private Date require_apply_labeling_time = new Date(); - private Date require_apply_strangulation_time = new Date(); - private Date require_empty_in_time = new Date(); - private Date require_empty_out_time = new Date(); + if (mode == 2 && move != 0 && task > 0) { + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈任务状态,指令号:" + task); + // inst_message + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + if (inst != null) { + inst_message = + "指令号:" + + inst.getInstruction_code() + + " " + + inst.getStart_point_code() + + "->" + + inst.getNext_point_code() + + " 载具号:" + + inst.getVehicle_code(); + if (StrUtil.equals(inst.getInstruction_status(), "1") + && StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { + vehicle_code = inst.getVehicle_code(); + finish_instruction(); + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task); + } else if (StrUtil.equals(inst.getInstruction_status(), "0") + && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { + inst.setInstruction_status("1"); + instructionService.update(inst); + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task); + } else { + logServer.deviceExecuteLog( + device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈失败任务状态不为就绪或者执行中状态,指令号:" + task); + } + } else { + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈任务状态,反馈失败,查询不到指令号:" + task); + } + } - private int instruction_require_time_out; - //行架机械手申请任务成功标识 - boolean requireSucess = false; - boolean requireApplyLabelingSuccess = false; - boolean requireApplyLaStrangulationSuccess = false; - boolean requireEmptyInSuccess = false; - boolean requireEmptyOutSuccess = false; - private int instruction_finished_time_out; - - int branchProtocol = 0; - String inst_message; - - //当前指令 - - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - int flag; - - String device_code; - - String vehicle_code; - - - @Override - public Device getDevice() { - return this.device; + } catch (Exception var17) { + inst_message = var17.getMessage(); + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "读取信号值时出现异常:" + var17.getMessage()); + // return; } + // if (!this.itemProtocol.getIsonline()) { + // this.setIsonline(false); + // this.setIserror(true); + // message = "信号量同步异常"; + // //未联机 + // } else + if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + // 有报警 + // } else if (error != 0) { + // this.setIsonline(false); + // this.setIserror(true); + // message = "有报警"; + // //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; - @Override - public void execute() throws Exception { - String message = null; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + // 申请任务 + if (move > 0 && !requireSucess) { + instruction_require(); + } + break; + case 4: + // 申请捆扎 + if (move > 0 && !requireSucess) { + applyLaStrangulation(); + } + break; + case 5: + // 申请贴标 + if (move > 0 && !requireSucess) { + applyLabeling(); + } + break; + case 6: + // 空托盘满垛入库申请 + if (move > 0 && !requireEmptyInSuccess) { + emptyIn(); + } + if (move > 0 && !requireSucess) { + instruction_require(); + } + break; + case 7: + // 空盘出库申请 + if (move == 0 && !requireEmptyOutSuccess) { + emptyOut(); + } + break; + case 8: + // 申请AGV任务 + if (move == 0 && !requireSucess) { + applyAgvTask(); + } + break; + } + } + last_mode = mode; + last_move = move; + last_carrier_direction = carrier_direction; + last_error = error; + last_task = task; + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + public void clearWrite() { + + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_target"); + map.put("value", "0"); + list.add(map); + Map map2 = new HashMap(); + map2.put("code", "to_task"); + map2.put("value", "0"); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_command"); + map3.put("value", "0"); + list.add(map3); + Map map4 = new HashMap(); + map4.put("code", "to_strap_times"); + map4.put("value", "0"); + list.add(map4); + Map map5 = new HashMap(); + map5.put("code", "to_length"); + map5.put("value", "0"); + list.add(map5); + Map map6 = new HashMap(); + map6.put("code", "to_weight"); + map6.put("value", "0"); + list.add(map6); + Map map7 = new HashMap(); + map7.put("code", "to_height"); + map7.put("value", "0"); + list.add(map7); + this.writing(list); + message = null; + vehicle_code = null; + } + + public boolean exe_business() { + return true; + } + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + // requireSucess = false; + return true; + } + + protected void thingToNothing() throws Exception { + requireSucess = false; + } + + public void writing(String param, String value) { + + String to_param = + this.getDevice().getOpc_server_code() + + "." + + this.getDevice().getOpc_plc_code() + + "." + + this.getDevice().getDevice_code() + + "." + + param; + // String opcservcerid = this.getDevice().getOpc_server_id(); + // Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + + itemMap.put(to_param, Integer.parseInt(value)); + // itemMap.put(to_param, Integer.parseInt(value)); + this.control(itemMap); + logServer.deviceExecuteLog( + device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); + } + + public void executing(Server server, Map itemMap) { + this.control(itemMap); + } + + public void writing(int command) { + + // String opcservcerid = this.getDevice().getOpc_server_id(); + // Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + this.control(itemMap); + } + + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + String mode = ""; + String move = ""; + String carrier_direction = ""; + if (this.getMode() == 0) { + mode = "脱机"; + } else if (this.getMode() == 1) { + mode = "单机"; + } else if (this.getMode() == 2) { + mode = "待机"; + } else if (this.getMode() == 3) { + mode = "运行中"; + } else if (this.getMode() == 4) { + mode = "申请捆扎中"; + } else if (this.getMode() == 5) { + mode = "申请贴标中"; + } else if (this.getMode() == 6) { + mode = "申请空盘入库中"; + } else if (this.getMode() == 7) { + mode = "申请空盘出库中"; + } else if (this.getMode() == 8) { + mode = "申请AGV任务中"; + } + + if (this.getMove() == 0) { + move = "无货"; + jo.put("hasGoods", false); + } else if (this.getMove() == 1) { + move = "有货"; + jo.put("hasGoods", true); + } else if (this.getMove() == 2) { + move = "有托盘有货"; + jo.put("hasGoods", true); + } + String requireApplyLabelingSuccess = "0"; + if (this.requireApplyLabelingSuccess) { + requireApplyLabelingSuccess = "1"; + } + String requireApplyLaStrangulationSuccess = "0"; + if (this.requireApplyLaStrangulationSuccess) { + requireApplyLaStrangulationSuccess = "1"; + } + jo.put("requireApplyLabelingSuccess", requireApplyLabelingSuccess); + jo.put("requireApplyLaStrangulationSuccess", requireApplyLaStrangulationSuccess); + + if (this.carrier_direction == 1) { + carrier_direction = "正转"; + } else if (this.carrier_direction == 2) { + carrier_direction = "反转"; + } + String requireSucess = "0"; + if (this.requireSucess) { + requireSucess = "1"; + } + + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("mode", mode); + jo.put("move", move); + jo.put("carrier_direction", carrier_direction); + jo.put("task", task); + jo.put("isOnline", this.getIsonline()); + jo.put("error", this.getError()); + jo.put("isError", this.getIserror()); + jo.put("message", this.getMessage()); + jo.put("is_click", true); + jo.put("requireSucess", requireSucess); + jo.put("driver_type", "siemens_conveyor"); + return jo; + } + + @Override + public void setDeviceStatus(JSONObject data) { + String requestSucess = data.getString("requireSucess"); + if (StrUtil.equals(requestSucess, "0")) { + this.requireSucess = false; + } else if (StrUtil.equals(requestSucess, "1")) { + this.requireSucess = true; + } + } + + public void writing(List list) { + + // String opcservcerid = this.getDevice().getOpc_server_id(); + // Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + for (int i = 0; i < list.size(); i++) { + Object ob = list.get(i); + JSONObject json = (JSONObject) JSONObject.toJSON(ob); + if (!StrUtil.isEmpty(json.getString("value"))) { + String to_param = + this.getDevice().getOpc_server_code() + + "." + + this.getDevice().getOpc_plc_code() + + "." + + this.getDevice().getDevice_code() + + "." + + json.getString("code"); + itemMap.put(to_param, json.getString("value")); + } + } + logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); + this.control(itemMap); + } + + /** 请求指令 */ + public synchronized boolean instruction_require() { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() + < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + // 判断是否存在起点相同 任务状态就绪的任务 + TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code); + if (!ObjectUtil.isEmpty(taskdto)) { + // if + // (!ObjectUtils.isEmpty(instructionService.findByBarcodeFromCache(container_code))) { + // return false; + // } + // 需要判断当前设备是否已经存在就绪的指令 如果存在就直接下发 不存在则创建 + Instruction inst = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()); + if (ObjectUtil.isNotEmpty(inst)) { + List list = new ArrayList(); + Map map = new HashMap(); + + if (StrUtil.isNotEmpty(taskdto.getTo_z())) { + if (StrUtil.equals(taskdto.getTo_z(), "01")) { + map.put("code", "to_target"); + map.put("value", "102"); + } else if (StrUtil.equals(taskdto.getTo_z(), "02")) { + map.put("code", "to_target"); + map.put("value", "201"); + } else if (StrUtil.equals(taskdto.getTo_z(), "03")) { + map.put("code", "to_target"); + map.put("value", "301"); + } + } + list.add(map); + Map map2 = new HashMap(); + map2.put("code", "to_task"); + map2.put("value", inst.getInstruction_code()); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_command"); + map3.put("value", "1"); + list.add(map3); + this.writing(list); + if (task != Integer.parseInt(inst.getInstruction_code())) { + this.writing(list); + logServer.deviceExecuteLog( + device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); + } + message = "下发电气任务号成功"; + requireSucess = true; + return true; + } + + // type 5 输送任务 + if (!StrUtil.equals(taskdto.getTask_type(), "5")) { + return false; + } + String taskid = taskdto.getTask_id(); + String taskcode = taskdto.getTask_code(); + String vehiclecode = taskdto.getVehicle_code(); + String priority = taskdto.getPriority(); + String start_point_code = taskdto.getStart_point_code(); + String start_device_code = taskdto.getStart_device_code(); + String route_plan_code = taskdto.getRoute_plan_code(); + String next_device_code = ""; + + /** 开始平均分配 */ + String this_coevice_code = + taskserver.queryAssignedByDevice(device_code, taskdto.getNext_device_code()); + if (StrUtil.isEmpty(this_coevice_code)) { + List shortPathsList = + routeLineService.getShortPathLines( + start_device_code, taskdto.getNext_device_code(), route_plan_code); + RouteLineDto routeLineDto = shortPathsList.get(0); + + String path = routeLineDto.getPath(); + String type = routeLineDto.getType(); + String[] str = path.split("->"); + + List pathlist = Arrays.asList(str); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(start_device_code)) { + index = m + 1; + break; + } + } + next_device_code = pathlist.get(index); + } else { + next_device_code = this_coevice_code; + } + // 校验路由关系 + List shortPathsList = + routeLineService.getShortPathLines( + start_device_code, next_device_code, route_plan_code); + if (ObjectUtils.isEmpty(shortPathsList)) { + throw new RuntimeException("路由不通!"); + } + + Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); + Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); + String next_point_code; + if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = taskdto.getTo_x() + "-" + taskdto.getTo_y() + "-" + taskdto.getTo_z(); + } else { + next_point_code = next_device_code; + } + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(taskdto.getRemark()); + instdto.setMaterial(taskdto.getMaterial()); + instdto.setQuantity(taskdto.getQuantity()); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + instdto.setVehicle_code(vehiclecode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setPriority(priority); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(start_point_code); try { - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - move = this.itemProtocol.getMove(); - carrier_direction = this.itemProtocol.getCarrier_direction(); - error = this.itemProtocol.getError(); - task = this.itemProtocol.getTask(); - weight = this.itemProtocol.getWeight(); - if (mode != last_mode) { - if( mode == 2){ - requireSucess = false; - requireApplyLabelingSuccess = false; - requireApplyLaStrangulationSuccess =false; - requireEmptyInSuccess =false; - requireEmptyOutSuccess =false; - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode +"复位请求标记"); - } - logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - if (move != last_move) { - if(move == 0 && mode == 2 ){ - this.clearWrite(); - } - logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); - } - if (carrier_direction != last_carrier_direction) { - logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(carrier_direction)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号carrier_direction:" + last_carrier_direction + "->" + carrier_direction); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); - } - if (task != last_task) { - logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); - } - - if (mode == 2 && move != 0 && task > 0) { - //inst_message - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - if (inst != null) { - inst_message = "指令号:" + inst.getInstruction_code() + " " + inst.getStart_point_code() + "->" + inst.getNext_point_code() + " 载具号:" + inst.getVehicle_code(); - if (StrUtil.equals(inst.getInstruction_status(), "1") && StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { - vehicle_code = inst.getVehicle_code(); - finish_instruction(); - } - if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { - inst.setInstruction_status("1"); - instructionService.update(inst); - } - } - } - - } catch (Exception var17) { - inst_message = var17.getMessage(); - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "读取信号值时出现异常:" + var17.getMessage()); - return; + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("指令创建异常!"); + return false; } - -// if (!this.itemProtocol.getIsonline()) { -// this.setIsonline(false); -// this.setIserror(true); -// message = "信号量同步异常"; -// //未联机 -// } else - if (mode == 0) { - this.setIsonline(false); - this.setIserror(true); - message = "未联机"; - //有报警 -// } else if (error != 0) { -// this.setIsonline(false); -// this.setIserror(true); -// message = "有报警"; -// //无报警 - } else { - this.setIsonline(true); - this.setIserror(false); - message = ""; - Instruction instruction = null; - List toInstructions; - - - switch (mode) { - case 1: - log.debug("设备运转模式:等待工作"); - break; - case 2: - //申请任务 - if (move > 0 && !requireSucess) { - instruction_require(); - } - break; - case 4: - //申请捆扎 - if (move > 0 && !requireApplyLaStrangulationSuccess) { - applyLaStrangulation(); - } - break; - case 5: - //申请贴标 - if (move > 0 && !requireApplyLabelingSuccess) { - applyLabeling(); - - } - break; - case 6: - //空托盘满垛入库申请 - if (move > 0 && !requireEmptyInSuccess) { - emptyIn(); - } - if (move > 0 && !requireSucess) { - instruction_require(); - } - break; - case 7: - //空盘出库申请 - if (move == 0 && !requireEmptyOutSuccess) { - emptyOut(); - } - break; - case 8: - //申请AGV任务 - if (move == 0 && !requireSucess) { - applyAgvTask(); - } - break; - - } - } - last_mode = mode; - last_move = move; - last_carrier_direction = carrier_direction; - last_error = error; - last_task = task; - } - - - public boolean exe_error() { - if (this.error == 0) { - return true; - } else { - log.debug("设备报警"); - return false; - } - } - - public void clearWrite() { + // 创建指令后修改任务状态 + taskdto.setTask_status("1"); + taskserver.update(taskdto); + requireSucess = true; + String next_addr = nextdevice.getExtraValue().get("address").toString(); List list = new ArrayList(); Map map = new HashMap(); - map.put("code","to_target"); - map.put("value","0"); + map.put("code", "to_target"); + map.put("value", next_addr); list.add(map); Map map2 = new HashMap(); - map2.put("code","to_task"); - map2.put("value","0"); + map2.put("code", "to_task"); + map2.put("value", instdto.getInstruction_code()); list.add(map2); Map map3 = new HashMap(); - map3.put("code","to_command"); - map3.put("value","0"); + map3.put("code", "to_command"); + map3.put("value", "1"); list.add(map3); - Map map4 = new HashMap(); - map4.put("code","to_strap_times"); - map4.put("value","0"); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code","to_length"); - map5.put("value","0"); - list.add(map5); - Map map6 = new HashMap(); - map6.put("code","to_weight"); - map6.put("value","0"); - list.add(map6); - Map map7 = new HashMap(); - map7.put("code","to_height"); - map7.put("value","0"); - list.add(map7); this.writing(list); - message = null; - vehicle_code = null; - } - - public boolean exe_business() { - return true; - } - - public synchronized boolean finish_instruction() throws Exception { - instructionService.finish(inst); -// requireSucess = false; - return true; - } - - - protected void thingToNothing() throws Exception { - requireSucess = false; - } - - - public void writing(String param, String value) { - - String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - - itemMap.put(to_param, Integer.parseInt(value)); -// itemMap.put(to_param, Integer.parseInt(value)); - ReadUtil.write(itemMap, server); - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); - } - - public void executing(Server server, Map itemMap) { - ReadUtil.write(itemMap, server); - } - - public void writing(int command) { - - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - ReadUtil.write(itemMap, server); - - } - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String move = ""; - String carrier_direction = ""; - if (this.getMode() == 0) { - mode = "脱机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "待机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } else if (this.getMode() == 4) { - mode = "申请捆扎中"; - } else if (this.getMode() == 5) { - mode = "申请贴标中"; - } else if (this.getMode() == 6) { - mode = "申请空盘入库中"; - } else if (this.getMode() == 7) { - mode = "申请空盘出库中"; - } else if (this.getMode() == 8) { - mode = "申请AGV任务中"; + if (task != Integer.parseInt(inst.getInstruction_code())) { + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); } - - if (this.getMove() == 0) { - move = "无货"; - jo.put("hasGoods", false); - } else if (this.getMove() == 1) { - move = "有货"; - jo.put("hasGoods", true); - } else if (this.getMove() == 2) { - move = "有托盘有货"; - jo.put("hasGoods", true); + } else { + // 如果不存在则直接找对应指令 + Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code); + if (ObjectUtil.isEmpty(inst)) { + return false; } - - if (this.carrier_direction == 1) { - carrier_direction = "正转"; - } else if (this.carrier_direction == 2) { - carrier_direction = "反转"; - } - String requireSucess = "0"; - if (this.requireSucess) { - requireSucess = "1"; + // 当起点为行架任务的时候不需要请求下发 + if (StrUtil.equals(inst.getInstruction_type(), "6")) { + return false; } + Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code()); + String next_addr = nextdevice.getExtraValue().get("address").toString(); - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("carrier_direction", carrier_direction); - jo.put("task", task); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("message", this.getMessage()); - jo.put("is_click", true); - jo.put("requireSucess", requireSucess); - jo.put("driver_type", "siemens_conveyor"); - return jo; + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_target"); + map.put("value", next_addr); + list.add(map); + Map map2 = new HashMap(); + map2.put("code", "to_task"); + map2.put("value", inst.getInstruction_code()); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_command"); + map3.put("value", "1"); + list.add(map3); + this.writing(list); + if (task != Integer.parseInt(inst.getInstruction_code())) { + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); + } + } + return true; } + } - @Override - public void setDeviceStatus(JSONObject data) { - String requestSucess = data.getString("requireSucess"); - if (StrUtil.equals(requestSucess, "0")) { - this.requireSucess = false; - } else if(StrUtil.equals(requestSucess, "1")) { - this.requireSucess = true; + // 申请贴标 + public synchronized void applyLabeling() { + Date date = new Date(); + if (date.getTime() - this.require_apply_labeling_time.getTime() + < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + this.require_apply_labeling_time = date; + String vehicle_code = ""; + if (weight == 0) { + logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备重量:" + weight + "异常"); + message = "申请贴标电气设备重量:" + weight + "异常"; + throw new RuntimeException("重量为空!"); + } + if (task > 0) { + Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); + if (ObjectUtil.isEmpty(instruction)) { + instruction = instructionService.findByCode(String.valueOf(task)); } + vehicle_code = instruction.getVehicle_code(); + } else { + logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:" + task + "异常"); + message = "申请贴标电气设备任务号:" + task + "异常"; + throw new RuntimeException("任务号为空!"); + } + if (StrUtil.isEmpty(vehicle_code)) { + logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:" + task + "未找到载具号"); + message = "申请贴标电气设备任务号:" + task + "未找到载具号"; + throw new RuntimeException("载具号为空!"); + } + ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = + new ApplyLabelingAndBindingRequest(); + JSONObject device_json = + WQLObject.getWQLObject("acs_storage_cell") + .query("storage_code ='" + this.device_code + "'") + .uniqueResult(0); + String start_point_code = null; + if (!ObjectUtil.isEmpty(device_json)) { + start_point_code = + (String) device_json.get("parent_storage_code") == null + ? this.device_code + : (String) device_json.get("parent_storage_code"); + } + applyLabelingAndBindingRequest.setDevice_code(start_point_code); + applyLabelingAndBindingRequest.setType("1"); + applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); + applyLabelingAndBindingRequest.setWeight(String.valueOf(weight / 100)); + ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = + acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); + + if (applyLabelingAndBindingResponse.getstatus() == 200) { + message = "申请贴标成功"; + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_command"); + map.put("value", "5"); + list.add(map); + this.writing(list); + this.writing(list); + message = "申请贴标下发电气信号成功"; + requireSucess = true; + } else { + message = "申请贴标失败," + applyLabelingAndBindingResponse.getMessage(); + } } + } - public void writing(List list) { + // 申请捆扎 + public synchronized void applyLaStrangulation() { + Date date = new Date(); + if (date.getTime() - this.require_apply_strangulation_time.getTime() + < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + this.require_apply_strangulation_time = date; + String vehicle_code = ""; + if (task > 0) { + Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); + vehicle_code = instruction.getVehicle_code(); + } else { + logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "异常"); + message = "申请捆扎电气设备任务号:" + task + "异常"; + throw new RuntimeException("任务号为空!"); + } + if (StrUtil.isEmpty(vehicle_code)) { + logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "未找到载具号"); + message = "申请捆扎电气设备任务号:" + task + "未找到载具号"; + throw new RuntimeException("载具号为空!"); + } + ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = + new ApplyLabelingAndBindingRequest(); + JSONObject device_json = + WQLObject.getWQLObject("acs_storage_cell") + .query("storage_code ='" + this.device_code + "'") + .uniqueResult(0); + String start_point_code = null; + if (!ObjectUtil.isEmpty(device_json)) { + start_point_code = + (String) device_json.get("parent_storage_code") == null + ? this.device_code + : (String) device_json.get("parent_storage_code"); + } + applyLabelingAndBindingRequest.setDevice_code(start_point_code); + applyLabelingAndBindingRequest.setType("2"); + applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); + ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = + acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); + if (applyLabelingAndBindingResponse.getstatus() == 200) { + if (ObjectUtil.isNotEmpty(applyLabelingAndBindingResponse.getData())) { + Map datas = applyLabelingAndBindingResponse.getData(); + String length = datas.get("box_length").toString(); + String width = datas.get("box_width").toString(); + String box_high = datas.get("box_high").toString(); + String bundle_times = datas.get("bundle_times").toString(); - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - for (int i = 0; i < list.size(); i++) { - Object ob = list.get(i); - JSONObject json = (JSONObject) JSONObject.toJSON(ob); - if (!StrUtil.isEmpty(json.getString("value"))) { - String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + json.getString("code"); - itemMap.put(to_param, json.getString("value")); - } - } - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); - ReadUtil.write(itemMap, server); - - } - - - /** - * 请求指令 - */ - public synchronized boolean instruction_require() throws Exception { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return false; + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_length"); + map.put("value", length); + list.add(map); + Map map2 = new HashMap(); + map2.put("code", "to_weight"); + map2.put("value", width); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_height"); + map3.put("value", box_high); + list.add(map3); + Map map4 = new HashMap(); + map4.put("code", "to_strap_times"); + map4.put("value", bundle_times); + list.add(map4); + Map map5 = new HashMap(); + map5.put("code", "to_command"); + map5.put("value", "4"); + list.add(map5); + this.writing(list); + this.writing(list); + message = "申请贴标成功"; + requireSucess = true; } else { - this.instruction_require_time = date; - //判断是否存在起点相同 任务状态就绪的任务 - TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code); - if (!ObjectUtil.isEmpty(taskdto)) { -// if (!ObjectUtils.isEmpty(instructionService.findByBarcodeFromCache(container_code))) { -// return false; -// } - //需要判断当前设备是否已经存在就绪的指令 如果存在就直接下发 不存在则创建 - Instruction inst = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()); - if(ObjectUtil.isNotEmpty(inst)){ - List list = new ArrayList(); - Map map = new HashMap(); - - if(StrUtil.isNotEmpty(taskdto.getTo_z())){ - if(StrUtil.equals(taskdto.getTo_z(),"01")){ - map.put("code","to_target"); - map.put("value","102"); - } else if(StrUtil.equals(taskdto.getTo_z(),"02")){ - map.put("code","to_target"); - map.put("value","201"); - } else if(StrUtil.equals(taskdto.getTo_z(),"03")){ - map.put("code","to_target"); - map.put("value","301"); - } - } - list.add(map); - Map map2 = new HashMap(); - map2.put("code","to_task"); - map2.put("value",inst.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code","to_command"); - map3.put("value","1"); - list.add(map3); - this.writing(list); - if( task != Integer.parseInt(inst.getInstruction_code())){ - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); - } - message = "下发电气任务号成功"; - requireSucess = true; - return true; - } - - // type 5 输送任务 - if(!StrUtil.equals(taskdto.getTask_type(),"5")){ - return false; - } - String taskid = taskdto.getTask_id(); - String taskcode = taskdto.getTask_code(); - String vehiclecode = taskdto.getVehicle_code(); - String priority = taskdto.getPriority(); - String start_point_code = taskdto.getStart_point_code(); - String start_device_code = taskdto.getStart_device_code(); - String route_plan_code = taskdto.getRoute_plan_code(); - String next_device_code = ""; - - /** - * 开始平均分配 - */ - String this_coevice_code = taskserver.queryAssignedByDevice(device_code, taskdto.getNext_device_code()); - if (StrUtil.isEmpty(this_coevice_code)) { - List shortPathsList = routeLineService.getShortPathLines(start_device_code, taskdto.getNext_device_code(), route_plan_code); - RouteLineDto routeLineDto = shortPathsList.get(0); - - String path = routeLineDto.getPath(); - String type = routeLineDto.getType(); - String[] str = path.split("->"); - - List pathlist = Arrays.asList(str); - int index = 0; - for (int m = 0; m < pathlist.size(); m++) { - if (pathlist.get(m).equals(start_device_code)) { - index = m + 1; - break; - } - } - next_device_code = pathlist.get(index); - } else { - next_device_code = this_coevice_code; - } - //校验路由关系 - List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - if (ObjectUtils.isEmpty(shortPathsList)) { - throw new RuntimeException("路由不通!"); - } - - Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); - Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); - String next_point_code; - if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { - next_point_code = taskdto.getTo_x() + "-" + taskdto.getTo_y() + "-" + taskdto.getTo_z(); - } else { - next_point_code = next_device_code; - } - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(taskdto.getRemark()); - instdto.setMaterial(taskdto.getMaterial()); - instdto.setQuantity(taskdto.getQuantity()); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - instdto.setVehicle_code(vehiclecode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setPriority(priority); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(start_point_code); - instructionService.create(instdto); - //创建指令后修改任务状态 - taskdto.setTask_status("1"); - taskserver.update(taskdto); - requireSucess = true; - String next_addr = nextdevice.getExtraValue().get("address").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code","to_target"); - map.put("value",next_addr); - list.add(map); - Map map2 = new HashMap(); - map2.put("code","to_task"); - map2.put("value",instdto.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code","to_command"); - map3.put("value","1"); - list.add(map3); - this.writing(list); - if( task != Integer.parseInt(inst.getInstruction_code())){ - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); - } - } else { - //如果不存在则直接找对应指令 - Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code); - if(ObjectUtil.isEmpty(inst)){ - return false; - } - //当起点为行架任务的时候不需要请求下发 - if(StrUtil.equals(inst.getInstruction_type(),"6")){ - return false; - } - Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code()); - String next_addr = nextdevice.getExtraValue().get("address").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code","to_target"); - map.put("value",next_addr); - list.add(map); - Map map2 = new HashMap(); - map2.put("code","to_task"); - map2.put("value",inst.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code","to_command"); - map3.put("value","1"); - list.add(map3); - this.writing(list); - if( task != Integer.parseInt(inst.getInstruction_code())){ - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); - } - } - return true; + message = "未返回尺寸信息"; } - } - //申请贴标 - public synchronized void applyLabeling() { - Date date = new Date(); - if (date.getTime() - this.require_apply_labeling_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; + } else { + message = applyLabelingAndBindingResponse.getMessage(); + } + } + } + + public synchronized void emptyIn() { + Date date = new Date(); + if (date.getTime() - this.require_empty_in_time.getTime() + < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + this.require_empty_in_time = date; + + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + message = "申请空盘入库任务中..."; + JSONObject apply = new JSONObject(); + apply.put("device_code", device_code); + apply.put("type", "2"); + String str = acsToWmsService.applyTaskToWms(apply); + JSONObject jo = JSON.parseObject(str); + if (ObjectUtil.isEmpty(jo)) { + message = "申请空盘入库接口不通"; } else { - this.require_apply_labeling_time = date; - String vehicle_code = ""; - if(weight == 0 ){ - logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备重量:"+weight+"异常"); - message = "申请贴标电气设备重量:"+weight+"异常"; - throw new RuntimeException("重量为空!"); - } - if(task >0 ){ - Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); - if (ObjectUtil.isEmpty(instruction)){ - instruction = instructionService.findByCode(String.valueOf(task)); - } - vehicle_code = instruction.getVehicle_code(); - - } else { - logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:"+task+"异常"); - message = "申请贴标电气设备任务号:"+task+"异常"; - throw new RuntimeException("任务号为空!"); - } - if(StrUtil.isEmpty(vehicle_code)){ - logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:"+task+"未找到载具号"); - message = "申请贴标电气设备任务号:"+task+"未找到载具号"; - throw new RuntimeException("载具号为空!"); - } - ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = - new ApplyLabelingAndBindingRequest(); - JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); - String start_point_code = null; - if (!ObjectUtil.isEmpty(device_json)) { - start_point_code = (String) device_json.get("parent_storage_code") == null ? this.device_code : (String) device_json.get("parent_storage_code"); - } - applyLabelingAndBindingRequest.setDevice_code(start_point_code); - applyLabelingAndBindingRequest.setType("1"); - applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); - applyLabelingAndBindingRequest.setWeight(String.valueOf(weight/10)); - ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - - if(applyLabelingAndBindingResponse.getstatus() == 200){ - message ="申请贴标成功"; - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code","to_command"); - map.put("value","5"); - list.add(map); - this.writing(list); - this.writing(list); - message ="申请贴标下发电气信号成功"; - requireApplyLabelingSuccess = true; - } else { - message = "申请贴标失败,"+applyLabelingAndBindingResponse.getMessage(); - } + if (jo.getInteger("status") == 200) { + message = "申请空盘入库成功"; + requireEmptyInSuccess = true; + } else { + requireEmptyInSuccess = false; + message = "申请空盘入库失败," + jo.get("message").toString(); + } } + } } + } - //申请捆扎 - public synchronized void applyLaStrangulation() { - Date date = new Date(); - if (date.getTime() - this.require_apply_strangulation_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; + public synchronized void applyAgvTask() { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() + < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + this.instruction_require_time = date; + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + message = "申请AGV搬运任务中..."; + JSONObject apply = new JSONObject(); + apply.put("device_code", device_code); + apply.put("type", "1"); + String str = acsToWmsService.applyTaskToWms(apply); + JSONObject jo = JSON.parseObject(str); + if (ObjectUtil.isEmpty(jo)) { + message = "申请AGV搬运任务接口不通"; } else { - this.require_apply_strangulation_time = date; - String vehicle_code = ""; - if(task >0 ){ - Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); - vehicle_code = instruction.getVehicle_code(); - } else { - logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:"+task+"异常"); - message = "申请捆扎电气设备任务号:"+task+"异常"; - throw new RuntimeException("任务号为空!"); - } - if(StrUtil.isEmpty(vehicle_code)){ - logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:"+task+"未找到载具号"); - message = "申请捆扎电气设备任务号:"+task+"未找到载具号"; - throw new RuntimeException("载具号为空!"); - } - ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = - new ApplyLabelingAndBindingRequest(); - JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); - String start_point_code = null; - if (!ObjectUtil.isEmpty(device_json)) { - start_point_code = (String) device_json.get("parent_storage_code") == null ? this.device_code : (String) device_json.get("parent_storage_code"); - } - applyLabelingAndBindingRequest.setDevice_code(start_point_code); - applyLabelingAndBindingRequest.setType("2"); - applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); - ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - if(applyLabelingAndBindingResponse.getstatus() == 200) { - if(ObjectUtil.isNotEmpty( applyLabelingAndBindingResponse.getData())){ - Map datas = applyLabelingAndBindingResponse.getData(); - String length = datas.get("box_length").toString(); - String width = datas.get("box_width").toString(); - String box_high = datas.get("box_high").toString(); - String bundle_times = datas.get("bundle_times").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code","to_length"); - map.put("value",length); - list.add(map); - Map map2 = new HashMap(); - map2.put("code","to_weight"); - map2.put("value",width); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code","to_height"); - map3.put("value",box_high); - list.add(map3); - Map map4 = new HashMap(); - map4.put("code","to_strap_times"); - map4.put("value",bundle_times); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code","to_command"); - map5.put("value","4"); - list.add(map5); - this.writing(list); - this.writing(list); - message ="申请贴标成功"; - requireApplyLaStrangulationSuccess = true; - } else { - message = "未返回尺寸信息"; - } - - } else { - message = applyLabelingAndBindingResponse.getMessage(); - } - + if (jo.getInteger("status") == 200) { + message = "申请AGV搬运任务成功"; + requireEmptyOutSuccess = true; + } else { + requireEmptyOutSuccess = false; + message = "申请AGV搬运任务失败," + jo.get("message").toString(); + } } + } } + } - public synchronized void emptyIn() { - Date date = new Date(); - if (date.getTime() - this.require_empty_in_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; + public synchronized void emptyOut() { + Date date = new Date(); + if (date.getTime() - this.require_empty_out_time.getTime() + < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + this.require_empty_out_time = date; + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + message = "申请空盘出库任务中..."; + JSONObject apply = new JSONObject(); + apply.put("device_code", device_code); + apply.put("type", "3"); + String str = acsToWmsService.applyTaskToWms(apply); + JSONObject jo = JSON.parseObject(str); + if (ObjectUtil.isEmpty(jo)) { + message = "申请空盘出库接口不通"; } else { - this.require_empty_in_time = date; - - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - message = "申请空盘入库任务中..."; - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type","2"); - String str = acsToWmsService.applyTaskToWms(apply); - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请空盘入库接口不通"; - } else { - if (jo.getInteger("status") == 200) { - message = "申请空盘入库成功"; - requireEmptyInSuccess = true; - } else { - requireEmptyInSuccess = false; - message = "申请空盘入库失败,"+jo.get("message").toString(); - } - } - - } + if (jo.getInteger("status") == 200) { + message = "申请空盘出库成功"; + requireEmptyOutSuccess = true; + } else { + requireEmptyOutSuccess = false; + message = "申请空盘出库失败," + jo.get("message").toString(); + } } + } } - - public synchronized void applyAgvTask() { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.instruction_require_time = date; - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - message = "申请AGV搬运任务中..."; - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type","1"); - String str = acsToWmsService.applyTaskToWms(apply); - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请AGV搬运任务接口不通"; - } else { - if (jo.getInteger("status") == 200) { - message = "申请AGV搬运任务成功"; - requireEmptyOutSuccess = true; - } else { - requireEmptyOutSuccess = false; - message = "申请AGV搬运任务失败,"+jo.get("message").toString(); - } - } - - } - } - } - - public synchronized void emptyOut() { - Date date = new Date(); - if (date.getTime() - this.require_empty_out_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_empty_out_time = date; - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - message = "申请空盘出库任务中..."; - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type","3"); - String str = acsToWmsService.applyTaskToWms(apply); - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请空盘出库接口不通"; - } else { - if (jo.getInteger("status") == 200) { - message = "申请空盘出库成功"; - requireEmptyOutSuccess = true; - } else { - requireEmptyOutSuccess = false; - message = "申请空盘出库失败,"+jo.get("message").toString(); - } - } - - } - } - } - - + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/SlitTwoManipulatorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/SlitTwoManipulatorDeviceDriver.java index 88cc92ec9..01e3a2272 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/SlitTwoManipulatorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/SlitTwoManipulatorDeviceDriver.java @@ -140,7 +140,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl @Override - public synchronized void execute() throws Exception { + public synchronized void execute(){ String message = null; try { device_code = this.getDeviceCode(); @@ -673,15 +673,16 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl } catch (Exception var17) { feedMessage = var17.getMessage(); logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage()); - return; +// return; } - if (!this.itemProtocol.getIsonline()) { - this.setIsonline(false); - this.setIserror(true); - message = "信号量同步异常"; - //未联机 - } else if (mode == 0) { +// if (!this.itemProtocol.getIsonline()) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "信号量同步异常"; +// //未联机 +// } else + if (mode == 0) { this.setIsonline(false); this.setIserror(true); message = "未联机"; @@ -1272,12 +1273,12 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl public void writing(String param, String value) { String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_param, Integer.parseInt(value)); - ReadUtil.write(itemMap, server); + this.control(itemMap); logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); } @@ -1291,10 +1292,10 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl public void executing(int command, Instruction instruction, String appendMessage) { - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); - ReadUtil.write(itemMap, server); + this.control(itemMap); } @@ -1306,18 +1307,18 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl public void executing(Server server, Map itemMap) { - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing1(int command) { String to_command1 = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_command1; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command1, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } @@ -1325,25 +1326,25 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl String to_command2 = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_command2; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command2, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int type, int command) { - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(List list) { - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); +// String opcservcerid = this.getDevice().getOpc_server_id(); +// Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); for (int i = 0; i < list.size(); i++) { Object ob = list.get(i); @@ -1355,7 +1356,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl } } logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); - ReadUtil.write(itemMap, server); + this.control(itemMap); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardCoveyorControlDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardCoveyorControlDeviceDriver.java index 351e8e354..499346239 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardCoveyorControlDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardCoveyorControlDeviceDriver.java @@ -141,7 +141,7 @@ public class StandardCoveyorControlDeviceDriver extends AbstractOpcDeviceDriver @Override - public void execute() throws Exception { + public void execute() { String message = null; try { device_code = this.getDeviceCode(); @@ -307,28 +307,28 @@ public class StandardCoveyorControlDeviceDriver extends AbstractOpcDeviceDriver if (instruction != null) { instruction_num = Integer.parseInt(instruction.getInstruction_code()); } - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, 1); itemMap.put(to_task, instruction_num); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void executing(Server server, Map itemMap) { - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_command; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } @@ -340,13 +340,13 @@ public class StandardCoveyorControlDeviceDriver extends AbstractOpcDeviceDriver + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_target; String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); itemMap.put(to_target, target); itemMap.put(to_task, task); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int type, int command) { @@ -356,8 +356,8 @@ public class StandardCoveyorControlDeviceDriver extends AbstractOpcDeviceDriver + "." + ItemProtocol.item_to_target; String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); if (type == 1) { itemMap.put(to_command, command); @@ -367,11 +367,11 @@ public class StandardCoveyorControlDeviceDriver extends AbstractOpcDeviceDriver } else if (type == 3) { itemMap.put(to_task, command); } - ReadUtil.write(itemMap, server); + this.control(itemMap); } - public boolean instruction_apply() throws Exception { + public boolean instruction_apply() { return false; } @@ -433,7 +433,7 @@ public class StandardCoveyorControlDeviceDriver extends AbstractOpcDeviceDriver } - public synchronized boolean apply_InEmpty() throws Exception { + public synchronized boolean apply_InEmpty(){ return false; } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java index 370748eb9..e459f504b 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java @@ -148,7 +148,7 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp } @Override - public void execute() throws Exception { + public void execute() { try { device_code = this.getDeviceCode(); mode = this.itemProtocol.getMode(); @@ -532,17 +532,17 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp if (instruction != null) { instruction_num = Integer.parseInt(instruction.getInstruction_code()); } - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, 1); itemMap.put(to_task, instruction_num); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void executing(Server server, Map itemMap) { - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing() { @@ -553,13 +553,13 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp + "." + ItemProtocol.item_to_target; String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, 1); itemMap.put(to_target, deviceAppservice.findDeviceByCode(inst.getNext_device_code()).getAddress()); itemMap.put(to_task, inst.getInstruction_code()); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int command, int target, int task) { @@ -570,24 +570,26 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp + "." + ItemProtocol.item_to_target; String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); itemMap.put(to_target, target); itemMap.put(to_task, task); - ReadUtil.write(itemMap, server); + this.control(itemMap); + +// this.control(itemMap); } public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_command; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int type, int command) { @@ -597,8 +599,8 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp + "." + ItemProtocol.item_to_target; String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); if (type == 1) { itemMap.put(to_command, command); @@ -609,15 +611,15 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp itemMap.put(to_task, command); } - ReadUtil.write(itemMap, server); + this.control(itemMap); } - public boolean instruction_require(String container_code) throws Exception { + public boolean instruction_require(String container_code) { return instruction_require(container_code, WcsConfig.task_container_type_default_desc); } @Transactional(rollbackFor = Exception.class) - public synchronized boolean instruction_apply(String container_code) throws Exception { + public synchronized boolean instruction_apply(String container_code) { Date date = new Date(); if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); @@ -723,7 +725,7 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp * @param container_type */ @Transactional(rollbackFor = Exception.class) - public synchronized boolean instruction_require(String container_code, String container_type) throws Exception { + public synchronized boolean instruction_require(String container_code, String container_type) { Date date = new Date(); if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); @@ -862,6 +864,18 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp move = "有托盘有货"; jo.put("hasGoods", true); } + String requireSucess = "0"; + if (this.requireSucess) { + requireSucess = "1"; + } + String applySucess = "0"; + if (this.applySucess) { + applySucess = "1"; + } + jo.put("requireSucess", requireSucess); + jo.put("applySucess", applySucess); + jo.put("driver_type", "standard_conveyor_control_with_scanner"); + jo.put("is_click", true); jo.put("device_name", this.getDevice().getDevice_name()); jo.put("mode", mode); jo.put("move", move); @@ -875,7 +889,12 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp @Override public void setDeviceStatus(JSONObject data) { - + String requestSucess = data.getString("requireSucess"); + if (StrUtil.equals(requestSucess, "0")) { + this.requireSucess = false; + } else if (StrUtil.equals(requestSucess, "1")) { + this.requireSucess = true; + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java index 816117424..7277df9df 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java @@ -132,39 +132,48 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe return barcode; } - public String barcode() throws Exception { + public String barcode() { ScannerDeviceDriver scanner = this.getScanner(); return scanner.readBarcode(); } - public void clearBarcode() throws Exception { + public void clearBarcode() { ScannerDeviceDriver scanner = this.getScanner(); scanner.cleanBarcode(); logServer.deviceExecuteLog(this.device_code, "", "", "清理条码"); } - public synchronized boolean finish_instruction() throws Exception { - instructionService.finish(inst); + public synchronized boolean finish_instruction(){ + try { + instructionService.finish(inst); + } catch (Exception e) { + e.printStackTrace(); + return false; + } return true; } - private ScannerDeviceDriver getScanner() throws Exception { + private ScannerDeviceDriver getScanner() { String scanner_code = (String) this.getDevice().getExtraValue().get(StandardConveyorWithScannerConfig.relation_scanner); if (StrUtil.isEmpty(scanner_code)) { - throw new Exception("未配置读码器"); + log.error("未配置读码器"); +// throw new Exception("未配置读码器"); } else { Device device = deviceAppservice.findDeviceByCode(scanner_code); if (device == null) { - throw new Exception("无设备:" + scanner_code); +// throw new Exception("无设备:" + scanner_code); + log.error("无设备:" + scanner_code); } else { DeviceDriver deviceDriver = device.getDeviceDriver(); if (!(deviceDriver instanceof ScannerDeviceDriver)) { - throw new Exception("扫码器类型不对,不是ScannerDeviceDriver"); +// throw new Exception("扫码器类型不对,不是ScannerDeviceDriver"); + log.error("扫码器类型不对,不是ScannerDeviceDriver"); } else { ScannerDeviceDriver driver = (ScannerDeviceDriver) deviceDriver; return driver; } } } + return null; } @Override @@ -174,8 +183,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe @Override - public void execute() throws Exception { - String message = null; + public void execute(){ try { device_code = this.getDeviceCode(); heartbeat = this.itemProtocol.getHeartbeat(); @@ -195,7 +203,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } } if (move != last_move) { - if (move == 0 && mode == 2) { + if (move == 0) { message = null; inst_message = null; clearBarcode(); @@ -360,7 +368,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } public void executing(Server server, Map itemMap) { - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int command, int target, int task) { @@ -371,24 +379,24 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe + "." + ItemProtocol.item_to_target; String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); itemMap.put(to_target, target); itemMap.put(to_task, task); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_command; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int type, int command) { @@ -398,8 +406,8 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe + "." + ItemProtocol.item_to_target; String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); if (type == 1) { itemMap.put(to_command, command); @@ -411,14 +419,14 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } - ReadUtil.write(itemMap, server); + this.control(itemMap); } - public boolean instruction_require(String container_code) throws Exception { + public boolean instruction_require(String container_code) { return instruction_require(container_code, WcsConfig.task_container_type_default_desc); } - public synchronized boolean instruction_apply(String container_code) throws Exception { + public synchronized boolean instruction_apply(String container_code) { Date date = new Date(); if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); @@ -480,7 +488,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe * @param container_code * @param container_type */ - public synchronized boolean instruction_require(String container_code, String container_type) throws Exception { + public synchronized boolean instruction_require(String container_code, String container_type) { Date date = new Date(); if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); @@ -491,9 +499,13 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe TaskDto taskdto = taskserver.findByContainer(container_code); if (!ObjectUtil.isEmpty(taskdto)) { if (!ObjectUtils.isEmpty(instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()))) { - Instruction instdto = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()); + logServer.deviceExecuteLog(this.device_code, "", "", "申请任务时该载具号"+container_code + +"已存在对应任务,不再请求"); + Instruction instdto = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()); if(!StrUtil.equals(instdto.getStart_device_code(),this.device_code)){ message ="当前载具号"+container_code+"查找对应指令起点与当前设备不符"; + logServer.deviceExecuteLog(this.device_code, "", "", "申请任务" + +"当前载具号"+container_code+"查找对应指令起点与当前设备不符"); // this.setIserror(true); // List list = new ArrayList(); // Map map = new HashMap(); @@ -540,10 +552,12 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe list.add(map3); this.writing(list); message = "下发电气任务号成功"; - if(task != Integer.parseInt(instdto.getInstruction_code()) ){ - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", instdto.getInstruction_code() + "再次下发电气信号"); - } + logServer.deviceExecuteLog(this.device_code, "", "", "申请任务时该载具号"+container_code + +"已存在对应任务,下发电气信号"); +// if(task != Integer.parseInt(instdto.getInstruction_code()) ){ +// this.writing(list); +// logServer.deviceExecuteLog(device_code, "", "", instdto.getInstruction_code() + "再次下发电气信号"); +// } requireSucess = true; applySucess = true; } else { @@ -640,7 +654,13 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe instdto.setPriority(priority); instdto.setInstruction_status("0"); instdto.setExecute_device_code(start_point_code); - instructionService.create(instdto); + try { + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("指令创建失败!",e.getMessage()); + return false; + } //创建指令后修改任务状态 taskdto.setTask_status("1"); taskserver.update(taskdto); @@ -671,10 +691,10 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe map3.put("value","1"); list.add(map3); this.writing(list); - if(task != Integer.parseInt(instdto.getInstruction_code()) ){ - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", instdto.getInstruction_code() + "再次下发电气信号"); - } +// if(task != Integer.parseInt(instdto.getInstruction_code()) ){ +// this.writing(list); +// logServer.deviceExecuteLog(device_code, "", "", instdto.getInstruction_code() + "再次下发电气信号"); +// } requireSucess = true; applySucess = true; } else { @@ -708,7 +728,6 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe requireSucess = true; applySucess = false; } else { - requireSucess = false; message = jo.get("message").toString(); List list = new ArrayList(); Map map = new HashMap(); @@ -725,6 +744,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe list.add(map3); this.writing(list); message = "申请任务失败下发退回,"+message; + requireSucess = true; } } @@ -741,20 +761,20 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_param, Integer.parseInt(value)); // itemMap.put(to_param, Integer.parseInt(value)); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(List list) { - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); +// String opcservcerid = this.getDevice().getOpc_server_id(); +// Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); for (int i = 0; i < list.size(); i++) { Object ob = list.get(i); @@ -766,7 +786,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } } logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); - ReadUtil.write(itemMap, server); + this.control(itemMap); } @Override diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_inspect_site/StandardInspectSiteDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_inspect_site/StandardInspectSiteDeviceDriver.java index 032f77abc..fcdd34ce2 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_inspect_site/StandardInspectSiteDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_inspect_site/StandardInspectSiteDeviceDriver.java @@ -343,28 +343,28 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp if (instruction != null) { instruction_num = Integer.parseInt(instruction.getInstruction_code()); } - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, 1); itemMap.put(to_task, instruction_num); - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void executing(Server server, Map itemMap) { - ReadUtil.write(itemMap, server); + this.control(itemMap); } public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_command; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); } @@ -375,8 +375,8 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp + "." + ItemProtocol.item_to_target; String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); if (type == 1) { itemMap.put(to_command, command); @@ -386,7 +386,7 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp } else if (type == 3) { itemMap.put(to_task, command); } - ReadUtil.write(itemMap, server); + this.control(itemMap); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_scanner/StandardScannerDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_scanner/StandardScannerDeviceDriver.java index d36492a8a..a3e5708be 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_scanner/StandardScannerDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_scanner/StandardScannerDeviceDriver.java @@ -12,71 +12,71 @@ import org.nl.acs.socket.SocketConfig; import org.nl.acs.udw.UnifiedDataAccessor; import org.nl.acs.udw.UnifiedDataAccessorFactory; -/** - * 标准版扫码器 - */ +/** 标准版扫码器 */ @Slf4j @Data -public class StandardScannerDeviceDriver extends AbstractDeviceDriver implements ScannerDeviceDriver, DeviceDriver, DeviceStageMonitor { +public class StandardScannerDeviceDriver extends AbstractDeviceDriver + implements ScannerDeviceDriver, DeviceDriver, DeviceStageMonitor { - UnifiedDataAccessor accessor_value; + UnifiedDataAccessor accessor_value; - public StandardScannerDeviceDriver() { - this.accessor_value = UnifiedDataAccessorFactory.getAccessor(SocketConfig.udw_unit_key); + public StandardScannerDeviceDriver() { + this.accessor_value = UnifiedDataAccessorFactory.getAccessor(SocketConfig.udw_unit_key); + } + + public String getIp() { + String ip = (String) this.getDevice().getExtraValue().get("scannerIP"); + return StrUtil.isEmpty(ip) ? null : ip; + } + + @Override + public String readBarcode() { + String ip = this.getIp(); + if (StrUtil.isEmpty(ip)) { + // throw new Exception("ip未配置"); + log.error("ip未配置"); + } else { + String result = (String) this.accessor_value.getValue(this.getIp()); + return result; } + return null; + } - public String getIp() { - String ip = (String) this.getDevice().getExtraValue().get("scannerIP"); - return StrUtil.isEmpty(ip) ? null : ip; + @Override + public void writeBarcode(String barcode) { + String ip = this.getIp(); + if (StrUtil.isEmpty(ip)) { + // throw new Exception("ip未配置"); + log.error("ip未配置"); + } else { + this.accessor_value.setValueWithPersistence(this.getIp(), barcode); } + } - @Override - public String readBarcode() throws Exception { - String ip = this.getIp(); - if (StrUtil.isEmpty(ip)) { - throw new Exception("ip未配置"); - } else { - String result = (String) this.accessor_value.getValue(this.getIp()); - return result; - } + @Override + public void cleanBarcode() { + String ip = this.getIp(); + if (StrUtil.isEmpty(ip)) { + log.error("ip未配置"); + // throw new Exception("ip未配置"); + } else { + this.accessor_value.setValueWithPersistence(this.getIp(), (Object) null); } + } - @Override - public void writeBarcode(String barcode) throws Exception { - String ip = this.getIp(); - if (StrUtil.isEmpty(ip)) { - throw new Exception("ip未配置"); - } else { - this.accessor_value.setValueWithPersistence(this.getIp(), barcode); - } - } + @Override + public JSONObject getDeviceStatusName() throws Exception { + JSONObject jo = new JSONObject(); + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("isOnline", true); + jo.put("device_type", device.getDevice_type()); + // 点击弹出 + jo.put("is_click", true); + jo.put("ip", this.getIp()); + jo.put("container", StrUtil.isEmpty(this.readBarcode()) ? "" : this.readBarcode()); + return jo; + } - @Override - public void cleanBarcode() throws Exception { - String ip = this.getIp(); - if (StrUtil.isEmpty(ip)) { - throw new Exception("ip未配置"); - } else { - this.accessor_value.setValueWithPersistence(this.getIp(), (Object) null); - } - } - - @Override - public JSONObject getDeviceStatusName() throws Exception { - JSONObject jo = new JSONObject(); - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("isOnline", true); - jo.put("device_type", device.getDevice_type()); - //点击弹出 - jo.put("is_click", true); - jo.put("ip", this.getIp()); - jo.put("container", StrUtil.isEmpty(this.readBarcode()) ? "" : this.readBarcode()); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - - } + @Override + public void setDeviceStatus(JSONObject data) {} } - diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java index ebf13e551..a4bbb4819 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java @@ -1,18 +1,114 @@ package org.nl.acs.device_driver.driver; +import com.alibaba.fastjson.JSONObject; +import org.nl.acs.ext.wms.data.JsonUtl; import org.nl.acs.opc.OpcConfig; +import org.nl.acs.opc.OpcServerService; +import org.nl.acs.opc.OpcServerServiceImpl; +import org.nl.acs.opc.WcsConfig; import org.nl.acs.udw.UnifiedDataAccessor; import org.nl.acs.udw.UnifiedDataAccessorFactory; +import org.nl.acs.udw.UnifiedDataAppService; +import org.nl.modules.wql.exception.WDKException; +import org.nl.modules.wql.util.SpringContextHolder; + +import java.util.Date; +import java.util.Iterator; +import java.util.Map; public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements OpcDeviceDriver { - UnifiedDataAccessor opcUdw; + UnifiedDataAccessor opcUdw; - public AbstractOpcDeviceDriver() { - this.opcUdw = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key); + private Date sendTime; + private String last_items; + private int noLog_sendTimeOut; + private Date noLog_sendTime; + private String noLog_last_items; + + public AbstractOpcDeviceDriver() { + this.opcUdw = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key); + } + + @Override + public UnifiedDataAccessor getOpcValueAccessor() { + return this.opcUdw; + } + + public boolean control(Map itemValues) { + + Iterator> it = itemValues.entrySet().iterator(); + + ItemValue p2[]; + p2 = new ItemValue[itemValues.size()]; + int i=0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + System.out.println(entry.getKey() + ":" + entry.getValue()); + p2[i] = new ItemValue(); + p2[i].setItem_code(entry.getKey()); + p2[i].setItem_value(entry.getValue()); + i++; } - @Override - public UnifiedDataAccessor getOpcValueAccessor() { - return this.opcUdw; + return this.control(p2); + } + + + + public boolean control(ItemValue[] itemValues) { + if (itemValues != null && itemValues.length != 0) { + String this_items = JsonUtl.parseWithoutException(itemValues); + boolean need_write = false; + StringBuilder sb = new StringBuilder(); + ItemValue[] var5 = itemValues; + int var6 = itemValues.length; + + for (int var7 = 0; var7 < var6; ++var7) { + ItemValue itemValue = var5[var7]; + String code = itemValue.getItem_code(); + Object udw_value = this.getUdwValue(code); + Object write_value = itemValue.getItem_value(); + sb.append(code); + sb.append(":"); + sb.append(JsonUtl.parseWithoutException(udw_value)); + sb.append(";"); +// if (!need_write && !UnifiedDataAppService.isEquals(udw_value, write_value)) { +// need_write = true; +// } + } + need_write = true; + + if (need_write) { + Date date = new Date(); + /*if (StringUtl.isEqual(this_items, this.last_items) && date.getTime() - this.sendTime.getTime() < (long) WcsConfig.opc_write_repeat_check) { + log.trace("发送时间因为小于{}毫秒,而被无视", WcsConfig.opc_write_repeat_check); + return false; + }*/ + + this.last_items = this_items; + this.sendTime = date; + /* this.execute_log.setResource(this.getDevice().getCode(), this.getDevice().getName()); + this.execute_log.log("原始记录{}->变更为{}", new Object[]{sb, this_items}); + OpcServerService opcServerService = OpcServerFactory.getOpcServerService();*/ + + OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class); + + opcServerService.writeInteger(this.getOpcServer(), itemValues); + UnifiedDataAccessor opcValueAccessor = this.getOpcValueAccessor(); + ItemValue[] var17 = itemValues; + int var18 = itemValues.length; + + for (int var19 = 0; var19 < var18; ++var19) { + ItemValue itemValue = var17[var19]; + String code = itemValue.getItem_code(); + Object value = itemValue.getItem_value(); + opcValueAccessor.setValue(code, value); + } + } + + return true; + } else { + throw new WDKException("下发 无内容"); } + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java index 084880009..743d1e290 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java @@ -1,17 +1,18 @@ package org.nl.acs.device_driver.driver; +import com.esotericsoftware.minlog.Log; import org.nl.acs.device_driver.DeviceDriver; public interface ExecutableDeviceDriver extends DeviceDriver { - default void executeAuto() { - try { - this.execute(); - } catch (Throwable var6) { - String message = "线程调用异常:" + var6.getMessage(); - } finally { - } - + default void executeAuto() { + try { + this.execute(); + } catch (Throwable var6) { + String message = "线程调用异常:" + var6.getMessage(); + Log.error(message); + } finally { } + } - void execute() throws Exception; + void execute(); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ItemValue.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ItemValue.java new file mode 100644 index 000000000..824c76977 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ItemValue.java @@ -0,0 +1,36 @@ +package org.nl.acs.device_driver.driver; + +/** + * @author ldjun + * @version 1.0 + * @date 2023年02月01日 11:21 + * @desc desc + */ +public class ItemValue { + private String item_code; + private Object item_value; + + public ItemValue() { + } + + public ItemValue(String item_code, Object item_value) { + this.item_code = item_code; + this.item_value = item_value; + } + + public String getItem_code() { + return this.item_code; + } + + public void setItem_code(String item_code) { + this.item_code = item_code; + } + + public Object getItem_value() { + return this.item_value; + } + + public void setItem_value(Object item_value) { + this.item_value = item_value; + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java index b955ff6ce..c17be0048 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java @@ -1,6 +1,7 @@ package org.nl.acs.device_driver.driver; +import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.nl.acs.device_driver.DeviceDriver; @@ -62,7 +63,13 @@ public interface OpcDeviceDriver extends DeviceDriver { } default Float getDoubleValue(String protocol) { - return (Float) this.getValue(protocol); + if(ObjectUtil.isEmpty(this.getValue(protocol))){ + return null; + } else { + return Float.valueOf(this.getValue(protocol).toString()); + } +// return Float.valueOf(this.getValue(protocol).toString()); +// return (Float) this.getValue(protocol); } default int[] getIntegeregerArrayValue(String protocol) { @@ -81,4 +88,9 @@ public interface OpcDeviceDriver extends DeviceDriver { return this.getOpcServer() + "." + this.getOpcPlc() + "." + this.getDeviceCode() + "." + item; } + default Object getUdwValue(String protocol) { + return this.getOpcValueAccessor().getValue(protocol); + } + + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/BaseStoreReportRequest.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/BaseStoreReportRequest.java index ad29613b5..ed5e9574f 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/BaseStoreReportRequest.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/BaseStoreReportRequest.java @@ -38,4 +38,7 @@ public class BaseStoreReportRequest { * 移库任务上报 1 已接收 2开始执行3 执行完成 4 起点库位有货被阻挡 5目的点库位无货被阻挡 */ public String state; + + public String robotId; + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java index 84bc2c458..b30190077 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java @@ -5,8 +5,6 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.nl.acs.ext.wms.data.*; -import java.util.Map; - public interface AcsToWmsService { /** @@ -105,5 +103,5 @@ public interface AcsToWmsService { UpdateLKTaskResponse updateLKTaskRequest(UpdateLKTaskRequest updateLKTaskRequest); // 输送线有货变成无货时向lms请求 - void shipDeviceUpdate(JSONObject param); + HttpResponse shipDeviceUpdate(JSONObject param); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java index c84b1e13e..9970c09fa 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java @@ -18,15 +18,11 @@ import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; -import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.system.service.ParamService; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import java.util.Map; - @Service @RequiredArgsConstructor @Slf4j @@ -502,7 +498,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } @Override - public void shipDeviceUpdate(JSONObject param) { + public HttpResponse shipDeviceUpdate(JSONObject param) { try { MDC.put(log_file_type, log_type); log.info("shipDeviceUpdate-----输入参数{}", param); @@ -511,7 +507,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { AddressDto addressDto = addressService.findByCode("shipDeviceUpdate"); String methods_url = addressDto.getMethods_url(); String url = wmsUrl + methods_url; - HttpRequest + return HttpRequest .post(url) .body(param.toString()) .execute(); @@ -521,5 +517,6 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } finally { MDC.remove(log_file_type); } + return null; } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java index edb72c1a8..79149fc11 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java @@ -61,6 +61,7 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { log.info("入库任务状态反馈-----输入参数{}", JSON.toJSONString(requestParam)); String inst_code = requestParam.getOrderId(); String status = requestParam.getState(); + String carNo = requestParam.getRobotId(); Instruction inst = instructionService.findByCodeFromCache(inst_code); TaskDto task = taskService.findByCodeFromCache(inst.getTask_code()); // 1 已接收 2 开始执行 3执行完成 4 5 取消 @@ -68,6 +69,8 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { task.setTask_status("1"); taskService.update(task); inst.setInstruction_status("1"); + inst.setExecute_device_code(carNo); + inst.setCarno(carNo); instructionService.update(inst); } else if(StrUtil.equals(status,"3")){ inst.setInstruction_status("2"); @@ -102,6 +105,7 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { log.info("出库任务状态反馈-----输入参数{}", JSON.toJSONString(requestParam)); String inst_code = requestParam.getOrderId(); String status = requestParam.getState(); + String carNo = requestParam.getRobotId(); Instruction inst = instructionService.findByCodeFromCache(inst_code); TaskDto task = taskService.findByCodeFromCache(inst.getTask_code()); @@ -110,6 +114,8 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { task.setTask_status("1"); taskService.update(task); inst.setInstruction_status("1"); + inst.setExecute_device_code(carNo); + inst.setCarno(carNo); instructionService.update(inst); } else if(StrUtil.equals(status,"3")){ inst.setInstruction_status("2"); @@ -148,6 +154,7 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { log.info("移库任务上报-----输入参数{}", JSON.toJSONString(requestParam)); String inst_code = requestParam.getOrderId(); String status = requestParam.getState(); + String carNo = requestParam.getRobotId(); Instruction inst = instructionService.findByCodeFromCache(inst_code); TaskDto task = taskService.findByCodeFromCache(inst.getTask_code()); // 1 已接收 2 开始执行 3执行完成 4 阻挡 5 空洞 @@ -155,6 +162,8 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { task.setTask_status("1"); taskService.update(task); inst.setInstruction_status("1"); + inst.setExecute_device_code(carNo); + inst.setCarno(carNo); instructionService.update(inst); } else if(StrUtil.equals(status,"3")){ @@ -210,6 +219,8 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { } } else if(StrUtil.equals(type,"2")){ siemensConveyorDeviceDriver.writing("to_command","3"); + siemensConveyorDeviceDriver.writing("to_command","3"); + result.put("result", "true"); result.put("comment", ""); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index 2e1fe6208..2ab2c8efe 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -188,7 +188,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { public Map queryDevice(String jsonObject) throws Exception { try { MDC.put(log_file_type, log_type); - log.info("queryDevice--------------:输入参数" + jsonObject.toString()); +// log.info("queryDevice--------------:输入参数" + jsonObject.toString()); JSONArray backja = new JSONArray(); JSONArray datas = JSONArray.parseArray(jsonObject); @@ -252,7 +252,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { resultJson.put("status", HttpStatus.OK.value()); resultJson.put("message", "操作成功"); resultJson.put("data", backja); - log.info("queryDevice--------------:输出参数" + resultJson.toString()); +// log.info("queryDevice--------------:输出参数" + resultJson.toString()); return resultJson; } finally { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/rest/InstructionController.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/rest/InstructionController.java index 841741cf1..050de45fa 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/rest/InstructionController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/rest/InstructionController.java @@ -2,6 +2,7 @@ package org.nl.acs.instruction.rest; +import cn.dev33.satoken.annotation.SaIgnore; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -132,6 +133,7 @@ public class InstructionController { return new ResponseEntity<>(instructionService.findByCodeFromCache(id), HttpStatus.OK); } + @SaIgnore @Log("查询缓存所有指令") @ApiOperation("查询缓存指令") @PostMapping(value = "/findAllInstFromCache") @@ -145,4 +147,12 @@ public class InstructionController { public ResponseEntity queryByTaskId(@RequestBody String taskId) { return new ResponseEntity<>(instructionService.getByTaskId(taskId), HttpStatus.OK); } + + @Log("初始化") + @ApiOperation("初始化") + @PostMapping(value = "/init/{id}") + public ResponseEntity init(@RequestBody String id) throws Exception { + instructionService.init(id); + return new ResponseEntity<>(HttpStatus.OK); + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java index 107f5c395..203e45e51 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java @@ -110,7 +110,7 @@ public interface InstructionService { * @param dto * @throws Exception */ - void createAgain(Instruction dto) throws Exception; + void createAgain(Instruction dto) throws Exception ; /** * 编辑 @@ -275,4 +275,5 @@ public interface InstructionService { boolean createLkInst(String type,Instruction inst); + void init(String id); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index 34198859d..aa00242ee 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -17,8 +17,10 @@ import org.nl.acs.agv.server.*; import org.nl.acs.auto.initial.ApplicationAutoInitial; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device.service.impl.DeviceServiceImpl; +import org.nl.acs.device_driver.DeviceDriver; import org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.CargoLiftConveyorDeviceDriver; import org.nl.acs.device_driver.basedriver.hongxiang_device.HongXiangConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_storage.StandardStorageDeviceDriver; @@ -33,6 +35,7 @@ import org.nl.acs.opc.DeviceAppServiceImpl; import org.nl.acs.route.service.RouteLineService; import org.nl.acs.route.service.dto.RouteLineDto; import org.nl.acs.route.service.impl.RouteLineServiceImpl; +import org.nl.acs.task.TaskInstructionLock; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; import org.nl.modules.common.exception.BadRequestException; @@ -226,6 +229,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu public Instruction findByCode(String code) { WQLObject wo = WQLObject.getWQLObject("acs_instruction"); JSONObject json = wo.query("instruction_code ='" + code + "'").uniqueResult(0); + if (ObjectUtil.isEmpty(json)){ + return null; + } final Instruction obj = json.toJavaObject(Instruction.class); return obj; } @@ -265,286 +271,294 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu } @Override - public void create(Instruction dto) throws Exception { - dto = foramte(dto); - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); + public void create(Instruction dto) { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + dto = foramte(dto); + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); - WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getPriority())) { - dto.setPriority(task.getPriority()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - if (StrUtil.isEmpty(dto.getIs_send())) { - dto.setIs_send(task.getIs_send()); - } - if (StrUtil.isEmpty(dto.getLink_num())) { - dto.setIs_send(task.getLink_num()); - } - if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { - dto.setInstruction_type(task.getTask_type()); - } else if (false) { - - } else { - dto.setInstruction_type("3"); - } - - - //起点设备与终点设备相同则为初始指令 - if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { - if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) { - dto.setCompound_inst("1"); - dto.setCompound_inst_data(task.getCompound_task_data()); + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); } - } + if (StrUtil.isEmpty(dto.getPriority())) { + dto.setPriority(task.getPriority()); + } + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); + } + if (StrUtil.isEmpty(dto.getIs_send())) { + dto.setIs_send(task.getIs_send()); + } + if (StrUtil.isEmpty(dto.getLink_num())) { + dto.setIs_send(task.getLink_num()); + } + if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { + dto.setInstruction_type(task.getTask_type()); + } else if (false) { - dto.setCreate_by(currentUsername); - dto.setUpdate_by(currentUsername); - dto.setUpdate_time(now); - dto.setCreate_time(now); - dto.setStart_parent_code(task.getStart_parent_code()); - dto.setNext_parent_code(task.getNext_parent_code()); + } else { + dto.setInstruction_type("3"); + } - if (ObjectUtil.isNotEmpty(task.getTask_type())) { - dto.setInstruction_type(task.getTask_type()); - } - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); - Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); - - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - - if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); - } - - try { - String start_device_code = dto.getStart_device_code(); - String next_device_code = dto.getNext_device_code(); - String route_plan_code = task.getRoute_plan_code(); - List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - RouteLineDto route = null; - for (int i = 0; i < shortPathsList.size(); i++) { - RouteLineDto routeLineDto = shortPathsList.get(i); - String route_device = routeLineDto.getDevice_code(); - String route_next_device = routeLineDto.getNext_device_code(); - if (route_device.equals(dto.getStart_device_code()) && route_next_device.equals(dto.getNext_device_code())) { - route = routeLineDto; - break; + //起点设备与终点设备相同则为初始指令 + if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { + if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); } } - if (ObjectUtil.isEmpty(route)) { - throw new BadRequestException("未查询到相关路由!"); + + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + dto.setStart_parent_code(task.getStart_parent_code()); + dto.setNext_parent_code(task.getNext_parent_code()); + + if (ObjectUtil.isNotEmpty(task.getTask_type())) { + dto.setInstruction_type(task.getTask_type()); } - if (StrUtil.equals(shortPathsList.get(0).getType(), "1")){ - // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 - if (!StrUtil.equals(task.getAgv_system_type(), "0") && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { - NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); - ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(),dto); - } else { - // Boolean result = createLkInst(task.getStorage_task_type(),dto); - Resp resp = acsToLiKuService.sendInst(task.getStorage_task_type(),dto); - if(StrUtil.equals(resp.result,"true")){ - dto.setSend_status("1"); - } else { - dto.setSend_status("2"); + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); + + HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; + StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; + + if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { + hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); + hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); + } + + try { + String start_device_code = dto.getStart_device_code(); + String next_device_code = dto.getNext_device_code(); + String route_plan_code = task.getRoute_plan_code(); + List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + RouteLineDto route = null; + for (int i = 0; i < shortPathsList.size(); i++) { + RouteLineDto routeLineDto = shortPathsList.get(i); + String route_device = routeLineDto.getDevice_code(); + String route_next_device = routeLineDto.getNext_device_code(); + if (route_device.equals(dto.getStart_device_code()) && route_next_device.equals(dto.getNext_device_code())) { + route = routeLineDto; + break; } } + if (ObjectUtil.isEmpty(route)) { + throw new BadRequestException("未查询到相关路由!"); + } + if (StrUtil.equals(shortPathsList.get(0).getType(), "1")){ + // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 + if (!StrUtil.equals(task.getAgv_system_type(), "0") && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); + ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(),dto); + } else { + // Boolean result = createLkInst(task.getStorage_task_type(),dto); + Resp resp = acsToLiKuService.sendInst(task.getStorage_task_type(),dto); + if(StrUtil.equals(resp.result,"true")){ + dto.setSend_status("1"); + } else { + dto.setSend_status("2"); + } + } + } + } catch (Exception e) { + dto.setSend_status("2"); + e.printStackTrace(); + log.error(""); } - } catch (Exception e) { - dto.setSend_status("2"); - e.printStackTrace(); + + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + instructions.add(dto); } - - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.insert(json); - instructions.add(dto); } @Override public void create2(Instruction dto) throws Exception { - dto = foramte(dto); - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + dto = foramte(dto); + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); - WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getPriority())) { - dto.setPriority(task.getPriority()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - if (StrUtil.isEmpty(dto.getIs_send())) { - dto.setIs_send(task.getIs_send()); - } - if (StrUtil.isEmpty(dto.getLink_num())) { - dto.setIs_send(task.getLink_num()); - } - if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { - dto.setInstruction_type(task.getTask_type()); - } else if (false) { - - } else { - dto.setInstruction_type("3"); - } - - - //起点设备与终点设备相同则为初始指令 - if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { - if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) { - dto.setCompound_inst("1"); - dto.setCompound_inst_data(task.getCompound_task_data()); + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); } - } + if (StrUtil.isEmpty(dto.getPriority())) { + dto.setPriority(task.getPriority()); + } + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); + } + if (StrUtil.isEmpty(dto.getIs_send())) { + dto.setIs_send(task.getIs_send()); + } + if (StrUtil.isEmpty(dto.getLink_num())) { + dto.setIs_send(task.getLink_num()); + } + if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { + dto.setInstruction_type(task.getTask_type()); + } else if (false) { - dto.setCreate_by(currentUsername); - dto.setUpdate_by(currentUsername); - dto.setUpdate_time(now); - dto.setCreate_time(now); - dto.setStart_parent_code(task.getStart_parent_code()); - dto.setNext_parent_code(task.getNext_parent_code()); + } else { + dto.setInstruction_type("3"); + } - if (ObjectUtil.isNotEmpty(task.getTask_type())) { - dto.setInstruction_type(task.getTask_type()); - } - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); - Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); - - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - - if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); - } - - try { - String start_device_code = dto.getStart_device_code(); - String next_device_code = dto.getNext_device_code(); - String route_plan_code = task.getRoute_plan_code(); - List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - RouteLineDto route = null; - for (int i = 0; i < shortPathsList.size(); i++) { - RouteLineDto routeLineDto = shortPathsList.get(i); - String route_device = routeLineDto.getDevice_code(); - String route_next_device = routeLineDto.getNext_device_code(); - if (route_device.equals(dto.getStart_device_code()) && route_next_device.equals(dto.getNext_device_code())) { - route = routeLineDto; - break; + //起点设备与终点设备相同则为初始指令 + if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { + if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); } } - if (ObjectUtil.isEmpty(route)) { - throw new BadRequestException("未查询到相关路由!"); + + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + dto.setStart_parent_code(task.getStart_parent_code()); + dto.setNext_parent_code(task.getNext_parent_code()); + + if (ObjectUtil.isNotEmpty(task.getTask_type())) { + dto.setInstruction_type(task.getTask_type()); } - if (StrUtil.equals(shortPathsList.get(0).getType(), "1")){ - // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 - if (!StrUtil.equals(task.getAgv_system_type(), "0") && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { - NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); - ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(),dto); - } else { + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); + + HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; + StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; + + if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { + hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); + hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); + } + + try { + String start_device_code = dto.getStart_device_code(); + String next_device_code = dto.getNext_device_code(); + String route_plan_code = task.getRoute_plan_code(); + List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + RouteLineDto route = null; + for (int i = 0; i < shortPathsList.size(); i++) { + RouteLineDto routeLineDto = shortPathsList.get(i); + String route_device = routeLineDto.getDevice_code(); + String route_next_device = routeLineDto.getNext_device_code(); + if (route_device.equals(dto.getStart_device_code()) && route_next_device.equals(dto.getNext_device_code())) { + route = routeLineDto; + break; + } + } + if (ObjectUtil.isEmpty(route)) { + throw new BadRequestException("未查询到相关路由!"); + } + if (StrUtil.equals(shortPathsList.get(0).getType(), "1")){ + // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 + if (!StrUtil.equals(task.getAgv_system_type(), "0") && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); + ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(),dto); + } else { // Boolean result = createLkInst(task.getStorage_task_type(),dto); + } } + } catch (Exception e) { + dto.setSend_status("2"); + e.printStackTrace(); } - } catch (Exception e) { - dto.setSend_status("2"); - e.printStackTrace(); + + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + instructions.add(dto); } - - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.insert(json); - instructions.add(dto); } @Override - @Transactional(rollbackFor = Exception.class) public void createAgain(Instruction dto) throws Exception { - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); - WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - List shortPathsList = routeLineService.getShortPathLines(dto.getStart_device_code(), dto.getNext_device_code(), dto.getRoute_plan_code()); - if (ObjectUtils.isEmpty(shortPathsList)) { - throw new Exception(dto.getStart_device_code() + "->" + dto.getNext_device_code() + "路由不通"); - } - String type = shortPathsList.get(0).getType(); - if (!StrUtil.equals(type, "0")) { - JSONObject instcheckjson = instwo.query(" instruction_status <3 and next_point_code= '" + dto.getNext_point_code() + "'" + " and start_point_code = '" + dto.getStart_point_code() + "'" + " and task_id = '" + dto.getTask_id() + "'").uniqueResult(0); - if (instcheckjson != null) { - throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); + } + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); + } + List shortPathsList = routeLineService.getShortPathLines(dto.getStart_device_code(), dto.getNext_device_code(), dto.getRoute_plan_code()); + if (ObjectUtils.isEmpty(shortPathsList)) { + throw new Exception(dto.getStart_device_code() + "->" + dto.getNext_device_code() + "路由不通"); + } + String type = shortPathsList.get(0).getType(); + if (!StrUtil.equals(type, "0")) { + JSONObject instcheckjson = instwo.query(" instruction_status <3 and next_point_code= '" + dto.getNext_point_code() + "'" + " and start_point_code = '" + dto.getStart_point_code() + "'" + " and task_id = '" + dto.getTask_id() + "'").uniqueResult(0); + if (instcheckjson != null) { + throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); + } } - } - if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) { - dto.setCompound_inst("1"); - dto.setCompound_inst_data(task.getCompound_task_data()); - } + if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); + } - dto.setCreate_by(currentUsername); - dto.setUpdate_by(currentUsername); - dto.setUpdate_time(now); - dto.setCreate_time(now); + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); - wo.insert(json); + wo.insert(json); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); - Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; + StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - if (!ObjectUtils.isEmpty(nextdevice.getExtraValue().get("link_three_lamp"))) { - String lamd_device = nextdevice.getExtraValue().get("link_three_lamp").toString(); - Device lamddevice = appService.findDeviceByCode(lamd_device); + if (!ObjectUtils.isEmpty(nextdevice.getExtraValue().get("link_three_lamp"))) { + String lamd_device = nextdevice.getExtraValue().get("link_three_lamp").toString(); + Device lamddevice = appService.findDeviceByCode(lamd_device); - } + } - // != 0 为agv任务 + // != 0 为agv任务 // if(!StrUtil.equals(type,"0")){ // if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1")) { // agvService.sendAgvInstToMagic(dto); @@ -554,33 +568,36 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu // agvService.addOrderSequences(dto); // } // } - instructions.add(dto); + instructions.add(dto); + } } @Override @Transactional(rollbackFor = Exception.class) public void update(Instruction dto) { - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - dto.setUpdate_time(now); - dto.setUpdate_by(currentUsername); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); - wo.update(json); + wo.update(json); - Iterator iterator = instructions.iterator(); - while (iterator.hasNext()) { - Instruction instruction = iterator.next(); - if (instruction.getInstruction_code().equals(dto.getInstruction_code())) { - iterator.remove(); - } +// Iterator iterator = instructions.iterator(); +// while (iterator.hasNext()) { +// Instruction instruction = iterator.next(); +// if (instruction.getInstruction_code().equals(dto.getInstruction_code())) { +// iterator.remove(); +// } +// } +// if (StrUtil.equals(dto.getInstruction_status(), "0") || StrUtil.equals(dto.getInstruction_status(), "1")) { +// instructions.add(dto); +// } + this.reload(); } - if (StrUtil.equals(dto.getInstruction_status(), "0") || StrUtil.equals(dto.getInstruction_status(), "1")) { - instructions.add(dto); - } - - } @Override @@ -635,7 +652,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override @Transactional(rollbackFor = Exception.class) - public void finish(String id) throws Exception { + public void finish(String id) { Instruction entity = this.findById(id); //if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); String currentUsername = SecurityUtils.getCurrentUsername(); @@ -712,66 +729,70 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu } removeByCodeFromCache(entity.getInstruction_code()); + this.reload(); } @Override @Transactional(rollbackFor = Exception.class) - public void finish(Instruction dto) throws Exception { - String now = DateUtil.now(); - dto.setInstruction_status("2"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); + public void finish(Instruction dto) { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + String now = DateUtil.now(); + dto.setInstruction_status("2"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); - wo.update(json); - String instnextdevice = dto.getNext_device_code(); - String insttaskid = dto.getTask_id(); - WQLObject taskwo = WQLObject.getWQLObject("acs_task"); - JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0); - TaskDto obj = taskjson.toJavaObject(TaskDto.class); - // =0 则不用再次请求 - if (StrUtil.equals(obj.getRequest_again(), "0")) { - if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { - taskService.finish(obj.getTask_id()); - } else { - finishAndCreateNextInst(dto); + wo.update(json); + String instnextdevice = dto.getNext_device_code(); + String insttaskid = dto.getTask_id(); + WQLObject taskwo = WQLObject.getWQLObject("acs_task"); + JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0); + TaskDto obj = taskjson.toJavaObject(TaskDto.class); + // =0 则不用再次请求 + if (StrUtil.equals(obj.getRequest_again(), "0")) { + if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { + taskService.finish(obj.getTask_id()); + } else { + finishAndCreateNextInst(dto); + } } - } - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - // 如果是无光电的设备 放货任务完成需要变更有货状态 + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + // 如果是无光电的设备 放货任务完成需要变更有货状态 // StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; // if(device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { // standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); // standardOrdinarySiteDeviceDriver.setMove(2); // } - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", dto.getStart_point_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - deviceService.changeDeviceStatus(jo); + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", dto.getStart_point_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + deviceService.changeDeviceStatus(jo); - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", dto.getNext_point_code()); - jo1.put("hasGoodStatus", "1"); - jo1.put("material_type", dto.getMaterial()); - jo1.put("batch", dto.getBatch()); - deviceService.changeDeviceStatus(jo1); - - removeByCodeFromCache(dto.getInstruction_code()); + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", dto.getNext_point_code()); + jo1.put("hasGoodStatus", "1"); + jo1.put("material_type", dto.getMaterial()); + jo1.put("batch", dto.getBatch()); + deviceService.changeDeviceStatus(jo1); + removeByCodeFromCache(dto.getInstruction_code()); + this.reload(); + } } @Override - public void finishAndCreateNextInst(Instruction dto) throws Exception { + public void finishAndCreateNextInst(Instruction dto){ dto = foramte(dto); String device_code = dto.getNext_device_code(); WQLObject taskwo = WQLObject.getWQLObject("acs_task"); @@ -827,70 +848,196 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu instdto.setPriority(acsTask.getPriority()); instdto.setInstruction_status("0"); instdto.setExecute_device_code(dto.getNext_device_code()); - this.create(instdto); + try { + this.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("完成并创建下一条指令",e.getMessage()); + } } @Override public void cancel(String id) throws Exception { - //flag= true时取消指令 - boolean flag = false; - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); - } + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + //flag= true时取消指令 + boolean flag = false; + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); + } - // != 0 为agv任务 1=magic 2=NDC 3=XZ,4=ZHEDA - if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1") - && !StrUtil.equals(entity.getSend_status(), "2")) { - MagicAgvService magicAgvService = SpringContextHolder.getBean(MagicAgvService.class); - magicAgvService.deleteAgvInst(entity.getInstruction_code()); - flag = true; + // != 0 为agv任务 1=magic 2=NDC 3=XZ,4=ZHEDA + if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1") + && !StrUtil.equals(entity.getSend_status(), "2")) { + MagicAgvService magicAgvService = SpringContextHolder.getBean(MagicAgvService.class); + magicAgvService.deleteAgvInst(entity.getInstruction_code()); + flag = true; - } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { - //NDC agv指令不当场取消指令,需要等agv上报 - if (!StrUtil.isEmpty(entity.getAgv_jobno())) { - ndcAgvService.deleteAgvInstToNDC(entity); + } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { + //NDC agv指令不当场取消指令,需要等agv上报 + if (!StrUtil.isEmpty(entity.getAgv_jobno())) { + ndcAgvService.deleteAgvInstToNDC(entity); + } else { + flag = true; + } + } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3") + && !StrUtil.equals(entity.getSend_status(), "2")) { + XianGongAgvService xianGongAgvService = SpringContextHolder.getBean(XianGongAgvService.class); + xianGongAgvService.deleteXZAgvInst(entity.getInstruction_code()); + flag = true; } else { flag = true; } - } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3") - && !StrUtil.equals(entity.getSend_status(), "2")) { - XianGongAgvService xianGongAgvService = SpringContextHolder.getBean(XianGongAgvService.class); - xianGongAgvService.deleteXZAgvInst(entity.getInstruction_code()); - flag = true; - } else { - flag = true; + + if (flag) { + + if(StrUtil.equals(entity.getInstruction_type(),"7")){ + CancelTaskRequest cancelTaskRequest = new CancelTaskRequest(); + cancelTaskRequest.setOrderId(entity.getInstruction_code()); + cancelTaskRequest.setPalletCode(entity.getVehicle_code()); + cancelTaskRequest.setSrcLocation(entity.getStart_point_code()); + cancelTaskRequest.setDestLocation(entity.getNext_point_code()); + //1 入库,2 出库,3 移库,4 空托盘入库,5 空托盘出库 + int type = 0; + if(StrUtil.equals(task.getStorage_task_type(),"1")){ + type = 1; + } else if (StrUtil.equals(task.getStorage_task_type(),"2")){ + type = 4; + } else if (StrUtil.equals(task.getStorage_task_type(),"3")){ + type = 2; + } else if (StrUtil.equals(task.getStorage_task_type(),"4")){ + type = 5; + } else if (StrUtil.equals(task.getStorage_task_type(),"5")){ + type = 3; + } + cancelTaskRequest.setTaskType(type); + acsToLiKuService.cancelTask(cancelTaskRequest); + } + + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + if (StrUtil.equals(entity.getMaterial(), "1")) { + jo.put("hasGoodStatus", "1"); + } else if (!StrUtil.equals(entity.getMaterial(), "1") && !StrUtil.isEmpty(entity.getMaterial())) { + jo.put("hasGoodStatus", "2"); + } else { + jo.put("hasGoodStatus", "0"); + } + jo.put("material_type", entity.getMaterial()); + jo.put("batch", entity.getBatch()); + jo.put("islock", "false"); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", entity.getNext_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + jo1.put("islock", "false"); + deviceService.changeDeviceStatus(jo1); + + String instnextdevice = entity.getNext_device_code(); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + removeByCodeFromCache(entity.getInstruction_code()); + } + this.reload(); + } + } + + @Override + public void forceCancel(String id) throws Exception { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + //flag= true时取消指令 + boolean flag = false; + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); + } + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + if (StrUtil.equals(entity.getMaterial(), "1")) { + jo.put("hasGoodStatus", "1"); + } else if (!StrUtil.equals(entity.getMaterial(), "1") && !StrUtil.isEmpty(entity.getMaterial())) { + jo.put("hasGoodStatus", "2"); + } else { + jo.put("hasGoodStatus", "0"); + } + jo.put("material_type", entity.getMaterial()); + jo.put("batch", entity.getBatch()); + jo.put("islock", "false"); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", entity.getNext_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + jo1.put("islock", "false"); + deviceService.changeDeviceStatus(jo1); + + String instnextdevice = entity.getNext_device_code(); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + removeByCodeFromCache(entity.getInstruction_code()); } - if (flag) { + } - if(StrUtil.equals(entity.getInstruction_type(),"7")){ - CancelTaskRequest cancelTaskRequest = new CancelTaskRequest(); - cancelTaskRequest.setOrderId(entity.getInstruction_code()); - cancelTaskRequest.setPalletCode(entity.getVehicle_code()); - cancelTaskRequest.setSrcLocation(entity.getStart_point_code()); - cancelTaskRequest.setDestLocation(entity.getNext_point_code()); - //1 入库,2 出库,3 移库,4 空托盘入库,5 空托盘出库 - int type = 0; - if(StrUtil.equals(task.getStorage_task_type(),"1")){ - type = 1; - } else if (StrUtil.equals(task.getStorage_task_type(),"2")){ - type = 4; - } else if (StrUtil.equals(task.getStorage_task_type(),"3")){ - type = 2; - } else if (StrUtil.equals(task.getStorage_task_type(),"4")){ - type = 5; - } else if (StrUtil.equals(task.getStorage_task_type(),"5")){ - type = 3; - } - cancelTaskRequest.setTaskType(type); - acsToLiKuService.cancelTask(cancelTaskRequest); + + @Override + public void cancelNOSendAgv(String id) throws Exception { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + //flag= true时取消指令 + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); } - String currentUsername = SecurityUtils.getCurrentUsername(); String now = DateUtil.now(); @@ -932,120 +1079,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu log.debug("地址对应设备未找到"); return; } + removeByCodeFromCache(entity.getInstruction_code()); } - - } - @Override - public void forceCancel(String id) throws Exception { - //flag= true时取消指令 - boolean flag = false; - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); - } - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - if (StrUtil.equals(entity.getMaterial(), "1")) { - jo.put("hasGoodStatus", "1"); - } else if (!StrUtil.equals(entity.getMaterial(), "1") && !StrUtil.isEmpty(entity.getMaterial())) { - jo.put("hasGoodStatus", "2"); - } else { - jo.put("hasGoodStatus", "0"); - } - jo.put("material_type", entity.getMaterial()); - jo.put("batch", entity.getBatch()); - jo.put("islock", "false"); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", entity.getNext_device_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - jo1.put("islock", "false"); - deviceService.changeDeviceStatus(jo1); - - String instnextdevice = entity.getNext_device_code(); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - removeByCodeFromCache(entity.getInstruction_code()); - } - - - @Override - public void cancelNOSendAgv(String id) throws Exception { - //flag= true时取消指令 - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); - } - - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - if (StrUtil.equals(entity.getMaterial(), "1")) { - jo.put("hasGoodStatus", "1"); - } else if (!StrUtil.equals(entity.getMaterial(), "1") && !StrUtil.isEmpty(entity.getMaterial())) { - jo.put("hasGoodStatus", "2"); - } else { - jo.put("hasGoodStatus", "0"); - } - jo.put("material_type", entity.getMaterial()); - jo.put("batch", entity.getBatch()); - jo.put("islock", "false"); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", entity.getNext_device_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - jo1.put("islock", "false"); - deviceService.changeDeviceStatus(jo1); - - String instnextdevice = entity.getNext_device_code(); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - - removeByCodeFromCache(entity.getInstruction_code()); - } @@ -1181,8 +1217,15 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByDeviceCodeFromCache(String devicecode) { - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); + List instructionList = instructions; + Collections.sort(instructionList, new Comparator() { + @Override + public int compare(Instruction o1, Instruction o2) { + return o1.getCreate_time().compareTo(o2.getCreate_time()); + } + }); + for (int i = 0; i < instructionList.size(); i++) { + Instruction inst = instructionList.get(i); if (StrUtil.equals(devicecode, inst.getStart_device_code()) && inst.getInstruction_status().equals("0")) { return inst; } @@ -1259,83 +1302,84 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public boolean createLkInst(String type, Instruction dto) { - //入库 - AcsToLiKuService acsToLiKuService = SpringContextHolder.getBean(AcsToLiKuService.class); - Resp resp = null; - if(StrUtil.equals(type,"1")){ - InStoreRequest request = new InStoreRequest(); - request.setFloorNo(Integer.parseInt(dto.getTo_z())); - request.setType(1); - request.setPalletCode(dto.getVehicle_code()); - request.setOrderId(dto.getInstruction_code()); - request.setSrcLocation(dto.getStart_point_code()); - request.setDestLocation(dto.getNext_point_code()); - resp = acsToLiKuService.inStore(request); - //空托入库 - } else if (StrUtil.equals(type,"2")){ - InStoreRequest request = new InStoreRequest(); - request.setFloorNo(Integer.parseInt(dto.getTo_z())); - request.setType(2); - request.setPalletCode(dto.getVehicle_code()); - request.setOrderId(dto.getInstruction_code()); - request.setSrcLocation(dto.getStart_point_code()); - request.setDestLocation(dto.getNext_point_code()); - resp = acsToLiKuService.inStore(request); - //出库 - } else if (StrUtil.equals(type,"3")){ - OutStoreRequest outStore = new OutStoreRequest(); - BaseStoreRequest baseReq = new BaseStoreRequest(); - List list = new ArrayList(); - baseReq.setOrderId(dto.getInstruction_code()); - baseReq.setSrcLocation(dto.getStart_point_code()); - baseReq.setDestLocation(dto.getNext_point_code()); - baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); - baseReq.setPalletCode(dto.getVehicle_code()); - list.add(baseReq); - outStore.setOrderInfos(list); - outStore.setGroupId(dto.getInstruction_code()); - resp = acsToLiKuService.outStore(outStore); - //空托出库 - } else if (StrUtil.equals(type,"4")) { - EmptyVehicleOutStoreRequest emptyVehicleOutStoreRequest = new EmptyVehicleOutStoreRequest(); - emptyVehicleOutStoreRequest.setOrderId(dto.getInstruction_code()); - emptyVehicleOutStoreRequest.setFloorNo(Integer.parseInt(dto.getFrom_z())); - emptyVehicleOutStoreRequest.setSrcLocation(dto.getStart_point_code()); - emptyVehicleOutStoreRequest.setDestLocation(dto.getNext_point_code()); - emptyVehicleOutStoreRequest.setPalletCode(dto.getVehicle_code()); - resp = acsToLiKuService.emptyVehicleOutStore(emptyVehicleOutStoreRequest); - //转库 - } else if (StrUtil.equals(type,"5")) { - MoveStoreRequest moveStoreRequest = new MoveStoreRequest(); - BaseStoreRequest baseReq = new BaseStoreRequest(); - List list = new ArrayList(); - baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); - baseReq.setPalletCode(dto.getVehicle_code()); - baseReq.setOrderId(dto.getInstruction_code()); - baseReq.setSrcLocation(dto.getStart_point_code()); - baseReq.setDestLocation(dto.getNext_point_code()); - list.add(baseReq); - moveStoreRequest.setGroupId(dto.getInstruction_code()); - moveStoreRequest.setOrderInfos(list); - resp = acsToLiKuService.moveStore(moveStoreRequest); - } + Class var3 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + //入库 + AcsToLiKuService acsToLiKuService = SpringContextHolder.getBean(AcsToLiKuService.class); + Resp resp = null; + if(StrUtil.equals(type,"1")){ + InStoreRequest request = new InStoreRequest(); + request.setFloorNo(Integer.parseInt(dto.getTo_z())); + request.setType(1); + request.setPalletCode(dto.getVehicle_code()); + request.setOrderId(dto.getInstruction_code()); + request.setSrcLocation(dto.getStart_point_code()); + request.setDestLocation(dto.getNext_point_code()); + resp = acsToLiKuService.inStore(request); + //空托入库 + } else if (StrUtil.equals(type,"2")){ + InStoreRequest request = new InStoreRequest(); + request.setFloorNo(Integer.parseInt(dto.getTo_z())); + request.setType(2); + request.setPalletCode(dto.getVehicle_code()); + request.setOrderId(dto.getInstruction_code()); + request.setSrcLocation(dto.getStart_point_code()); + request.setDestLocation(dto.getNext_point_code()); + resp = acsToLiKuService.inStore(request); + //出库 + } else if (StrUtil.equals(type,"3")){ + OutStoreRequest outStore = new OutStoreRequest(); + BaseStoreRequest baseReq = new BaseStoreRequest(); + List list = new ArrayList(); + baseReq.setOrderId(dto.getInstruction_code()); + baseReq.setSrcLocation(dto.getStart_point_code()); + baseReq.setDestLocation(dto.getNext_point_code()); + baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); + baseReq.setPalletCode(dto.getVehicle_code()); + list.add(baseReq); + outStore.setOrderInfos(list); + outStore.setGroupId(dto.getInstruction_code()); + resp = acsToLiKuService.outStore(outStore); + //空托出库 + } else if (StrUtil.equals(type,"4")) { + EmptyVehicleOutStoreRequest emptyVehicleOutStoreRequest = new EmptyVehicleOutStoreRequest(); + emptyVehicleOutStoreRequest.setOrderId(dto.getInstruction_code()); + emptyVehicleOutStoreRequest.setFloorNo(Integer.parseInt(dto.getFrom_z())); + emptyVehicleOutStoreRequest.setSrcLocation(dto.getStart_point_code()); + emptyVehicleOutStoreRequest.setDestLocation(dto.getNext_point_code()); + emptyVehicleOutStoreRequest.setPalletCode(dto.getVehicle_code()); + resp = acsToLiKuService.emptyVehicleOutStore(emptyVehicleOutStoreRequest); + //转库 + } else if (StrUtil.equals(type,"5")) { + MoveStoreRequest moveStoreRequest = new MoveStoreRequest(); + BaseStoreRequest baseReq = new BaseStoreRequest(); + List list = new ArrayList(); + baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); + baseReq.setPalletCode(dto.getVehicle_code()); + baseReq.setOrderId(dto.getInstruction_code()); + baseReq.setSrcLocation(dto.getStart_point_code()); + baseReq.setDestLocation(dto.getNext_point_code()); + list.add(baseReq); + moveStoreRequest.setGroupId(dto.getInstruction_code()); + moveStoreRequest.setOrderInfos(list); + resp = acsToLiKuService.moveStore(moveStoreRequest); + } - if(ObjectUtil.isNotEmpty(resp)){ - if(StrUtil.equals(resp.getResult(),"true")){ - dto.setSend_status("1"); + if(ObjectUtil.isNotEmpty(resp)){ + if(StrUtil.equals(resp.getResult(),"true")){ + dto.setSend_status("1"); + } else { + dto.setSend_status("2"); + dto.setRemark(resp.getData().toString()); + return false; + } } else { dto.setSend_status("2"); - dto.setRemark(resp.getData().toString()); + dto.setRemark("ERROR"); return false; } - } else { - dto.setSend_status("2"); - dto.setRemark("ERROR"); - return false; + return true; } - - - return true; } @@ -1361,4 +1405,36 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); return pattern.matcher(str).matches(); } + + @Override + public void init(String id) { + Instruction inst = this.findById(id); + if (inst == null) { + throw new BadRequestException("指令不存在或已删除"); + } + if ("2".equals(inst.getInstruction_status())) { + throw new BadRequestException("指令已经完成"); + } + + Device startDevice = deviceAppService.findDeviceByCode(inst.getStart_device_code()); + DeviceDriver startDeviceDriver = startDevice.getDeviceDriver(); + if (startDeviceDriver instanceof SiemensConveyorDeviceDriver) { + Device nextDevice = deviceAppService.findDeviceByCode(inst.getNext_device_code()); + + List> list = new ArrayList<>(); + Map map = new HashMap<>(); + map.put("code", "to_target"); + map.put("value", nextDevice.getExtraValue().get("address").toString()); + list.add(map); + Map map2 = new HashMap<>(); + map2.put("code", "to_task"); + map2.put("value", inst.getInstruction_code()); + list.add(map2); + Map map3 = new HashMap<>(); + map3.put("code", "to_command"); + map3.put("value", "1"); + list.add(map3); + ((SiemensConveyorDeviceDriver) startDeviceDriver).writing(list); + } + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index 2b118bb52..2c06c54c7 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -15,193 +15,205 @@ import java.util.*; @Slf4j public class DeviceOpcProtocolRunable implements Runnable { - List protocols; - OpcServerManageDto OpcServer; - int error_num; - String message; + List protocols; + OpcServerManageDto OpcServer; + int error_num; + String message; + private Server server; - public DeviceOpcProtocolRunable() { - this.error_num = 0; - this.message = null; - } + public DeviceOpcProtocolRunable() { + this.error_num = 0; + this.message = null; + this.server = null; + } - public List getProtocols() { - return this.protocols; - } + public List getProtocols() { + return this.protocols; + } - public void setProtocols(List protocols) { - this.protocols = protocols; - } + public void setProtocols(List protocols) { + this.protocols = protocols; + } - public OpcServerManageDto getOpcServer() { - return this.OpcServer; - } + public OpcServerManageDto getOpcServer() { + return this.OpcServer; + } - public void setOpcServer(OpcServerManageDto opcServer) { - this.OpcServer = opcServer; - } + public void setOpcServer(OpcServerManageDto opcServer) { + this.OpcServer = opcServer; + } - OpcItemDto getItem(String item) { - Iterator var2 = this.protocols.iterator(); + OpcItemDto getItem(String item) { + Iterator var2 = this.protocols.iterator(); - OpcItemDto dto; - do { - if (!var2.hasNext()) { - return null; - } + OpcItemDto dto; + do { + if (!var2.hasNext()) { + return null; + } - dto = (OpcItemDto) var2.next(); - } while (!StrUtil.equals(item, dto.getItem_code())); + dto = (OpcItemDto) var2.next(); + } while (!StrUtil.equals(item, dto.getItem_code())); - return dto; - } + return dto; + } - @Override - public void run() { - while (true) { - try { - Server server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); - Group group = server.addGroup(); - List itemsString = new ArrayList(); - Iterator it = this.protocols.iterator(); + @Override + public void run() { + while (true) { + try { + server = OpcServerUtl.getServerWithOutException( + this.OpcServer.getOpc_host(), + this.OpcServer.getCls_id(), + this.OpcServer.getUser(), + this.OpcServer.getPassword(), + this.OpcServer.getDomain()); + Group group = server.addGroup(); + List itemsString = new ArrayList(); + Iterator it = this.protocols.iterator(); - while (it.hasNext()) { - OpcItemDto protocol = (OpcItemDto) it.next(); - String item = protocol.getItem_code(); - itemsString.add(item); - } - - Map itemsMap = new LinkedHashMap(); - boolean is_error = false; - StringBuilder err_message = new StringBuilder(); - Iterator var7 = itemsString.iterator(); - - while (var7.hasNext()) { - String string = (String) var7.next(); - - try { - itemsMap.put(string, group.addItem(string)); - log.trace("添加成功 {}", string); - } catch (Exception var29) { - err_message.append(string + ":" + var29.getMessage()); - if (!is_error) { - is_error = true; - } - } - } - - if (is_error) { - log.info("设备OPC数据同步配置异常," + err_message); - } - - if (!OpcStartTag.is_run) { - OpcStartTag.is_run = true; - } - - //线程名 - String tag = Thread.currentThread().getName(); - if (this.OpcServer != null) { - tag = tag + this.OpcServer.getOpc_code(); - } - UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key); - - boolean time_out = false; - - label97: - while (true) { - long begin = System.currentTimeMillis(); - Map itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); - long end = System.currentTimeMillis(); - log.trace("{} 开始记时{}", tag, DateUtil.now()); - long duration = end - begin; - log.trace("{} 读取耗时:{}", tag, duration); - if (duration > 1000L) { - if (!time_out) { - log.warn(" {} 读取超时 : {} ", tag, duration); - } - - time_out = true; - } else { - time_out = false; - } - - Set items = itemStatus.keySet(); - Iterator var18 = items.iterator(); - - while (true) { - Item item; - //当前值 - Object value; - //旧的值 - Object his; - do { - if (!var18.hasNext()) { - end = System.currentTimeMillis(); - log.trace("{}", itemsString); - log.trace("{} 计算完成耗时{}", tag, end - begin); - Thread.sleep((long) OpcConfig.synchronized_millisecond); - if (this.error_num != 0) { - this.error_num = 0; - this.message = null; - } - continue label97; - } - - item = (Item) var18.next(); - ItemState itemState = (ItemState) itemStatus.get(item); - value = OpcUtl.getValue(item, itemState); - his = accessor_value.getValue(item.getId()); - if (!ObjectUtil.equal(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { - log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality()); - } - } while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码 - - OpcItemDto itemDto = this.getItem(item.getId()); - if (itemDto.getNeed_log() != null && itemDto.getNeed_log()) { - StringBuilder sb = new StringBuilder(); - //设备的ITEM项 - List relate_items = itemDto.getRelate_items(); - Iterator var26 = relate_items.iterator(); - - while (var26.hasNext()) { - String relate = (String) var26.next(); - Object obj = accessor_value.getValue(relate); - sb.append("key:" + relate + "value:" + obj + ";"); - } - - log.info("信号{}变更从{}->{};信号快照:{}", new Object[]{item.getId(), his, value, sb}); - - } - //设置值 - accessor_value.setValue(item.getId(), value); - - } - } - } catch (Exception var30) { - String error_message = "设备信息同步异常"; - if (!StrUtil.equals(this.message, error_message)) { - log.warn("", var30); - } - - try { - Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000)); - } catch (InterruptedException e) { - e.printStackTrace(); - } - ++this.error_num; - if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) { - log.info("设备同步通信异常"); - this.message = error_message; - } - } + while (it.hasNext()) { + OpcItemDto protocol = (OpcItemDto) it.next(); + String item = protocol.getItem_code(); + itemsString.add(item); } - } - public static String formatDuring(long mss) { - long days = mss / 86400000L; - long hours = mss % 86400000L / 3600000L; - long minutes = mss % 3600000L / 60000L; - long seconds = mss % 60000L / 1000L; - return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds "; + Map itemsMap = new LinkedHashMap(); + boolean is_error = false; + StringBuilder err_message = new StringBuilder(); + Iterator var7 = itemsString.iterator(); + + while (var7.hasNext()) { + String string = (String) var7.next(); + + try { + itemsMap.put(string, group.addItem(string)); + log.trace("添加成功 {}", string); + } catch (Exception var29) { + err_message.append(string + ":" + var29.getMessage()); + if (!is_error) { + is_error = true; + } + } + } + + if (is_error) { + log.info("设备OPC数据同步配置异常," + err_message); + } + + if (!OpcStartTag.is_run) { + OpcStartTag.is_run = true; + } + + // 线程名 + String tag = Thread.currentThread().getName(); + if (this.OpcServer != null) { + tag = tag + this.OpcServer.getOpc_code(); + } + UnifiedDataAccessor accessor_value = + UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key); + + boolean time_out = false; + + label97: + while (true) { +// System.out.println("label97"); + long begin = System.currentTimeMillis(); + Map itemStatus = + group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); + long end = System.currentTimeMillis(); + log.trace("{} 开始记时{}", tag, DateUtil.now()); + long duration = end - begin; + log.trace("{} 读取耗时:{}", tag, duration); + if (duration > 1000L) { + if (!time_out) { + log.warn(" {} 读取超时 : {} ", tag, duration); + } + + time_out = true; + } else { + time_out = false; + } + + Set items = itemStatus.keySet(); + Iterator var18 = items.iterator(); + + while (true) { +// System.out.println("label98"); + Item item; + // 当前值 + Object value; + // 旧的值 + Object his; + do { + if (!var18.hasNext()) { + end = System.currentTimeMillis(); + log.trace("{}", itemsString); + log.trace("{} 计算完成耗时{}", tag, end - begin); + Thread.sleep((long) OpcConfig.synchronized_millisecond); + if (this.error_num != 0) { + this.error_num = 0; + this.message = null; + } + continue label97; + } + + item = (Item) var18.next(); + ItemState itemState = itemStatus.get(item); + value = OpcUtl.getValue(item, itemState); + his = accessor_value.getValue(item.getId()); + if (!ObjectUtil.equal(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) + && his != null) { + log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality()); + } + } while (ObjectUtil.equal(value, his)); // 如果两次的值相等,不走下面的代码 + + OpcItemDto itemDto = this.getItem(item.getId()); + if (itemDto.getNeed_log() != null && itemDto.getNeed_log()) { + StringBuilder sb = new StringBuilder(); + // 设备的ITEM项 + List relate_items = itemDto.getRelate_items(); + Iterator var26 = relate_items.iterator(); + + while (var26.hasNext()) { + String relate = (String) var26.next(); + Object obj = accessor_value.getValue(relate); + sb.append("key:" + relate + "value:" + obj + ";"); + } + + log.info("信号{}变更从{}->{};信号快照:{}", new Object[] {item.getId(), his, value, sb}); + } + System.out.println("设置值:【"+item.getId()+"】-->"+value); + // 设置值 + accessor_value.setValue(item.getId(), value); + } + } + } catch (Exception var30) { + if (this.server != null) { + try { + this.server.disconnect(); + } catch (Exception var6) { + } + this.server = null; + } + + String error_message = "设备信息同步异常"; + if (!StrUtil.equals(this.message, error_message)) { + log.warn("", var30); + } + + try { + Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + ++this.error_num; + if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) { + log.info("设备同步通信异常"); + this.message = error_message; + } + } } + } + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcSynchronizeAutoRun.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcSynchronizeAutoRun.java index 246a54a35..a87a83976 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcSynchronizeAutoRun.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcSynchronizeAutoRun.java @@ -17,6 +17,8 @@ import java.util.concurrent.Executors; */ @Component public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable { + + public static boolean isRun = false; ExecutorService executorService = Executors.newCachedThreadPool(); @Autowired private DeviceAppService deviceAppService; @@ -36,6 +38,7 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable { @Override public void autoRun() throws Exception { { + isRun = true; Map servers = this.opcServerManageService.queryAllServerMap(); Map>> pros; @@ -72,6 +75,7 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable { @Override public void after() { + isRun = false; this.executorService.shutdownNow(); this.executorService = Executors.newCachedThreadPool(); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcConfig.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcConfig.java index cadf67c22..850716847 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcConfig.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcConfig.java @@ -10,4 +10,7 @@ public class OpcConfig { public static String opc_server_default_group = "group"; public static String resource_code = "opc_sync"; public static String resource_name = "opc同步"; + + //OPC 数据同步是否采用回调机制实现。之前是线程定期全部读,效率低。 + public static Boolean opc_item_read_using_callback = false; } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java new file mode 100644 index 000000000..3e1f7a302 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java @@ -0,0 +1,21 @@ +package org.nl.acs.opc; + +import org.nl.acs.device_driver.driver.ItemValue; +import org.openscada.opc.lib.da.Group; + +/** + * @author ldjun + * @version 1.0 + * @date 2023年02月01日 11:26 + * @desc desc + */ +public interface OpcServerService { + + void reload(); + + Group getServer(String var1); + + void writeInteger(String var1, ItemValue... var2); + + void clearServer(String var1); +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java new file mode 100644 index 000000000..416c55f02 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java @@ -0,0 +1,151 @@ +package org.nl.acs.opc; + +import org.jinterop.dcom.common.JIException; +import org.nl.acs.auto.initial.ApplicationAutoInitial; +import org.nl.acs.device_driver.driver.ItemValue; +import org.nl.modules.wql.exception.WDKException; +import org.openscada.opc.lib.common.NotConnectedException; +import org.openscada.opc.lib.da.Group; +import org.openscada.opc.lib.da.Server; +import org.openscada.opc.lib.da.UnknownGroupException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.net.UnknownHostException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * @author ldjun + * @version 1.0 + * @date 2023年02月01日 11:27 + * @desc desc + */ +@Service +public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoInitial { + + private static final Logger log = LoggerFactory.getLogger(OpcServerServiceImpl.class); + @Autowired OpcServerManageService opcServerManageService; + Map opcServerManageDtos = new HashMap(); + Map servers = Collections.synchronizedMap(new HashMap()); + Map groups = Collections.synchronizedMap(new HashMap()); + + public OpcServerServiceImpl() {} + + public void autoInitial() throws Exception { + this.reload(); + if (OpcConfig.auto_start_opc) { + Thread t = + new Thread() { + public void run() { + Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator(); + + while (var1.hasNext()) { + OpcServerManageDto dto = (OpcServerManageDto) var1.next(); + + try { + OpcServerServiceImpl.this.getServer(dto.getOpc_code()); + OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code()); + } catch (Exception var4) { + OpcServerServiceImpl.log.warn("启动无法载入servers", var4); + } + } + } + }; + t.start(); + } + } + + public synchronized void reload() { + this.opcServerManageDtos = this.opcServerManageService.queryAllServerMap(); + this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos); + } + + public synchronized Group getServer(String code) { + Group group = null; + group = (Group) this.groups.get(code); + if (group != null) { + try { + if (group.isActive()) { + return group; + } + } catch (JIException var9) { + var9.printStackTrace(); + } + } + + Server server = (Server) this.servers.get(code); + boolean needcreate = false; + if (server == null) { + needcreate = true; + } else { + try { + group = server.findGroup(OpcConfig.opc_server_default_group); + } catch (UnknownHostException + | JIException + | UnknownGroupException + | NotConnectedException + | IllegalArgumentException var8) { + var8.printStackTrace(); + needcreate = true; + } + } + + if (needcreate) { + OpcServerManageDto dto = (OpcServerManageDto) this.opcServerManageDtos.get(code); + if (dto == null) { + throw new WDKException("code 不存在"); + } + + server = OpcServerUtl.getServerWithOutException( + dto.getOpc_host(), + dto.getCls_id(), + dto.getUser(), + dto.getPassword(), + dto.getDomain()); + +// server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); + + + try { + group = server.addGroup(OpcConfig.opc_server_default_group); + } catch (Exception var7) { + throw new WDKException(var7); + } + + this.servers.put(code, server); + this.groups.put(code, group); + } + + return group; + } + + public synchronized void clearServer(String code) { + try { + Server server = (Server) this.servers.get(code); + server.disconnect(); + } catch (Exception e) { + e.printStackTrace(); + log.error("清理server异常,",e.getMessage()); + } + + this.servers.remove(code); + this.groups.remove(code); + } + + public void writeInteger(String code, ItemValue... values) { + try { + Group group = this.getServer(code); + OpcUtl.writeValue(group, values); + } catch (Exception var4) { + this.clearServer(code); + log.warn("写入出错opc server {} 重新加载", code, var4); + ThreadUtl.sleep(5000L); + throw var4; + } + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java index 6c8bc199d..e03649e7f 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java @@ -4,12 +4,15 @@ import cn.hutool.core.util.NumberUtil; import lombok.extern.slf4j.Slf4j; import org.jinterop.dcom.common.JIException; import org.jinterop.dcom.core.*; +import org.nl.acs.device_driver.driver.ItemValue; import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.wql.exception.WDKException; import org.openscada.opc.lib.common.ConnectionInformation; import org.openscada.opc.lib.da.*; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.concurrent.Executors; @@ -26,9 +29,9 @@ public class OpcUtl { } - public static void writeValue(Group group, WriteRequest... requests) { + public static void writeValue(Group group, WriteRequest... requests) throws WDKException { try { - Map e = group.write(requests); + Map e = group.write(requests); boolean is_success = true; StringBuilder message = new StringBuilder(); Iterator arg4 = e.keySet().iterator(); @@ -52,10 +55,57 @@ public class OpcUtl { // throw new BusinessException(message.toString()); System.out.println("下发信号失败:"+message.toString()); log.info("下发信号失败:"+message.toString()); - group.write(requests); + throw new WDKException(message.toString()); +// group.write(requests); } } catch (JIException arg7) { - // throw new BusinessException(arg7); + log.info("下发信号失败:"+arg7.getMessage()); + throw new WDKException(arg7); + } + } + + public static void writeValue(Group group, ItemValue... values) throws WDKException { + try { + if (values != null && values.length > 0) { + List ws = new ArrayList(); + ItemValue[] var3 = values; + int var4 = values.length; + + for(int var5 = 0; var5 < var4; ++var5) { + ItemValue value = var3[var5]; + Item item = group.addItem(value.getItem_code()); + ws.add(new WriteRequest(item, getVariant(value.getItem_value()))); + } + + writeValue(group, (WriteRequest[])ws.toArray(new WriteRequest[0])); + } + + } catch (AddFailedException | JIException var8) { + throw new WDKException(var8); + } + } + + public static JIVariant getVariant(Object object) { + if (object instanceof Integer) { + return getIntegerVariant((Integer)object); + } else if (object instanceof String) { + return getStringVariant((String)object); + } else if (object instanceof byte[]) { + return getByteArrayVariant((byte[])((byte[])object)); + } else if (object instanceof Byte[]) { + return getByteArrayVariant((Byte[])((Byte[])object)); + } else if (object instanceof Boolean) { + return new JIVariant((Boolean)object); + } else if (object instanceof int[]) { + return getByteArrayVariantxx((int[])((int[])object)); + } else if (object instanceof Integer[]) { + JIArray array = new JIArray((Integer)object, false); + JIVariant value = new JIVariant(array); + return value; + } else if (object instanceof JIVariant) { + return (JIVariant)object; + } else { + throw new WDKException("未实现目前支持是int,string,byte[]"); } } @@ -63,6 +113,7 @@ public class OpcUtl { if (NumberUtil.compare(itemState.getQuality(), Short.valueOf(QualityTypeValue.OPC_QUALITY_GOOD)) != 0) { if (item != null) { log.debug("value is not good {} : {}", item.getId(), itemState.getQuality()); +// throw new WDKException("值不健康进行重连!"); } else { log.debug("value is not good {}", itemState.getQuality()); } @@ -179,6 +230,44 @@ public class OpcUtl { return connection; } + public static JIVariant getByteArrayVariantxx(int[] bytes) { + Integer[] byte_Data = new Integer[bytes.length]; + + for(int i = 0; i < bytes.length; ++i) { + byte_Data[i] = bytes[i]; + } + + JIArray array = new JIArray(byte_Data, false); + JIVariant value = new JIVariant(array); + return value; + } + + public static JIVariant getIntegerVariant(Integer integer) { + return new JIVariant(integer); + } + + public static JIVariant getStringVariant(String string) { + return new JIVariant(string); + } + + public static JIVariant getByteArrayVariant(byte[] bytes) { + Byte[] byte_Data = new Byte[bytes.length]; + + for(int i = 0; i < bytes.length; ++i) { + byte_Data[i] = bytes[i]; + } + + JIArray array = new JIArray(byte_Data, false); + JIVariant value = new JIVariant(array); + return value; + } + + public static JIVariant getByteArrayVariant(Byte[] bytes) { + JIArray array = new JIArray(bytes, false); + JIVariant value = new JIVariant(array); + return value; + } + public static String read(String item) throws Exception { System.out.println(item); Server server = getServer("192.168.81.251", "7bc0cc8e-482c-47ca-abdc-0fe7f9c6e729", "administrator", "Huawei@123", ""); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/ThreadUtl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/ThreadUtl.java new file mode 100644 index 000000000..c2e51c0b3 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/ThreadUtl.java @@ -0,0 +1,21 @@ +package org.nl.acs.opc; + +/** + * @author ldjun + * @version 1.0 + * @date 2023年02月01日 11:28 + * @desc desc + */ +public class ThreadUtl { + private ThreadUtl() { + } + + public static void sleep(long times) throws RuntimeException { + try { + Thread.sleep(times); + } catch (InterruptedException var3) { + throw new RuntimeException(var3); + } + } +} + diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/WcsConfig.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/WcsConfig.java index d35748e1c..7f7f74530 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/WcsConfig.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/WcsConfig.java @@ -10,4 +10,7 @@ public class WcsConfig { //物料默认类型描述 public static String task_container_type_default_desc; + //重复的指令下发超时 ms + public static Integer opc_write_repeat_check = 1000; + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/TaskInstructionLock.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/TaskInstructionLock.java new file mode 100644 index 000000000..fd1c749ed --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/TaskInstructionLock.java @@ -0,0 +1,6 @@ +package org.nl.acs.task; + +public class TaskInstructionLock { + public TaskInstructionLock() { + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java index ee4f68570..284308331 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java @@ -25,6 +25,7 @@ import org.nl.modules.quartz.domain.QuartzLog; import org.nl.modules.quartz.repository.QuartzLogRepository; import org.nl.modules.quartz.service.QuartzJobService; import org.nl.modules.wql.util.SpringContextHolder; +import org.quartz.DisallowConcurrentExecution; import org.quartz.JobExecutionContext; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.quartz.QuartzJobBean; @@ -41,6 +42,7 @@ import java.util.concurrent.ThreadPoolExecutor; @Async @SuppressWarnings({"unchecked", "all"}) @Slf4j +@DisallowConcurrentExecution public class ExecutionJob extends QuartzJobBean { /** diff --git a/acs/nladmin-system/src/main/resources/logback-spring.xml b/acs/nladmin-system/src/main/resources/logback-spring.xml index b661855b1..86bdaa02c 100644 --- a/acs/nladmin-system/src/main/resources/logback-spring.xml +++ b/acs/nladmin-system/src/main/resources/logback-spring.xml @@ -102,6 +102,7 @@ https://juejin.cn/post/6844903775631572999 + diff --git a/acs/nladmin-ui/src/api/acs/instruction/instruction.js b/acs/nladmin-ui/src/api/acs/instruction/instruction.js index 5d8bec045..df0cda541 100644 --- a/acs/nladmin-ui/src/api/acs/instruction/instruction.js +++ b/acs/nladmin-ui/src/api/acs/instruction/instruction.js @@ -70,4 +70,12 @@ export function reload() { }) } -export default { add, edit, del, finish, cancel, forceCancel, queryUnFinish, queryByTaskId, reload } +export function init(instruction_id) { + return request({ + url: 'api/instruction/init/' + instruction_id, + method: 'post', + data: instruction_id + }) +} + +export default { add, edit, del, finish, cancel, forceCancel, queryUnFinish, queryByTaskId, reload, init } diff --git a/acs/nladmin-ui/src/views/acs/instruction/index.vue b/acs/nladmin-ui/src/views/acs/instruction/index.vue index d3af064a9..92eb8a07f 100644 --- a/acs/nladmin-ui/src/views/acs/instruction/index.vue +++ b/acs/nladmin-ui/src/views/acs/instruction/index.vue @@ -180,6 +180,7 @@ 完成 取消 强制取消 + 初始化 @@ -320,6 +321,14 @@ export default { console.log(err.response.data.message) }) }, + init(index, row) { + crudInstruction.init(row.instruction_id).then(res => { + this.crud.toQuery() + this.crud.notify('初始化成功', CRUD.NOTIFICATION_TYPE.SUCCESS) + }).catch(err => { + console.log(err.response.data.message) + }) + }, reload() { crudInstruction.reload().then(res => { this.crud.toQuery() @@ -346,6 +355,9 @@ export default { case 'c':// 强制取消 this.forceCancel(command.index, command.row) break + case 'd':// 初始化 + this.init(command.index, command.row) + break } } diff --git a/acs/nladmin-ui/src/views/system/monitor/device/index.vue b/acs/nladmin-ui/src/views/system/monitor/device/index.vue index 5816a051e..27daccefa 100644 --- a/acs/nladmin-ui/src/views/system/monitor/device/index.vue +++ b/acs/nladmin-ui/src/views/system/monitor/device/index.vue @@ -103,6 +103,12 @@ + + + + + +