From 51ef2677dabc2018aeff716548001239a7b12934 Mon Sep 17 00:00:00 2001 From: "USER-20220102CG\\noblelift" <546428999@qq.com> Date: Wed, 8 Feb 2023 14:35:29 +0800 Subject: [PATCH] init --- acs/nladmin-system/.gitignore | 1 + acs/nladmin-system/pom.xml | 5 + .../src/main/java/org/nl/acs/AcsConfig.java | 2 + .../acs/agv/server/impl/AgvServiceImpl.java | 1 - .../run/OneNDCSocketConnectionAutoRun.java | 28 +- .../device/device_driver/DriverTypeEnum.java | 7 +- .../standard_inspect/ReadUtil.java | 109 +- .../service/impl/DeviceServiceImpl.java | 24 + .../nl/acs/device_driver/DeviceDriver.java | 3 + .../device_driver/ScannerDeviceDriver.java | 6 +- .../agv/ndcone/AgvNdcOneDeviceDriver.java | 189 +- ...BoxPalletizingManipulatorDeviceDriver.java | 14 +- .../CargoLiftConveyorDeviceDriver.java | 24 +- ...tyVehicleStackingPositionDeviceDriver.java | 12 +- .../HailiangSmartplcTestDeviceDriver.java | 12 +- .../HongXiangStationDeviceDriver.java | 18 +- .../HongXiangConveyorDeviceDriver.java | 70 +- .../hongxiang_device/ItemProtocol.java | 40 +- .../oven_manipulator/ItemProtocol.java | 4 + .../OvenGantryManipulatorDeviceDriver.java | 216 +- .../PaintConveyorDeviceDriver.java | 12 +- .../plug_pull_device_site/ItemProtocol.java | 161 + .../PlugPullDeviceSiteDefination.java | 60 + .../PlugPullDeviceSiteDeviceDriver.java | 239 ++ .../siemens_conveyor/ItemProtocol.java | 9 + .../SiemensConveyorDeviceDriver.java | 629 +++- .../siemens_conveyor_ckk/ItemProtocol.java | 132 + .../SiemensConveyorCkkDefination.java | 64 + .../SiemensConveyorCkkDeviceDriver.java | 914 ++++++ .../ItemProtocol.java | 134 + .../SiemensConveyorLabelingDefination.java | 64 + .../SiemensConveyorLabelingDeviceDriver.java | 931 ++++++ .../slit_two_manipulator/ItemProtocol.java | 5 + .../SlitTwoManipulatorDeviceDriver.java | 471 ++- .../StandardCoveyorControlDeviceDriver.java | 32 +- ...eyorControlWithPlcScannerDeviceDriver.java | 61 +- .../ItemProtocol.java | 58 +- ...CoveyorControlWithScannerDeviceDriver.java | 546 +++- .../StandardInspectSiteDeviceDriver.java | 20 +- .../StandardScannerDeviceDriver.java | 112 +- .../driver/AbstractOpcDeviceDriver.java | 108 +- .../driver/ExecutableDeviceDriver.java | 21 +- .../acs/device_driver/driver/ItemValue.java | 36 + .../device_driver/driver/OpcDeviceDriver.java | 18 +- .../main/java/org/nl/acs/ext/wms/AcsUtil.java | 4 +- .../data/ApplyLabelingAndBindingRequest.java | 3 + .../data/ApplyLabelingAndBindingResponse.java | 5 + .../wms/liKuData/BaseStoreReportRequest.java | 3 + .../ext/wms/liKuData/DeviceStatusData.java | 32 + .../ext/wms/liKuData/DeviceStatusRequest.java | 11 + .../wms/liKuData/DeviceStatusResponse.java | 14 + .../wms/liKuData/putEmptyPalletRequest.java | 14 + .../acs/ext/wms/rest/AcsToLiKuController.java | 53 +- .../acs/ext/wms/rest/AcsToWmsController.java | 25 +- .../acs/ext/wms/rest/LiKuToACSController.java | 21 +- .../acs/ext/wms/rest/WmsToAcsController.java | 29 +- .../acs/ext/wms/service/AcsToLiKuService.java | 25 + .../acs/ext/wms/service/AcsToWmsService.java | 7 +- .../acs/ext/wms/service/LiKuToAcsService.java | 8 + .../acs/ext/wms/service/WmsToAcsService.java | 9 + .../service/impl/AcsToLiKuServiceImpl.java | 152 +- .../wms/service/impl/AcsToWmsServiceImpl.java | 65 +- .../service/impl/LiKuToAcsServiceImpl.java | 295 +- .../wms/service/impl/WmsToAcsServiceImpl.java | 273 +- .../common/InstructStatusEnum.java | 2 + .../rest/InstructionController.java | 10 + .../service/InstructionService.java | 8 +- .../service/impl/InstructionServiceImpl.java | 765 +++-- .../instruction/service/wql/QINST_QUERY.wql | 105 +- .../java/org/nl/acs/log/LokiLogAspect.java | 2 +- .../impl/DeviceExecuteLogServiceImpl.java | 57 +- .../nl/acs/opc/DeviceOpcProtocolRunable.java | 370 ++- .../acs/opc/DeviceOpcSynchronizeAutoRun.java | 4 + .../main/java/org/nl/acs/opc/OpcConfig.java | 3 + .../java/org/nl/acs/opc/OpcServerService.java | 21 + .../org/nl/acs/opc/OpcServerServiceImpl.java | 154 + .../java/org/nl/acs/opc/OpcServerUtl.java | 1 + .../main/java/org/nl/acs/opc/OpcStartTag.java | 2 +- .../src/main/java/org/nl/acs/opc/OpcUtl.java | 156 +- .../main/java/org/nl/acs/opc/ThreadUtl.java | 21 + .../main/java/org/nl/acs/opc/WcsConfig.java | 3 + .../org/nl/acs/task/TaskInstructionLock.java | 6 + .../org/nl/acs/task/rest/TaskController.java | 11 + .../org/nl/acs/task/service/TaskService.java | 21 +- .../service/impl/TaskFeedbackServiceImpl.java | 1 - .../task/service/impl/TaskServiceImpl.java | 2747 +++++++++-------- .../nl/acs/task/service/wql/QTASK_QUERY.wql | 6 +- .../main/java/org/nl/common/utils/IdUtil.java | 11 + .../nl/modules/logging/InterfaceLogType.java | 24 + .../nl/modules/logging/annotation/Log.java | 31 + .../nl/modules/logging/aspect/LogAspect.java | 100 +- .../logging/rest/InterfaceLogController.java | 51 + .../logging/service/InterfaceLogService.java | 44 + .../service/impl/InterfaceLogServiceImpl.java | 70 + .../service/wql/QSCH_INTERFACE_LOGS.wql | 68 + .../mnt/websocket/WebSocketServer.java | 2 - .../modules/quartz/task/AutoCreateInst.java | 5 + .../quartz/task/QueryLKDeviceStatus.java | 44 + .../nl/modules/quartz/utils/ExecutionJob.java | 2 + .../security/service/OnlineUserService.java | 2 + .../java/org/nl/modules/system/wql/sys.xls | Bin 223744 -> 228864 bytes .../main/resources/config/application-dev.yml | 11 +- .../resources/config/application-prod.yml | 13 +- .../resources/config/application-test.yml | 100 +- .../src/main/resources/config/application.yml | 2 +- .../src/main/resources/log/AcsToLk.xml | 33 + .../src/main/resources/log/AcsToWms.xml | 33 + .../resources/log/AgvNdcOneDeviceDriver.xml | 33 + .../src/main/resources/log/AutoCreateInst.xml | 32 + .../src/main/resources/log/LkToAcs.xml | 33 + .../log/OneNDCSocketConnectionAutoRun.xml | 33 + .../src/main/resources/log/OpcUtil.xml | 33 + .../src/main/resources/log/WmsToAcs.xml | 33 + .../src/main/resources/logback-spring.xml | 70 +- acs/nladmin-ui/.env.production | 4 +- acs/nladmin-ui/src/App.vue | 2 +- .../src/api/acs/instruction/instruction.js | 10 +- .../src/views/acs/device/config.vue | 9 +- .../acs/device/driver/hongxiang_conveyor.vue | 17 + .../acs/device/driver/hongxiang_device.vue | 17 + .../acs/device/driver/oven_manipulator.vue | 17 + .../device/driver/plug_pull_device_site.vue | 507 +++ .../acs/device/driver/siemens_conveyor.vue | 28 +- .../device/driver/siemens_conveyor_ckk.vue | 530 ++++ .../driver/siemens_conveyor_labeling.vue | 530 ++++ .../device/driver/slit_two_manipulator.vue | 17 + ...standard_conveyor_control_with_scanner.vue | 17 + .../src/views/acs/device/protocol/index.vue | 5 +- .../acs/history/taskTreeRecord/index.vue | 2 + .../src/views/acs/instruction/index.vue | 59 +- .../src/views/acs/monitor/device/index.vue | 22 +- .../src/views/acs/monitor/device/index2.vue | 14 +- acs/nladmin-ui/src/views/acs/task/index.vue | 40 +- .../src/views/monitor/interfaceLog/index.vue | 120 + .../monitor/interfaceLog/interfaceLog.js | 22 + .../src/views/monitor/interfaceLog/search.vue | 49 + .../src/views/system/monitor/device/index.vue | 188 +- 137 files changed, 11180 insertions(+), 3105 deletions(-) create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDefination.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDeviceDriver.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/ItemProtocol.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDefination.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDeviceDriver.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/ItemProtocol.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDefination.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ItemValue.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/DeviceStatusData.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/DeviceStatusRequest.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/DeviceStatusResponse.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/putEmptyPalletRequest.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/opc/ThreadUtl.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/task/TaskInstructionLock.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/common/utils/IdUtil.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/logging/InterfaceLogType.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/logging/rest/InterfaceLogController.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/logging/service/InterfaceLogService.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/InterfaceLogServiceImpl.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/logging/service/wql/QSCH_INTERFACE_LOGS.wql create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryLKDeviceStatus.java create mode 100644 acs/nladmin-system/src/main/resources/log/AcsToLk.xml create mode 100644 acs/nladmin-system/src/main/resources/log/AcsToWms.xml create mode 100644 acs/nladmin-system/src/main/resources/log/AgvNdcOneDeviceDriver.xml create mode 100644 acs/nladmin-system/src/main/resources/log/AutoCreateInst.xml create mode 100644 acs/nladmin-system/src/main/resources/log/LkToAcs.xml create mode 100644 acs/nladmin-system/src/main/resources/log/OneNDCSocketConnectionAutoRun.xml create mode 100644 acs/nladmin-system/src/main/resources/log/OpcUtil.xml create mode 100644 acs/nladmin-system/src/main/resources/log/WmsToAcs.xml create mode 100644 acs/nladmin-ui/src/views/acs/device/driver/plug_pull_device_site.vue create mode 100644 acs/nladmin-ui/src/views/acs/device/driver/siemens_conveyor_ckk.vue create mode 100644 acs/nladmin-ui/src/views/acs/device/driver/siemens_conveyor_labeling.vue create mode 100644 acs/nladmin-ui/src/views/monitor/interfaceLog/index.vue create mode 100644 acs/nladmin-ui/src/views/monitor/interfaceLog/interfaceLog.js create mode 100644 acs/nladmin-ui/src/views/monitor/interfaceLog/search.vue diff --git a/acs/nladmin-system/.gitignore b/acs/nladmin-system/.gitignore index caa1a2a..a9a5d89 100644 --- a/acs/nladmin-system/.gitignore +++ b/acs/nladmin-system/.gitignore @@ -6,3 +6,4 @@ */*.iml /.gradle/ /target/* +/logPath_IS_UNDEFINED/ diff --git a/acs/nladmin-system/pom.xml b/acs/nladmin-system/pom.xml index 2641144..e02d8fb 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/AcsConfig.java b/acs/nladmin-system/src/main/java/org/nl/acs/AcsConfig.java index 8d3d47f..77cbff7 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/AcsConfig.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/AcsConfig.java @@ -54,4 +54,6 @@ public interface AcsConfig { String AutoCleanDays = "AutoCleanDays"; //最大任务下发时间 String MAXSENDTASKTIME = "maxSendTaskTime"; + //指令下发立库 + String INSTSENDLK = "instSendLk"; } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java index 6bd14f5..ae50b36 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java @@ -97,7 +97,6 @@ public class AgvServiceImpl implements AgvService { if (address.indexOf("-") > 0) { String str = address.substring(address.indexOf("-"), address.length()); address = address.substring(0, address.indexOf("-")); - System.out.println(address); } } } 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 6e176c0..6eb984a 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()); @@ -84,6 +86,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { dos = new DataOutputStream(s.getOutputStream()); dis = new DataInputStream(s.getInputStream()); System.out.println("1楼NDCAgv链接成功"); + log.info("1楼NDCAgv链接成功"); while (bConnected) { int count = dis.read(b); @@ -119,6 +122,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { //车号 int carno = arr[20]; Instruction link_inst = null; + Instruction inst = null; List insts = null; boolean link_flag = false; Device agv_device = null; @@ -126,7 +130,10 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno)); } if (ikey != 0) { - insts = instructionService.findByLinkNum(String.valueOf(ikey)); + inst = instructionService.findByCodeFromCache(String.valueOf(ikey)); + if (ObjectUtil.isEmpty(inst)){ + inst = instructionService.findByCode(String.valueOf(ikey)); + } } if (!ObjectUtil.isEmpty(link_inst)) { link_flag = true; @@ -142,7 +149,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { //开始任务/上报订单号 if (phase == 0x01) { - for (Instruction inst : insts) { + if (!ObjectUtil.isEmpty(inst)) { inst.setInstruction_status("1"); inst.setAgv_jobno(String.valueOf(index)); inst.setSend_status("1"); @@ -154,7 +161,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { //(无车id及状态) else if (phase == 0x0A) { - for (Instruction inst : insts) { + if (!ObjectUtil.isEmpty(inst)) { if (!ObjectUtil.isEmpty(inst)) { instructionService.finish(inst.getInstruction_id()); } @@ -172,7 +179,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { //(需要WCS反馈) else if(phase == 0xFF) { - for (Instruction inst : insts) { + if (!ObjectUtil.isEmpty(inst)) { if (!ObjectUtil.isEmpty(inst)) { instructionService.cancelNOSendAgv(inst.getInstruction_id()); } @@ -187,10 +194,13 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { } else { device = deviceAppService.findDeviceByCode(Integer.toString(arr[20])); } - if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) { - agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver(); - agvNdcOneDeviceDriver.processSocket(arr); + if(ObjectUtil.isNotEmpty(device)){ + if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) { + agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver(); + agvNdcOneDeviceDriver.processSocket(arr); + } } + } if (!ObjectUtil.isEmpty(data)) { write(data); @@ -203,6 +213,10 @@ 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/device_driver/DriverTypeEnum.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index ef600f8..d4f54e4 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -37,8 +37,13 @@ public enum DriverTypeEnum { HONGXIANG_CONVEYOR(13, "hongxiang_conveyor", "烘箱对接位", "conveyor"), - INSPECT_CONVEYOR_CONTROL_WITH_SCANNER(14, "standard_conveyor_control_with_scanner", "标准版-输送机-控制点-关联扫码", "conveyor"); + INSPECT_CONVEYOR_CONTROL_WITH_SCANNER(14, "standard_conveyor_control_with_scanner", "标准版-输送机-控制点-关联扫码", "conveyor"), + PLUG_PULL_DEVICE_SITE(15, "plug_pull_device_site", "插拔轴站点", "conveyor"), + + SIEMENS_CONVEYOR_LABELING(16, "siemens_conveyor_labeling", "西门子-输送机驱动-贴标", "conveyor"), + + SIEMENS_CONVEYOR_CKK(17, "siemens_conveyor_ckk", "西门子-输送机驱动-出库口", "conveyor"); //驱动索引 diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/standard_inspect/ReadUtil.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/standard_inspect/ReadUtil.java index 4ce2cde..cb22b1d 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/standard_inspect/ReadUtil.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/standard_inspect/ReadUtil.java @@ -21,93 +21,10 @@ import org.openscada.opc.lib.list.ServerList; import java.net.UnknownHostException; import java.util.*; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; public class ReadUtil { - public static void main(String[] args) throws AlreadyConnectedException, JIException, UnknownHostException, NotConnectedException, DuplicateGroupException, AddFailedException, InterruptedException { - // 启动服务 - /* ItemProtocol ipl = new ItemProtocol(); - List list = ipl.getReadableItemDtos(); - List ls = new ArrayList<>(); - for (ItemDto dto : list) { - //ls.add("RD3.RD3.2265."+ dto.getCode()); - } - ls.add("DDJ1.DDJ1.DDJ1.heartbeat"); - ls.add("DDJ1.DDJ1.DDJ1.action"); - final Server server = getServer(); - Map map = read(ls, server); - *//*Map params=new HashMap<>(); - params.put("RD3.RD3.2265."+"mode","0"); - write(params, server);*//* - System.out.println(111);*/ - /* try { - test(); - } catch (InterruptedException e) { - e.printStackTrace(); - }*/ - - //List> maps = showAllOpcServer("192.168.81.207", "administrator", "123", ""); - - Server server = getServer(); - List itemString = new ArrayList(); - itemString.add("RD1.RD1.1005.test"); - Map map = read(itemString, server); - System.out.println(map.get("RD1.RD1.1005.test")); -// int[] a = (int[]) map.get("RD1.RD1.1005.test"); -// for(int i=0; i itemMap = new HashMap(); -// itemMap.put("RD1.RD1.1005.test", "1.2"); - - } - - /** - * 发布订阅测试 - */ - private static final int PERIOD = 100; - - private static final int SLEEP = 2000; - - public static void test() throws AlreadyConnectedException, JIException, UnknownHostException, AddFailedException, NotConnectedException, DuplicateGroupException, InterruptedException { - /*ConnectionInformation ci = new ConnectionInformation(); - ci.setHost("10.1.5.123"); - ci.setDomain(""); - ci.setUser("freud"); - ci.setPassword("password"); - ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305"); - - Server server = new Server(ci, - Executors.newSingleThreadScheduledExecutor());*/ - Server server = getServer(); - - // server.connect(); - - AccessBase access = new Async20Access(server, PERIOD, false); - - access.addItem("RD1.RD1.B21.mode", new DataCallback() { - - private int count; - - @SneakyThrows - public void changed(Item item, ItemState itemstate) { - System.out.println("[" + (++count) + "],ItemName:[" - + item.getId() + "],value:" + itemstate.getValue()); - System.out.println(itemstate.getValue().isArray()); - List listB = Arrays.asList(itemstate.getValue().toString()); - System.out.println(listB.get(0)); - - } - }); - - access.bind(); - Thread.sleep(SLEEP); - access.unbind(); - server.dispose(); - } public static Server getServer(String opc_id) { //OPC表【acs_opc】 @@ -134,28 +51,6 @@ public class ReadUtil { return server; } - public static Server getServer() { - //RD1.RD1.1028 - // 连接信息 - ConnectionInformation ci = new ConnectionInformation(); - ci.setHost("192.168.81.251"); - ci.setDomain(""); - ci.setUser("administrator"); - ci.setPassword("Huawei@123"); - ci.setClsid("7BC0CC8E-482C-47CA-ABDC-0FE7F9C6E729"); - final Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor()); - try { - server.connect(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } catch (JIException e) { - e.printStackTrace(); - } catch (AlreadyConnectedException e) { - e.printStackTrace(); - } - return server; - } - public static void write(Map strings, Server server) { try { //Group group = this.opcServerService.getServer(opcServiceCode); @@ -198,7 +93,6 @@ public class ReadUtil { public static Map read(List itemString, Server server) { HashMap map = new HashMap(); try { - //Group group = this.opcServerService.getServer(opcServiceCode); Group group = server.addGroup(); Map items = new LinkedHashMap(); Iterator is = itemString.iterator(); @@ -226,6 +120,7 @@ public class ReadUtil { } catch (Exception e) { e.printStackTrace(); } + return map; } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java index 28097f0..a50e0ed 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java @@ -22,7 +22,10 @@ import org.nl.acs.device.service.*; import org.nl.acs.device.service.dto.*; import org.nl.acs.device_driver.DeviceDriverDefination; import org.nl.acs.device_driver.ScannerDeviceDriver; +import org.nl.acs.device_driver.basedriver.oven_manipulator.OvenGantryManipulatorDeviceDriver; import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk.SiemensConveyorCkkDeviceDriver; +import org.nl.acs.device_driver.basedriver.siemens_conveyor_labeling.SiemensConveyorLabelingDeviceDriver; import org.nl.acs.device_driver.basedriver.slit_two_manipulator.SlitTwoManipulatorDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver; @@ -55,6 +58,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.util.*; +import java.util.stream.Collectors; /** * @author ldjun @@ -104,6 +108,13 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial param.put("opc_id", whereJson.get("opc_id")); } JSONObject json = WQL.getWO("Qdevice_query_002").addParamMap(param).pageQuery(WqlUtil.getHttpContext(page), "update_time desc"); + JSONArray jsonArray = json.getJSONArray("content"); + List objects = jsonArray.toJavaList(Object.class); + Integer currentPageNumber = page.getPageNumber() + 1; + Integer pageMaxSize = page.getPageSize(); + List protocolList = objects.stream().skip((currentPageNumber - 1) * pageMaxSize).limit(pageMaxSize).collect(Collectors.toList()); + json.put("content", protocolList); + json.put("totalElements", jsonArray.size()); return json; } @@ -933,6 +944,19 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial } else if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { SiemensConveyorDeviceDriver siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); siemensConveyorDeviceDriver.setDeviceStatus(form); + } else if (device.getDeviceDriver() instanceof SiemensConveyorLabelingDeviceDriver) { + SiemensConveyorLabelingDeviceDriver siemensConveyorLabelingDeviceDriver = (SiemensConveyorLabelingDeviceDriver) device.getDeviceDriver(); + siemensConveyorLabelingDeviceDriver.setDeviceStatus(form); + } else if (device.getDeviceDriver() instanceof OvenGantryManipulatorDeviceDriver) { + OvenGantryManipulatorDeviceDriver ovenGantryManipulatorDeviceDriver = (OvenGantryManipulatorDeviceDriver) device.getDeviceDriver(); + ovenGantryManipulatorDeviceDriver.setDeviceStatus(form); + } else if (device.getDeviceDriver() instanceof SiemensConveyorCkkDeviceDriver) { + SiemensConveyorCkkDeviceDriver siemensConveyorCkkDeviceDriver = (SiemensConveyorCkkDeviceDriver) device.getDeviceDriver(); + siemensConveyorCkkDeviceDriver.setDeviceStatus(form); + } else if (device.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver){ + StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver + = (StandardCoveyorControlWithScannerDeviceDriver) device.getDeviceDriver(); + standardCoveyorControlWithScannerDeviceDriver.setDeviceStatus(form); } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/DeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/DeviceDriver.java index eb07de8..3f702c5 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/DeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/DeviceDriver.java @@ -2,6 +2,8 @@ package org.nl.acs.device_driver; import org.nl.acs.opc.Device; +import java.util.List; + public interface DeviceDriver { default String getDeviceCode() { return this.getDevice().getDevice_code(); @@ -17,4 +19,5 @@ public interface DeviceDriver { return this.getDriverDefination().getDriverCode(); } + } 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 ea21637..05d6961 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 28a3549..eaac648 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 @@ -9,6 +9,7 @@ import org.nl.acs.agv.server.NDCAgvService; import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_storage.StandardStorageDeviceDriver; import org.nl.acs.device_driver.driver.AbstractDeviceDriver; @@ -26,7 +27,10 @@ import org.nl.modules.system.service.ParamService; import org.nl.modules.system.service.impl.ParamServiceImpl; import org.nl.modules.wql.util.SpringContextHolder; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * NDC单工位AGV @@ -78,13 +82,17 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic int carno = arr[20]; Instruction link_inst = null; List insts = null; + Instruction inst = null; boolean link_flag = false; Device agv_device = null; if (carno != 0) { agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno)); } if (ikey != 0) { - insts = instructionService.findByLinkNum(String.valueOf(ikey)); + inst = instructionService.findByCodeFromCache(String.valueOf(ikey)); + if (ObjectUtil.isEmpty(inst)){ + inst = instructionService.findByCode(String.valueOf(ikey)); + } } if (!ObjectUtil.isEmpty(link_inst)) { link_flag = true; @@ -107,14 +115,14 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; //货架 StandardStorageDeviceDriver standardStorageDeviceDriver; + // + SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; //分配 车id //(不需要WCS反馈) if (phase == 0x02) { - for (Instruction inst : insts) { - inst.setCarno(String.valueOf(carno)); - instructionService.update(inst); - } + inst.setCarno(String.valueOf(carno)); + instructionService.update(inst); logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + "反馈:" + data); //到达取货点 @@ -148,26 +156,34 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic logServer.deviceExecuteLog(this.device_code, "", "", agvaddr + "对应设备号为空"); return; } - for (Instruction inst : insts) { - //校验agv上报站点编号与指令起始点相同 - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到关联编号{}对应的指令", ikey); - logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey); - break; - } - - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); - } - - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到编号{}对应的指令", ikey); + logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey); + return; } + + if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); + standardOrdinarySiteDeviceDriver.setAgvphase(phase); + standardOrdinarySiteDeviceDriver.setIndex(index); + standardOrdinarySiteDeviceDriver.setInst(inst); + } + + if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { + siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); + if (siemensConveyorDeviceDriver.getMove() == 1) { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + } else { + log.info("请求取货条件不满足待机有货"); + } + } + + if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + } + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); + //取货完毕 //(需要WCS反馈) } else if (phase == 0x05) { @@ -198,28 +214,44 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic logServer.deviceExecuteLog(this.device_code, "", "", "对应设备号为空" + device_code); return; } - for (Instruction inst : insts) { - //校验agv上报站点编号与指令起始点相同 - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到关联编号{}对应的指令", ikey); - logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey); - break; + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey); + return; + } + + if (StrUtil.equals(inst.getStart_device_code(), device_code)) { + + if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); + standardOrdinarySiteDeviceDriver.setAgvphase(phase); + standardOrdinarySiteDeviceDriver.setIndex(index); + standardOrdinarySiteDeviceDriver.setInst(inst); } - if (StrUtil.equals(inst.getStart_device_code(), device_code)) { - - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); - } - - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); + if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { + siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); + if(siemensConveyorDeviceDriver.getTo_command() == 2){ + log.info("取货完成请求离开,当前输送to_command:"+siemensConveyorDeviceDriver.getTo_command()); data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + } else { + log.info("取货完成请求离开下发输送信号,当前输送to_command:"+siemensConveyorDeviceDriver.getTo_command()); + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_command"); + map.put("value", "2"); + list.add(map); + siemensConveyorDeviceDriver.writing(list); + siemensConveyorDeviceDriver.writing(list); } } + + if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { + standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + } + } logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); @@ -251,26 +283,26 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic log.info(agvaddr + "对应设备号为空!"); return; } - for (Instruction inst : insts) { - //校验agv上报站点编号与指令起始点相同 - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到关联编号{}对应的指令", ikey); - break; - } - if (StrUtil.equals(inst.getNext_device_code(), device_code)) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + return; + } + if (StrUtil.equals(inst.getNext_device_code(), device_code)) { - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); - } - - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } + if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); +// standardOrdinarySiteDeviceDriver.setAgvphase(phase); +// standardOrdinarySiteDeviceDriver.setIndex(index); +// standardOrdinarySiteDeviceDriver.setInst(inst); + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); } + + if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { + standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + } + } logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); @@ -303,25 +335,26 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic log.info(agvaddr + "对应设备号为空!"); return; } - for (Instruction inst : insts) { - //校验agv上报站点编号与指令起始点相同 - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到关联编号{}对应的指令", ikey); - break; - } - if (StrUtil.equals(inst.getNext_device_code(), device_code)) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到编号{}对应的指令", ikey); + return; + } + if (StrUtil.equals(inst.getNext_device_code(), device_code)) { - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); - } - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } + if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { + standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); } + + if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); +// standardOrdinarySiteDeviceDriver.setAgvphase(phase); +// standardOrdinarySiteDeviceDriver.setIndex(index); +// standardOrdinarySiteDeviceDriver.setInst(inst); + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + } + } logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); @@ -334,10 +367,10 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic agvaddr_copy = agvaddr; data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); - }else if(phase == 0x50){//进入交通灯区域 + } else if (phase == 0x50) {//进入交通灯区域 data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); - }else if(phase == 0x51){//离开交通灯区域 + } else if (phase == 0x51) {//离开交通灯区域 data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); } 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 a347f2f..88363cb 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 2b566d8..73f6ad5 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 a02e553..02651d0 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 c18c2d9..7cf39de 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 b6f15f5..886c2d8 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 1affdce..39f29a9 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 @@ -82,12 +82,12 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple public int error1 = 0; public int material = 0; public int consumption = 0; - public int voltageA = 0; - public int voltageB = 0; - public int voltageC = 0; - public int currentA = 0; - public int currentB = 0; - public int currentC = 0; + public float voltageA = 0; + public float voltageB = 0; + public float voltageC = 0; + public float currentA = 0; + public float currentB = 0; + public float currentC = 0; public int last_heartbeat = 0; public int last_mode = 0; @@ -104,12 +104,12 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple public int last_error1 = 0; public int last_material = 0; public int last_consumption = 0; - public int last_voltageA = 0; - public int last_voltageB = 0; - public int last_voltageC = 0; - public int last_currentA = 0; - public int last_currentB = 0; - public int last_currentC = 0; + public float last_voltageA = 0; + public float last_voltageB = 0; + public float last_voltageC = 0; + public float last_currentA = 0; + public float last_currentB = 0; + public float last_currentC = 0; Boolean isonline = true; @@ -171,15 +171,17 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple } logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_finish + "->" + finish); } - - - if (error != 0) { + if (mode == 0) { this.setIsonline(false); + message = "有报警"; + //无报警 + } else if (error != 0) { this.setIserror(true); message = "有报警"; //无报警 } else { - + this.setIsonline(true); + this.setIserror(false); if (move == 0 && last_move == 1) { //requireSucess = false; } @@ -221,11 +223,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 +250,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 +268,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 +283,7 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple log.info("设备:" + device_code + ",下发PLC信号" + to_task + ",value:" + command); } - ReadUtil.write(itemMap, server); + this.control(itemMap); } @Override @@ -293,12 +295,15 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple if (this.getMode() == 0) { mode = "未联机"; } else if (this.getMode() == 1) { - mode = "单机"; + mode = "联机"; } else if (this.getMode() == 2) { mode = "联机"; - } else if (this.getMode() == 3) { - mode = "运行中"; } + String requireSucess = "0"; + if (this.requireSucess) { + requireSucess = "1"; + } + jo.put("requireSucess", requireSucess); if (this.getMove() == 0) { move = "无货"; @@ -311,6 +316,15 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple jo.put("hasGoods", true); } jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("temperature", temperature); + jo.put("finish", finish); + jo.put("isOnline", this.getIsonline()); + jo.put("error", this.getError()); + jo.put("isError", this.getIserror()); + jo.put("countdown_house", countdown_house); + jo.put("countdown_min", countdown_min); + jo.put("countdown_sec", countdown_sec); + jo.put("door", door); jo.put("mode", mode); jo.put("move", move); jo.put("action", action); 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 10ee502..03e42ab 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 @@ -99,23 +99,23 @@ public class ItemProtocol { public int getItem_consumption(){ return this.getOpcIntegerValue(item_consumption); } ; - public int getItem_voltageA(){ - return this.getOpcIntegerValue(item_voltageA); + public float getItem_voltageA(){ + return this.getOpcFloatValue(item_voltageA); } ; - public int getItem_voltageB(){ - return this.getOpcIntegerValue(item_voltageB); + public float getItem_voltageB(){ + return this.getOpcFloatValue(item_voltageB); } ; - public int getItem_voltageC(){ - return this.getOpcIntegerValue(item_voltageC); + public float getItem_voltageC(){ + return this.getOpcFloatValue(item_voltageC); } ; - public int getItem_currentA(){ - return this.getOpcIntegerValue(item_currentA); + public float getItem_currentA(){ + return this.getOpcFloatValue(item_currentA); } ; - public int getItem_currentB(){ - return this.getOpcIntegerValue(item_currentB); + public float getItem_currentB(){ + return this.getOpcFloatValue(item_currentB); } ; - public int getItem_currentC(){ - return this.getOpcIntegerValue(item_currentC); + public float getItem_currentC(){ + return this.getOpcFloatValue(item_currentC); } ; Boolean isonline; @@ -132,6 +132,18 @@ public class ItemProtocol { } + public float getOpcFloatValue(String protocol) { + Float value = this.driver.getDoubleValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0L; + + } + public static List getReadableItemDtos() { ArrayList list = new ArrayList(); list.add(new ItemDto(item_heartbeat, "心跳", "251")); @@ -171,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 bfde080..c963542 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 9bff921..2b58f54 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 @@ -126,7 +126,10 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i task = this.itemProtocol.getTask(); if (mode != last_mode) { if (mode == 2) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号复位前requireSuccess:" + requireSucess); this.setRequireSucess(false); + message = null; + logServer.deviceExecuteLog(this.device_code, "", "", "信号复位后requireSuccess:" + requireSucess); } logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); @@ -159,8 +162,9 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i if (inst1 != null) { if (StrUtil.equals(inst1.getInstruction_status(), "0")) { 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(); @@ -185,22 +189,58 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i if (device.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) device.getDeviceDriver(); //hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); - if (hongXiangConveyorDeviceDriver.getMode() == 1 && hongXiangConveyorDeviceDriver.getDoor() == 1 && hongXiangConveyorDeviceDriver.getAction() == 1 && hongXiangConveyorDeviceDriver.getError1() == 0) { - this.writing("to_command", "2"); - this.setNow_steps_type(3); + int mode = hongXiangConveyorDeviceDriver.getMode(); + int door = hongXiangConveyorDeviceDriver.getDoor(); + int action = hongXiangConveyorDeviceDriver.getAction(); + int error1 = hongXiangConveyorDeviceDriver.getError1(); + if (mode == 1 && door == 1 && action == 1 && error1 == 0) { + if (this.getNow_steps_type() == 2) { + this.writing("to_command", "2"); + this.setNow_steps_type(3); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为下发电气信号(now_steps_type!=2)"); + } } else { if (this.getNow_steps_type() == 2) { - feedMessage = "请检查烘箱:door=1&&action==1&&error1=0"; + feedMessage = "烘箱:" + hongXiangConveyorDeviceDriver.getDevice_code(); + if (mode != 1) { + feedMessage = feedMessage + "mode未联机,"; + } + if (door != 1) { + feedMessage = feedMessage + "door未开门,"; + } + if (action != 1) { + feedMessage = feedMessage + "action未允许取放,"; + } + if (error1 != 0) { + feedMessage = feedMessage + "error1出现故障。"; + } } } } else { - this.writing("to_command", "2"); - this.setNow_steps_type(3); + if (this.getNow_steps_type() == 2) { + this.writing("to_command", "2"); + this.setNow_steps_type(3); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为下发电气信号(now_steps_type!=2)\")"); + } } } } else { if (this.getNow_steps_type() == 2) { - feedMessage = "请检查:mode == 3 && action == 1 && move == 0 && task > 0"; + feedMessage = "行架机械手:"; + if (mode != 3) { + feedMessage = feedMessage + "mode不为运行中状态,"; + } + if (action != 1) { + feedMessage = feedMessage + "action不为取货中状态,"; + } + if (move != 0) { + feedMessage = feedMessage + "move不为无货状态,"; + } + if (task == 0) { + feedMessage = feedMessage + "task为0。"; + } } } @@ -215,12 +255,28 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) device.getDeviceDriver(); hongXiangConveyorDeviceDriver.writing("to_close_door", "1"); } - this.writing("to_command", "3"); - this.setNow_steps_type(4); + if (this.getNow_steps_type() == 3) { + this.writing("to_command", "3"); + this.setNow_steps_type(4); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为允许取货(now_steps_type!=3)"); + } } } else { if (this.getNow_steps_type() == 3) { - feedMessage = "请检查:mode == 3 && action == 2 && move == 1 && task > 0"; + feedMessage = "行架机械手:"; + if (mode != 3) { + feedMessage = feedMessage + "mode不为运行中状态,"; + } + if (action != 2) { + feedMessage = feedMessage + "action不为取货完成状态,"; + } + if (move != 1) { + feedMessage = feedMessage + "move不为有货状态,"; + } + if (task == 0) { + feedMessage = feedMessage + "task为0。"; + } } } @@ -233,19 +289,55 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i if (nextDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextDevice.getDeviceDriver(); //hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); - if (hongXiangConveyorDeviceDriver.getMode() == 1 && hongXiangConveyorDeviceDriver.getDoor() == 1 && hongXiangConveyorDeviceDriver.getAction() == 1 && hongXiangConveyorDeviceDriver.getError1() == 0) { + int mode = hongXiangConveyorDeviceDriver.getMode(); + int door = hongXiangConveyorDeviceDriver.getDoor(); + int action = hongXiangConveyorDeviceDriver.getAction(); + int error1 = hongXiangConveyorDeviceDriver.getError1(); + if (mode == 1 && door == 1 && action == 1 && error1 == 0) { + if (this.getNow_steps_type() == 4) { + this.writing("to_command", "4"); + this.setNow_steps_type(5); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为允许放货(now_steps_type!=4)"); + } + } else { + feedMessage = "烘箱:" + hongXiangConveyorDeviceDriver.getDevice_code(); + if (mode != 1) { + feedMessage = feedMessage + "mode未联机,"; + } + if (door != 1) { + feedMessage = feedMessage + "door未开门,"; + } + if (action != 1) { + feedMessage = feedMessage + "action未允许取放,"; + } + if (error1 != 0) { + feedMessage = feedMessage + "error1出现故障。"; + } + } + } else { + if (this.getNow_steps_type() == 4) { this.writing("to_command", "4"); this.setNow_steps_type(5); } else { - feedMessage = "请检查烘箱:door=1&&action==1&&error1=0"; + logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为允许放货(now_steps_type!=4)"); } - } else { - this.writing("to_command", "4"); - this.setNow_steps_type(5); } } else { if (this.getNow_steps_type() == 4) { - feedMessage = "请检查:mode == 3 && action == 3 && move == 1 && task > 0"; + feedMessage = "行架机械手:"; + if (mode != 3) { + feedMessage = feedMessage + "mode不为运行中状态,"; + } + if (action != 3) { + feedMessage = feedMessage + "action不为放货中状态,"; + } + if (move != 1) { + feedMessage = feedMessage + "move不为有货状态,"; + } + if (task == 0) { + feedMessage = feedMessage + "task为0。"; + } } } @@ -282,10 +374,14 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i hongXiangConveyorDeviceDriver.writing("to_time_min", String.valueOf(minutes)); } } - this.writing("to_command", "5"); - this.setNow_steps_type(6); - this.setNow_steps_type(0); - feedMessage = ""; + if (this.getNow_steps_type() == 5) { + this.writing("to_command", "5"); + this.setNow_steps_type(6); + this.setNow_steps_type(0); + feedMessage = ""; + } else { + logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为放货完成(now_steps_type!=5)"); + } // this.writing("to_onset", "0"); // this.writing("to_target", "0"); // this.writing("to_task", "0"); @@ -293,28 +389,38 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i } } else { if (this.getNow_steps_type() == 5) { - feedMessage = "请检查:mode == 3 && action == 4 && move == 0 && task > 0"; + feedMessage = "行架机械手:"; + if (mode != 3) { + feedMessage = feedMessage + "mode不为运行中状态,"; + } + if (action != 4) { + feedMessage = feedMessage + "action不为放货完成状态,"; + } + if (move != 0) { + feedMessage = feedMessage + "move不为无货状态,"; + } + if (task == 0) { + feedMessage = feedMessage + "task为0。"; + } } } } catch (Exception var17) { feedMessage = var17.getMessage(); logServer.deviceExecuteLog(this.getDevice_code(), "", "", "读取信号值时出现异常:" + var17.getMessage()); - return; } - if (!this.itemProtocol.getIsonline()) { +// if (!this.itemProtocol.getIsonline()) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "信号量同步异常"; +// //未联机 +// } else + if (mode == 0) { 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 = "有报警"; //无报警 @@ -334,15 +440,18 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i } else { if (mode == 2) { //if (!requireSucess) { - String remark = ""; + String remark = "未查找任务原因为:"; if (mode != 2) { - remark = remark + "mode不为2,"; + remark = remark + "mode不是待机状态,"; } if (move != 0) { - remark = remark + "move不为0,"; + remark = remark + "move为有货状态,"; } if (task != 0) { - remark = remark + "task不为0,"; + remark = remark + "task任务号不为0,"; + } + if (requireSucess) { + remark = remark + "请求标记requireSucess为true。"; } this.setNotCreateTaskMessage(remark); //} @@ -475,7 +584,7 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i instructionService.create(instdto); } catch (Exception e) { notCreateInstMessage = e.getMessage(); - e.printStackTrace(); + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); return false; } //创建指令后修改任务状态 @@ -487,10 +596,12 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i Device nextDevice = deviceAppService.findDeviceByCode(instdto.getNext_device_code()); if (ObjectUtil.isEmpty(startDevice.getExtraValue().get("address"))) { notCreateInstMessage = "设备:" + startDevice.getDevice_code() + "未设置电气调度号!"; + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "设备:" + startDevice.getDevice_code() + "未设置电气调度号!"); throw new BadRequestException("设备:" + startDevice.getDevice_code() + "未设置电气调度号!"); } if (ObjectUtil.isEmpty(nextDevice.getExtraValue().get("address"))) { notCreateInstMessage = "设备:" + nextDevice.getDevice_code() + "未设置电气调度号!"; + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "设备:" + nextDevice.getDevice_code() + "未设置电气调度号!"); throw new BadRequestException("设备:" + nextDevice.getDevice_code() + "未设置电气调度号!"); } String start_addr = startDevice.getExtraValue().get("address").toString(); @@ -505,7 +616,7 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); } - if (startDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver){ + if (startDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startDevice.getDeviceDriver(); hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); @@ -534,18 +645,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); } //判断取货位或放货位为烘箱设备时关联的同一列烘箱设备是否有开门 @@ -608,16 +719,17 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i } } catch (Exception e) { isClose = true; + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "检查烘箱是否关门时出现异常:" + e.getMessage()); notCreateInstMessage = "检查烘箱是否关门时出现异常:" + e.getMessage(); } return isClose; } 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); } @@ -678,6 +790,11 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i move = "有货"; } + String requireSucess = "0"; + if (this.requireSucess) { + requireSucess = "1"; + } + jo.put("requireSucess", requireSucess); if (this.getAction() == 1) { action = "取货中"; } else if (this.getAction() == 2) { @@ -701,12 +818,19 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i jo.put("notCreateTaskMessage", notCreateTaskMessage); jo.put("notCreateInstMessage", notCreateInstMessage); jo.put("feedMessage", feedMessage); + jo.put("driver_type", "siemens_conveyor"); + jo.put("is_click", true); 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(int type, int command) { @@ -718,7 +842,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 a90ec80..64bca67 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 new file mode 100644 index 0000000..68656c2 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java @@ -0,0 +1,161 @@ +package org.nl.acs.device_driver.basedriver.plug_pull_device_site; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + //1/0 手动/自动 + public static String item_mode = "mode"; + //0/1 半自动/全自动 + public static String item_action = "action"; + //0/1 远程/本地控制 + public static String item_control = "control"; + //2 运行中 + //1 急停/故障 + //0 待机中 + public static String item_status = "status"; + //1 机头上有轴 + public static String item_move = "move"; + //1/0 穿轴中/穿轴完成 + public static String item_plug_finish = "plug_finish"; + //1/0 把轴中/拔轴完成 + public static String item_pull_finish = "pull_finish"; + //3寸轴穿轴次数 + public static String item_3plug_times = "3plug_times"; + //6寸轴穿轴次数 + public static String item_6plug_times = "6plug_times"; + //3寸轴拔轴次数 + public static String item_3pull_times = "3pull_times"; + //6寸轴拔轴次数 + public static String item_6pull_times = "6pull_times"; + //穿轴总次数 + public static String item_plug_alltimes = "plug_alltimes"; + //拔轴总次数 + public static String item_pull_alltimes = "pull_alltimes"; + + + //1 全自动启动 + public static String item_to_command = "to_command"; + //0/1 穿轴/拔轴 + public static String item_to_type = "to_type"; + //3/6 轴尺寸 + public static String item_to_size = "to_size"; + + + private PlugPullDeviceSiteDeviceDriver driver; + + public ItemProtocol(PlugPullDeviceSiteDeviceDriver driver) { + this.driver = driver; + } + + public int getItem_mode(){ + return this.getOpcIntegerValue(item_mode); + } ; + public int getItem_move(){ + return this.getOpcIntegerValue(item_move); + } ; + public int getItem_action(){ + return this.getOpcIntegerValue(item_action); + }; + public int getItem_control(){ + return this.getOpcIntegerValue(item_control); + } ; + public int getItem_status(){ + return this.getOpcIntegerValue(item_status); + } ; + public int getItem_plug_finish(){ + return this.getOpcIntegerValue(item_plug_finish); + } ; + public int getItem_pull_finish(){ + return this.getOpcIntegerValue(item_pull_finish); + } ; + public int getItem_3plug_times(){ + return this.getOpcIntegerValue(item_3plug_times); + } ; + public int getItem_6plug_times(){ + return this.getOpcIntegerValue(item_6plug_times); + } ; + public int getItem_3pull_times(){ + return this.getOpcIntegerValue(item_3pull_times); + } ; + public int getItem_6pull_times(){ + return this.getOpcIntegerValue(item_6pull_times); + } ; + public int getItem_plug_alltimes(){ + return this.getOpcIntegerValue(item_plug_alltimes); + } ; + public int getItem_pull_alltimes(){ + return this.getOpcIntegerValue(item_pull_alltimes); + } ; + + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public float getOpcFloatValue(String protocol) { + Float value = this.driver.getDoubleValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_mode, "工作模式", "30243")); + list.add(new ItemDto(item_action, "半自动/全自动", "30245")); + list.add(new ItemDto(item_control, "远程控制", "30254")); + list.add(new ItemDto(item_status, "状态", "30181")); + list.add(new ItemDto(item_move, "机头上有轴", "30252")); + list.add(new ItemDto(item_plug_finish, "穿轴完成", "30249")); + list.add(new ItemDto(item_pull_finish, "拔轴完成", "30250")); + list.add(new ItemDto(item_3plug_times, "3寸轴穿轴次数", "30231")); + list.add(new ItemDto(item_6plug_times, "6寸轴穿轴次数", "30235")); + list.add(new ItemDto(item_3pull_times, "3寸轴拔轴次数", "30233")); + list.add(new ItemDto(item_6pull_times, "6寸轴拔轴次数", "30237")); + list.add(new ItemDto(item_plug_alltimes, "穿轴总次数", "30239")); + list.add(new ItemDto(item_pull_alltimes, "拔轴总次数", "30241")); + + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "40246")); + list.add(new ItemDto(item_to_type, "类型", "40244")); + list.add(new ItemDto(item_to_size, "尺寸", "40247")); + + 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/PlugPullDeviceSiteDefination.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDefination.java new file mode 100644 index 0000000..bce3297 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDefination.java @@ -0,0 +1,60 @@ +package org.nl.acs.device_driver.basedriver.plug_pull_device_site; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 插拔轴工位 + */ +@Service +public class PlugPullDeviceSiteDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "plug_pull_device_site"; + } + + @Override + public String getDriverName() { + return "插拔轴工位"; + } + + @Override + public String getDriverDescription() { + return "插拔轴工位"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new PlugPullDeviceSiteDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return PlugPullDeviceSiteDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} 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 new file mode 100644 index 0000000..a46c520 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDeviceDriver.java @@ -0,0 +1,239 @@ +package org.nl.acs.device_driver.basedriver.plug_pull_device_site; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; +import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 插拔轴工位 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class PlugPullDeviceSiteDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService paramService = SpringContextHolder.getBean(ParamService.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); + @Autowired + AgvService agvService = SpringContextHolder.getBean(AgvService.class); + + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + + public int mode = 0; + public int move = 0; + public int action = 0; + public int status = 0; + public int control = 0; + public int plug_finish = 0; + public int pull_finish = 0; + public int plug3_times = 0; + public int plug6_times = 0; + public int pull3_times = 0; + public int pull6_times = 0; + public int plug_alltimes = 0; + public int pull_alltimes = 0; + + public int last_mode = 0; + public int last_move = 0; + public int last_action = 0; + public int last_status = 0; + public int last_control = 0; + public int last_plug_finish = 0; + public int last_pull_finish = 0; + + + Boolean isonline = true; + + Boolean iserror = false; + + //1-执行任务;2-取货完成;3-放货完成; + int flag; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + //请求成功标记 + Boolean requireSucess = false; + + @Override + public void execute() { + String message = null; + + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getItem_mode(); + move = this.itemProtocol.getItem_move(); + action = this.itemProtocol.getItem_action(); + status = this.itemProtocol.getItem_status(); + control = this.itemProtocol.getItem_control(); + plug_finish = this.itemProtocol.getItem_plug_finish(); + pull_finish = this.itemProtocol.getItem_pull_finish(); + plug3_times = this.itemProtocol.getItem_3plug_times(); + plug6_times = this.itemProtocol.getItem_6plug_times(); + pull3_times = this.itemProtocol.getItem_3pull_times(); + pull6_times = this.itemProtocol.getItem_6pull_times(); + plug_alltimes = this.itemProtocol.getItem_plug_alltimes(); + pull_alltimes = this.itemProtocol.getItem_pull_alltimes(); + + + + + if (status != 1) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + + + } + + last_mode = mode; + last_move = move; + last_action = action; + } + + + protected void thingToNothing() { + //this.setRequireSucess(false); + } + + 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 List getExtraDeviceCodes(String extraName) { + String extraValue = (String) this.getDevice().getExtraValue().get(extraName); + if (StrUtil.isEmpty(extraValue)) { + return new ArrayList<>(); + } + String devicesString = extraValue.substring(1, extraValue.length() - 1); + List devicesList = new ArrayList<>(); + String[] devices = devicesString.split(","); + for (int i = 0; i < devices.length; i++) { + String s = devices[i].replace("\"", "").replace("\"", ""); + devicesList.add(s); + } + return devicesList; + } + + + + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + String mode = ""; + String action = ""; + String move = ""; + if (this.getMode() == 0) { + mode = "未联机"; + } else if (this.getMode() == 1) { + mode = "单机"; + } else if (this.getMode() == 2) { + mode = "联机"; + } else if (this.getMode() == 3) { + mode = "运行中"; + } + + 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); + } + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("mode", mode); + jo.put("move", move); + jo.put("action", action); + jo.put("isOnline", this.getIsonline()); + jo.put("isError", this.getIserror()); + return jo; + } + + @Override + public void setDeviceStatus(JSONObject data) { + + } + + 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, value); +// itemMap.put(to_param, Integer.parseInt(value)); + this.control(itemMap); + } + + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/ItemProtocol.java index afe2f4f..32616f2 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/ItemProtocol.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/ItemProtocol.java @@ -73,6 +73,10 @@ public class ItemProtocol { return this.getOpcIntegerValue(item_task); } + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + Boolean isonline; @@ -123,5 +127,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/siemens_conveyor/SiemensConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java index 6caae49..8e5840d 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,20 +4,27 @@ 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; +import org.nl.acs.agv.server.NDCAgvService; import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device_driver.DeviceDriver; import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.ScannerDeviceDriver; +import org.nl.acs.device_driver.basedriver.standard_scanner.StandardScannerDeviceDriver; import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; +import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; @@ -64,6 +71,8 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); @Autowired DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); //当前指令 Instruction inst = null; @@ -82,8 +91,12 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme //任务号 int task = 0; int last_task = 0; + int agvphase = 0; + String task_code = null; + int to_command = 0; - + int phase = 0; + int index = 0; Boolean isonline = true; int hasGoods = 0; String message = null; @@ -96,17 +109,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; //当前指令 @@ -115,6 +130,8 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme String device_code; + String vehicle_code; + String last_vehicle_code; @Override public Device getDevice() { @@ -123,8 +140,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(); @@ -132,36 +148,32 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme carrier_direction = this.itemProtocol.getCarrier_direction(); error = this.itemProtocol.getError(); task = this.itemProtocol.getTask(); + to_command = this.itemProtocol.getTo_command(); if (mode != last_mode) { if (mode == 2) { - logServer.deviceExecuteLog(device_code, "", "", "开始请求标记复位`此时请求标记值为requireSucess:" + requireSucess); requireSucess = false; - logServer.deviceExecuteLog(device_code, "", "", "请求标记复位成功`此时请求标记值为requireSucess:" + requireSucess); - } - if (mode == 4) { - logServer.deviceExecuteLog(device_code, "", "", "开始请求标记复位`此时请求标记值为requireApplyLabelingSuccess:" + requireApplyLabelingSuccess); requireApplyLabelingSuccess = false; - logServer.deviceExecuteLog(device_code, "", "", "请求标记复位成功`此时请求标记值为requireApplyLabelingSuccess:" + requireApplyLabelingSuccess); - } - if (mode == 5) { - logServer.deviceExecuteLog(device_code, "", "", "开始请求标记复位`此时请求标记值为requireApplyLaStrangulationSuccess:" + requireApplyLaStrangulationSuccess); requireApplyLaStrangulationSuccess = false; - logServer.deviceExecuteLog(device_code, "", "", "请求标记复位成功`此时请求标记值为requireApplyLaStrangulationSuccess:" + requireApplyLaStrangulationSuccess); - } - if (mode == 6) { - logServer.deviceExecuteLog(device_code, "", "", "开始请求标记复位`此时请求标记值为requireEmptyInSuccess:" + requireEmptyInSuccess); requireEmptyInSuccess = false; - logServer.deviceExecuteLog(device_code, "", "", "请求标记复位成功`此时请求标记值为requireEmptyInSuccess:" + requireEmptyInSuccess); - } - if (mode == 7) { - logServer.deviceExecuteLog(device_code, "", "", "开始请求标记复位`此时请求标记值为requireEmptyOutSuccess:" + requireEmptyOutSuccess); requireEmptyOutSuccess = false; - logServer.deviceExecuteLog(device_code, "", "", "请求标记复位成功`此时请求标记值为requireEmptyOutSuccess:" + requireEmptyOutSuccess); + 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) { + 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 ("true".equals(this.device.getExtraValue().get("ship_device_update"))) { + this.requiresShipDeviceUpdate = false; + } + } logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); } @@ -178,45 +190,44 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); } - if (task > 0) { - Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); - if (ObjectUtil.isNotEmpty(instruction)) { - - if (StrUtil.equals(this.getDeviceCode(), instruction.getStart_device_code())) { - - if (StrUtil.equals(instruction.getInstruction_status(), "0")) { - instruction.setInstruction_status("1"); - instructionService.update(instruction); - } - - String next_device_code = instruction.getNext_device_code(); - Device device = deviceAppservice.findDeviceByCode(next_device_code); - if (ObjectUtil.isEmpty(device)) { - logServer.deviceExecuteLog(this.device_code, "", "", "任务号:" + task + "输送线任务未完成,目标站设备为空!"); - return; - } - SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; - if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { - siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); - int nextTask = siemensConveyorDeviceDriver.getTask(); - if (nextTask == task) { - inst_message = "指令号:" + instruction.getInstruction_code() + " " + instruction.getStart_point_code() + "->" + instruction.getNext_point_code() + " 载具号:" + instruction.getVehicle_code(); - if (StrUtil.equals(instruction.getInstruction_status(), "1")) { - inst = instruction; - finish_instruction(); - this.clearWrite(); - } - } - } + 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(); + 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()) { @@ -227,18 +238,21 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme // } else if (mode == 0) { this.setIsonline(false); - this.setIserror(true); message = "未联机"; //有报警 - } else if (error != 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 = ""; + if (error != 0) { + this.setIserror(true); + message = "有报警"; + } + Instruction instruction = null; List toInstructions; @@ -267,17 +281,23 @@ 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 && !requireApplyLabelingSuccess) { - applyLabeling(); + //申请捆扎 + if (move > 0 ) { + applyLaStrangulation(); } break; case 5: - //申请困扎 - if (move > 0 && !requireApplyLaStrangulationSuccess) { - applyLaStrangulation(); + //申请贴标 + if (move > 0 && !requireSucess) { + applyLabeling(); + } break; case 6: @@ -285,13 +305,22 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme if (move > 0 && !requireEmptyInSuccess) { emptyIn(); } + if (move > 0 && !requireSucess) { + instruction_require(); + } break; case 7: - //空托盘满垛出库申请 - if (move > 0 && !requireEmptyOutSuccess) { + //空盘出库申请 + if (move == 0 && !requireSucess) { emptyOut(); } break; + case 8: + //申请AGV任务 + if (move == 1 && !requireSucess) { + applyAgvTask(); + } + break; } } @@ -302,6 +331,17 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme last_task = task; } + private void shipDeviceUpdate() { + JSONObject param = new JSONObject() {{ + put("device_code", device_code); + }}; + + HttpResponse response = acsToWmsService.shipDeviceUpdate(param); + if (response == null || response.getStatus() == 200) { + this.requiresShipDeviceUpdate = true; + } + } + public boolean exe_error() { if (this.error == 0) { @@ -313,13 +353,39 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme } public void clearWrite() { - this.writing("to_command", "0"); - this.writing("to_target", "0"); - this.writing("to_container_type", "0"); - this.writing("to_strap_times", "0"); - this.writing("to_length", "0"); - this.writing("to_weight", "0"); - this.writing("to_height", "0"); + + 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() { @@ -328,6 +394,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme public synchronized boolean finish_instruction() throws Exception { instructionService.finish(inst); +// requireSucess = false; return true; } @@ -341,26 +408,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); } @@ -378,12 +445,27 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme 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); } if (this.carrier_direction == 1) { @@ -395,12 +477,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()); @@ -416,64 +504,110 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme String requestSucess = data.getString("requireSucess"); if (StrUtil.equals(requestSucess, "0")) { this.requireSucess = false; - } else { + } else if (StrUtil.equals(requestSucess, "1")) { this.requireSucess = true; } } -// public void writing(int type, int command) { -// String to_material_code = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() -// + "." + ItemProtocol.item_to_material_code; + public void writing(List list) { + // String opcservcerid = this.getDevice().getOpc_server_id(); // Server server = ReadUtil.getServer(opcservcerid); -// Map itemMap = new HashMap(); -// if (type == 2) { -// itemMap.put(to_material_code, command); -// } -// ReadUtil.write(itemMap, server); -// -// } + 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() 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); return false; } else { this.instruction_require_time = date; - //container_code - TaskDto task = taskserver.findByStartCodeAndReady(device_code); - if (!ObjectUtil.isEmpty(task)) { + //判断是否存在起点相同 任务状态就绪的任务 + TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code); + if (!ObjectUtil.isEmpty(taskdto)) { // if (!ObjectUtils.isEmpty(instructionService.findByBarcodeFromCache(container_code))) { // return false; // } - String taskid = task.getTask_id(); - String taskcode = task.getTask_code(); - String vehiclecode = task.getVehicle_code(); - String priority = task.getPriority(); - String start_point_code = task.getStart_point_code(); - String start_device_code = task.getStart_device_code(); - String route_plan_code = task.getRoute_plan_code(); + //需要判断当前设备是否已经存在就绪的指令 如果存在就直接下发 不存在则创建 + 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); +// message = "重新下发电气信号"; +// 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, task.getNext_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, task.getNext_device_code(), route_plan_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("->"); -// if (!StrUtil.equals(type, "0")) { -// return false; -// } + List pathlist = Arrays.asList(str); int index = 0; for (int m = 0; m < pathlist.size(); m++) { @@ -496,16 +630,16 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); String next_point_code; if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { - next_point_code = task.getTo_x() + "-" + task.getTo_y() + "-" + task.getTo_z(); + 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(task.getRemark()); - instdto.setMaterial(task.getMaterial()); - instdto.setQuantity(task.getQuantity()); + instdto.setRemark(taskdto.getRemark()); + instdto.setMaterial(taskdto.getMaterial()); + instdto.setQuantity(taskdto.getQuantity()); instdto.setTask_id(taskid); instdto.setTask_code(taskcode); instdto.setVehicle_code(vehiclecode); @@ -519,23 +653,75 @@ 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; + } //创建指令后修改任务状态 - task.setTask_status("1"); - taskserver.update(task); + taskdto.setTask_status("1"); + taskserver.update(taskdto); requireSucess = true; String next_addr = nextdevice.getExtraValue().get("address").toString(); - this.writing("to_target", next_addr); - this.writing("to_task", instdto.getInstruction_code()); - this.writing("to_command", "1"); - this.writing("to_task", instdto.getInstruction_code()); - this.writing("to_target", next_addr); - this.writing("to_command", "1"); + + 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); +// message = "重新下发电气信号"; +// 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; } } + //申请贴标 public synchronized void applyLabeling() { Date date = new Date(); if (date.getTime() - this.require_apply_labeling_time.getTime() < (long) this.instruction_require_time_out) { @@ -543,6 +729,20 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme return; } else { this.require_apply_labeling_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); @@ -552,11 +752,28 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme } applyLabelingAndBindingRequest.setDevice_code(start_point_code); applyLabelingAndBindingRequest.setType("1"); - acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - requireApplyLabelingSuccess = true; + applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); + 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(); + } } } + //申请捆扎 + @SneakyThrows public synchronized void applyLaStrangulation() { Date date = new Date(); if (date.getTime() - this.require_apply_strangulation_time.getTime() < (long) this.instruction_require_time_out) { @@ -564,6 +781,27 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme return; } else { this.require_apply_strangulation_time = date; + String vehicle_code = ""; + if (task > 0) { + Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); + if(ObjectUtil.isEmpty(instruction)){ + message = "申请捆扎电气设备任务号:" + task + "未找到对应指令"; + return ; +// throw new RuntimeException("该电气任务号未找到对应指令!"); + } + vehicle_code = instruction.getVehicle_code(); + } else { + logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "异常"); + message = "申请捆扎电气设备任务号:" + task + "异常"; + return ; +// throw new RuntimeException("任务号为空!"); + } + if (StrUtil.isEmpty(vehicle_code)) { + logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "未找到载具号"); + message = "申请捆扎电气设备任务号:" + task + "未找到载具号"; + return ; +// throw new RuntimeException("载具号为空!"); + } ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = new ApplyLabelingAndBindingRequest(); JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); @@ -573,8 +811,50 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme } applyLabelingAndBindingRequest.setDevice_code(start_point_code); applyLabelingAndBindingRequest.setType("2"); - acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - requireApplyLaStrangulationSuccess = true; + 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 = "申请捆扎成功"; + requireSucess = true; + } else { + message = "未返回尺寸信息"; + } + + } else { + message = applyLabelingAndBindingResponse.getMessage(); + } + } } @@ -585,6 +865,75 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme return; } else { this.require_empty_in_time = date; + + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + message = "申请空盘入库任务中..."; + + if(taskserver.querySameOriginTask(this.device_code) > 0 ){ + message = "已存在空盘出库任务不再请求"; + return; + } + + 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 = "申请空盘入库接口不通"; + requireEmptyInSuccess = true; + } else { + if (jo.getInteger("status") == 200) { + message = "申请空盘入库成功"; + requireEmptyInSuccess = true; + } else { + requireEmptyInSuccess = true; + 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")) { + Instruction instruction = instructionService.findByCode(String.valueOf(task)); + if(ObjectUtil.isEmpty(instruction)){ + message = "指令号"+task+"未找到对应指令"; + return; + } + if(StrUtil.isEmpty(instruction.getVehicle_code())){ + message = "指令号"+task+"未找到对应木箱号"; + return; + } + message = "申请AGV搬运任务中..."; + JSONObject apply = new JSONObject(); + apply.put("device_code", device_code); + apply.put("type", "4"); + apply.put("vehicle_code", instruction.getVehicle_code()); + String str = acsToWmsService.applyTaskToWms(apply); + 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 = true; + message = "申请AGV搬运任务失败," + jo.get("message").toString(); + } + } + + } } } @@ -595,7 +944,33 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme return; } else { this.require_empty_out_time = date; + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + if(taskserver.querySameDestinationTask(this.device_code) > 0 ){ + message = "已存在空盘出库任务不再请求"; + return; + } + 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 = "申请空盘出库接口不通"; + requireSucess = true; + } else { + if (jo.getInteger("status") == 200) { + message = "申请空盘出库成功"; + requireSucess = true; + } else { + requireSucess = true; + message = "申请空盘出库失败," + jo.get("message").toString(); + } + } + + } } } + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/ItemProtocol.java new file mode 100644 index 0000000..6d64f74 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/ItemProtocol.java @@ -0,0 +1,132 @@ +package org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk; + +import cn.hutool.core.util.StrUtil; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + //心跳 + public static String item_heartbeat = "heartbeat"; + //工作模式 + public static String item_mode = "mode"; + //光电信号 + public static String item_move = "move"; + //托盘方向 + public static String item_carrier_direction = "carrier_direction"; + //报警 + public static String item_error = "error"; + //任务号 + public static String item_task = "task"; + + //下发命令 + public static String item_to_command = "to_command"; + //下发目标站 + public static String item_to_target = "to_target"; + //下发托盘类型 + public static String item_to_container_type = "to_container_type"; + //下发任务号 + public static String item_to_task = "to_task"; + //困扎次数 + public static String item_to_strap_times = "to_strap_times"; + //木箱长度 + public static String item_to_length = "to_length"; + //木箱宽度 + public static String item_to_weight = "to_weight"; + //木箱高度 + public static String item_to_height = "to_height"; + + + private SiemensConveyorCkkDeviceDriver driver; + + public ItemProtocol(SiemensConveyorCkkDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getCarrier_direction() { + return this.getOpcIntegerValue(item_carrier_direction); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + // log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public String getOpcStringValue(String protocol) { + String value = this.driver.getStringValue(protocol); + if (StrUtil.isEmpty(value)) { + + } else { + return value; + } + return "0"; + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB600.B2")); + list.add(new ItemDto(item_move, "光电信号", "DB600.B3")); + list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB600.B4")); + list.add(new ItemDto(item_error, "报警信号", "DB600.B6")); + list.add(new ItemDto(item_task, "任务号", "DB600.D10")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2")); + list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W4")); + list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB601.W6")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8")); + list.add(new ItemDto(item_to_strap_times, "困扎次数", "DB601.W12")); + list.add(new ItemDto(item_to_length, "木箱长度", "DB601.W14")); + list.add(new ItemDto(item_to_weight, "木箱宽度", "DB601.W16")); + list.add(new ItemDto(item_to_height, "木箱高度", "DB601.W18")); + return list; + } + + @Override + public String toString() { + return ""; + } + +} + diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDefination.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDefination.java new file mode 100644 index 0000000..248dc8f --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDefination.java @@ -0,0 +1,64 @@ +package org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 西门子-输送机驱动 + * + */ +@Service +public class SiemensConveyorCkkDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "siemens_conveyor_ckk"; + } + + @Override + public String getDriverName() { + return "西门子-输送机驱动-出库口"; + } + + @Override + public String getDriverDescription() { + return "西门子-输送机驱动-出库口"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new SiemensConveyorCkkDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return SiemensConveyorCkkDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.station); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDeviceDriver.java new file mode 100644 index 0000000..b7f935e --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDeviceDriver.java @@ -0,0 +1,914 @@ +package org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk; + +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.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; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; +import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 西门子-输送机驱动-出库口 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class SiemensConveyorCkkDeviceDriver 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; + + //工作模式 + 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 last_task = 0; + int agvphase = 0; + String task_code = null; + + 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 = 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; + + //当前指令 + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String device_code; + + String vehicle_code; + String last_vehicle_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + 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(); + 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) { + message = null; + if (move == 0 ) { + inst_message = null; + requireSucess = false; + 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 (move != 0 && task > 0) { + 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(); + 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(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()); + } + +// if (!this.itemProtocol.getIsonline()) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "信号量同步异常"; +// //未联机 +// } else + if (mode == 0) { + this.setIsonline(false); + message = "未联机"; + + } else { + this.setIsonline(true); + this.setIserror(false); + + if (error != 0) { + this.setIserror(true); + message = "有报警"; + } + + Instruction instruction = null; + List toInstructions; + + + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + //申请任务 + if (move > 0 && !requireSucess) { + try { + instruction_require(); + } catch (Exception e) { + e.printStackTrace(); + } + } + break; + case 4: + break; + case 5: + break; + case 6: + break; + case 7: + break; + case 8: + break; + } + } + last_mode = mode; + last_move = move; + last_carrier_direction = carrier_direction; + last_error = error; + last_task = task; + } + + private void shipDeviceUpdate() { + JSONObject param = new JSONObject() {{ + put("device_code", device_code); + }}; + + HttpResponse response = acsToWmsService.shipDeviceUpdate(param); + if (response == null || response.getStatus() == 200) { + this.requiresShipDeviceUpdate = true; + } + } + + + 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); + } + + 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("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()); + 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; + if (task > 0) { + Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); + if (ObjectUtil.isEmpty(instruction)) { + //instruction = instructionService.findByCode(String.valueOf(task)); + message ="任务号:"+task +"未找到对应立库指令,请检查"; + return false; + } + if(StrUtil.equals(instruction.getInstruction_status(),"1")){ + if (StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { + vehicle_code = inst.getVehicle_code(); + inst.setExecute_device_code(this.device_code); + try { + finish_instruction(); + } catch (Exception e) { + e.printStackTrace(); + } + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task); + } + } + } else { + logServer.deviceExecuteLog(device_code, "", "", "申请输送任务电气设备任务号:" + task + "异常"); + message = "申请输送任务电气设备任务号:" + task + "异常"; + return false; + } + + //判断是否存在起点相同 任务状态就绪的任务 + 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); + message = "重新下发电气信号"; + 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 { + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("指令创建失败!",e.getMessage()); + return false; + } + //创建指令后修改任务状态 + 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); + message = "重新下发电气信号"; + logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); + } + } else { + //如果不存在则直接找对应指令 + Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code); + if (ObjectUtil.isEmpty(inst)) { + 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() + "再次下发电气信号"); + } + requireSucess = true; + } + return 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 (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("1"); + applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); + 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(); + } + } + } + + //申请捆扎 + @SneakyThrows + 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)); + if(ObjectUtil.isEmpty(instruction)){ + message = "申请捆扎电气设备任务号:" + task + "未找到对应指令"; + throw new RuntimeException("该电气任务号未找到对应指令!"); + } + 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 = "申请捆扎成功"; + requireSucess = true; + } else { + message = "未返回尺寸信息"; + } + + } 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 = "申请空盘入库接口不通"; + requireEmptyInSuccess = true; + } else { + if (jo.getInteger("status") == 200) { + message = "申请空盘入库成功"; + requireEmptyInSuccess = true; + } else { + requireEmptyInSuccess = true; + 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")) { + Instruction instruction = instructionService.findByCode(String.valueOf(task)); + if(ObjectUtil.isEmpty(instruction)){ + message = "指令号"+task+"未找到对应指令"; + return; + } + message = "申请AGV搬运任务中..."; + JSONObject apply = new JSONObject(); + apply.put("device_code", device_code); + apply.put("type", "4"); + apply.put("vehicle_code", instruction.getVehicle_code()); + String str = acsToWmsService.applyTaskToWms(apply); + 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 = true; + 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 = "申请空盘出库接口不通"; + requireSucess = true; + } else { + if (jo.getInteger("status") == 200) { + message = "申请空盘出库成功"; + requireSucess = true; + } else { + 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/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/ItemProtocol.java new file mode 100644 index 0000000..baa5e9a --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/ItemProtocol.java @@ -0,0 +1,134 @@ +package org.nl.acs.device_driver.basedriver.siemens_conveyor_labeling; + +import cn.hutool.core.util.StrUtil; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + //心跳 + public static String item_heartbeat = "heartbeat"; + //工作模式 + public static String item_mode = "mode"; + //光电信号 + public static String item_move = "move"; + //托盘方向 + public static String item_carrier_direction = "carrier_direction"; + //报警 + public static String item_error = "error"; + //任务号 + public static String item_task = "task"; + //重量 + public static String item_weight = "weight"; + + //下发命令 + public static String item_to_command = "to_command"; + //下发目标站 + public static String item_to_target = "to_target"; + //下发托盘类型 + public static String item_to_container_type = "to_container_type"; + //下发任务号 + public static String item_to_task = "to_task"; + //困扎次数 + public static String item_to_strap_times = "to_strap_times"; + //木箱长度 + public static String item_to_length = "to_length"; + //木箱宽度 + public static String item_to_weight = "to_weight"; + //木箱高度 + public static String item_to_height = "to_height"; + + + private SiemensConveyorLabelingDeviceDriver driver; + + public ItemProtocol(SiemensConveyorLabelingDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getCarrier_direction() { + return this.getOpcIntegerValue(item_carrier_direction); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + public int getWeight() { + return this.getOpcIntegerValue(item_weight); + } + + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + // log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public String getOpcStringValue(String protocol) { + String value = this.driver.getStringValue(protocol); + if (StrUtil.isEmpty(value)) { + + } else { + return value; + } + return "0"; + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB101.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB101.B152")); + list.add(new ItemDto(item_move, "光电信号", "DB101.B153")); + list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB101.B154")); + list.add(new ItemDto(item_error, "报警信号", "DB101.B156")); + list.add(new ItemDto(item_task, "任务号", "DB101.D160")); + list.add(new ItemDto(item_weight, "重量", "DB101.D160")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "DB102.W152")); + list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W154")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB102.D158")); + return list; + } + + @Override + public String toString() { + return ""; + } + +} + diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDefination.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDefination.java new file mode 100644 index 0000000..20f246c --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDefination.java @@ -0,0 +1,64 @@ +package org.nl.acs.device_driver.basedriver.siemens_conveyor_labeling; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 西门子-输送机驱动-贴标 + * + */ +@Service +public class SiemensConveyorLabelingDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "siemens_conveyor_labeling"; + } + + @Override + public String getDriverName() { + return "西门子-输送机驱动-贴标"; + } + + @Override + public String getDriverDescription() { + return "西门子-输送机驱动-贴标"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new SiemensConveyorLabelingDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return SiemensConveyorLabelingDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.station); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} 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 new file mode 100644 index 0000000..b495fd2 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java @@ -0,0 +1,931 @@ +package org.nl.acs.device_driver.basedriver.siemens_conveyor_labeling; + +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 com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.nl.acs.AcsConfig; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; +import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +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; + + // 工作模式 + 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; + 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); + } + + 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); + } + } + + } 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); + message = "未联机"; + // 有报警 + // } else if (error != 0) { + // this.setIsonline(false); + // this.setIserror(true); + // message = "有报警"; + // //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + if (error != 0) { + this.setIserror(true); + message = "有报警"; + } + 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 && !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 { + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("指令创建异常!"); + return false; + } + // 创建指令后修改任务状态 + 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; + } + } + + // 申请贴标 + 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((float) 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 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(); + + 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 { + message = "未返回尺寸信息"; + } + + } 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 { + if (jo.getInteger("status") == 200) { + message = "申请空盘入库成功"; + requireEmptyInSuccess = true; + } else { + requireEmptyInSuccess = 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/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/ItemProtocol.java index 93caf7e..2ca2c06 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/ItemProtocol.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/ItemProtocol.java @@ -174,5 +174,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/slit_two_manipulator/SlitTwoManipulatorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/SlitTwoManipulatorDeviceDriver.java index da555b0..2d5c601 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(); @@ -213,6 +213,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl if (StrUtil.equals(inst1.getInstruction_status(), "0")) { //当前执行步骤为更新任务状态 inst1.setInstruction_status("1"); + inst1.setExecute_device_code(this.getDevice_code()); instructionService.update(inst1); // TaskDto taskDto = taskserver.findByCodeFromCache(inst1.getTask_code()); // if (!ObjectUtil.isEmpty(taskDto)) { @@ -240,6 +241,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl //当前指令更新状态 now_steps_type2 = 1; inst2.setInstruction_status("1"); + inst2.setExecute_device_code(this.device_code); instructionService.update(inst2); // TaskDto taskDto = taskserver.findByCodeFromCache(inst2.getTask_code()); // if (!ObjectUtil.isEmpty(taskDto)) { @@ -266,6 +268,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl if (StrUtil.equals(inst2.getInstruction_status(), "0")) { //当前指令更新状态 inst2.setInstruction_status("1"); + inst2.setExecute_device_code(this.device_code); instructionService.update(inst2); // TaskDto taskDto = taskserver.findByCodeFromCache(inst2.getTask_code()); // if (!ObjectUtil.isEmpty(taskDto)) { @@ -306,16 +309,32 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl this.setNow_steps_type3(3); } } else { - log.warn("前工位取货位无货,取货位:{},mode:{},move:{}", start_device_code, mode, move); + log.warn("后工位取货位无货,取货位:{},mode:{},move:{}", start_device_code, mode, move); if (this.getNow_steps_type2() == 2 || this.getNow_steps_type3() == 2) { - feedMessage = "请检查输送线:mode == 2 && move == 1,此时读取到mode = " + mode + "move = " + move; + feedMessage = "后工位未取货原因-->"; + if (mode != 2) { + feedMessage += "后工位取货位工作模式不为待机(mode != 2),"; + } else if (move != 1) { + feedMessage += "后工位取货位无货(move != 1)"; + } } } } } else { if (this.getNow_steps_type2() == 2 || this.getNow_steps_type3() == 2) { - feedMessage = "请检查:mode == 3 && action2 == 1 && move2 == 0 && task2 > 0,此时读取到mode = " + mode - + "action2 = " + action2 + "move2 = " + move2 + "task2 = " + task2; + feedMessage = "后工位未取货原因-->"; + if (mode != 3) { + feedMessage += "行架工作模式不为运行中(mode != 3),"; + } + if (action2 != 1) { + feedMessage += "后工位动作信号不为取货中(action2 != 1),"; + } + if (move2 != 0) { + feedMessage += "后工位光电信号不为空(move2 != 0),"; + } + if (task2 == 0) { + feedMessage += "后工位没有任务(task2 == 0)"; + } } } @@ -330,8 +349,19 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl } } else { if (this.getNow_steps_type2() == 3 || this.getNow_steps_type3() == 3) { - feedMessage = "请检查:mode == 3 && action2 == 2 && move2 == 1 && task2 > 0,此时读取到mode = " + mode - + "action2 = " + action2 + "move2 = " + move2 + "task2 = " + task2; + feedMessage = "后工位取货完成后未反馈原因-->"; + if (mode != 3) { + feedMessage += "行架工作模式不为运行中(mode != 3),"; + } + if (action2 != 2) { + feedMessage += "后工位未取货完成(action2 != 2),"; + } + if (move2 == 0) { + feedMessage += "后工位光电信号为空(move2 == 0),"; + } + if (task2 == 0) { + feedMessage += "后工位没有任务(task2 == 0)"; + } } } @@ -345,8 +375,19 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl } } else { if (this.getNow_steps_type1() == 2 || this.getNow_steps_type3() == 4) { - feedMessage = "请检查mode == 3 && action1 == 1 && move1 == 0 && task1 > 0,此时读取到mode = " + mode - + "action1 = " + action1 + "move1 = " + move1 + "task1 = " + task1; + feedMessage = "前工位未取货原因"; + if (mode != 3) { + feedMessage += "行架工作模式不为运行中(mode != 3),"; + } + if (action1 != 1) { + feedMessage += "前工位动作信号不为取货中(action2 != 1),"; + } + if (move1 != 0) { + feedMessage += "前工位光电信号不为空(move2 != 0),"; + } + if (task1 == 0) { + feedMessage += "前工位没有任务(task2 == 0)"; + } } } @@ -361,8 +402,19 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl } } else { if (this.getNow_steps_type1() == 3 || this.getNow_steps_type3() == 5) { - feedMessage = "请检查:mode == 3 && action1 == 2 && move1 == 1 && task1 > 0,此时读取到mode = " + mode - + "action1 = " + action1 + "move1 = " + move1 + "task1 = " + task1; + feedMessage = "前工位取货完成后未反馈原因"; + if (mode != 3) { + feedMessage += "行架工作模式不为运行中(mode != 3),"; + } + if (action1 != 2) { + feedMessage += "前工位未取货完成(action2 != 2),"; + } + if (move1 == 0) { + feedMessage += "前工位光电信号为空(move2 == 0),"; + } + if (task1 == 0) { + feedMessage += "前工位没有任务(task2 == 0)"; + } } } @@ -377,8 +429,19 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl } } else { if (this.getNow_steps_type2() == 4 || this.getNow_steps_type3() == 6) { - feedMessage = "请检查:mode == 3 && action2 == 3 && move2 == 1 && task2 > 0,此时读取到mode = " + mode - + "action2 = " + action2 + "move2 = " + move2 + "task2 = " + task2; + feedMessage = "后工位未放货原因-->"; + if (mode != 3) { + feedMessage += "行架工作模式不为运行中(mode != 3),"; + } + if (action2 != 3) { + feedMessage += "后工位动作信号不为放货中(action2 != 3),"; + } + if (move2 == 0) { + feedMessage += "后工位光电信号为空(move2 == 0),"; + } + if (task2 == 0) { + feedMessage += "后工位没有任务(task2 == 0)"; + } } } @@ -408,8 +471,22 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl } } else { if (this.getNow_steps_type2() == 5) { - feedMessage = "请检查:mode == 3 && action2 == 4 && move2 == 0 && task2 > 0 && type == 2,此时读取到 " + - "mode =" + mode + "action2 = " + action2 + "move2 = " + move2 + "task2 = " + task2 + "type = " + type; + feedMessage = "单任务后工位放货完成后未反馈原因-->"; + if (mode != 3) { + feedMessage += "行架工作模式不为运行中(mode != 3),"; + } + if (action2 != 4) { + feedMessage += "后工位未放货完成(action2 != 4),"; + } + if (move2 != 0) { + feedMessage += "后工位光电信号为有货(move2 != 0),"; + } + if (task2 == 0) { + feedMessage += "后工位没有任务(task2 == 0),"; + } + if (type != 2) { + feedMessage += "不是后工位单任务(type != 2)"; + } } } @@ -419,8 +496,25 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl this.setNow_steps_type3(8); } else { if (this.getNow_steps_type3() == 7) { - feedMessage = "请检查:mode == 3 && action2 == 4 && move2 == 0 && task1 > 0 && task2 > 0 && type == 3,此时读取到mode = " + mode - + "action2 = " + action2 + "move2 = " + move2 + "task1 = " + task1 + "task2 = " + task2 + "type = " + type; + feedMessage = "双任务后工位放货完成后未反馈原因-->"; + if (mode != 3) { + feedMessage += "行架工作模式不为运行中(mode != 3),"; + } + if (action2 != 4) { + feedMessage += "后工位未放货完成(action2 != 4),"; + } + if (move2 != 0) { + feedMessage += "后工位光电信号为有货(move2 != 0),"; + } + if (task1 == 0) { + feedMessage += "前工位没有任务(task1 == 0),"; + } + if (task2 == 0) { + feedMessage += "后工位没有任务(task2 == 0),"; + } + if (type != 3) { + feedMessage += "不是双任务(type != 3)"; + } } } @@ -453,14 +547,30 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl } else { log.warn("后工位放货位有货,放货位:{},mode:{},move:{}", next_device_code, mode, move); if (this.getNow_steps_type1() == 4 || this.getNow_steps_type3() == 8) { - feedMessage = "请检查输送线:move == 1 && mode == 2,此时读取到mode = " + mode + "move = " + move; + feedMessage = "前工位未放货原因-->"; + if (mode != 2) { + feedMessage += "前工位放货位工作模式不为待机(mode != 2),"; + } else if (move == 0) { + feedMessage += "前工位放货位无货(move == 0)"; + } } } } } else { if (this.getNow_steps_type1() == 4 || this.getNow_steps_type3() == 8) { - feedMessage = "请检查:mode == 3 && action1 == 3 && move1 == 1 && task1 > 0,此时读取到mode = " + mode + "action1 = " - + action1 + "move1 = " + move1 + "task1 = " + task1; + feedMessage = "前工位未放货原因-->"; + if (mode != 3) { + feedMessage += "行架工作模式不为运行中(mode != 3),"; + } + if (action1 != 3) { + feedMessage += "前工位动作信号不为放货中(action1 != 3),"; + } + if (move1 == 0) { + feedMessage += "前工位光电信号为空(move1 == 0),"; + } + if (task1 == 0) { + feedMessage += "前工位没有任务(task1 == 0),"; + } } } @@ -491,8 +601,22 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl } } else { if (this.getNow_steps_type1() == 5) { - feedMessage = "请检查:mode == 3 && action1 == 4 && move1 == 0 && task1 > 0 && type == 1,此时读取到 mode = " + - mode + "action1 = " + action1 + "move1 = " + move1 + "task1 = " + task1 + "type = " + type; + feedMessage = "单任务前工位放货完成后未反馈原因-->"; + if (mode != 3) { + feedMessage += "行架工作模式不为运行中(mode != 3),"; + } + if (action1 != 4) { + feedMessage += "前工位未放货完成(action1 != 4),"; + } + if (move1 != 0) { + feedMessage += "前工位光电信号为有货(move1 != 0),"; + } + if (task1 == 0) { + feedMessage += "前工位没有任务(task1 == 0),"; + } + if (type != 1) { + feedMessage += "不为前工位单任务(type != 1)"; + } } } @@ -523,8 +647,25 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl } } else { if (this.getNow_steps_type3() == 9) { - feedMessage = "请检查:mode == 3 && action1 == 4 && move1 == 0 && task1 > 0 && task2 > 0 && type == 3,此时读取到mode = " + mode - + "action1 = " + action1 + "move1 = " + move1 + "task1 = " + task1 + "task2 = " + task2 + "type = " + type; + feedMessage = "双任务前工位放货完成后未反馈原因-->"; + if (mode != 3) { + feedMessage += "行架工作模式不为运行中(mode != 3),"; + } + if (action1 != 4) { + feedMessage += "前工位未放货完成(action1 != 4),"; + } + if (move1 != 0) { + feedMessage += "前工位光电信号为有货(move1 != 0),"; + } + if (task1 == 0) { + feedMessage += "前工位没有任务(task1 == 0),"; + } + if (task2 == 0) { + feedMessage += "后工位没有任务(task2 == 0),"; + } + if (type != 3) { + feedMessage += "不是双任务(type != 3)"; + } } } @@ -532,21 +673,20 @@ 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()) { +// if (!this.itemProtocol.getIsonline()) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "信号量同步异常"; +// //未联机 +// } else + if (mode == 0) { 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 = "有报警"; //无报警 @@ -561,7 +701,8 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl //申请任务 if (mode == 2 && move1 == 0 && move2 == 0 && action1 == 0 && action2 == 0 && task1 == 0 && task2 == 0 && !requireSucess) { //获取关联设备驱动信息 判断关联设备是否禁用 - Device device = deviceAppservice.findDeviceByCode(device_code); + String link_device_code = String.valueOf(this.getDevice().getExtraValue().get("link_device_code")); + Device device = deviceAppservice.findDeviceByCode(link_device_code); SlitTwoManipulatorDeviceDriver slitTwoManipulatorDeviceDriver; if (device.getDeviceDriver() instanceof SlitTwoManipulatorDeviceDriver) { slitTwoManipulatorDeviceDriver = (SlitTwoManipulatorDeviceDriver) device.getDeviceDriver(); @@ -592,25 +733,25 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl if (!requireSucess) { String remark = ""; if (mode != 2) { - remark = remark + "mode不为2,"; + remark = remark + "行架工作模式不为待机(mode != 2),"; } if (move1 != 0) { - remark = remark + "move1不为0,"; + remark = remark + "前工位有货(move1 != 0),"; } if (move2 != 0) { - remark = remark + "move2不为0,"; + remark = remark + "后工位有货(move2 != 0),"; } if (action1 != 0) { - remark = remark + "action1不为0,"; + remark = remark + "前工位动作信号不为0(action1 != 0),"; } if (action2 != 0) { - remark = remark + "action2不为0,"; + remark = remark + "后工位动作信号不为0(action2 != 0),"; } if (task1 != 0) { - remark = remark + "task1不为0,"; + remark = remark + "前工位存在任务(task1 != 0),"; } if (task2 != 0) { - remark = remark + "task2不为0,"; + remark = remark + "后工位存在任务(task2 != 0),"; } this.setNotCreateTaskMessage(remark); } @@ -970,19 +1111,76 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl Device nextDevice = deviceAppservice.findDeviceByCode(next_device_code); String start_addr = startDevice.getExtraValue().get("address").toString(); String next_addr = nextDevice.getExtraValue().get("address").toString(); + List list = new ArrayList(); if (StrUtil.equals(type, "1")) { - this.writing("to_onset1", start_addr); - this.writing("to_target1", next_addr); - this.writing("to_task1", dto.getInstruction_code()); - this.writing("to_command1", "1"); - this.writing("to_type", "1"); + Map map1 = new HashMap(); + map1.put("code", "to_onset1"); + map1.put("value", start_addr); + list.add(map1); + Map map2 = new HashMap(); + map2.put("code", "to_target1"); + map2.put("value", next_addr); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_task1"); + map3.put("value", dto.getInstruction_code()); + list.add(map3); + Map map4 = new HashMap(); + map4.put("code", "to_type"); + map4.put("value", "1"); + list.add(map4); + Map map5 = new HashMap(); + map5.put("code", "to_command1"); + map5.put("value", "1"); + list.add(map5); + HashMap map6 = new HashMap() {{ + put("code", "to_command2"); + put("value", "0"); + }}; + list.add(map6); + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", dto.getInstruction_code() + "下发前工位任务"); + +// this.writing("to_onset1", start_addr); +// this.writing("to_target1", next_addr); +// this.writing("to_task1", dto.getInstruction_code()); +// this.writing("to_command1", "1"); +// this.writing("to_type", "1"); this.setNow_steps_type1(2); } else if (StrUtil.equals(type, "2")) { - this.writing("to_onset2", start_addr); - this.writing("to_target2", next_addr); - this.writing("to_task2", dto.getInstruction_code()); - this.writing("to_command2", "1"); - this.writing("to_type", "2"); + Map map1 = new HashMap(); + map1.put("code", "to_onset2"); + map1.put("value", start_addr); + list.add(map1); + Map map2 = new HashMap(); + map2.put("code", "to_target2"); + map2.put("value", next_addr); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_task2"); + map3.put("value", dto.getInstruction_code()); + list.add(map3); + Map map4 = new HashMap(); + map4.put("code", "to_type"); + map4.put("value", "2"); + list.add(map4); + Map map5 = new HashMap(); + map5.put("code", "to_command2"); + map5.put("value", "1"); + list.add(map5); + HashMap map6 = new HashMap() {{ + put("code", "to_command1"); + put("value", "0"); + }}; + list.add(map6); + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", dto.getInstruction_code() + "下发后工位任务"); + +// this.writing("to_onset2", start_addr); +// this.writing("to_target2", next_addr); +// this.writing("to_task2", dto.getInstruction_code()); +// this.writing("to_command2", "1"); +// this.writing("to_type", "2"); this.setNow_steps_type2(2); } else if (StrUtil.equals(type, "3")) { String start_device_code2 = dto.getStart_device_code2(); @@ -991,17 +1189,65 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl Device nextDevice2 = deviceAppservice.findDeviceByCode(next_device_code2); String start_addr2 = startDevice2.getExtraValue().get("address").toString(); String next_addr2 = nextDevice2.getExtraValue().get("address").toString(); - this.writing("to_onset1", start_addr2); - this.writing("to_target1", next_addr2); - this.writing("to_task1", dto.getInstruction_code()); - this.writing("to_command1", "1"); - this.writing("to_onset2", start_addr); - this.writing("to_target2", next_addr); - this.writing("to_task2", dto.getInstruction_code()); - this.writing("to_command2", "1"); - this.writing("to_type", "3"); + + + Map map1 = new HashMap(); + map1.put("code", "to_onset1"); + map1.put("value", start_addr2); + list.add(map1); + Map map2 = new HashMap(); + map2.put("code", "to_target1"); + map2.put("value", next_addr2); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_task1"); + map3.put("value", dto.getInstruction_code()); + list.add(map3); + Map map4 = new HashMap(); + map4.put("code", "to_onset2"); + map4.put("value", start_addr); + list.add(map4); + Map map5 = new HashMap(); + map5.put("code", "to_target2"); + map5.put("value", next_addr); + list.add(map5); + Map map6 = new HashMap(); + map6.put("code", "to_task2"); + map6.put("value", dto.getInstruction_code()); + list.add(map6); + Map map7 = new HashMap(); + map7.put("code", "to_type"); + map7.put("value", "3"); + list.add(map7); + Map map8 = new HashMap(); + map8.put("code", "to_command1"); + map8.put("value", "1"); + list.add(map8); + Map map9 = new HashMap(); + map9.put("code", "to_command2"); + map9.put("value", "1"); + list.add(map9); + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", dto.getInstruction_code() + "下发双工位任务"); + + +// this.writing("to_onset1", start_addr2); +// this.writing("to_target1", next_addr2); +// this.writing("to_task1", dto.getInstruction_code()); +// this.writing("to_command1", "1"); +// this.writing("to_onset2", start_addr); +// this.writing("to_target2", next_addr); +// this.writing("to_task2", dto.getInstruction_code()); +// this.writing("to_command2", "1"); +// this.writing("to_type", "3"); this.setNow_steps_type3(2); } + + if (task1 != Integer.parseInt(dto.getInstruction_code()) || task2 != Integer.parseInt(dto.getInstruction_code())) { + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", dto.getInstruction_code() + "再次下发电气信号"); + } + } //判断点位是否设置电气值 @@ -1025,12 +1271,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); } @@ -1044,10 +1290,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); } @@ -1059,18 +1305,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); } @@ -1078,21 +1324,40 @@ 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); + 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 List getExtraDeviceCodes(String extraName) { String extraValue = (String) this.getDevice().getExtraValue().get(extraName); @@ -1203,6 +1468,12 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl is_disable = "禁用"; } + String requireSucess = "0"; + if (this.requireSucess) { + requireSucess = "1"; + } + jo.put("requireSucess", requireSucess); + jo.put("device_name", this.getDevice().getDevice_name()); jo.put("mode", mode); jo.put("status", status); @@ -1218,7 +1489,7 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl jo.put("isError", this.getIserror()); jo.put("is_disable1", this.getIs_disable()); jo.put("is_disable", is_disable); - jo.put("message", "此时,type = 1时," + this.getNow_steps_type1() + ",type = 2时," + this.getNow_steps_type2() + ",type = 3时," + this.getNow_steps_type3()); + jo.put("message", this.messageInfo(type)); jo.put("is_click", true); jo.put("driver_type", "slit_two_manipulator"); jo.put("notCreateTaskMessage", notCreateTaskMessage); @@ -1227,11 +1498,57 @@ public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver impl return jo; } + public String messageInfo(int type) { + String set_type = ""; + JSONObject map = new JSONObject(); + if (type == 1) { + set_type = String.valueOf(now_steps_type1); + map.put("0", "前工位单任务未执行"); + map.put("1", "前工位单任务改变指令状态"); + map.put("2", "前工位单任务下发电气任务信息"); + map.put("3", "单任务前工位允许取货"); + map.put("4", "单任务前工位取货完成"); + map.put("5", "单任务前工位允许放货"); + map.put("6", "单任务前工位放货完成"); + } else if (type == 2) { + set_type = String.valueOf(now_steps_type2); + map.put("0", "后工位单任务未执行"); + map.put("1", "后工位单任务改变指令状态"); + map.put("2", "后工位单任务下发电气任务信息"); + map.put("3", "单任务后工位允许取货"); + map.put("4", "单任务后工位取货完成"); + map.put("5", "单任务后工位允许放货"); + map.put("6", "单任务后工位放货完成"); + } else if (type == 3) { + set_type = String.valueOf(now_steps_type3); + map.put("0", "双任务未执行"); + map.put("1", "双任务改变指令状态"); + map.put("2", "双任务下发电气任务信息"); + map.put("3", "双任务后工位允许取货"); + map.put("4", "双任务后工位取货完成"); + map.put("5", "双任务前工位允许取货"); + map.put("6", "双任务前工位取货完成"); + map.put("7", "双任务后工位允许放货"); + map.put("8", "双任务后工位放货完成"); + map.put("9", "双任务前工位允许放货"); + map.put("10", "双任务前工位放货完成"); + } else { + return "未执行任务"; + } + return map.getString(set_type); + } + @Override public void setDeviceStatus(JSONObject data) { String is_disable = data.getString("is_disable"); if (StrUtil.isNotEmpty(is_disable)) { this.setIs_disable(Integer.parseInt(is_disable)); } + 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/StandardCoveyorControlDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardCoveyorControlDeviceDriver.java index 351e8e3..4993462 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 370748e..e459f50 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/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/ItemProtocol.java index 60d2575..99ec030 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/ItemProtocol.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/ItemProtocol.java @@ -1,5 +1,6 @@ package org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner; +import cn.hutool.core.util.StrUtil; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; @@ -24,6 +25,11 @@ public class ItemProtocol { public static String item_error = "error"; //任务号 public static String item_task = "task"; + //条码长度 + public static String item_barcode_length = "barcode_length"; + //条码 + public static String item_barcode = "barcode"; + //下发命令 public static String item_to_command = "to_command"; @@ -73,6 +79,14 @@ public class ItemProtocol { return this.getOpcIntegerValue(item_task); } + public int getBarCode_length() { + return this.getOpcIntegerValue(item_barcode_length); + } + + public String getplcBarCode() { + return this.getOpcStringValue(item_barcode); + } + Boolean isonline; @@ -89,30 +103,48 @@ public class ItemProtocol { } + public String getOpcStringValue(String protocol) { + String value = this.driver.getStringValue(protocol); + if (StrUtil.isEmpty(value)) { + + } else { + return value; + } + return "0"; + } public static List getReadableItemDtos() { ArrayList list = new ArrayList(); - list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); - list.add(new ItemDto(item_mode, "工作模式", "DB600.B2")); - list.add(new ItemDto(item_move, "光电信号", "DB600.B3")); - list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB600.B4")); - list.add(new ItemDto(item_error, "报警信号", "DB600.B6")); - list.add(new ItemDto(item_task, "任务号", "DB600.D10")); + list.add(new ItemDto(item_heartbeat, "心跳", "DB101.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB101.B252")); + list.add(new ItemDto(item_move, "光电信号", "DB101.B253")); + list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB101.B254")); + list.add(new ItemDto(item_error, "报警信号", "DB101.B256")); + list.add(new ItemDto(item_task, "任务号", "DB101.D260")); + list.add(new ItemDto(item_barcode_length, "条码长度", "DB101.B800")); + list.add(new ItemDto(item_barcode, "条码", "DB101.STRING802.50")); + return list; } public static List getWriteableItemDtos() { ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2")); - list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W4")); - list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8")); - list.add(new ItemDto(item_to_strap_times, "捆扎次数", "DB601.W12")); - list.add(new ItemDto(item_to_length, "木箱长度", "DB601.W14")); - list.add(new ItemDto(item_to_weight, "木箱宽度", "DB601.W16")); - list.add(new ItemDto(item_to_height, "木箱高度", "DB601.W18")); + list.add(new ItemDto(item_to_command, "下发命令", "DB102.W252")); + list.add(new ItemDto(item_to_target, "下发目标站", "DB102.W254")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB102.D258")); +// list.add(new ItemDto(item_to_strap_times, "捆扎次数", "DB102.W12")); +// list.add(new ItemDto(item_to_length, "木箱长度", "DB102.W14")); +// list.add(new ItemDto(item_to_weight, "木箱宽度", "DB102.W16")); +// list.add(new ItemDto(item_to_height, "木箱高度", "DB102.W18")); return list; } + @Override + public String toString() { + return ""; + } + + } 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 1b9f32b..1ddc0e5 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 @@ -21,6 +21,7 @@ import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.monitor.DeviceStageMonitor; import org.nl.acs.opc.Device; import org.nl.acs.opc.DeviceAppService; @@ -64,6 +65,8 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe @Autowired AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); String container; protected String barcode = null; @@ -81,6 +84,10 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe int action = 0; int error = 0; int task = 0; + String plcbarcode = null; + String last_plcbarcode = null; + int plcbarcode_length = 0; + int last_plcbarcode_length = 0; Boolean isonline = true; @@ -125,38 +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 @@ -166,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(); @@ -175,28 +191,51 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe move = this.itemProtocol.getMove(); error = this.itemProtocol.getError(); task = this.itemProtocol.getTask(); + plcbarcode = this.itemProtocol.getplcBarCode(); + plcbarcode_length = this.itemProtocol.getBarCode_length(); if (mode != last_mode) { - this.setRequireSucess(false); - } - if (move != last_move) { - if (move == 0 && mode == 2) { - thingToNothing(); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode +"复位请求标记"); + if(mode == 2){ + this.setRequireSucess(false); + this.setApplySucess(false); + message = null; } } + if (move != last_move) { + if (move == 0) { + message = null; + inst_message = null; + clearBarcode(); + thingToNothing(); + } + logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); + } if (error != last_error) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + if (plcbarcode_length != last_plcbarcode_length) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号plcbarcode_length:" + last_plcbarcode_length + "->" + plcbarcode_length); + } + if (!StrUtil.equals(plcbarcode,last_plcbarcode) ) { + logServer.deviceExecuteLog(this.device_code, "", "", "信号plcbarcode:" + last_plcbarcode + "->" + plcbarcode); } + if (task != last_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())) { + inst.setExecute_device_code(this.device_code); finish_instruction(); } 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); } } @@ -214,12 +253,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe 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); @@ -232,11 +266,24 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe break; case 2: //申请任务 - if (move > 0 && !StrUtil.isEmpty(barcode()) && !requireSucess) { - instruction_require(barcode()); + String newBarcode = null; + + if(!StrUtil.isEmpty(barcode())){ + newBarcode = barcode(); + } else { + // + if(plcbarcode_length>2){ + newBarcode = plcbarcode; + } else { + break; + } } - if (move > 0 && !StrUtil.isEmpty(barcode()) && !applySucess) { - instruction_apply(barcode()); + + if (move > 0 && !StrUtil.isEmpty(newBarcode) && !requireSucess) { + instruction_require(newBarcode.trim()); + } + if (move > 0 && !StrUtil.isEmpty(newBarcode) && !applySucess) { + instruction_apply(newBarcode.trim()); } } switch (flag) { @@ -255,6 +302,8 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe last_error = error; last_move = move; last_task = task; + last_plcbarcode_length = plcbarcode_length; + last_plcbarcode = plcbarcode; } public boolean exe_error() { @@ -270,8 +319,40 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe this.setBarcode(null); this.setRequireSucess(false); this.setApplySucess(false); + applySucess = false; clearBarcode(); this.set_last_container(container); + 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; } public void set_last_container(String barcode) { @@ -287,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) { @@ -298,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) { @@ -325,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); @@ -338,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); @@ -355,94 +436,45 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe //container_code TaskDto task = taskserver.findByContainer(container_code); if (!ObjectUtil.isEmpty(task)) { - String taskid = task.getTask_id(); - String taskcode = task.getTask_code(); - String vehiclecode = task.getVehicle_code(); - String priority = task.getPriority(); - String start_point_code = task.getStart_point_code(); - String start_device_code = task.getStart_device_code(); - String route_plan_code = task.getRoute_plan_code(); - String next_device_code = ""; + Instruction instdto = instructionService.findByTaskcodeAndStatus(task.getTask_code()); + if(!StrUtil.equals(instdto.getStart_device_code(),this.device_code)){ + message ="当前载具号"+container_code+"查找对应指令起点与当前设备不符"; +// this.setIserror(true); + return false; + } + if(ObjectUtil.isNotEmpty(instdto)){ + List list = new ArrayList(); + Map map = new HashMap(); - /** - * 开始平均分配 - */ - String this_coevice_code = taskserver.queryAssignedByDevice(device_code, task.getNext_device_code()); - if (StrUtil.isEmpty(this_coevice_code)) { - List shortPathsList = routeLineService.getShortPathLines(start_device_code, task.getNext_device_code(), route_plan_code); - RouteLineDto routeLineDto = shortPathsList.get(0); - - String path = routeLineDto.getPath(); - String type = routeLineDto.getType(); - String[] str = path.split("->"); -// if (!StrUtil.equals(type, "0")) { -// return false; -// } - 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; + if(StrUtil.isNotEmpty(task.getTo_z())){ + if(StrUtil.equals(task.getTo_z(),"01")){ + map.put("code","to_target"); + map.put("value","102"); + } else if(StrUtil.equals(task.getTo_z(),"02")){ + map.put("code","to_target"); + map.put("value","201"); + } else if(StrUtil.equals(task.getTo_z(),"03")){ + map.put("code","to_target"); + map.put("value","301"); } } - next_device_code = pathlist.get(index); + 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); + message = "下发电气任务号成功"; + requireSucess = true; + applySucess = true; } 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("路由不通!"); + message = "任务号:"+ task.getTask_code()+"未找到指令"; } - 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 = task.getTo_x() + "-" + task.getTo_y() + "-" + task.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(task.getRemark()); - instdto.setMaterial(task.getMaterial()); - instdto.setQuantity(task.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); - //创建指令后修改任务状态 - WQLObject taskwo = WQLObject.getWQLObject("acs_task"); - task.setTask_status("1"); - //创建指令后修改任务状态 - task.setTask_status("1"); - taskserver.update(task); - this.writing("to_command","1"); - if(StrUtil.isNotEmpty(task.getTo_z())){ - if(StrUtil.equals(task.getTo_z(),"01")){ - this.writing("to_target","102"); - } else if(StrUtil.equals(task.getTo_z(),"02")){ - this.writing("to_target","201"); - } else if(StrUtil.equals(task.getTo_z(),"03")){ - this.writing("to_target","301"); - } - } - this.writing("to_command","1"); - this.writing("to_task",instdto.getInstruction_code()); - applySucess = true; } else { log.info("未找到载具号{}对应任务", container_code); } @@ -452,11 +484,11 @@ 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); @@ -464,26 +496,91 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } else { this.instruction_require_time = date; //container_code - TaskDto task = taskserver.findByContainer(container_code); - if (!ObjectUtil.isEmpty(task)) { - if (!ObjectUtils.isEmpty(instructionService.findByBarcodeFromCache(container_code))) { - return false; + TaskDto taskdto = taskserver.findByContainer(container_code); + if (!ObjectUtil.isEmpty(taskdto)) { + if (!ObjectUtils.isEmpty(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(); +// map.put("code","to_target"); +// map.put("value","1011"); +// list.add(map); +// Map map2 = new HashMap(); +// map2.put("code","to_command"); +// map2.put("value","1"); +// Map map3 = new HashMap(); +// map3.put("code","to_task"); +// map3.put("value","0"); +// list.add(map3); +// this.writing(list); +// this.setRequireSucess(true); +// this.setApplySucess(true); + return false; + } + this.setIserror(false); + if (ObjectUtil.isNotEmpty(instdto)) { + 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", 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); + message = "下发电气任务号成功"; + 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 { + message = "任务号:" + taskdto.getTask_code() + "未找到指令"; + } + return true; } - String taskid = task.getTask_id(); - String taskcode = task.getTask_code(); - String vehiclecode = task.getVehicle_code(); - String priority = task.getPriority(); - String start_point_code = task.getStart_point_code(); - String start_device_code = task.getStart_device_code(); - String route_plan_code = task.getRoute_plan_code(); + + 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, task.getNext_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, task.getNext_device_code(), route_plan_code); + List shortPathsList = routeLineService.getShortPathLines(start_device_code, taskdto.getNext_device_code(), route_plan_code); RouteLineDto routeLineDto = shortPathsList.get(0); String path = routeLineDto.getPath(); @@ -514,16 +611,36 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); String next_point_code; if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { - next_point_code = task.getTo_x() + "-" + task.getTo_y() + "-" + task.getTo_z(); + next_point_code = taskdto.getTo_x() + "-" + taskdto.getTo_y() + "-" + taskdto.getTo_z(); } else { next_point_code = next_device_code; } + + if(!StrUtil.equals(taskdto.getStart_device_code(),this.device_code)){ + message ="当前载具号"+container_code+"查找对应指令起点与当前设备不符"; +// List list = new ArrayList(); +// Map map = new HashMap(); +// map.put("code","to_target"); +// map.put("value","1011"); +// list.add(map); +// Map map2 = new HashMap(); +// map2.put("code","to_command"); +// map2.put("value","1"); +// Map map3 = new HashMap(); +// map3.put("code","to_task"); +// map3.put("value","0"); +// list.add(map3); +// this.writing(list); +// this.setRequireSucess(true); +// this.setApplySucess(true); + return false; + } Instruction instdto = new Instruction(); instdto.setInstruction_id(IdUtil.simpleUUID()); instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(task.getRemark()); - instdto.setMaterial(task.getMaterial()); - instdto.setQuantity(task.getQuantity()); + instdto.setRemark(taskdto.getRemark()); + instdto.setMaterial(taskdto.getMaterial()); + instdto.setQuantity(taskdto.getQuantity()); instdto.setTask_id(taskid); instdto.setTask_code(taskcode); instdto.setVehicle_code(vehiclecode); @@ -537,22 +654,47 @@ 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; + } //创建指令后修改任务状态 - task.setTask_status("1"); - taskserver.update(task); - this.writing("to_command","1"); - if(StrUtil.isNotEmpty(task.getTo_z())){ - if(StrUtil.equals(task.getTo_z(),"01")){ - this.writing("to_target","102"); - } else if(StrUtil.equals(task.getTo_z(),"02")){ - this.writing("to_target","201"); - } else if(StrUtil.equals(task.getTo_z(),"03")){ - this.writing("to_target","301"); + taskdto.setTask_status("1"); + taskserver.update(taskdto); + + + 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"); } } - this.writing("to_command","1"); - this.writing("to_task",instdto.getInstruction_code()); + 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(instdto.getInstruction_code()) ){ +// this.writing(list); +// logServer.deviceExecuteLog(device_code, "", "", instdto.getInstruction_code() + "再次下发电气信号"); +// } requireSucess = true; applySucess = true; } else { @@ -561,19 +703,56 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe JSONObject apply = new JSONObject(); apply.put("vehicle_code", container_code); 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 = "接口不通"; + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code","to_target"); + map.put("value","1011"); + list.add(map); + Map map2 = new HashMap(); + map2.put("code","to_command"); + map2.put("value","1"); + Map map3 = new HashMap(); + map3.put("code","to_task"); + map3.put("value","0"); + list.add(map3); + this.writing(list); + message = "申请任务失败接口不通下发退回"; } else { if (jo.getInteger("status") == 200) { + message = "申请任务成功"; requireSucess = true; + applySucess = false; } else { - requireSucess = false; - message = jo.get("message").toString(); + if (jo.get("message")!=null){ + message = jo.get("message").toString(); + } + + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code","to_target"); + map.put("value","1011"); + list.add(map); + Map map2 = new HashMap(); + map2.put("code","to_command"); + map2.put("value","1"); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code","to_task"); + map3.put("value","0"); + list.add(map3); + this.writing(list); + message = "申请任务失败下发退回,"+message; + requireSucess = true; + } } - +// requireSucess = true; +// message = "申请任务成功"; } } return true; @@ -585,16 +764,34 @@ 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); + 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); + } + @Override public JSONObject getDeviceStatusName() { JSONObject jo = new JSONObject(); @@ -610,7 +807,6 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } else if (this.getMode() == 3) { mode = "运行中"; } - if (this.getAction() == 0) { action = "禁止取放"; } else if (this.getAction() == 1) { @@ -620,8 +816,6 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } else if (this.getAction() == 3) { action = "允许取放"; } - - if (this.getMove() == 0) { move = "无货"; jo.put("hasGoods", false); @@ -633,20 +827,48 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe jo.put("hasGoods", true); } jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("driver_type", "standard_conveyor_control_with_scanner"); jo.put("mode", mode); jo.put("move", move); jo.put("action", action); + jo.put("is_click", true); jo.put("isOnline", this.getIsonline()); jo.put("error", this.getError()); jo.put("isError", this.getIserror()); jo.put("message", this.getMessage()); + jo.put("inst_message", this.inst_message); jo.put("task", this.getTask()); - jo.put("barcode", this.getBarcode()); + jo.put("barcode", plcbarcode); + jo.put("barcode_length", plcbarcode_length); + String requireSucess = "0"; + if (this.requireSucess) { + requireSucess = "1"; + } + jo.put("requireSucess", requireSucess); + String applySucess = "0"; + if (this.applySucess) { + applySucess = "1"; + } + jo.put("applySucess", applySucess); + return jo; } @Override public void setDeviceStatus(JSONObject data) { - + String requestSucess = data.getString("requireSucess"); + System.out.println(requestSucess); + if (StrUtil.equals(requestSucess, "0")) { + this.requireSucess = false; + } else if (StrUtil.equals(requestSucess, "1")) { + this.requireSucess = true; + } + String applySucess = data.getString("applySucess"); + if (StrUtil.equals(applySucess, "0")) { + this.applySucess = false; + } else if (StrUtil.equals(applySucess, "1")) { + this.applySucess = true; + } } + } 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 032f77a..fcdd34c 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 d36492a..a3e5708 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 ebf13e5..30eac18 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 0848800..326d189 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,20 @@ 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 { +// } + this.execute(); - } + } - 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 0000000..824c769 --- /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 8b3cf17..edf93e8 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; @@ -24,7 +25,7 @@ public interface OpcDeviceDriver extends DeviceDriver { //设备扩展表【acs_device_extra】 WQLObject extraTab = WQLObject.getWQLObject("acs_device_extra"); - JSONArray arr = extraTab.query("filed_type='02' and device_id = '" + this.getDevice().getDevice_id() + "'").getResultJSONArray(0); + JSONArray arr = extraTab.query(" (filed_type='02' or filed_type='03' )and device_id = '" + this.getDevice().getDevice_id() + "'").getResultJSONArray(0); for (int i = 0; i < arr.size(); i++) { JSONObject json = arr.getJSONObject(i); OpcItemDto dto = new OpcItemDto(); @@ -61,6 +62,16 @@ public interface OpcDeviceDriver extends DeviceDriver { return (Integer) this.getValue(protocol); } + default Float getDoubleValue(String 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) { return (int[]) this.getOpcValueAccessor().getValue(this.getItem(protocol)); } @@ -77,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/AcsUtil.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/AcsUtil.java index 4ce629b..39f2037 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/AcsUtil.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/AcsUtil.java @@ -37,7 +37,7 @@ public class AcsUtil { logServer.extLog(LokiLogType.ACS_TO_LK.name(),"下发立库任务请求参数:{}"+JSON.toJSONString(requestParam) ); log.info("下发立库任务请求参数:{}", JSON.toJSONString(requestParam)); String body = HttpRequest - .post(liKu_wcs_url + api) + .post(liKu_wcs_url + api).setConnectionTimeout(3000) .body(JSON.toJSONString(requestParam)) .execute() .body(); @@ -46,7 +46,7 @@ public class AcsUtil { } catch (Exception e) { JSONObject result = new JSONObject(); result.put("result", "false"); - result.put("code", ""); + result.put("code", "1"); result.put("comment", e.getMessage()); log.info("下发立库任务异常返回参数:{}", String.valueOf(result)); return String.valueOf(result); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/ApplyLabelingAndBindingRequest.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/ApplyLabelingAndBindingRequest.java index f68fe71..65c5bb5 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/ApplyLabelingAndBindingRequest.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/ApplyLabelingAndBindingRequest.java @@ -12,4 +12,7 @@ public class ApplyLabelingAndBindingRequest extends BaseRequest { * 3:烘箱 */ private String type; + + private String weight; + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/ApplyLabelingAndBindingResponse.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/ApplyLabelingAndBindingResponse.java index e60e5cd..cf20c9c 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/ApplyLabelingAndBindingResponse.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/ApplyLabelingAndBindingResponse.java @@ -1,9 +1,14 @@ package org.nl.acs.ext.wms.data; +import com.alibaba.fastjson.JSONObject; import lombok.Data; +import java.util.HashMap; +import java.util.Map; + @Data public class ApplyLabelingAndBindingResponse extends BaseResponse { + private Map data = new HashMap(); } 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 ad29613..ed5e957 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/liKuData/DeviceStatusData.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/DeviceStatusData.java new file mode 100644 index 0000000..a2b5c34 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/DeviceStatusData.java @@ -0,0 +1,32 @@ +package org.nl.acs.ext.wms.liKuData; + +import lombok.Data; + +@Data +public class DeviceStatusData { + + String deviceId; + + String x; + + String y; + + //楼层 + String mapId; + + //电量 + String power; + + //托盘 + String pallet; + + //有无货 + String load; + + //报警 + String alarm; + + //任务号 + String taskId; + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/DeviceStatusRequest.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/DeviceStatusRequest.java new file mode 100644 index 0000000..006bbaa --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/DeviceStatusRequest.java @@ -0,0 +1,11 @@ +package org.nl.acs.ext.wms.liKuData; + +import lombok.Data; + +@Data +public class DeviceStatusRequest { + + String deviceId; + + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/DeviceStatusResponse.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/DeviceStatusResponse.java new file mode 100644 index 0000000..b50b15b --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/DeviceStatusResponse.java @@ -0,0 +1,14 @@ +package org.nl.acs.ext.wms.liKuData; + +public class DeviceStatusResponse { + + String result; + + String code; + + String comment; + + DeviceStatusData data; + + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/putEmptyPalletRequest.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/putEmptyPalletRequest.java new file mode 100644 index 0000000..2d921b8 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/liKuData/putEmptyPalletRequest.java @@ -0,0 +1,14 @@ +package org.nl.acs.ext.wms.liKuData; + +import lombok.Data; + +@Data +public class putEmptyPalletRequest { + + String deviceId; + + String orderId; + + String type; + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToLiKuController.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToLiKuController.java index 56b3894..494393c 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToLiKuController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToLiKuController.java @@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j; import org.nl.acs.ext.wms.liKuData.*; import org.nl.acs.ext.wms.service.AcsToLiKuService; import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.modules.logging.InterfaceLogType; import org.nl.modules.logging.annotation.Log; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -34,58 +35,80 @@ public class AcsToLiKuController { private final AcsToLiKuService acsToLiKuService; @PostMapping("/inStore") - @Log("向立库wcs下发入库任务") - @ApiOperation("向立库wcs下发入库任务") + @Log(value = "下发立库入库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库物料入库任务") public ResponseEntity inStore(@RequestBody InStoreRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.inStore(requestParam), HttpStatus.OK); } @PostMapping("/outStore") - @Log("向立库wcs下发出库任务") - @ApiOperation("向立库wcs下发出库任务") + @Log(value = "下发立库出库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库出库任务") public ResponseEntity outStore(@RequestBody OutStoreRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.outStore(requestParam), HttpStatus.OK); } @PostMapping("/emptyVehicleOutStore") - @Log("向立库wcs下发空托盘出库任务") - @ApiOperation("向立库wcs下发空托盘出库任务") + @Log(value = "下发立库空盘出库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库空盘出库任务") public ResponseEntity emptyVehicleOutStore(@RequestBody EmptyVehicleOutStoreRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.emptyVehicleOutStore(requestParam), HttpStatus.OK); } @PostMapping("/moveStore") - @Log("向立库wcs下发移库任务") - @ApiOperation("向立库wcs下发移库任务") + @Log(value = "下发立库移库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库移库任务") public ResponseEntity moveStore(@RequestBody MoveStoreRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.moveStore(requestParam), HttpStatus.OK); } @PostMapping("/inStoreReset") - @Log("向立库wcs下发入库任务调整") - @ApiOperation("向立库wcs下发入库任务调整") + @Log(value = "下发立库入库任务调整",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库入库任务调整") public ResponseEntity inStoreReset(@RequestBody InStoreResetRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.inStoreReset(requestParam), HttpStatus.OK); } @PostMapping("/moveStoreReset") - @Log("向立库wcs下发移库任务调整") - @ApiOperation("向立库wcs下发移库任务调整") + @Log(value = "下发立库移库任务调整",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库移库任务调整") public ResponseEntity moveStoreReset(@RequestBody MoveStoreResetRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.moveStoreReset(requestParam), HttpStatus.OK); } @PostMapping("/roadWayIsLock") - @Log("向立库下发巷道锁定或解锁") + @Log(value = "下发立库巷道锁定或解锁",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) @ApiOperation("向立库下发巷道锁定或解锁") public ResponseEntity roadWayIsLock(@RequestBody RoadWayIsLockRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.roadWayIsLock(requestParam), HttpStatus.OK); } @PostMapping("/cancelTask") - @Log("向立库下发任务取消") - @ApiOperation("向立库下发任务取消") + @Log(value = "取消立库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("取消立库任务") public ResponseEntity cancelTask(@RequestBody CancelTaskRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.cancelTask(requestParam), HttpStatus.OK); } + + @PostMapping("/queryCarStatus") + @Log(value = "查询四向车状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("查询四向车状态") + public ResponseEntity queryCarStatus(@RequestBody DeviceStatusRequest requestParam) { + return new ResponseEntity<>(acsToLiKuService.queryCarDeviceStatus(requestParam), HttpStatus.OK); + } + + @PostMapping("/queryTsjStatus") + @Log(value = "查询提升机状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("查询提升机状态") + public ResponseEntity queryTsjStatus(@RequestBody DeviceStatusRequest requestParam) { + return new ResponseEntity<>(acsToLiKuService.queryTsjDeviceStatus(requestParam), HttpStatus.OK); + } + + @PostMapping("/querySsxStatus") + @Log(value = "查询提升机状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("查询提升机状态") + public ResponseEntity querySsxStatus(@RequestBody DeviceStatusRequest requestParam) { + return new ResponseEntity<>(acsToLiKuService.queryTsjDeviceStatus(requestParam), HttpStatus.OK); + } + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java index 9d5d6c5..35965e4 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java @@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j; import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; import org.nl.acs.ext.wms.data.LiKuApplyTaskRequest; import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.modules.logging.InterfaceLogType; import org.nl.modules.logging.annotation.Log; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -34,43 +35,43 @@ public class AcsToWmsController { private final AcsToWmsService acstowmsService; @PostMapping("/applyTask") - @Log("向WMS申请任务") - @ApiOperation("向WMS申请任务") + @Log(value = "ACS向WMS申请任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) + @ApiOperation("ACS向WMS申请任务") public ResponseEntity applyTaskToWms(@RequestBody JSONObject jo) { return new ResponseEntity<>(acstowmsService.applyTaskToWms(jo), HttpStatus.OK); } @PostMapping("/taskStatusFeedback") - @Log("向WMS反馈任务状态") - @ApiOperation("向WMS反馈任务状态") + @Log(value = "ACS向WMS反馈任务状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) + @ApiOperation("ACS向WMS反馈任务状态") public ResponseEntity feedbackTaskStatusToWms(@RequestBody Map whereJson) { JSONArray data = JSONArray.parseArray(String.valueOf(whereJson)); return new ResponseEntity<>(acstowmsService.feedbackTaskStatusToWms(data), HttpStatus.OK); } @PostMapping("/feedbackAgvStatus") - @Log("反馈AGV设备状态") + @Log(value = "反馈AGV设备状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("反馈AGV设备状态") public ResponseEntity feedbackAgvStatus(@RequestBody String device_code, String error, String error_message) { return new ResponseEntity<>(acstowmsService.feedbackAgvStatus(device_code, error, error_message), HttpStatus.OK); } @PostMapping("/feedbackAgv") - @Log("反馈AGV设备信息") + @Log(value = "反馈AGV设备信息",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("反馈AGV设备信息") public ResponseEntity feedbackAgv(@RequestBody JSONArray from) { return new ResponseEntity<>(acstowmsService.feedbackAgv(from), HttpStatus.OK); } @PostMapping("/feedbackDeviceStatus") - @Log("反馈设备状态") + @Log(value = "反馈设备状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("反馈设备状态") public ResponseEntity feedbackDeviceStatus(@RequestBody String device_code, String code, String value) { return new ResponseEntity<>(acstowmsService.feedbackDeviceStatus(device_code, code, value), HttpStatus.OK); } @PostMapping("/feedbackOrderStatus") - @Log("acs强制完成向wms反馈") + @Log(value = "ACS强制完成向WMS反馈",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("acs强制完成向wms反馈") public ResponseEntity feedbackOrderStatus(@RequestBody JSONObject param) { return new ResponseEntity<>(acstowmsService.feedbackOrderStatus(param), HttpStatus.OK); @@ -78,28 +79,28 @@ public class AcsToWmsController { @PostMapping("/applyInCacheLineTask") - @Log("ACS申请缓存线入库任务") + @Log(value = "ACS申请缓存线入库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("ACS申请缓存线入库任务") public ResponseEntity applyInCacheLineTask(@RequestBody JSONObject param) { return new ResponseEntity<>(acstowmsService.applyInCacheLineTask(param), HttpStatus.OK); } @PostMapping("/applyOutCacheLineTask") - @Log("ACS系统申请出库任务") + @Log(value = "ACS系统申请出库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("ACS系统申请出库任务") public ResponseEntity applyOutCacheLineTask(@RequestBody JSONObject param) { return new ResponseEntity<>(acstowmsService.applyOutCacheLineTask(param), HttpStatus.OK); } @PostMapping("/applyLabelingAndBindingRequest") - @Log("ACS系统申请贴标、捆扎") + @Log(value = "ACS系统申请贴标、捆扎",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("ACS系统申请贴标、捆扎") public ResponseEntity applyLabelingAndBindingRequest(@RequestBody ApplyLabelingAndBindingRequest param) { return new ResponseEntity<>(acstowmsService.applyLabelingAndBindingRequest(param), HttpStatus.OK); } @PostMapping("/liKuApplyTaskRequest") - @Log("立库申请任务") + @Log(value = "立库申请任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("立库申请任务") public ResponseEntity liKuApplyTaskRequest(@RequestBody LiKuApplyTaskRequest param) { return new ResponseEntity<>(acstowmsService.liKuApplyTaskRequest(param), HttpStatus.OK); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/LiKuToACSController.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/LiKuToACSController.java index 24faaf6..e140f01 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/LiKuToACSController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/LiKuToACSController.java @@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j; import org.nl.acs.ext.wms.liKuData.*; import org.nl.acs.ext.wms.service.AcsToLiKuService; import org.nl.acs.ext.wms.service.LiKuToAcsService; +import org.nl.modules.logging.InterfaceLogType; import org.nl.modules.logging.annotation.Log; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -33,27 +34,35 @@ public class LiKuToACSController { @SaIgnore @PostMapping("/inStoreReport") - @Log("入库任务上报") - @ApiOperation("向立库下发入库任务上报") + @Log(value = "立库反馈入库任务状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LK_TO_ACS) + @ApiOperation("立库反馈入库任务状态") public ResponseEntity inStoreReport(@RequestBody InStoreReportRequest requestParam) throws Exception { return new ResponseEntity<>(liKuToAcsService.inStoreReport(requestParam), HttpStatus.OK); } @SaIgnore @PostMapping("/outStoreReport") - @Log("出库任务上报") - @ApiOperation("向立库下发出库任务上报") + @Log(value = "立库反馈出库任务状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LK_TO_ACS) + @ApiOperation("立库反馈出库任务状态") public ResponseEntity outStoreReport(@RequestBody OutStoreReportRequest requestParam) throws Exception { return new ResponseEntity<>(liKuToAcsService.outStoreReport(requestParam), HttpStatus.OK); } @SaIgnore @PostMapping("/moveStoreReport") - @Log("移库任务上报") - @ApiOperation("向立库下发移库任务上报") + @Log(value = "立库反馈移库任务状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LK_TO_ACS) + @ApiOperation("立库反馈移库任务状态") public ResponseEntity moveStoreReport(@RequestBody MoveStoreReportRequest requestParam) throws Exception { return new ResponseEntity<>(liKuToAcsService.moveStoreReport(requestParam), HttpStatus.OK); } + @SaIgnore + @PostMapping("/putEmptyPallet") + @Log(value = "立库请求放空盘",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LK_TO_ACS) + @ApiOperation("立库请求放空盘") + public ResponseEntity putEmptyPallet(@RequestBody putEmptyPalletRequest requestParam) throws Exception { + return new ResponseEntity<>(liKuToAcsService.putEmptyPallet(requestParam), HttpStatus.OK); + } + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java index 4f0ca0d..47c5a88 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java @@ -10,6 +10,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.ext.wms.data.CreateTaskResponse; import org.nl.acs.ext.wms.service.WmsToAcsService; +import org.nl.modules.logging.InterfaceLogType; import org.nl.modules.logging.annotation.Log; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -31,7 +32,7 @@ public class WmsToAcsController { private final WmsToAcsService wmstoacsService; @PostMapping("/task") - @Log("接收WMS任务") + @Log(value = "ACS接收WMS任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) @ApiOperation("接收WMS任务") @SaIgnore public ResponseEntity createFromWms(@RequestBody String whereJson) { @@ -39,7 +40,7 @@ public class WmsToAcsController { } @PostMapping("/cancelTask") - @Log("WMS取消任务") + @Log(value = "WMS取消任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) @ApiOperation("WMS取消任务") @SaIgnore public ResponseEntity cancelFromWms(@RequestBody String whereJson) throws Exception { @@ -47,42 +48,50 @@ public class WmsToAcsController { } @PostMapping("/updateDeviceGoodsFromWms") - @Log("WMS修改点位状态") + @Log(value = "WMS修改点位状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) @ApiOperation("WMS修改点位状态") public ResponseEntity updateDeviceGoodsFromWms(@RequestBody String whereJson) { return new ResponseEntity<>(wmstoacsService.updateDeviceGoodsFromWms(whereJson), HttpStatus.OK); } @PostMapping("/areaControl") - @Log("区域控制") + @Log(value = "区域控制",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) @ApiOperation("区域控制") public ResponseEntity areaControl(@RequestBody JSONObject whereJson) { return new ResponseEntity<>(wmstoacsService.areaControl(whereJson), HttpStatus.OK); } @PostMapping("/action") - @Log("下发动作") - @ApiOperation("WMS修改点位状态") + @Log(value = "WMS下发点位信号",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) + @ApiOperation("WMS下发点位信号") @SaIgnore public ResponseEntity putAction(@RequestBody String whereJson) throws Exception { return new ResponseEntity<>(wmstoacsService.putAction(whereJson), HttpStatus.OK); } @PostMapping("/querydevice") - @Log("查询设备状态") - @ApiOperation("查询设备状态") + @Log(value = "WMS查询设备状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) + @ApiOperation("WMS查询设备状态") @SaIgnore public ResponseEntity queryDevice(@RequestBody String whereJson) throws Exception { return new ResponseEntity<>(wmstoacsService.queryDevice(whereJson), HttpStatus.OK); } @PostMapping("/queryDeviceDBValue") - @Log("查询设备DB值") - @ApiOperation("查询设备DB值") + @Log(value = "WMS查询设备DB值",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) + @ApiOperation("WMS查询设备DB值") @SaIgnore public ResponseEntity queryDeviceDBValue(@RequestBody String whereJson){ return new ResponseEntity<>(wmstoacsService.queryDeviceDBValue(whereJson), HttpStatus.OK); } + @PostMapping("/putPlusPullAction") + @Log(value = "WMS下发插拔轴动作",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) + @ApiOperation("WMS下发插拔轴动作") + @SaIgnore + public ResponseEntity putPlusPullAction(@RequestBody String whereJson){ + return new ResponseEntity<>(wmstoacsService.putPlusPullAction(whereJson), HttpStatus.OK); + } + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToLiKuService.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToLiKuService.java index 0087d73..60c427e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToLiKuService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToLiKuService.java @@ -1,6 +1,8 @@ package org.nl.acs.ext.wms.service; +import com.alibaba.fastjson.JSONObject; import org.nl.acs.ext.wms.liKuData.*; +import org.nl.acs.instruction.service.dto.Instruction; /** * @author: geng by @@ -8,6 +10,9 @@ import org.nl.acs.ext.wms.liKuData.*; */ public interface AcsToLiKuService { + + public Resp sendInst(String type, Instruction inst); + /** * 入库任务下发 * @param requestParam @@ -65,4 +70,24 @@ public interface AcsToLiKuService { * @return */ public Resp cancelTask(CancelTaskRequest requestParam); + + /** + *查询小车设备状态 + * @return + */ + public Resp queryCarDeviceStatus(DeviceStatusRequest requestParam); + + /** + *查询tsj设备状态 + * @return + */ + public Resp queryTsjDeviceStatus(DeviceStatusRequest requestParam); + + /** + *查询ssx设备状态 + * @return + */ + public Resp querySsxDeviceStatus(DeviceStatusRequest requestParam); } + + 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 ec7c36f..b301900 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 { /** @@ -93,7 +91,7 @@ public interface AcsToWmsService { HttpResponse applyOutCacheLineTask(JSONObject param); /** - * ACS系统申请出库任务 + * 申请捆扎、贴标 * * @param param * @return @@ -103,4 +101,7 @@ public interface AcsToWmsService { LiKuApplyTakResponse liKuApplyTaskRequest(LiKuApplyTaskRequest liKuApplyTaskRequest); UpdateLKTaskResponse updateLKTaskRequest(UpdateLKTaskRequest updateLKTaskRequest); + + // 输送线有货变成无货时向lms请求 + HttpResponse shipDeviceUpdate(JSONObject param); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/LiKuToAcsService.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/LiKuToAcsService.java index 12c4d0a..b739480 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/LiKuToAcsService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/LiKuToAcsService.java @@ -29,4 +29,12 @@ public interface LiKuToAcsService { */ public Resp moveStoreReport(MoveStoreReportRequest requestParam) throws Exception; + + /** + * 移库任务上报 + * @param requestParam + * @return + */ + public Resp putEmptyPallet(putEmptyPalletRequest requestParam) throws Exception; + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/WmsToAcsService.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/WmsToAcsService.java index 1a676db..a9125cc 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/WmsToAcsService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/WmsToAcsService.java @@ -75,4 +75,13 @@ public interface WmsToAcsService { Map querydevice(String whereJson); + /** + * 下发插拔轴动作 + * + * @param whereJson 条件 + * @return Map + */ + Map putPlusPullAction(String whereJson); + + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToLiKuServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToLiKuServiceImpl.java index 0e76e85..1bdb2e8 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToLiKuServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToLiKuServiceImpl.java @@ -1,15 +1,26 @@ package org.nl.acs.ext.wms.service.impl; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.nl.acs.AcsConfig; import org.nl.acs.device.address.service.AddressService; import org.nl.acs.ext.wms.RespUtil; import org.nl.acs.ext.wms.AcsUtil; import org.nl.acs.ext.wms.liKuData.*; import org.nl.acs.ext.wms.service.AcsToLiKuService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.wql.util.SpringContextHolder; import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + /** * 立库WCS接口 * @@ -26,12 +37,13 @@ public class AcsToLiKuServiceImpl implements AcsToLiKuService { private String log_file_type="log_file_type"; private String log_type="ACS请求立库"; + @Override public Resp inStore(InStoreRequest requestParam) { try { MDC.put(log_file_type, log_type); String api = addressService.findByCode("inStore").getMethods_url(); - log.info("inStore-----输入参数{}", requestParam); + log.info("inStore-----输入参数{}", JSON.toJSONString(requestParam)); String result = AcsUtil.notifyAcs(api, requestParam); log.info("inStore-----输出参数{}", result); return RespUtil.getResp(result, new InStoreResponse()); @@ -45,7 +57,7 @@ public class AcsToLiKuServiceImpl implements AcsToLiKuService { public Resp outStore(OutStoreRequest requestParam) { try { MDC.put(log_file_type, log_type); - log.info("outStore-----输入参数{}", requestParam); + log.info("outStore-----输入参数{}", JSON.toJSONString(requestParam)); String api = addressService.findByCode("outStore").getMethods_url(); String result = AcsUtil.notifyAcs(api, requestParam); log.info("outStore-----输出参数{}", result); @@ -60,7 +72,7 @@ public class AcsToLiKuServiceImpl implements AcsToLiKuService { public Resp emptyVehicleOutStore(EmptyVehicleOutStoreRequest requestParam) { try { MDC.put(log_file_type, log_type); - log.info("emptyVehicleOutStore-----输入参数{}", requestParam); + log.info("emptyVehicleOutStore-----输入参数{}", JSON.toJSONString(requestParam)); String api = addressService.findByCode("emptyVehicleOutStore").getMethods_url(); String result = AcsUtil.notifyAcs(api, requestParam); log.info("emptyVehicleOutStore-----输出参数{}", result); @@ -75,7 +87,7 @@ public class AcsToLiKuServiceImpl implements AcsToLiKuService { public Resp moveStore(MoveStoreRequest requestParam) { try { MDC.put(log_file_type, log_type); - log.info("moveStore-----输入参数{}", requestParam); + log.info("moveStore-----输入参数{}", JSON.toJSONString(requestParam)); String api = addressService.findByCode("moveStore").getMethods_url(); String result = AcsUtil.notifyAcs(api, requestParam); log.info("moveStore-----输出参数{}", result); @@ -90,7 +102,7 @@ public class AcsToLiKuServiceImpl implements AcsToLiKuService { public Resp inStoreReset(InStoreResetRequest requestParam) { try { MDC.put(log_file_type, log_type); - log.info("inStoreReset-----输入参数{}", requestParam); + log.info("inStoreReset-----输入参数{}", JSON.toJSONString(requestParam)); String api = addressService.findByCode("inStoreReset").getMethods_url(); String result = AcsUtil.notifyAcs(api, requestParam); log.info("inStoreReset-----输出参数{}", result); @@ -105,7 +117,7 @@ public class AcsToLiKuServiceImpl implements AcsToLiKuService { public Resp moveStoreReset(MoveStoreResetRequest requestParam) { try { MDC.put(log_file_type, log_type); - log.info("moveStoreReset-----输入参数{}", requestParam); + log.info("moveStoreReset-----输入参数{}", JSON.toJSONString(requestParam)); String api = addressService.findByCode("moveStoreReset").getMethods_url(); String result = AcsUtil.notifyAcs(api, requestParam); log.info("moveStoreReset-----输出参数{}", result); @@ -121,7 +133,7 @@ public class AcsToLiKuServiceImpl implements AcsToLiKuService { public Resp roadWayIsLock(RoadWayIsLockRequest requestParam) { try { MDC.put(log_file_type, log_type); - log.info("roadWayIsLock-----输入参数{}", requestParam); + log.info("roadWayIsLock-----输入参数{}", JSON.toJSONString(requestParam)); String api = addressService.findByCode("roadWayIsLock").getMethods_url(); String result = AcsUtil.notifyAcs(api, requestParam); log.info("roadWayIsLock-----输出参数{}", result); @@ -138,7 +150,7 @@ public class AcsToLiKuServiceImpl implements AcsToLiKuService { public Resp cancelTask(CancelTaskRequest requestParam) { try { MDC.put(log_file_type, log_type); - log.info("cancelTask-----输入参数{}", requestParam); + log.info("cancelTask-----输入参数{}", JSON.toJSONString(requestParam)); String api = addressService.findByCode("cancelTask").getMethods_url(); String result = AcsUtil.notifyAcs(api, requestParam); log.info("cancelTask-----输出参数{}", result); @@ -150,4 +162,128 @@ public class AcsToLiKuServiceImpl implements AcsToLiKuService { } + @Override + public Resp queryCarDeviceStatus(DeviceStatusRequest requestParam) { + try { + MDC.put(log_file_type, log_type); + log.info("queryCarDeviceStatus-----输入参数{}", JSON.toJSONString(requestParam)); + String api = addressService.findByCode("queryCarDeviceStatus").getMethods_url(); + String result = AcsUtil.notifyAcs(api, requestParam); + log.info("queryCarDeviceStatus-----输出参数{}", result); + return RespUtil.getResp(result, new DeviceStatusRequest()); + } finally { + MDC.remove(log_file_type); + } + } + + @Override + public Resp queryTsjDeviceStatus(DeviceStatusRequest requestParam) { + try { + MDC.put(log_file_type, log_type); + log.info("queryTsjDeviceStatus-----输入参数{}", JSON.toJSONString(requestParam)); + String api = addressService.findByCode("queryTsjDeviceStatus").getMethods_url(); + String result = AcsUtil.notifyAcs(api, requestParam); + log.info("queryTsjDeviceStatus-----输出参数{}", result); + return RespUtil.getResp(result, new DeviceStatusRequest()); + } finally { + MDC.remove(log_file_type); + } + } + + @Override + public Resp querySsxDeviceStatus(DeviceStatusRequest requestParam) { + try { + MDC.put(log_file_type, log_type); + log.info("querySsxDeviceStatus-----输入参数{}", JSON.toJSONString(requestParam)); + String api = addressService.findByCode("querySsxDeviceStatus").getMethods_url(); + String result = AcsUtil.notifyAcs(api, requestParam); + log.info("querySsxDeviceStatus-----输出参数{}", result); + return RespUtil.getResp(result, new DeviceStatusRequest()); + } finally { + MDC.remove(log_file_type); + } + } + + @Override + public Resp sendInst(String type, Instruction dto){ + AcsToLiKuService acsToLiKuService = SpringContextHolder.getBean(AcsToLiKuService.class); + ParamService paramService = SpringContextHolder.getBean(ParamService.class); + + Resp resp = new Resp(); + String instSendLk = paramService.findByCode(AcsConfig.INSTSENDLK).getValue(); + + try { + if(StrUtil.equals(instSendLk, "1")){ + 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); + } + } else { + resp.setCode("0"); + resp.setResult("true"); + resp.setComment("ACS模拟下发成功"); + } + + } catch (Exception e) { + resp.setCode("1"); + resp.setResult("false"); + resp.setComment(e.getMessage()); + } + + return resp; + } + } 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 23fdfcc..71e9640 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 @@ -1,6 +1,7 @@ package org.nl.acs.ext.wms.service.impl; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; @@ -18,15 +19,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 @@ -67,11 +64,16 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { .header("Authorization", token) .body(String.valueOf(jo)) .execute(); - System.out.println(result2); +// ////System.out.println(result2); } catch (Exception e) { String msg = e.getMessage(); + log.info("applyTaskToWms-----输出参数{}", msg); //网络不通 - System.out.println(msg); +// //System.out.println(msg); + } + if(ObjectUtil.isEmpty(result2)){ + log.info("applyTaskToWms-----输出参数{}", "返回结果为空"); + return null; } String type = ""; if (result2.getStatus() == 200) { @@ -112,13 +114,16 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { result2 = HttpRequest.post(wmsurl + methods_url) .header("Authorization", token).body(String.valueOf(data)) .execute(); - System.out.println(result2); +// //System.out.println(result2); } catch (Exception e) { String msg = e.getMessage(); //网络不通 - System.out.println(msg); +// //System.out.println(msg); + log.info("feedbackTaskStatusToWms-----输出参数{}", msg); + } + String type = ""; if (result2.getStatus() == 200) { type = "info"; @@ -153,12 +158,13 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { result2 = HttpRequest.post(url) .body(String.valueOf(jo)) .execute().body(); - System.out.println(result2); + //System.out.println(result2); log.info("requestTaskAgain----返回参数{}", result2); } catch (Exception e) { String msg = e.getMessage(); //网络不通 - System.out.println(msg); + //System.out.println(msg); + } return result2; } @@ -187,7 +193,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } catch (Exception e) { String msg = e.getMessage(); //网络不通 - System.out.println(msg); + //System.out.println(msg); } return result; } @@ -220,7 +226,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } catch (Exception e) { String msg = e.getMessage(); //网络不通 - System.out.println(msg); + //System.out.println(msg); } return result; } @@ -244,7 +250,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } catch (Exception e) { String msg = e.getMessage(); //网络不通 - System.out.println(msg); + //System.out.println(msg); } return result; } @@ -269,7 +275,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } catch (Exception e) { String msg = e.getMessage(); //网络不通 - System.out.println(msg); + //System.out.println(msg); } return result; } @@ -290,7 +296,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } catch (Exception e) { String msg = e.getMessage(); //网络不通 - System.out.println(msg); + //System.out.println(msg); } return result; @@ -327,7 +333,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } catch (Exception e) { String msg = e.getMessage(); //网络不通 - System.out.println(msg); + //System.out.println(msg); } return result; @@ -360,7 +366,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } catch (Exception e) { String msg = e.getMessage(); //网络不通 - System.out.println(msg); + //System.out.println(msg); } return result; } @@ -392,7 +398,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } catch (Exception e) { String msg = e.getMessage(); //网络不通 - System.out.println(msg); + //System.out.println(msg); } return result; } @@ -411,6 +417,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { String url = wmsUrl + methods_url; log.info("ApplyLabelingAndBindingRequest----请求参数{}", param); try { +// String result = ""; String result = HttpRequest.post(url) .body(JSON.toJSONString(param)) .execute().body(); @@ -500,4 +507,26 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } + @Override + public HttpResponse shipDeviceUpdate(JSONObject param) { + try { + MDC.put(log_file_type, log_type); +// log.info("shipDeviceUpdate-----输入参数{}", param); + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue(); + AddressDto addressDto = addressService.findByCode("shipDeviceUpdate"); + String methods_url = addressDto.getMethods_url(); + String url = wmsUrl + methods_url; + return HttpRequest + .post(url) + .body(param.toString()) + .execute(); + } + } catch (Throwable ignored) { + + } 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 791e6b4..a097034 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 @@ -1,10 +1,15 @@ package org.nl.acs.ext.wms.service.impl; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.device.address.service.AddressService; +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.ext.wms.AcsUtil; import org.nl.acs.ext.wms.RespUtil; import org.nl.acs.ext.wms.data.UpdateLKTaskRequest; @@ -15,8 +20,12 @@ import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.ext.wms.service.LiKuToAcsService; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.DeviceAppServiceImpl; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.wql.util.SpringContextHolder; import org.slf4j.MDC; import org.springframework.stereotype.Service; @@ -48,76 +57,62 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { //入库任务状态反馈 @Override public Resp inStoreReport(InStoreReportRequest requestParam) throws Exception { - try { - MDC.put(log_file_type, log_type); - log.info("入库任务状态反馈-----输入参数{}", requestParam); - String inst_code = requestParam.getOrderId(); - String status = requestParam.getState(); - Instruction inst = instructionService.findByCodeFromCache(inst_code); - TaskDto task = taskService.findByCodeFromCache(inst.getTask_code()); - // 1 已接收 2 开始执行 3执行完成 4 阻挡 5 空洞 - if(StrUtil.equals(status,"1") || StrUtil.equals(status,"2") ){ - inst.setInstruction_status("1"); - instructionService.update(inst); - } else if(StrUtil.equals(status,"3")){ - inst.setInstruction_status("2"); - instructionService.finish(inst.getInstruction_id()); - } else if(StrUtil.equals(status,"4")) { - UpdateLKTaskRequest updateLKTaskRequest = new UpdateLKTaskRequest(); - updateLKTaskRequest.setVehicle_code(inst.getVehicle_code()); - updateLKTaskRequest.setExt_task_id(task.getExt_task_id()); - updateLKTaskRequest.setDtl_type(task.getStorage_task_type()); - updateLKTaskRequest.setSrcLocation(inst.getNext_point_code()); - updateLKTaskRequest.setType("1"); - //调用LMS接口申请获取新库位 - UpdateLKTaskResponse updateLKTaskResponse = acsToWmsService.updateLKTaskRequest(updateLKTaskRequest); - if(updateLKTaskResponse.getstatus() == 200){ - String srcLocation = updateLKTaskResponse.getParameters().get("srcLocation"); - String destLocation = updateLKTaskResponse.getParameters().get("destLocation "); - InStoreResetRequest inStoreResetRequest = new InStoreResetRequest(); - inStoreResetRequest.setFloorNo(Integer.parseInt(inst.getTo_z())); - inStoreResetRequest.setSrcLocation(srcLocation); - inStoreResetRequest.setDestLocation(destLocation); - inStoreResetRequest.setPalletCode(inst.getVehicle_code()); - inStoreResetRequest.setOrderId(inst.getInstruction_code()); - acsToLiKuService.inStoreReset(inStoreResetRequest); - } - } else if(StrUtil.equals(status,"5")) { - UpdateLKTaskRequest updateLKTaskRequest = new UpdateLKTaskRequest(); - updateLKTaskRequest.setVehicle_code(inst.getVehicle_code()); - updateLKTaskRequest.setExt_task_id(task.getExt_task_id()); - updateLKTaskRequest.setDtl_type(task.getStorage_task_type()); - updateLKTaskRequest.setSrcLocation(inst.getNext_point_code()); - updateLKTaskRequest.setType("2"); - //调用LMS接口申请获取新库位 - UpdateLKTaskResponse updateLKTaskResponse = acsToWmsService.updateLKTaskRequest(updateLKTaskRequest); - if(updateLKTaskResponse.getstatus() == 200){ - String srcLocation = updateLKTaskResponse.getParameters().get("srcLocation"); - String destLocation = updateLKTaskResponse.getParameters().get("destLocation "); - InStoreResetRequest inStoreResetRequest = new InStoreResetRequest(); - inStoreResetRequest.setFloorNo(Integer.parseInt(inst.getTo_z())); - inStoreResetRequest.setSrcLocation(srcLocation); - inStoreResetRequest.setDestLocation(destLocation); - inStoreResetRequest.setPalletCode(inst.getVehicle_code()); - inStoreResetRequest.setOrderId(inst.getInstruction_code()); - acsToLiKuService.inStoreReset(inStoreResetRequest); - - } - } + log.info("入库任务状态反馈-----输入参数{}", JSON.toJSONString(requestParam)); + String inst_code = requestParam.getOrderId(); + String status = requestParam.getState(); + String carNo = requestParam.getRobotId(); + Instruction inst = instructionService.findByCodeFromCache(inst_code); + if (ObjectUtil.isEmpty(inst)) { InStoreReportResponse inStoreReportResponse = new InStoreReportResponse(); inStoreReportResponse.setOrderId(inst_code); JSONObject result = new JSONObject(); - result.put("result", "true"); + result.put("result", "false"); result.put("code", "0"); - result.put("comment", ""); + result.put("comment", "未找到对应指令"); result.put("data", inStoreReportResponse ); log.info("入库任务状态反馈-----输出参数{}", result); return RespUtil.getResp(result.toString(), new InStoreReportResponse()); - } finally { - MDC.remove(log_file_type); } + TaskDto task = taskService.findByCodeFromCache(inst.getTask_code()); + if (ObjectUtil.isEmpty(task)) { + InStoreReportResponse inStoreReportResponse = new InStoreReportResponse(); + inStoreReportResponse.setOrderId(inst_code); + JSONObject result = new JSONObject(); + result.put("result", "false"); + result.put("code", "0"); + result.put("comment", "未找到对应任务"); + result.put("data", inStoreReportResponse ); + log.info("入库任务状态反馈-----输出参数{}", result); + return RespUtil.getResp(result.toString(), new InStoreReportResponse()); + } + // 1 已接收 2 开始执行 3执行完成 4 5 取消 + if(StrUtil.equals(status,"1") || StrUtil.equals(status,"2") ){ + 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"); + instructionService.finish(inst.getInstruction_id()); + } else if(StrUtil.equals(status,"4")) { + // 5 取消指令 + } else if(StrUtil.equals(status,"5")) { + + instructionService.cancel(inst.getInstruction_id()); + } + InStoreReportResponse inStoreReportResponse = new InStoreReportResponse(); + inStoreReportResponse.setOrderId(inst_code); + JSONObject result = new JSONObject(); + result.put("result", "true"); + result.put("code", "0"); + result.put("comment", ""); + result.put("data", inStoreReportResponse ); + log.info("入库任务状态反馈-----输出参数{}", result); + return RespUtil.getResp(result.toString(), new InStoreReportResponse()); } @@ -125,37 +120,58 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { public Resp outStoreReport(OutStoreReportRequest requestParam) throws Exception { try { MDC.put(log_file_type, log_type); - log.info("出库任务状态反馈-----输入参数{}", requestParam); + log.info("出库任务状态反馈-----输入参数{}", JSON.toJSONString(requestParam)); String inst_code = requestParam.getOrderId(); String status = requestParam.getState(); + String carNo = requestParam.getRobotId(); Instruction inst = instructionService.findByCodeFromCache(inst_code); + if (ObjectUtil.isEmpty(inst)) { + OutStoreReportResponse outStoreReportResponse = new OutStoreReportResponse(); + outStoreReportResponse.setOrderId(inst_code); + JSONObject result = new JSONObject(); + result.put("result", "false"); + result.put("code", "0"); + result.put("comment", "未找到对应指令"); + result.put("data", outStoreReportResponse ); + log.info("出库任务状态反馈-----输出参数{}", result); + return RespUtil.getResp(result.toString(), new OutStoreReportResponse()); + } TaskDto task = taskService.findByCodeFromCache(inst.getTask_code()); - + if (ObjectUtil.isEmpty(task)) { + OutStoreReportResponse outStoreReportResponse = new OutStoreReportResponse(); + outStoreReportResponse.setOrderId(inst_code); + JSONObject result = new JSONObject(); + result.put("result", "false"); + result.put("code", "0"); + result.put("comment", "未找到对应任务"); + result.put("data", outStoreReportResponse ); + log.info("出库任务状态反馈-----输出参数{}", result); + return RespUtil.getResp(result.toString(), new OutStoreReportResponse()); + } // 1 已接收 2 开始执行 3执行完成 4 阻挡 5 空洞 if(StrUtil.equals(status,"1") || StrUtil.equals(status,"2") ){ + 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"); - instructionService.finish(inst.getInstruction_id()); - //出库任务起点无货 - } else if(StrUtil.equals(status,"4")){ - UpdateLKTaskRequest updateLKTaskRequest = new UpdateLKTaskRequest(); - updateLKTaskRequest.setVehicle_code(inst.getVehicle_code()); - updateLKTaskRequest.setExt_task_id(task.getExt_task_id()); - updateLKTaskRequest.setDtl_type(task.getStorage_task_type()); - updateLKTaskRequest.setSrcLocation(inst.getStart_point_code()); - updateLKTaskRequest.setType("5"); - //调用LMS接口 - UpdateLKTaskResponse updateLKTaskResponse = acsToWmsService.updateLKTaskRequest(updateLKTaskRequest); +// inst.setInstruction_status("1"); +// instructionService.finish(inst.getInstruction_id()); + if(StrUtil.equals(task.getTask_type(),"7") && StrUtil.equals(task.getStorage_task_type(),"4")){ + inst.setInstruction_status("2"); + instructionService.finish(inst.getInstruction_id()); + } else { + inst.setRemark("立库已反馈完成,待输送上报任务号"); + instructionService.update(inst); + } + + } else if(StrUtil.equals(status,"4")){ + //5 取消指令 } else if(StrUtil.equals(status,"5")){ - UpdateLKTaskRequest updateLKTaskRequest = new UpdateLKTaskRequest(); - updateLKTaskRequest.setVehicle_code(inst.getVehicle_code()); - updateLKTaskRequest.setExt_task_id(task.getExt_task_id()); - updateLKTaskRequest.setDtl_type(task.getStorage_task_type()); - updateLKTaskRequest.setSrcLocation(inst.getStart_point_code()); - updateLKTaskRequest.setType("6"); - UpdateLKTaskResponse updateLKTaskResponse = acsToWmsService.updateLKTaskRequest(updateLKTaskRequest); + instructionService.cancel(inst.getInstruction_id()); } OutStoreReportResponse outStoreReportResponse = new OutStoreReportResponse(); @@ -182,61 +198,50 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { public Resp moveStoreReport(MoveStoreReportRequest requestParam) throws Exception { try { MDC.put(log_file_type, log_type); - log.info("移库任务上报-----输入参数{}", requestParam); + log.info("移库任务上报-----输入参数{}", JSON.toJSONString(requestParam)); String inst_code = requestParam.getOrderId(); String status = requestParam.getState(); + String carNo = requestParam.getRobotId(); Instruction inst = instructionService.findByCodeFromCache(inst_code); + if (ObjectUtil.isEmpty(inst)) { + MoveStoreReportResponse moveStoreReportResponse = new MoveStoreReportResponse(); + moveStoreReportResponse.setOrderId(inst_code); + JSONObject result = new JSONObject(); + result.put("result", "false"); + result.put("code", "0"); + result.put("comment", "未找到对应指令"); + result.put("data", moveStoreReportResponse ); + log.info("移库任务状态反馈-----输出参数{}", result); + return RespUtil.getResp(result.toString(), new MoveStoreReportResponse()); + } TaskDto task = taskService.findByCodeFromCache(inst.getTask_code()); - // 1 已接收 2 开始执行 3执行完成 4 阻挡 5 空洞 + if (ObjectUtil.isEmpty(task)) { + MoveStoreReportResponse moveStoreReportResponse = new MoveStoreReportResponse(); + moveStoreReportResponse.setOrderId(inst_code); + JSONObject result = new JSONObject(); + result.put("result", "false"); + result.put("code", "0"); + result.put("comment", "未找到对应任务"); + result.put("data", moveStoreReportResponse ); + log.info("移库任务状态反馈-----输出参数{}", result); + return RespUtil.getResp(result.toString(), new MoveStoreReportResponse()); + } // 1 已接收 2 开始执行 3执行完成 4 阻挡 5 空洞 if(StrUtil.equals(status,"1") || StrUtil.equals(status,"2") ){ + 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"); instructionService.finish(inst.getInstruction_id()); } else if(StrUtil.equals(status,"4")){ - UpdateLKTaskRequest updateLKTaskRequest = new UpdateLKTaskRequest(); - updateLKTaskRequest.setVehicle_code(inst.getVehicle_code()); - updateLKTaskRequest.setExt_task_id(task.getExt_task_id()); - updateLKTaskRequest.setDtl_type(task.getStorage_task_type()); - updateLKTaskRequest.setSrcLocation(inst.getStart_point_code()); - updateLKTaskRequest.setType("3"); - //调用LMS接口 - UpdateLKTaskResponse updateLKTaskResponse = acsToWmsService.updateLKTaskRequest(updateLKTaskRequest); - if(updateLKTaskResponse.getstatus() == 200){ - String srcLocation = updateLKTaskResponse.getParameters().get("srcLocation"); - String destLocation = updateLKTaskResponse.getParameters().get("destLocation "); - InStoreResetRequest inStoreResetRequest = new InStoreResetRequest(); - inStoreResetRequest.setFloorNo(Integer.parseInt(inst.getTo_z())); - inStoreResetRequest.setSrcLocation(srcLocation); - inStoreResetRequest.setDestLocation(destLocation); - inStoreResetRequest.setPalletCode(inst.getVehicle_code()); - inStoreResetRequest.setOrderId(inst.getInstruction_code()); - acsToLiKuService.inStoreReset(inStoreResetRequest); - - } } else if(StrUtil.equals(status,"5")){ - UpdateLKTaskRequest updateLKTaskRequest = new UpdateLKTaskRequest(); - updateLKTaskRequest.setVehicle_code(inst.getVehicle_code()); - updateLKTaskRequest.setExt_task_id(task.getExt_task_id()); - updateLKTaskRequest.setDtl_type(task.getStorage_task_type()); - updateLKTaskRequest.setSrcLocation(inst.getNext_point_code()); - updateLKTaskRequest.setType("4"); - UpdateLKTaskResponse updateLKTaskResponse = acsToWmsService.updateLKTaskRequest(updateLKTaskRequest); - if(updateLKTaskResponse.getstatus() == 200){ - String srcLocation = updateLKTaskResponse.getParameters().get("srcLocation"); - String destLocation = updateLKTaskResponse.getParameters().get("destLocation "); - - InStoreResetRequest inStoreResetRequest = new InStoreResetRequest(); - inStoreResetRequest.setFloorNo(Integer.parseInt(inst.getTo_z())); - inStoreResetRequest.setSrcLocation(srcLocation); - inStoreResetRequest.setDestLocation(destLocation); - inStoreResetRequest.setPalletCode(inst.getVehicle_code()); - inStoreResetRequest.setOrderId(inst.getInstruction_code()); - acsToLiKuService.inStoreReset(inStoreResetRequest); - - } + instructionService.cancel(inst.getInstruction_id()); } MoveStoreReportResponse moveStoreReportResponse = new MoveStoreReportResponse(); moveStoreReportResponse.setOrderId(inst_code); @@ -252,9 +257,49 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { MDC.remove(log_file_type); } - - } + + + //请求放空盘 + @Override + public Resp putEmptyPallet(putEmptyPalletRequest requestParam) throws Exception { + try { + MDC.put(log_file_type, log_type); + log.info("请求放空盘-----输入参数{}", JSON.toJSONString(requestParam)); + String device_code = requestParam.getDeviceId(); + String type = requestParam.getType(); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device device = appService.findDeviceByCode(device_code); + SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; + JSONObject result = new JSONObject(); + result.put("code", "0"); + if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { + siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); + if(StrUtil.equals(type,"1")){ + if((siemensConveyorDeviceDriver.getMode() ==2 || siemensConveyorDeviceDriver.getMode() ==7 )&& siemensConveyorDeviceDriver.getMove() ==0){ + result.put("result", "true"); + result.put("comment", ""); + } else { + result.put("result", "false"); + result.put("comment", "当前设备光电信号:"+siemensConveyorDeviceDriver.getMove()+",工作模式:"+siemensConveyorDeviceDriver.getMode()); + } + } else if(StrUtil.equals(type,"2")){ + siemensConveyorDeviceDriver.writing("to_command","3"); + siemensConveyorDeviceDriver.writing("to_command","3"); + + result.put("result", "true"); + result.put("comment", ""); + } + + } + log.info("请求放空盘-----输出参数{}", result); + return RespUtil.getResp(result.toString(), new DeviceStatusResponse()); + } finally { + MDC.remove(log_file_type); + } + + } + } 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 05a9ca8..15564de 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 @@ -2,6 +2,7 @@ package org.nl.acs.ext.wms.service.impl; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; @@ -13,8 +14,11 @@ import org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.CargoLiftConveyor import org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position.EmptyVehicleStackingPositionDeviceDriver; import org.nl.acs.device_driver.basedriver.hongxiang_conveyor.HongXiangStationDeviceDriver; import org.nl.acs.device_driver.basedriver.hongxiang_device.HongXiangConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.plug_pull_device_site.PlugPullDeviceSiteDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; import org.nl.acs.ext.wms.data.*; +import org.nl.acs.ext.wms.liKuData.Resp; +import org.nl.acs.ext.wms.service.AcsToLiKuService; import org.nl.acs.ext.wms.service.WmsToAcsService; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; @@ -34,6 +38,8 @@ import org.springframework.context.ApplicationContext; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -49,6 +55,8 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { private final DeviceService deviceService; private final DeviceAppService deviceAppService; private final RouteLineService routeLineService; + private final AcsToLiKuService acsToLiKuService; + private String log_file_type="log_file_type"; private String log_type="LMS请求ACS"; @@ -95,7 +103,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } response.setMessage("success"); response.setErrArr(errArr); - log.info("createFromWms--------------:输出参数:" + response); + log.info("cancelFromWms--------------:输出参数:" + response); return response; } @@ -157,10 +165,14 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { throw new Exception("未找到对应设备:" + device_code); } HongXiangStationDeviceDriver hongXiangStationDeviceDriver; + PlugPullDeviceSiteDeviceDriver plugPullDeviceSiteDeviceDriver; if (device.getDeviceDriver() instanceof HongXiangStationDeviceDriver) { hongXiangStationDeviceDriver = (HongXiangStationDeviceDriver) device.getDeviceDriver(); hongXiangStationDeviceDriver.writing(code, value); } + + + } response.setStatus(200); response.setMessage("success"); @@ -176,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); @@ -219,7 +231,8 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { jo.put("countdown_house", hongXiangConveyorDeviceDriver.getCountdown_house()); jo.put("countdown_min", hongXiangConveyorDeviceDriver.getCountdown_min()); jo.put("countdown_sec", hongXiangConveyorDeviceDriver.getCountdown_sec()); - jo.put("temperature", hongXiangConveyorDeviceDriver.getTemperature()); + //温度需要除以10 + jo.put("temperature", hongXiangConveyorDeviceDriver.getTemperature()/10); jo.put("door", hongXiangConveyorDeviceDriver.getDoor()); jo.put("finish", hongXiangConveyorDeviceDriver.getFinish()); jo.put("task", hongXiangConveyorDeviceDriver.getTask()); @@ -239,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 { @@ -291,6 +304,160 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { return null; } + + + @Override + public Map putPlusPullAction(String param) { + try { + MDC.put(log_file_type, log_type); + log.info("putPlusPullAction-----输入参数{}", param); + JSONObject jo = JSON.parseObject(param); + String device_code = jo.getString("device_code"); + String size = jo.getString("size"); + String type = jo.getString("type"); + Device device = deviceAppService.findDeviceByCode(device_code); + if (ObjectUtil.isEmpty(device)) { + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "未找到对应的设备:"+device_code); + return resultJson; + } + PlugPullDeviceSiteDeviceDriver plugPullDeviceSiteDeviceDriver; + if (device.getDeviceDriver() instanceof PlugPullDeviceSiteDeviceDriver) { + plugPullDeviceSiteDeviceDriver = (PlugPullDeviceSiteDeviceDriver) device.getDeviceDriver(); + // 0 穿轴 1拔轴 + if(StrUtil.equals(type,"1")){ + + if(plugPullDeviceSiteDeviceDriver.getMode() == 1){ + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "请求拔轴,当前设备工作模式未自动"); + return resultJson; + } + if(plugPullDeviceSiteDeviceDriver.getAction() == 0){ + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "请求拔轴,当前设备未全自动"); + return resultJson; + } + if(plugPullDeviceSiteDeviceDriver.getStatus() != 0){ + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "请求拔轴,当前设备未待机"); + return resultJson; + } + if(plugPullDeviceSiteDeviceDriver.getControl() != 0){ + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "请求拔轴,当前设备未远程控制"); + return resultJson; + } + if(plugPullDeviceSiteDeviceDriver.getMove() != 0){ + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "请求拔轴,当前设备有轴"); + return resultJson; + } + if(plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() ==1 + && plugPullDeviceSiteDeviceDriver.getStatus() ==0 && plugPullDeviceSiteDeviceDriver.getMove() ==0 + && plugPullDeviceSiteDeviceDriver.getControl() ==0 ){ + + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code","to_size"); + map.put("value",size); + list.add(map); + Map map2 = new HashMap(); + map2.put("code","to_type"); + map2.put("value",type); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code","to_command"); + map3.put("value","1"); + list.add(map3); + plugPullDeviceSiteDeviceDriver.writing(list); + + } else { + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "当前设备状态不满足下发条件"); + return resultJson; + } + + } else if (StrUtil.equals(type,"0")){ + + if(plugPullDeviceSiteDeviceDriver.getMode() == 1){ + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "请求插轴,当前设备工作模式未自动"); + return resultJson; + } + if(plugPullDeviceSiteDeviceDriver.getAction() == 0){ + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "请求插轴,当前设备未全自动"); + return resultJson; + } + if(plugPullDeviceSiteDeviceDriver.getStatus() != 0){ + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "请求插轴,当前设备未待机"); + return resultJson; + } + if(plugPullDeviceSiteDeviceDriver.getControl() != 0){ + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "请求插轴,当前设备未远程控制"); + return resultJson; + } + if(plugPullDeviceSiteDeviceDriver.getMove() != 1){ + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "请求插轴,当前设备没有轴"); + return resultJson; + } + + if(plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() ==1 + && plugPullDeviceSiteDeviceDriver.getStatus() ==0 && plugPullDeviceSiteDeviceDriver.getMove() ==1 + && plugPullDeviceSiteDeviceDriver.getControl() ==0 ){ + + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code","to_size"); + map.put("value",size); + list.add(map); + Map map2 = new HashMap(); + map2.put("code","to_type"); + map2.put("value",type); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code","to_command"); + map3.put("value","1"); + list.add(map3); + plugPullDeviceSiteDeviceDriver.writing(list); + + } else { + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", "当前设备状态不满足下发条件"); + return resultJson; + } + } + } + + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.OK.value()); + resultJson.put("message", "操作成功"); + log.info("putPlusPullAction--------------:输出参数" + resultJson.toString()); + return resultJson; + + } finally { + MDC.remove(log_file_type); + } + } + + + @Override public CreateTaskResponse crateTask(String param) { try { @@ -330,13 +497,28 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { String next_point_code2 = ""; String put_point_code = ""; if (StrUtil.isEmpty(task_code)) { - throw new WDKException("任务号不能为空"); + JSONObject json = new JSONObject(); + json.put("task_code", task_code); + json.put("ext_task_id", ext_task_id); + json.put("message", "任务号不能为空"); + errArr.add(json); + continue; } if (StrUtil.isEmpty(start_device_code)) { - throw new WDKException("起点不能为空"); + JSONObject json = new JSONObject(); + json.put("task_code", task_code); + json.put("ext_task_id", ext_task_id); + json.put("message", "起点不能为空"); + errArr.add(json); + continue; } if (StrUtil.isEmpty(next_device_code)) { - throw new WDKException("终点不能为空"); + JSONObject json = new JSONObject(); + json.put("task_code", task_code); + json.put("ext_task_id", ext_task_id); + json.put("message", "终点不能为空"); + errArr.add(json); + continue; } @@ -350,15 +532,15 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } JSONObject start_device_json2 = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + start_device_code2 + "'").uniqueResult(0); if (!ObjectUtil.isEmpty(start_device_json2)) { - start_point_code2 = (String) start_device_json2.get("parent_storage_code") == null ? start_device_code2 : (String) start_device_json.get("storage_code"); + start_point_code2 = (String) start_device_json2.get("parent_storage_code") == null ? start_device_code2 : (String) start_device_json2.get("storage_code"); } JSONObject next_device_json2 = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + next_device_code2 + "'").uniqueResult(0); if (!ObjectUtil.isEmpty(next_device_json2)) { - next_point_code2 = (String) next_device_json2.get("parent_storage_code") == null ? next_device_code2 : (String) next_device_json.get("storage_code"); + next_point_code2 = (String) next_device_json2.get("parent_storage_code") == null ? next_device_code2 : (String) next_device_json2.get("storage_code"); } JSONObject put_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + put_device_code + "'").uniqueResult(0); if (!ObjectUtil.isEmpty(put_device_json)) { - put_point_code = (String) put_device_json.get("parent_storage_code") == null ? put_device_code : (String) next_device_json.get("storage_code"); + put_point_code = (String) put_device_json.get("parent_storage_code") == null ? put_device_code : (String) put_device_json.get("storage_code"); } if (StrUtil.isNotEmpty(start_point_code) && start_point_code.indexOf("-") > 0) { String str[] = start_point_code.split("-"); @@ -399,14 +581,32 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { route_plan_code = "normal"; } + if( StrUtil.equals(task_type,"5") && taskService.querySameDeviceReadyTask(start_device_code,next_device_code,"0") > 1){ + JSONObject json = new JSONObject(); + json.put("task_code", task_code); + json.put("ext_task_id", ext_task_id); + json.put("message", "已存在相同的起点终点未执行的输送任务"); + errArr.add(json); + continue; + } TaskDto taskDto = taskService.findByCodeFromCache(task_code); if (taskDto != null) { - throw new WDKException("不能存在相同的任务号!"); + JSONObject json = new JSONObject(); + json.put("task_code", task_code); + json.put("ext_task_id", ext_task_id); + json.put("message", "不能存在相同的任务号"); + errArr.add(json); + continue; } if (!StrUtil.isEmpty(vehicle_code)) { TaskDto vehicle_dto = taskService.findByContainer(vehicle_code); if (vehicle_dto != null) { - throw new WDKException("已存在该载具号的任务!"); + JSONObject json = new JSONObject(); + json.put("task_code", task_code); + json.put("ext_task_id", ext_task_id); + json.put("message", "不能存在相同的托盘号"); + errArr.add(json); + continue; } } @@ -460,27 +660,66 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { try { // task_type=7 则是立库任务需要下刻下发 if (StrUtil.equals(task_dto.getTask_type(), "7")) { - taskService.create(task_dto); +// taskService.create(task_dto); +// try{ +// taskService.createInst(task_dto.getTask_id()); +// } catch (Exception e) { +// e.printStackTrace(); +// JSONObject json = new JSONObject(); +// json.put("task_code", task_code); +// json.put("ext_task_id", ext_task_id); +// json.put("message", "创建指令失败:"+e.getMessage()); +// errArr.add(json); +// } + + //创建临时指令 不创建、不生成 + //等立库反馈成功才能创建任务和指令 + Instruction inst = taskService.createTemporaryInst(task_dto); + Resp resp = acsToLiKuService.sendInst(task_dto.getStorage_task_type(),inst); + + if(StrUtil.equals(resp.result,"true")){ + //创建任务和指令 + taskService.create(task_dto); + inst.setSend_status("1"); + taskService.createInst(inst); + + } else { + JSONObject json = new JSONObject(); + json.put("task_code", task_code); + json.put("ext_task_id", ext_task_id); + json.put("message", resp.getComment()); + json.put("code", resp.code); + json.put("data", data); + errArr.add(json); + continue; + } + } else { taskService.create(task_dto); } } catch (Exception e) { - e.printStackTrace(); +// e.printStackTrace(); JSONObject json = new JSONObject(); json.put("task_code", task_code); json.put("ext_task_id", ext_task_id); json.put("message", e.getMessage()); errArr.add(json); + continue; } } if (ObjectUtil.isEmpty(errArr)) { response.setStatus(200); + response.setMessage("success"); } else { response.setStatus(400); + if(ObjectUtil.isNotEmpty(errArr)){ + response.setMessage(errArr.getJSONObject(0).getString("message")); + } else { + response.setMessage("false"); + } + response.setErrArr(errArr); } - response.setMessage("success"); - response.setErrArr(errArr); - log.info("createFromWms--------------:输出参数:" + response); + log.info("createFromWms--------------:输出参数:" + JSON.toJSONString(response)); return response; } finally { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/common/InstructStatusEnum.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/common/InstructStatusEnum.java index dafc5d2..46c0b46 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/common/InstructStatusEnum.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/common/InstructStatusEnum.java @@ -1,4 +1,6 @@ package org.nl.acs.instruction.common; public class InstructStatusEnum { + + } 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 841741c..050de45 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 62c9d75..203e45e 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 @@ -103,13 +103,14 @@ public interface InstructionService { */ void create(Instruction dto) throws Exception; + void create2(Instruction dto) throws Exception; /** * 再次创建 * * @param dto * @throws Exception */ - void createAgain(Instruction dto) throws Exception; + void createAgain(Instruction dto) throws Exception ; /** * 编辑 @@ -270,4 +271,9 @@ public interface InstructionService { boolean removeByCodeFromCache(String code); + + 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 37b47a7..3081615 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 @@ -1,30 +1,29 @@ - package org.nl.acs.instruction.service.impl; - +import cn.hutool.core.collection.ListUtil; 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.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.nl.acs.AcsConfig; -import org.nl.acs.agv.server.*; +import org.nl.acs.agv.server.MagicAgvService; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.agv.server.XianGongAgvService; 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.basedriver.cargo_lift_conveyor.CargoLiftConveyorDeviceDriver; +import org.nl.acs.device_driver.DeviceDriver; 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; import org.nl.acs.ext.wms.liKuData.*; import org.nl.acs.ext.wms.service.AcsToLiKuService; -import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.opc.Device; @@ -33,6 +32,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; @@ -52,19 +52,22 @@ import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Predicate; import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * @author ldjun * @description 服务实现 * @date 2021-03-18 - **/ + */ @Service @RequiredArgsConstructor @Slf4j public class InstructionServiceImpl implements InstructionService, ApplicationAutoInitial { - List instructions = new ArrayList(); + List instructions = new CopyOnWriteArrayList(); @Autowired DeviceAppService deviceAppService; @@ -86,15 +89,12 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public synchronized void reload() { - this.instructions = this.queryAll("instruction_status <2 and is_delete =0"); + List list = this.queryAll("instruction_status <2 and is_delete =0"); + this.instructions = new CopyOnWriteArrayList<>(list); } @Override public Map queryAll(Map whereJson, Pageable page) { - /*WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "instruction_status < 2 and is_delete =0 ", "update_time desc"); - */ -// this.reload(); HashMap map = new HashMap<>(); map.put("flag", "1"); String code = (String) whereJson.get("code"); @@ -103,6 +103,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu String status = (String) whereJson.get("status"); String point_code = (String) whereJson.get("point_code"); String is_over = (String) whereJson.get("is_over"); + String instruction_type = (String) whereJson.get("instruction_type"); if (!StrUtil.isEmpty(code)) { map.put("code", code); } @@ -121,9 +122,21 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu if (!StrUtil.isEmpty(is_over)) { map.put("is_over", is_over); } + map.put("instruction_type", instruction_type); - - final JSONObject jo = WQL.getWO("QINST_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), ""); + Integer currentPageNumber = page.getPageNumber() + 1; + Integer pageMaxSize = page.getPageSize(); + final JSONObject jo = + WQL.getWO("QINST_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), ""); + JSONArray jsonArray = jo.getJSONArray("content"); + List instructions = jsonArray.toJavaList(Instruction.class); + List instDtoList = + instructions.stream() + .skip((currentPageNumber - 1) * pageMaxSize) + .limit(pageMaxSize) + .collect(Collectors.toList()); + jo.put("content", instDtoList); + jo.put("totalElements", jsonArray.size()); return jo; } @@ -158,7 +171,10 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu map.put("end_time", end_time); } - final JSONObject jo = WQL.getWO("QINST_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); + final JSONObject jo = + WQL.getWO("QINST_QUERY") + .addParamMap(map) + .pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); return jo; } @@ -197,7 +213,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public List queryAll(String whereJson) { WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONArray arr = wo.query(whereJson).getResultJSONArray(0); + JSONArray arr = wo.query(whereJson, "create_time").getResultJSONArray(0); List list = arr.toJavaList(Instruction.class); return list; } @@ -217,6 +233,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; } @@ -231,13 +250,15 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByTaskcodeAndStatus(String code) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("task_code ='" + code + "' and instruction_status = '0'").uniqueResult(0); - if (ObjectUtil.isNotEmpty(json)){ - final Instruction obj = json.toJavaObject(Instruction.class); - return obj; - } - return null; + Iterator var3 = instructions.iterator(); + while (var3.hasNext()) { + Instruction instruction = (Instruction) var3.next(); + if (StrUtil.equals(instruction.getTask_code(), code) + && StrUtil.equals(instruction.getInstruction_status(), "0")) { + return instruction; + } + } + return null; } @Override @@ -254,8 +275,129 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu } @Override - @Transactional(rollbackFor = Exception.class) - public void create(Instruction dto) throws Exception { + public void create(Instruction dto) { + dto = foramte(dto); + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); + + 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.isEmpty(dto.getVehicle_code() )) { + // Instruction inst_dto = findByContainer(dto.getVehicle_code()); + // if (inst_dto != null) { + // log.error("存在相同载具号任务,载具号"+dto.getVehicle_code()); + // throw new BadRequestException("存在相同载具号任务!"); + // } + // } + // 起点设备与终点设备相同则为初始指令 + 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()); + } + } + + 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()); + } + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_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(""); + } + + 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); @@ -289,10 +431,10 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu 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")) { + 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()); } @@ -325,13 +467,15 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu 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); + 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())) { + if (route_device.equals(dto.getStart_device_code()) + && route_next_device.equals(dto.getNext_device_code())) { route = routeLineDto; break; } @@ -339,81 +483,14 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu if (ObjectUtil.isEmpty(route)) { throw new BadRequestException("未查询到相关路由!"); } - if (StrUtil.equals(shortPathsList.get(0).getType(), "1")){ + 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())) { + 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); + ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); } else { - //入库 - AcsToLiKuService acsToLiKuService = SpringContextHolder.getBean(AcsToLiKuService.class); - Resp resp = null; - if(StrUtil.equals(task.getStorage_task_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(task.getStorage_task_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(task.getStorage_task_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(task.getStorage_task_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(task.getStorage_task_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"); - } else { - dto.setSend_status("2"); - dto.setRemark(resp.getData().toString()); - } - } + // Boolean result = createLkInst(task.getStorage_task_type(),dto); } } } catch (Exception e) { @@ -428,9 +505,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu 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); @@ -446,19 +521,34 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu 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()); + 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); + 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")) { + 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()); } @@ -473,7 +563,6 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu 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()); @@ -484,20 +573,21 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu 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任务 -// if(!StrUtil.equals(type,"0")){ -// if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1")) { -// agvService.sendAgvInstToMagic(dto); -// } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { -// agvService.sendAgvInstToNDC(dto); -// } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) { -// agvService.addOrderSequences(dto); -// } -// } + // if(!StrUtil.equals(type,"0")){ + // if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1")) + // { + // agvService.sendAgvInstToMagic(dto); + // } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), + // "2")) { + // agvService.sendAgvInstToNDC(dto); + // } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), + // "3")) { + // agvService.addOrderSequences(dto); + // } + // } instructions.add(dto); } @@ -512,19 +602,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu JSONObject json = (JSONObject) JSONObject.toJSON(dto); wo.update(json); - - 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); - } - - + removeByCodeFromCache(dto.getInstruction_code()); + instructions.add(dto); +// this.reload(); } @Override @@ -579,9 +659,9 @@ 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("被删除或无权限,操作失败!"); + // if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); String currentUsername = SecurityUtils.getCurrentUsername(); String now = DateUtil.now(); entity.setUpdate_time(now); @@ -656,11 +736,12 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu } removeByCodeFromCache(entity.getInstruction_code()); +// this.reload(); } @Override @Transactional(rollbackFor = Exception.class) - public void finish(Instruction dto) throws Exception { + public void finish(Instruction dto) { String now = DateUtil.now(); dto.setInstruction_status("2"); WQLObject wo = WQLObject.getWQLObject("acs_instruction"); @@ -689,11 +770,12 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu return; } // 如果是无光电的设备 放货任务完成需要变更有货状态 -// StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; -// if(device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { -// standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); -// standardOrdinarySiteDeviceDriver.setMove(2); -// } + // StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; + // if(device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + // standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) + // device.getDeviceDriver(); + // standardOrdinarySiteDeviceDriver.setMove(2); + // } // 如果是无光电的设备 指令完成变更起点、终点状态 JSONObject jo = new JSONObject(); @@ -711,19 +793,21 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu deviceService.changeDeviceStatus(jo1); removeByCodeFromCache(dto.getInstruction_code()); - + // this.reload(); } @Override @Transactional(rollbackFor = Exception.class) - 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"); JSONObject taskjson = taskwo.query("task_id ='" + dto.getTask_id() + "'").uniqueResult(0); TaskDto acsTask = taskjson.toJavaObject(TaskDto.class); RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); - List list = routeLineService.getShortPathLines(dto.getNext_device_code(), acsTask.getNext_device_code(), acsTask.getRoute_plan_code()); + List list = + routeLineService.getShortPathLines( + dto.getNext_device_code(), acsTask.getNext_device_code(), acsTask.getRoute_plan_code()); if (ObjectUtils.isEmpty(list)) { throw new BadRequestException("路由不通"); } @@ -741,8 +825,20 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu String start_device_code = dto.getNext_device_code(); String start_point_code = null; String next_point_code = null; - String start_device = deviceAppService.findDeviceByCode(start_device_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name(); - String next_device = deviceAppService.findDeviceByCode(next_device_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name(); + String start_device = + deviceAppService + .findDeviceByCode(start_device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + String next_device = + deviceAppService + .findDeviceByCode(next_device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); if (StrUtil.equals("storage", start_device)) { start_point_code = start_device_code + "-" + acsTask.getFrom_y() + "-" + acsTask.getFrom_z(); } else { @@ -772,12 +868,17 @@ 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时取消指令 + // flag= true时取消指令 boolean flag = false; Instruction entity = this.findById(id); if (entity == null) { @@ -796,7 +897,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu flag = true; } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { - //NDC agv指令不当场取消指令,需要等agv上报 + // NDC agv指令不当场取消指令,需要等agv上报 if (!StrUtil.isEmpty(entity.getAgv_jobno())) { ndcAgvService.deleteAgvInstToNDC(entity); } else { @@ -813,30 +914,29 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu if (flag) { - if(StrUtil.equals(entity.getInstruction_type(),"7")){ + 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 空托盘出库 + // 1 入库,2 出库,3 移库,4 空托盘入库,5 空托盘出库 int type = 0; - if(StrUtil.equals(task.getStorage_task_type(),"1")){ + if (StrUtil.equals(task.getStorage_task_type(), "1")) { type = 1; - } else if (StrUtil.equals(task.getStorage_task_type(),"2")){ + } else if (StrUtil.equals(task.getStorage_task_type(), "2")) { type = 4; - } else if (StrUtil.equals(task.getStorage_task_type(),"3")){ + } else if (StrUtil.equals(task.getStorage_task_type(), "3")) { type = 2; - } else if (StrUtil.equals(task.getStorage_task_type(),"4")){ + } else if (StrUtil.equals(task.getStorage_task_type(), "4")) { type = 5; - } else if (StrUtil.equals(task.getStorage_task_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); @@ -853,7 +953,8 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu 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())) { + } else if (!StrUtil.equals(entity.getMaterial(), "1") + && !StrUtil.isEmpty(entity.getMaterial())) { jo.put("hasGoodStatus", "2"); } else { jo.put("hasGoodStatus", "0"); @@ -879,11 +980,12 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu } removeByCodeFromCache(entity.getInstruction_code()); } - +// this.reload(); } + @Override public void forceCancel(String id) throws Exception { - //flag= true时取消指令 + // flag= true时取消指令 boolean flag = false; Instruction entity = this.findById(id); if (entity == null) { @@ -908,7 +1010,8 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu 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())) { + } else if (!StrUtil.equals(entity.getMaterial(), "1") + && !StrUtil.isEmpty(entity.getMaterial())) { jo.put("hasGoodStatus", "2"); } else { jo.put("hasGoodStatus", "0"); @@ -935,10 +1038,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu removeByCodeFromCache(entity.getInstruction_code()); } - @Override public void cancelNOSendAgv(String id) throws Exception { - //flag= true时取消指令 + // flag= true时取消指令 Instruction entity = this.findById(id); if (entity == null) { throw new BadRequestException("被删除或无权限,操作失败!"); @@ -964,7 +1066,8 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu 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())) { + } else if (!StrUtil.equals(entity.getMaterial(), "1") + && !StrUtil.isEmpty(entity.getMaterial())) { jo.put("hasGoodStatus", "2"); } else { jo.put("hasGoodStatus", "0"); @@ -990,78 +1093,81 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu } removeByCodeFromCache(entity.getInstruction_code()); - } - @Override public Instruction findByLinkNumSend(String code) { - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); - if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "1")) { - return inst; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "1")) { + return inst; + } } - } + return null; } - @Override public List findByLinkNum(String code) { - List list = new ArrayList<>(); - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); - if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { - list.add(inst); + List list = new ArrayList<>(); + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { + list.add(inst); + } } - } - return list; + return list; } @Override public Instruction findByLinkNumNoSend(String code) { - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); - if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { - return inst; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { + return inst; + } } - } - return null; + + return null; } @Override public Instruction findByCodeFromCache(String code) { - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); - if (StrUtil.equals(code, inst.getInstruction_code())) { - return inst; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getInstruction_code())) { + return inst; + } } - } - return null; + return null; } - @Override public Instruction findByBarcodeFromCache(String barcode) { - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); - if (StrUtil.equals(barcode, inst.getVehicle_code())) { - return inst; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(barcode, inst.getVehicle_code())) { + return inst; + } } - } - return null; + return null; } @Override public Instruction findByIdFromCache(String id) { - - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); - if (StrUtil.equals(id, inst.getInstruction_id())) { - return inst; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(id, inst.getInstruction_id())) { + return inst; + } } - } - return null; + return null; } @Override @@ -1089,7 +1195,13 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu inst.setFrom_y(start_point[1]); inst.setFrom_z(start_point[2]); } else { - String start_device = deviceAppService.findDeviceByCode(start_device_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name(); + String start_device = + deviceAppService + .findDeviceByCode(start_device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); if (StrUtil.equals("storage", start_device)) { String[] start_point = start_point_code.split("-"); inst.setFrom_x(start_point[0]); @@ -1109,7 +1221,13 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu inst.setTo_z(next_point[2]); } else { - String next_device = deviceAppService.findDeviceByCode(next_device_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name(); + String next_device = + deviceAppService + .findDeviceByCode(next_device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); if (StrUtil.equals("storage", next_device)) { String[] next_point = start_point_code.split("-"); inst.setTo_x(next_point[0]); @@ -1125,13 +1243,24 @@ 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); - if (StrUtil.equals(devicecode, inst.getStart_device_code()) && inst.getInstruction_status().equals("0")) { - return inst; + List instructionList = instructions; + ListUtil.sort( + instructionList, + new Comparator() { + @Override + public int compare(Instruction o1, Instruction o2) { + return o1.getCreate_time().compareTo(o2.getCreate_time()); + } + }); + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(devicecode, inst.getStart_device_code()) + && inst.getInstruction_status().equals("0")) { + return inst; + } } - } + return null; } @@ -1140,78 +1269,152 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu return instructions; } - @Override public Integer querySameDestinationInst(String devicecode) { - int num = 0; - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); - //处理空盘位站点 - String next_code = inst.getNext_point_code(); - if (next_code.indexOf(".") != -1) { - next_code = next_code.substring(0, next_code.indexOf(".")); + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + // 处理空盘位站点 + String next_code = inst.getNext_point_code(); + if (next_code.indexOf(".") != -1) { + next_code = next_code.substring(0, next_code.indexOf(".")); + } + if (StrUtil.equals(devicecode, next_code)) { + num = num + 1; + } } - if (StrUtil.equals(devicecode, next_code)) { - num = num + 1; - } - } - return num; + + return num; } @Override public Integer querySameInstType(String inst_type) { - int num = 0; - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); - if (StrUtil.equals(inst.getInstruction_type(), inst_type)) { - num = num + 1; + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(inst.getInstruction_type(), inst_type)) { + num = num + 1; + } } + return num; } - return num; - } @Override public Integer querySameOriginInst(String devicecode) { - int num = 0; - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); - //处理空盘位站点 - String start_code = inst.getStart_point_code(); - if (start_code.indexOf(".") != -1) { - start_code = start_code.substring(0, start_code.indexOf(".")); + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + // 处理空盘位站点 + String start_code = inst.getStart_point_code(); + if (start_code.indexOf(".") != -1) { + start_code = start_code.substring(0, start_code.indexOf(".")); + } + if (StrUtil.equals(devicecode, start_code)) { + num = num + 1; + } } - if (StrUtil.equals(devicecode, start_code)) { - num = num + 1; - } - } - return num; + return num; } @Override public boolean removeByCodeFromCache(String code) { - - Iterator iterator = instructions.iterator(); - while (iterator.hasNext()) { - Instruction instruction = iterator.next(); - if (instruction.getInstruction_code().equals(code)) { - iterator.remove(); - return true; - } - } - return false; + CopyOnWriteArrayList instructions = (CopyOnWriteArrayList) this.instructions; + instructions.removeIf((inst) -> { + return inst.getInstruction_code().equals(code); + }); +// while (iterator.hasNext()) { +// Instruction instruction = iterator.next(); +// if (instruction.getInstruction_code().equals(code)) { +// iterator.remove(); +// return true; +// } +// } + return true; } - public Instruction findByContainer(String container_code) { - Iterator var3 = instructions.iterator(); - - while (var3.hasNext()) { - Instruction instruction = (Instruction) var3.next(); - if (StrUtil.equals(instruction.getVehicle_code(), container_code)) { - return instruction; + @Override + public boolean createLkInst(String type, Instruction dto) { + 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); } - } - return null; + 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("ERROR"); + return false; + } + return true; + } } /* @@ -1223,4 +1426,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/instruction/service/wql/QINST_QUERY.wql b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/wql/QINST_QUERY.wql index 170478f..4b39fdf 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/wql/QINST_QUERY.wql +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/wql/QINST_QUERY.wql @@ -19,9 +19,9 @@ 输入.material_type TYPEAS s_string 输入.status TYPEAS s_string 输入.point_code TYPEAS s_string - 输入.point_code TYPEAS s_string 输入.create_time TYPEAS time 输入.end_time TYPEAS time + 输入.instruction_type TYPEAS s_string [临时表] @@ -45,46 +45,52 @@ ########################################## # 3、业务主过程 # ########################################## - IF 输入.flag = "1" - PAGEQUERY - SELECT - * - FROM - acs_instruction inst - WHERE - is_delete =0 - OPTION 输入.is_over = "1" - inst.instruction_status >= 2 - ENDOPTION - OPTION 输入.is_over <> "1" - inst.instruction_status < 2 - ENDOPTION - OPTION 输入.task_code <> "" - ( - inst.instruction_code = 输入.code - OR - inst.task_code = 输入.code - ) - ENDOPTION - OPTION 输入.status <> "" - inst.instruction_status = 输入.status - ENDOPTION - OPTION 输入.vehicle_code <> "" - inst.vehicle_code = 输入.vehicle_code - ENDOPTION - OPTION 输入.material_type <> "" - inst.material = 输入.material_type - ENDOPTION - OPTION 输入.point_code <> "" - ( - inst.start_point_code = 输入.point_code - OR - inst.next_point_code = 输入.point_code - ) - ENDOPTION - ENDSELECT - ENDPAGEQUERY - ENDIF + + IF 输入.flag = "1" + PAGEQUERY + SELECT + * + FROM + acs_instruction inst + WHERE + is_delete =0 + OPTION 输入.is_over = "1" + inst.instruction_status >= 2 + ENDOPTION + OPTION 输入.is_over <> "1" + inst.instruction_status < 2 + ENDOPTION + OPTION 输入.code <> "" + ( + inst.instruction_code LIKE CONCAT ( '%', 输入.code, '%' ) + OR + inst.task_code LIKE CONCAT ( '%', 输入.code, '%' ) + ) + ENDOPTION + OPTION 输入.status <> "" + inst.instruction_status = 输入.status + ENDOPTION + OPTION 输入.vehicle_code <> "" + inst.vehicle_code LIKE CONCAT ( '%', 输入.vehicle_code, '%' ) + ENDOPTION + OPTION 输入.material_type <> "" + inst.material = 输入.material_type + ENDOPTION + OPTION 输入.point_code <> "" + ( + inst.start_point_code LIKE CONCAT ( '%', 输入.point_code, '%' ) + OR + inst.next_point_code LIKE CONCAT ( '%', 输入.point_code, '%' ) + ) + ENDOPTION + OPTION 输入.instruction_type <> "" + inst.instruction_type = 输入.instruction_type + ENDOPTION + ORDER BY + inst.create_time DESC + ENDSELECT + ENDPAGEQUERY + ENDIF IF 输入.flag = "2" PAGEQUERY @@ -94,33 +100,32 @@ acs_instruction inst WHERE is_delete =0 - OPTION 输入.task_code <> "" + OPTION 输入.code <> "" ( - inst.instruction_code = 输入.code + inst.instruction_code LIKE CONCAT ( '%', 输入.code, '%' ) OR - inst.task_code = 输入.code + inst.task_code LIKE CONCAT ( '%', 输入.code, '%' ) ) ENDOPTION OPTION 输入.status <> "" inst.instruction_status = 输入.status ENDOPTION OPTION 输入.vehicle_code <> "" - inst.vehicle_code = 输入.vehicle_code + inst.vehicle_code LIKE CONCAT ( '%', 输入.vehicle_code, '%' ) ENDOPTION OPTION 输入.material_type <> "" inst.material = 输入.material_type ENDOPTION OPTION 输入.point_code <> "" ( - inst.start_point_code = 输入.point_code + inst.start_point_code LIKE CONCAT ( '%', 输入.point_code, '%' ) OR - inst.next_point_code = 输入.point_code + inst.next_point_code LIKE CONCAT ( '%', 输入.point_code, '%' ) ) ENDOPTION + OPTION 输入.create_time <> "" + inst.create_time between 输入.create_time and 输入.end_time ENDOPTION - OPTION 输入.create_time <> "" - inst.create_time between 输入.create_time and 输入.end_time - ENDOPTION ENDSELECT ENDPAGEQUERY ENDIF diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/log/LokiLogAspect.java b/acs/nladmin-system/src/main/java/org/nl/acs/log/LokiLogAspect.java index d41679d..7caa9b5 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/log/LokiLogAspect.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/log/LokiLogAspect.java @@ -37,7 +37,7 @@ public class LokiLogAspect { * @return */ @Around("operatorLog()") - public synchronized Object around(ProceedingJoinPoint pjp) throws Throwable { + public Object around(ProceedingJoinPoint pjp) throws Throwable { // ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); // HttpServletRequest request = attributes.getRequest(); // HttpServletResponse response = attributes.getResponse(); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/log/service/impl/DeviceExecuteLogServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/log/service/impl/DeviceExecuteLogServiceImpl.java index 1b17132..c31e502 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/log/service/impl/DeviceExecuteLogServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/log/service/impl/DeviceExecuteLogServiceImpl.java @@ -1,11 +1,10 @@ - package org.nl.acs.log.service.impl; - import cn.hutool.core.date.DateUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.OpcUtl; import org.slf4j.MDC; import org.springframework.stereotype.Service; @@ -13,39 +12,41 @@ import org.springframework.stereotype.Service; * @author loujf * @description 服务实现 * @date 2022-02-25 - **/ + */ @Service @RequiredArgsConstructor @Slf4j public class DeviceExecuteLogServiceImpl implements DeviceExecuteLogService { + @Override + public void deviceItemValue(String device_code, String key, String value) { + String now = DateUtil.now(); + } - @Override - public void deviceItemValue(String device_code, String key, String value) { - String now = DateUtil.now(); - - + @Override + public void deviceExecuteLog( + String device_code, String vehicle_code, String inst_code, String message) { + try { + MDC.put("device_code_log", device_code); + log.info("{},{}", device_code, message); + } catch (Exception e) { + e.printStackTrace(); + } finally { + MDC.remove("device_code_log"); + System.out.println("successNum:" + OpcUtl.successNum); + System.out.println("errNum:" + OpcUtl.errNum); } + } - @Override - public void deviceExecuteLog(String device_code, String vehicle_code, String inst_code, String message) { - try { - MDC.put("device_code_log", device_code); - log.info("{},{}", device_code, message); - } finally { - MDC.remove("device_code_log"); - } - } - - @Override - public void extLog(String name, String message) { - try { - MDC.put(name, name); - log.info("{}", message); - } finally { - MDC.remove(name); - } + @Override + public void extLog(String name, String message) { + try { + MDC.put(name, name); + log.info("{}", message); + } catch (Exception e) { + e.printStackTrace(); + } finally { + MDC.remove(name); } + } } - - 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 4a39009..ac5ade6 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 @@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; import org.nl.acs.udw.UnifiedDataAccessor; import org.nl.acs.udw.UnifiedDataAccessorFactory; +import org.nl.modules.wql.util.SpringContextHolder; import org.openscada.opc.lib.da.Group; import org.openscada.opc.lib.da.Item; import org.openscada.opc.lib.da.ItemState; @@ -15,193 +16,220 @@ import java.util.*; @Slf4j public class DeviceOpcProtocolRunable implements Runnable { - List protocols; - OpcServerManageDto OpcServer; - int error_num; - String message; + OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class); - public DeviceOpcProtocolRunable() { - this.error_num = 0; - this.message = null; - } - public List getProtocols() { - return this.protocols; - } + List protocols; + OpcServerManageDto OpcServer; + int error_num; + String message; - public void setProtocols(List protocols) { - this.protocols = protocols; - } + Group group; - public OpcServerManageDto getOpcServer() { - return this.OpcServer; - } + public DeviceOpcProtocolRunable() { + this.error_num = 0; + this.message = null; + } - public void setOpcServer(OpcServerManageDto opcServer) { - this.OpcServer = opcServer; - } + public List getProtocols() { + return this.protocols; + } - OpcItemDto getItem(String item) { - Iterator var2 = this.protocols.iterator(); + public void setProtocols(List protocols) { + this.protocols = protocols; + } - OpcItemDto dto; - do { - if (!var2.hasNext()) { - return null; - } + public OpcServerManageDto getOpcServer() { + return this.OpcServer; + } - dto = (OpcItemDto) var2.next(); - } while (!StrUtil.equals(item, dto.getItem_code())); + public void setOpcServer(OpcServerManageDto opcServer) { + this.OpcServer = opcServer; + } - return dto; - } + OpcItemDto getItem(String item) { + Iterator var2 = this.protocols.iterator(); - @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(); + OpcItemDto dto; + do { + if (!var2.hasNext()) { + return null; + } - while (it.hasNext()) { - OpcItemDto protocol = (OpcItemDto) it.next(); - String item = protocol.getItem_code(); - itemsString.add(item); - } + dto = (OpcItemDto) var2.next(); + } while (!StrUtil.equals(item, dto.getItem_code())); - Map itemsMap = new LinkedHashMap(); - boolean is_error = false; - StringBuilder err_message = new StringBuilder(); - Iterator var7 = itemsString.iterator(); + return dto; + } - while (var7.hasNext()) { - String string = (String) var7.next(); + @Override + public void run() { + while (true) { + try { + group= opcServerService.getServer(this.OpcServer.getOpc_code()); - 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; - } - } - } + List itemsString = new ArrayList(); + Iterator it = this.protocols.iterator(); - if (is_error) { - log.info("设备OPC数据同步配置异常"); - } - - 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 =null; + + try{ + itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); + }catch (Exception e){ + try{ + itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); + }catch (Exception e2){ + itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); + } + } + + + //TODO 读完释放server可行否? + + 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; + } + + // A1_HK_04.A1_HK_04.A1_HK_04_3.door 列表 + Set items = itemStatus.keySet(); + Iterator var18 = items.iterator(); + + while (true) { + Item item; + // A1_HK_04.A1_HK_04.A1_HK_04_3.door + // 当前值 + 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}); + } + // 设置值 + accessor_value.setValue(item.getId(), value); + } + } + } catch (Exception var30) { + + if (group != null) { + try { + group.getServer().dispose(); + group.clear(); + group.remove(); + } catch (Exception var6) { + } + this.group = 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 246a54a..a87a839 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 cadf67c..8507168 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 0000000..3e1f7a3 --- /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 0000000..92a2654 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java @@ -0,0 +1,154 @@ +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); + if (server!=null){ + 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/OpcServerUtl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerUtl.java index 5cdc7ed..8bce071 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerUtl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerUtl.java @@ -12,6 +12,7 @@ public class OpcServerUtl { domain = ""; } return OpcUtl.getServer(host, clsid, user, password, domain); +// return OpcUtl.getAutoServer(host, clsid, user, password, domain); } else { return null; } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcStartTag.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcStartTag.java index c8ef74e..0b1679a 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcStartTag.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcStartTag.java @@ -1,5 +1,5 @@ package org.nl.acs.opc; public class OpcStartTag { - public static boolean is_run = true; + public static boolean is_run = false; } 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 ae20e87..41e6525 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,19 +4,28 @@ 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; @Slf4j public class OpcUtl { - private static int timeout = 180000; + private static int timeout = 1*60*1000; private static String key = "rpc.socketTimeout"; + public static int successNum=0; + public static int errNum=0; + + static { + checkTimeout(); + } public static void checkTimeout() { if (Integer.getInteger(key, 0).intValue() != timeout) { @@ -26,9 +35,20 @@ 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=null; + try{ + e=group.write(requests); + group.write(requests); + }catch (Exception e1){ + try{ + e= group.write(requests); + }catch (Exception e2){ + e= group.write(requests); + } + } + boolean is_success = true; StringBuilder message = new StringBuilder(); Iterator arg4 = e.keySet().iterator(); @@ -50,9 +70,60 @@ public class OpcUtl { if (!is_success) { // throw new BusinessException(message.toString()); + System.out.println("下发信号失败:"+message.toString()); + System.out.println("下发信号失败原因:"+message.toString()); + log.info("下发信号失败:"+message.toString()); + throw new WDKException(message.toString()); } } catch (JIException arg7) { - // throw new BusinessException(arg7); + log.info("下发信号失败:"+arg7.getMessage()); + System.out.println("下发信号失败原因:"+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[]"); } } @@ -60,6 +131,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()); } @@ -150,12 +222,27 @@ public class OpcUtl { server = new Server(getConnection(host, clsid, user, password, domain), Executors.newSingleThreadScheduledExecutor()); server.connect(); + successNum++; return server; } catch (Exception e) { - throw new WDKException(e); + errNum++; + throw new WDKException(e.getMessage()); + }finally{ + System.out.println("successNum:"+successNum); + System.out.println("errNum:"+errNum); + System.out.println(11); } } + public static Server getAutoServer(String host, String clsid, String user, String password, String domain) throws WDKException { + checkTimeout(); + Server server = null; + server = new Server(getConnection(host, clsid, user, password, domain), Executors.newSingleThreadScheduledExecutor()); + AutoReconnectController autoReconnectController = new AutoReconnectController(server); + autoReconnectController.connect(); + return server; + } + public static ConnectionInformation getConnection(String host, String clsid, String user, String password, String domain) { ConnectionInformation connection = new ConnectionInformation(); @@ -167,31 +254,44 @@ public class OpcUtl { return connection; } - 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", ""); -// String byteItemString = "RD1.RD1.1001.mode"; - Group group = server.addGroup(); - Item byteItem = group.addItem(item); - ItemState itemState = null; - JIVariant value = null; - itemState = byteItem.read(true); - value = itemState.getValue(); - String data = OpcUtl.getValue(byteItem, itemState) + ""; - return data; + 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 void main(String[] args) throws Exception { - Server server = getServer("192.168.81.251", "7bc0cc8e-482c-47ca-abdc-0fe7f9c6e729", "administrator", "Huawei@123", ""); - String byteItemString = "RD1.RD1.1001.mode"; - Group group = server.addGroup(); - Item byteItem = group.addItem(byteItemString); - ItemState itemState = null; - JIVariant value = null; - System.out.println(byteItem.getId()); - itemState = byteItem.read(true); - System.out.println(itemState.getQuality()); - System.out.println(getValue(byteItem, itemState)); + 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; + } + + } 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 0000000..c2e51c0 --- /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 d35748e..7f7f745 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 0000000..fd1c749 --- /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/acs/task/rest/TaskController.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java index e208999..9b37cfc 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java @@ -2,6 +2,7 @@ package org.nl.acs.task.rest; +import cn.dev33.satoken.annotation.SaIgnore; import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -46,6 +47,7 @@ public class TaskController { @GetMapping("/reload") @Log("数据同步") @ApiOperation("数据同步") + @SaIgnore //@PreAuthorize("@el.check('task:list')") public ResponseEntity reload() { taskService.reload(); @@ -146,4 +148,13 @@ public class TaskController { return new ResponseEntity<>(HttpStatus.CREATED); } + @SaIgnore + @Log("查询缓存所有任务") + @ApiOperation("查询缓存任务") + @PostMapping(value = "/findAllTaskFromCache") + public ResponseEntity findAllTaskFromCache() { + return new ResponseEntity<>(taskService.findAllTaskFromCache(), HttpStatus.OK); + } + + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java index f5f5f07..2acbb63 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java @@ -3,6 +3,7 @@ package org.nl.acs.task.service; import com.alibaba.fastjson.JSONObject; +import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.task.service.dto.TaskDto; import org.springframework.data.domain.Pageable; @@ -191,7 +192,12 @@ public interface TaskService { * * @param ids */ - void createInst(String ids) throws Exception; + Instruction createInst(String ids) throws Exception; + + Instruction createInst(Instruction inst) throws Exception; + + + Instruction createTemporaryInst(TaskDto dto); /** * 导出数据 @@ -219,6 +225,7 @@ public interface TaskService { TaskDto findByCodeFromCache(String task_code); + /** * 根据目的地设备编号查询当前是否有设备 * @@ -291,11 +298,21 @@ public interface TaskService { Integer querySameOriginTask(String code); /** - * 查询相同起终任务的数量 + * 查询相同终点任务的数量 * * @param code * @return */ Integer querySameDestinationTask(String code); + + /** + * 查询相同起终任务的数量 + * + * @param + * @return + */ + Integer querySameDeviceReadyTask(String start_device,String next_device,String status); + + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java index dd4d38a..e034bc8 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java @@ -180,7 +180,6 @@ public class TaskFeedbackServiceImpl implements TaskFeedbackService { e.printStackTrace(); } int status = body.getStatus(); - JSONObject jo = (JSONObject) JSONObject.toJSON(body.body()); dto.setTask_status(entity.getTask_status()); if (status == 200) { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index 15ea30f..7efd12e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -1,7 +1,5 @@ - package org.nl.acs.task.service.impl; - import cn.hutool.core.date.DateUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.IdUtil; @@ -12,6 +10,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; +import lombok.Synchronized; import lombok.extern.slf4j.Slf4j; import org.nl.acs.AcsConfig; import org.nl.acs.agv.server.XianGongAgvService; @@ -31,6 +30,7 @@ import org.nl.acs.opc.DeviceAppServiceImpl; import org.nl.acs.opc.DeviceType; import org.nl.acs.route.service.RouteLineService; import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.TaskInstructionLock; import org.nl.acs.task.service.TaskFeedbackService; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; @@ -53,1303 +53,1558 @@ import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * @author ldjun * @description 服务实现 * @date 2021-03-18 - **/ + */ @Service @RequiredArgsConstructor @Slf4j public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { - List tasks = new ArrayList(); + List tasks = new CopyOnWriteArrayList<>(); - @Autowired - DeviceAppService deviceAppService; - @Autowired - RouteLineService routelineserver; - @Autowired - AcsToWmsService acstowmsService; - @Autowired - TaskFeedbackService taskFeedbackService; - @Autowired - ParamService paramService; - @Autowired - XianGongAgvService agvService; - @Autowired - RouteLineService routeLineService; - @Autowired - DeviceAssignedService deviceAssignedService; - @Autowired - InstructionService instructionService; - @Autowired - StorageCellService storageCellService; + @Autowired DeviceAppService deviceAppService; + @Autowired RouteLineService routelineserver; + @Autowired AcsToWmsService acstowmsService; + @Autowired TaskFeedbackService taskFeedbackService; + @Autowired ParamService paramService; + @Autowired XianGongAgvService agvService; + @Autowired RouteLineService routeLineService; + @Autowired DeviceAssignedService deviceAssignedService; + @Autowired InstructionService instructionService; + @Autowired StorageCellService storageCellService; - @Override - public void autoInitial() throws Exception { - this.reload(); + @Override + public void autoInitial() throws Exception { + Class var1 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + this.reload(); + } + } + + public synchronized void reload() { + List list = this.queryAll("task_status <2 and is_delete =0 order by create_time"); + + tasks = new CopyOnWriteArrayList<>(list); + } + + @Override + public List queryAll(String whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONArray arr = wo.query(whereJson).getResultJSONArray(0); + List list = arr.toJavaList(TaskDto.class); + return list; + } + + @Override + public Map queryAll(Map whereJson, Pageable page) { + + // WQLObject wo = WQLObject.getWQLObject("acs_task"); + // ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time + // desc"); + HashMap map = new HashMap<>(); + map.put("flag", "1"); + String task_code = (String) whereJson.get("task_code"); + String vehicle_code = (String) whereJson.get("vehicle_code"); + String material_type = (String) whereJson.get("material_type"); + String status = (String) whereJson.get("status"); + String point_code = (String) whereJson.get("point_code"); + String is_over = (String) whereJson.get("is_over"); + if (!StrUtil.isEmpty(task_code)) { + map.put("task_code", task_code); + } + if (!StrUtil.isEmpty(vehicle_code)) { + map.put("vehicle_code", vehicle_code); + } + if (!StrUtil.isEmpty(material_type)) { + map.put("material_type", material_type); + } + if (!StrUtil.isEmpty(status)) { + map.put("status", status); + } + if (!StrUtil.isEmpty(point_code)) { + map.put("point_code", point_code); + } + if (!StrUtil.isEmpty(is_over)) { + map.put("is_over", is_over); + } + final JSONObject jo = + WQL.getWO("QTASK_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), ""); + return jo; + } + + @Override + public Map queryAllByCache(Map whereJson, Pageable page) { + + + + this.reload(); + String task_code = (String) whereJson.get("task_code"); + String vehicle_code = (String) whereJson.get("vehicle_code"); + String material_type = (String) whereJson.get("material_type"); + String status = (String) whereJson.get("status"); + String point_code = (String) whereJson.get("point_code"); + String is_over = (String) whereJson.get("is_over"); + String task_type = (String) whereJson.get("task_type"); + List taskList = new ArrayList(); + + synchronized (TaskServiceImpl.class){ + Iterator it = tasks.iterator(); + while (it.hasNext()) { + TaskDto task = it.next(); + if ("1".equals(is_over) && Integer.valueOf(task.getTask_status()) < 2) { + continue; + } + if (!"1".equals(is_over) && Integer.valueOf(task.getTask_status()) >= 2) { + continue; + } + if (!ObjectUtil.isEmpty(task_code) && !task.getTask_code().contains(task_code)) { + continue; + } + if (!ObjectUtil.isEmpty(status) && !task.getTask_status().equals(status)) { + continue; + } + if (!ObjectUtil.isEmpty(vehicle_code) && !task.getVehicle_code().contains(vehicle_code)) { + continue; + } + if (!ObjectUtil.isEmpty(material_type) && !task.getMaterial().equals(material_type)) { + continue; + } + if (!ObjectUtil.isEmpty(point_code) + && !(task.getStart_point_code().contains(point_code) + || task.getNext_point_code().contains(point_code))) { + continue; + } + if (!ObjectUtil.isEmpty(task_type) && !task.getTask_type().equals(task_type)) { + continue; + } + taskList.add(task); } - public synchronized void reload() { - this.tasks = this.queryAll("task_status <2 and is_delete =0"); + // 按照创建时间排序 + taskList = + taskList.stream() + .sorted( + (task1, task2) -> + DateUtil.compare( + DateUtil.parseDate(task1.getCreate_time()), + DateUtil.parse(task2.getCreate_time()))) + .collect(Collectors.toList()); + } - @Override - public List queryAll(String whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONArray arr = wo.query(whereJson).getResultJSONArray(0); - List list = arr.toJavaList(TaskDto.class); - return list; + Integer currentPageNumber = page.getPageNumber() + 1; + Integer pageMaxSize = page.getPageSize(); + List taskDtoList = + taskList.stream() + .skip((currentPageNumber - 1) * pageMaxSize) + .limit(pageMaxSize) + .collect(Collectors.toList()); + JSONObject jo = new JSONObject(); + jo.put("content", taskDtoList); + jo.put("totalElements", taskList.size()); + return jo; + + } + + @Override + public Map getAll(Map whereJson, Pageable page) { + // WQLObject wo = WQLObject.getWQLObject("acs_task"); + // ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time + // desc"); + HashMap map = new HashMap<>(); + map.put("flag", "2"); + String task_code = (String) whereJson.get("task_code"); + String vehicle_code = (String) whereJson.get("vehicle_code"); + String material_type = (String) whereJson.get("material_type"); + String status = (String) whereJson.get("status"); + String point_code = (String) whereJson.get("point_code"); + String create_time = (String) whereJson.get("createTime"); + String end_time = (String) whereJson.get("end_time"); + if (!StrUtil.isEmpty(task_code)) { + map.put("task_code", task_code); } - - @Override - public Map queryAll(Map whereJson, Pageable page) { - - //WQLObject wo = WQLObject.getWQLObject("acs_task"); - //ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time desc"); - HashMap map = new HashMap<>(); - map.put("flag", "1"); - String task_code = (String) whereJson.get("task_code"); - String vehicle_code = (String) whereJson.get("vehicle_code"); - String material_type = (String) whereJson.get("material_type"); - String status = (String) whereJson.get("status"); - String point_code = (String) whereJson.get("point_code"); - String is_over = (String) whereJson.get("is_over"); - if (!StrUtil.isEmpty(task_code)) { - map.put("task_code", task_code); - } - if (!StrUtil.isEmpty(vehicle_code)) { - map.put("vehicle_code", vehicle_code); - } - if (!StrUtil.isEmpty(material_type)) { - map.put("material_type", material_type); - } - if (!StrUtil.isEmpty(status)) { - map.put("status", status); - } - if (!StrUtil.isEmpty(point_code)) { - map.put("point_code", point_code); - } - if (!StrUtil.isEmpty(is_over)) { - map.put("is_over", is_over); - } - final JSONObject jo = WQL.getWO("QTASK_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), ""); - return jo; + if (!StrUtil.isEmpty(vehicle_code)) { + map.put("vehicle_code", vehicle_code); } + if (!StrUtil.isEmpty(material_type)) { + map.put("material_type", material_type); + } + if (!StrUtil.isEmpty(status)) { + map.put("status", status); + } + if (!StrUtil.isEmpty(point_code)) { + map.put("point_code", point_code); + } + if (!StrUtil.isEmpty(create_time) && !StrUtil.isEmpty(end_time)) { + map.put("create_time", create_time); + map.put("end_time", end_time); + } + JSONObject jsonObject1 = + WQL.getWO("QTASK_QUERY") + .addParamMap(map) + .pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); + JSONArray array = jsonObject1.getJSONArray("content"); + int totalElements = (Integer) jsonObject1.get("totalElements"); + JSONArray arr = new JSONArray(); + for (int i = 0; i < array.size(); i++) { + JSONObject jsonObject = (JSONObject) array.get(i); + jsonObject.put("hasChildren", true); + arr.add(jsonObject); + } + JSONObject jo = new JSONObject(); + jo.put("content", arr); + jo.put("totalElements", totalElements); + return jo; + } - @Override - public Map queryAllByCache(Map whereJson, Pageable page) { - this.reload(); - String task_code = (String) whereJson.get("task_code"); - String vehicle_code = (String) whereJson.get("vehicle_code"); - String material_type = (String) whereJson.get("material_type"); - String status = (String) whereJson.get("status"); - String point_code = (String) whereJson.get("point_code"); - String is_over = (String) whereJson.get("is_over"); - List taskList = new ArrayList(); - for (int i = 0; i < tasks.size(); i++) { - TaskDto task = tasks.get(i); - if ("1".equals(is_over) && Integer.valueOf(task.getTask_status()) < 2) { - continue; - } - if (!"1".equals(is_over) && Integer.valueOf(task.getTask_status()) >= 2) { - continue; - } - if (!ObjectUtil.isEmpty(task_code) && !task.getTask_code().equals(task_code)) { - continue; - } - if (!ObjectUtil.isEmpty(status) && !task.getTask_status().equals(status)) { - continue; - } - if (!ObjectUtil.isEmpty(vehicle_code) && !task.getVehicle_code().equals(vehicle_code)) { - continue; - } - if (!ObjectUtil.isEmpty(material_type) && !task.getMaterial().equals(material_type)) { - continue; - } - if (!ObjectUtil.isEmpty(point_code) && !(task.getStart_point_code().equals(point_code) || task.getNext_point_code().equals(point_code))) { - continue; - } - taskList.add(task); + @Override + public List queryAll(Map whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONArray arr = wo.query().getResultJSONArray(0); + List list = arr.toJavaList(TaskDto.class); + return list; + } + + @Override + public TaskDto findById(String task_id) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = wo.query("task_id ='" + task_id + "'").uniqueResult(0); + final TaskDto obj = json.toJavaObject(TaskDto.class); + return obj; + } + + @Override + public List queryAllUnfinished(Map whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONArray arr = wo.query("task_status < 2 ").getResultJSONArray(0); + List list = arr.toJavaList(TaskDto.class); + return list; + } + + @Override + public TaskDto findByCode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); + final TaskDto obj = json.toJavaObject(TaskDto.class); + return obj; + } + + @Override + public List queryTaskByDeviceCode(String device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getStart_device_code().equals(device_code) + && StrUtil.equals(task.getTask_status(), "0")) { + list.add(task); } + } + return list; + } + + @Override + public List queryTaskByStartDeviceCode(String start_device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if ((task.getStart_device_code().equals(start_device_code) + || task.getStart_device_code2().equals(start_device_code)) + && StrUtil.equals(task.getTask_status(), "0")) { + list.add(task); + } + } + return list; + } + + @Override + public List queryTaskByBackDeviceCode(String back_start_device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if (task.getStart_device_code().equals(back_start_device_code) + && StrUtil.equals(task.getTask_status(), "0")) { + list.add(task); + } + } + return list; + } + + @Override + public List queryTaskByDeviceCodeAndStatus(String device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getStart_device_code().equals(device_code) + && StrUtil.equals(task.getTask_status(), "1")) { + Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); + if (ObjectUtil.isNotEmpty(instruction)) { + list.add(task); + } + } + } + return list; + } + + public List queryTaskByStartAndIntStatus(String head_start_device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if ((task.getStart_device_code().equals(head_start_device_code) + || task.getStart_device_code2().equals(head_start_device_code)) + && StrUtil.equals(task.getTask_status(), "1")) { + Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); + if (ObjectUtil.isNotEmpty(instruction)) { + list.add(task); + } + } + } + return list; + } + + public List queryTaskByNextAndIntStatus(String back_start_device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if ((task.getStart_device_code().equals(back_start_device_code)) + && StrUtil.equals(task.getTask_status(), "1")) { + Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); + if (ObjectUtil.isNotEmpty(instruction)) { + list.add(task); + } + } + } + return list; + } + + @Override + public TaskDto queryTaskByLinkNum(String link_num) { + return null; + } + + @Override + public List queryByStauts(String status) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONArray arr = wo.query("task_status = '" + status + "'").getResultJSONArray(0); + List list = arr.toJavaList(TaskDto.class); + return list; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(TaskDto dto) throws Exception { + dto = foramte(dto); + if (!StrUtil.isEmpty(dto.getVehicle_code())) { + TaskDto vehicle_dto = this.findByContainer(dto.getVehicle_code()); + if (vehicle_dto != null) { + throw new WDKException("已存在该载具号的任务!"); + } + } + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + String task_uuid = dto.getTask_id(); + if (StrUtil.isEmpty(task_uuid)) { + dto.setTask_id(IdUtil.simpleUUID()); + } + String task_code = dto.getTask_code(); + if (StrUtil.isEmpty(task_code)) { + task_code = CodeUtil.getNewCode("TASK_NO"); + task_code = "-" + task_code; + } + String start_point_code = dto.getStart_point_code(); + String next_point_code = dto.getNext_point_code(); + String start_device_code = dto.getStart_device_code(); + String next_device_code = dto.getNext_device_code(); + String route_plan_code = dto.getRoute_plan_code(); + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + dto.setTask_code(task_code); + dto.setRoute_plan_code(route_plan_code); + dto.setTask_status("0"); + dto.setStart_device_code2(dto.getStart_point_code2()); + dto.setNext_device_code2(dto.getNext_point_code2()); + + if (StrUtil.isEmpty(dto.getPriority())) { + dto.setPriority("1"); + } + String plan_code = dto.getRoute_plan_code(); + // 判断起点终点设备类型 + String startDeviceType = deviceAppService.findDeviceTypeByCode(dto.getStart_device_code()); + String nextDeviceType = deviceAppService.findDeviceTypeByCode(dto.getNext_device_code()); + if (routelineserver + .getShortPathLines(dto.getStart_device_code(), dto.getNext_device_code(), plan_code) + .size() + == 0) { + throw new Exception(dto.getStart_point_code() + "->" + dto.getNext_point_code() + "路由不通!"); + } + String createTaskCheck = paramService.findByCode(AcsConfig.CREATETASKCHECK).getValue(); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device nextdevice = appService.findDeviceByCode(next_device_code); + Device startdevice = appService.findDeviceByCode(start_device_code); + dto.setMaterial(startdevice.getMaterial_type()); + if (StrUtil.equals(createTaskCheck, "1")) { + // 判断起点为输送设备 + if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) {} + + if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) {} + } else { + // 判断起点为输送设备 + if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) {} + + if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) { + // if (nextdevice.getDeviceDriver() instanceof + // StandardOrdinarySiteDeviceDriver) { + // standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) + // nextdevice.getDeviceDriver(); + // if (nextdevice.getHas_goods() != 0) { + // throw new Exception("任务终点需满足无货!"); + // } + // } + JSONObject jo = new JSONObject(); - jo.put("content", taskList); - jo.put("totalElements", taskList.size()); - return jo; - } + JSONObject jo2 = new JSONObject(); + if (!StrUtil.isEmpty(dto.getMaterial())) { + if (!StrUtil.equals(dto.getMaterial(), "1")) { + jo.put("hasGoodStatus", "2"); + jo.put("material_type", dto.getMaterial()); + } else { + jo.put("hasGoodStatus", "1"); + jo.put("material_type", "1"); + } - @Override - public Map getAll(Map whereJson, Pageable page) { - //WQLObject wo = WQLObject.getWQLObject("acs_task"); - //ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time desc"); - HashMap map = new HashMap<>(); - map.put("flag", "2"); - String task_code = (String) whereJson.get("task_code"); - String vehicle_code = (String) whereJson.get("vehicle_code"); - String material_type = (String) whereJson.get("material_type"); - String status = (String) whereJson.get("status"); - String point_code = (String) whereJson.get("point_code"); - String create_time = (String) whereJson.get("createTime"); - String end_time = (String) whereJson.get("end_time"); - if (!StrUtil.isEmpty(task_code)) { - map.put("task_code", task_code); - } - if (!StrUtil.isEmpty(vehicle_code)) { - map.put("vehicle_code", vehicle_code); - } - if (!StrUtil.isEmpty(material_type)) { - map.put("material_type", material_type); - } - if (!StrUtil.isEmpty(status)) { - map.put("status", status); - } - if (!StrUtil.isEmpty(point_code)) { - map.put("point_code", point_code); - } - if (!StrUtil.isEmpty(create_time) && !StrUtil.isEmpty(end_time)) { - map.put("create_time", create_time); - map.put("end_time", end_time); - } - JSONObject jsonObject1 = WQL.getWO("QTASK_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); - JSONArray array = jsonObject1.getJSONArray("content"); - int totalElements = (Integer) jsonObject1.get("totalElements"); - JSONArray arr = new JSONArray(); - for (int i = 0; i < array.size(); i++) { - JSONObject jsonObject = (JSONObject) array.get(i); - jsonObject.put("hasChildren", true); - arr.add(jsonObject); - } - JSONObject jo = new JSONObject(); - jo.put("content", arr); - jo.put("totalElements", totalElements); - return jo; - } - - @Override - public List queryAll(Map whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONArray arr = wo.query().getResultJSONArray(0); - List list = arr.toJavaList(TaskDto.class); - return list; - } - - @Override - public TaskDto findById(String task_id) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = wo.query("task_id ='" + task_id + "'").uniqueResult(0); - final TaskDto obj = json.toJavaObject(TaskDto.class); - return obj; - } - - @Override - public List queryAllUnfinished(Map whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONArray arr = wo.query("task_status < 2 ").getResultJSONArray(0); - List list = arr.toJavaList(TaskDto.class); - return list; - } - - @Override - public TaskDto findByCode(String code) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); - final TaskDto obj = json.toJavaObject(TaskDto.class); - return obj; - } - - @Override - public List queryTaskByDeviceCode(String device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getStart_device_code().equals(device_code) && StrUtil.equals(task.getTask_status(), "0")) { - list.add(task); - } - } - return list; - } - - @Override - public List queryTaskByStartDeviceCode(String start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if ((task.getStart_device_code().equals(start_device_code) || task.getStart_device_code2().equals(start_device_code)) && StrUtil.equals(task.getTask_status(), "0")) { - list.add(task); - } - } - return list; - } - - @Override - public List queryTaskByBackDeviceCode(String back_start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if (task.getStart_device_code().equals(back_start_device_code) && StrUtil.equals(task.getTask_status(), "0")) { - list.add(task); - } - } - return list; - } - - @Override - public List queryTaskByDeviceCodeAndStatus(String device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getStart_device_code().equals(device_code) && StrUtil.equals(task.getTask_status(), "1")) { - Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); - if (ObjectUtil.isNotEmpty(instruction)) { - list.add(task); - } - } - } - return list; - } - - - public List queryTaskByStartAndIntStatus(String head_start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if ((task.getStart_device_code().equals(head_start_device_code) || task.getStart_device_code2().equals(head_start_device_code)) && StrUtil.equals(task.getTask_status(), "1")) { - Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); - if (ObjectUtil.isNotEmpty(instruction)) { - list.add(task); - } - } - } - return list; - } - - public List queryTaskByNextAndIntStatus(String back_start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if ((task.getStart_device_code().equals(back_start_device_code)) && StrUtil.equals(task.getTask_status(), "1")) { - Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); - if (ObjectUtil.isNotEmpty(instruction)) { - list.add(task); - } - } - } - return list; - } - - @Override - public TaskDto queryTaskByLinkNum(String link_num) { - return null; - } - - @Override - public List queryByStauts(String status) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONArray arr = wo.query("task_status = '" + status + "'").getResultJSONArray(0); - List list = arr.toJavaList(TaskDto.class); - return list; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void create(TaskDto dto) throws Exception { - dto = foramte(dto); - if (!StrUtil.isEmpty(dto.getVehicle_code())) { - TaskDto vehicle_dto = this.findByContainer(dto.getVehicle_code()); - if (vehicle_dto != null) { - throw new WDKException("已存在该载具号的任务!"); - } - } - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - String task_uuid = dto.getTask_id(); - if (StrUtil.isEmpty(task_uuid)) { - dto.setTask_id(IdUtil.simpleUUID()); - } - String task_code = dto.getTask_code(); - if (StrUtil.isEmpty(task_code)) { - task_code = CodeUtil.getNewCode("TASK_NO"); - task_code = "-" + task_code; - } - String start_point_code = dto.getStart_point_code(); - String next_point_code = dto.getNext_point_code(); - String start_device_code = dto.getStart_device_code(); - String next_device_code = dto.getNext_device_code(); - String route_plan_code = dto.getRoute_plan_code(); - dto.setCreate_by(currentUsername); - dto.setUpdate_by(currentUsername); - dto.setUpdate_time(now); - dto.setCreate_time(now); - dto.setTask_code(task_code); - dto.setRoute_plan_code(route_plan_code); - dto.setTask_status("0"); - dto.setStart_device_code2(dto.getStart_point_code2()); - dto.setNext_device_code2(dto.getNext_point_code2()); - - if (StrUtil.isEmpty(dto.getPriority())) { - dto.setPriority("1"); - } - String plan_code = dto.getRoute_plan_code(); - //判断起点终点设备类型 - String startDeviceType = deviceAppService.findDeviceTypeByCode(dto.getStart_device_code()); - String nextDeviceType = deviceAppService.findDeviceTypeByCode(dto.getNext_device_code()); - if (routelineserver.getShortPathLines(dto.getStart_device_code(), dto.getNext_device_code(), plan_code).size() == 0) { - throw new Exception(dto.getStart_point_code() + "->" + dto.getNext_point_code() + "路由不通!"); - } - String createTaskCheck = paramService.findByCode(AcsConfig.CREATETASKCHECK).getValue(); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device nextdevice = appService.findDeviceByCode(next_device_code); - Device startdevice = appService.findDeviceByCode(start_device_code); - dto.setMaterial(startdevice.getMaterial_type()); - if (StrUtil.equals(createTaskCheck, "1")) { - //判断起点为输送设备 - if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) { - - } - if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) { - } } else { - //判断起点为输送设备 - if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) { - - } - - if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) { -// if (nextdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { -// standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) nextdevice.getDeviceDriver(); -// if (nextdevice.getHas_goods() != 0) { -// throw new Exception("任务终点需满足无货!"); -// } -// } - - JSONObject jo = new JSONObject(); - JSONObject jo2 = new JSONObject(); - if (!StrUtil.isEmpty(dto.getMaterial())) { - if (!StrUtil.equals(dto.getMaterial(), "1")) { - jo.put("hasGoodStatus", "2"); - jo.put("material_type", dto.getMaterial()); - } else { - jo.put("hasGoodStatus", "1"); - jo.put("material_type", "1"); - } - - } else { - jo.put("hasGoodStatus", "1"); - jo.put("material_type", "1"); - } - jo.put("device_code", dto.getStart_device_code()); - jo.put("quantity", dto.getQuantity()); - jo.put("remark", dto.getRemark()); - jo.put("batch", startdevice.getBatch()); - jo.put("islock", "true"); - deviceService.changeDeviceStatus(jo); - Device deviceByCode = deviceAppService.findDeviceByCode(dto.getNext_device_code()); - jo2.put("device_code", dto.getNext_device_code()); - jo2.put("hasGoodStatus", deviceByCode.getHas_goods()); - jo2.put("quantity", deviceByCode.getQuantity()); - jo2.put("remark", deviceByCode.getRemark()); - jo2.put("material_type", deviceByCode.getMaterial_type()); - jo2.put("batch", deviceByCode.getBatch()); - jo2.put("islock", "true"); - deviceService.changeDeviceStatus(jo2); - } + jo.put("hasGoodStatus", "1"); + jo.put("material_type", "1"); } - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); + jo.put("device_code", dto.getStart_device_code()); + jo.put("quantity", dto.getQuantity()); + jo.put("remark", dto.getRemark()); + jo.put("batch", startdevice.getBatch()); + jo.put("islock", "true"); + deviceService.changeDeviceStatus(jo); + Device deviceByCode = deviceAppService.findDeviceByCode(dto.getNext_device_code()); + jo2.put("device_code", dto.getNext_device_code()); + jo2.put("hasGoodStatus", deviceByCode.getHas_goods()); + jo2.put("quantity", deviceByCode.getQuantity()); + jo2.put("remark", deviceByCode.getRemark()); + jo2.put("material_type", deviceByCode.getMaterial_type()); + jo2.put("batch", deviceByCode.getBatch()); + jo2.put("islock", "true"); + deviceService.changeDeviceStatus(jo2); + } + } + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); - wo.insert(json); + wo.insert(json); + synchronized(TaskServiceImpl.class){ + System.out.println("-------------------"+dto.getTask_code()); + System.out.println("-------------1"+tasks.size()); + + tasks.add(dto); + System.out.println("-------------2"+tasks.size()); + + } + } + + /** + * 常规任务保存 + * + * @param / + * @throws Exception + */ + @Override + public void ordinaryTaskCreate(JSONObject json) throws Exception { + JSONArray array = json.getJSONArray("data"); + + if (array.size() == 0) { + throw new RuntimeException("请选择起点"); + } + for (int i = 0; i < array.size(); i++) { + JSONObject arrjo = array.getJSONObject(i); + String material_type = arrjo.getString("material_type"); + String quantity = arrjo.getString("quantity"); + String remark = arrjo.getString("remark"); + TaskDto dto = new TaskDto(); + Map whereJson = (Map) array.get(i); + + // String device_code = (String) whereJson.get("device_code"); + String device_code = MapUtil.getStr(whereJson, "device_code"); + dto.setRoute_plan_code("one"); + String next_device_code = ""; + String plan_uuid = + WQLObject.getWQLObject("acs_route_plan") + .query("plan_code= '" + dto.getRoute_plan_code() + "'") + .uniqueResult(0) + .getString("plan_uuid"); + JSONArray ja = routelineserver.queryNextLine(device_code, plan_uuid); + for (int j = 0; j < ja.size(); j++) { + JSONObject jo = (JSONObject) ja.get(j); + next_device_code = jo.get("next_device_code").toString(); + } + if (ObjectUtil.isNotEmpty(this.findByStartCode(device_code))) { + throw new WDKException("已存在该起点的任务!"); + } + if (StrUtil.equals(material_type, "") || StrUtil.equals(quantity, "")) { + throw new RuntimeException("请填写物料信息!"); + } + dto.setStart_device_code(device_code); + dto.setStart_point_code(device_code); + dto.setNext_device_code(next_device_code); + dto.setNext_point_code(next_device_code); + dto.setRemark(remark); + dto.setMaterial(material_type); + create(dto); + } + } + + /** + * 特殊任务保存 + * + * @param / + * @throws Exception + */ + @Override + public void specialTaskCreate(JSONObject json) throws Exception { + + JSONArray array = json.getJSONArray("data1"); + JSONArray array2 = json.getJSONArray("data2"); + JSONArray array3 = json.getJSONArray("data3"); + if (array.size() != 0 && array3.size() != 0) { + throw new RuntimeException("只能选择一个终点"); + } + + for (int i = 0; i < array2.size(); i++) { + JSONObject arrjo = array2.getJSONObject(i); + String material_type = arrjo.getString("material_type"); + String quantity = arrjo.getString("quantity"); + String remark = arrjo.getString("remark"); + TaskDto dto = new TaskDto(); + Map whereJson; + Map whereJson2; + Map whereJson3; + if (array.size() != 0) { + whereJson = (Map) array.get(i); + } else { + whereJson = null; + } + if (array2.size() != 0) { + whereJson2 = (Map) array2.get(i); + } else { + whereJson2 = null; + } + if (array3.size() != 0) { + whereJson3 = (Map) array3.get(i); + } else { + whereJson3 = null; + } + String start_device_code = MapUtil.getStr(whereJson2, "device_code"); + String next_device_code = ""; + if (ObjectUtil.isEmpty(whereJson)) { + next_device_code = MapUtil.getStr(whereJson3, "device_code"); + } else { + next_device_code = MapUtil.getStr(whereJson, "device_code"); + } + + if (ObjectUtil.isNotEmpty(this.findByStartCode(start_device_code)) + || ObjectUtil.isNotEmpty(this.findByNextCode(next_device_code))) { + throw new WDKException("已存在该起点或终点的任务!"); + } + if (StrUtil.equals(material_type, "") || StrUtil.equals(quantity, "")) { + throw new RuntimeException("请填写物料信息!"); + } + dto.setRoute_plan_code("two"); + dto.setStart_device_code(start_device_code); + dto.setStart_point_code(start_device_code); + dto.setNext_device_code(next_device_code); + dto.setNext_point_code(next_device_code); + dto.setRemark(remark); + dto.setMaterial(material_type); + create(dto); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(TaskDto dto) { + + TaskDto entity = this.findById(dto.getTask_id()); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.update(json); + + Iterator iterator = tasks.iterator(); +// while (iterator.hasNext()) { +// TaskDto task = iterator.next(); +// if (task.getTask_code().equals(dto.getTask_code())) { +// iterator.remove(); +// } +// } + + + removeByCodeFromCache(entity.getTask_code()); + + if (StrUtil.equals(dto.getTask_status(), "0") || StrUtil.equals(dto.getTask_status(), "1")) { tasks.add(dto); - } - - /** - * 常规任务保存 - * - * @param / - * @throws Exception - */ - @Override - public void ordinaryTaskCreate(JSONObject json) throws Exception { - JSONArray array = json.getJSONArray("data"); - - if (array.size() == 0) { - throw new RuntimeException("请选择起点"); - } - for (int i = 0; i < array.size(); i++) { - JSONObject arrjo = array.getJSONObject(i); - String material_type = arrjo.getString("material_type"); - String quantity = arrjo.getString("quantity"); - String remark = arrjo.getString("remark"); - TaskDto dto = new TaskDto(); - Map whereJson = (Map) array.get(i); - - //String device_code = (String) whereJson.get("device_code"); - String device_code = MapUtil.getStr(whereJson, "device_code"); - dto.setRoute_plan_code("one"); - String next_device_code = ""; - String plan_uuid = WQLObject.getWQLObject("acs_route_plan").query("plan_code= '" + dto.getRoute_plan_code() + "'").uniqueResult(0).getString("plan_uuid"); - JSONArray ja = routelineserver.queryNextLine(device_code, plan_uuid); - for (int j = 0; j < ja.size(); j++) { - JSONObject jo = (JSONObject) ja.get(j); - next_device_code = jo.get("next_device_code").toString(); - } - if (ObjectUtil.isNotEmpty(this.findByStartCode(device_code))) { - throw new WDKException("已存在该起点的任务!"); - } - if (StrUtil.equals(material_type, "") || StrUtil.equals(quantity, "")) { - throw new RuntimeException("请填写物料信息!"); - } - dto.setStart_device_code(device_code); - dto.setStart_point_code(device_code); - dto.setNext_device_code(next_device_code); - dto.setNext_point_code(next_device_code); - dto.setRemark(remark); - dto.setMaterial(material_type); - create(dto); - } - } - - /** - * 特殊任务保存 - * - * @param / - * @throws Exception - */ - @Override - public void specialTaskCreate(JSONObject json) throws Exception { - - JSONArray array = json.getJSONArray("data1"); - JSONArray array2 = json.getJSONArray("data2"); - JSONArray array3 = json.getJSONArray("data3"); - if (array.size() != 0 && array3.size() != 0) { - throw new RuntimeException("只能选择一个终点"); - } - - for (int i = 0; i < array2.size(); i++) { - JSONObject arrjo = array2.getJSONObject(i); - String material_type = arrjo.getString("material_type"); - String quantity = arrjo.getString("quantity"); - String remark = arrjo.getString("remark"); - TaskDto dto = new TaskDto(); - Map whereJson; - Map whereJson2; - Map whereJson3; - if (array.size() != 0) { - whereJson = (Map) array.get(i); - } else { - whereJson = null; - } - if (array2.size() != 0) { - whereJson2 = (Map) array2.get(i); - } else { - whereJson2 = null; - } - if (array3.size() != 0) { - whereJson3 = (Map) array3.get(i); - } else { - whereJson3 = null; - } - String start_device_code = MapUtil.getStr(whereJson2, "device_code"); - String next_device_code = ""; - if (ObjectUtil.isEmpty(whereJson)) { - next_device_code = MapUtil.getStr(whereJson3, "device_code"); - } else { - next_device_code = MapUtil.getStr(whereJson, "device_code"); - } - - if (ObjectUtil.isNotEmpty(this.findByStartCode(start_device_code)) - || ObjectUtil.isNotEmpty(this.findByNextCode(next_device_code))) { - throw new WDKException("已存在该起点或终点的任务!"); - } - if (StrUtil.equals(material_type, "") || StrUtil.equals(quantity, "")) { - throw new RuntimeException("请填写物料信息!"); - } - dto.setRoute_plan_code("two"); - dto.setStart_device_code(start_device_code); - dto.setStart_point_code(start_device_code); - dto.setNext_device_code(next_device_code); - dto.setNext_point_code(next_device_code); - dto.setRemark(remark); - dto.setMaterial(material_type); - create(dto); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(TaskDto dto) { - TaskDto entity = this.findById(dto.getTask_id()); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - dto.setUpdate_time(now); - dto.setUpdate_by(currentUsername); - - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.update(json); - - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(dto.getTask_code())) { - iterator.remove(); - } - } - if (StrUtil.equals(dto.getTask_status(), "0") || StrUtil.equals(dto.getTask_status(), "1")) { - tasks.add(dto); - } - //判断是否为WMS下发的任务,如果是反馈任务状态给WMS - String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); - if (!StrUtil.startWith(dto.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { - TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); - JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_id", entity.getExt_task_id()); - feed_jo.put("task_code", dto.getTask_code()); - feed_jo.put("task_status", dto.getTask_status()); - JSONArray ja = new JSONArray(); - ja.add(feed_jo); - String message = null; - HttpResponse body = null; - boolean flag = false; - try { - body = acstowmsService.feedbackTaskStatusToWms(ja); - } catch (Exception e) { - flag = true; - message = e.getMessage(); - e.printStackTrace(); - } finally { - - } - if (flag) { - if (ObjectUtil.isEmpty(feefbackdto)) { - feefbackdto = new TaskFeedbackDto(); - feefbackdto.setTask_id(entity.getTask_id()); - feefbackdto.setTask_code(entity.getTask_code()); - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setVehicle_type(entity.getVehicle_type()); - feefbackdto.setVehicle_code(entity.getVehicle_code()); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getStart_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - feefbackdto.setError_code("400"); - feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(message); - taskFeedbackService.create(feefbackdto); - } else { - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getStart_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - feefbackdto.setError_code("400"); - feefbackdto.setRemark(message); - taskFeedbackService.update(feefbackdto); - } - } else { - int status = body.getStatus(); - JSONObject jo = JSONObject.parseObject(body.body()); - if (ObjectUtil.isEmpty(feefbackdto)) { - feefbackdto = new TaskFeedbackDto(); - feefbackdto.setTask_id(entity.getTask_id()); - feefbackdto.setTask_code(entity.getTask_code()); - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setVehicle_type(entity.getVehicle_type()); - feefbackdto.setVehicle_code(entity.getVehicle_code()); - feefbackdto.setError_code(String.valueOf(body.getStatus())); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getNext_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - if (status == 200) { - if (StrUtil.equals(entity.getTask_status(), "2")) { - feefbackdto.setIs_finished("1"); - } else { - feefbackdto.setIs_finished("0"); - } - } else { - feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(jo.getString("message")); - } - taskFeedbackService.create(feefbackdto); - } else { - feefbackdto.setTask_status(entity.getTask_status()); - if (status == 200) { - } else { - if (StrUtil.equals(entity.getTask_status(), "2")) { - feefbackdto.setIs_finished("1"); - } else { - feefbackdto.setIs_finished("0"); - } - } - taskFeedbackService.update(feefbackdto); - } - } + } + // 判断是否为WMS下发的任务,如果是反馈任务状态给WMS + String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); + if (!StrUtil.startWith(dto.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { + TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); + JSONObject feed_jo = new JSONObject(); + feed_jo.put("task_id", entity.getExt_task_id()); + feed_jo.put("task_code", dto.getTask_code()); + feed_jo.put("task_status", dto.getTask_status()); + JSONArray ja = new JSONArray(); + ja.add(feed_jo); + String message = null; + HttpResponse body = null; + boolean flag = false; + try { + body = acstowmsService.feedbackTaskStatusToWms(ja); + } catch (Exception e) { + flag = true; + message = e.getMessage(); + e.printStackTrace(); + } finally { } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteAll(String[] ids) throws Exception { - for (String task_id : ids) { - this.cancel(task_id); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void finish(String id) { - TaskDto entity = this.findById(id); - if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); - InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); - InstructionDto instdto = instructionservice.findByTaskid(id, "instruction_status <2 "); - if (instdto != null) throw new BadRequestException("有指令未完成!"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setTask_status("2"); - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - removeByCodeFromCache(entity.getTask_code()); - //判断是否为WMS下发的任务,如果是反馈任务状态给WMS - String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); - if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { - TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); - JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_id", entity.getTask_id()); - feed_jo.put("task_code", entity.getTask_code()); - feed_jo.put("task_status", entity.getTask_status()); - JSONArray ja = new JSONArray(); - ja.add(feed_jo); - String message = null; - HttpResponse body = null; - boolean flag = false; - try { - body = acstowmsService.feedbackTaskStatusToWms(ja); - } catch (Exception e) { - flag = true; - message = e.getMessage(); - e.printStackTrace(); - } finally { - - } - if (flag) { - if (ObjectUtil.isEmpty(feefbackdto)) { - feefbackdto = new TaskFeedbackDto(); - feefbackdto.setTask_id(entity.getTask_id()); - feefbackdto.setTask_code(entity.getTask_code()); - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setVehicle_type(entity.getVehicle_type()); - feefbackdto.setVehicle_code(entity.getVehicle_code()); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getStart_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - feefbackdto.setError_code("400"); - feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(message); - taskFeedbackService.create(feefbackdto); - } else { - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getStart_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - feefbackdto.setError_code("400"); - feefbackdto.setRemark(message); - taskFeedbackService.update(feefbackdto); - } - } else { - int status = body.getStatus(); - JSONObject jo = JSONObject.parseObject(body.body()); - if (ObjectUtil.isEmpty(feefbackdto)) { - feefbackdto = new TaskFeedbackDto(); - feefbackdto.setTask_id(entity.getTask_id()); - feefbackdto.setTask_code(entity.getTask_code()); - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setVehicle_type(entity.getVehicle_type()); - feefbackdto.setVehicle_code(entity.getVehicle_code()); - feefbackdto.setError_code(String.valueOf(body.getStatus())); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getNext_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - if (status == 200) { - if (StrUtil.equals(entity.getTask_status(), "2")) { - feefbackdto.setIs_finished("1"); - } else { - feefbackdto.setIs_finished("0"); - } - } else { - feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(jo.getString("message")); - } - taskFeedbackService.create(feefbackdto); - } else { - feefbackdto.setTask_status(entity.getTask_status()); - if (status == 200) { - if (StrUtil.equals(entity.getTask_status(), "2")) { - feefbackdto.setIs_finished("1"); - } else { - feefbackdto.setIs_finished("0"); - } - } else { - feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(jo.getString("message")); - } - taskFeedbackService.update(feefbackdto); - } - } - - } - //如果属于先知AGV,关闭运单序列 - if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) { - try { - agvService.markComplete(entity.getTask_code()); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void cancel(String id) throws Exception { - TaskDto entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); - InstructionDto instdto = instructionservice.findByTaskid(id, "instruction_status <2 "); - if (instdto != null) { - throw new BadRequestException("有指令未完成!"); - } - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setTask_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - //清理缓存 - for (int i = 0; i < tasks.size(); i++) { - TaskDto taskDto = tasks.get(i); - if (taskDto.getTask_id().equals(id)) { - tasks.remove(i); - } - } - //判断是否为WMS下发的任务,如果是反馈任务状态给WMS - String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); - if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { - JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_id", entity.getTask_id()); - feed_jo.put("task_code", entity.getTask_code()); - feed_jo.put("task_status", entity.getTask_status()); - JSONArray ja = new JSONArray(); - ja.add(feed_jo); - acstowmsService.feedbackTaskStatusToWms(ja); - } - List shortPathsList = routeLineService.getShortPathLines(entity.getStart_device_code(), entity.getNext_device_code(), entity.getRoute_plan_code()); - String type = shortPathsList.get(0).getType(); - // != 0 为agv任务 - if (!StrUtil.equals(type, "0")) { - if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) { - agvService.markComplete(entity.getTask_code()); - } - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void createInst(String ids) throws Exception { - TaskDto acsTask = this.findById(ids); - if (acsTask == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); - InstructionDto inst = instructionservice.findByTaskid(ids, "instruction_status < 2 "); - if (inst != null) { - throw new BadRequestException("有指令未完成!"); - } - - String taskid = acsTask.getTask_id(); - String taskcode = acsTask.getTask_code(); - String vehiclecode = acsTask.getVehicle_code(); - String priority = acsTask.getPriority(); - String start_point_code = acsTask.getStart_point_code(); - String start_device_code = acsTask.getStart_device_code(); - String route_plan_code = acsTask.getRoute_plan_code(); - String vehicleType = acsTask.getVehicle_type(); - //是否复合任务 =0非复合任务 - String compound_task = acsTask.getCompound_task(); - String next_point_code = acsTask.getNext_point_code(); - String next_device_code = acsTask.getNext_device_code(); - String start_point_code2 = acsTask.getStart_point_code2(); - String next_point_code2 = acsTask.getNext_point_code2(); - String agv_system_type = acsTask.getAgv_system_type(); - String task_type = acsTask.getTask_type(); - /** - * 开始平均分解校验 - */ - String this_device_code = this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); - if (StrUtil.isEmpty(this_device_code)) { - List shortPathsList = routeLineService.getShortPathLines(start_device_code, acsTask.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); + if (flag) { + if (ObjectUtil.isEmpty(feefbackdto)) { + feefbackdto = new TaskFeedbackDto(); + feefbackdto.setTask_id(entity.getTask_id()); + feefbackdto.setTask_code(entity.getTask_code()); + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setVehicle_type(entity.getVehicle_type()); + feefbackdto.setVehicle_code(entity.getVehicle_code()); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getStart_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + feefbackdto.setError_code("400"); + feefbackdto.setIs_finished("0"); + feefbackdto.setRemark(message); + taskFeedbackService.create(feefbackdto); + } else { + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getStart_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + feefbackdto.setError_code("400"); + feefbackdto.setRemark(message); + taskFeedbackService.update(feefbackdto); + } } else { - next_device_code = this_device_code; + int status = body.getStatus(); + JSONObject jo = JSONObject.parseObject(body.body()); + if (ObjectUtil.isEmpty(feefbackdto)) { + feefbackdto = new TaskFeedbackDto(); + feefbackdto.setTask_id(entity.getTask_id()); + feefbackdto.setTask_code(entity.getTask_code()); + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setVehicle_type(entity.getVehicle_type()); + feefbackdto.setVehicle_code(entity.getVehicle_code()); + feefbackdto.setError_code(String.valueOf(body.getStatus())); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getNext_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + if (status == 200) { + if (StrUtil.equals(entity.getTask_status(), "2")) { + feefbackdto.setIs_finished("1"); + } else { + feefbackdto.setIs_finished("0"); + } + } else { + feefbackdto.setIs_finished("0"); + feefbackdto.setRemark(jo.getString("message")); + } + taskFeedbackService.create(feefbackdto); + } else { + feefbackdto.setTask_status(entity.getTask_status()); + if (status == 200) { + } else { + if (StrUtil.equals(entity.getTask_status(), "2")) { + feefbackdto.setIs_finished("1"); + } else { + feefbackdto.setIs_finished("0"); + } + } + taskFeedbackService.update(feefbackdto); + } } + } - if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { - next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAll(String[] ids) throws Exception { + for (String task_id : ids) { + this.cancel(task_id); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void finish(String id) { + TaskDto entity = this.findById(id); + if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); + InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); + InstructionDto instdto = instructionservice.findByTaskid(id, "instruction_status <2 "); + if (instdto != null) throw new BadRequestException("有指令未完成!"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setTask_status("2"); + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + removeByCodeFromCache(entity.getTask_code()); + // 判断是否为WMS下发的任务,如果是反馈任务状态给WMS + String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); + if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { + TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); + System.out.println(feefbackdto == null); + JSONObject feed_jo = new JSONObject(); + feed_jo.put("task_id", entity.getTask_id()); + feed_jo.put("task_code", entity.getTask_code()); + feed_jo.put("task_status", entity.getTask_status()); + JSONArray ja = new JSONArray(); + ja.add(feed_jo); + String message = null; + HttpResponse body = null; + boolean flag = false; + try { + body = acstowmsService.feedbackTaskStatusToWms(ja); + } catch (Exception e) { + flag = true; + message = e.getMessage(); + e.printStackTrace(); + } finally { + + } + if (flag) { + if (ObjectUtil.isEmpty(feefbackdto)) { + feefbackdto = new TaskFeedbackDto(); + feefbackdto.setTask_id(entity.getTask_id()); + feefbackdto.setTask_code(entity.getTask_code()); + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setVehicle_type(entity.getVehicle_type()); + feefbackdto.setVehicle_code(entity.getVehicle_code()); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getStart_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + feefbackdto.setError_code("400"); + feefbackdto.setIs_finished("0"); + feefbackdto.setRemark(message); + taskFeedbackService.create(feefbackdto); } else { - next_point_code = next_device_code; + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getStart_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + feefbackdto.setError_code("400"); + feefbackdto.setRemark(message); + taskFeedbackService.update(feefbackdto); } - - Instruction instdto = new Instruction(); - instdto.setInstruction_type(task_type); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(acsTask.getRemark()); - instdto.setMaterial(acsTask.getMaterial()); - instdto.setQuantity(acsTask.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); - instdto.setVehicle_type(vehicleType); - instdto.setStart_point_code2(start_point_code2); - instdto.setStart_device_code2(start_point_code2); - instdto.setNext_device_code2(next_point_code2); - instdto.setNext_point_code2(next_point_code2); - instdto.setAgv_system_type(agv_system_type); - //判断agv系统 - //1、1楼叉车系统 - //2、2楼1区域AGV系统 - //3、2楼2区域AGV系统 - if (!StrUtil.equals(agv_system_type, "1")) { - // task_type - //1、生箔; Itype=1:取空,取满,放空,放满; - //2、分切 Itype=3取满、取空、放满、放空; - //3、普通任务 Itype=2:取货、放货; - //4、叉车任务 - //5、输送任务 - //6、行架 - //7、立库 - if (StrUtil.equals(task_type, "1")) { - instdto.setAgv_inst_type("1"); - } else if (StrUtil.equals(task_type, "3")) { - instdto.setAgv_inst_type("2"); - } else if (StrUtil.equals(task_type, "2")) { - instdto.setAgv_inst_type("3"); + } else { + int status = body.getStatus(); + JSONObject jo = JSONObject.parseObject(body.body()); + if (ObjectUtil.isEmpty(feefbackdto)) { + feefbackdto = new TaskFeedbackDto(); + feefbackdto.setTask_id(entity.getTask_id()); + feefbackdto.setTask_code(entity.getTask_code()); + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setVehicle_type(entity.getVehicle_type()); + feefbackdto.setVehicle_code(entity.getVehicle_code()); + feefbackdto.setError_code(String.valueOf(body.getStatus())); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getNext_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + if (status == 200) { + if (StrUtil.equals(entity.getTask_status(), "2")) { + feefbackdto.setIs_finished("1"); + } else { + feefbackdto.setIs_finished("0"); } + } else { + feefbackdto.setIs_finished("0"); + feefbackdto.setRemark(jo.getString("message")); + } + taskFeedbackService.create(feefbackdto); } else { - instdto.setAgv_inst_type("4"); - } - instructionservice.create(instdto); - - acsTask.setTask_status("1"); - this.update(acsTask); - } - - @Override - public void download(List all, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (TaskDto acsTask : all) { - Map map = new LinkedHashMap<>(); - map.put("任务号", acsTask.getTask_code()); - map.put("载具号", acsTask.getVehicle_code()); - map.put("载具类型", acsTask.getVehicle_type()); - map.put("任务类型", acsTask.getTask_type()); - map.put("任务状态", acsTask.getTask_status()); - map.put("任务优先级", acsTask.getPriority()); - map.put("创建类型", acsTask.getCreate_type()); - map.put("完成类型", acsTask.getFinish_type()); - map.put("执行描述编码", acsTask.getExecute_code()); - map.put("执行描述信息", acsTask.getExecute_message()); - map.put("起始点位编码", acsTask.getStart_point_code()); - map.put("起始设备编码", acsTask.getStart_device_code()); - map.put("目标点位编码", acsTask.getNext_point_code()); - map.put("目标设备编码", acsTask.getNext_device_code()); - map.put("排", acsTask.getFrom_x()); - map.put("列", acsTask.getFrom_y()); - map.put("层", acsTask.getFrom_z()); - map.put("排", acsTask.getTo_x()); - map.put("列", acsTask.getTo_y()); - map.put("层", acsTask.getTo_z()); - map.put("路由方案名称", acsTask.getRoute_plan_name()); - map.put("路由方案编码", acsTask.getRoute_plan_code()); - map.put("是否需要反馈上位系统", acsTask.getIs_needfeedback()); - map.put("备注", acsTask.getRemark()); - map.put("是否启用", acsTask.getIs_active()); - map.put("是否删除", acsTask.getIs_delete()); - map.put("创建者", acsTask.getCreate_by()); - map.put("创建时间", acsTask.getCreate_time()); - map.put("修改者", acsTask.getUpdate_by()); - map.put("修改时间", acsTask.getUpdate_time()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } - - @Override - public void createTaskByClick(JSONObject json) { - - } - - @Override - public int checkAllowCreate(String devicecode) { - Map map = new HashMap(); - List taskList = this.queryAllUnfinished(map); - int num = 0; - for (int i = 0; i < taskList.size(); i++) { - TaskDto onetask = taskList.get(i); - String next_code = onetask.getNext_point_code(); - if (StrUtil.equals(devicecode, next_code)) { - num = num + 1; - } - } - return num; - } - - @Override - public boolean removeByCodeFromCache(String code) { - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(code)) { - iterator.remove(); - return true; - } - } - return false; - } - - @Override - public List findAllTaskFromCache() { - return tasks; - } - - - public TaskDto findByContainer(String container_code) { - Iterator var3 = tasks.iterator(); - - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getVehicle_code(), container_code)) { - return task; - } - } - - return null; - } - - public TaskDto findByCodeFromCache(String task_code) { - Iterator var3 = tasks.iterator(); - - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getTask_code(), task_code)) { - return task; - } - } - return null; - } - - @Override - public TaskDto findByNextCode(String device_code) { - Iterator var3 = tasks.iterator(); - - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getNext_device_code(), device_code)) { - return task; - } - } - return null; - } - - @Override - public List findAllByNextCode(String device_code) { - return null; - } - - @Override - public Integer queryAllTaskMaterialQty(String device_code) { - return null; - } - - - @Override - public TaskDto findByStartCodeAndReady(String device_code) { - Iterator var3 = tasks.iterator(); - - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (!StrUtil.equals(task.getTask_type(), "5")) { - continue; - } - if (StrUtil.equals(task.getStart_device_code(), device_code) && StrUtil.equals(task.getTask_status(), "0")) { - return task; - } - } - return null; - } - - @Override - public TaskDto findByStartCode(String device_code) { - Iterator var3 = tasks.iterator(); - - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getStart_device_code(), device_code)) { - return task; - } - } - return null; - } - - @Override - public TaskDto foramte(TaskDto task) { - String start_point_code = task.getStart_point_code(); - String next_point_code = task.getNext_point_code(); - String from_y = null; - String from_z = null; - String to_y = null; - String to_z = null; - if (StrUtil.contains(start_point_code, "-") && StrUtil.count(start_point_code, "-") == 2) { - String[] start_point = start_point_code.split("-"); - task.setFrom_x(start_point[0]); - task.setStart_device_code(start_point[0]); - if (Integer.parseInt(start_point[1]) < 10 && start_point[1].length() == 1) { - from_y = "0" + start_point[1]; - task.setFrom_y(from_y); + feefbackdto.setTask_status(entity.getTask_status()); + if (status == 200) { + if (StrUtil.equals(entity.getTask_status(), "2")) { + feefbackdto.setIs_finished("1"); } else { - from_y = start_point[1]; - task.setFrom_y(from_y); + feefbackdto.setIs_finished("0"); } - if (Integer.parseInt(start_point[2]) < 10 && start_point[2].length() == 1) { - from_z = "0" + start_point[2]; - task.setFrom_z(from_z); - } else { - from_z = start_point[2]; - } - task.setStart_point_code(task.getStart_device_code() + "-" + from_y + "-" + from_z); - task.setStart_device_code(task.getStart_device_code()); + } else { + feefbackdto.setIs_finished("0"); + feefbackdto.setRemark(jo.getString("message")); + } + taskFeedbackService.update(feefbackdto); + } + } + } + // 如果属于先知AGV,关闭运单序列 + if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) { + try { + agvService.markComplete(entity.getTask_code()); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + @Override + @Transactional(rollbackFor = Exception.class) + public void cancel(String id) throws Exception { + TaskDto entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); + InstructionDto instdto = instructionservice.findByTaskid(id, "instruction_status <2 "); + if (instdto != null) { + throw new BadRequestException("有指令未完成!"); + } + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setTask_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + +// synchronized (TaskServiceImpl.class){ +// Iterator it = tasks.iterator(); +// // 清理缓存 +// while (it.hasNext()) { +// TaskDto taskDto = it.next(); +// if (taskDto.getTask_id().equals(id)) { +// tasks.remove(taskDto); +// } +// }} + + removeByCodeFromCache(entity.getTask_code()); + + // 判断是否为WMS下发的任务,如果是反馈任务状态给WMS + String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); + if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { + JSONObject feed_jo = new JSONObject(); + feed_jo.put("task_id", entity.getTask_id()); + feed_jo.put("task_code", entity.getTask_code()); + feed_jo.put("task_status", entity.getTask_status()); + JSONArray ja = new JSONArray(); + ja.add(feed_jo); + acstowmsService.feedbackTaskStatusToWms(ja); + } + List shortPathsList = + routeLineService.getShortPathLines( + entity.getStart_device_code(), + entity.getNext_device_code(), + entity.getRoute_plan_code()); + String type = shortPathsList.get(0).getType(); + // != 0 为agv任务 + if (!StrUtil.equals(type, "0")) { + if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) { + agvService.markComplete(entity.getTask_code()); + } + } + } + + @Override + public Instruction createTemporaryInst(TaskDto acsTask) { + if (acsTask == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + acsTask = foramte(acsTask); + ParamService paramService = SpringContextHolder.getBean(ParamService.class); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); + // InstructionDto inst = instructionservice.findByTaskid(acsTask, "instruction_status < 2 + // "); + // if (inst != null) { + // throw new BadRequestException("有指令未完成!"); + // } + + String taskid = acsTask.getTask_id(); + String taskcode = acsTask.getTask_code(); + String vehiclecode = acsTask.getVehicle_code(); + String priority = acsTask.getPriority(); + String start_point_code = acsTask.getStart_point_code(); + String start_device_code = acsTask.getStart_device_code(); + String route_plan_code = acsTask.getRoute_plan_code(); + String vehicleType = acsTask.getVehicle_type(); + // 是否复合任务 =0非复合任务 + String compound_task = acsTask.getCompound_task(); + String next_point_code = acsTask.getNext_point_code(); + String next_device_code = acsTask.getNext_device_code(); + String start_point_code2 = acsTask.getStart_point_code2(); + String next_point_code2 = acsTask.getNext_point_code2(); + String agv_system_type = acsTask.getAgv_system_type(); + String task_type = acsTask.getTask_type(); + String from_x = acsTask.getFrom_x(); + String from_y = acsTask.getFrom_y(); + String from_z = acsTask.getFrom_z(); + String to_x = acsTask.getTo_x(); + String to_y = acsTask.getTo_y(); + String to_z = acsTask.getTo_z(); + + /** 开始平均分解校验 */ + String this_device_code = + this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); + if (StrUtil.isEmpty(this_device_code)) { + List shortPathsList = + routeLineService.getShortPathLines( + start_device_code, acsTask.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_device_code; + } + + if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); + } else { + next_point_code = next_device_code; + } + + Instruction instdto = new Instruction(); + if (StrUtil.isEmpty(instdto.getInstruction_code())) { + instdto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + instdto.setInstruction_type(task_type); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(acsTask.getRemark()); + instdto.setMaterial(acsTask.getMaterial()); + instdto.setQuantity(acsTask.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); + instdto.setVehicle_type(vehicleType); + instdto.setStart_point_code2(start_point_code2); + instdto.setStart_device_code2(start_point_code2); + instdto.setNext_device_code2(next_point_code2); + instdto.setNext_point_code2(next_point_code2); + instdto.setAgv_system_type(agv_system_type); + instdto.setFrom_x(from_x); + instdto.setFrom_y(from_y); + instdto.setFrom_z(from_z); + instdto.setTo_x(to_x); + instdto.setTo_y(to_y); + instdto.setTo_z(to_z); + + // 判断agv系统 + // 1、1楼叉车系统 + // 2、2楼1区域AGV系统 + // 3、2楼2区域AGV系统 + if (!StrUtil.equals(agv_system_type, "1")) { + // task_type + // 1、生箔; Itype=1:取空,取满,放空,放满; + // 2、分切 Itype=3取满、取空、放满、放空; + // 3、普通任务 Itype=2:取货、放货; + // 4、叉车任务 + // 5、输送任务 + // 6、行架 + // 7、立库 + if (StrUtil.equals(task_type, "1")) { + instdto.setAgv_inst_type("1"); + } else if (StrUtil.equals(task_type, "3")) { + instdto.setAgv_inst_type("2"); + } else if (StrUtil.equals(task_type, "2")) { + instdto.setAgv_inst_type("3"); + } + } else { + instdto.setAgv_inst_type("4"); + } + return instdto; + } + + @Override + public Instruction createInst(String ids) throws Exception { + TaskDto acsTask = this.findById(ids); + if (acsTask == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); + InstructionDto inst = instructionservice.findByTaskid(ids, "instruction_status < 2 "); + if (inst != null) { + throw new BadRequestException("有指令未完成!"); + } + + String taskid = acsTask.getTask_id(); + String taskcode = acsTask.getTask_code(); + String vehiclecode = acsTask.getVehicle_code(); + String priority = acsTask.getPriority(); + String start_point_code = acsTask.getStart_point_code(); + String start_device_code = acsTask.getStart_device_code(); + String route_plan_code = acsTask.getRoute_plan_code(); + String vehicleType = acsTask.getVehicle_type(); + // 是否复合任务 =0非复合任务 + String compound_task = acsTask.getCompound_task(); + String next_point_code = acsTask.getNext_point_code(); + String next_device_code = acsTask.getNext_device_code(); + String start_point_code2 = acsTask.getStart_point_code2(); + String next_point_code2 = acsTask.getNext_point_code2(); + String agv_system_type = acsTask.getAgv_system_type(); + String task_type = acsTask.getTask_type(); + /** 开始平均分解校验 */ + String this_device_code = + this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); + if (StrUtil.isEmpty(this_device_code)) { + List shortPathsList = + routeLineService.getShortPathLines( + start_device_code, acsTask.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_device_code; + } + + if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); + } else { + next_point_code = next_device_code; + } + + Instruction instdto = new Instruction(); + instdto.setInstruction_type(task_type); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(acsTask.getRemark()); + instdto.setMaterial(acsTask.getMaterial()); + instdto.setQuantity(acsTask.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); + instdto.setVehicle_type(vehicleType); + instdto.setStart_point_code2(start_point_code2); + instdto.setStart_device_code2(start_point_code2); + instdto.setNext_device_code2(next_point_code2); + instdto.setNext_point_code2(next_point_code2); + instdto.setAgv_system_type(agv_system_type); + // 判断agv系统 + // 1、1楼叉车系统 + // 2、2楼1区域AGV系统 + // 3、2楼2区域AGV系统 + if (!StrUtil.equals(agv_system_type, "1")) { + // task_type + // 1、生箔; Itype=1:取空,取满,放空,放满; + // 2、分切 Itype=3取满、取空、放满、放空; + // 3、普通任务 Itype=2:取货、放货; + // 4、叉车任务 + // 5、输送任务 + // 6、行架 + // 7、立库 + if (StrUtil.equals(task_type, "1")) { + instdto.setAgv_inst_type("1"); + } else if (StrUtil.equals(task_type, "3")) { + instdto.setAgv_inst_type("2"); + } else if (StrUtil.equals(task_type, "2")) { + instdto.setAgv_inst_type("3"); + } + } else { + instdto.setAgv_inst_type("4"); + } + instructionservice.create2(instdto); + + // acsTask.setTask_status("1"); + // this.update(acsTask); + return instdto; + } + + @Override + public Instruction createInst(Instruction inst) throws Exception { + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); + + instructionservice.create2(inst); + return inst; + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TaskDto acsTask : all) { + Map map = new LinkedHashMap<>(); + map.put("任务号", acsTask.getTask_code()); + map.put("载具号", acsTask.getVehicle_code()); + map.put("载具类型", acsTask.getVehicle_type()); + map.put("任务类型", acsTask.getTask_type()); + map.put("任务状态", acsTask.getTask_status()); + map.put("任务优先级", acsTask.getPriority()); + map.put("创建类型", acsTask.getCreate_type()); + map.put("完成类型", acsTask.getFinish_type()); + map.put("执行描述编码", acsTask.getExecute_code()); + map.put("执行描述信息", acsTask.getExecute_message()); + map.put("起始点位编码", acsTask.getStart_point_code()); + map.put("起始设备编码", acsTask.getStart_device_code()); + map.put("目标点位编码", acsTask.getNext_point_code()); + map.put("目标设备编码", acsTask.getNext_device_code()); + map.put("排", acsTask.getFrom_x()); + map.put("列", acsTask.getFrom_y()); + map.put("层", acsTask.getFrom_z()); + map.put("排", acsTask.getTo_x()); + map.put("列", acsTask.getTo_y()); + map.put("层", acsTask.getTo_z()); + map.put("路由方案名称", acsTask.getRoute_plan_name()); + map.put("路由方案编码", acsTask.getRoute_plan_code()); + map.put("是否需要反馈上位系统", acsTask.getIs_needfeedback()); + map.put("备注", acsTask.getRemark()); + map.put("是否启用", acsTask.getIs_active()); + map.put("是否删除", acsTask.getIs_delete()); + map.put("创建者", acsTask.getCreate_by()); + map.put("创建时间", acsTask.getCreate_time()); + map.put("修改者", acsTask.getUpdate_by()); + map.put("修改时间", acsTask.getUpdate_time()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } + + @Override + public void createTaskByClick(JSONObject json) {} + + @Override + public int checkAllowCreate(String devicecode) { + Map map = new HashMap(); + List taskList = this.queryAllUnfinished(map); + int num = 0; + for (int i = 0; i < taskList.size(); i++) { + TaskDto onetask = taskList.get(i); + String next_code = onetask.getNext_point_code(); + if (StrUtil.equals(devicecode, next_code)) { + num = num + 1; + } + } + return num; + } + + @Override + public boolean removeByCodeFromCache(String code) { + CopyOnWriteArrayList taskDtos = (CopyOnWriteArrayList) this.tasks; + taskDtos.removeIf((task) -> { + return task.getTask_code().equals(code); + }); + return true; + } + + @Override + public List findAllTaskFromCache() { + return tasks; + } + + public TaskDto findByContainer(String container_code) { + Iterator var3 = tasks.iterator(); + + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getVehicle_code(), container_code)) { + return task; + } + } + + return null; + } + + public TaskDto findByCodeFromCache(String task_code) { + Iterator var3 = tasks.iterator(); + + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getTask_code(), task_code)) { + return task; + } + } + return null; + } + + @Override + public TaskDto findByNextCode(String device_code) { + Iterator var3 = tasks.iterator(); + + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getNext_device_code(), device_code)) { + return task; + } + } + return null; + } + + @Override + public List findAllByNextCode(String device_code) { + return null; + } + + @Override + public Integer queryAllTaskMaterialQty(String device_code) { + return null; + } + + @Override + public TaskDto findByStartCodeAndReady(String device_code) { + Iterator var3 = tasks.iterator(); + + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + // if (!StrUtil.equals(task.getTask_type(), "5")) { + // continue; + // } + if (StrUtil.equals(task.getStart_device_code(), device_code) + && StrUtil.equals(task.getTask_status(), "0")) { + return task; + } + } + return null; + } + + @Override + public TaskDto findByStartCode(String device_code) { + Iterator var3 = tasks.iterator(); + + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getStart_device_code(), device_code)) { + return task; + } + } + return null; + } + + @Override + public TaskDto foramte(TaskDto task) { + String start_point_code = task.getStart_point_code(); + String next_point_code = task.getNext_point_code(); + String from_y = null; + String from_z = null; + String to_y = null; + String to_z = null; + if (StrUtil.contains(start_point_code, "-") && StrUtil.count(start_point_code, "-") == 2) { + String[] start_point = start_point_code.split("-"); + task.setFrom_x(start_point[0]); + task.setStart_device_code(start_point[0]); + if (Integer.parseInt(start_point[1]) < 10 && start_point[1].length() == 1) { + from_y = "0" + start_point[1]; + task.setFrom_y(from_y); + } else { + from_y = start_point[1]; + task.setFrom_y(from_y); + } + if (Integer.parseInt(start_point[2]) < 10 && start_point[2].length() == 1) { + from_z = "0" + start_point[2]; + task.setFrom_z(from_z); + } else if (start_point[2].length() == 2) { + from_z = start_point[2]; + task.setFrom_z(start_point[2]); + } else { + from_z = start_point[2]; + } + task.setStart_point_code(task.getStart_device_code() + "-" + from_y + "-" + from_z); + task.setStart_device_code(task.getStart_device_code()); + + } else { + String start_device = + deviceAppService + .findDeviceByCode(start_point_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + // 如果point_device为货架,则不包含列层信息,需要重新拼接 + if (StrUtil.equals("storage", start_device)) { + if (StrUtil.isEmpty(task.getFrom_x())) { + throw new BadRequestException("货位信息起点需要包含列信息"); + } + if (StrUtil.isEmpty(task.getFrom_y())) { + throw new BadRequestException("货位信息起点需要包含层信息"); + } + if (Integer.parseInt(task.getFrom_y()) < 10 && task.getFrom_y().length() == 1) { + from_y = "0" + task.getFrom_y(); + task.setFrom_y(from_y); } else { - String start_device = deviceAppService.findDeviceByCode(start_point_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name(); - //如果point_device为货架,则不包含列层信息,需要重新拼接 - if (StrUtil.equals("storage", start_device)) { - if (StrUtil.isEmpty(task.getFrom_x())) { - throw new BadRequestException("货位信息起点需要包含列信息"); - } - if (StrUtil.isEmpty(task.getFrom_y())) { - throw new BadRequestException("货位信息起点需要包含层信息"); - } - if (Integer.parseInt(task.getFrom_y()) < 10 && task.getFrom_y().length() == 1) { - from_y = "0" + task.getFrom_y(); - task.setFrom_y(from_y); - } else { - from_y = task.getFrom_y(); - } - if (Integer.parseInt(task.getFrom_z()) < 10 && task.getFrom_z().length() == 1) { - from_z = "0" + task.getFrom_z(); - task.setFrom_z(from_z); - } else { - from_z = task.getFrom_z(); - } - task.setFrom_x(start_point_code); - task.setStart_point_code(start_point_code + "-" + from_y + "-" + from_z); - task.setStart_device_code(start_point_code); - } else { - task.setStart_device_code(start_point_code); - task.setStart_device_code(start_point_code); - } + from_y = task.getFrom_y(); } - - if (StrUtil.contains(next_point_code, "-") && StrUtil.count(next_point_code, "-") == 2) { - String[] next_point = next_point_code.split("-"); - task.setNext_device_code(next_point[0]); - task.setTo_x(next_point[0]); - if (Integer.parseInt(next_point[1]) < 10 && next_point[1].length() == 1) { - to_y = "0" + next_point[1]; - task.setTo_y(to_y); - } else { - to_y = next_point[1]; - task.setTo_y(to_y); - } - if (Integer.parseInt(next_point[2]) < 10 && next_point[2].length() == 1) { - to_z = "0" + next_point[2]; - task.setTo_z(to_z); - } else { - to_z = next_point[2]; - task.setTo_z(to_z); - } - task.setNext_point_code(task.getNext_device_code() + "-" + to_y + "-" + to_z); - task.setNext_device_code(task.getNext_device_code()); - + if (Integer.parseInt(task.getFrom_z()) < 10 && task.getFrom_z().length() == 1) { + from_z = "0" + task.getFrom_z(); + task.setFrom_z(from_z); + } else if (task.getFrom_z().length() == 2) { + from_z = task.getFrom_z(); + task.setFrom_z(from_z); } else { - String next_device = deviceAppService.findDeviceByCode(next_point_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name(); - if (StrUtil.equals("storage", next_device)) { - if (StrUtil.isEmpty(task.getTo_x())) { - throw new BadRequestException("货位信息终点需要包含列信息"); - } - if (StrUtil.isEmpty(task.getTo_y())) { - throw new BadRequestException("货位信息终点需要包含层信息"); - } - if (Integer.parseInt(task.getTo_y()) < 10 && task.getTo_y().length() == 1) { - to_y = "0" + task.getTo_y(); - task.setTo_y(to_y); - } else { - to_y = task.getTo_y(); - } - if (Integer.parseInt(task.getTo_z()) < 10 && task.getTo_z().length() == 1) { - to_z = "0" + task.getTo_z(); - task.setTo_z(to_z); - } else { - to_z = task.getTo_z(); - } - task.setTo_x(next_point_code); - task.setNext_point_code(next_point_code + "-" + to_y + "-" + to_z); - task.setNext_device_code(next_point_code); - - } else { - task.setNext_device_code(next_point_code); - task.setNext_device_code(next_point_code); - - } + from_z = task.getFrom_z(); } - return task; + task.setFrom_x(start_point_code); + task.setStart_point_code(start_point_code + "-" + from_y + "-" + from_z); + task.setStart_device_code(start_point_code); + } else { + task.setStart_device_code(start_point_code); + task.setStart_device_code(start_point_code); + } } - @Override - public void updateByCodeFromCache(TaskDto dto) { - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(dto.getTask_code())) { - iterator.remove(); - } + if (StrUtil.contains(next_point_code, "-") && StrUtil.count(next_point_code, "-") == 2) { + String[] next_point = next_point_code.split("-"); + task.setNext_device_code(next_point[0]); + task.setTo_x(next_point[0]); + if (Integer.parseInt(next_point[1]) < 10 && next_point[1].length() == 1) { + to_y = "0" + next_point[1]; + task.setTo_y(to_y); + } else { + to_y = next_point[1]; + task.setTo_y(to_y); + } + if (Integer.parseInt(next_point[2]) < 10 && next_point[2].length() == 1) { + to_z = "0" + next_point[2]; + task.setTo_z(to_z); + } else if (next_point[2].length() == 2) { + to_z = next_point[2]; + task.setTo_z(to_z); + } else { + to_z = next_point[2]; + task.setTo_z(to_z); + } + task.setNext_point_code(task.getNext_device_code() + "-" + to_y + "-" + to_z); + task.setNext_device_code(task.getNext_device_code()); + + } else { + String next_device = + deviceAppService + .findDeviceByCode(next_point_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + if (StrUtil.equals("storage", next_device)) { + if (StrUtil.isEmpty(task.getTo_x())) { + throw new BadRequestException("货位信息终点需要包含列信息"); } - tasks.add(dto); - } - - @Override - public String queryAssignedByDevice(String device_code, String task_nextdeice_code) { - List list = deviceAssignedService.queryAssignedBydevice(device_code, task_nextdeice_code); - int flag1 = 0; - String flag2 = null; - for (int i = 0; i < list.size(); i++) { - DeviceAssignedDto dto = list.get(i); - String inst_nextDevice_code = dto.getInst_nextdevice_code(); - String task_nextDevice_code = dto.getTask_nextdevice_code(); - String param = dto.getParam(); - JSONObject jo = JSON.parseObject(param); - String regEx = "[`~!@#$%^&*()+=|{}':;'\\[\\].<>/?~!@#¥%……&*()——+|{}【】':”“’。、?]"; - Pattern p = Pattern.compile(regEx); - Matcher m = p.matcher(inst_nextDevice_code); - String toSpeechText = m.replaceAll("").trim(); - - String[] str = toSpeechText.split(","); - List pathlist = Arrays.asList(str); - for (int j = 0; j < pathlist.size(); j++) { - String this_device_code = pathlist.get(j).toString(); - JSONObject data = JSON.parseObject(jo.getString(this_device_code)); - String limit = data.getString("limit"); - int num = instructionService.querySameDestinationInst(this_device_code); - if (num >= Integer.parseInt(limit)) { - continue; - } - if (j == 0) { - flag1 = num; - } - if (num <= flag1) { - flag2 = this_device_code; - } - } - + if (StrUtil.isEmpty(task.getTo_y())) { + throw new BadRequestException("货位信息终点需要包含层信息"); } - if (!StrUtil.isEmpty(flag2)) { - return flag2; + if (Integer.parseInt(task.getTo_y()) < 10 && task.getTo_y().length() == 1) { + to_y = "0" + task.getTo_y(); + task.setTo_y(to_y); + } else { + to_y = task.getTo_y(); } - return null; - } - - @Override - public Integer querySameTaskByType(String taskType) { - int num = 0; - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_type().equals(taskType) && task.getTask_status().equals("1")) { - num++; - } + if (Integer.parseInt(task.getTo_z()) < 10 && task.getTo_z().length() == 1) { + to_z = "0" + task.getTo_z(); + task.setTo_z(to_z); + } else if (task.getTo_z().length() == 2) { + to_z = task.getTo_z(); + task.setTo_z(to_z); + } else { + to_z = task.getTo_z(); } + task.setTo_x(next_point_code); + task.setNext_point_code(next_point_code + "-" + to_y + "-" + to_z); + task.setNext_device_code(next_point_code); - return num; + } else { + task.setNext_device_code(next_point_code); + task.setNext_device_code(next_point_code); + } } + return task; + } - @Override - public Integer querySameOriginTask(String code) { - return null; + @Override + public void updateByCodeFromCache(TaskDto dto) { + removeByCodeFromCache(dto.getTask_code()); + tasks.add(dto); + } + + @Override + public String queryAssignedByDevice(String device_code, String task_nextdeice_code) { + List list = + deviceAssignedService.queryAssignedBydevice(device_code, task_nextdeice_code); + int flag1 = 0; + String flag2 = null; + for (int i = 0; i < list.size(); i++) { + DeviceAssignedDto dto = list.get(i); + String inst_nextDevice_code = dto.getInst_nextdevice_code(); + String task_nextDevice_code = dto.getTask_nextdevice_code(); + String param = dto.getParam(); + JSONObject jo = JSON.parseObject(param); + String regEx = "[`~!@#$%^&*()+=|{}':;'\\[\\].<>/?~!@#¥%……&*()——+|{}【】':”“’。、?]"; + Pattern p = Pattern.compile(regEx); + Matcher m = p.matcher(inst_nextDevice_code); + String toSpeechText = m.replaceAll("").trim(); + + String[] str = toSpeechText.split(","); + List pathlist = Arrays.asList(str); + for (int j = 0; j < pathlist.size(); j++) { + String this_device_code = pathlist.get(j).toString(); + JSONObject data = JSON.parseObject(jo.getString(this_device_code)); + String limit = data.getString("limit"); + int num = instructionService.querySameDestinationInst(this_device_code); + if (num >= Integer.parseInt(limit)) { + continue; + } + if (j == 0) { + flag1 = num; + } + if (num <= flag1) { + flag2 = this_device_code; + } + } } - - @Override - public Integer querySameDestinationTask(String code) { - return null; + if (!StrUtil.isEmpty(flag2)) { + return flag2; } + return null; + } + @Override + public Integer querySameDeviceReadyTask(String start_device, String next_device, String status) { + int num = 0; + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (StrUtil.equals(task.getStart_device_code(), start_device) + && StrUtil.equals(task.getNext_device_code(), next_device) + && StrUtil.equals(task.getTask_status(), status)) { + num++; + } + } + + return num; + } + + + @Override + public Integer querySameTaskByType(String taskType) { + int num = 0; + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getTask_type().equals(taskType) && task.getTask_status().equals("1")) { + num++; + } + } + + return num; + } + + @Override + public Integer querySameOriginTask(String code) { + int num = 0; + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (StrUtil.equals(task.getStart_device_code(), code)) { + num++; + } + } + + return num; + } + + @Override + public Integer querySameDestinationTask(String code) { + int num = 0; + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (StrUtil.equals(task.getNext_device_code(), code)) { + num++; + } + } + + return num; + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/wql/QTASK_QUERY.wql b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/wql/QTASK_QUERY.wql index dbd0efd..fac35ef 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/wql/QTASK_QUERY.wql +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/wql/QTASK_QUERY.wql @@ -95,16 +95,16 @@ IF 输入.flag = "2" task.task_status = 输入.status ENDOPTION OPTION 输入.vehicle_code <> "" - task.vehicle_code = 输入.vehicle_code + task.vehicle_code LIKE CONCAT ( '%', 输入.vehicle_code, '%' ) ENDOPTION OPTION 输入.material_type <> "" task.material = 输入.material_type ENDOPTION OPTION 输入.point_code <> "" ( - task.start_point_code = 输入.point_code + task.start_point_code LIKE CONCAT ( '%', 输入.point_code, '%' ) OR - task.next_point_code = 输入.point_code + task.next_point_code LIKE CONCAT ( '%', 输入.point_code, '%') ) ENDOPTION OPTION 输入.create_time <> "" diff --git a/acs/nladmin-system/src/main/java/org/nl/common/utils/IdUtil.java b/acs/nladmin-system/src/main/java/org/nl/common/utils/IdUtil.java new file mode 100644 index 0000000..41f47c0 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/common/utils/IdUtil.java @@ -0,0 +1,11 @@ +package org.nl.common.utils; + +public class IdUtil { + public static Long getLongId() { + return cn.hutool.core.util.IdUtil.getSnowflake(1, 1).nextId(); + } + + public static String getStringId() { + return String.valueOf(IdUtil.getLongId()); + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/InterfaceLogType.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/InterfaceLogType.java new file mode 100644 index 0000000..41c4896 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/InterfaceLogType.java @@ -0,0 +1,24 @@ +package org.nl.modules.logging; + +/** + * @author: lyd + * @description: + * @Date: 2022/10/11 + */ +public enum InterfaceLogType { + DEFAULT("默认"), + LMS_TO_ACS("LMS请求ACS"), + ACS_TO_LMS("ACS请求LMS"), + ACS_TO_LK("ACS请求立库"), + LK_TO_ACS("立库请求ACS"); + + private String desc; + + InterfaceLogType(String desc) { + this.desc=desc; + } + + public String getDesc() { + return desc; + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/annotation/Log.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/annotation/Log.java index e14ae50..9898419 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/logging/annotation/Log.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/annotation/Log.java @@ -15,6 +15,8 @@ */ package org.nl.modules.logging.annotation; +import org.nl.modules.logging.InterfaceLogType; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -28,4 +30,33 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) public @interface Log { String value() default ""; + + /** + * 是否打印到日志文件 + * + * @return + */ + boolean isPrintToLogFile() default false; + + + /** + * 是否插入操作日志表 + * + * @return + */ + boolean isAddLogTable() default true; + + /** + * 是否接口日志 + * + * @return + */ + boolean isInterfaceLog() default false; + + /** + * 接口日志类型 + * + * @return + */ + InterfaceLogType interfaceLogType() default InterfaceLogType.DEFAULT; } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java index 24e8e05..04b0ec7 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java @@ -15,22 +15,23 @@ */ package org.nl.modules.logging.aspect; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; -import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; +import org.nl.common.utils.IdUtil; import org.nl.modules.common.utils.RequestHolder; -import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.common.utils.StringUtils; import org.nl.modules.common.utils.ThrowableUtil; import org.nl.modules.logging.domain.Log; import org.nl.modules.logging.service.LogService; +import org.nl.modules.wql.core.bean.WQLObject; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; @@ -38,10 +39,7 @@ import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; import java.lang.reflect.Parameter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Zheng Jie @@ -54,8 +52,6 @@ public class LogAspect { private final LogService logService; - ThreadLocal currentTime = new ThreadLocal<>(); - public LogAspect(LogService logService) { this.logService = logService; } @@ -75,21 +71,60 @@ public class LogAspect { */ @Around("logPointcut()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { + String trackId = UUID.randomUUID().toString(); MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); // 方法路径 String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()"; - String params=getParameter(method, joinPoint.getArgs()); - log.info("请求方法:{}",methodName); - log.info("请求方法参数:{}",params); + String params = getParameter(method, joinPoint.getArgs()); - Object result; - currentTime.set(System.currentTimeMillis()); - result = joinPoint.proceed(); - Log log = new Log("INFO",System.currentTimeMillis() - currentTime.get()); - currentTime.remove(); + org.nl.modules.logging.annotation.Log logInfo = method.getAnnotation(org.nl.modules.logging.annotation.Log.class); + + //是否输出到日志文件 + if (logInfo.isPrintToLogFile()) { + log.info("track_id:{},请求方法:{},请求方法参数:{}", trackId, methodName, params); + } HttpServletRequest request = RequestHolder.getHttpServletRequest(); - logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log); + String requestIp = StringUtils.getIp(request); + Object result; + long startTime = System.currentTimeMillis(); + try { + result = joinPoint.proceed(); + //是否把日志存到日志表 + if (logInfo.isAddLogTable()) { + Log log = new Log("INFO", System.currentTimeMillis() - startTime); + logService.save("", StringUtils.getBrowser(request), requestIp, joinPoint, log); + } + if (logInfo.isInterfaceLog()) { + try { + WQLObject interfaceLog = WQLObject.getWQLObject("sys_interface_log"); + JSONObject json = new JSONObject(); + json.put("log_id", IdUtil.getStringId()); + json.put("description", logInfo.value()); + json.put("log_type", logInfo.interfaceLogType().getDesc()); + json.put("log_level", "1"); + json.put("method", methodName); + json.put("params", getParameter(method, joinPoint.getArgs())); + json.put("request_ip", StringUtils.getIp(request)); + json.put("time", System.currentTimeMillis() - startTime); + json.put("username", ""); + json.put("address", StringUtils.getCityInfo(requestIp)); + json.put("browser", StringUtils.getBrowser(request)); + json.put("exception_detail", IdUtil.getStringId()); + json.put("create_time", DateUtil.now()); + json.put("return_result", result.toString()); + interfaceLog.insert(json); + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (Exception ex) { + log.error("track_id:{},error:{}", trackId, ex.getMessage()); + Log log = new Log("ERROR", System.currentTimeMillis() - startTime); + log.setExceptionDetail(ThrowableUtil.getStackTrace(ex).getBytes()); + logService.save("", StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log); + throw ex; + } return result; } @@ -123,26 +158,11 @@ public class LogAspect { return argList.size() == 1 ? JSONUtil.toJsonStr(argList.get(0)) : JSONUtil.toJsonStr(argList); } - /** - * 配置异常通知 - * - * @param joinPoint join point for advice - * @param e exception - */ - @AfterThrowing(pointcut = "logPointcut()", throwing = "e") - public void logAfterThrowing(JoinPoint joinPoint, Throwable e) { - Log log = new Log("ERROR",System.currentTimeMillis() - currentTime.get()); - currentTime.remove(); - log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes()); - HttpServletRequest request = RequestHolder.getHttpServletRequest(); - logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log); - } - - public String getUsername() { - try { - return SecurityUtils.getCurrentUsername(); - }catch (Exception e){ - return ""; - } - } +// public String getUsername() { +// try { +// return SecurityUtils.getCurrentUsername(); +// } catch (Exception e) { +// return ""; +// } +// } } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/rest/InterfaceLogController.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/rest/InterfaceLogController.java new file mode 100644 index 0000000..847d8f5 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/rest/InterfaceLogController.java @@ -0,0 +1,51 @@ +package org.nl.modules.logging.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.nl.modules.logging.annotation.Log; +import org.nl.modules.logging.service.InterfaceLogService; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + * @author ldjun + * @version 1.0 + * @date 2023年01月29日 18:55 + * @desc desc + */ + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/interfaceLog") +@Api(tags = "系统:接口日志管理") +public class InterfaceLogController { + private final InterfaceLogService interfaceLogService; + + @GetMapping + @Log("查询接口日志") + @ApiOperation("查询接口日志") + //@SaCheckPermission("point:list") + public ResponseEntity query(@RequestParam Map whereJson, Pageable page) { + return new ResponseEntity<>(interfaceLogService.queryAll(whereJson, page), HttpStatus.OK); + } + + @DeleteMapping(value = "/delLogs") + @Log("删除所有接口日志") + @ApiOperation("删除所有接口日志") + public ResponseEntity delLogs(){ + interfaceLogService.delLogs(); + return new ResponseEntity<>(HttpStatus.OK); + } + + @GetMapping("/logTypeList") + @Log("查询接口日志类型下拉框") + @ApiOperation("查询接口日志类型下拉框") + public ResponseEntity logTypeList() { + return new ResponseEntity<>(interfaceLogService.logTypeList(), HttpStatus.OK); + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/InterfaceLogService.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/InterfaceLogService.java new file mode 100644 index 0000000..b40b2d6 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/InterfaceLogService.java @@ -0,0 +1,44 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.logging.service; + +import com.alibaba.fastjson.JSONArray; +import org.springframework.data.domain.Pageable; + +import java.util.Map; + +/** + * @author Zheng Jie + * @date 2018-11-24 + */ +public interface InterfaceLogService { + + /** + * 查询数据分页 + * @param whereJson 条件 + * @param page 分页参数 + * @return Map + */ + Map queryAll(Map whereJson, Pageable page); + + + /** + * 删除所有日志 + */ + void delLogs(); + + JSONArray logTypeList(); +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/InterfaceLogServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/InterfaceLogServiceImpl.java new file mode 100644 index 0000000..6b9d5a5 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/InterfaceLogServiceImpl.java @@ -0,0 +1,70 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.logging.service.impl; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.modules.logging.InterfaceLogType; +import org.nl.modules.logging.service.InterfaceLogService; +import org.nl.modules.wql.WQL; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.WqlUtil; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Zheng Jie + * @date 2018-11-24 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class InterfaceLogServiceImpl implements InterfaceLogService { + + + @Override + public Map queryAll(Map whereJson, Pageable pageable) { + HashMap map = new HashMap(); + map.put("flag", "1"); + map.put("blurry", whereJson.get("blurry")); + map.put("logType", whereJson.get("logType")); + map.put("begin_time", whereJson.get("begin_time")); + map.put("end_time", whereJson.get("end_time")); + JSONObject json = WQL.getWO("QSCH_INTERFACE_LOGS").addParamMap(map).pageQuery(WqlUtil.getHttpContext(pageable), "create_time desc"); + return json; + } + + @Override + public void delLogs() { + WQLObject logTab = WQLObject.getWQLObject("sys_interface_log"); + logTab.delete("log_id is not null"); + } + + @Override + public JSONArray logTypeList() { + JSONArray jsonArray = new JSONArray(); + InterfaceLogType[] values = InterfaceLogType.values(); + for (InterfaceLogType value : values) { + jsonArray.add(value.getDesc()); + } + return jsonArray; + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/wql/QSCH_INTERFACE_LOGS.wql b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/wql/QSCH_INTERFACE_LOGS.wql new file mode 100644 index 0000000..afd14ee --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/wql/QSCH_INTERFACE_LOGS.wql @@ -0,0 +1,68 @@ +[交易说明] + 交易名: 接口日志分页查询 + 所属模块: + 功能简述: + 版权所有: + 表引用: + 版本经历: + +[数据库] + --指定数据库,为空采用默认值,默认为db.properties中列出的第一个库 + +[IO定义] + ################################################# + ## 表字段对应输入参数 + ################################################# + 输入.flag TYPEAS s_string + 输入.blurry TYPEAS s_string + 输入.logType TYPEAS s_string + 输入.begin_time TYPEAS s_string + 输入.end_time TYPEAS s_string + + +[临时表] + --这边列出来的临时表就会在运行期动态创建 + +[临时变量] + --所有中间过程变量均可在此处定义 + +[业务过程] + + ########################################## + # 1、输入输出检查 # + ########################################## + + + ########################################## + # 2、主过程前处理 # + ########################################## + + + ########################################## + # 3、业务主过程 # + ########################################## + + IF 输入.flag = "1" + PAGEQUERY + SELECT + * + FROM + sys_interface_log + WHERE + 1=1 + OPTION 输入.blurry <> "" + description like "%" 输入.blurry "%" + ENDOPTION + OPTION 输入.logType <> "" + log_type = 输入.logType + ENDOPTION + OPTION 输入.begin_time <> "" + create_time >= 输入.begin_time + ENDOPTION + OPTION 输入.end_time <> "" + create_time <= 输入.end_time + ENDOPTION + ENDSELECT + ENDPAGEQUERY + ENDIF + diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/mnt/websocket/WebSocketServer.java b/acs/nladmin-system/src/main/java/org/nl/modules/mnt/websocket/WebSocketServer.java index f6e9d0c..74a00f3 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/mnt/websocket/WebSocketServer.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/mnt/websocket/WebSocketServer.java @@ -77,7 +77,6 @@ public class WebSocketServer { * @param message 客户端发送过来的消息*/ @OnMessage public void onMessage(String message, Session session) { - log.info("收到来"+sid+"的信息:"+message); //群发消息 for (WebSocketServer item : webSocketSet) { try { @@ -106,7 +105,6 @@ public class WebSocketServer { * */ public static void sendInfo(SocketMsg socketMsg,@PathParam("sid") String sid) throws IOException { String message = JSONObject.toJSONString(socketMsg); - log.info("推送消息到"+sid+",推送内容:"+message); for (WebSocketServer item : webSocketSet) { try { //这里可以设定只推送给这个sid的,为null则全部推送 diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java index 02eca6a..f68170c 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java @@ -39,10 +39,14 @@ public class AutoCreateInst { List list = taskserver.queryAll("task_status = '0'"); for (int i = 0; i < list.size(); i++) { TaskDto acsTask = list.get(i); + if(StrUtil.equals(acsTask.getTask_type(),"7") && !StrUtil.startWith(acsTask.getTask_code(), "-") ){ + continue; + } String taskid = acsTask.getTask_id(); String taskcode = acsTask.getTask_code(); String task_type = acsTask.getTask_type(); String vehiclecode = acsTask.getVehicle_code(); + String storage_task_type = acsTask.getStorage_task_type(); String priority = acsTask.getPriority(); String is_send = acsTask.getIs_send(); @@ -70,6 +74,7 @@ public class AutoCreateInst { if (StrUtil.equals(is_send, "0")) { continue; } + //校验路由关系 List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); if (ObjectUtils.isEmpty(shortPathsList)) { diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryLKDeviceStatus.java b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryLKDeviceStatus.java new file mode 100644 index 0000000..98b5a5f --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryLKDeviceStatus.java @@ -0,0 +1,44 @@ +package org.nl.modules.quartz.task; + +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.ZheDaAgvService; +import org.nl.acs.ext.wms.liKuData.DeviceStatusRequest; +import org.nl.acs.ext.wms.liKuData.DeviceStatusResponse; +import org.nl.acs.ext.wms.liKuData.Resp; +import org.nl.acs.ext.wms.service.AcsToLiKuService; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 查询立库设备状态 + */ +@Slf4j +@Component +public class QueryLKDeviceStatus { + + @Autowired + AcsToLiKuService acsToLiKuService; + + + public void run() throws Exception { + DeviceStatusRequest deviceStatusRequest = new DeviceStatusRequest(); + deviceStatusRequest.setDeviceId("0"); + Resp carResp = acsToLiKuService.queryCarDeviceStatus(deviceStatusRequest); + Resp ssxResp = acsToLiKuService.querySsxDeviceStatus(deviceStatusRequest); + Resp tsjResp = acsToLiKuService.queryTsjDeviceStatus(deviceStatusRequest); + + + + } +} 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 ee4f685..2843083 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/java/org/nl/modules/security/service/OnlineUserService.java b/acs/nladmin-system/src/main/java/org/nl/modules/security/service/OnlineUserService.java index e4b8b5e..2ae96ec 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/security/service/OnlineUserService.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/security/service/OnlineUserService.java @@ -16,6 +16,7 @@ package org.nl.modules.security.service; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; import org.nl.modules.common.utils.*; @@ -118,6 +119,7 @@ public class OnlineUserService { * @param token / */ public void logout(String token) { + if (ObjectUtil.isNotEmpty(token)) redisUtils.del(token); } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/system/wql/sys.xls b/acs/nladmin-system/src/main/java/org/nl/modules/system/wql/sys.xls index a73514e742fd336ef67fc966b2897443e62d08c3..82566ab6461a4d0e92adeacbb1883cf1ca00f877 100644 GIT binary patch delta 15029 zcmeHud3Y4X)^}C+YzdicB#?wH3x+@vn3+r_0|d!7VM)Rk2&jROWkLek%)%C6CLjW$ zLKvXg30xKKRS*m?0s`TR;DUg%sHljbASj5UAPD9?r@Ln|>BRT@?(=-#^Spn&GtZf- z`c?Hgbxu{CQ(fI-J*T!lQZJA1o<|5_fc|Q3Zia;a6v6K=K=UY9p=5$~SG-79Ffv9( zZ3^Zun`}`}TLhaOQ2;GAQ$pN;%#bexngUb|^cc8Jg>)K_?Ttn8wjbCzK53u*zWvUP z&#Cq6>E_)2U(kG8jcfrM!ZNl$WyM|zInVN_SZk}2@AYsaq^vxz#9UHbSZ&iP3T$f> zzBI`8x+0K{v%RZGa%;Ab(a-fV5|2htWu4O2&r@N0$-RTE!m|hD^|o41KS%=_mwC<) zvOU#%sLiMM(8evjH!zmV#E)b^=O_sxWTuZ#LU2MbQA7nJKB5JufDQ=7r3|JqQ-*YZY{X8y%rP$3&pqQFYt+IX`e4L5-MN_9D+q$&;TqU(Llgm zhs-T_j>?bBQGo`|PYj*1@&3BTaZ!amY|GMoX|Sz(S|k%nZO_K{VZx~G=V3i;edE2E zo-NrYFx!s_$2LJWO`7cyEPt6 zd)D7_s}cLjP@0{`EhOIL@;g|T(M9I`qTiN!79vKE3s{A@EWdWn((#B*xF}#(N6?ue zQxWqdxA`T@(xSzobNzD=>E8iXBVp;EbH15Zv>1_?p#n1gnVF*jNd{K2V-b?kP8K@z z*pk383yCjzz8*0-f8oC~E6jMYHyOE6Xj!y4zNqsU#JZ9b7i_n4yNBMt)pEi2=Ff7l z(wAJnFQBjHU(K`y4yAxDK2cT|wlISgrl(&ol3dG}?u zU3n_onkhj&UQlAg`AV@Niw!B63`Gy14vn8oxy$%>fGi5_N9dg>8G1A2ou0N3nZL#9 z(4ZDSru0y#`vcf8vU4w{Zz)UvZPLNh6K_oAPUkd}bI4w3$hS=x6m;h#VA7TwU_CfK z^^kc2DEf#u>8FvAbHJu3`^ZJqx zBXm7gNlBqw7OsCf<;)xZZhmfYc8YpWai&l7{OYY)PngylqA#x9v*LNfD#h9RU*A8q zevvBVR9*S){?|7(*M3u*pYol1Lv@$*M)wJkADIqxtA8!5S7vDH?IEUnNjX8gLe@W@ zXPHp2+2S+nt*LMRWS($oaHWiXr_cMH4DsqQPoTSk@7eq4y;En-co$r>zuV*4S3*`S->^sZ^=nKJyJX^9 z9cEvtxZ3EznTeL@x!tA3lc2(1=%a;>4gjB-^BRs zN}F(ca#UFUnT3xw?9V=R-$NO{e)9FEQ@6t2J{u91b>xD_KVv-eSNz!Y-B)e{pD!7- z>&kb=?q|9xXQdtJ`QY2LCrra8-rREU_}8U1k#VL;uWo%RU3dEYjxEQIM{VN=%p2|MI3y|?${@9xIe_?G4;1dgJ|>WUlW zmv5Y?E4J!(?pU>Z!qbN~TUS4O(R#~Dhu+@kTP#1FeeOQ9pvf=c(a~?U(iD>=|EO-*+bR_otP2V|t9g_b*+|%BANc^LNMXeA)hTestEGxyM5H zm#+gR)80J!(VXm#mxh0_V~g=n<-QlUUEluen$5kGBZ}vqUUDh-@WG+C5AFt57bEY! zHS)sIN#hE;Wn^*hzWM3Hn`iDPYkFKi*){%bc*6HScV4nIrQZIe`O=iVi+ixfWjner zGZ|{*Pha)Wc!bZ7-R3oT=8CyzYkz+D%iX!#vP*xNmr<~@D$euj{jcg~&l@-)^2Uvg zL4QUE7Hz)y{k)pa*Zh*}yOkgL>PN4SnqE^{<{jO1H{3jB>W;@THvg*Z0>i3ZTdMax z^mzNi!ao}S88CR1A_%?zge-Ut zyyuT^yicwFCg9eCs6TQW6qol;QqG)bII+I^{+MY8p1J?SmmPNX`>S@#pN%@qV;sOdzX9S6Zvhaa6r}OVD>mal#FjwVQ7FSdk zmzPN!LR_uNsj8~3EH0ZOBNUw_I(1bG^Xgd@X4k81`(E*~Y?~K3#uY@VZp4FvTNb)h zVxDd;k&!Xrwc7M-zxjNL*!xm*by0bn-h)rA$|)_&Ej5E4=wIxC{NRG(THouBy%{u4qU6J@ap?WJ0^@;?h>S32KnCoZ_--^AvL>aE_>n z%TtdX|BPsnnksW;S+1q+WzbX2_=NFFfpKm@L8ZA0yV|O!ETJPy-(OOcB{s{eES~`k zrOjkSj&?k^>{8a*c^jrktJNf$ANopjbxmbi4hX6#sg^c^t}{8tNuGtr=h?n|tqUDt zJG3d#_R>O?#dV$p2$C=&3USg~Q$=QxDv|?Rp$mNg{QV!c_AB|L4 zGx?RONOhSI`()*WY=HiUR}pd;f?htPe?oc%(%Etg3~n_9NChDgHH0)lDw_@$z@VRm zv;bo9vol~e!OZM2lMp+kJ0LYdWE(n*kjs#|&n9Fmgx0qq9R<;LSS=ynLV5wxGBqJf z<`5F%Nr>-ULjDEmQb@xfTHl9snFTW4pc8w+#PcBy@_`!)NS8o5+Dga`NPmFT3VYPY z^9fnyN660$2wCJ$$kpcvsqF;977{Y6Ga-+jCuC&+A@43CsmlN_Er2Y`JmobDWR}fMM z@%lGN%g}T-LbAan{JxTqa=JV_-4e8baOxOR3jFN5Mk1kp2#7#X3T6 zf~6Q3k2zo&cAwoHxg0=mI&TV$U3k@_Xa}NfaVV&tp?3+Y=Lp>NJ!&W*g${< zs{aAkK>7&M>0pVyufV3JQ{#p0t314~lfs>OvrGD4TD3Om;l|Iqb4Sx?Pym<(KA;0^ zen9YE7=rzTd~?ut^u#D?H3sUp z!N3%4FqjZ+Ffc(I476;)ETUjgwFMM07~nP-40am~2EGjjlb{U-6QT`ffyvPZ?9mPu z+zuAf4hA?g+XL5v>3~a3{ehCjF!=ERLSj1r?LKSV9h{<7k^qb7bcQBd<$*cj`W~~wi8F<{9Ahv zoN#Jlv~_IiB^fJlu~>t%8s>`NgK(ltF`U#=4BT)V3|w*>4BT=H=I}S*qgy~xFs=@% z5HzP019#pA1J~XL!##ykqMQwQe)vPkzzPYkj0j^EO1^(o8!EYVmL35 z#V>7H;8c({Z*MBN&IE}f|KUvF>R~cTSo}BR-fFd>Cq_lSZOa1Vs#Fn-t5OW(DzeZj zX-CP*$4ClQjc9Ds zOUurw=>+Pz${V(RJt<)glsrgvnOtf1wO(|CjJf8;)y}3ta-7oFxGX<9OX#c;hyG4$P141Ko~b3|@*-cC>qd>G=T7`Ix&N&FuGhP zC}MagBgN4F0%rfU6D{`vPmmWuH%oNDU90pm+_g$E+_g%v=you?`;@lRxMGfh)VhMA z4!U-*n07FIJ6LQxn4ukvYwk_wN#fLCp`Cq2A3D-Y5~vcP&P%e5OKt~CX$Ld4gQd2E z4Rytai^dq{3X0h9cCfT|uyg_A{xyIOl;}DNs$hV)hXd$RN!0|Q%D!$O9qFwYHjI+w zOc&=cTD%M3-b|+h=vwY(It`N;3-=Zs$u3M_1qnMg-2O{v1iB9?hA~NcEyg5iJ9HmT z%wa6_A5KsdjQ&H4q5F_x=sp0mU&x^T?(Sbqr^IU+B^#H!sGerqbxC30v4vg^VJQjZ zX3wV6M6dgQ;Sssrt7#w?`4#m93x2Vh)^YY)y4txA1@DQ@#Nl)t9u;?SQj9<7k$7Ho zFw%DDV5As27(#{NvD#10p%np&4J#;_u)#%FahNkX<7ztUKU31N|8w+T^z?SnIm%t} z^ASoK&$~!+TJ=f@*k}2>^qK!q9GElW7;SV~Qix5s+jfkxqbIoAmSS-3)&|3^x3nGJ zgh?^nAULs5I=!8EAPg%GAvEOXyhoS9#!hvd*7zyD{*01ue{!*e!{!#;bFOu3*~syG zPAucm4+8|#4<6Uz<5_rM3Zw+W7d9ZG6L%nd=nD@9h#JTf$P35^XakThP)8s?pmji< zfSv#f015;O!h@JDTrmSry#4L<43kd-phx_DnH5s_;64}jsbnp;=}VgSpADC=1f16h z_HhmTR?&`P;OFwbqDv(X2FKAcs~rvo$5D#mI7%_$M5=Z8$8nUlb6ttVak}HW6di(H zm!bo6U5XCObtyV9VJRB955K0pU>g65$u4`)C2H%aQ2$KHpZD6C9xzyKr$=Dtmgyo4 z&8c78b#n3TJG2GVy#+|y$ z8|>a)>Zjx;jHi9L_+O|um+~i#<*Y32#NX+4Kv(ei4@x2#hP#tSM}npCBpebr&dRhv zEeV9xg&&;R|0naZaL4A_o;SD4Q3xnO9rc9aw~_oKI_xsxT?9&Us^r)T;nH$~E>Tm8 z{XZKVQHJIJ)8GiMLKK3VZmA-;>GmSS(YFwiAT~sE0oV#dvw6AfC-4*-Kf&}zXm=Rj zFM>e}rhotS@1oQ{sgkp!jcRr3aMWb(YjnLZ>Hm#uG}%pfrzh z=MP^)L9si7u?`-Hk}&!)l!X!lrBlulOL|gtYeJn2yuKakER<2eg>tAADin}Ir-mo{ z@a_zh!YNWO{u@C(dBHdhd&A`<0k6X68GYz!Q4|Z;Mba}+Lf&{R5ykUn;YKo=e&WRC zaLr>2f4Kshpc@t*jwnfA+RsI(Mih!p2(?x5Lg8^MF!)pyD&vKo6`9MNLhvbFZ7%!RL%=MFA9}Ah00qA#WNtm0&-EPAXAPq zE$wQGZWJ~3d@Txf1EJyc zk|@*-gbFLejTicj6L+i_w^l;kKxq3b2AviTX(+EKI-oxEGCqAnbK%;Jq~D6naX|@V z3NKf!dgW0;?Zf#I`sgdg4yxe zL5rpye`{V0C#Y!zFI3G7y(S7(^FptSLe@ zFZ2gds3$Ms2 zahI}aXRcoaRR#S-MnOyF4xVJ}BC0#Mg$D-k8U**zLmETpaLo^CtRFf-tU$M@P^^U> z2fA^~$J01&)}M5d?ap5lRzIQzUUxjI_!q!0XVqY8uX;p3kjY*%MKW9hWxC3`U~V#H z8n{{yCe$7(V=gjGBxC;zUP@>Aj5{-3MmyVUyqHCl2fQ6MevDNW%8<-aaMRR`eaZB8 z=KO>l)cSD^-Iz`mEin*1P!dUjZz_oI&lWw+*(bnHCCh5C&op?mN_w6Z_w(Zq1!3?Xiah)bk~rSl&ncgw*P#E z@lmd1<1Nc!Cg3~8aMD0*Kr4Y(0j&n&fYt!51;YE-^^oG5#&}4v38(=G@hy>-f!+Yx0kjk7O-crkt&rIZ^cGMf&>oLAkBlI@V0U%^} z5Yl&m4qO{UX6hJ6&w&!bRwx=g+u>aw_5y;zHUDQ-+wg)kjCZ*S%&8fkwV z!8XgqIoOGEej0X%WzilhzIB7|=V-EqGt222h8gNcM)~>;F9qtWOz`k0?I(L^PaB@=hXlll^k zMsJuKrt3>IVVbby0omh8aajSpD3_f{W>r<2OJj7|lr`)6R+r?3jU?%&;KZ8h^3uz> z_ojJhHH`IR81*NV2ui3U9LI&o^zd`Y2XfX`M-zl4=~1LNxm1=-8xGnCn`N zHYqwOHCSG^y1mpy5(7wTVr*PuTp~CVLuzVrv|dLv#^|JElQEiT zO))xcqTc9@i*m7HTot?-Se4EH1BT#VV6qb{Do9Fhb#8Wgc|OT4$sTJit;i;(nfc}t zV_(g?)&iz~U-Qg@#b*B}*`_cn`L?e~z3egx@?L1^%S?VT!=u9dNx&B}WVmvGaZRfbRA3gn+7J0ZFN`$vTppm>6w} zO|%$Dv>v^MF)=~gKRPBRwPCi=nrcXn=|4B@ctG6(U5UA@e0sT7cPA^!lzpt%eC>|T z4W3I9NM}&<%eCZ|lA^)I#f+s63CWw$M#1lO3A!!UJ(QRG##AM|Q|i0(n`ypVcI5^4-&h*l zKiGR43khjfkIU7Z{9UcPrPke0>oOo|R_FEo@zif!4CimD4L8&V3nb0zE9&ZBD}PkG z1rNxbkhnk_FogIXrPhHk%%!jG))KD|Wx8{+eo@ngeh6;_4%pE>%sb+#1lZ`9Gs5Fy zZ*`9yccXjkT(4Moz0%T?{6U`BRO@w5k>K_0JiC6zx1OKT#|mw;qFJ$AZOJ;(tf-9C zKUV7>sP!8kE4=hraYs?K_kn`(_NKOwZ;V{sAa*<@+!uq`P)h8N2C>&<9q^UZ0?>R0 zsp4)Wu`@;o(LN-bfFt1}Un~SCjAIzFq9H`V%7PGuaS`S*F+vVQmWj`4A&mhXgP9%> zF{W~Rli4tzGLVtS`>PUg9)+Zu>ygU#wtJ+oe=+SXZ+IarMAnf@7{Ye)832M~!PDu0 zB?eqQH)RN$>Z5A|A4WK)4eURZ9pHn#Y0YFZ!m(}O*N3tRK87~%BZM)~w`P(t444?( zz-tih-v+)4FpNNmk?mby(TRJI#&)f*h~P}aSwC)V8tcJD8R2JQ8XM2OH=K>)UWEqS zFT>fA`ih=h>~Pkb(-_&H`U-c;xi9apcF*S0cYfaS#JC^NZGxcI3;~O5D7sdwjbEFw zPW9m1m0!Q~wgVq{W#?wMi8<+enA@lN*Z)xDz_0u)`}k`4D_@z$_jfn#K0vFR#gBC&3Ckm&Lxq&?WX+Pq9C;8O9`I z|Ng1Trc^_U&Xq#d?kS^^28E`WQj)=Y#^_Cnv5A^QgFsL_BzaJ1j5a1l7pphuU<0Q! zB=zU^Ph@}S8l#H}M$#H|#;D-9*#1$$$!d4-lHeq{=1HtS_vs{dr>&vb-9A5uolfa@ z+=I!ig|4*E%4Opix`*4H&xQ@J0OR6~w_6QBct-XH5U5GEgX!@JG;VSV zX3gO9*xvb{O~M5gum(5MT*&Y2SzEn4jI$Q733A-&m2mGBuxT`n^D#rB<|dlif2dII bp|eLWau3XGD5EC!u7#{0V^1hzo9KT5x*cU@ delta 11141 zcmeI2d011|w!qguCxk)5JP#Vd)-jj>2|+~(8I&TTQioenW&{O;3;) zu(rh{VyjGZPImK}jHDQ43Q9BTF@3=9@?I5^y>aXJ7m3uPY+Kk57m3T zd<}dcXo2Z$fnUIn%UY`n=MN|h97#2V!QW1s{w(P1zTi5oa&*Gx2wU>2Pu9E>X_3(TmQuMl5YaAQMkJp}3jO z-SlnnC~0C0U4Y!Xh}99`eD5rljNst-ZZ(>We+V8FJ?tAHQ5IQX7yUZbWPK%#PD}{7 zw*?u$~Qbz7Im?{xX+g@K>0P4?1hS1%0cIyPJPOAjgcm9f5Y);E7# z`s4H$slrzdp1yZz`sojES}uKf#(Rk@vB+&`z1!ISJ`sOpENPzj=jnyYvM#^LZuORg zz8l#4-u(GtRhrKF@9U4uKXv6`Zx?Z};dno%HT^H07o8t4^YH86cz(5&oi=!f*EWxF zvLgA^P1U+JA4pa5KF3Rw&7md}`U&sp9=9 zud33{{NDI@-P^Mo8$PN2ZhzRyIa|{otXaLf_q2~j&n>uk_WhS%i;Ukmx_r;>-Tn!Y z%g3AUA294J?bd1SxCedw+_Y!jx&Ez7|G+^Vam}Or<+f(Z0w6f6SM8y6v zOC=^xlY06;8m?OODThYxtu#mn{XR8+Z?E*h@k7H`sdKN-TJiqSfkQoRzhwzrYB;}a z+SVWT%zixo?X35%QyuFfPkiCD^VGMA9;oH|CGBr_PmJ7q;rmKyl}FazYp!3PbD6VU zeb>2vmot7F?~m#{Z%@~}!-h)}f9>vC+W8?_q+n=bfvX zf4zRRHuH&Pz50WS^C@p0{C3Hq*gEe1qx47T*eyQ}NPf@!;uq%YcNW~4aHsEsE!^-O zC*w^QhCN()xGK|m^wY;>nU}ZUIWyzIkx`uzUVPo0V7YQ|{i5;+*^x8N&DWluTJm$J z=GyROgQu)YOSvC*SBCuYSZUfwxqeP!~^-=i*V?t3PtJ|b=U zx^4ZkTrO5c$`4jv|8wmd-#$EAc6sE_%9tB(8^$%3zrACx-)FrS-F~{HQ7FGQ{pdCr z=~U{K)#vLS116*|xw&#o!sO9EJjxH>Ri9uQ36BRwE3OPQ^{Pm6T7|LV%Z8~H{(+lL z2pZb z!H*4i@FN}!e-#sq2%~EiKvxfd*RkAzrBgLPBu2EUST4ens{we=3*af1A>II!rvWU$ z@^dVI!ZK$%fYAq_Y9^*JKY*fIfO-A^;|&1Q0|3Su0crvPUabRI7KBMKVHUz*0P$>q zfgyMUbMOX20RmqGkcT0kiyY%w34D4D8unSE!&xC>|dWhviEPq~xf~K0W90e^? z$DyD_3Rj?@C04COK})Pyg@Qe=SdD@`&qe>``Zj2Gzvb>VJv}US;niN*_o}z|^FLsI zz{#?R*p~+6z9=hqp)L2JZ5x2wzm}wtaE`1aBRs+h!KhC_0QCE&&p(=A2ye{-#1mW? zFRVZ>!}AQg){bE}+cETYJBGb$$9x@`!FFMEXuF2!J7oQzyFv70yLRZ)b`1U7j?vu3 z@0qAA z4XjlQRU$+sEP4Ljs)M@bc}~w-bx;?vgf1JY4tLaH;5ThmLjA_Cu`8ke!#bN1-+y}} z)TJHiI1GM3U0X%prY(nZ{aUORI*jY7P&{g}zD=QrH7>1(Enu4Hc+%i_VmbT@Zwz-s z-F!E{&;fg~1J=C*)}sT~(~(WEjp1I7(8hXq!1{E+Bv$tPSdVILXHqowbg)FDgIO9J zPb`fKgDpTkM=jik?haaKJN-0mI@()gd5(N{G>!q>DXb;_rXI&aOw*1@O-aX;ridE> zrp99$=lSmeRR8_C07Al-k0Rm3g`2vL$d?`$c#DOe)?LU<987Nb&NBHQ??SRn^5b#- z&qonD=tK~1syp7j=kqlfLTSx&)0_@=+WOpa--PFD=&G6D8e?obhH=)aq3b7n4RjLl zHBhVZ8AfEQhNE4I{d^7W{6zzMCW3U@eHftfOMpMlcHl$P-LsQqjqcC9C&1v7<@W5{ z33nk)B2R1Bq23kZyUDchTqbX}(Tu_G3H2zSQIGN&4OM(b{mW<6zirH(F{p#vpl!Bc zQf=&y3PB~%^4a~`5mC?lFw+mhP1$)DA` zfD8AUD@i5c=JT#(5aYJ$UjSj4^4%Hk{uMIZwu);F!d&S(qIiMc(guf1&|7K@c&3tG zGK-57kx2aVI1%a38%O^?d+Dn8e>`^ctp0y-_L@(65`W=;n7%kFodU>M;?doOfOi;y zwStID$(g6w{&(7%_Y2uEDk;yij7|9~*&Vx=(z_kS}jD&03 zjo2C3f(^|rd`2fApV8dHXEe98F?$}N$)ye2E<$q)pV8dHXEe9)8O<$xMso|FagxrY zw#^9NSUXJ9y{~OyVI-}L4i-DJ8-a#;KBJ+Y&uFOUGaBmKn8Ma!8tdDjjnPogXEf9! zGiP-ndT$IVXQgC4uMcz;%>No)1@jqQ1@oDt14j3={B}}DW_P5_5!(6?-2sc~fW>ye zSDY-lUvg4CoxudBnc3jMipG!Xd0F>5@q4|}?Y;12~FH~5TZH9n(pgU@K(Xk&IW(ZJCLZDyi@gU@K(;4>OG zkeM~3iNBlMDg1Ucrtle!DSSp_3XoRE7|s1&Bc(yYsD%W6 zHaYaN)wSVtkuvwM^)cAfe&e>NZpI$>aTC^=3247`xP;Y^H@dP6h`E-}$+*9G8E*9# zWKWy0lh5cbuZ=~JS38LNt-hpw!-m|?Uy^#v zy|11om3~6~83N_k9IW7AXvGV3!MefqS+cb*SRKxBfe9Np_ZuYTuNlj}W4GJHF}E6R zU9ja=?(7Xx&zs8Bg!WNnpUTvPd`3;kXV$g5ZCPOdE;S*)o#V&{`vV!rp>O}PqF}v-kkK3R_800e=2KkJJK|Z6)CuH1!7OTnJeh~AN;lwX7Lhep7BQ(2& zG7nhC^Da!WfQZbMk<2{8v>41S-Ix~EdeDP0xfYpoLNwAf0GOozuYcr3+D>~w2;H8M3sqfYug z9V8)*x9W;UuCwY=Sg%2~D*aHE43%iGp~m*rICF9|Gh}G;6dbJM;T-IOJnJU|4+V5} z(qd@O7bEYe{YA>n-_U=a!ry3lyT;}j~H*~Eo{K@7G{8fJ~~)} z-ZP=RjY5CdUyedKhvgcSl_;xFR-;h97RzlY>rpnKY(&|FvKeIy%2t#WC_7Q!LD`P7 z17#P=UXGU^sfHWN^po;)E1V$Y9e_l}O~|+&Mdv6fX^MW!wUQ#Ftm(>0OHR2QtCs^bZ4hpvS+MiCY2>gl7?usa-&wIGOA-mMyKfcTH}g|W!WVl))f`!muINO z`jQg;6oD`mwUz13LLK|9le>#xjJ|Agj$S``a*+8_3R^?Cyi~S$NvVe~O@u;xvLnE! zKMdO0VjwN|FcfYkJ~D9zBJk?cIL*{NcgB1$S2 zq~+8d6%Q@SDGSOjtAP|C0T|JYOlrDLUsh7?G7#gJ5YjqLnIjMCziFC_x~RMk_$-t5nBoq)ACktZRDmFiqN+^f?*af?=$}@Q%@SVI!!5 zK&^^bYNM4nxl}s2N)n4xI##08M9XlR$HgV7iuuNYOH4`t;U*1!FLK0{Sn zs>!Z^?2MuM-0b2EcsakMG(%gRo0VUzjFL9yCMl!t}RoFe0q7?@%75TxLMk;~#fOLXjguqSOjkwor{Fvx|Tp!_?v(^=SuR!$$Cisdey)Zw&B4)>6 zJjz;{-zcvz7VQXmhmGFDhFx(RvI!>1uB`u8(~iy&q>kw`BFFuzDI&rk=)DPZ%qEwY z3yaEeSb=q14ThjmV)o??9z{?+CaGq!0CJjeE=`7zk~>b(e>&-XVxY0aXV0F?lYO!e zhe(eOiy`@Cw{ug4W3}=2Jpf<%XH62!bHyzMsw_s9^a5=;c1ygXb~!(ajY&d zfsZi$mf#fJ&zu8w27dk^Hd;6gLle%^!H;R1>i+u{8gY@#u;0E#}ToUUa5XfmxtK-`G?2;{=I*Wdf&T>H}_qi zxZ2JaYzZ&h(<{)R*|p2k6?2Mw){msqDhr9?GV|C_b3p+sAWTRdS3HsZh|OO&mg`x_Mp5uL zT3%1*7TC%UvBWRmDrEaIeI|0jML4c$ImwELOk#Vn6%~4}auPd%q?<2HVz)44iMghP z{e>MBr;F1llC;`*xhxvh||RB z6!BVhe4GNa3YB;{w|^>o%R5@pM@&T~jl<7ac?`Fsj6H2Omb2A_G;xnBSOb}3uBl|> z7_yJsU&Ti1iqT?p12G519fhtG>2p^6Lk#Ybaan~zcSY}@C+K5K0ZLv?mGzkB0Jefl>;M1& diff --git a/acs/nladmin-system/src/main/resources/config/application-dev.yml b/acs/nladmin-system/src/main/resources/config/application-dev.yml index 64f07d5..d4bbec2 100644 --- a/acs/nladmin-system/src/main/resources/config/application-dev.yml +++ b/acs/nladmin-system/src/main/resources/config/application-dev.yml @@ -1,12 +1,17 @@ server: port: 8010 + tomcat: + accept-count: 1000 + max-connections: 10000 + max-threads: 800 + min-spare-threads: 100 #配置数据源 spring: datasource: druid: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy - # url: jdbc:log4jdbc:mysql://${DB_HOST:47.111.78.178}:${DB_PORT:3306}/${DB_NAME:lzhl_one_wcs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + # url: jdbc:log4jdbc:mysql://${DB_HOST:10.1.3.91}:${DB_PORT:3306}/${DB_NAME:acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true # url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:lzhl_one_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:lzhl_one_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true username: ${DB_USER:root} @@ -131,7 +136,7 @@ file: avatarMaxSize: 5 logging: file: - path: C:\log\wms + path: D:\acs_log config: classpath:logback-spring.xml # Sa-Token配置 @@ -155,5 +160,5 @@ sa-token: token-prefix: Bearer loki: - url: http://localhost:3100/loki/api/v1 + url: http://127.0.0.1:3100/loki/api/v1 systemName: acs diff --git a/acs/nladmin-system/src/main/resources/config/application-prod.yml b/acs/nladmin-system/src/main/resources/config/application-prod.yml index 47dada2..e6113d9 100644 --- a/acs/nladmin-system/src/main/resources/config/application-prod.yml +++ b/acs/nladmin-system/src/main/resources/config/application-prod.yml @@ -1,12 +1,17 @@ server: - port: 8010 + port: 8011 + tomcat: + accept-count: 1000 + max-connections: 10000 + max-threads: 800 + min-spare-threads: 100 #配置数据源 spring: datasource: druid: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy - url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:lzhl}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + url: jdbc:log4jdbc:mysql://${DB_HOST:10.1.3.91}:${DB_PORT:3306}/${DB_NAME:acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true username: ${DB_USER:root} password: ${DB_PWD:123456} # 初始连接数 @@ -53,7 +58,7 @@ spring: multi-statement-allow: true redis: #数据库索引 - database: ${REDIS_DB:15} + database: ${REDIS_DB:9} host: ${REDIS_HOST:127.0.0.1} port: ${REDIS_PORT:6379} password: ${REDIS_PWD:} @@ -135,7 +140,7 @@ file: avatarMaxSize: 5 logging: file: - path: /app/jar/logs + path: D:\acs_log config: classpath:logback-spring.xml # Sa-Token配置 diff --git a/acs/nladmin-system/src/main/resources/config/application-test.yml b/acs/nladmin-system/src/main/resources/config/application-test.yml index 250e563..4a18ca4 100644 --- a/acs/nladmin-system/src/main/resources/config/application-test.yml +++ b/acs/nladmin-system/src/main/resources/config/application-test.yml @@ -1,42 +1,22 @@ server: - port: 8010 -#ERP系统相关 -erp: - oracle: - enabled: false - jdbcurl: jdbc:oracle:thin:@192.168.81.251:1522:ORCL2 - username: system - password: 123456 - sqlserver: - enabled: false - jdbcurl: jdbc:sqlserver://47.97.157.227:1433;DatabaseName=testdb-lx - username: sa - password: Nl@123 - + port: 8011 #配置数据源 spring: datasource: druid: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy - # url: jdbc:log4jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:whxr}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true - url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:whxr_mes1}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + url: jdbc:log4jdbc:mysql://${DB_HOST:10.1.3.91}:${DB_PORT:3306}/${DB_NAME:acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true username: ${DB_USER:root} - password: ${DB_PWD:Root.123456} - # username: ${DB_USER:root} - # password: ${DB_PWD:root} + password: ${DB_PWD:123456} # 初始连接数 initial-size: 5 # 最小连接数 min-idle: 15 # 最大连接数 - max-active: 30 - # 是否自动回收超时连接 - remove-abandoned: true - # 超时时间(以秒数为单位) - remove-abandoned-timeout: 180 + max-active: 60 # 获取连接超时时间 - max-wait: 3000 + max-wait: 5000 # 连接有效性检测时间 time-between-eviction-runs-millis: 60000 # 连接在池中最小生存的时间 @@ -56,8 +36,11 @@ spring: enabled: true stat-view-servlet: enabled: true + # 控制台管理用户名和密码 url-pattern: /druid/* reset-enable: false + login-username: admin + login-password: 123456 filter: stat: enabled: true @@ -70,16 +53,16 @@ spring: multi-statement-allow: true redis: #数据库索引 - database: ${REDIS_DB:1} - host: ${REDIS_HOST:47.111.78.178} + database: ${REDIS_DB:9} + host: ${REDIS_HOST:127.0.0.1} port: ${REDIS_PORT:6379} password: ${REDIS_PWD:} #连接超时时间 - timeout: 10000 + timeout: 5000 # 登录相关配置 login: # 登录缓存 - cache-enable: false + cache-enable: true # 是否限制单用户登录 single-login: false # 验证码 @@ -94,7 +77,7 @@ login: heigth: 36 # 内容长度 length: 2 - # 字体名称,为空则使用默认字体 + # 字体名称,为空则使用默认字体,如遇到线上乱码,设置其他字体即可 font-name: # 字体大小 font-size: 25 @@ -106,29 +89,36 @@ jwt: token-start-with: Bearer # 必须使用最少88位的Base64对该令牌进行编码 base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI= - # 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html - token-validity-in-seconds: 14400000 + # 令牌过期时间 此处单位/毫秒 ,默认2小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html + token-validity-in-seconds: 7200000 # 在线用户key online-key: online-token- # 验证码 code-key: code-key- - # token 续期检查时间范围(默认30分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期 + # token 续期检查时间范围(默认30分钟,单位默认毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期 detect: 1800000 - # 续期时间范围,默认1小时,单位毫秒 + # 续期时间范围,默认 1小时,这里单位毫秒 renew: 3600000 -#是否允许生成代码,生产环境设置为false -generator: - enabled: true - -#是否开启 swagger-ui -swagger: - enabled: true - # IP 本地解析 ip: local-parsing: true +#是否允许生成代码,生产环境设置为false +generator: + enabled: false + +#如果生产环境要开启swagger,需要配置请求地址 +#springfox: +# documentation: +# swagger: +# v2: +# host: # 接口域名或外网ip + +#是否开启 swagger-ui +swagger: + enabled: false + # 文件存储路径 file: mac: @@ -145,5 +135,29 @@ file: avatarMaxSize: 5 logging: file: - path: C:\log\wms + path: /app/jar/logs config: classpath:logback-spring.xml + +# Sa-Token配置 +sa-token: + # token 名称 (同时也是cookie名称) + token-name: Authorization + # token 有效期,单位s 默认30天, -1代表永不过期 + timeout: 2592000 + # token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒 + activity-timeout: -1 + # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) + is-concurrent: true + # 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token) + is-share: false + # token风格 + token-style: random-128 + # 是否输出操作日志 + is-log: false + jwt-secret-key: opsjajisdnnca0sdkksdfaaasdfwwq + # token 前缀 + token-prefix: Bearer + +loki: + url: http://localhost:3100/loki/api/v1 + systemName: acs diff --git a/acs/nladmin-system/src/main/resources/config/application.yml b/acs/nladmin-system/src/main/resources/config/application.yml index 7e3fbea..f943602 100644 --- a/acs/nladmin-system/src/main/resources/config/application.yml +++ b/acs/nladmin-system/src/main/resources/config/application.yml @@ -44,7 +44,7 @@ rsa: private_key: MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9pB6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZUBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3tTbklZkD2A== logging: file: - path: C:\log\wms + path: D:\acs_log config: classpath:logback-spring.xml # sa-token白名单配置 security: diff --git a/acs/nladmin-system/src/main/resources/log/AcsToLk.xml b/acs/nladmin-system/src/main/resources/log/AcsToLk.xml new file mode 100644 index 0000000..c8c2d04 --- /dev/null +++ b/acs/nladmin-system/src/main/resources/log/AcsToLk.xml @@ -0,0 +1,33 @@ + + + + + + + + + ${LOG_HOME}/ACS请求立库/%d{yyyy-MM-dd}.%i.log + + 15 + + 200MB + + 2GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + ${log.charset} + + + + + + + + + + + diff --git a/acs/nladmin-system/src/main/resources/log/AcsToWms.xml b/acs/nladmin-system/src/main/resources/log/AcsToWms.xml new file mode 100644 index 0000000..1fd47da --- /dev/null +++ b/acs/nladmin-system/src/main/resources/log/AcsToWms.xml @@ -0,0 +1,33 @@ + + + + + + + + + ${LOG_HOME}/ACS请求WMS/%d{yyyy-MM-dd}.%i.log + + 15 + + 200MB + + 2GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + ${log.charset} + + + + + + + + + + + diff --git a/acs/nladmin-system/src/main/resources/log/AgvNdcOneDeviceDriver.xml b/acs/nladmin-system/src/main/resources/log/AgvNdcOneDeviceDriver.xml new file mode 100644 index 0000000..cb94a38 --- /dev/null +++ b/acs/nladmin-system/src/main/resources/log/AgvNdcOneDeviceDriver.xml @@ -0,0 +1,33 @@ + + + + + + + + + ${LOG_HOME}/AgvNdcOneDeviceDriver/%d{yyyy-MM-dd}.%i.log + + 15 + + 200MB + + 2GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + ${log.charset} + + + + + + + + + + + diff --git a/acs/nladmin-system/src/main/resources/log/AutoCreateInst.xml b/acs/nladmin-system/src/main/resources/log/AutoCreateInst.xml new file mode 100644 index 0000000..cf6996b --- /dev/null +++ b/acs/nladmin-system/src/main/resources/log/AutoCreateInst.xml @@ -0,0 +1,32 @@ + + + + + + + + + ${LOG_HOME}/自动创建指令/%d{yyyy-MM-dd}.%i.log + + 15 + + 200MB + + 2GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + ${log.charset} + + + + + + + + + + diff --git a/acs/nladmin-system/src/main/resources/log/LkToAcs.xml b/acs/nladmin-system/src/main/resources/log/LkToAcs.xml new file mode 100644 index 0000000..2df63ce --- /dev/null +++ b/acs/nladmin-system/src/main/resources/log/LkToAcs.xml @@ -0,0 +1,33 @@ + + + + + + + + + ${LOG_HOME}/立库请求ACS/%d{yyyy-MM-dd}.%i.log + + 15 + + 200MB + + 2GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + ${log.charset} + + + + + + + + + + + diff --git a/acs/nladmin-system/src/main/resources/log/OneNDCSocketConnectionAutoRun.xml b/acs/nladmin-system/src/main/resources/log/OneNDCSocketConnectionAutoRun.xml new file mode 100644 index 0000000..7387ef7 --- /dev/null +++ b/acs/nladmin-system/src/main/resources/log/OneNDCSocketConnectionAutoRun.xml @@ -0,0 +1,33 @@ + + + + + + + + + ${LOG_HOME}/一楼NDC系统/%d{yyyy-MM-dd}.%i.log + + 15 + + 200MB + + 2GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + ${log.charset} + + + + + + + + + + + diff --git a/acs/nladmin-system/src/main/resources/log/OpcUtil.xml b/acs/nladmin-system/src/main/resources/log/OpcUtil.xml new file mode 100644 index 0000000..2db9428 --- /dev/null +++ b/acs/nladmin-system/src/main/resources/log/OpcUtil.xml @@ -0,0 +1,33 @@ + + + + + + + + + ${LOG_HOME}/下发KEP信号/%d{yyyy-MM-dd}.%i.log + + 15 + + 200MB + + 2GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + ${log.charset} + + + + + + + + + + + diff --git a/acs/nladmin-system/src/main/resources/log/WmsToAcs.xml b/acs/nladmin-system/src/main/resources/log/WmsToAcs.xml new file mode 100644 index 0000000..9c26bda --- /dev/null +++ b/acs/nladmin-system/src/main/resources/log/WmsToAcs.xml @@ -0,0 +1,33 @@ + + + + + + + + + ${LOG_HOME}/WMS下发ACS/%d{yyyy-MM-dd}.%i.log + + 15 + + 200MB + + 2GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + ${log.charset} + + + + + + + + + + + diff --git a/acs/nladmin-system/src/main/resources/logback-spring.xml b/acs/nladmin-system/src/main/resources/logback-spring.xml index 4edd8e5..15d2500 100644 --- a/acs/nladmin-system/src/main/resources/logback-spring.xml +++ b/acs/nladmin-system/src/main/resources/logback-spring.xml @@ -29,8 +29,18 @@ https://juejin.cn/post/6844903775631572999 - --> + --> + + + + + + + + + + @@ -39,6 +49,7 @@ https://juejin.cn/post/6844903775631572999 + @@ -81,15 +92,37 @@ https://juejin.cn/post/6844903775631572999 + + + error + + + + ${LOG_HOME}/ERROR/%d{yyyy-MM-dd}.%i.log + + 15 + + 200MB + + 20GB + + + ${log.pattern} + ${log.charset} + + + + + @@ -130,52 +163,49 @@ https://juejin.cn/post/6844903775631572999 - + - - + + - - + + + - + - + + + - - + - - + - - + - - + - - + - - + diff --git a/acs/nladmin-ui/.env.production b/acs/nladmin-ui/.env.production index 762ac12..9be6cba 100644 --- a/acs/nladmin-ui/.env.production +++ b/acs/nladmin-ui/.env.production @@ -2,6 +2,6 @@ ENV = 'production' # 如果使用 Nginx 代理后端接口,那么此处需要改为 '/',文件查看 Docker 部署篇,Nginx 配置 # 接口地址,注意协议,如果你没有配置 ssl,需要将 https 改为 http -VUE_APP_BASE_API = 'http://127.0.0.1:8010' +VUE_APP_BASE_API = 'http://10.1.3.90:8011' # 如果接口是 http 形式, wss 需要改为 ws -VUE_APP_WS_API = 'ws://127.0.0.1:8010' +VUE_APP_WS_API = 'ws://10.1.3.90:8011' diff --git a/acs/nladmin-ui/src/App.vue b/acs/nladmin-ui/src/App.vue index 2f82bcc..bd570a9 100644 --- a/acs/nladmin-ui/src/App.vue +++ b/acs/nladmin-ui/src/App.vue @@ -24,7 +24,7 @@ export default { this.timmer = setTimeout(() => { sessionStorage.clear() this.logout() - }, 1000 * 60 * 15) // 15分钟 https://blog.csdn.net/qq_42345108/article/details/103496456 + }, 1000 * 60 * 60) // 15分钟 https://blog.csdn.net/qq_42345108/article/details/103496456 }, logout() { this.$store.dispatch('LogOut').then(() => { diff --git a/acs/nladmin-ui/src/api/acs/instruction/instruction.js b/acs/nladmin-ui/src/api/acs/instruction/instruction.js index 5d8bec0..df0cda5 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/device/config.vue b/acs/nladmin-ui/src/views/acs/device/config.vue index fc36312..477cdc6 100644 --- a/acs/nladmin-ui/src/views/acs/device/config.vue +++ b/acs/nladmin-ui/src/views/acs/device/config.vue @@ -92,7 +92,9 @@ import siemens_conveyor from '@/views/acs/device/driver/siemens_conveyor' import slit_two_manipulator from '@/views/acs/device/driver/slit_two_manipulator' import hongxiang_device from '@/views/acs/device/driver/hongxiang_device' import hongxiang_conveyor from '@/views/acs/device/driver/hongxiang_conveyor' - +import plug_pull_device_site from '@/views/acs/device/driver/plug_pull_device_site' +import siemens_conveyor_labeling from '@/views/acs/device/driver/siemens_conveyor_labeling' +import siemens_conveyor_ckk from '@/views/acs/device/driver/siemens_conveyor_ckk' export default { name: 'DeviceConfig', @@ -115,7 +117,10 @@ export default { box_palletizing_manipulator, oven_manipulator, siemens_conveyor, - slit_two_manipulator + slit_two_manipulator, + plug_pull_device_site, + siemens_conveyor_labeling, + siemens_conveyor_ckk }, dicts: ['device_type'], mixins: [crud], diff --git a/acs/nladmin-ui/src/views/acs/device/driver/hongxiang_conveyor.vue b/acs/nladmin-ui/src/views/acs/device/driver/hongxiang_conveyor.vue index 8f23c7a..e0d20f8 100644 --- a/acs/nladmin-ui/src/views/acs/device/driver/hongxiang_conveyor.vue +++ b/acs/nladmin-ui/src/views/acs/device/driver/hongxiang_conveyor.vue @@ -222,6 +222,14 @@ /> + + + + + + + + + + + + + + + + + + + + + + + + @@ -125,10 +127,11 @@ import { get } from '@/api/system/dictDetail' import { selectOpcList } from '@/api/acs/device/opc' import { download } from '@/api/data' import { downloadFile } from '@/utils' +import pagination from '@crud/Pagination' export default { name: 'Protocol', - components: { crudOperation, rrOperation }, + components: { crudOperation, rrOperation, pagination }, mixins: [presenter(), header(), crud()], cruds() { return CRUD({ diff --git a/acs/nladmin-ui/src/views/acs/history/taskTreeRecord/index.vue b/acs/nladmin-ui/src/views/acs/history/taskTreeRecord/index.vue index da57075..ac8fd51 100644 --- a/acs/nladmin-ui/src/views/acs/history/taskTreeRecord/index.vue +++ b/acs/nladmin-ui/src/views/acs/history/taskTreeRecord/index.vue @@ -99,6 +99,8 @@ + + diff --git a/acs/nladmin-ui/src/views/acs/instruction/index.vue b/acs/nladmin-ui/src/views/acs/instruction/index.vue index 7d5c0ed..49d8b8f 100644 --- a/acs/nladmin-ui/src/views/acs/instruction/index.vue +++ b/acs/nladmin-ui/src/views/acs/instruction/index.vue @@ -55,6 +55,18 @@ class="filter-item" @keyup.enter.native="crud.toQuery" /> + + + @@ -109,8 +121,12 @@ - - + + + + @@ -128,20 +144,21 @@ - + + - - - - - - - - - + + + + + + + + + @@ -163,12 +180,14 @@ 完成 取消 强制取消 + 初始化 + @@ -178,6 +197,7 @@ import crudInstruction from '@/api/acs/instruction/instruction' import CRUD, { presenter, header, form, crud } from '@crud/crud' import crudOperation from '@crud/CRUD.operation' import { getDicts } from '@/api/system/dict' +import pagination from '@crud/Pagination' const defaultForm = { instruction_id: null, @@ -216,9 +236,9 @@ const defaultForm = { update_time: null } export default { - dicts: ['task_status'], + dicts: ['task_status', 'task_type'], name: 'Instruction', - components: { crudOperation }, + components: { crudOperation, pagination }, mixins: [presenter(), header(), form(defaultForm), crud()], cruds() { return CRUD({ @@ -301,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() @@ -327,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/acs/monitor/device/index.vue b/acs/nladmin-ui/src/views/acs/monitor/device/index.vue index a06ec01..d800fc2 100644 --- a/acs/nladmin-ui/src/views/acs/monitor/device/index.vue +++ b/acs/nladmin-ui/src/views/acs/monitor/device/index.vue @@ -416,26 +416,26 @@ export default { } else if (val === 'full_ready_req_agv') { const obj = { name: '满箱位就绪,请求AGV', value: data[val] } arr.push(obj) - } else if (val === 'full_out') { - const obj = { name: '满箱已运出满箱位', value: data[val] } + } else if (val === 'temperature') { + const obj = { name: '当前温度', value: data[val] } arr.push(obj) } else if (val === 'finish') { - const obj = { name: '订单完成', value: data[val] } + const obj = { name: '烘箱完成', value: data[val] } arr.push(obj) - } else if (val === 'order_compel_finish') { - const obj = { name: '订单强制完成', value: data[val] } + } else if (val === 'countdown_house') { + const obj = { name: '恒温倒计时(时)', value: data[val] } arr.push(obj) - } else if (val === 'now_order_prod_num') { - const obj = { name: '当前生产总量', value: data[val] } + } else if (val === 'countdown_min') { + const obj = { name: '恒温倒计时(分)', value: data[val] } arr.push(obj) - } else if (val === 'now_one_prod_num') { - const obj = { name: '当前箱生产量', value: data[val] } + } else if (val === 'countdown_sec') { + const obj = { name: '恒温倒计时(秒)', value: data[val] } arr.push(obj) } else if (val === 'task') { const obj = { name: '任务号', value: data[val] } arr.push(obj) - } else if (val === 'full_number') { - const obj = { name: '出料口满框数量', value: data[val] } + } else if (val === 'door') { + const obj = { name: '门状态', value: data[val] } arr.push(obj) } else if (val === 'storage_stock_num') { const obj = { name: '储料仓库存数量', value: data[val] } diff --git a/acs/nladmin-ui/src/views/acs/monitor/device/index2.vue b/acs/nladmin-ui/src/views/acs/monitor/device/index2.vue index a06ec01..febabca 100644 --- a/acs/nladmin-ui/src/views/acs/monitor/device/index2.vue +++ b/acs/nladmin-ui/src/views/acs/monitor/device/index2.vue @@ -420,7 +420,19 @@ export default { const obj = { name: '满箱已运出满箱位', value: data[val] } arr.push(obj) } else if (val === 'finish') { - const obj = { name: '订单完成', value: data[val] } + const obj = { name: '烘箱完成', value: data[val] } + arr.push(obj) + } else if (val === 'countdown_house') { + const obj = { name: '恒温倒计时(时)', value: data[val] } + arr.push(obj) + } else if (val === 'countdown_min') { + const obj = { name: '恒温倒计时(分)', value: data[val] } + arr.push(obj) + } else if (val === 'countdown_sec') { + const obj = { name: '恒温倒计时(秒)', value: data[val] } + arr.push(obj) + } else if (val === 'door') { + const obj = { name: '门状态', value: data[val] } arr.push(obj) } else if (val === 'order_compel_finish') { const obj = { name: '订单强制完成', value: data[val] } diff --git a/acs/nladmin-ui/src/views/acs/task/index.vue b/acs/nladmin-ui/src/views/acs/task/index.vue index 999e564..7b7d4dd 100644 --- a/acs/nladmin-ui/src/views/acs/task/index.vue +++ b/acs/nladmin-ui/src/views/acs/task/index.vue @@ -55,6 +55,18 @@ class="filter-item" @keyup.enter.native="crud.toQuery" /> + + + @@ -117,7 +129,7 @@ /> - + - + - + - + - + - - - - - - - - - + + + + + + + + + diff --git a/acs/nladmin-ui/src/views/monitor/interfaceLog/index.vue b/acs/nladmin-ui/src/views/monitor/interfaceLog/index.vue new file mode 100644 index 0000000..3999c89 --- /dev/null +++ b/acs/nladmin-ui/src/views/monitor/interfaceLog/index.vue @@ -0,0 +1,120 @@ + + + + + diff --git a/acs/nladmin-ui/src/views/monitor/interfaceLog/interfaceLog.js b/acs/nladmin-ui/src/views/monitor/interfaceLog/interfaceLog.js new file mode 100644 index 0000000..fed5509 --- /dev/null +++ b/acs/nladmin-ui/src/views/monitor/interfaceLog/interfaceLog.js @@ -0,0 +1,22 @@ +import request from '@/utils/request' + +export function add(data) { + return request({ + url: 'api/interfaceLog', + method: 'post', + data + }) +} +export function delLogs() { + return request({ + url: 'api/interfaceLog/delLogs', + method: 'delete' + }) +} +export function getLogTypeList() { + return request({ + url: 'api/interfaceLog/logTypeList', + method: 'get' + }) +} +export default { add, delLogs, getLogTypeList } diff --git a/acs/nladmin-ui/src/views/monitor/interfaceLog/search.vue b/acs/nladmin-ui/src/views/monitor/interfaceLog/search.vue new file mode 100644 index 0000000..e1eb1fa --- /dev/null +++ b/acs/nladmin-ui/src/views/monitor/interfaceLog/search.vue @@ -0,0 +1,49 @@ + + + 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 7cfd2c2..fc0af8e 100644 --- a/acs/nladmin-ui/src/views/system/monitor/device/index.vue +++ b/acs/nladmin-ui/src/views/system/monitor/device/index.vue @@ -85,6 +85,12 @@ 禁用 + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -159,6 +189,7 @@ export default { dialogFormVisible3: false, dialogFormVisible4: false, dialogFormVisible5: false, + dialogFormVisible6: false, form: { device_code: '', hasGoodStatus: null, @@ -167,7 +198,8 @@ export default { material_type: '', requireSucess: '', fullrequireSucess: '', - is_disable: '' + is_disable: '', + applySucess: '' }, allDeviceMsg: [], msgTop: '200px', @@ -289,6 +321,7 @@ export default { if (clickObj.data.device_type === 'scanner') { // 扫码器 this.dialogFormVisible1 = true } else { + console.log(clickObj.data.driver_type) if (clickObj.data.driver_type === 'standard_ordinary_site') { this.dialogFormVisible3 = true } else if (clickObj.data.driver_type === 'hailiang_packer_station') { @@ -299,6 +332,8 @@ export default { this.dialogFormVisible4 = true } else if (clickObj.data.driver_type === 'siemens_conveyor') { this.dialogFormVisible5 = true + } else if (clickObj.data.driver_type === 'standard_conveyor_control_with_scanner') { + this.dialogFormVisible6 = true } else { this.dialogFormVisible = true } @@ -311,6 +346,7 @@ export default { this.form.requireSucess = clickObj.data.requireSucess this.form.fullrequireSucess = clickObj.data.fullrequireSucess this.form.is_disable = clickObj.data.is_disable1 + this.form.applySucess = clickObj.data.applySucess }, moveShow(nodeData) { // 点击之后显示出来的数据----只需要设备信息 let item = '' @@ -357,21 +393,33 @@ export default { } else if (val === 'number') { const obj = { name: '托盘数量', value: data[val] } this.arr.push(obj) - } else if (val === 'instruction_message') { + } else if (val === 'inst_message') { const obj = { name: '指令信息', value: data[val] } this.arr.push(obj) - } else if (val === 'last_instruction_message') { + } else if (val === 'message') { + const obj = { name: '备注信息', value: data[val] } + this.arr.push(obj) + } else if (val === 'inst_message') { + const obj = { name: '当前指令信息', value: data[val] } + this.arr.push(obj) + } else if (val === 'last_inst_message') { const obj = { name: '上次指令信息', value: data[val] } this.arr.push(obj) - } else if (val === 'container') { + } else if (val === 'barcode') { const obj = { name: '载具号', value: data[val] } this.arr.push(obj) + } else if (val === 'barcode_length') { + const obj = { name: '载具长度', value: data[val] } + this.arr.push(obj) } else if (val === 'last_container') { const obj = { name: '上次载具号', value: data[val] } this.arr.push(obj) } else if (val === 'instruction_code') { const obj = { name: '指令号', value: data[val] } this.arr.push(obj) + } else if (val === 'task_code') { + const obj = { name: '任务号', value: data[val] } + this.arr.push(obj) } else if (val === 'last_instruction_code') { const obj = { name: '上次指令号', value: data[val] } this.arr.push(obj) @@ -393,87 +441,21 @@ export default { } else if (val === 'applySucess') { const obj = { name: '是否申请指令', value: data[val] } this.arr.push(obj) - } else if (val === 'message') { - const obj = { name: '说明', value: data[val] } + } else if (val === 'requireApplyLabelingSuccess') { + const obj = { name: '是否申请贴标', value: data[val] } + this.arr.push(obj) + } else if (val === 'requireApplyLaStrangulationSuccess') { + const obj = { name: '是否申请捆扎', value: data[val] } this.arr.push(obj) } else if (val === 'status') { const obj = { name: '设备状态', value: data[val] } this.arr.push(obj) - } else if (val === 'open_time') { - const obj = { name: '开机时间', value: data[val] } - this.arr.push(obj) - } else if (val === 'close_time') { - const obj = { name: '关机时间', value: data[val] } - this.arr.push(obj) - } else if (val === 'standby_time') { - const obj = { name: '待机时间', value: data[val] } - this.arr.push(obj) - } else if (val === 'production_time') { - const obj = { name: '生产时间', value: data[val] } - this.arr.push(obj) - } else if (val === 'error_time') { - const obj = { name: '故障时间', value: data[val] } - this.arr.push(obj) } else if (val === 'weight') { - const obj = { name: '生产重量', value: data[val] } - this.arr.push(obj) - } else if (val === 'order_No') { - const obj = { name: '工单号', value: data[val] } - this.arr.push(obj) - } else if (val === 'mix_num') { - const obj = { name: '碾次', value: data[val] } - this.arr.push(obj) - } else if (val === 'barcode') { - const obj = { name: '条码', value: data[val] } - this.arr.push(obj) - } else if (val === 'qualified') { - const obj = { name: '合格数量', value: data[val] } - this.arr.push(obj) - } else if (val === 'unqualified') { - const obj = { name: '不合格数量', value: data[val] } - this.arr.push(obj) - } else if (val === 'put_station') { - const obj = { name: '当前码盘工位', value: data[val] } - this.arr.push(obj) - } else if (val === 'encoder_qty') { - const obj = { name: '码盘数量', value: data[val] } - this.arr.push(obj) - } else if (val === 'outKiln_move') { - const obj = { name: '出窑光电', value: data[val] } - this.arr.push(obj) - } else if (val === 'outKiln_barcode') { - const obj = { name: '出窑条码', value: data[val] } - this.arr.push(obj) - } else if (val === 'outKiln_device') { - const obj = { name: '出窑设备', value: data[val] } - this.arr.push(obj) - } else if (val === 'car_sum') { - const obj = { name: '窑车总数', value: data[val] } - this.arr.push(obj) - } else if (val === 'nullCar_qty') { - const obj = { name: '空窑车数', value: data[val] } - this.arr.push(obj) - } else if (val === 'burning_car_qty') { - const obj = { name: '在烧窑车数', value: data[val] } - this.arr.push(obj) - } else if (val === 'container_qty') { - const obj = { name: '托盘数', value: data[val] } + const obj = { name: '重量', value: data[val] } this.arr.push(obj) } else if (val === 'tray_crib_qty') { const obj = { name: '托盘垛数', value: data[val] } this.arr.push(obj) - } else if (val === 'total_container') { - const obj = { name: '托盘总数量', value: data[val] } - this.arr.push(obj) - } else if (val === 'total_split') { - const obj = { name: '累计拆垛数量', value: data[val] } - this.arr.push(obj) - } else if (val === 'getStation') { - const obj = { name: '当前抓取工位', value: data[val] } - this.arr.push(obj) - } else if (val === 'putStation') { - const obj = { name: '当前码盘工位', value: data[val] } - this.arr.push(obj) } else if (val === 'move_1') { const obj = { name: '前工位光电信号', value: data[val] } this.arr.push(obj) @@ -498,39 +480,27 @@ export default { } else if (val === 'task') { const obj = { name: '任务号', value: data[val] } this.arr.push(obj) - } else if (val === 'labeling_qty') { - const obj = { name: '贴标数量', value: data[val] } - this.arr.push(obj) - } else if (val === 'container_type') { - const obj = { name: '托盘类型', value: data[val] } - this.arr.push(obj) - } else if (val === 'specifications') { - const obj = { name: '规格', value: data[val] } - this.arr.push(obj) - } else if (val === 'onoff_status') { - const obj = { name: '开关机状态', value: data[val] } - this.arr.push(obj) - } else if (val === 'task_qty') { - const obj = { name: '当前任务数量', value: data[val] } - this.arr.push(obj) - } else if (val === 'finishTask_qty') { - const obj = { name: '完成任务数量', value: data[val] } - this.arr.push(obj) - } else if (val === 'AlongSide') { - const obj = { name: 'A长边', value: data[val] } - this.arr.push(obj) - } else if (val === 'BshortSide') { - const obj = { name: 'B短边', value: data[val] } - this.arr.push(obj) - } else if (val === 'Htrapezoidal') { - const obj = { name: 'H梯形高', value: data[val] } - this.arr.push(obj) - } else if (val === 'Wthickness') { - const obj = { name: 'W厚度', value: data[val] } - this.arr.push(obj) } else if (val === 'is_disable') { const obj = { name: '是否禁用', value: data[val] } this.arr.push(obj) + } else if (val === 'temperature') { + const obj = { name: '当前温度', value: data[val] } + this.arr.push(obj) + } else if (val === 'finish') { + const obj = { name: '烘箱完成', value: data[val] } + this.arr.push(obj) + } else if (val === 'countdown_house') { + const obj = { name: '恒温倒计时(时)', value: data[val] } + this.arr.push(obj) + } else if (val === 'countdown_min') { + const obj = { name: '恒温倒计时(分)', value: data[val] } + this.arr.push(obj) + } else if (val === 'countdown_sec') { + const obj = { name: '恒温倒计时(秒)', value: data[val] } + this.arr.push(obj) + } else if (val === 'door') { + const obj = { name: '门状态', value: data[val] } + this.arr.push(obj) } else if (val === 'notCreateTaskMessage') { const obj = { name: '任务创建失败原因', value: data[val] } this.arr.push(obj) @@ -543,6 +513,9 @@ export default { } else if (val === 'requireSucess') { const obj = { name: '请求成功标记', value: data[val] } this.arr.push(obj) + } else if (val === 'applySucess') { + const obj = { name: 'applySucess', value: data[val] } + this.arr.push(obj) } } } @@ -590,6 +563,7 @@ export default { this.dialogFormVisible3 = false this.dialogFormVisible4 = false this.dialogFormVisible5 = false + this.dialogFormVisible6 = false this.initStageData() }).catch(err => { this.dialogFormVisible = false