From 746ba466f9b018bd67e59f7b84c777eefea3e043 Mon Sep 17 00:00:00 2001 From: yanps Date: Thu, 1 Aug 2024 17:33:56 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=B7=BB=E5=8A=A0plc=5Fto=5Fagv?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8,=E4=B8=8B=E5=8F=91agv=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- acs/nladmin-system/nlsso-server/pom.xml | 12 + .../agv/server/impl/NDCAgvServiceImpl.java | 17 +- .../run/OneNDCSocketConnectionAutoRun.java | 4 +- .../device/device_driver/DriverTypeEnum.java | 2 + .../service/impl/DeviceServiceImpl.java | 9 +- .../agv/ndcone/AgvNdcOneDeviceDriver.java | 146 +- .../basedriver/plc_to_agv/ItemProtocol.java | 93 + .../plc_to_agv/PlcToAgvDefination.java | 61 + .../plc_to_agv/PlcToAgvDeviceDriver.java | 197 ++ .../SiemensConveyorLabelingDeviceDriver.java | 1678 +++++++++-------- .../acs/ext/wms/service/AcsToWmsService.java | 2 - .../wms/service/impl/AcsToWmsServiceImpl.java | 3 +- .../rest/InstructionController.java | 3 - .../service/impl/InstructionServiceImpl.java | 40 +- .../service/impl/RouteLineServiceImpl.java | 3 +- .../org/nl/acs/task/rest/TaskController.java | 4 - .../task/service/impl/TaskServiceImpl.java | 302 +-- .../param/impl/SysParamServiceImpl.java | 5 +- .../resources/log/AgvNdcOneDeviceDriver.xml | 16 +- acs/nladmin-ui/package.json | 4 +- .../src/views/acs/device/config.vue | 2 + .../views/acs/device/driver/plc_to_agv.vue | 531 ++++++ 22 files changed, 2085 insertions(+), 1049 deletions(-) create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/ItemProtocol.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/PlcToAgvDefination.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/PlcToAgvDeviceDriver.java create mode 100644 acs/nladmin-ui/src/views/acs/device/driver/plc_to_agv.vue diff --git a/acs/nladmin-system/nlsso-server/pom.xml b/acs/nladmin-system/nlsso-server/pom.xml index 0283300..d17bd49 100644 --- a/acs/nladmin-system/nlsso-server/pom.xml +++ b/acs/nladmin-system/nlsso-server/pom.xml @@ -401,11 +401,23 @@ org.openscada.jinterop org.openscada.jinterop.core 2.1.8 + + + org.bouncycastle + bcprov-jdk15on + + org.openscada.jinterop org.openscada.jinterop.deps 1.5.0 + + + org.bouncycastle + bcprov-jdk15on + + org.openscada.utgard diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java index d6abfb0..6c6addb 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java @@ -112,21 +112,24 @@ public class NDCAgvServiceImpl implements NDCAgvService { System.out.println(str1); byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X12, + (byte) 0X00, (byte) 0X14, (byte) 0X00, (byte) 0X01, (byte) 0X00, (byte) 0X71, - (byte) 0X00, (byte) 0X0E, - (byte) 0X01, prioritylow, + (byte) 0X00, (byte) 0X10, + (byte) 0X01, (byte) 0X80, (byte) 0X00, (byte) 0X01, (byte) ikeyhigh, (byte) ikeylow, (byte) ikeyhigh, (byte) ikeylow, (byte) typehigh, (byte) typelow, (byte) qhdhigh, (byte) qhdlow, - (byte) fhdhigh, (byte) fhdlow + (byte) fhdhigh, (byte) fhdlow, + (byte) 0X00, (byte) 0X00, }; log.info("下发AGV作业指令--{}", str1); + log.info("下发AGV作业指令--{}", str); OneNDCSocketConnectionAutoRun.write(b); System.out.println("下发agv指令数据:" + Bytes2HexString(b)); + log.info("下发agv指令数据:" + Bytes2HexString(b)); } } @@ -138,14 +141,8 @@ public class NDCAgvServiceImpl implements NDCAgvService { byte indexlow = (byte) IntToHexLow(index); byte phasehigh = (byte) IntToHexHigh(phase); byte phaselow = (byte) IntToHexLow(phase); - byte startPointHigh =(byte) IntToHexHigh(startPoint); - byte startPointLow =(byte) IntToHexLow(startPoint); byte nextPointHigh =(byte) IntToHexHigh(nextPoint); byte nextPointLow =(byte) IntToHexLow(nextPoint); - byte startHighHigh =(byte) IntToHexHigh(startHigh); - byte startHighLow =(byte) IntToHexLow(startHigh); - byte nextHighHigh =(byte) IntToHexHigh(nextHigh); - byte nextHighLow =(byte) IntToHexLow(nextHigh); byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, (byte) 0X00, (byte) 0X08, diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java index 54b814c..55b9d09 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java @@ -236,9 +236,9 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { //上报异常信息 //(不需要WCS反馈) if (phase == 0x70 || phase == 0x71 || phase == 0x72 || phase == 0x73 || phase == 0x74) { - device = deviceAppService.findDeviceByCode("AGV0" +agvaddr); + device = deviceAppService.findDeviceByCode(Integer.toString(agvaddr)); } else { - device = deviceAppService.findDeviceByCode("AGV0" + Integer.toString(arr[20])); + device = deviceAppService.findDeviceByCode(Integer.toString(arr[20])); } if (ObjectUtil.isNotEmpty(device)) { if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) { diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index 72ad705..9e46bab 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -25,6 +25,8 @@ public enum DriverTypeEnum { AGV_NDC_ONE(7, "agv_ndc_one", "NDCAGV", "agv"), + PLC_TO_AGV(15, "plc_to_agv", "PLCTOAGV站点", "conveyor"), + AGV_NDC_TWO(8, "agv_ndc_two", "NDC2楼AGV", "agv"), XGAGV(9, "xg_agv", "xg_agv", "agv"), diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java index 98989a3..21f20f5 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java @@ -1018,7 +1018,14 @@ public class DeviceServiceImpl extends CommonServiceImpl i @Override public void changeDeviceStatus(JSONObject form) { String device_code = form.getString("device_code"); - if (StrUtil.contains(device_code, "-") && StrUtil.count(device_code, "-") == 2) { + String start_device = + deviceAppService + .findDeviceByCode(device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + if (StrUtil.equals("storage", start_device) && StrUtil.contains(device_code, "-") && StrUtil.count(device_code, "-") == 2) { String[] point = device_code.split("-"); device_code = point[0]; } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java index ce7ba16..81b504e 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java @@ -15,7 +15,9 @@ import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; import org.nl.acs.device.domain.Device; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.basedriver.plc_to_agv.PlcToAgvDeviceDriver; import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver; 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; @@ -128,7 +130,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic } TaskDto task = new TaskDto(); - if(ObjectUtil.isNotEmpty(inst)){ + if (ObjectUtil.isNotEmpty(inst)) { task = taskService.findById(inst.getTask_id()); } @@ -178,8 +180,39 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey); return; } - - data = getData(data, index, inst, task); + if (device.getDeviceDriver() instanceof PlcToAgvDeviceDriver) { + PlcToAgvDeviceDriver plcToAgvDeviceDriver = (PlcToAgvDeviceDriver) device.getDeviceDriver(); + if (plcToAgvDeviceDriver.getAGVEnable() != 0) { + if (ObjectUtil.isNotEmpty(plcToAgvDeviceDriver.getExtraValue().get("upper_lower_levels"))) { + Object plc_to_agv = plcToAgvDeviceDriver.getExtraValue().get("upper_lower_levels"); + if ("1".equals(plc_to_agv)) { + plcToAgvDeviceDriver.writing("AGVSetOutReqUpper", "1"); + if (plcToAgvDeviceDriver.getAGVSetOutUpperAllowed() == 1) { + data = feedBackStatus(data, index, 1, inst, task); + plcToAgvDeviceDriver.writing("AGVInOP", "1"); + } + } else if ("2".equals(plc_to_agv)) { + plcToAgvDeviceDriver.writing("AGVSetOutReqLower", "1"); + if (plcToAgvDeviceDriver.getAGVSetOutLowerAllowed() == 1) { + data = feedBackStatus(data, index, 1, inst, task); + plcToAgvDeviceDriver.writing("AGVInOP", "1"); + } + } + } else { + log.info("设备未设置上下层:{}", plcToAgvDeviceDriver.getExtraValue().get("upper_lower_levels")); + } + } else { + log.info("agv动作使能的信号不满足:{}", plcToAgvDeviceDriver.getAGVEnable()); + } + } else if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + try { + data = feedBackStatus(data, index, 1, inst, task); + } catch (Exception e) { + log.info("到达取货点反馈AGV状态失败:{}", e.getMessage()); + } + } else { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); + } //到达取货等待点 //(需要WCS反馈) } else if (phase == 0x04) { @@ -220,7 +253,23 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey); return; } - data = getData(data, index, inst, task); + if (device.getDeviceDriver() instanceof PlcToAgvDeviceDriver) { + PlcToAgvDeviceDriver plcToAgvDeviceDriver = (PlcToAgvDeviceDriver) device.getDeviceDriver(); + try { + plcToAgvDeviceDriver.writing("AGVInOP", "0"); + } catch (Exception e) { + log.info("下发AGVInOP信号:{}失败", "0"); + } + data = feedBackStatus(data, index, 2, inst, task); + } else if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + try { + data = feedBackStatus(data, index, 2, inst, task); + } catch (Exception e) { + log.info("取货完成反馈AGV状态失败:{}", e.getMessage()); + } + } else { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); + } //到达放货等待点 //(需要WCS反馈) } else if (phase == 0x06) { @@ -258,7 +307,39 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic log.info("未找到关联编号{}对应的指令", ikey); return; } - data = getData(data, index, inst, task); + if (device.getDeviceDriver() instanceof PlcToAgvDeviceDriver) { + PlcToAgvDeviceDriver plcToAgvDeviceDriver = (PlcToAgvDeviceDriver) device.getDeviceDriver(); + if (plcToAgvDeviceDriver.getAGVEnable() != 0) { + if (ObjectUtil.isNotEmpty(plcToAgvDeviceDriver.getExtraValue().get("upper_lower_levels"))) { + Object plc_to_agv = plcToAgvDeviceDriver.getExtraValue().get("upper_lower_levels"); + if ("1".equals(plc_to_agv)) { + plcToAgvDeviceDriver.writing("AGVSetInReqUpper", "1"); + if (plcToAgvDeviceDriver.getAGVSetInUpperAllowed() == 1) { + data = feedBackStatus(data, index, 3, inst, task); + plcToAgvDeviceDriver.writing("AGVInOP", "1"); + } + } else if ("2".equals(plc_to_agv)) { + plcToAgvDeviceDriver.writing("AGVSetInReqLower", "1"); + if (plcToAgvDeviceDriver.getAGVSetInLowerAllowed() == 1) { + data = feedBackStatus(data, index, 3, inst, task); + plcToAgvDeviceDriver.writing("AGVInOP", "1"); + } + } + } else { + log.info("设备未设置上下层:{}", plcToAgvDeviceDriver.getExtraValue().get("upper_lower_levels")); + } + } else { + log.info("agv动作使能的信号不满足:{}", plcToAgvDeviceDriver.getAGVEnable()); + } + } else if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + try { + data = feedBackStatus(data, index, 3, inst, task); + } catch (Exception e) { + log.info("到达放货点反馈AGV状态失败:{}", e.getMessage()); + } + } else { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); + } //放货完毕 //(需要WCS反馈) @@ -299,7 +380,23 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic return; } transportOrder = ""; - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); + if (device.getDeviceDriver() instanceof PlcToAgvDeviceDriver) { + PlcToAgvDeviceDriver plcToAgvDeviceDriver = (PlcToAgvDeviceDriver) device.getDeviceDriver(); + try { + plcToAgvDeviceDriver.writing("AGVInOP", "0"); + } catch (Exception e) { + log.info("下发AGVInOP信号:{}失败", "0"); + } + data = feedBackStatus(data, index, 4, inst, task); + } else if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + try { + data = feedBackStatus(data, index, 4, inst, task); + } catch (Exception e) { + log.info("放货完成反馈AGV状态失败:{},", e.getMessage()); + } + } else { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); + } } //到达位置点 //(需要WCS反馈) @@ -328,10 +425,10 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic //agv电量 electric_qty = ikey; int electric = Integer.parseInt(paramService.findByCode(AcsConfig.ELECTRIC).getValue()); - if (electric_qty>0&&electric_qty < electric) { - log.info("当前车辆{}电量为{}低于{},开始判断是否需要充电!", this.device_code, electric_qty,electric); + if (electric_qty > 0 && electric_qty < electric) { + log.info("当前车辆{}电量为{}低于{},开始判断是否需要充电!", this.device_code, electric_qty, electric); NDCAgvService.charge(String.valueOf(this.agvaddr)); - isCharge =true; + isCharge = true; } } else if (phase == 0x74) { //三色灯状态 @@ -344,13 +441,14 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic } private byte[] getData(byte[] data, int index, Instruction inst, TaskDto task) { - if (!"2".equals(task.getTask_type())) { + String hasWms = paramService.findByCode("hasWms").getValue(); + if ("3".equals(task.getTask_type()) && StrUtil.isNotEmpty(hasWms) && "1".equals(hasWms)) { String resp = acsToWmsService.requestTaskAgain(task.getNext_point_code(), task.getExt_task_id(), inst.getVehicle_code()); JSONObject respjson = JSONObject.parseObject(resp); - String next_device_code = respjson.getString("next_point_code"); - task.setNext_point_code(next_device_code); + String point_code = respjson.getString("point_code"); + task.setStart_device_code2(point_code); int start_address = deviceService.queryAddressBydeviceCode(inst.getStart_point_code()); - int next_address = deviceService.queryAddressBydeviceCode(next_device_code); + int next_address = deviceService.queryAddressBydeviceCode(point_code); taskService.update(task); data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, start_address, next_address, 0, 0); log.info("指令号:{},phase:{},acs请求wms申请成功", inst.getInstruction_code(), phase); @@ -360,4 +458,26 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic return data; } + private byte[] feedBackStatus(byte[] data, int index, int agvStatus, Instruction inst, TaskDto task) { + String hasWms = paramService.findByCode("hasWms").getValue(); + if (StrUtil.isNotEmpty(hasWms) && "1".equals(hasWms)) { + JSONArray ja = new JSONArray(); + JSONObject jo = new JSONObject(); + jo.put("vehicle_code", inst.getVehicle_code()); + jo.put("status", agvStatus); + jo.put("device_code", this.device_code); + jo.put("task_code", inst.getTask_code()); + ja.add(jo); + HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(ja); + if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); + } else { + log.info("指令号:{},phase:{},acs反馈wms失败:{}", inst.getInstruction_code(), phase, httpResponse); + } + } else { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); + } + return data; + } + } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/ItemProtocol.java new file mode 100644 index 0000000..7772e10 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/ItemProtocol.java @@ -0,0 +1,93 @@ +package org.nl.acs.device_driver.basedriver.plc_to_agv; + +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_AGVSetInLowerAllowed = "AGVSetInLowerAllowed"; + public static String item_AGVSetOutLowerAllowed = "AGVSetOutLowerAllowed"; + public static String item_AGVSetInUpperAllowed = "AGVSetInUpperAllowed"; + public static String item_AGVSetOutUpperAllowed = "AGVSetOutUpperAllowed"; + public static String item_AGVEnable = "AGVEnable"; + public static String item_AGVSetInReqLower = "AGVSetInReqLower"; + public static String item_AGVSetOutReqLower = "AGVSetOutReqLower"; + public static String item_AGVSetInReqUpper = "AGVSetInReqUpper"; + public static String item_AGVSetOutReqUpper = "AGVSetOutReqUpper"; + public static String item_AGVInOP = "AGVInOP"; + + private PlcToAgvDeviceDriver driver; + + public ItemProtocol(PlcToAgvDeviceDriver driver) { + this.driver = driver; + } + + public int getAGVSetInLowerAllowed() { + return this.getOpcIntegerValue(item_AGVSetInLowerAllowed); + } + + public int getAGVSetOutLowerAllowed() { + return this.getOpcIntegerValue(item_AGVSetOutLowerAllowed); + } + + public int getAGVSetInUpperAllowed() { + return this.getOpcIntegerValue(item_AGVSetInUpperAllowed); + } + + public int getAGVSetOutUpperAllowed() { + return this.getOpcIntegerValue(item_AGVSetOutUpperAllowed); + } + + public int getAGVEnable() { + return this.getOpcIntegerValue(item_AGVEnable); + } + + + //是否有货 + public int hasGoods(int move) { + return move; + } + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_AGVSetInLowerAllowed, "下层允许上料", "DB600.B0")); + list.add(new ItemDto(item_AGVSetOutLowerAllowed, "下层允许下料", "DB600.B2")); + list.add(new ItemDto(item_AGVSetInUpperAllowed, "上层允许上料", "DB600.B3")); + list.add(new ItemDto(item_AGVSetOutUpperAllowed, "上层允许下料", "DB600.B4")); + list.add(new ItemDto(item_AGVEnable, "agv动作使能", "DB600.D6")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_AGVSetInReqLower, "下层上料请求", "DB600.B0")); + list.add(new ItemDto(item_AGVSetOutReqLower, "下层下料请求", "DB600.B2")); + list.add(new ItemDto(item_AGVSetInReqUpper, "上层上料请求", "DB600.B3")); + list.add(new ItemDto(item_AGVSetOutReqUpper, "上层下料请求", "DB600.B4")); + list.add(new ItemDto(item_AGVInOP, "在工位内", "DB600.D6")); + return list; + } + +} + diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/PlcToAgvDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/PlcToAgvDefination.java new file mode 100644 index 0000000..3855277 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/PlcToAgvDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.plc_to_agv; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.enums.DeviceType; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * PlcToAgv站点 + */ +@Service +public class PlcToAgvDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "plc_to_agv"; + } + + @Override + public String getDriverName() { + return "PlcToAgv站点"; + } + + @Override + public String getDriverDescription() { + return "PlcToAgv站点"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new PlcToAgvDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return PlcToAgvDeviceDriver.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/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/PlcToAgvDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/PlcToAgvDeviceDriver.java new file mode 100644 index 0000000..c3e247d --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plc_to_agv/PlcToAgvDeviceDriver.java @@ -0,0 +1,197 @@ +package org.nl.acs.device_driver.basedriver.plc_to_agv; + +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.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RequestMethodEnum; +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.feedBackTaskStatus.FeedBackTaskStatusRequest; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.instruction.domain.Instruction; +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.WcsConfig; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.domain.Task; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.acs.task.service.mapper.TaskMapper; +import org.nl.acs.utils.ConvertUtil; +import org.nl.common.utils.CodeUtil; +import org.nl.config.SpringContextHolder; +import org.nl.system.service.lucene.LuceneExecuteLogService; +import org.nl.system.service.lucene.dto.LuceneLogDto; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * PlcToAgv站点 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class PlcToAgvDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver , DeviceStageMonitor { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + TaskMapper taskMapper; + + AcsToWmsService acsToWmsService=SpringContextHolder.getBean("acsToWmsServiceImpl"); + + LuceneExecuteLogService luceneExecuteLogService = SpringContextHolder.getBean(LuceneExecuteLogService.class); + + + int AGVSetInLowerAllowed =0; + int AGVSetOutLowerAllowed=0; + int AGVSetInUpperAllowed =0; + int AGVSetOutUpperAllowed=0; + int AGVEnable=0; + + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + AGVSetInLowerAllowed = this.itemProtocol.getAGVSetInLowerAllowed(); + AGVSetOutLowerAllowed = this.itemProtocol.getAGVSetOutLowerAllowed(); + AGVSetInUpperAllowed = this.itemProtocol.getAGVSetInUpperAllowed(); + AGVSetOutUpperAllowed = this.itemProtocol.getAGVSetOutUpperAllowed(); + AGVEnable = this.itemProtocol.getAGVEnable(); + + } catch (Exception var17) { + return; + } + + } + + + /** + * 多个信号一起下发电气 + * + * @param map + */ + public void writing(Map map) throws Exception { + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + Map itemMap = new LinkedHashMap<>(); + map.forEach((key, value) -> { + if (ObjectUtil.isNotEmpty(value)) { + itemMap.put(getToParam() + key, value); + } + }); + if (ObjectUtil.isNotEmpty(itemMap)) { + this.checkcontrol(itemMap); + logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); + LuceneLogDto logDto = LuceneLogDto.builder() + .device_code(device_code) + .content("下发多个电气信号" + itemMap) + .build(); + logDto.setLog_level(3); + luceneExecuteLogService.deviceExecuteLog(logDto); + } + } + + 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; + + Map itemMap = new HashMap(); + + itemMap.put(to_param, Integer.parseInt(value)); + try { + this.checkcontrol(itemMap); + } catch (Exception e) { + e.printStackTrace(); + } + LuceneLogDto logDto = LuceneLogDto.builder() + .device_code(device_code) + .content("下发多个电气信号" + itemMap) + .build(); + logDto.setLog_level(4); + luceneExecuteLogService.deviceExecuteLog(logDto); + } + + public String getToParam() { + return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; + } + + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + + + public void executing(Server server, Map itemMap) { + this.control(itemMap); + } + + + + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + return jo; + } + + @Override + public void setDeviceStatus(JSONObject data) { + + } + + 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; + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java index 04eb215..4ef79a5 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java @@ -40,899 +40,909 @@ 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 ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class); - @Autowired AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); - - @Autowired - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - - @Autowired NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); - - @Autowired - StorageCellMapper storageCellMapper; - // 当前指令 - 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() { + 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 + ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); + + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + + @Autowired + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); + + @Autowired + StorageCellMapper storageCellMapper; + // 当前指令 + 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; - 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); - } - } + Boolean iserror = false; - } catch (Exception var17) { - inst_message = var17.getMessage(); - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "读取信号值时出现异常:" + var17.getMessage()); - // return; - } + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date require_apply_labeling_time = new Date(); + private Date require_apply_strangulation_time = new Date(); + private Date require_empty_in_time = new Date(); + private Date require_empty_out_time = new Date(); - // if (!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任务中"; - } + 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; - 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); + int branchProtocol = 0; + String inst_message; - 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; - } - } + // 暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; - public void writing(List list) { + String device_code; - // 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")); - } + String vehicle_code; + + @Override + public Device getDevice() { + return this.device; } - 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"); + + @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); } - } - 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; + 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); + } } - } - 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("路由不通!"); + + } catch (Exception var17) { + inst_message = var17.getMessage(); + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "读取信号值时出现异常:" + var17.getMessage()); + // return; } - 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(); + // 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 { - next_point_code = next_device_code; + 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; + } } - 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; + 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; } - // 创建指令后修改任务状态 - taskdto.setTask_status("1"); - taskserver.update(taskdto); - requireSucess = true; - String next_addr = nextdevice.getExtraValue().get("address").toString(); + } + + public void clearWrite() { List list = new ArrayList(); Map map = new HashMap(); map.put("code", "to_target"); - map.put("value", next_addr); + map.put("value", "0"); list.add(map); Map map2 = new HashMap(); map2.put("code", "to_task"); - map2.put("value", instdto.getInstruction_code()); + map2.put("value", "0"); list.add(map2); Map map3 = new HashMap(); map3.put("code", "to_command"); - map3.put("value", "1"); + 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); - if (task != Integer.parseInt(inst.getInstruction_code())) { - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); + 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); } - } else { - // 如果不存在则直接找对应指令 - Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code); - if (ObjectUtil.isEmpty(inst)) { - return false; + String requireApplyLabelingSuccess = "0"; + if (this.requireApplyLabelingSuccess) { + requireApplyLabelingSuccess = "1"; } - // 当起点为行架任务的时候不需要请求下发 - if (StrUtil.equals(inst.getInstruction_type(), "6")) { - return false; + String requireApplyLaStrangulationSuccess = "0"; + if (this.requireApplyLaStrangulationSuccess) { + requireApplyLaStrangulationSuccess = "1"; } - Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code()); - String next_addr = nextdevice.getExtraValue().get("address").toString(); + jo.put("requireApplyLabelingSuccess", requireApplyLabelingSuccess); + jo.put("requireApplyLaStrangulationSuccess", requireApplyLaStrangulationSuccess); - 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() + "再次下发电气信号"); + if (this.carrier_direction == 1) { + carrier_direction = "正转"; + } else if (this.carrier_direction == 2) { + carrier_direction = "反转"; } - } - return true; + 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; } - } - - // 申请贴标 - 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)); + + @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")); + } } - 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(); + 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); - StorageCell storageCell = new LambdaQueryChainWrapper<>(storageCellMapper).eq(StorageCell::getStorage_code,this.device_code).one(); - String start_point_code = null; - if (!ObjectUtil.isEmpty(storageCell)) { - start_point_code = - (String) storageCell.getParent_storage_code() == null - ? this.device_code - : (String) storageCell.getParent_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(); - } + StorageCell storageCell = new LambdaQueryChainWrapper<>(storageCellMapper).eq(StorageCell::getStorage_code, this.device_code).one(); + String start_point_code = null; + if (!ObjectUtil.isEmpty(storageCell)) { + start_point_code = + (String) storageCell.getParent_storage_code() == null + ? this.device_code + : (String) storageCell.getParent_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(); + + // 申请捆扎 + 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); - StorageCell storageCell = new LambdaQueryChainWrapper<>(storageCellMapper).eq(StorageCell::getStorage_code,this.device_code).one(); - String start_point_code = null; - if (!ObjectUtil.isEmpty(storageCell)) { - start_point_code = - (String) storageCell.getParent_storage_code() == null - ? this.device_code - : (String) storageCell.getParent_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 = "未返回尺寸信息"; + StorageCell storageCell = new LambdaQueryChainWrapper<>(storageCellMapper).eq(StorageCell::getStorage_code, this.device_code).one(); + String start_point_code = null; + if (!ObjectUtil.isEmpty(storageCell)) { + start_point_code = + (String) storageCell.getParent_storage_code() == null + ? this.device_code + : (String) storageCell.getParent_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(); + } } - - } 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 = "申请空盘入库接口不通"; + + 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 { - if (jo.getInteger("status") == 200) { - message = "申请空盘入库成功"; - requireEmptyInSuccess = true; - } else { - requireEmptyInSuccess = false; - message = "申请空盘入库失败," + jo.get("message").toString(); - } + 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搬运任务接口不通"; + + 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 { - if (jo.getInteger("status") == 200) { - message = "申请AGV搬运任务成功"; - requireEmptyOutSuccess = true; - } else { - requireEmptyOutSuccess = false; - message = "申请AGV搬运任务失败," + jo.get("message").toString(); - } + 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 = "申请空盘出库接口不通"; + + 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 { - if (jo.getInteger("status") == 200) { - message = "申请空盘出库成功"; - requireEmptyOutSuccess = true; - } else { - requireEmptyOutSuccess = false; - message = "申请空盘出库失败," + jo.get("message").toString(); - } + 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/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java index afa76bb..8b44737 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java @@ -114,8 +114,6 @@ public interface AcsToWmsService { HttpResponse feedAgvTaskStatus(JSONArray from); - - /** * ACS向WMS申请任务 */ diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java index a2db2d3..5d85266 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java @@ -546,8 +546,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { log.info("feedAgvTaskStatus----返回参数{}", result); } catch (Exception e) { String msg = e.getMessage(); - //网络不通 - //System.out.println(msg); + log.info("feedAgvTaskStatus----报错{}", msg); } return result; } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/rest/InstructionController.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/rest/InstructionController.java index a121c85..f34d06b 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/rest/InstructionController.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/rest/InstructionController.java @@ -37,9 +37,6 @@ public class InstructionController { @ApiOperation("查询指令") //@PreAuthorize("@el.check('instruction:list')") public ResponseEntity query(@RequestParam Map whereJson, Pageable page) { - if(ObjectUtil.isEmpty(whereJson.get("status"))) { - whereJson.put("status", "1"); - } return new ResponseEntity<>(instructionService.queryAll(whereJson, page), HttpStatus.OK); } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index 02901eb..14a608f 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -195,7 +195,7 @@ public class InstructionServiceImpl extends CommonServiceImpl instructionMybatis.like(InstructionMybatis::getInstruction_code, code).or().like(InstructionMybatis::getTask_code, code)); wrapper.like(StringUtils.isNotBlank(vehicle_code), InstructionMybatis::getVehicle_code, vehicle_code); wrapper.eq(StringUtils.isNotBlank(material_type), InstructionMybatis::getMaterial, material_type); - wrapper.eq(StringUtils.isNotBlank(status), InstructionMybatis::getInstruction_status, status); + wrapper.le(InstructionMybatis::getInstruction_status, "1"); wrapper.and(StringUtils.isNotBlank(point_code), instructionMybatis -> instructionMybatis.like(InstructionMybatis::getStart_point_code, point_code).or().like(InstructionMybatis::getNext_point_code, point_code)); wrapper.eq(StringUtils.isNotBlank(instruction_type), InstructionMybatis::getInstruction_type, instruction_type); if (!StrUtil.isEmpty(is_over)) { @@ -1027,12 +1027,12 @@ public class InstructionServiceImpl extends CommonServiceImpl query(@RequestParam Map whereJson, Pageable page) { -// return new ResponseEntity<>(taskService.queryAllByCache(whereJson, page), HttpStatus.OK); - if(ObjectUtil.isEmpty(whereJson.get("status"))) { - whereJson.put("status", "1"); - } return new ResponseEntity<>(taskService.queryAll(whereJson, page), HttpStatus.OK); } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index 7da4931..e4eab9e 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -75,9 +75,9 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; /** -* @author jiaolm -* @date 2023-05-09 -*/ + * @author jiaolm + * @date 2023-05-09 + */ @Service @Slf4j @Lazy @@ -122,7 +122,7 @@ public class TaskServiceImpl extends CommonServiceImpl impleme } @Override - public List queryAll(TaskQueryParam query){ + public List queryAll(TaskQueryParam query) { return ConvertUtil.convertList(taskMapper.selectList(QueryHelpMybatisPlus.getPredicate(query)), TaskDto.class); } @@ -146,7 +146,7 @@ public class TaskServiceImpl extends CommonServiceImpl impleme @Override @Transactional(rollbackFor = Exception.class) - public int updateById(TaskDto resources){ + public int updateById(TaskDto resources) { Task entity = ConvertUtil.convert(resources, Task.class); int ret = taskMapper.updateById(entity); // delCaches(resources.id); @@ -155,14 +155,14 @@ public class TaskServiceImpl extends CommonServiceImpl impleme @Override @Transactional(rollbackFor = Exception.class) - public int removeByIds(Set ids){ + public int removeByIds(Set ids) { // delCaches(ids); return taskMapper.deleteBatchIds(ids); } @Override @Transactional(rollbackFor = Exception.class) - public int removeById(String id){ + public int removeById(String id) { Set set = new HashSet<>(1); set.add(id); return this.removeByIds(set); @@ -252,6 +252,7 @@ public class TaskServiceImpl extends CommonServiceImpl impleme /** * 获取未完成任务 + * * @throws Exception */ @Override @@ -270,12 +271,12 @@ public class TaskServiceImpl extends CommonServiceImpl impleme @Override public List queryAll(String whereJson) { - List taskList= new LambdaQueryChainWrapper<>(taskMapper) + List taskList = new LambdaQueryChainWrapper<>(taskMapper) .lt(Task::getTask_status, "2") - .eq(Task::getIs_delete,"0") + .eq(Task::getIs_delete, "0") .orderByDesc(Task::getCreate_time) .list(); - return ConvertUtil.convertList(taskList,TaskDto.class); + return ConvertUtil.convertList(taskList, TaskDto.class); } @Override @@ -284,35 +285,32 @@ public class TaskServiceImpl extends CommonServiceImpl impleme 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"); IPage queryPage = PageUtil.toMybatisPage(page); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (!StrUtil.isEmpty(task_code)) { - wrapper.eq(Task::getTask_code,task_code); + wrapper.eq(Task::getTask_code, task_code); } if (!StrUtil.isEmpty(vehicle_code)) { - wrapper.eq(Task::getVehicle_code,vehicle_code); + wrapper.eq(Task::getVehicle_code, vehicle_code); } if (!StrUtil.isEmpty(material_type)) { - wrapper.eq(Task::getMaterial,material_type); - } - if (!StrUtil.isEmpty(status)) { - wrapper.eq(Task::getTask_status,status); + wrapper.eq(Task::getMaterial, material_type); } + wrapper.le(Task::getTask_status, "1"); if (!StrUtil.isEmpty(point_code)) { - wrapper.and(task -> task.like(Task::getStart_point_code,point_code).or().like(Task::getNext_point_code,point_code)); + wrapper.and(task -> task.like(Task::getStart_point_code, point_code).or().like(Task::getNext_point_code, point_code)); } if (!StrUtil.isEmpty(is_over)) { - if (StrUtil.equals(is_over,"1")){ - wrapper.ge(Task::getTask_status,2); - }else{ - wrapper.lt(Task::getTask_status,2); + if (StrUtil.equals(is_over, "1")) { + wrapper.ge(Task::getTask_status, 2); + } else { + wrapper.lt(Task::getTask_status, 2); } } - IPage taskPage = taskMapper.selectPage(queryPage,wrapper); + IPage taskPage = taskMapper.selectPage(queryPage, wrapper); final JSONObject json = (JSONObject) JSON.toJSON(ConvertUtil.convertPage(taskPage, TaskDto.class)); return json; } @@ -402,24 +400,24 @@ public class TaskServiceImpl extends CommonServiceImpl impleme LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); // wrapper.eq(InstructionMybatis::getIs_delete,"0"); if (!StrUtil.isEmpty(task_code)) { - wrapper.eq(Task::getTask_code,task_code); + wrapper.eq(Task::getTask_code, task_code); } if (!StrUtil.isEmpty(vehicle_code)) { - wrapper.like(Task::getVehicle_code,vehicle_code); + wrapper.like(Task::getVehicle_code, vehicle_code); } if (!StrUtil.isEmpty(material_type)) { - wrapper.eq(Task::getMaterial,material_type); + wrapper.eq(Task::getMaterial, material_type); } if (!StrUtil.isEmpty(status)) { - wrapper.eq(Task::getTask_status,status); + wrapper.eq(Task::getTask_status, status); } if (!StrUtil.isEmpty(point_code)) { - wrapper.and(task -> task.like(Task::getStart_point_code,point_code).or().like(Task::getNext_point_code,point_code)); + wrapper.and(task -> task.like(Task::getStart_point_code, point_code).or().like(Task::getNext_point_code, point_code)); } if (!StrUtil.isEmpty(create_time) && !StrUtil.isEmpty(end_time)) { - wrapper.between(Task::getCreate_time,create_time,end_time); + wrapper.between(Task::getCreate_time, create_time, end_time); } - IPage taskPage = taskMapper.selectPage(queryPage,wrapper); + IPage taskPage = taskMapper.selectPage(queryPage, wrapper); final JSONObject json = (JSONObject) JSON.toJSON(ConvertUtil.convertPage(taskPage, TaskDto.class)); JSONArray array = json.getJSONArray("content"); int totalElements = (int) json.getLongValue("totalElements"); @@ -438,9 +436,9 @@ public class TaskServiceImpl extends CommonServiceImpl impleme @Override public List queryAll(Map whereJson) { - List taskList= new LambdaQueryChainWrapper<>(taskMapper) + List taskList = new LambdaQueryChainWrapper<>(taskMapper) .list(); - return ConvertUtil.convertList(taskList,TaskDto.class); + return ConvertUtil.convertList(taskList, TaskDto.class); } // @Override @@ -457,10 +455,10 @@ public class TaskServiceImpl extends CommonServiceImpl impleme // JSONArray arr = wo.query("task_status < 2 ").getResultJSONArray(0); // List list = arr.toJavaList(TaskDto.class); // return list; - List taskList= new LambdaQueryChainWrapper<>(taskMapper) - .lt(Task::getTask_status,"2") + List taskList = new LambdaQueryChainWrapper<>(taskMapper) + .lt(Task::getTask_status, "2") .list(); - return ConvertUtil.convertList(taskList,TaskDto.class); + return ConvertUtil.convertList(taskList, TaskDto.class); } @Override @@ -469,10 +467,10 @@ public class TaskServiceImpl extends CommonServiceImpl impleme // JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); // final TaskDto obj = json.toJavaObject(TaskDto.class); // return obj; - Task task= new LambdaQueryChainWrapper<>(taskMapper) - .eq(Task::getTask_code,code) + Task task = new LambdaQueryChainWrapper<>(taskMapper) + .eq(Task::getTask_code, code) .one(); - return ConvertUtil.convert(task,TaskDto.class); + return ConvertUtil.convert(task, TaskDto.class); } @Override @@ -591,10 +589,10 @@ public class TaskServiceImpl extends CommonServiceImpl impleme // JSONArray arr = wo.query("task_status = '" + status + "'").getResultJSONArray(0); // List list = arr.toJavaList(TaskDto.class); // return list; - List taskList= new LambdaQueryChainWrapper<>(taskMapper) - .eq(Task::getTask_status,status) + List taskList = new LambdaQueryChainWrapper<>(taskMapper) + .eq(Task::getTask_status, status) .list(); - return ConvertUtil.convertList(taskList,TaskDto.class); + return ConvertUtil.convertList(taskList, TaskDto.class); } @Override @@ -1457,131 +1455,141 @@ public class TaskServiceImpl extends CommonServiceImpl impleme 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(); + String start_device = + deviceAppService + .findDeviceByCode(start_point_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + if (StrUtil.equals("storage", start_device)) { + 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 = task.getFrom_y(); + from_y = start_point[1]; + task.setFrom_y(from_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 if (task.getFrom_z().length() == 2) { - from_z = task.getFrom_z(); + 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 = task.getFrom_z(); + from_z = start_point[2]; } - task.setFrom_x(start_point_code); - task.setStart_point_code(start_point_code + "-" + from_y + "-" + from_z); - task.setStart_device_code(start_point_code); + task.setStart_point_code(task.getStart_device_code() + "-" + from_y + "-" + from_z); + task.setStart_device_code(task.getStart_device_code()); } else { - task.setStart_device_code(start_point_code); - task.setStart_device_code(start_point_code); - } - } - - 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); + // 如果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 if (task.getFrom_z().length() == 2) { + from_z = 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); + } } - 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("货位信息终点需要包含列信息"); - } - 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.setStart_device_code(start_point_code); + task.setStart_device_code(start_point_code); + } + + String next_device = + deviceAppService + .findDeviceByCode(next_point_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + if (StrUtil.equals("storage", next_device)) { + 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 = task.getTo_y(); + to_y = next_point[1]; + task.setTo_y(to_y); } - if (Integer.parseInt(task.getTo_z()) < 10 && task.getTo_z().length() == 1) { - to_z = "0" + task.getTo_z(); + 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 (task.getTo_z().length() == 2) { - to_z = task.getTo_z(); + } else if (next_point[2].length() == 2) { + to_z = next_point[2]; task.setTo_z(to_z); } else { - to_z = task.getTo_z(); + to_z = next_point[2]; + task.setTo_z(to_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); + task.setNext_point_code(task.getNext_device_code() + "-" + to_y + "-" + to_z); + task.setNext_device_code(task.getNext_device_code()); } else { - task.setNext_device_code(next_point_code); - task.setNext_device_code(next_point_code); + + 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 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); + + } else { + task.setNext_device_code(next_point_code); + task.setNext_device_code(next_point_code); + } } + } else { + task.setNext_device_code(next_point_code); + task.setNext_device_code(next_point_code); } return task; } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/param/impl/SysParamServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/param/impl/SysParamServiceImpl.java index a1578c3..0b60dcb 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/param/impl/SysParamServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/param/impl/SysParamServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; @@ -12,6 +13,7 @@ import org.nl.common.domain.query.PageQuery; import org.nl.common.exception.BadRequestException; import org.nl.common.utils.SecurityUtils; import org.nl.config.MapOf; +import org.nl.system.service.coderule.dao.SysCodeRuleDetail; import org.nl.system.service.param.ISysParamService; import org.nl.system.service.param.dao.Param; import org.nl.system.service.param.dao.mapper.SysParamMapper; @@ -41,7 +43,8 @@ public class SysParamServiceImpl extends ServiceImpl impl public Page queryPage(Map whereJson, PageQuery page) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.orderBy(true, true, "create_time"); - Page paramPage = paramMapper.selectPage(page.build(), queryWrapper); + Page pages = new Page<>(page.getPage() + 1, page.getSize()); + Page paramPage = paramMapper.selectPage(pages, queryWrapper); return paramPage; } diff --git a/acs/nladmin-system/nlsso-server/src/main/resources/log/AgvNdcOneDeviceDriver.xml b/acs/nladmin-system/nlsso-server/src/main/resources/log/AgvNdcOneDeviceDriver.xml index 5ea9f1d..f323915 100644 --- a/acs/nladmin-system/nlsso-server/src/main/resources/log/AgvNdcOneDeviceDriver.xml +++ b/acs/nladmin-system/nlsso-server/src/main/resources/log/AgvNdcOneDeviceDriver.xml @@ -3,7 +3,7 @@ - + ${LOG_HOME}/AGV驱动与NDC交互/%d{yyyy-MM-dd}.%i.log @@ -19,14 +19,18 @@ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n ${log.charset} - + - - - 512 + 0 + 500 + - + + + + + diff --git a/acs/nladmin-ui/package.json b/acs/nladmin-ui/package.json index 0fe34f1..1402809 100644 --- a/acs/nladmin-ui/package.json +++ b/acs/nladmin-ui/package.json @@ -33,8 +33,8 @@ "url": "https://github.com/elunez/eladmin/issues" }, "dependencies": { - "@logicflow/core": "^1.1.22", - "@logicflow/extension": "^1.1.22", + "@logicflow/core": "1.1.22", + "@logicflow/extension": "1.1.22", "@riophae/vue-treeselect": "0.4.0", "af-table-column": "^1.0.3", "ansi_up": "^5.1.0", diff --git a/acs/nladmin-ui/src/views/acs/device/config.vue b/acs/nladmin-ui/src/views/acs/device/config.vue index 7559797..3facd7a 100644 --- a/acs/nladmin-ui/src/views/acs/device/config.vue +++ b/acs/nladmin-ui/src/views/acs/device/config.vue @@ -75,6 +75,7 @@ import { get, selectDriverCodeList } from '@/api/acs/device/driverConfig' import { getDicts } from '@/views/system/dict/dict' import standard_autodoor from '@/views/acs/device/driver/standard_autodoor' import standard_inspect_site from './driver/standard_inspect_site' +import plc_to_agv from './driver/plc_to_agv' import standard_ordinary_site from './driver/standard_ordinary_site' import standard_storage from '@/views/acs/device/driver/standard_storage' import standard_scanner from '@/views/acs/device/driver/standard_scanner' @@ -102,6 +103,7 @@ export default { tubanxian_site, standard_ordinary_site, standard_inspect_site, + plc_to_agv, standard_storage, standard_scanner, standard_conveyor_control_with_scanner, diff --git a/acs/nladmin-ui/src/views/acs/device/driver/plc_to_agv.vue b/acs/nladmin-ui/src/views/acs/device/driver/plc_to_agv.vue new file mode 100644 index 0000000..94fd810 --- /dev/null +++ b/acs/nladmin-ui/src/views/acs/device/driver/plc_to_agv.vue @@ -0,0 +1,531 @@ + + + + +