diff --git a/wcs/hd/nladmin-system/pom.xml b/wcs/hd/nladmin-system/pom.xml index 13ece7a..725ee9e 100644 --- a/wcs/hd/nladmin-system/pom.xml +++ b/wcs/hd/nladmin-system/pom.xml @@ -37,6 +37,21 @@ 2.5.14 + + org.openscada.jinterop + org.openscada.jinterop.core + 2.1.8 + + + org.openscada.jinterop + org.openscada.jinterop.deps + 1.5.0 + + + org.openscada.utgard + org.openscada.opc.dcom + 1.5.0 + org.openscada.utgard org.openscada.opc.lib @@ -64,6 +79,11 @@ lucene-analyzers-smartcn 8.4.0 + + org.rxtx + rxtx + 2.1.7 + org.apache.lucene diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java index da18658..e26d5f3 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java @@ -16,6 +16,8 @@ public interface AgvService { */ public HttpResponse sendAgvInstToMagic(Instruction inst) throws Exception; + public HttpResponse sendAgvInstToZDAgv(Instruction inst) throws Exception; + public HttpResponse markComplete(String code) throws Exception; public HttpResponse sendAgvInstToMagic(String code) throws Exception; @@ -34,6 +36,9 @@ public interface AgvService { public HttpResponse queryXZAgvInstStatus(String instCode); + //type:1、二楼AGV系统;2、一楼AGV系统 + public HttpResponse queryZDAgvInstStatus(String type); + Map findAllAgvFromCache(); void updateAgvFromCache(AgvDto dto); diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java index bd2582b..107a908 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java @@ -14,6 +14,11 @@ import org.nl.acs.config.AcsConfig; import org.nl.acs.config.server.AcsConfigService; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device.service.impl.DeviceServiceImpl; +import org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.CargoLiftConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position.EmptyVehicleStackingPositionDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_smart_plc_test.HailiangSmartplcTestDeviceDriver; +import org.nl.acs.device_driver.basedriver.haokai_auto_conveyor.HaoKaiAutoConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.paint_conveyor.PaintConveyorDeviceDriver; 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; @@ -172,6 +177,13 @@ public class AgvServiceImpl implements AgvService { pro2.put("value", "0");//弧度值,如0 properties.add(pro2); destinationOrder.put("properties", properties); + } else if (propertiesType.equals("5")) {//在该点进行等待 + JSONArray properties = new JSONArray(); + JSONObject pro1 = new JSONObject(); + pro1.put("key", "Wait"); + pro1.put("value", "True"); + properties.add(pro1); + destinationOrder.put("properties", properties); } return destinationOrder; } @@ -332,6 +344,60 @@ public class AgvServiceImpl implements AgvService { } + @Override + public HttpResponse sendAgvInstToZDAgv(Instruction inst) throws Exception { + JSONObject jo = new JSONObject(); + String start_point_code = inst.getStart_point_code(); + String next_point_code = inst.getNext_point_code(); + //1、叠盘架追加任务;2、养生区需要追加任务,在缓存点等待3、二楼普通任务4、一楼普通任务 + String task_type = inst.getInstruction_type(); + jo.put("deadline", getNextDay(1)); + //判断是否追加任务 + if (task_type.equals("2") || task_type.equals("1")) { + jo.put("complete", "false"); + } else { + jo.put("complete", "true"); + } + jo.put("task_code", inst.getInstruction_code()); + //根据任务,下发指令类型 + JSONArray destinations = new JSONArray(); + if (task_type.equals("1")) { + destinations.add(destination(start_point_code, "Wait", "5", "1")); + } else { + destinations.add(destination(start_point_code, "Load", "1", "1")); + if (task_type.equals("2")) { + destinations.add(destination(next_point_code, "Wait", "5", "1")); + } else { + destinations.add(destination(next_point_code, "Unload", "5", "1")); + } + } + jo.put("destinations", destinations); + + if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) { + String url = ""; + String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); + String agvurl2 = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL2); + String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); + //不同楼层下发不同的agv系统 + if (task_type.equals("8")) { + url = agvurl2; + } else { + url = agvurl; + } + url = url + ":" + agvport + "v1/transportOrders/" + inst.getInstruction_code(); + log.info("下发agv任务请求:{}", url); + + HttpResponse result = HttpRequest.post(agvurl) + .body(String.valueOf(jo))//表单内容 + .timeout(20000)//超时,毫秒 + .execute(); + log.info("下发agv任务请求反馈:{}", result); + return result; + } else { + return null; + } + } + @Override public HttpResponse markComplete(String code) throws Exception { @@ -339,7 +405,7 @@ public class AgvServiceImpl implements AgvService { String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); - agvurl = agvurl + ":" + agvport + "/api/route/orderSequences/" + code + "/markComplete"; + agvurl = agvurl + ":" + agvport + "/v1/" + code + "/markComplete"; log.info("关闭agv运单序列请求:{}", agvurl); HttpResponse result = HttpRequest.post(agvurl) @@ -426,10 +492,11 @@ public class AgvServiceImpl implements AgvService { /** * 双工位诺宝车任务 + * * @param inst */ @Override - public void sendAgvTwoInstToNDC(Instruction inst,Instruction inst2) { + public void sendAgvTwoInstToNDC(Instruction inst, Instruction inst2) { String instcode = inst.getLink_num(); int type = Integer.parseInt(inst.getAgv_inst_type()); int priority = Integer.parseInt(inst.getPriority()) + 128; @@ -440,14 +507,13 @@ public class AgvServiceImpl implements AgvService { int startAddress2 = 0; int putAddress2 = 0; int nextAddress2 = 0; - if(ObjectUtil.isNotEmpty(inst2)){ + if (ObjectUtil.isNotEmpty(inst2)) { startAddress2 = deviceService.queryAddressBydeviceCode(inst2.getStart_point_code()); putAddress2 = deviceService.queryAddressBydeviceCode(inst2.getPut_point_code()); nextAddress2 = deviceService.queryAddressBydeviceCode(inst2.getNext_point_code()); } - byte ikeyhigh = (byte) IntToHexHigh(Integer.parseInt(instcode)); byte ikeylow = (byte) IntToHexLow(Integer.parseInt(instcode)); byte typehigh = (byte) IntToHexHigh(type); @@ -475,18 +541,18 @@ public class AgvServiceImpl implements AgvService { String str = "十进制下发:"; String str1 = "十六进制下发:"; - str1+="ikey:"+hexToString(ikeyhigh & 0xFF)+hexToString(ikeylow & 0xFF); + str1 += "ikey:" + hexToString(ikeyhigh & 0xFF) + hexToString(ikeylow & 0xFF); - str+="/type:"+(type); - str1+="/type:"+hexToString(typehigh & 0xFF)+hexToString(typelow & 0xFF); + str += "/type:" + (type); + str1 += "/type:" + hexToString(typehigh & 0xFF) + hexToString(typelow & 0xFF); - str1+="/qhd1:"+hexToString(qhd1high & 0xFF)+hexToString(qhd1low & 0xFF); - str1+="/qhd2:"+hexToString(qhd2high & 0xFF)+hexToString(qhd2low & 0xFF); - str1+="/dld1:"+hexToString(dld1high & 0xFF)+hexToString(dld1low & 0xFF); + str1 += "/qhd1:" + hexToString(qhd1high & 0xFF) + hexToString(qhd1low & 0xFF); + str1 += "/qhd2:" + hexToString(qhd2high & 0xFF) + hexToString(qhd2low & 0xFF); + str1 += "/dld1:" + hexToString(dld1high & 0xFF) + hexToString(dld1low & 0xFF); - str1+="/dld2:"+hexToString(dld2high & 0xFF)+hexToString(dld2low & 0xFF); - str1+="/fhd1:"+hexToString(fhd1high & 0xFF)+hexToString(fhd1low & 0xFF); - str1+="/fhd2:"+hexToString(fhd2high & 0xFF)+hexToString(fhd2low & 0xFF); + str1 += "/dld2:" + hexToString(dld2high & 0xFF) + hexToString(dld2low & 0xFF); + str1 += "/fhd1:" + hexToString(fhd1high & 0xFF) + hexToString(fhd1low & 0xFF); + str1 += "/fhd2:" + hexToString(fhd2high & 0xFF) + hexToString(fhd2low & 0xFF); System.out.println(str); System.out.println(str1); @@ -558,7 +624,7 @@ public class AgvServiceImpl implements AgvService { .execute(); System.out.println("查询agv状态数据:" + result.body()); if (result.getStatus() == 200) { - JSONArray ja = (JSONArray)JSONArray.parse(result.body()); + JSONArray ja = (JSONArray) JSONArray.parse(result.body()); for (int i = 0; i < ja.size(); i++) { JSONObject jo = (JSONObject) ja.get(i); String name = jo.getString("name"); @@ -611,7 +677,7 @@ public class AgvServiceImpl implements AgvService { System.out.println("查询agv状态数据:" + result.body()); if (result.getStatus() == 200) { - JSONArray ja = (JSONArray)JSONArray.parse(result.body()); + JSONArray ja = (JSONArray) JSONArray.parse(result.body()); for (int i = 0; i < ja.size(); i++) { JSONObject jo = (JSONObject) ja.get(i); @@ -619,7 +685,7 @@ public class AgvServiceImpl implements AgvService { String state = jo.getString("state"); String energyLevel = jo.getString("energyLevel"); String transportOrder = jo.getString("transportOrder"); - JSONObject detailjo = (JSONObject)JSONObject.parse(result2.body()); + JSONObject detailjo = (JSONObject) JSONObject.parse(result2.body()); JSONObject item = (JSONObject) detailjo.get(name); String x = item.getString("x"); String y = item.getString("y"); @@ -647,10 +713,8 @@ public class AgvServiceImpl implements AgvService { } - @Override public HttpResponse queryXZAgvInstStatus(String instCode) { - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) { String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); @@ -667,8 +731,31 @@ public class AgvServiceImpl implements AgvService { return null; } + } + @Override + public HttpResponse queryZDAgvInstStatus(String type) { + if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) { + String agvurl = ""; + if (type.equals("1")) { + agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); + } + if (type.equals("2")) { + agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL2); + } + String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); + agvurl = agvurl + ":" + agvport + "/transportOrders"; + + HttpResponse result = HttpRequest.get(agvurl) + .timeout(20000)//超时,毫秒 + .execute(); + System.out.println("查询agv指令数据:" + result.body()); + + return result; + } else { + return null; + } } @Override @@ -755,22 +842,22 @@ public class AgvServiceImpl implements AgvService { (byte) indexhigh, (byte) indexlow, }; log.info("下发删除AGV指令--{}", Bytes2HexString(b)); - if (ObjectUtil.isNotEmpty(b)){ + if (ObjectUtil.isNotEmpty(b)) { NDCSocketConnectionAutoRun.write(b); System.out.println("下发删除agv指令数据:" + Bytes2HexString(b)); } } } - //1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 @Override public synchronized String process(String jobno, String type, String address, String action, String processingVehicle) { log.info("查询到AGV请求参数,jobno:{},address:{}", jobno + ",address:" + address + ",type:" + type + ",action:" + action); + //释放AGV资源,继续后续动作 boolean is_feedback = false; String str = ""; String backaddress = address; if (address.indexOf(".") > 0) { - str = address.substring(address.indexOf("."), address.length()); + str = address.substring(address.indexOf(".") + 1, address.length()); address = address.substring(0, address.indexOf(".")); } else if (address.indexOf("-") > 0) { address = address.substring(0, address.indexOf("-")); @@ -781,39 +868,258 @@ public class AgvServiceImpl implements AgvService { DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); Device addressdevice = appService.findDeviceByCode(address); - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - //请求进入 - if ("onEntry".equals(type)) { - } else if ("onStation".equals(type)) { + CargoLiftConveyorDeviceDriver cargoLiftConveyorDeviceDriver; + EmptyVehicleStackingPositionDeviceDriver emptyVehicleStackingPositionDeviceDriver; + HailiangSmartplcTestDeviceDriver hailiangSmartplcTestDeviceDriver; + HaoKaiAutoConveyorDeviceDriver haoKaiAutoConveyorDeviceDriver; + PaintConveyorDeviceDriver paintConveyorDeviceDriver; + //取货的进入前等待和离开等待 + if (action.equals("Load")) { + if ("EntryRequired".equals(type)) { + //共挤线三工位 + if (addressdevice.getDeviceDriver() instanceof HailiangSmartplcTestDeviceDriver) { + hailiangSmartplcTestDeviceDriver = (HailiangSmartplcTestDeviceDriver) addressdevice.getDeviceDriver(); + if ((hailiangSmartplcTestDeviceDriver.getAction() == 1 || hailiangSmartplcTestDeviceDriver.getAction() == 3) && hailiangSmartplcTestDeviceDriver.getMove() == 1) { + inst.setExecute_status("1"); + is_feedback = true; + } + } + //叠盘位 + if (addressdevice.getDeviceDriver() instanceof EmptyVehicleStackingPositionDeviceDriver) { + emptyVehicleStackingPositionDeviceDriver = (EmptyVehicleStackingPositionDeviceDriver) addressdevice.getDeviceDriver(); + int number = emptyVehicleStackingPositionDeviceDriver.getNumber(); + if (number < Integer.valueOf(str)) { + log.info("叠盘位:" + jobno + "当前层高为:" + number + ",不存在第" + str + "的托盘!"); + return null; + } + inst.setExecute_status("1"); + is_feedback = true; + } + //货梯对接线 + if (addressdevice.getDeviceDriver() instanceof CargoLiftConveyorDeviceDriver) { + cargoLiftConveyorDeviceDriver = (CargoLiftConveyorDeviceDriver) addressdevice.getDeviceDriver(); + if ((cargoLiftConveyorDeviceDriver.getAction() == 1 || cargoLiftConveyorDeviceDriver.getAction() == 3) && cargoLiftConveyorDeviceDriver.getMove() == 1) { + inst.setExecute_status("1"); + is_feedback = true; + } + } + //豪凯自动线对接位 + if (addressdevice.getDeviceDriver() instanceof HaoKaiAutoConveyorDeviceDriver) { + haoKaiAutoConveyorDeviceDriver = (HaoKaiAutoConveyorDeviceDriver) addressdevice.getDeviceDriver(); + if ((haoKaiAutoConveyorDeviceDriver.getAction() == 1 || haoKaiAutoConveyorDeviceDriver.getAction() == 3) && haoKaiAutoConveyorDeviceDriver.getMove() == 1) { + inst.setExecute_status("1"); + is_feedback = true; + } + } + //油漆线 + if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { + paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); + if ((paintConveyorDeviceDriver.getAction() == 1 || paintConveyorDeviceDriver.getAction() == 3) && paintConveyorDeviceDriver.getMove() == 1) { + inst.setExecute_status("1"); + is_feedback = true; + } + } + } + if ("PauseOnStation".equals(type)) { + if (addressdevice.getDeviceDriver() instanceof HailiangSmartplcTestDeviceDriver) { + hailiangSmartplcTestDeviceDriver = (HailiangSmartplcTestDeviceDriver) addressdevice.getDeviceDriver(); + inst.setExecute_status("2"); + hailiangSmartplcTestDeviceDriver.writing(2); + is_feedback = true; + } + + if (addressdevice.getDeviceDriver() instanceof EmptyVehicleStackingPositionDeviceDriver) { + emptyVehicleStackingPositionDeviceDriver = (EmptyVehicleStackingPositionDeviceDriver) addressdevice.getDeviceDriver(); + inst.setExecute_status("2"); + emptyVehicleStackingPositionDeviceDriver.writing(2); + is_feedback = true; + } + + if (addressdevice.getDeviceDriver() instanceof CargoLiftConveyorDeviceDriver) { + cargoLiftConveyorDeviceDriver = (CargoLiftConveyorDeviceDriver) addressdevice.getDeviceDriver(); + inst.setExecute_status("2"); + cargoLiftConveyorDeviceDriver.writing(2); + is_feedback = true; + } + + if (addressdevice.getDeviceDriver() instanceof HaoKaiAutoConveyorDeviceDriver) { + haoKaiAutoConveyorDeviceDriver = (HaoKaiAutoConveyorDeviceDriver) addressdevice.getDeviceDriver(); + inst.setExecute_status("2"); + haoKaiAutoConveyorDeviceDriver.writing(2); + is_feedback = true; + } + + if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { + paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); + inst.setExecute_status("2"); + paintConveyorDeviceDriver.writing(2); + is_feedback = true; + } + + } } + //等待点等待 + if (action.equals("Wait")) { + if ("Wait".equals(type)) { + JSONObject jo = new JSONObject(); + jo.put("task_code", inst.getInstruction_code()); + JSONArray destinations = new JSONArray(); + String inst_type = inst.getInstruction_type(); + //如果任务类型为1,在点位进行等待,则查询当前叠盘位的数量,取当前数量的层数进行追加任务 + if ("1".equals(inst_type)) { + emptyVehicleStackingPositionDeviceDriver = (EmptyVehicleStackingPositionDeviceDriver) addressdevice.getDeviceDriver(); + int current_num = emptyVehicleStackingPositionDeviceDriver.getNumber(); + if (current_num > 12) { + log.info("当前叠盘架:" + jobno + "已放满!"); + return null; + } + String start_point_code = inst.getStart_point_code(); + String next_point_code = inst.getNext_point_code(); + start_point_code = start_point_code + "." + (current_num + 1); + destinations.add(destination(start_point_code, "Load", "1", "1")); + destinations.add(destination(next_point_code, "Unload", "1", "1")); + } + + //如果任务类型为2,在点位进行等待,则调用LMS的货位申请接口 + if ("2".equals(inst_type)) { + String next_point_code = ""; + //调用LMS接口 + + + destinations.add(destination(next_point_code, "Unload", "5", "1")); + } + jo.put("destinations", destinations); + + String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); + String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); + + String url = agvurl + ":" + agvport + "addDestinations"; + log.info("下发agv任务请求:{}", url); + + HttpResponse result = HttpRequest.post(url) + .body(String.valueOf(jo))//表单内容 + .timeout(20000)//超时,毫秒 + .execute(); + log.info("下发agv任务请求反馈:{}", result); + + //对任务进行封口 + JSONObject complete = new JSONObject(); + complete.put("task_code", inst.getInstruction_code()); + + String url2 = agvurl + ":" + agvport + "markComplete"; + log.info("下发agv任务请求:{}", url2); + + HttpResponse result2 = HttpRequest.post(url2) + .body(String.valueOf(complete))//表单内容 + .timeout(20000)//超时,毫秒 + .execute(); + log.info("下发agv任务请求反馈:{}", result2); + } + } + //放货的进入前等待和离开等待 + if (action.equals("Unload")) { + if ("EntryRequired".equals(type)) { + if (addressdevice.getDeviceDriver() instanceof HailiangSmartplcTestDeviceDriver) { + hailiangSmartplcTestDeviceDriver = (HailiangSmartplcTestDeviceDriver) addressdevice.getDeviceDriver(); + if ((hailiangSmartplcTestDeviceDriver.getAction() == 2 || hailiangSmartplcTestDeviceDriver.getAction() == 3) && hailiangSmartplcTestDeviceDriver.getMove() == 0) { + inst.setExecute_status("3"); + is_feedback = true; + } + } + + if (addressdevice.getDeviceDriver() instanceof EmptyVehicleStackingPositionDeviceDriver) { + emptyVehicleStackingPositionDeviceDriver = (EmptyVehicleStackingPositionDeviceDriver) addressdevice.getDeviceDriver(); + int number = emptyVehicleStackingPositionDeviceDriver.getNumber(); + if (number >= Integer.valueOf(str)) { + log.info("叠盘位:" + jobno + "第" + str + "上有货!"); + return null; + } + inst.setExecute_status("3"); + is_feedback = true; + } + + if (addressdevice.getDeviceDriver() instanceof CargoLiftConveyorDeviceDriver) { + cargoLiftConveyorDeviceDriver = (CargoLiftConveyorDeviceDriver) addressdevice.getDeviceDriver(); + if ((cargoLiftConveyorDeviceDriver.getAction() == 2 || cargoLiftConveyorDeviceDriver.getAction() == 3) && cargoLiftConveyorDeviceDriver.getMove() == 0) { + inst.setExecute_status("3"); + is_feedback = true; + } + } + + if (addressdevice.getDeviceDriver() instanceof HaoKaiAutoConveyorDeviceDriver) { + haoKaiAutoConveyorDeviceDriver = (HaoKaiAutoConveyorDeviceDriver) addressdevice.getDeviceDriver(); + if ((haoKaiAutoConveyorDeviceDriver.getAction() == 2 || haoKaiAutoConveyorDeviceDriver.getAction() == 3) && haoKaiAutoConveyorDeviceDriver.getMove() == 0) { + inst.setExecute_status("3"); + is_feedback = true; + } + } + + if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { + paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); + if ((paintConveyorDeviceDriver.getAction() == 2 || paintConveyorDeviceDriver.getAction() == 3) && paintConveyorDeviceDriver.getMove() == 0) { + inst.setExecute_status("3"); + is_feedback = true; + } + } + } + if ("PauseOnStation".equals(type)) { + if (addressdevice.getDeviceDriver() instanceof HailiangSmartplcTestDeviceDriver) { + hailiangSmartplcTestDeviceDriver = (HailiangSmartplcTestDeviceDriver) addressdevice.getDeviceDriver(); + inst.setExecute_status("4"); + hailiangSmartplcTestDeviceDriver.writing(3); + is_feedback = true; + } + + if (addressdevice.getDeviceDriver() instanceof EmptyVehicleStackingPositionDeviceDriver) { + emptyVehicleStackingPositionDeviceDriver = (EmptyVehicleStackingPositionDeviceDriver) addressdevice.getDeviceDriver(); + inst.setExecute_status("4"); + emptyVehicleStackingPositionDeviceDriver.writing(3); + is_feedback = true; + } + + if (addressdevice.getDeviceDriver() instanceof CargoLiftConveyorDeviceDriver) { + cargoLiftConveyorDeviceDriver = (CargoLiftConveyorDeviceDriver) addressdevice.getDeviceDriver(); + inst.setExecute_status("4"); + cargoLiftConveyorDeviceDriver.writing(3); + is_feedback = true; + } + + if (addressdevice.getDeviceDriver() instanceof HaoKaiAutoConveyorDeviceDriver) { + haoKaiAutoConveyorDeviceDriver = (HaoKaiAutoConveyorDeviceDriver) addressdevice.getDeviceDriver(); + inst.setExecute_status("4"); + haoKaiAutoConveyorDeviceDriver.writing(3); + is_feedback = true; + } + + if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { + paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); + inst.setExecute_status("4"); + paintConveyorDeviceDriver.writing(3); + is_feedback = true; + } + } + } JSONObject requestjo = new JSONObject(); - JSONArray ja = new JSONArray(); if (is_feedback) { - String param = ""; - JSONObject jo = new JSONObject(); - if (str.length() > 0) { - backaddress = backaddress + str; + requestjo.put("task_code",jobno); + requestjo.put("operation",action); + if (type.equals("entryRequired") || type.equals("EntryRequired")){ + requestjo.put("entryRequired","true"); + }else { + requestjo.put("pauseOnStation","true"); } - if ("onEntry".equals(type)) { - param = "EntryPermitted-" + backaddress + action; - } else if ("onStation".equals(type)) { - param = "ContinueOnStation-" + backaddress + action; - } - - jo.put("key", param); - jo.put("value", "False"); - ja.add(jo); - requestjo.put("properties", ja); log.info("反馈AGV请求数据:{}", requestjo); System.out.println("back agv:" + requestjo); String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); + if (inst.getInstruction_type().equals("4")){ + agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL2); + } agvurl = agvurl + ":" + agvport + "/v1/transportOrders/" + jobno + "/interact"; HttpResponse result = HttpRequest.post(agvurl) @@ -821,7 +1127,6 @@ public class AgvServiceImpl implements AgvService { .timeout(20000)//超时,毫秒 .execute(); } - is_feedback = false; return requestjo.toString(); @@ -1077,22 +1382,22 @@ public class AgvServiceImpl implements AgvService { @Override public byte[] sendAgvTwoModeInst(int phase, int index, int result) { - if(phase<0 || index<0) + if (phase < 0 || index < 0) return null; - byte indexhigh=(byte)IntToHexHigh(index); - byte indexlow=(byte)IntToHexLow(index); - byte phasehigh=(byte)IntToHexHigh(phase); - byte phaselow=(byte)IntToHexLow(phase); + byte indexhigh = (byte) IntToHexHigh(index); + byte indexlow = (byte) IntToHexLow(index); + byte phasehigh = (byte) IntToHexHigh(phase); + byte phaselow = (byte) IntToHexLow(phase); - byte[] b = new byte[]{(byte) 0X87,(byte)0XCD, - (byte)0X00,(byte)0X08, - (byte)0X00,(byte)0X0A, - (byte)0X00,(byte)0X01, - (byte)0X00,(byte)0X6D, - (byte)0X00,(byte)0X06, + byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X0A, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X6D, + (byte) 0X00, (byte) 0X06, (byte) indexhigh, (byte) indexlow, - (byte)0X01,(byte)0X14, - (byte)phasehigh,(byte)phaselow + (byte) 0X01, (byte) 0X14, + (byte) phasehigh, (byte) phaselow }; log.info("反馈agv动作数据--index:" + hexToString(indexhigh & 0xFF) + hexToString(indexlow & 0xFF) + ",phase:" + hexToString(phasehigh & 0xFF) + hexToString(phaselow & 0xFF)); diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/common/StandardCoveyorControlWithScannerDevice.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/common/StandardCoveyorControlWithScannerDevice.java index 562f7cc..8941e37 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/common/StandardCoveyorControlWithScannerDevice.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/common/StandardCoveyorControlWithScannerDevice.java @@ -20,11 +20,7 @@ public class StandardCoveyorControlWithScannerDevice extends AbstractDriverServi JSONObject jo = super.getCommonDeviceInfo(standardCoveyorControlWithScannerDeviceDriver,0,0); jo.put("error", standardCoveyorControlWithScannerDeviceDriver.getError()); jo.put("isError", standardCoveyorControlWithScannerDeviceDriver.getIserror()); - jo.put("height", standardCoveyorControlWithScannerDeviceDriver.getHeight()); - jo.put("operation_type", standardCoveyorControlWithScannerDeviceDriver.getOperation_type()); - jo.put("direction", standardCoveyorControlWithScannerDeviceDriver.getDirection()); jo.put("action", standardCoveyorControlWithScannerDeviceDriver.getAction()); - jo.put("ioaction", standardCoveyorControlWithScannerDeviceDriver.getIoaction()); try { jo.put("container", StrUtil.isEmpty(standardCoveyorControlWithScannerDeviceDriver.barcode()) ? "" : standardCoveyorControlWithScannerDeviceDriver.barcode()); } catch (Exception e) { @@ -33,7 +29,6 @@ public class StandardCoveyorControlWithScannerDevice extends AbstractDriverServi jo.put("message", StrUtil.equals(standardCoveyorControlWithScannerDeviceDriver.getMessage(), "null") ? "" : standardCoveyorControlWithScannerDeviceDriver.getMessage()); jo.put("requestSucess", standardCoveyorControlWithScannerDeviceDriver.getRequireSucess().toString()); jo.put("applySucess", standardCoveyorControlWithScannerDeviceDriver.getApplySucess().toString()); - jo.put("instruction_message", standardCoveyorControlWithScannerDeviceDriver.getInst_message()); return jo; } } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/config/AcsConfig.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/config/AcsConfig.java index c004021..c772c86 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/config/AcsConfig.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/config/AcsConfig.java @@ -14,8 +14,10 @@ public interface AcsConfig { String CREATETASKCHECK = "createTaskCheck"; //撤销任务检查 String CANCELTASKCHECK = "cancelTaskCheck"; - //双工agv系统接口地址 + //二楼agv系统接口地址 String AGVURL = "agvurl"; + //一楼agv系统接口地址 + String AGVURL2 = "agvurl"; //双工AGV系统端口 String AGVPORT = "agvport"; //单工agv系统接口地址 diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index 2db1f62..6f46ade 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -17,14 +17,21 @@ public enum DriverTypeEnum { SCANNER(4, "standard_scanner", "标准版-扫码器", "scanner"), - INSPECT_CONVEYOR_CONTROL_WITH_SCANNER(5, "standard_conveyor_control_with_scanner", "标准版-输送机-控制点-关联扫码", "conveyor"), + INSPECT_CONVEYOR_CONTROL(5, "standard_conveyor_control", "标准版-输送机-控制点", "conveyor"), - INSPECT_CONVEYOR_CONTROL(6, "standard_conveyor_control", "标准版-输送机-控制点", "conveyor"), + INSPECT_CONVEYOR_MONITOR(6, "standard_conveyor_monitor", "标准版-输送机-监控点", "conveyor"), - INSPECT_CONVEYOR_MONITOR(7, "standard_conveyor_monitor", "标准版-输送机-监控点", "conveyor"), + HAILIANG_SMART_PLC_TEST(7, "hailiang_smart_plc_test", "永裕共挤线-西门子SMART200PLC", "conveyor"), - HAILIANG_SMART_PLC_TEST(8, "hailiang_smart_plc_test", "永裕共挤线-西门子SMART200PLC", "conveyor"); + EMPTY_VEHICLE_STACKING_POSITION(8, "empty_vehicle_stacking_position", "永裕叠盘位-西门子SMART200PLC", "conveyor"), + CARGO_LIFT_CONVEYOR(9, "cargo_lift_conveyor", "货梯对接线", "conveyor"), + + INSPECT_CONVEYOR_CONTROL_WITH_SCANNER(10, "standard_conveyor_control_with_scanner", "货梯对接线-关联扫码", "conveyor"), + + HAOKAI_AUTO_CONVEYOR(11, "haokai_auto_conveyor", "豪恺自动线对接位", "conveyor"), + + PAINT_CONVEYOR(12, "paint_conveyor", "油漆线", "conveyor"); //驱动索引 diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java index c973d9c..52acd6f 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java @@ -73,14 +73,6 @@ public class DeviceController { deviceService.downDeviceDBloadCSV(deviceService.queryDeviceProtocol(whereJson), response); } - @Log("导出欧姆龙设备协议CSV") - @ApiOperation("导出欧姆龙设备协议CSV") - @GetMapping(value = "/protocol/downloadoumulongCSV") - //@PreAuthorize("@el.check('device:list')") - public void downDeviceDBloadOumulongCSV(HttpServletResponse response, @RequestParam Map whereJson) throws IOException { - deviceService.downDeviceDBloadOumulongCSV(deviceService.queryDeviceProtocol(whereJson), response); - } - @PostMapping @Log("新增设备") @ApiOperation("新增设备") @@ -374,4 +366,20 @@ public class DeviceController { return new ResponseEntity<>(DriverTypeEnum.getList(), HttpStatus.OK); } + @Log("导出Smart设备协议CSV") + @ApiOperation("导出Smart设备协议CSV") + @GetMapping(value = "/protocol/downloadSmartCSV") +//@PreAuthorize("@el.check('device:list')") + public void downDeviceDBloadOumulongCSV(HttpServletResponse response, @RequestParam Map whereJson) throws IOException { + deviceService.downDeviceDBloadSmartCSV(deviceService.queryDeviceProtocol(whereJson), response); + } + + @Log("导出FX5U设备协议CSV") + @ApiOperation("导出FX5U设备协议CSV") + @GetMapping(value = "/protocol/downloadFX5UCSV") +//@PreAuthorize("@el.check('device:list')") + public void downDeviceDBloadFX5UCSV(HttpServletResponse response, @RequestParam Map whereJson) throws IOException { + deviceService.downDeviceDBloadFX5UCSV(deviceService.queryDeviceProtocol(whereJson), response); + } + } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java index ac201f5..708d0e2 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java @@ -285,4 +285,8 @@ public interface DeviceService { * @throws IOException / */ void downloadProtocolConfig(JSONObject whereJson, HttpServletResponse response) throws IOException; + + void downDeviceDBloadSmartCSV(JSONArray queryDeviceProtocol, HttpServletResponse response); + + void downDeviceDBloadFX5UCSV(JSONArray queryDeviceProtocol, HttpServletResponse response); } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java index 54aa8e5..a31f3a1 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java @@ -1719,6 +1719,94 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial } } + @Override + public void downDeviceDBloadSmartCSV(JSONArray jsonarr, HttpServletResponse response) { + List cellList = new ArrayList<>(); + for (int i = 0; i < jsonarr.size(); i++) { + List item = new ArrayList(); + JSONObject jo = jsonarr.getJSONObject(i); + String extra_code = jo.getString("extra_code"); + //校验数据 格式为: RD1.RD1.A1.mode + int num = countStr(extra_code, "."); + if (num != 3) { + throw new BadRequestException(extra_code + "数据格式不正确"); + } + + extra_code = extra_code.substring(extra_code.indexOf(".") + 1, extra_code.length()); + extra_code = extra_code.substring(extra_code.indexOf(".") + 1, extra_code.length()); + item.add(extra_code); + item.add(jo.get("extra_name")); + String datatype = jo.getString("extra_name"); + //西门子200 + if (!datatype.contains(".")) { + String[] split = datatype.split(""); + if (split[1].equals("W")) { + datatype = "Word"; + } else if (split[1].equals("D")) { + datatype = "DWord"; + } + } else { + datatype = "Boolean"; + } + + item.add(datatype); + item.add("1"); + item.add("R/W"); + item.add("100"); + + cellList.add(item.toArray()); + } + + String[] tableHeaderArr = {"Tag Name", "Address", "Data Type", "Respect Data Type", + "Client Access", "Scan Rate"}; + String fileName = "导出文件.csv"; + byte[] bytes = ExportCSVUtil.writeCsvAfterToBytes(tableHeaderArr, cellList); + ExportCSVUtil.responseSetProperties(fileName, bytes, response); + } + + @Override + public void downDeviceDBloadFX5UCSV(JSONArray jsonarr, HttpServletResponse response) { + List cellList = new ArrayList<>(); + for (int i = 0; i < jsonarr.size(); i++) { + List item = new ArrayList(); + JSONObject jo = jsonarr.getJSONObject(i); + String extra_code = jo.getString("extra_code"); + //校验数据 格式为: RD1.RD1.A1.mode + int num = countStr(extra_code, "."); + if (num != 3) { + throw new BadRequestException(extra_code + "数据格式不正确"); + } + + extra_code = extra_code.substring(extra_code.indexOf(".") + 1, extra_code.length()); + extra_code = extra_code.substring(extra_code.indexOf(".") + 1, extra_code.length()); + item.add(extra_code); + item.add(jo.get("extra_name")); + String datatype = jo.getString("extra_name"); + //FX5U + if (!datatype.contains(".")) { + String[] split = datatype.split(""); + if (split[1].equals("D")) { + datatype = "Long"; + } + } else { + datatype = "Boolean"; + } + + item.add(datatype); + item.add("1"); + item.add("R/W"); + item.add("100"); + + cellList.add(item.toArray()); + } + + String[] tableHeaderArr = {"Tag Name", "Address", "Data Type", "Respect Data Type", + "Client Access", "Scan Rate"}; + String fileName = "导出文件.csv"; + byte[] bytes = ExportCSVUtil.writeCsvAfterToBytes(tableHeaderArr, cellList); + ExportCSVUtil.responseSetProperties(fileName, bytes, response); + } + public Map getValue1(JSONArray wss, int j, Integer dbInterval, int i){ int size = wss.size(); Map map = new ListOrderedMap<>(); diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/wql/task_inst.xls b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/wql/task_inst.xls index 50a6b44..7fe09b4 100644 Binary files a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/wql/task_inst.xls and b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/wql/task_inst.xls differ diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/CargoLiftConveyorDefination.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/CargoLiftConveyorDefination.java new file mode 100644 index 0000000..44bdb8c --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/CargoLiftConveyorDefination.java @@ -0,0 +1,60 @@ +package org.nl.acs.device_driver.basedriver.cargo_lift_conveyor; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮迅捷plc测试 + */ +@Service +public class CargoLiftConveyorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "cargo_lift_conveyor"; + } + + @Override + public String getDriverName() { + return "货梯对接线"; + } + + @Override + public String getDriverDescription() { + return "货梯对接线"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new CargoLiftConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return CargoLiftConveyorDeviceDriver.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/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/CargoLiftConveyorDeviceDriver.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/CargoLiftConveyorDeviceDriver.java new file mode 100644 index 0000000..88cad73 --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/CargoLiftConveyorDeviceDriver.java @@ -0,0 +1,208 @@ +package org.nl.acs.device_driver.basedriver.cargo_lift_conveyor; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.config.server.AcsConfigService; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.LogServer; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.utils.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮清洗机储料仓 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class CargoLiftConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); + @Autowired + LogServer logServer = SpringContextHolder.getBean(LogServer.class); + @Autowired + AgvService agvService = SpringContextHolder.getBean(AgvService.class); + + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + + int heartbeat = 0; + int mode = 0; + int move = 0; + int action = 0; + int error = 0; + int task = 0; + + Boolean isonline = true; + + Boolean iserror = false; + + //1-执行任务;2-取货完成;3-放货完成; + int flag; + + int last_mode = 0; + int last_move = 0; + int last_error = 0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + //请求成功标记 + Boolean requireSucess = false; + + @Override + public void execute() { + String message = null; + + device_code = this.getDeviceCode(); + heartbeat = this.itemProtocol.getItem_heartbeat(); + mode = this.itemProtocol.getItem_mode(); + move = this.itemProtocol.getItem_mode(); + error = this.itemProtocol.getItem_error(); + task = this.itemProtocol.getItem_task(); + action = this.itemProtocol.getItem_action(); + + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (move != last_move) { + if (move == 0) { + thingToNothing(); + } + } + if (error != last_error) { + } + + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (flag) { + //取货完成 + case 1: + writing(2); + break; + //放货完成 + case 2: + writing(3); + break; + + } + } + + last_mode = mode; + last_move = move; + last_error = error; + } + + + public synchronized boolean instruction_apply(String container_code) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_apply_time = date; + requireSucess = true; + return true; + } + } + + protected void thingToNothing() { + + } + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + } + + public void writing(int type, int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (type == 1) { + itemMap.put(to_command, command); + log.info("设备:" + device_code + ",下发PLC信号" + to_command + ",value:" + command); + } else if (type == 2) { + itemMap.put(to_target, command); + log.info("设备:" + device_code + ",下发PLC信号" + to_target + ",value:" + command); + + } else if (type == 3) { + itemMap.put(to_task, command); + log.info("设备:" + device_code + ",下发PLC信号" + to_task + ",value:" + command); + } + + ReadUtil.write(itemMap, server); + } +} diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/ItemProtocol.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/ItemProtocol.java new file mode 100644 index 0000000..1be3569 --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/cargo_lift_conveyor/ItemProtocol.java @@ -0,0 +1,94 @@ +package org.nl.acs.device_driver.basedriver.cargo_lift_conveyor; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position.EmptyVehicleStackingPositionDeviceDriver; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_move = "move"; + public static String item_action = "action"; + public static String item_error = "error"; + public static String item_task = "task"; + + + public static String item_to_command = "to_command"; + public static String item_to_target = "to_target"; + public static String item_to_task = "to_task"; + + + private CargoLiftConveyorDeviceDriver driver; + + public ItemProtocol(CargoLiftConveyorDeviceDriver driver) { + this.driver = driver; + } + + public int getItem_heartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getItem_mode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getItem_move() { + return this.getOpcIntegerValue(item_move); + } + + public int getItem_error() { + return this.getOpcIntegerValue(item_error); + } + + public int getItem_action() { + return this.getOpcIntegerValue(item_action); + } + + public int getItem_task() { + return this.getOpcIntegerValue(item_task); + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "VW0")); + list.add(new ItemDto(item_mode, "工作模式", "VW2")); + list.add(new ItemDto(item_move, "光电信号", "VW4")); + list.add(new ItemDto(item_action, "取放信号", "VW6")); + list.add(new ItemDto(item_error, "故障", "VW8")); + list.add(new ItemDto(item_task, "任务号", "VD10")); + + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "VW102")); + list.add(new ItemDto(item_to_target, "下发目标站", "VW104")); + list.add(new ItemDto(item_to_task, "任务号", "VD108")); + return list; + } + + +} + diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/EmptyVehicleStackingPositionDefination.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/EmptyVehicleStackingPositionDefination.java new file mode 100644 index 0000000..57b0b11 --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/EmptyVehicleStackingPositionDefination.java @@ -0,0 +1,60 @@ +package org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮迅捷plc测试 + */ +@Service +public class EmptyVehicleStackingPositionDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "empty_vehicle_stacking_position"; + } + + @Override + public String getDriverName() { + return "永裕叠盘位smart200"; + } + + @Override + public String getDriverDescription() { + return "永裕叠盘位smart200"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new EmptyVehicleStackingPositionDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return EmptyVehicleStackingPositionDeviceDriver.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/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/EmptyVehicleStackingPositionDeviceDriver.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/EmptyVehicleStackingPositionDeviceDriver.java new file mode 100644 index 0000000..d4ec4f5 --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/EmptyVehicleStackingPositionDeviceDriver.java @@ -0,0 +1,194 @@ +package org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.config.server.AcsConfigService; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.LogServer; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.utils.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮清洗机储料仓 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class EmptyVehicleStackingPositionDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); + @Autowired + LogServer logServer = SpringContextHolder.getBean(LogServer.class); + @Autowired + AgvService agvService = SpringContextHolder.getBean(AgvService.class); + + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + + int heartbeat = 0; + int mode = 0; + int move = 0; + int error = 0; + int number = 0; + int container_type = 0; + int task = 0; + + Boolean isonline = true; + + Boolean iserror = false; + + //1-执行任务;2-取货完成;3-放货完成; + int flag; + + int last_mode = 0; + int last_move = 0; + int last_error = 0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + //请求成功标记 + Boolean requireSucess = false; + + @Override + public void execute() { + String message = null; + + device_code = this.getDeviceCode(); + heartbeat = this.itemProtocol.getItem_heartbeat(); + mode = this.itemProtocol.getItem_mode(); + move = this.itemProtocol.getItem_mode(); + error = this.itemProtocol.getItem_error(); + number = this.itemProtocol.getItem_number(); + container_type = this.itemProtocol.getItem_container_type(); + task = this.itemProtocol.getItem_task(); + + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (move != last_move) { + if (move == 0) { + thingToNothing(); + } + } + if (error != last_error) { + } + + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (flag) { + //取货完成 + case 1: + writing(2); + break; + //放货完成 + case 2: + writing(3); + break; + + } + } + + last_mode = mode; + last_move = move; + last_error = error; + } + + + public synchronized boolean instruction_apply(String container_code) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_apply_time = date; + requireSucess = true; + return true; + } + } + + protected void thingToNothing() { + + } + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, value); + ReadUtil.write(itemMap, server); + } +} diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/ItemProtocol.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/ItemProtocol.java new file mode 100644 index 0000000..adc0f2a --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/empty_vehicle_stacking_position/ItemProtocol.java @@ -0,0 +1,100 @@ +package org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_move = "move"; + public static String item_error = "error"; + public static String item_number = "number"; + public static String item_container_type = "container_type"; + public static String item_task = "task"; + + + public static String item_to_command = "to_command"; + public static String item_to_target = "to_target"; + public static String item_to_container_type = "to_container_type"; + public static String item_to_task = "to_task"; + + + private EmptyVehicleStackingPositionDeviceDriver driver; + + public ItemProtocol(EmptyVehicleStackingPositionDeviceDriver driver) { + this.driver = driver; + } + + public int getItem_heartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getItem_mode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getItem_move() { + return this.getOpcIntegerValue(item_move); + } + + public int getItem_error() { + return this.getOpcIntegerValue(item_error); + } + + public int getItem_number() { + return this.getOpcIntegerValue(item_number); + } + + public int getItem_container_type() { + return this.getOpcIntegerValue(item_container_type); + } + + public int getItem_task() { + return this.getOpcIntegerValue(item_task); + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "VW0")); + list.add(new ItemDto(item_mode, "工作模式", "VW2")); + list.add(new ItemDto(item_move, "光电信号", "VW4")); + list.add(new ItemDto(item_number, "数量", "VW6")); + list.add(new ItemDto(item_container_type, "托盘类型", "VW8")); + list.add(new ItemDto(item_error, "故障", "VW10")); + list.add(new ItemDto(item_task, "任务号", "VD12")); + + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "VW52")); + list.add(new ItemDto(item_to_target , "下发目标站", "VW54")); + list.add(new ItemDto(item_to_task, "任务号", "VD58")); + return list; + } + + +} + diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDefination.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDefination.java index 64017e2..41ac944 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDefination.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDefination.java @@ -22,12 +22,12 @@ public class HailiangSmartplcTestDefination implements OpcDeviceDriverDefination @Override public String getDriverName() { - return "海亮-西门子plc测试"; + return "永裕共挤线smart200"; } @Override public String getDriverDescription() { - return "海亮-西门子plc测试"; + return "永裕共挤线smart200"; } @Override diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDeviceDriver.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDeviceDriver.java index c5a1dbf..12724ce 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDeviceDriver.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/HailiangSmartplcTestDeviceDriver.java @@ -1,5 +1,7 @@ package org.nl.acs.device_driver.basedriver.hailiang_smart_plc_test; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -26,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -55,6 +58,11 @@ public class HailiangSmartplcTestDeviceDriver extends AbstractOpcDeviceDriver im @Autowired AgvService agvService = SpringContextHolder.getBean(AgvService.class); + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + int heartbeat = 0; int mode = 0; int move = 0; @@ -64,6 +72,17 @@ public class HailiangSmartplcTestDeviceDriver extends AbstractOpcDeviceDriver im int container_type = 0; int task = 0; + Boolean isonline = true; + + Boolean iserror = false; + + //1-执行任务;2-取货完成;3-放货完成; + int flag; + + int last_mode = 0; + int last_move = 0; + int last_error = 0; + String device_code; @Override @@ -71,23 +90,132 @@ public class HailiangSmartplcTestDeviceDriver extends AbstractOpcDeviceDriver im return this.device; } + //请求成功标记 + Boolean requireSucess = false; @Override public void execute() { + String message = null; + device_code = this.getDeviceCode(); heartbeat = this.itemProtocol.getItem_heartbeat(); mode = this.itemProtocol.getItem_mode(); - move = this.itemProtocol.getItem_mode(); + move = this.itemProtocol.getItem_move(); action = this.itemProtocol.getItem_action(); error = this.itemProtocol.getItem_error(); number = this.itemProtocol.getItem_number(); container_type = this.itemProtocol.getItem_container_type(); task = this.itemProtocol.getItem_task(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (move != last_move) { + if (move == 0) { + thingToNothing(); + } + } + if (error != last_error) { + } + + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + JSONObject jo = new JSONObject(); + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 4: + //申请空盘 + if (move == 0 && !requireSucess) { + 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); + }else { + //向LMS发送请求,发送终点和托盘类型 + jo.put("type", "1"); + jo.put("point_code", device_code); + jo.put("vehicle_num", "1"); + jo.put("vehicle_type", container_type); + String result = acsToWmsService.applyTaskToWms(jo); + JSONObject res_jo = JSONObject.parseObject(result); + if (res_jo.getString("status").equals("200")){ + requireSucess = true; + } + } + } + break; + case 5: + //满托入库 + if (move == 1 && !requireSucess) { + 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); + }else { + //向LMS发送请求,发送起点 + jo.put("type", "2"); + jo.put("point_code", device_code); + jo.put("vehicle_num", "1"); + jo.put("vehicle_type", container_type); + jo.put("qty", number); + String result = acsToWmsService.applyTaskToWms(jo); + JSONObject res_jo = JSONObject.parseObject(result); + if (res_jo.getString("status").equals("200")){ + requireSucess = true; + } + } + } + break; + } + switch (flag) { + //取货完成 + case 1: + writing(2); + break; + //放货完成 + case 2: + writing(3); + break; + + } + } + + last_mode = mode; + last_move = move; + last_error = error; + } + + + protected void thingToNothing() { + } public void writing(int command) { - + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); } public void writing(String key, String value) { diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/ItemProtocol.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/ItemProtocol.java index 4c9da20..4ecd889 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/ItemProtocol.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_smart_plc_test/ItemProtocol.java @@ -49,7 +49,7 @@ public class ItemProtocol { } public int getItem_error() { - return this.getOpcIntegerValue(item_action); + return this.getOpcIntegerValue(item_error); } public int getItem_number() { diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/haokai_auto_conveyor/HaoKaiAutoConveyorDefination.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/haokai_auto_conveyor/HaoKaiAutoConveyorDefination.java new file mode 100644 index 0000000..d8f37e4 --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/haokai_auto_conveyor/HaoKaiAutoConveyorDefination.java @@ -0,0 +1,60 @@ +package org.nl.acs.device_driver.basedriver.haokai_auto_conveyor; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮迅捷plc测试 + */ +@Service +public class HaoKaiAutoConveyorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "haokai_auto_conveyor"; + } + + @Override + public String getDriverName() { + return "豪凯自动线对接位"; + } + + @Override + public String getDriverDescription() { + return "豪凯自动线对接位"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HaoKaiAutoConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return HaoKaiAutoConveyorDeviceDriver.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/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/haokai_auto_conveyor/HaoKaiAutoConveyorDeviceDriver.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/haokai_auto_conveyor/HaoKaiAutoConveyorDeviceDriver.java new file mode 100644 index 0000000..7337bdf --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/haokai_auto_conveyor/HaoKaiAutoConveyorDeviceDriver.java @@ -0,0 +1,237 @@ +package org.nl.acs.device_driver.basedriver.haokai_auto_conveyor; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.config.server.AcsConfigService; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.LogServer; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.utils.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮清洗机储料仓 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HaoKaiAutoConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); + @Autowired + LogServer logServer = SpringContextHolder.getBean(LogServer.class); + @Autowired + AgvService agvService = SpringContextHolder.getBean(AgvService.class); + + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + + int heartbeat = 0; + int mode = 0; + int move = 0; + int action = 0; + int error = 0; + int task = 0; + + Boolean isonline = true; + + Boolean iserror = false; + + //1-执行任务;2-取货完成;3-放货完成; + int flag; + + int last_mode = 0; + int last_move = 0; + int last_error = 0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + //请求成功标记 + Boolean requireSucess = false; + + @Override + public void execute() { + String message = null; + + device_code = this.getDeviceCode(); + heartbeat = this.itemProtocol.getItem_heartbeat(); + mode = this.itemProtocol.getItem_mode(); + move = this.itemProtocol.getItem_mode(); + error = this.itemProtocol.getItem_error(); + task = this.itemProtocol.getItem_task(); + action = this.itemProtocol.getItem_action(); + + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (move != last_move) { + if (move == 0) { + thingToNothing(); + } + } + if (error != last_error) { + } + + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + //申请任务 + if (move > 0 && !requireSucess) { + message = "申请任务中..."; + JSONObject apply = new JSONObject(); + apply.put("type","8"); + apply.put("point_code",device_code); + String str = acsToWmsService.applyTaskToWms(apply); + JSONObject jo = JSON.parseObject(str); + if (ObjectUtil.isEmpty(jo)) { + message = "接口不通"; + } else { + if (jo.getInteger("status") == 200) { + requireSucess = true; + } else { + requireSucess = false; + message = jo.get("message").toString(); + } + } + } + + } + switch (flag) { + //取货完成 + case 1: + writing(2); + break; + //放货完成 + case 2: + writing(3); + break; + + } + } + + last_mode = mode; + last_move = move; + last_error = error; + } + + + public synchronized boolean instruction_apply(String container_code) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_apply_time = date; + requireSucess = true; + return true; + } + } + + protected void thingToNothing() { + this.setRequireSucess(false); + } + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + } + + public void writing(int type, int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (type == 1) { + itemMap.put(to_command, command); + log.info("设备:" + device_code + ",下发PLC信号" + to_command + ",value:" + command); + } else if (type == 2) { + itemMap.put(to_target, command); + log.info("设备:" + device_code + ",下发PLC信号" + to_target + ",value:" + command); + + } else if (type == 3) { + itemMap.put(to_task, command); + log.info("设备:" + device_code + ",下发PLC信号" + to_task + ",value:" + command); + } + + ReadUtil.write(itemMap, server); + } +} diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/haokai_auto_conveyor/ItemProtocol.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/haokai_auto_conveyor/ItemProtocol.java new file mode 100644 index 0000000..c0dbe02 --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/haokai_auto_conveyor/ItemProtocol.java @@ -0,0 +1,94 @@ +package org.nl.acs.device_driver.basedriver.haokai_auto_conveyor; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.CargoLiftConveyorDeviceDriver; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_move = "move"; + public static String item_action = "action"; + public static String item_error = "error"; + public static String item_task = "task"; + + + public static String item_to_command = "to_command"; + public static String item_to_target = "to_target"; + public static String item_to_task = "to_task"; + + + private HaoKaiAutoConveyorDeviceDriver driver; + + public ItemProtocol(HaoKaiAutoConveyorDeviceDriver driver) { + this.driver = driver; + } + + public int getItem_heartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getItem_mode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getItem_move() { + return this.getOpcIntegerValue(item_move); + } + + public int getItem_error() { + return this.getOpcIntegerValue(item_error); + } + + public int getItem_action() { + return this.getOpcIntegerValue(item_action); + } + + public int getItem_task() { + return this.getOpcIntegerValue(item_task); + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "VW0")); + list.add(new ItemDto(item_mode, "工作模式", "VW2")); + list.add(new ItemDto(item_move, "光电信号", "VW4")); + list.add(new ItemDto(item_action, "取放信号", "VW6")); + list.add(new ItemDto(item_error, "故障", "VW8")); + list.add(new ItemDto(item_task, "任务号", "VD10")); + + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "VW102")); + list.add(new ItemDto(item_to_target, "下发目标站", "VW104")); + list.add(new ItemDto(item_to_task, "任务号", "VD108")); + return list; + } + + +} + diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/ItemProtocol.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/ItemProtocol.java new file mode 100644 index 0000000..9b3b8d7 --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/ItemProtocol.java @@ -0,0 +1,100 @@ +package org.nl.acs.device_driver.basedriver.paint_conveyor; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.basedriver.hailiang_smart_plc_test.HailiangSmartplcTestDeviceDriver; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_move = "move"; + public static String item_action = "action"; + public static String item_error = "error"; + public static String item_number = "number"; + public static String item_task = "task"; + + + public static String item_to_target = "to_target";// + public static String item_to_command = "to_command";// + public static String item_to_task = "to_task";// + + + private PaintConveyorDeviceDriver driver; + + public ItemProtocol(PaintConveyorDeviceDriver driver) { + this.driver = driver; + } + + public int getItem_heartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getItem_mode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getItem_move() { + return this.getOpcIntegerValue(item_move); + } + + public int getItem_action() { + return this.getOpcIntegerValue(item_action); + } + + public int getItem_error() { + return this.getOpcIntegerValue(item_error); + } + + public int getItem_number() { + return this.getOpcIntegerValue(item_number); + } + + public int getItem_task() { + return this.getOpcIntegerValue(item_task); + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "D0000000")); + list.add(new ItemDto(item_mode, "模式", "D0000004")); + list.add(new ItemDto(item_move, "光电信号", "D0000008")); + list.add(new ItemDto(item_action, "取放信号", "D0000012")); + list.add(new ItemDto(item_error, "故障", "D0000016")); + list.add(new ItemDto(item_number, "数量", "D0000020")); + list.add(new ItemDto(item_task, "任务号", "D0000024")); + + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "D00000102")); + list.add(new ItemDto(item_to_target , "下发目标站", "D00000106")); + list.add(new ItemDto(item_to_task, "任务号", "D00000110")); + return list; + } + + +} + diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDefination.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDefination.java new file mode 100644 index 0000000..02524ca --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.paint_conveyor; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮迅捷plc测试 + */ +@Service +public class PaintConveyorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "paint_conveyor"; + } + + @Override + public String getDriverName() { + return "油漆线"; + } + + @Override + public String getDriverDescription() { + return "油漆线"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new PaintConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return PaintConveyorDeviceDriver.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/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDeviceDriver.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDeviceDriver.java new file mode 100644 index 0000000..3240558 --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDeviceDriver.java @@ -0,0 +1,261 @@ +package org.nl.acs.device_driver.basedriver.paint_conveyor; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.JSONPObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.config.server.AcsConfigService; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.LogServer; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.utils.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 海亮清洗机储料仓 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class PaintConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); + @Autowired + LogServer logServer = SpringContextHolder.getBean(LogServer.class); + @Autowired + AgvService agvService = SpringContextHolder.getBean(AgvService.class); + + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + + int heartbeat = 0; + int mode = 0; + int move = 0; + int action = 0; + int error = 0; + int number = 0; + int task = 0; + + Boolean isonline = true; + + Boolean iserror = false; + + //1-执行任务;2-取货完成;3-放货完成; + int flag; + + int last_mode = 0; + int last_move = 0; + int last_error = 0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + //请求成功标记 + Boolean requireSucess = false; + + @Override + public void execute() { + String message = null; + + device_code = this.getDeviceCode(); + heartbeat = this.itemProtocol.getItem_heartbeat(); + mode = this.itemProtocol.getItem_mode(); + move = this.itemProtocol.getItem_move(); + action = this.itemProtocol.getItem_action(); + error = this.itemProtocol.getItem_error(); + number = this.itemProtocol.getItem_number(); + task = this.itemProtocol.getItem_task(); + + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (move != last_move) { + if (move == 0) { + thingToNothing(); + } + } + if (error != last_error) { + } + + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + JSONObject jo = new JSONObject(); + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 5: + //下料位申请空盘 + if (move == 0 && !requireSucess) { + //向LMS发送请求,发送终点和托盘类型 + jo.put("type","3"); + jo.put("point_code",device_code); + jo.put("vehicle_num","10"); + String result = acsToWmsService.applyTaskToWms(jo); + JSONObject res_jo = JSONObject.parseObject(result); + if (res_jo.getString("status").equals("200")){ + requireSucess = true; + } + } + case 6: + //下料位满拖申请 + if (move == 1 && !requireSucess) { + //向LMS发送请求,发送起点 + jo.put("type","7"); + jo.put("point_code",device_code); + String result = acsToWmsService.applyTaskToWms(jo); + JSONObject res_jo = JSONObject.parseObject(result); + if (res_jo.getString("status").equals("200")){ + requireSucess = true; + } + } + case 7: + //上料位满拖申请 + if (move == 0 && !requireSucess) { + //向LMS发送请求,发送起点 + jo.put("type","4"); + jo.put("point_code",device_code); + String result = acsToWmsService.applyTaskToWms(jo); + JSONObject res_jo = JSONObject.parseObject(result); + if (res_jo.getString("status").equals("200")){ + requireSucess = true; + } + } + break; + case 8: + if (move == 1 && !requireSucess) { + //上料位空托入库 + jo.put("type", "5"); + jo.put("point_code", device_code); + jo.put("vehicle_num", number); + String result = acsToWmsService.applyTaskToWms(jo); + JSONObject res_jo = JSONObject.parseObject(result); + if (res_jo.getString("status").equals("200")){ + requireSucess = true; + } + break; + } + case 9: + if (move == 1 && !requireSucess) { + //强制满垛入库 + jo.put("type", "5"); + jo.put("point_code", device_code); + jo.put("vehicle_num", number); + String result = acsToWmsService.applyTaskToWms(jo); + JSONObject res_jo = JSONObject.parseObject(result); + if (res_jo.getString("status").equals("200")){ + requireSucess = true; + } + break; + } + } + switch (flag) { + //取货完成 + case 1: + writing(2); + break; + //放货完成 + case 2: + writing(3); + break; + + } + } + + last_mode = mode; + last_move = move; + last_error = error; + } + + + public synchronized boolean instruction_apply(String container_code) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_apply_time = date; + requireSucess = true; + return true; + } + } + + protected void thingToNothing() { + + } + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, value); + ReadUtil.write(itemMap, server); + } +} diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java index 6e95597..b29c269 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java @@ -817,7 +817,7 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp applySucess = true; } else { if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.HASWMS).toString(), "1")) { - String str = acsToWmsService.applyTaskToWms(this.getDeviceCode(), container_code, height, 0); + //String str = acsToWmsService.applyTaskToWms(this.getDeviceCode(), container_code, height, 0); JSONObject jo = JSON.parseObject(str); if (ObjectUtil.isEmpty(jo)) { message = "接口不通"; diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/ItemProtocol.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/ItemProtocol.java index 6c26264..a1c8e77 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/ItemProtocol.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/ItemProtocol.java @@ -3,7 +3,6 @@ package org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scann 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; @@ -15,17 +14,14 @@ public class ItemProtocol { public static String item_mode = "mode"; public static String item_move = "move"; public static String item_action = "action"; - public static String item_ioaction = "ioaction"; - public static String item_height = "height"; public static String item_error = "error"; - public static String item_direction = "direction"; - public static String item_operation_type = "operation_type"; public static String item_task = "task"; + public static String item_to_command = "to_command"; public static String item_to_target = "to_target"; public static String item_to_task = "to_task"; - public static String item_weight = "weight"; + private StandardCoveyorControlWithScannerDeviceDriver driver; @@ -33,70 +29,35 @@ public class ItemProtocol { this.driver = driver; } - public int getHeartbeat() { + public int getItem_heartbeat() { return this.getOpcIntegerValue(item_heartbeat); } - public int getMode() { + public int getItem_mode() { return this.getOpcIntegerValue(item_mode); } - public int getMove() { + public int getItem_move() { return this.getOpcIntegerValue(item_move); } - public int getAction() { - return this.getOpcIntegerValue(item_action); - } - - public int getIoAction() { - return this.getOpcIntegerValue(item_ioaction); - } - - public int getHeight() { - return this.getOpcIntegerValue(item_height); - } - - public int getDirection() { - return this.getOpcIntegerValue(item_direction); - } - - public int getOperation_type() { - return this.getOpcIntegerValue(item_operation_type); - } - - - public int getError() { + public int getItem_error() { return this.getOpcIntegerValue(item_error); } - public int getTask() { + public int getItem_action() { + return this.getOpcIntegerValue(item_action); + } + + public int getItem_task() { return this.getOpcIntegerValue(item_task); } - public int getToCommand() { - return this.getOpcIntegerValue(item_to_command); - } - - public int getToTarget() { - return this.getOpcIntegerValue(item_to_target); - } - - public int getToTask() { - return this.getOpcIntegerValue(item_to_task); - } - - //是否有货 - 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); @@ -108,26 +69,24 @@ public class ItemProtocol { public static List getReadableItemDtos() { ArrayList list = new ArrayList(); - list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); - list.add(new ItemDto(item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); - list.add(new ItemDto(item_move, "光电开关信号", "DB600.B2")); - list.add(new ItemDto(item_action, "取放信号", "DB600.B3")); - list.add(new ItemDto(item_ioaction, "进出类型", "DB600.B4")); - list.add(new ItemDto(item_height, "高度类型", "DB600.B5")); - list.add(new ItemDto(item_error, "报警信号", "DB600.B6")); - list.add(new ItemDto(item_direction, "电机方向", "DB600.B7")); - list.add(new ItemDto(item_operation_type, "作业类型", "DB600.B8")); - list.add(new ItemDto(item_task, "任务号", "DB600.D22")); + list.add(new ItemDto(item_heartbeat, "心跳", "VW0")); + list.add(new ItemDto(item_mode, "工作模式", "VW2")); + list.add(new ItemDto(item_move, "光电信号", "VW4")); + list.add(new ItemDto(item_action, "取放信号", "VW6")); + list.add(new ItemDto(item_error, "故障", "VW8")); + list.add(new ItemDto(item_task, "任务号", "VD10")); + return list; } public static List getWriteableItemDtos() { ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command, "作业命令", "DB601.W2", Boolean.valueOf(true))); - list.add(new ItemDto(item_to_target, "目标站", "DB601.W4")); - list.add(new ItemDto(item_to_task, "任务号", "DB601.D8")); + list.add(new ItemDto(item_to_command, "下发命令", "VW102")); + list.add(new ItemDto(item_to_target, "下发目标站", "VW104")); + list.add(new ItemDto(item_to_task, "任务号", "VD108")); return list; } + } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardConveyorControlWithScannerDefination.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardConveyorControlWithScannerDefination.java index 67f4538..93a4dd4 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardConveyorControlWithScannerDefination.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardConveyorControlWithScannerDefination.java @@ -24,12 +24,12 @@ public class StandardConveyorControlWithScannerDefination implements OpcDeviceDr @Override public String getDriverName() { - return "标准版-输送机-控制点-关联扫码器"; + return "货梯对接线-关联扫码器"; } @Override public String getDriverDescription() { - return "标准版-输送机-控制点-关联扫码器"; + return "货梯对接线-关联扫码器"; } @Override @@ -52,23 +52,9 @@ public class StandardConveyorControlWithScannerDefination implements OpcDeviceDr @Override public List getReadableItemDtos() { - return getReadableItemDtos2(); + return ItemProtocol.getReadableItemDtos(); } - public static List getReadableItemDtos2() { - List list = new ArrayList(); - list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); - list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); - list.add(new ItemDto(ItemProtocol.item_move, "光电开关信号", "DB600.B2")); - list.add(new ItemDto(ItemProtocol.item_action, "取放信号", "DB600.B3")); - list.add(new ItemDto(ItemProtocol.item_ioaction, "进出类型", "DB600.B4")); - list.add(new ItemDto(ItemProtocol.item_height, "高度类型", "DB600.B5")); - list.add(new ItemDto(ItemProtocol.item_error, "报警信号", "DB600.B6")); - list.add(new ItemDto(ItemProtocol.item_direction, "电机方向", "DB600.B7")); - list.add(new ItemDto(ItemProtocol.item_operation_type, "作业类型", "DB600.B8")); - list.add(new ItemDto(ItemProtocol.item_task, "任务号", "DB600.D22")); - return list; - } @Override public List getWriteableItemDtos() { diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java index 747739d..6b41695 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java @@ -62,83 +62,46 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); ; + String container; + protected String barcode = null; protected String formatcode = null; - String container; - String container_type_desc; - String last_container_type_desc; - String last_container; - //放货准备锁 - String putReadyLock = null; - //有货标记 - protected boolean has_goods_tag = false; - - int mode = 0; - int error = 0; - int move = 0; - int task = 0; - int height = 0; - int action = 0; - int ioaction = 0; - int direction = 0; - int operation_type = 0; - int last_mode = 0; - int last_error = 0; - int last_move = 0; - int last_task = 0; - Boolean isonline = true; - int hasGoods = 0; - String message = null; - Boolean iserror = false; - - String inst_message; - boolean hasVehicle = false; - boolean isReady = false; - protected int instruction_num = 0; - protected int instruction_num_truth = 0; - boolean isFold = false; - private String assemble_check_tag; - - protected String current_stage_instruction_message; - protected String last_stage_instruction_message; - Integer heartbeat_tag; private Date instruction_require_time = new Date(); private Date instruction_finished_time = new Date(); private Date instruction_apply_time = new Date(); private int instruction_require_time_out = 3000; - //请求成功标记 - Boolean requireSucess = false; - //申请指令成功标记 - Boolean applySucess = false; - private int instruction_finished_time_out; + int heartbeat = 0; + int mode = 0; + int move = 0; + int action = 0; + int error = 0; + int task = 0; - int branchProtocol = 0; - //备注 - String remark; - //数量 - String qty; - //物料 - String material; - //当前指令 - Instruction inst = null; - //上次指令 - Instruction last_inst = null; + Boolean isonline = true; - //触摸屏手动触发任务 - private Boolean is_has_task = false; + Boolean iserror = false; - //申请搬运任务 - private Boolean apply_handling = false; - //申请物料 - private Boolean apply_material = false; - - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + //1-执行任务;2-取货完成;3-放货完成; int flag; + int last_mode = 0; + int last_move = 0; + int last_error = 0; + int last_task = 0; + String last_container; + String device_code; + String message; + + //请求成功标记 + Boolean requireSucess = false; + + //申请成功标记 + Boolean applySucess = false; + public boolean exe_declaration() { try { this.barcode = this.barcode(); @@ -201,45 +164,24 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe String message = null; try { device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - error = this.itemProtocol.getError(); - move = this.itemProtocol.getMove(); - task = this.itemProtocol.getTask(); - action = this.itemProtocol.getAction(); - ioaction = this.itemProtocol.getIoAction(); - height = this.itemProtocol.getHeight(); - operation_type = this.itemProtocol.getOperation_type(); - direction = this.itemProtocol.getDirection(); - hasGoods = this.itemProtocol.getMove(); + heartbeat = this.itemProtocol.getItem_heartbeat(); + mode = this.itemProtocol.getItem_mode(); + move = this.itemProtocol.getItem_move(); + error = this.itemProtocol.getItem_error(); + task = this.itemProtocol.getItem_task(); + action = this.itemProtocol.getItem_action(); if (mode != last_mode) { this.setRequireSucess(false); } if (move != last_move) { - if (move == 0) { + if (move == 0 && mode == 2) { thingToNothing(); } } if (error != last_error) { } - if (mode == 2 && move != 0 && task > 0) { - //inst_message - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - if (inst != null) { - inst_message = "指令号:" + inst.getInstruction_code() + " " + inst.getStart_point_code() + "->" + inst.getNext_point_code() + " 载具号:" + inst.getVehicle_code(); - if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { - inst.setInstruction_status("1"); - instructionService.update(inst); - } - if (StrUtil.equals(inst.getInstruction_status(), "1") && StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { - finish_instruction(); - } - } - } - if (getBarcode() != null) { - - } } catch (Exception var17) { return; } @@ -270,10 +212,10 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe break; case 2: //申请任务 - if (hasGoods > 0 && !StrUtil.isEmpty(barcode()) && height > 0 && !requireSucess) { + if (move > 0 && !StrUtil.isEmpty(barcode()) && !requireSucess) { instruction_require(barcode()); } - if (hasGoods > 0 && !StrUtil.isEmpty(barcode()) && height > 0 && !applySucess) { + if (move > 0 && !StrUtil.isEmpty(barcode()) && !applySucess) { instruction_apply(barcode()); } } @@ -304,30 +246,20 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } } - public synchronized boolean finish_instruction() throws Exception { - instructionService.finish(inst); - return true; - } - protected void thingToNothing() throws Exception { this.setBarcode(null); this.setRequireSucess(false); this.setApplySucess(false); clearBarcode(); - writing(1, 0); - this.set_last_container(container, container_type_desc); - } - - public void set_last_container(String barcode, String type_desc) { - this.setInst_message(null); - this.setContainer(null); - this.set_last_container(barcode); - this.set_last_container_type_desc(type_desc); + this.set_last_container(container); } public void set_last_container(String barcode) { + this.setContainer(null); } + + public void set_last_container_type_desc(String type) { } @@ -335,53 +267,10 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe return true; } - protected void executing(Instruction instruction) { - this.executing(1, instruction, ""); - } - - public void executing(int command, Instruction instruction, String appendMessage) { - String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_command; - String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_target; - String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_task; - if (appendMessage == null) { - appendMessage = ""; - } - if (instruction != null) { - instruction_num = Integer.parseInt(instruction.getInstruction_code()); - } - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - itemMap.put(to_command, 1); - itemMap.put(to_task, instruction_num); - ReadUtil.write(itemMap, server); - - } - public void executing(Server server, Map itemMap) { ReadUtil.write(itemMap, server); } - public void writing() { - - String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_command; - String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_target; - String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_task; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - itemMap.put(to_command, 1); - itemMap.put(to_target, deviceAppservice.findDeviceByCode(inst.getNext_device_code()).getAddress()); - itemMap.put(to_task, inst.getInstruction_code()); - ReadUtil.write(itemMap, server); - } - public void writing(int command, int target, int task) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() @@ -627,7 +516,11 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } else { if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.HASWMS).toString(), "1")) { message = "申请任务中..."; - String str = acsToWmsService.applyTaskToWms(this.getDeviceCode(), container_code, height, 0); + JSONObject apply = new JSONObject(); + apply.put("type","6"); + apply.put("vehicle_code",container_code); + apply.put("point_code",device_code); + String str = acsToWmsService.applyTaskToWms(apply); JSONObject jo = JSON.parseObject(str); if (ObjectUtil.isEmpty(jo)) { message = "接口不通"; diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_scanner/StandardScannerDeviceDriver.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_scanner/StandardScannerDeviceDriver.java index 3ebed9e..086e749 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_scanner/StandardScannerDeviceDriver.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_scanner/StandardScannerDeviceDriver.java @@ -29,6 +29,7 @@ public class StandardScannerDeviceDriver extends AbstractDeviceDriver implements return StrUtil.isEmpty(ip) ? null : ip; } + @Override public String readBarcode() throws Exception { String ip = this.getIp(); if (StrUtil.isEmpty(ip)) { @@ -39,6 +40,7 @@ public class StandardScannerDeviceDriver extends AbstractDeviceDriver implements } } + @Override public void writeBarcode(String barcode) throws Exception { String ip = this.getIp(); if (StrUtil.isEmpty(ip)) { @@ -48,6 +50,7 @@ public class StandardScannerDeviceDriver extends AbstractDeviceDriver implements } } + @Override public void cleanBarcode() throws Exception { String ip = this.getIp(); if (StrUtil.isEmpty(ip)) { diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractDeviceDriver.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractDeviceDriver.java index ec3dd5f..e0c58cf 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractDeviceDriver.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractDeviceDriver.java @@ -19,6 +19,7 @@ public class AbstractDeviceDriver implements DeviceDriver { } + @Override public Device getDevice() { return this.device; } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java index 7bca6bb..edc96da 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java @@ -50,6 +50,7 @@ public interface OpcDeviceDriver extends DeviceDriver { return this.getDevice().getOpc_server_code(); } + @Override Device getDevice(); diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java index 635dda4..bfed2b2 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java @@ -34,8 +34,8 @@ public class AcsToWmsController { @PostMapping("/applyTask") @Log("向WMS申请任务") @ApiOperation("向WMS申请任务") - public ResponseEntity applyTaskToWms(@RequestBody String device_code, String container_code, int height, int weight) { - return new ResponseEntity<>(acstowmsService.applyTaskToWms(device_code, container_code, height, weight), HttpStatus.OK); + public ResponseEntity applyTaskToWms(@RequestBody JSONObject jo) { + return new ResponseEntity<>(acstowmsService.applyTaskToWms(jo), HttpStatus.OK); } @PostMapping("/taskStatusFeedback") diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java index 0f6361c..6c2487f 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java @@ -10,8 +10,14 @@ public interface AcsToWmsService { /** * ACS向WMS申请任务 + * type:必填;1共挤线申请空盘、2共挤线满托入库、3油漆线申请空盘、4油漆线申请物料、5油漆线空盘入库、6、一楼空托入库 + * point_code:必填; + * vehicle_num 载具数量 + * vehicle_type 载具类型 + * vehicle_code 载具号 + * qty 物料数量 */ - String applyTaskToWms(String device_code, String container_code, int height, int weight); + String applyTaskToWms(JSONObject jo); /** * 向WMS反馈任务状态 diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java index 4ffa2ec..eba120c 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java @@ -50,26 +50,13 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { public String token; @Override - public String applyTaskToWms(String device_code, String container_code, int height, int weight) { + public String applyTaskToWms(JSONObject jo) { String wmsurl = acsConfigService.findConfigFromCache().get(AcsConfig.WMSURL); AddressDto addressDto = addressService.findByCode("applyTaskToWms"); String url = wmsurl + addressDto.getMethods_url(); - JSONObject param = new JSONObject(); - param.put("height", height); - param.put("weight", weight); - String parent_device_code = ""; - JSONObject jo = new JSONObject(); - JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + device_code + "'").uniqueResult(0); - if (!device_json.isEmpty()) { - parent_device_code = (String) device_json.get("parent_storage_cell") == null ? device_code : (String) device_json.get("parent_storage_cell"); - } - jo.put("device_code", parent_device_code); - jo.put("container_code", container_code); - jo.put("param", param); log.info("applyTaskToWms-----请求参数{}", jo.toString()); HttpResponse result2 = null; try { - //{"status":400,"timestamp":"2021-10-22 16:32:22","message":"业务类型不正确!"} result2 = HttpRequest.post(url) .header("Authorization", token) .body(String.valueOf(jo)) @@ -86,7 +73,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } else { type = "error"; } - logServer.log("", "applyTaskToWms", type, jo.toString(), result2.body(), String.valueOf(result2.getStatus()), url, container_code); + logServer.log("", "applyTaskToWms", type, jo.toString(), result2.body(), String.valueOf(result2.getStatus()), url, ""); log.info("applyTaskToWms-----输出参数{}", result2.body()); return result2.body(); } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index f6b6d4a..360a213 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -10,6 +10,8 @@ import org.nl.acs.common.IDriverService; import org.nl.acs.config.AcsConfig; import org.nl.acs.config.server.AcsConfigService; import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.CargoLiftConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position.EmptyVehicleStackingPositionDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control.StandardCoveyorControlDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_plcscanner.StandardCoveyorControlWithPlcScannerDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; @@ -25,6 +27,7 @@ import org.nl.acs.opc.DeviceExtraManageDto; import org.nl.acs.route.service.RouteLineService; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; +import org.nl.exception.BadRequestException; import org.nl.exception.WDKException; import org.nl.utils.SpringContextHolder; import org.nl.wql.core.bean.WQLObject; @@ -57,7 +60,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { JSONArray errArr = new JSONArray(); for (int i = 0; i < tasks.size(); i++) { JSONObject task = tasks.getJSONObject(i); - String task_uuid = task.getString("task_uuid"); + String ext_task_id = task.getString("task_id"); String task_code = task.getString("task_code"); String start_point_code = task.getString("start_device_code"); String next_point_code = task.getString("next_device_code"); @@ -125,6 +128,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } JSONObject jo = new JSONObject(); jo.put("task_code", task_code); + jo.put("task_id", ext_task_id); jo.put("start_point_code", start_point_code); jo.put("next_point_code", next_point_code); jo.put("start_parent_code", start_point_code); @@ -140,8 +144,8 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { jo.put("params", params); jo.put("task_type", StrUtil.isEmpty(task_type) ? 1 : Integer.parseInt(task_type)); - if (!StrUtil.isEmpty(task_uuid)) { - jo.put("ext_task_id", task_uuid); + if (!StrUtil.isEmpty(ext_task_id)) { + jo.put("ext_task_id", ext_task_id); } TaskDto task_dto = jo.toJavaObject(TaskDto.class); @@ -151,18 +155,19 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { e.printStackTrace(); JSONObject json = new JSONObject(); json.put("task_code", task_code); - json.put("task_uuid", task_uuid); + json.put("ext_task_id", ext_task_id); json.put("message", e.getMessage()); errArr.add(json); } } if (ObjectUtil.isEmpty(errArr)) { resultJson.put("status", 200); + resultJson.put("message", "操作成功"); } else { resultJson.put("status", 400); + resultJson.put("message", "操作失败"); } resultJson.put("errArr", errArr); - resultJson.put("message", "操作成功"); resultJson.put("data", new JSONObject()); log.info("createFromWms--------------:输出参数:" + resultJson.toString()); @@ -286,256 +291,49 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { JSONArray backja = new JSONArray(); JSONArray datas = JSONArray.parseArray(jsonObject); - //无光电普通站点 - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - //检测站点 - StandardInspectSiteDeviceDriver standardInspectSiteDevicedriver; - //控制点 - StandardCoveyorControlDeviceDriver standardCoveyorControlDeviceDriver; - //控制点-带扫码 + //空托盘叠盘位 + EmptyVehicleStackingPositionDeviceDriver emptyVehicleStackingPositionDeviceDriver; + //货梯对接线 + CargoLiftConveyorDeviceDriver cargoLiftConveyorDeviceDriver; + //货梯对接线-带扫码器 StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - //控制点-PLC扫码 - StandardCoveyorControlWithPlcScannerDeviceDriver standardCoveyorControlWithPlcScannerDeviceDriver; - //扫码器 - StandardScannerDeviceDriver standardScannerDeviceDriver; if (datas.size() == 0) { - List list = deviceService.findCacheDevice(); - for (int i = 0, j = list.size(); i < j; i++) { - Device device = list.get(i); - JSONObject obj = new JSONObject(); - String device_code = device.getDevice_code(); - JSONObject jo = new JSONObject(); - if (ObjectUtil.isNull(device)) { - continue; - } - if (device.getDeviceDriver() instanceof StandardCoveyorControlDeviceDriver) { - standardCoveyorControlDeviceDriver = (StandardCoveyorControlDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("mode", standardCoveyorControlDeviceDriver.getMode()); - jo.put("move", standardCoveyorControlDeviceDriver.getMove()); - jo.put("hasGoods", standardCoveyorControlDeviceDriver.getHasGoods()); - jo.put("isOnline", standardCoveyorControlDeviceDriver.getIsonline()); - jo.put("error", standardCoveyorControlDeviceDriver.getError()); - jo.put("isError", standardCoveyorControlDeviceDriver.getIserror()); - jo.put("requestSucess", standardCoveyorControlDeviceDriver.getRequireSucess()); - jo.put("applySucess", standardCoveyorControlDeviceDriver.getApplySucess()); - jo.put("message", standardCoveyorControlDeviceDriver.getMessage()); - } else if (device.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver) { - standardCoveyorControlWithScannerDeviceDriver = (StandardCoveyorControlWithScannerDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("mode", standardCoveyorControlWithScannerDeviceDriver.getMode()); - jo.put("move", standardCoveyorControlWithScannerDeviceDriver.getMove()); - jo.put("hasGoods", standardCoveyorControlWithScannerDeviceDriver.getHasGoods()); - jo.put("isOnline", standardCoveyorControlWithScannerDeviceDriver.getIsonline()); - jo.put("error", standardCoveyorControlWithScannerDeviceDriver.getError()); - jo.put("isError", standardCoveyorControlWithScannerDeviceDriver.getIserror()); - jo.put("height", standardCoveyorControlWithScannerDeviceDriver.getHeight()); - jo.put("operation_type", standardCoveyorControlWithScannerDeviceDriver.getOperation_type()); - jo.put("direction", standardCoveyorControlWithScannerDeviceDriver.getDirection()); - jo.put("action", standardCoveyorControlWithScannerDeviceDriver.getAction()); - jo.put("ioaction", standardCoveyorControlWithScannerDeviceDriver.getIoaction()); - jo.put("container", StrUtil.isEmpty(standardCoveyorControlWithScannerDeviceDriver.barcode()) ? "" : standardCoveyorControlWithScannerDeviceDriver.barcode()); - jo.put("message", standardCoveyorControlWithScannerDeviceDriver.getMessage()); - jo.put("requestSucess", standardCoveyorControlWithScannerDeviceDriver.getRequireSucess().toString()); - jo.put("applySucess", standardCoveyorControlWithScannerDeviceDriver.getApplySucess().toString()); - jo.put("instruction_message", standardCoveyorControlWithScannerDeviceDriver.getInst_message()); - } else if (device.getDeviceDriver() instanceof StandardCoveyorControlWithPlcScannerDeviceDriver) { - standardCoveyorControlWithPlcScannerDeviceDriver = (StandardCoveyorControlWithPlcScannerDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("mode", standardCoveyorControlWithPlcScannerDeviceDriver.getMode()); - jo.put("move", standardCoveyorControlWithPlcScannerDeviceDriver.getMove()); - jo.put("hasGoods", standardCoveyorControlWithPlcScannerDeviceDriver.getHasGoods()); - jo.put("isOnline", standardCoveyorControlWithPlcScannerDeviceDriver.getIsonline()); - jo.put("error", standardCoveyorControlWithPlcScannerDeviceDriver.getError()); - jo.put("isError", standardCoveyorControlWithPlcScannerDeviceDriver.getIserror()); - jo.put("height", standardCoveyorControlWithPlcScannerDeviceDriver.getHeight()); - jo.put("operation_type", standardCoveyorControlWithPlcScannerDeviceDriver.getOperation_type()); - jo.put("direction", standardCoveyorControlWithPlcScannerDeviceDriver.getDirection()); - jo.put("action", standardCoveyorControlWithPlcScannerDeviceDriver.getAction()); - jo.put("ioaction", standardCoveyorControlWithPlcScannerDeviceDriver.getIoaction()); - jo.put("container", StrUtil.isEmpty(standardCoveyorControlWithPlcScannerDeviceDriver.getBarcode()) ? "" : standardCoveyorControlWithPlcScannerDeviceDriver.getBarcode()); - jo.put("message", standardCoveyorControlWithPlcScannerDeviceDriver.getMessage()); - jo.put("requestSucess", standardCoveyorControlWithPlcScannerDeviceDriver.getRequireSucess().toString()); - jo.put("applySucess", standardCoveyorControlWithPlcScannerDeviceDriver.getApplySucess().toString()); - jo.put("instruction_message", standardCoveyorControlWithPlcScannerDeviceDriver.getInst_message()); - } - //检测站点 - else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDevicedriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("mode", standardInspectSiteDevicedriver.getMode()); - jo.put("move", standardInspectSiteDevicedriver.getMove()); - jo.put("hasGoods", standardInspectSiteDevicedriver.getHasGoods()); - jo.put("isOnline", standardInspectSiteDevicedriver.getIsonline()); - jo.put("error", standardInspectSiteDevicedriver.getError()); - jo.put("isError", standardInspectSiteDevicedriver.getIserror()); - jo.put("container", standardInspectSiteDevicedriver.getContainer()); - jo.put("message", standardInspectSiteDevicedriver.getMessage()); - } - //普通站点 - else if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("move", standardOrdinarySiteDeviceDriver.getMove()); - jo.put("container", standardOrdinarySiteDeviceDriver.getContainer()); - jo.put("hasGoods", standardOrdinarySiteDeviceDriver.getHasGoods()); - jo.put("isOnline", true); - //点击弹出 - jo.put("is_click", true); - jo.put("device_type", device.getDevice_type()); - jo.put("error", standardOrdinarySiteDeviceDriver.getError()); - jo.put("isError", standardOrdinarySiteDeviceDriver.getIserror()); - jo.put("container", standardOrdinarySiteDeviceDriver.getContainer()); - jo.put("message", standardOrdinarySiteDeviceDriver.getMessage()); - jo.put("material", standardOrdinarySiteDeviceDriver.getMaterial()); - jo.put("batch", standardOrdinarySiteDeviceDriver.getBatch()); + throw new BadRequestException("缺少输入参数!"); + } - } else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDevicedriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("mode", standardInspectSiteDevicedriver.getMode()); - jo.put("move", standardInspectSiteDevicedriver.getMove()); - jo.put("hasGoods", standardInspectSiteDevicedriver.getHasGoods()); - jo.put("isOnline", standardInspectSiteDevicedriver.getIsonline()); - jo.put("error", standardInspectSiteDevicedriver.getError()); - jo.put("isError", standardInspectSiteDevicedriver.getIserror()); - jo.put("container", standardInspectSiteDevicedriver.getContainer()); - jo.put("message", standardInspectSiteDevicedriver.getMessage()); - } else if (device.getDeviceDriver() instanceof StandardScannerDeviceDriver) { - standardScannerDeviceDriver = (StandardScannerDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("isOnline", true); - jo.put("device_type", device.getDevice_type()); - //点击弹出 - jo.put("is_click", true); - jo.put("ip", standardScannerDeviceDriver.getIp()); - jo.put("container", StrUtil.isEmpty(standardScannerDeviceDriver.readBarcode()) ? "" : standardScannerDeviceDriver.readBarcode()); - } else { - jo.put("device_code", device.getDevice_code()); - } - backja.add(jo); + for (int i = 0; i < datas.size(); i++) { + JSONObject jo = new JSONObject(); + JSONObject data = datas.getJSONObject(i); + String device_code = data.getString("device_code"); + Device device = deviceAppService.findDeviceByCode(device_code); + if (ObjectUtil.isEmpty(device)) { + throw new Exception("未找到对应设备:" + device_code); } - } else { - for (int i = 0; i < datas.size(); i++) { - JSONObject jo = new JSONObject(); - JSONObject data = datas.getJSONObject(i); - String device_code = data.getString("device_code"); - Device device = deviceAppService.findDeviceByCode(device_code); - if (ObjectUtil.isEmpty(device)) { - throw new Exception("未找到对应设备:" + device_code); - } - if (device.getDeviceDriver() instanceof StandardCoveyorControlDeviceDriver) { - standardCoveyorControlDeviceDriver = (StandardCoveyorControlDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("mode", standardCoveyorControlDeviceDriver.getMode()); - jo.put("move", standardCoveyorControlDeviceDriver.getMove()); - jo.put("hasGoods", standardCoveyorControlDeviceDriver.getHasGoods()); - jo.put("isOnline", standardCoveyorControlDeviceDriver.getIsonline()); - jo.put("error", standardCoveyorControlDeviceDriver.getError()); - jo.put("isError", standardCoveyorControlDeviceDriver.getIserror()); - jo.put("requestSucess", standardCoveyorControlDeviceDriver.getRequireSucess()); - jo.put("applySucess", standardCoveyorControlDeviceDriver.getApplySucess()); - jo.put("message", standardCoveyorControlDeviceDriver.getMessage()); - } else if (device.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver) { - standardCoveyorControlWithScannerDeviceDriver = (StandardCoveyorControlWithScannerDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("mode", standardCoveyorControlWithScannerDeviceDriver.getMode()); - jo.put("move", standardCoveyorControlWithScannerDeviceDriver.getMove()); - jo.put("hasGoods", standardCoveyorControlWithScannerDeviceDriver.getHasGoods()); - jo.put("isOnline", standardCoveyorControlWithScannerDeviceDriver.getIsonline()); - jo.put("error", standardCoveyorControlWithScannerDeviceDriver.getError()); - jo.put("isError", standardCoveyorControlWithScannerDeviceDriver.getIserror()); - jo.put("height", standardCoveyorControlWithScannerDeviceDriver.getHeight()); - jo.put("operation_type", standardCoveyorControlWithScannerDeviceDriver.getOperation_type()); - jo.put("direction", standardCoveyorControlWithScannerDeviceDriver.getDirection()); - jo.put("action", standardCoveyorControlWithScannerDeviceDriver.getAction()); - jo.put("ioaction", standardCoveyorControlWithScannerDeviceDriver.getIoaction()); - jo.put("container", StrUtil.isEmpty(standardCoveyorControlWithScannerDeviceDriver.barcode()) ? "" : standardCoveyorControlWithScannerDeviceDriver.barcode()); - jo.put("message", standardCoveyorControlWithScannerDeviceDriver.getMessage()); - jo.put("requestSucess", standardCoveyorControlWithScannerDeviceDriver.getRequireSucess().toString()); - jo.put("applySucess", standardCoveyorControlWithScannerDeviceDriver.getApplySucess().toString()); - jo.put("instruction_message", standardCoveyorControlWithScannerDeviceDriver.getInst_message()); - } else if (device.getDeviceDriver() instanceof StandardCoveyorControlWithPlcScannerDeviceDriver) { - standardCoveyorControlWithPlcScannerDeviceDriver = (StandardCoveyorControlWithPlcScannerDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("mode", standardCoveyorControlWithPlcScannerDeviceDriver.getMode()); - jo.put("move", standardCoveyorControlWithPlcScannerDeviceDriver.getMove()); - jo.put("hasGoods", standardCoveyorControlWithPlcScannerDeviceDriver.getHasGoods()); - jo.put("isOnline", standardCoveyorControlWithPlcScannerDeviceDriver.getIsonline()); - jo.put("error", standardCoveyorControlWithPlcScannerDeviceDriver.getError()); - jo.put("isError", standardCoveyorControlWithPlcScannerDeviceDriver.getIserror()); - jo.put("height", standardCoveyorControlWithPlcScannerDeviceDriver.getHeight()); - jo.put("operation_type", standardCoveyorControlWithPlcScannerDeviceDriver.getOperation_type()); - jo.put("direction", standardCoveyorControlWithPlcScannerDeviceDriver.getDirection()); - jo.put("action", standardCoveyorControlWithPlcScannerDeviceDriver.getAction()); - jo.put("ioaction", standardCoveyorControlWithPlcScannerDeviceDriver.getIoaction()); - jo.put("container", StrUtil.isEmpty(standardCoveyorControlWithPlcScannerDeviceDriver.getBarcode()) ? "" : standardCoveyorControlWithPlcScannerDeviceDriver.getBarcode()); - jo.put("message", standardCoveyorControlWithPlcScannerDeviceDriver.getMessage()); - jo.put("requestSucess", standardCoveyorControlWithPlcScannerDeviceDriver.getRequireSucess().toString()); - jo.put("applySucess", standardCoveyorControlWithPlcScannerDeviceDriver.getApplySucess().toString()); - jo.put("instruction_message", standardCoveyorControlWithPlcScannerDeviceDriver.getInst_message()); - } - //检测站点 - else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDevicedriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("mode", standardInspectSiteDevicedriver.getMode()); - jo.put("move", standardInspectSiteDevicedriver.getMove()); - jo.put("hasGoods", standardInspectSiteDevicedriver.getHasGoods()); - jo.put("isOnline", standardInspectSiteDevicedriver.getIsonline()); - jo.put("error", standardInspectSiteDevicedriver.getError()); - jo.put("isError", standardInspectSiteDevicedriver.getIserror()); - jo.put("container", standardInspectSiteDevicedriver.getContainer()); - jo.put("message", standardInspectSiteDevicedriver.getMessage()); - } - //普通站点 - else if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("move", standardOrdinarySiteDeviceDriver.getMove()); - jo.put("container", standardOrdinarySiteDeviceDriver.getContainer()); - jo.put("hasGoods", standardOrdinarySiteDeviceDriver.getHasGoods()); - jo.put("isOnline", true); - //点击弹出 - jo.put("is_click", true); - jo.put("device_type", device.getDevice_type()); - jo.put("error", standardOrdinarySiteDeviceDriver.getError()); - jo.put("isError", standardOrdinarySiteDeviceDriver.getIserror()); - jo.put("container", standardOrdinarySiteDeviceDriver.getContainer()); - jo.put("message", standardOrdinarySiteDeviceDriver.getMessage()); - jo.put("material", standardOrdinarySiteDeviceDriver.getMaterial()); - jo.put("batch", standardOrdinarySiteDeviceDriver.getBatch()); - - } else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDevicedriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("mode", standardInspectSiteDevicedriver.getMode()); - jo.put("move", standardInspectSiteDevicedriver.getMove()); - jo.put("hasGoods", standardInspectSiteDevicedriver.getHasGoods()); - jo.put("isOnline", standardInspectSiteDevicedriver.getIsonline()); - jo.put("error", standardInspectSiteDevicedriver.getError()); - jo.put("isError", standardInspectSiteDevicedriver.getIserror()); - jo.put("container", standardInspectSiteDevicedriver.getContainer()); - jo.put("message", standardInspectSiteDevicedriver.getMessage()); - } else if (device.getDeviceDriver() instanceof StandardScannerDeviceDriver) { - standardScannerDeviceDriver = (StandardScannerDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", device.getDevice_code()); - jo.put("isOnline", true); - jo.put("device_type", device.getDevice_type()); - //点击弹出 - jo.put("is_click", true); - jo.put("ip", standardScannerDeviceDriver.getIp()); - jo.put("container", StrUtil.isEmpty(standardScannerDeviceDriver.readBarcode()) ? "" : standardScannerDeviceDriver.readBarcode()); - } else { - jo.put("device_code", device.getDevice_code()); - } - backja.add(jo); + if (device.getDeviceDriver() instanceof EmptyVehicleStackingPositionDeviceDriver) { + emptyVehicleStackingPositionDeviceDriver = (EmptyVehicleStackingPositionDeviceDriver) device.getDeviceDriver(); + jo.put("device_code", device.getDevice_code()); + jo.put("vehicle_num", emptyVehicleStackingPositionDeviceDriver.getNumber()); + } else if (device.getDeviceDriver() instanceof CargoLiftConveyorDeviceDriver) { + cargoLiftConveyorDeviceDriver = (CargoLiftConveyorDeviceDriver) device.getDeviceDriver(); + jo.put("device_code", device.getDevice_code()); + jo.put("move", cargoLiftConveyorDeviceDriver.getMove()); + jo.put("action", cargoLiftConveyorDeviceDriver.getAction()); + jo.put("error", cargoLiftConveyorDeviceDriver.getError()); + } else if (device.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver) { + standardCoveyorControlWithScannerDeviceDriver = (StandardCoveyorControlWithScannerDeviceDriver) device.getDeviceDriver(); + jo.put("device_code", device.getDevice_code()); + jo.put("move", standardCoveyorControlWithScannerDeviceDriver.getMove()); + jo.put("action", standardCoveyorControlWithScannerDeviceDriver.getAction()); + jo.put("error", standardCoveyorControlWithScannerDeviceDriver.getError()); + } else { + jo.put("device_code", device.getDevice_code()); } + backja.add(jo); } JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.OK); + resultJson.put("status", HttpStatus.OK.value()); resultJson.put("message", "操作成功"); resultJson.put("data", backja); log.info("queryDevice--------------:输出参数" + resultJson.toString()); diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java index 9f50b34..fc35393 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java @@ -46,7 +46,7 @@ public class InstructionDto implements Serializable { /** * 执行状态 */ - //暂定 0就绪 1请求取货 2取货完成离开 3请求倒料 4倒料完成离开 5请求放货 6放货完成离开 + //暂定 0就绪 1请求取货 2取货完成离开 3请求放货 4放货完成离开 private String execute_status; /** diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index 6caf817..18ae983 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -17,6 +17,8 @@ import org.nl.acs.config.AcsConfig; import org.nl.acs.config.server.AcsConfigService; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device.service.impl.DeviceServiceImpl; +import org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.CargoLiftConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.haokai_auto_conveyor.HaoKaiAutoConveyorDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control.StandardCoveyorControlDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_plcscanner.StandardCoveyorControlWithPlcScannerDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; @@ -81,6 +83,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu this.reload(); } + @Override public synchronized void reload() { this.instructions = this.queryAll("instruction_status <2 and is_delete =0"); } @@ -244,7 +247,6 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu dto = foramte(dto); String task_code = dto.getTask_code(); TaskDto task = taskService.findByCodeFromCache(task_code); - String excutetype = null; WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); String currentUsername = SecurityUtils.getCurrentUsername(); @@ -267,7 +269,14 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu if (StrUtil.isEmpty(dto.getLink_num())) { dto.setIs_send(task.getLink_num()); } - dto.setInstruction_type(task.getTask_type()); + if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { + dto.setInstruction_type(task.getTask_type()); + } else if (false) { + + } else { + dto.setInstruction_type("3"); + } + //起点设备与终点设备相同则为初始指令 if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { @@ -283,12 +292,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu dto.setCreate_time(now); dto.setStart_parent_code(task.getStart_parent_code()); dto.setNext_parent_code(task.getNext_parent_code()); - // 1 双工agv系统 2叉车agv系统 - if (StrUtil.equals(task.getAgv_system_type(), "1")) { - dto.setAgv_system_type("1"); - } else if (StrUtil.equals(task.getAgv_system_type(), "2")) { - dto.setAgv_system_type("2"); - } + if (StrUtil.equals(task.getTask_type(), "1")) { dto.setAgv_inst_type("1"); @@ -298,82 +302,35 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu dto.setAgv_inst_type("3"); } else if (StrUtil.equals(task.getTask_type(), "4")) { dto.setAgv_inst_type("4"); - } else if (StrUtil.equals(task.getTask_type(), "5")) { - dto.setAgv_inst_type("5"); - } else if (StrUtil.equals(task.getTask_type(), "6")) { - dto.setAgv_inst_type("1"); - } else if (StrUtil.equals(task.getTask_type(), "7")) { - dto.setAgv_inst_type("2"); - } else if (StrUtil.equals(task.getTask_type(), "8")) { - dto.setAgv_inst_type("3"); } DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + CargoLiftConveyorDeviceDriver cargoLiftConveyorDeviceDriver; + HaoKaiAutoConveyorDeviceDriver haoKaiAutoConveyorDeviceDriver; StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - StandardCoveyorControlWithPlcScannerDeviceDriver standardCoveyorControlWithPlcScannerDeviceDriver; - StandardCoveyorControlDeviceDriver standardCoveyorControlDeviceDriver; - StandardStorageDeviceDriver standardStorageDeviceDriver; - //将指令赋予对象 下发指令号给电气 - if (startdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) startdevice.getDeviceDriver(); - standardInspectSiteDeviceDriver.setBranchProtocol(2); - standardInspectSiteDeviceDriver.setInst(dto); - standardInspectSiteDeviceDriver.setMessage("下发指令:dto.getInstruction_code(),执行中"); - standardInspectSiteDeviceDriver.writing(3, 1); + //输送线相关需要给任务字段进行赋值,通过任务来判断输送线当前执行到哪一步 + if (startdevice.getDeviceDriver() instanceof CargoLiftConveyorDeviceDriver) { + cargoLiftConveyorDeviceDriver = (CargoLiftConveyorDeviceDriver) startdevice.getDeviceDriver(); + cargoLiftConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); + } + if (startdevice.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver) { + standardCoveyorControlWithScannerDeviceDriver = (StandardCoveyorControlWithScannerDeviceDriver) startdevice.getDeviceDriver(); + standardCoveyorControlWithScannerDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); + } + if (nextdevice.getDeviceDriver() instanceof HaoKaiAutoConveyorDeviceDriver) { + haoKaiAutoConveyorDeviceDriver = (HaoKaiAutoConveyorDeviceDriver) startdevice.getDeviceDriver(); + haoKaiAutoConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); } try { - // != 0 为agv任务 - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "1")) { - HttpResponse result = agvService.sendAgvInstToMagic(dto); - if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) { - dto.setSend_status("2"); - } else { - dto.setSend_status("1"); - } - } else if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "2")) { - //区分是否下发、下发任务类型、以及调度系统 - //dto.setInstruction_type("2"); - //任务、指令类型 - /** - * 1 双工agv双任务 - * 2 双工agv但认为 - * 3 单入-单任务 - * 4 双入-双任务 - * 5 点对点任务 - * 6 称重平台称重PS20 agvtype:1 - * 7 不去称重平台称重PS20 agvtype:2 - * 8 RT20 agvtype:3 - */ - if (StrUtil.equals("1", dto.getAgv_system_type())) { - agvService.sendAgvTwoInstToNDC(dto, null); - } else if (StrUtil.equals("2", dto.getAgv_system_type())) { - agvService.sendAgvOneInstToNDC(dto); - } + HttpResponse result = agvService.sendAgvInstToZDAgv(dto); + if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) { + dto.setSend_status("2"); + } else { dto.setSend_status("1"); - - } else if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3")) { - if (StrUtil.equals(task.getRequest_again_success(), "1")) { - //追加订单 - HttpResponse result = agvService.addOrderSequences(dto); - if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) { - dto.setSend_status("2"); - } else { - dto.setSend_status("1"); - } - } else { - //创建订单序列 - HttpResponse result = agvService.sendOrderSequencesToXZ(dto); - if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) { - dto.setSend_status("2"); - } else { - dto.setSend_status("1"); - } - } } } catch (Exception e) { dto.setSend_status("2"); @@ -593,19 +550,6 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - //将指令赋予对象 下发指令号给电气 - if (startdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) startdevice.getDeviceDriver(); - standardInspectSiteDeviceDriver.setBranchProtocol(2); - standardInspectSiteDeviceDriver.setInst(dto); - standardInspectSiteDeviceDriver.writing(3, 1); - } - if (startdevice.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver) { - standardCoveyorControlWithScannerDeviceDriver = (StandardCoveyorControlWithScannerDeviceDriver) startdevice.getDeviceDriver(); - standardCoveyorControlWithScannerDeviceDriver.setInst(dto); - standardCoveyorControlWithScannerDeviceDriver.writing(); - } - if (!ObjectUtils.isEmpty(nextdevice.getExtraValue().get("link_three_lamp"))) { String lamd_device = nextdevice.getExtraValue().get("link_three_lamp").toString(); Device lamddevice = appService.findDeviceByCode(lamd_device); diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/opc/Device.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/opc/Device.java index dd463dc..0230442 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/opc/Device.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/opc/Device.java @@ -13,6 +13,7 @@ public class Device extends DeviceManageDto { private DeviceDriver deviceDriver; private DeviceDriverDefination deviceDriverDefination; + @Override public String toString() { return ""; } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java index 7e9b0ca..b69a1c5 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java @@ -146,16 +146,4 @@ public class TaskController { return new ResponseEntity<>(HttpStatus.CREATED); } - @Log("设备申请任务") - @ApiOperation("设备申请任务") - @PostMapping("/deviceAskTask") - //@PreAuthorize("@el.check('task:add')") - public ResponseEntity deviceAskTask(@RequestBody Map json) { - String device_code = (String) json.get("device_code"); - String container_code = (String) json.get("carrierno"); - int height = Integer.parseInt((String) json.get("height")); - int weight = Integer.parseInt((String) json.get("weight")); - String s = acsToWmsService.applyTaskToWms(device_code, container_code, height, weight); - return new ResponseEntity<>(s, HttpStatus.CREATED); - } } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java index 695f614..0c206e9 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskFeedbackServiceImpl.java @@ -4,6 +4,7 @@ package org.nl.acs.task.service.impl; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -26,6 +27,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; +import javax.swing.*; import java.io.IOException; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -75,6 +77,9 @@ public class TaskFeedbackServiceImpl implements TaskFeedbackService { public TaskFeedbackDto findByCode(String code) { WQLObject wo = WQLObject.getWQLObject("acs_task_feedback"); JSONObject json = wo.query("task_code ='" + code + "' and is_finished='0' ").uniqueResult(0); + if (ObjectUtil.isEmpty(json)){ + return null; + } final TaskFeedbackDto obj = json.toJavaObject(TaskFeedbackDto.class); return obj; } @@ -162,11 +167,11 @@ public class TaskFeedbackServiceImpl implements TaskFeedbackService { TaskFeedbackDto dto = this.findById(id); TaskDto entity = taskService.findById(dto.getTask_id()); JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_uuid", entity.getTask_id()); + feed_jo.put("task_id", entity.getTask_id()); feed_jo.put("task_code", entity.getTask_code()); feed_jo.put("task_status", entity.getTask_status()); JSONArray ja = new JSONArray(); - + ja.add(feed_jo); HttpResponse body = null; String error_message = null; try { diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index 0c25fc5..538fe81 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -21,8 +21,6 @@ import org.nl.acs.device.service.DeviceService; import org.nl.acs.device.service.StorageCellService; import org.nl.acs.device.service.dto.DeviceAssignedDto; import org.nl.acs.device.service.impl.DeviceServiceImpl; -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.ext.wms.service.AcsToWmsService; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; @@ -111,6 +109,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public Map queryAll(Map whereJson, Pageable page) { + //WQLObject wo = WQLObject.getWQLObject("acs_task"); + //ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time desc"); HashMap map = new HashMap<>(); map.put("flag", "1"); String task_code = (String) whereJson.get("task_code"); @@ -254,15 +254,11 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } @Override - public TaskDto queryTaskByLinkNum(String link_num) { - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getLink_num().equals(link_num) && StrUtil.equals(task.getIs_send(), "0")) { - return task; - } - } - return null; + public TaskDto findByCode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); + final TaskDto obj = json.toJavaObject(TaskDto.class); + return obj; } @Override @@ -278,19 +274,15 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { return list; } - @Override - public TaskDto findByCode(String code) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); - final TaskDto obj = json.toJavaObject(TaskDto.class); - return obj; + public TaskDto queryTaskByLinkNum(String link_num) { + return null; } @Override public List queryByStauts(String status) { WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONArray arr = wo.query("task_status = '" + status + "'","create_time").getResultJSONArray(0); + JSONArray arr = wo.query("task_status = '" + status + "'").getResultJSONArray(0); List list = arr.toJavaList(TaskDto.class); return list; } @@ -328,32 +320,78 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { dto.setTask_code(task_code); dto.setRoute_plan_code(route_plan_code); dto.setTask_status("0"); + if (StrUtil.isEmpty(dto.getPriority())) { dto.setPriority("1"); } - String taskType = dto.getTask_type(); - if(StrUtil.equals(taskType,"1") || StrUtil.equals(taskType,"2") || StrUtil.equals(taskType,"3") || - StrUtil.equals(taskType,"4") || StrUtil.equals(taskType,"5") ){ - dto.setAgv_system_type("1"); - } else { - dto.setAgv_system_type("2"); - } String plan_code = dto.getRoute_plan_code(); //判断起点终点设备类型 String startDeviceType = deviceAppService.findDeviceTypeByCode(dto.getStart_device_code()); String nextDeviceType = deviceAppService.findDeviceTypeByCode(dto.getNext_device_code()); - - + if (routelineserver.getShortPathLines(dto.getStart_device_code(), dto.getNext_device_code(), plan_code).size() == 0) { + throw new Exception(dto.getStart_point_code() + "->" + dto.getNext_point_code() + "路由不通!"); + } String createTaskCheck = acsConfigService.findConfigFromCache().get(AcsConfig.CREATETASKCHECK); DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); Device nextdevice = appService.findDeviceByCode(next_device_code); Device startdevice = appService.findDeviceByCode(start_device_code); dto.setMaterial(startdevice.getMaterial_type()); - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + if (StrUtil.equals(createTaskCheck, "1")) { + //判断起点为输送设备 + if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) { + + } + if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) { + } + } else { + //判断起点为输送设备 + if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) { + + } + + if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) { +// if (nextdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { +// standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) nextdevice.getDeviceDriver(); +// if (nextdevice.getHas_goods() != 0) { +// throw new Exception("任务终点需满足无货!"); +// } +// } + + JSONObject jo = new JSONObject(); + JSONObject jo2 = new JSONObject(); + if (!StrUtil.isEmpty(dto.getMaterial())) { + if (!StrUtil.equals(dto.getMaterial(), "1")) { + jo.put("hasGoodStatus", "2"); + jo.put("material_type", dto.getMaterial()); + } else { + jo.put("hasGoodStatus", "1"); + jo.put("material_type", "1"); + } + + } else { + jo.put("hasGoodStatus", "1"); + jo.put("material_type", "1"); + } + jo.put("device_code", dto.getStart_device_code()); + jo.put("quantity", dto.getQuantity()); + jo.put("remark", dto.getRemark()); + jo.put("batch", startdevice.getBatch()); + jo.put("islock", "true"); + deviceService.changeDeviceStatus(jo); + Device deviceByCode = deviceAppService.findDeviceByCode(dto.getNext_device_code()); + jo2.put("device_code", dto.getNext_device_code()); + jo2.put("hasGoodStatus", deviceByCode.getHas_goods()); + jo2.put("quantity", deviceByCode.getQuantity()); + jo2.put("remark", deviceByCode.getRemark()); + jo2.put("material_type", deviceByCode.getMaterial_type()); + jo2.put("batch", deviceByCode.getBatch()); + jo2.put("islock", "true"); + deviceService.changeDeviceStatus(jo2); + } + } WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); wo.insert(json); tasks.add(dto); @@ -400,7 +438,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { dto.setStart_point_code(device_code); dto.setNext_device_code(next_device_code); dto.setNext_point_code(next_device_code); - dto.setQuantity(quantity); dto.setRemark(remark); dto.setMaterial(material_type); create(dto); @@ -467,7 +504,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { dto.setStart_point_code(start_device_code); dto.setNext_device_code(next_device_code); dto.setNext_point_code(next_device_code); - dto.setQuantity(quantity); dto.setRemark(remark); dto.setMaterial(material_type); create(dto); @@ -478,7 +514,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Transactional(rollbackFor = Exception.class) public void update(TaskDto dto) { TaskDto entity = this.findById(dto.getTask_id()); - if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } String currentUsername = SecurityUtils.getCurrentUsername(); String now = DateUtil.now(); @@ -505,7 +543,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { if (!StrUtil.startWith(dto.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_uuid", dto.getTask_id()); + feed_jo.put("task_id", entity.getTask_id()); feed_jo.put("task_code", dto.getTask_code()); feed_jo.put("task_status", dto.getTask_status()); JSONArray ja = new JSONArray(); @@ -535,7 +573,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { feefbackdto.setNext_device_code(entity.getNext_device_code()); feefbackdto.setNext_point_code(entity.getNext_point_code()); feefbackdto.setError_code("400"); - feefbackdto.setAgv_system_type(entity.getAgv_system_type()); feefbackdto.setIs_finished("0"); feefbackdto.setRemark(message); taskFeedbackService.create(feefbackdto); @@ -622,7 +659,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_uuid", entity.getTask_id()); + feed_jo.put("task_id", entity.getTask_id()); feed_jo.put("task_code", entity.getTask_code()); feed_jo.put("task_status", entity.getTask_status()); JSONArray ja = new JSONArray(); @@ -667,7 +704,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } else { int status = body.getStatus(); - JSONObject jo = (JSONObject) JSONObject.toJSON(body.body()); + JSONObject jo = JSONObject.parseObject(body.body()); if (ObjectUtil.isEmpty(feefbackdto)) { feefbackdto = new TaskFeedbackDto(); feefbackdto.setTask_id(entity.getTask_id()); @@ -722,10 +759,14 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Transactional(rollbackFor = Exception.class) public void cancel(String id) throws Exception { TaskDto entity = this.findById(id); - if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); InstructionDto instdto = instructionservice.findByTaskid(id, "instruction_status <2 "); - if (instdto != null) throw new BadRequestException("有指令未完成!"); + if (instdto != null) { + throw new BadRequestException("有指令未完成!"); + } String currentUsername = SecurityUtils.getCurrentUsername(); String now = DateUtil.now(); entity.setUpdate_time(now); @@ -745,36 +786,42 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { String hasWms = acsConfigService.findConfigFromCache().get(AcsConfig.HASWMS); if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_uuid", entity.getTask_id()); + feed_jo.put("task_id", entity.getTask_id()); feed_jo.put("task_code", entity.getTask_code()); feed_jo.put("task_status", entity.getTask_status()); JSONArray ja = new JSONArray(); ja.add(feed_jo); acstowmsService.feedbackTaskStatusToWms(ja); } - + List shortPathsList = routeLineService.getShortPathLines(entity.getStart_device_code(), entity.getNext_device_code(), entity.getRoute_plan_code()); + String type = shortPathsList.get(0).getType(); // != 0 为agv任务 - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3")) { - agvService.markComplete(entity.getTask_code()); + if (!StrUtil.equals(type, "0")) { + if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3")) { + agvService.markComplete(entity.getTask_code()); + } } } @Override @Transactional(rollbackFor = Exception.class) public void createInst(String ids) throws Exception { - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); TaskDto acsTask = this.findById(ids); - if (acsTask == null) throw new BadRequestException("被删除或无权限,操作失败!"); + if (acsTask == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); InstructionDto inst = instructionservice.findByTaskid(ids, "instruction_status < 2 "); - if (inst != null) throw new BadRequestException("有指令未完成!"); - String link_no = CodeUtil.getNewCode("LINK_NO"); + if (inst != null) { + throw new BadRequestException("有指令未完成!"); + } + String taskid = acsTask.getTask_id(); String taskcode = acsTask.getTask_code(); String vehiclecode = acsTask.getVehicle_code(); String priority = acsTask.getPriority(); - String material = acsTask.getMaterial(); String start_point_code = acsTask.getStart_point_code(); String start_device_code = acsTask.getStart_device_code(); String route_plan_code = acsTask.getRoute_plan_code(); @@ -783,34 +830,50 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { String compound_task = acsTask.getCompound_task(); String next_point_code = acsTask.getNext_point_code(); String next_device_code = acsTask.getNext_device_code(); - String agv_system_type = acsTask.getAgv_system_type(); - String put_device_code = acsTask.getPut_device_code(); - String put_point_code = acsTask.getPut_point_code(); - String remark = acsTask.getRemark(); - String task_type = acsTask.getTask_type(); - String quantity = acsTask.getQuantity(); - String is_send = acsTask.getIs_send(); - if(StrUtil.equals(is_send,"0")){ - return; + String maxInstnumber = acsConfigService.findConfigFromCache().get(AcsConfig.MAXINSTNUMBER); + + /** + * 开始平均分解校验 + */ + String this_device_code = this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); + if (StrUtil.isEmpty(this_device_code)) { + List shortPathsList = routeLineService.getShortPathLines(start_device_code, acsTask.getNext_device_code(), route_plan_code); + RouteLineDto routeLineDto = shortPathsList.get(0); + String path = routeLineDto.getPath(); + String type = routeLineDto.getType(); + String[] str = path.split("->"); + List pathlist = Arrays.asList(str); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(start_device_code)) { + index = m + 1; + break; + } + } + next_device_code = pathlist.get(index); + } else { + next_device_code = this_device_code; } + + if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); + } else { + next_point_code = next_device_code; + } + Instruction instdto = new Instruction(); - instdto.setInstruction_type(task_type); + instdto.setInstruction_type(acsTask.getTask_type()); instdto.setInstruction_id(IdUtil.simpleUUID()); instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(remark); - instdto.setLink_num(link_no); - instdto.setMaterial(material); - instdto.setQuantity(quantity); - instdto.setPut_device_code(put_device_code); - instdto.setPut_point_code(put_point_code); - instdto.setAgv_system_type(agv_system_type); + instdto.setRemark(acsTask.getRemark()); + instdto.setMaterial(acsTask.getMaterial()); + instdto.setQuantity(acsTask.getQuantity()); instdto.setTask_id(taskid); instdto.setTask_code(taskcode); instdto.setVehicle_code(vehiclecode); String now = DateUtil.now(); - String currentUsername = SecurityUtils.getCurrentUsername(); instdto.setCreate_time(now); - instdto.setCreate_by(currentUsername); + 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); @@ -819,12 +882,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { instdto.setInstruction_status("0"); instdto.setExecute_device_code(start_point_code); instdto.setVehicle_type(vehicleType); + instructionservice.create(instdto); - //创建指令后修改任务状态 - acsTask.setTask_status("1"); - acsTask.setTask_type("2"); - acsTask.setLink_num(link_no); - taskserver.update(acsTask); } @Override @@ -869,30 +928,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public void createTaskByClick(JSONObject json) { - String device_code = json.getString("device_code"); - String type = json.getString("type"); - Device device = deviceAppService.findDeviceByCode(device_code); - if (ObjectUtil.isNull(device)) { - return; - } - StandardInspectSiteDeviceDriver deviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - if (ObjectUtil.isNull(deviceDriver)) { - return; - } - //type=1 叫料 2 搬运任务 - if (StrUtil.equals(type, "1")) { - Boolean is_applyMaterial = deviceDriver.getApply_material(); - //未生成任务 - if (!is_applyMaterial) { - deviceDriver.setApply_material(true); - } - } else { - Boolean is_applyHandling = deviceDriver.getApply_handling(); - //未生成任务 - if (!is_applyHandling) { - deviceDriver.setApply_handling(true); - } - } + } @Override @@ -967,33 +1003,14 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { return null; } - @Override public List findAllByNextCode(String device_code) { - List list = new ArrayList<>(); - Iterator var3 = tasks.iterator(); - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getNext_device_code(), device_code)) { - list.add(task); - } - } - return list; + return null; } - @Override public Integer queryAllTaskMaterialQty(String device_code) { - int qty = 0; - Iterator var3 = tasks.iterator(); - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getNext_device_code(), device_code)) { - if(StrUtil.isNotEmpty(task.getQuantity())) - qty = qty + Integer.parseInt(task.getQuantity()); - } - } - return qty; + return null; } @Override @@ -1191,37 +1208,13 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } @Override - public Integer querySameDestinationTask(String devicecode) { - int num = 0; - for (int i = 0; i < this.tasks.size(); i++) { - TaskDto task = tasks.get(i); - //处理空盘位站点 - String start_code = task.getNext_device_code(); - if (start_code.indexOf(".") != -1) { - start_code = start_code.substring(0, start_code.indexOf(".")); - } - if (StrUtil.equals(devicecode, start_code)) { - num = num + 1; - } - } - return num; + public Integer querySameOriginTask(String code) { + return null; } @Override - public Integer querySameOriginTask(String devicecode) { - int num = 0; - for (int i = 0; i < this.tasks.size(); i++) { - TaskDto task = tasks.get(i); - //处理空盘位站点 - String next_code = task.getStart_device_code(); - if (next_code.indexOf(".") != -1) { - next_code = next_code.substring(0, next_code.indexOf(".")); - } - if (StrUtil.equals(devicecode, next_code)) { - num = num + 1; - } - } - return num; + public Integer querySameDestinationTask(String code) { + return null; } } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVTwoInst.java b/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVTwoInst.java deleted file mode 100644 index 2c06743..0000000 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVTwoInst.java +++ /dev/null @@ -1,329 +0,0 @@ -package org.nl.modules.quartz.task; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.StrUtil; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; -import org.nl.acs.config.AcsConfig; -import org.nl.acs.config.server.AcsConfigService; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.instruction.service.dto.Instruction; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.opc.DeviceAppServiceImpl; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.modules.system.util.CodeUtil; -import org.nl.utils.SpringContextHolder; -import org.springframework.stereotype.Component; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; - -/** - * 自动创建指令 - */ -@Slf4j -@Component -public class AutoCreateAGVTwoInst { - - /** - * 根据任务状态创建指令、生成下一条指令 - * 创建指令前需要判断是否条件具备:起始位置是否有货、目标位置是否有货 - */ - public void run() throws Exception { - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); - List list = taskserver.queryAll("task_status = '0' and agv_system_type = '1' "); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - int maxSendTaskTime = Integer.valueOf(String.valueOf(acsConfigService.findByCode(AcsConfig.MAXSENDTASKTIME).getValue())); - for (int i = 0; i < list.size(); i++) { - TaskDto acsTask = list.get(i); - String taskid = acsTask.getTask_id(); - String taskcode = acsTask.getTask_code(); - String vehiclecode = acsTask.getVehicle_code(); - String priority = acsTask.getPriority(); - String is_send = acsTask.getIs_send(); - String create_time = acsTask.getCreate_time(); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date date = new Date(); - String start_device_code = acsTask.getStart_device_code(); - String next_device_code = acsTask.getNext_device_code(); - - String start_point_code = acsTask.getStart_point_code(); - String put_point_code = acsTask.getPut_point_code(); - String put_device_code = acsTask.getPut_device_code(); - String route_plan_code = acsTask.getRoute_plan_code(); - String vehicleType = acsTask.getVehicle_type(); - - //是否复合任务 =0非复合任务 - String compound_task = acsTask.getCompound_task(); - String next_point_code = acsTask.getNext_point_code(); - - if(StrUtil.equals(is_send,"0")){ - continue; - } - - //判断当前任务创建时间是否超过最大等待时间 - if(date.getTime() - simpleDateFormat.parse(create_time).getTime() > (long) maxSendTaskTime*1000){ - //判断是否能进行合并 - //不能合并则立刻下发AGV - Device start_device = appService.findDeviceByCode(start_device_code); - String start_region = start_device.getRegion(); - Device next_device = appService.findDeviceByCode(next_device_code); - String next_region = next_device.getRegion(); - boolean flag = false; - if(list.size()>1){ - for(int j=0;j1) { - for (int j = 0; j < list.size(); j++) { - TaskDto taskDto = list.get(j); - if (!StrUtil.equals(taskDto.getTask_code(), taskcode)) { - String one_start_region = appService.findDeviceByCode(taskDto.getStart_device_code()).getRegion(); - String one_next_region = appService.findDeviceByCode(taskDto.getNext_device_code()).getRegion(); - if (StrUtil.equals(start_region, one_start_region) && StrUtil.equals(next_region, one_next_region)) { - //成功找到匹配的任务 - //生成指令 - String link_no = CodeUtil.getNewCode("LINK_NO"); - Instruction instdto = new Instruction(); - instdto.setInstruction_type(acsTask.getTask_type()); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(acsTask.getRemark()); - instdto.setMaterial(acsTask.getMaterial()); - instdto.setQuantity(acsTask.getQuantity()); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - instdto.setVehicle_code(vehiclecode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setPut_device_code(put_device_code); - instdto.setPut_point_code(put_point_code); - instdto.setNext_device_code(next_device_code); - instdto.setNext_point_code(next_point_code); - instdto.setPriority(priority); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(start_point_code); - instdto.setVehicle_type(vehicleType); - instdto.setLink_num(link_no); - - Instruction instdto2 = new Instruction(); - String start_point_code2 = taskDto.getStart_point_code(); - String start_device_code2 = taskDto.getStart_device_code(); - String put_point_code2 = taskDto.getPut_point_code(); - String put_device_code2 = taskDto.getPut_device_code(); - String route_plan_code2 = taskDto.getRoute_plan_code(); - String vehicleType2 = taskDto.getVehicle_type(); - String priority2 = taskDto.getPriority(); - String compound_task2 = taskDto.getCompound_task(); - String next_point_code2 = taskDto.getNext_point_code(); - String next_device_code2 = taskDto.getNext_device_code(); - instdto2.setInstruction_type(taskDto.getTask_type()); - instdto2.setInstruction_id(IdUtil.simpleUUID()); - instdto2.setRoute_plan_code(route_plan_code2); - instdto2.setRemark(taskDto.getRemark()); - instdto2.setMaterial(taskDto.getMaterial()); - instdto2.setQuantity(taskDto.getQuantity()); - instdto2.setTask_id(taskDto.getTask_id()); - instdto2.setTask_code(taskDto.getTask_code()); - instdto2.setVehicle_code(taskDto.getVehicle_code()); - instdto2.setCreate_time(now); - instdto2.setCreate_by("auto"); - instdto2.setStart_device_code(start_device_code2); - instdto2.setStart_point_code(start_point_code2); - instdto2.setPut_device_code(put_device_code2); - instdto2.setPut_point_code(put_point_code2); - instdto2.setNext_device_code(next_device_code2); - instdto2.setNext_point_code(next_point_code2); - instdto2.setPriority(priority2); - instdto2.setInstruction_status("0"); - instdto2.setExecute_device_code(start_point_code2); - instdto2.setVehicle_type(vehicleType2); - instdto2.setLink_num(link_no); - - try { - instructionService.createTwoInst(instdto, instdto2); - list.remove(i); - list.remove(j); - flag = true; - } catch (Exception e) { - acsTask.setRemark(e.getMessage()); - taskserver.updateByCodeFromCache(acsTask); - taskDto.setRemark(e.getMessage()); - taskserver.updateByCodeFromCache(taskDto); - continue; - } - //创建指令后修改任务状态 - acsTask.setTask_status("1"); - acsTask.setLink_num(link_no); - taskserver.update(acsTask); - - taskDto.setTask_status("1"); - taskDto.setLink_num(link_no); - taskserver.update(taskDto); - break; - } else { - continue; - } - } - } - } - } - } - } -} diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVOneInst.java b/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java similarity index 72% rename from wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVOneInst.java rename to wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java index dc23473..04c60dd 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVOneInst.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; import org.nl.acs.config.AcsConfig; import org.nl.acs.config.server.AcsConfigService; import org.nl.acs.instruction.service.InstructionService; @@ -11,12 +12,14 @@ import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.opc.DeviceAppService; import org.nl.acs.opc.DeviceAppServiceImpl; import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; import org.nl.modules.system.util.CodeUtil; import org.nl.utils.SpringContextHolder; import org.springframework.stereotype.Component; +import java.util.Arrays; import java.util.List; /** @@ -24,7 +27,7 @@ import java.util.List; */ @Slf4j @Component -public class AutoCreateAGVOneInst { +public class AutoCreateInst { /** * 根据任务状态创建指令、生成下一条指令 @@ -34,10 +37,9 @@ public class AutoCreateAGVOneInst { TaskService taskserver = SpringContextHolder.getBean(TaskService.class); InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); - List list = taskserver.queryAll("task_status = '0' and agv_system_type = '2' "); DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - int maxSendTaskTime = Integer.valueOf(String.valueOf(acsConfigService.findByCode(AcsConfig.MAXSENDTASKTIME).getValue())); + + List list = taskserver.queryAll("task_status = '0'"); for (int i = 0; i < list.size(); i++) { TaskDto acsTask = list.get(i); String taskid = acsTask.getTask_id(); @@ -45,7 +47,6 @@ public class AutoCreateAGVOneInst { String vehiclecode = acsTask.getVehicle_code(); String priority = acsTask.getPriority(); String is_send = acsTask.getIs_send(); - String create_time = acsTask.getCreate_time(); String start_device_code = acsTask.getStart_device_code(); String next_device_code = acsTask.getNext_device_code(); @@ -55,15 +56,44 @@ public class AutoCreateAGVOneInst { String route_plan_code = acsTask.getRoute_plan_code(); String vehicleType = acsTask.getVehicle_type(); - //是否复合任务 =0非复合任务 - String compound_task = acsTask.getCompound_task(); String next_point_code = acsTask.getNext_point_code(); if(StrUtil.equals(is_send,"0")){ continue; } - String link_no = CodeUtil.getNewCode("LINK_NO"); + //校验路由关系 + List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + if (ObjectUtils.isEmpty(shortPathsList)) { + acsTask.setRemark("路由不通无法生成指令"); + taskserver.updateByCodeFromCache(acsTask); + continue; + } + + if (!StrUtil.equals(shortPathsList.get(0).getType(), "1")) { + continue; + } + + RouteLineDto routeLineDto = shortPathsList.get(0); + String path = routeLineDto.getPath(); + String type = routeLineDto.getType(); + String[] str = path.split("->"); + List pathlist = Arrays.asList(str); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(start_device_code)) { + index = m + 1; + break; + } + } + next_device_code = pathlist.get(index); + + if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); + } else { + next_point_code = next_device_code; + } + Instruction instdto = new Instruction(); instdto.setInstruction_type(acsTask.getTask_type()); instdto.setInstruction_id(IdUtil.simpleUUID()); @@ -87,7 +117,6 @@ public class AutoCreateAGVOneInst { instdto.setInstruction_status("0"); instdto.setExecute_device_code(start_point_code); instdto.setVehicle_type(vehicleType); - instdto.setLink_num(link_no); try { instructionService.create(instdto); } catch (Exception e) { @@ -97,7 +126,6 @@ public class AutoCreateAGVOneInst { } //创建指令后修改任务状态 acsTask.setTask_status("1"); - acsTask.setLink_num(link_no); taskserver.update(acsTask); } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/NdcAutoReconnection.java b/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/NdcAutoReconnection.java deleted file mode 100644 index f138f8f..0000000 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/NdcAutoReconnection.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.nl.modules.quartz.task; - -import cn.hutool.core.util.StrUtil; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.config.AcsConfig; -import org.nl.acs.config.server.AcsConfigService; -import org.nl.start.auto.run.AutoRunService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * 自动清理日志 - */ -@Slf4j -@Component -public class NdcAutoReconnection { - - @Autowired - AcsConfigService acsConfigService; - - @Autowired - AutoRunService autoRunService; - - public void run(String threadCode) throws Exception { - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.NDC_RECONNECTION).toString(), "1")) { - - if (!autoRunService.getThreadByCode(threadCode).isAlive()) { - autoRunService.startThread(threadCode); - } - - } - } -} diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/NdxyDeviceStatus.java b/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/NdxyDeviceStatus.java deleted file mode 100644 index b33a14b..0000000 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/NdxyDeviceStatus.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.nl.modules.quartz.task; - - -import cn.hutool.core.map.MapUtil; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.modules.mnt.websocket.MsgType; -import org.nl.modules.mnt.websocket.SocketMsg; -import org.nl.modules.mnt.websocket.WebSocketServer; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.Map; - -/** - * 纽迪希亚设备状态 - */ - -@Slf4j -@Component -public class NdxyDeviceStatus { - @Autowired - DeviceService deviceService; - - @Autowired - DeviceAppService deviceAppService; - - public void run() throws Exception { - - try { - log.info("run 执行成功"); - JSONObject json = new JSONObject(); - JSONArray device = new JSONArray(); - JSONArray device2 = new JSONArray(); - JSONArray device3 = new JSONArray(); - JSONObject jo = new JSONObject(); - Map whereJson1; - Map whereJson2; - Map whereJson3; - JSONArray array1 = deviceService.selectDeviceListOne(); - JSONArray array2 = deviceService.selectDeviceListTwo(); - JSONArray array3 = deviceService.selectDeviceListThree(); - for (int i = 0; i < array1.size(); i++) { - whereJson1 = (Map) array1.get(i); - String device_code = MapUtil.getStr(whereJson1, "device_code"); - Device deviceApp = deviceAppService.findDeviceByCode(device_code); - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - if (deviceApp.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) deviceApp.getDeviceDriver(); - jo.put("device_code", device_code); - jo.put("quantity", standardOrdinarySiteDeviceDriver.getQty()); - jo.put("material_type", standardOrdinarySiteDeviceDriver.getMaterial()); - jo.put("hasGood", standardOrdinarySiteDeviceDriver.getHasGoods()); - jo.put("remark", standardOrdinarySiteDeviceDriver.getRemark()); - } - device.add(jo); - } - for (int i = 0; i < array2.size(); i++) { - whereJson2 = (Map) array2.get(i); - String device_code = MapUtil.getStr(whereJson2, "device_code"); - Device deviceApp = deviceAppService.findDeviceByCode(device_code); - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - if (deviceApp.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) deviceApp.getDeviceDriver(); - jo.put("device_code", device_code); - jo.put("quantity", standardOrdinarySiteDeviceDriver.getQty()); - jo.put("material_type", standardOrdinarySiteDeviceDriver.getMaterial()); - jo.put("hasGood", standardOrdinarySiteDeviceDriver.getHasGoods()); - jo.put("remark", standardOrdinarySiteDeviceDriver.getRemark()); - } - device2.add(jo); - } - for (int i = 0; i < array3.size(); i++) { - whereJson3 = (Map) array3.get(i); - String device_code = MapUtil.getStr(whereJson3, "device_code"); - Device deviceApp = deviceAppService.findDeviceByCode(device_code); - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - if (deviceApp.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) deviceApp.getDeviceDriver(); - jo.put("device_code", device_code); - jo.put("quantity", standardOrdinarySiteDeviceDriver.getQty()); - jo.put("material_type", standardOrdinarySiteDeviceDriver.getMaterial()); - jo.put("hasGood", standardOrdinarySiteDeviceDriver.getHasGoods()); - jo.put("remark", standardOrdinarySiteDeviceDriver.getRemark()); - } - device3.add(jo); - } - json.put("device", device); - json.put("device2", device2); - json.put("device3", device3); - SocketMsg deviceInfo = new SocketMsg(json, MsgType.INFO); - WebSocketServer.sendInfo(deviceInfo, "ndxy_data"); - - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryMagicAgvTaskStatus.java b/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryMagicAgvTaskStatus.java deleted file mode 100644 index f6bf1ab..0000000 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryMagicAgvTaskStatus.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.nl.modules.quartz.task; - -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpResponse; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.agv.server.AgvService; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.instruction.service.dto.Instruction; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * 查询AGV任务状态 - */ -@Slf4j -@Component -public class QueryMagicAgvTaskStatus { - - @Autowired - InstructionService instructionService; - - @Autowired - AgvService agvService; - - - public void run() throws Exception { - List instList = instructionService.findAllInstFromCache(); - log.info("instList:{}", instList.size()); - if (instList.size() > 0) { - for (int i = 0; i < instList.size(); i++) { - Instruction inst = instList.get(i); - String instcode = inst.getInstruction_code(); - HttpResponse response = agvService.queryAgvInstStatus(instcode); - JSONObject jo = JSONObject.parseObject(response.body()); - if (MapUtil.isEmpty(jo)) continue; - //反馈结果状态 - log.info("instcode:" + instcode + "," + jo.toString()); - //指令执行状态 - String state = jo.getString("state"); - String processingVehicle = ""; - //正在执行指令agv车号 - if (!StrUtil.isEmpty(jo.getString("processingVehicle"))) { - processingVehicle = jo.getString("processingVehicle"); - inst.setCarno(processingVehicle); - } -// RAW:初始状态 -// ACTIVE:业务订单已激活 -// DISPATCHABLE:业务订单已通过系统验证,等待被调度执行 -// BEING_PROCESSED:业务订单正在被执行 -// WITHDRAWN:业务订单已被撤销 -// FINISHED:业务订单已完成 -// FAILED:业务订单已失败 -// UNROUTABLE:无法规划该业务订单的执行路线 - - //执行中 - if ("BEING_PROCESSED".equals(state)) { - if (inst != null) { - inst.setInstruction_status("1"); - instructionService.update(inst); - } - } else if ("FINISHED".equals(state)) { - if (inst != null) { - inst.setInstruction_status("2"); - instructionService.finish(inst); - } - } else if ("WITHDRAWN".equals(state) || "FAILED".equals(state)) { - if (inst != null) { - inst.setInstruction_status("3"); - instructionService.update(inst); - instructionService.removeByCodeFromCache(instcode); - } - } else { - - } - JSONArray ja = jo.getJSONArray("properties"); - for (int j = 0; j < ja.size(); j++) { - JSONObject item = ja.getJSONObject(j); - if ("True".equals(item.get("value"))) { - String param = item.get("key").toString(); - String[] strs = param.split("-"); - //onEntry请求进入 onStation请求离开 - //onStation-库位名-动作名" - String type = null; - String device = null; - String action = null; - // =5表示为货位 - if (strs.length == 5) { - type = strs[0]; - device = strs[1] + "-" + strs[2] + "-" + strs[3]; - action = strs[4]; - } else { - type = strs[0]; - device = strs[1]; - action = strs[2]; - } - - String mes = ""; - - agvService.process(instcode, type, device, action, processingVehicle); - } - - } - } - } - } - - public static void main(String[] args) { - String str = "onEntry-0101-07-03-Unload"; - String[] strs = str.split("-"); - System.out.println(strs.length); - - } -} diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java b/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java deleted file mode 100644 index 0452d66..0000000 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.nl.modules.quartz.task; - -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpResponse; -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.agv.server.AgvService; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.instruction.service.dto.Instruction; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * 查询AGV任务状态 - */ -@Slf4j -@Component -public class QueryXZAgvTaskStatus { - - @Autowired - InstructionService instructionService; - - @Autowired - AgvService agvService; - - - public void run() throws Exception { - List instList = instructionService.findAllInstFromCache(); - if (instList.size() > 0) { - for (int i = 0; i < instList.size(); i++) { - Instruction inst = instList.get(i); - if (!StrUtil.equals(inst.getSend_status(), "1")) continue; - String instcode = inst.getInstruction_code(); - HttpResponse response = agvService.queryXZAgvInstStatus(instcode); - JSONObject jo = JSONObject.parseObject(response.body()); - if (MapUtil.isEmpty(jo)) continue; - //反馈结果状态 - log.info("instcode:" + instcode + "," + jo.toString()); - //指令执行状态 - String state = jo.getString("state"); - String processingVehicle = ""; - //正在执行指令agv车号 - if (!StrUtil.isEmpty(jo.getString("processingVehicle"))) { - processingVehicle = jo.getString("processingVehicle"); - inst.setCarno(processingVehicle); - } - -// RAW:初始状态 -// ACTIVE:业务订单已激活 -// DISPATCHABLE:业务订单已通过系统验证,等待被调度执行 -// BEING_PROCESSED:业务订单正在被执行 -// WITHDRAWN:业务订单已被撤销 -// FINISHED:业务订单已完成 -// FAILED:业务订单已失败 -// UNROUTABLE:无法规划该业务订单的执行路线 - - //执行中 - if ("BEING_PROCESSED".equals(state)) { - if (inst != null) { - inst.setInstruction_status("1"); - instructionService.update(inst); - } - } else if ("FINISHED".equals(state)) { - if (inst != null) { - inst.setInstruction_status("2"); - instructionService.finish(inst); - } - } else if ("WITHDRAWN".equals(state) || "FAILED".equals(state)) { - if (inst != null) { - inst.setInstruction_status("4"); - instructionService.update(inst); - //instructionService.removeByCodeFromCache(instcode); - } - } else { - - } - - } - } - } -} diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryZDAgvTaskStatus.java b/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryZDAgvTaskStatus.java new file mode 100644 index 0000000..f86f3c5 --- /dev/null +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryZDAgvTaskStatus.java @@ -0,0 +1,163 @@ +package org.nl.modules.quartz.task; + +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 查询AGV任务状态 + */ +@Slf4j +@Component +public class QueryZDAgvTaskStatus { + + @Autowired + InstructionService instructionService; + + @Autowired + AgvService agvService; + + + public void run() throws Exception { + HttpResponse response = agvService.queryZDAgvInstStatus("1"); + //查询AGV指令列表 + JSONArray inst_rows = JSONArray.parseArray(response.body()); + for (int i = 0; i < inst_rows.size(); i++) { + JSONObject inst_jo = inst_rows.getJSONObject(i); + String inst_code = inst_jo.getString("task_code"); + Instruction inst = instructionService.findByCodeFromCache(inst_code); + if (ObjectUtil.isEmpty(inst)){ + continue; + } + //反馈结果状态 + log.info("instcode:" + inst_code + "," + inst_jo.toString()); + + String state = inst_jo.getString("state"); + String vehicle = ""; + //正在执行指令agv车号 + if (!StrUtil.isEmpty(inst_jo.getString("vehicle"))) { + vehicle = inst_jo.getString("vehicle"); + inst.setCarno(vehicle); + } +// RAW:初始状态 +// ACTIVE:业务订单已激活 +// DISPATCHABLE:业务订单已通过系统验证,等待被调度执行 +// BEING_PROCESSED:业务订单正在被执行 +// WITHDRAWN:业务订单已被撤销 +// FINISHED:业务订单已完成 +// FAILED:业务订单已失败 +// UNROUTABLE:无法规划该业务订单的执行路线 + + //执行中 + if ("BEING_PROCESSED".equals(state)) { + if (inst != null) { + inst.setInstruction_status("1"); + instructionService.update(inst); + } + } else if ("FINISHED".equals(state)) { + if (inst != null) { + inst.setInstruction_status("2"); + instructionService.finish(inst); + } + } else if ("WITHDRAWN".equals(state) || "FAILED".equals(state)) { + if (inst != null) { + inst.setInstruction_status("3"); + instructionService.update(inst); + instructionService.removeByCodeFromCache(inst_jo.getString("task_code")); + } + } + JSONArray ja = inst_jo.getJSONArray("destinations"); + for (int j = 0; j < ja.size(); j++) { + JSONObject jo = ja.getJSONObject(j); + JSONArray pro_rows = jo.getJSONArray("properties"); + //Load 取货动作 Unload放货动作 Wait等待 + String operation = jo.getString("operation"); + String device = jo.getString("locationName"); + for (int k = 0; k < pro_rows.size(); k++) { + JSONObject item = pro_rows.getJSONObject(k); + if ("True".equals(item.get("value"))) { + String param = item.get("key").toString(); + //EntryRequired是否进入前等待 PauseOnStation是否离开等待 Wait在该点进行等待 + agvService.process(inst_code, param, device, operation, vehicle); + } + } + } + } + + HttpResponse response2 = agvService.queryZDAgvInstStatus("2"); + //查询AGV指令列表 + JSONArray inst_rows2 = JSONArray.parseArray(response.body()); + for (int i = 0; i < inst_rows2.size(); i++) { + JSONObject inst_jo = inst_rows2.getJSONObject(i); + String inst_code = inst_jo.getString("task_code"); + Instruction inst = instructionService.findByCodeFromCache(inst_code); + if (ObjectUtil.isEmpty(inst)){ + continue; + } + //反馈结果状态 + log.info("instcode:" + inst_code + "," + inst_jo.toString()); + + String state = inst_jo.getString("state"); + String vehicle = ""; + //正在执行指令agv车号 + if (!StrUtil.isEmpty(inst_jo.getString("vehicle"))) { + vehicle = inst_jo.getString("vehicle"); + inst.setCarno(vehicle); + } +// RAW:初始状态 +// ACTIVE:业务订单已激活 +// DISPATCHABLE:业务订单已通过系统验证,等待被调度执行 +// BEING_PROCESSED:业务订单正在被执行 +// WITHDRAWN:业务订单已被撤销 +// FINISHED:业务订单已完成 +// FAILED:业务订单已失败 +// UNROUTABLE:无法规划该业务订单的执行路线 + + //执行中 + if ("BEING_PROCESSED".equals(state)) { + if (inst != null) { + inst.setInstruction_status("1"); + instructionService.update(inst); + } + } else if ("FINISHED".equals(state)) { + if (inst != null) { + inst.setInstruction_status("2"); + instructionService.finish(inst); + } + } else if ("WITHDRAWN".equals(state) || "FAILED".equals(state)) { + if (inst != null) { + inst.setInstruction_status("3"); + instructionService.update(inst); + instructionService.removeByCodeFromCache(inst_jo.getString("task_code")); + } + } + JSONArray ja = inst_jo.getJSONArray("destinations"); + for (int j = 0; j < ja.size(); j++) { + JSONObject jo = ja.getJSONObject(j); + JSONArray pro_rows = jo.getJSONArray("properties"); + //Load 取货动作 Unload放货动作 Wait等待 + String operation = jo.getString("operation"); + String device = jo.getString("locationName"); + for (int k = 0; k < pro_rows.size(); k++) { + JSONObject item = pro_rows.getJSONObject(k); + if ("True".equals(item.get("value"))) { + String param = item.get("key").toString(); + //EntryRequired是否进入前等待 PauseOnStation是否离开等待 Wait在该点进行等待 + agvService.process(inst_code, param, device, operation, vehicle); + } + } + } + } + } +} diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/start/auto/run/AutoRunServiceImpl.java b/wcs/hd/nladmin-system/src/main/java/org/nl/start/auto/run/AutoRunServiceImpl.java index 4d57f3f..d40639d 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/start/auto/run/AutoRunServiceImpl.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/start/auto/run/AutoRunServiceImpl.java @@ -2,6 +2,7 @@ package org.nl.start.auto.run; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; import org.nl.exception.WDKException; @@ -165,9 +166,9 @@ public class AutoRunServiceImpl implements AutoRunService, ApplicationAutoInitia private List getAllAutoThread() { - return (List) (this.abstractAutoRunnableList != null && this.abstractAutoRunnableList.size() != 0 + return ObjectUtil.isNotEmpty(abstractAutoRunnableList) ? this.abstractAutoRunnableList - : new LinkedList()); + : new LinkedList(); } @Override diff --git a/wcs/hd/nladmin-system/src/test/java/org/nl/ChuanKou.java b/wcs/hd/nladmin-system/src/test/java/org/nl/ChuanKou.java new file mode 100644 index 0000000..e4382ea --- /dev/null +++ b/wcs/hd/nladmin-system/src/test/java/org/nl/ChuanKou.java @@ -0,0 +1,200 @@ +package org.nl; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.TooManyListenersException; + +import gnu.io.CommPort; +import gnu.io.CommPortIdentifier; +import gnu.io.NoSuchPortException; +import gnu.io.PortInUseException; +import gnu.io.SerialPort; +import gnu.io.SerialPortEventListener; +import gnu.io.UnsupportedCommOperationException; +/** + * 串口通信工具 + * @author ChenWei + * @email 582900710@qq.com + * @date 2021年11月11日 上午11:01:23 + * @since 1 + */ +class SerialComKit { + /** + * 查询可用串口 + * @author ChenWei + * @email 582900710@qq.com + * @date 2021年11月11日 上午11:45:29 + * @since 1 + * @return + */ + public static List findPort() { + //获得当前所有可用串口 + @SuppressWarnings("unchecked") + Enumeration portList = + CommPortIdentifier.getPortIdentifiers(); + List portNameList = new ArrayList<>(9); + //将可用串口名添加到List并返回该List + while (portList.hasMoreElements()) { + String portName = portList.nextElement().getName(); + portNameList.add(portName); + } + return portNameList; + } + /** + * 开启串口 + * @author ChenWei + * @email 582900710@qq.com + * @date 2021年11月11日 上午11:44:55 + * @since 1 + * @param portName 串口名称 + * @param baudrate 波特率 + * @return + * @throws NoSuchPortException + * @throws PortInUseException + * @throws UnsupportedCommOperationException + * @throws Exception + */ + public static SerialPort openPort( + String portName, + int baudrate) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException{ + //通过端口名识别端口 + CommPortIdentifier portIdentifier = + CommPortIdentifier.getPortIdentifier(portName); + + //打开端口,并给端口名字和一个timeout(打开操作的超时时间) + CommPort commPort = portIdentifier.open(portName, 3000); + + //判断是不是串口 + if (commPort instanceof SerialPort) { + SerialPort serialPort = (SerialPort) commPort; + //设置一下串口的波特率等参数 + serialPort.setSerialPortParams( + baudrate, SerialPort.DATABITS_8, + SerialPort.STOPBITS_1, + SerialPort.PARITY_NONE); + return serialPort; + }else { + return null; + } + } + /** + * 关闭串口 + * @author ChenWei + * @email 582900710@qq.com + * @date 2021年11月11日 上午11:47:17 + * @since 1 + * @param serialPort + */ + public static void closePort( + SerialPort serialPort) { + if (serialPort != null) { + try { + serialPort.removeEventListener(); + serialPort.close(); + serialPort = null; + } catch (Exception e) { + } + } + } + /** + * 发送数据到串口 + * @author ChenWei + * @email 582900710@qq.com + * @date 2021年11月11日 上午11:51:22 + * @since 1 + * @param serialPort + * @param data + * @return + * @throws Exception + */ + public static boolean sendToPort( + SerialPort serialPort, + byte[] data) throws Exception{ + + OutputStream out = null; + try { + out = serialPort.getOutputStream(); + out.write(data); + out.flush(); + return true; + } catch (IOException e) { + return false; + } finally { + try { + if (out != null) { + out.close(); + out = null; + } + } catch (IOException e) { + } + } + + } + /** + * 读取串口数据 + * @author ChenWei + * @email 582900710@qq.com + * @date 2021年11月11日 上午11:55:01 + * @since 1 + * @param serialPort + * @return 字节数组 + */ + public static byte[] readFromPort( + SerialPort serialPort) { + InputStream in = null; + byte[] bytes = null; + try { + in = serialPort.getInputStream(); + //获取buffer里的数据长度 + int bufflenth = in.available(); + while (bufflenth != 0) { + //初始化byte数组为buffer中数据的长度 + bytes = new byte[bufflenth]; + in.read(bytes); + bufflenth = in.available(); + } + } catch (IOException e) { + return null; + } finally { + try { + if (in != null) { + in.close(); + in = null; + } + } catch(IOException e) { + } + } + return bytes; + } + /** + * 添加监听事件 + * @author ChenWei + * @email 582900710@qq.com + * @date 2021年11月11日 下午2:25:16 + * @since 1 + * @param port + * @param listener + * @throws TooManyListenersException + */ + public static void addListener( + SerialPort port, + SerialPortEventListener listener) throws TooManyListenersException{ + //给串口添加监听器 + port.addEventListener(listener); + //设置当有数据到达时唤醒监听接收线程 + port.notifyOnDataAvailable(true); + //设置当通信中断时唤醒中断线程 + port.notifyOnBreakInterrupt(true); + } + public static void main(String[] args) { + List findPort = SerialComKit.findPort(); + System.out.println(findPort); + } +} + + + diff --git a/wcs/hd/nladmin-system/src/test/java/org/nl/TaskCreate.java b/wcs/hd/nladmin-system/src/test/java/org/nl/TaskCreate.java index fb157fc..58eb89a 100644 --- a/wcs/hd/nladmin-system/src/test/java/org/nl/TaskCreate.java +++ b/wcs/hd/nladmin-system/src/test/java/org/nl/TaskCreate.java @@ -1,14 +1,342 @@ package org.nl; -/** - * 模拟从1001-1002的AGV搬运任务生成,如从入库口到库内 - * 任务触发,比如mode变为2 - * 1、申请任务,需要判断路由是否存在。 - * 1.1、电器按钮:mode=2,3,4代表任务类型:申请空盘,申请入库等 - * 1.2、光电信号:move:0,1 有货,无货等 - * 2、相关接口 - * 2.1 申请WMS,WMS直接返回任务 - * 2.2 申请WMS,直接返回false或true,然后WMS通过定时器下发给ACS - */ -public class TaskCreate { -} +import gnu.io.*; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.*; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + + +class ContinueRead extends Thread implements SerialPortEventListener { // SerialPortEventListener + // 监听器,我的理解是独立开辟一个线程监听串口数据 +// 串口通信管理类 + static CommPortIdentifier portId; + + /* 有效连接上的端口的枚举 */ + + @SuppressWarnings("unchecked") + static Enumeration portList; + InputStream inputStream; // 从串口来的输入流 + static OutputStream outputStream;// 向串口输出的流 + static SerialPort serialPort; // 串口的引用 + // 堵塞队列用来存放读到的数据 + private BlockingQueue msgQueue = new LinkedBlockingQueue(); + + @Override + /** + * SerialPort EventListene 的方法,持续监听端口上是否有数据流 + */ + public void serialEvent(SerialPortEvent event) {// + + switch (event.getEventType()) { + case SerialPortEvent.BI: + case SerialPortEvent.OE: + case SerialPortEvent.FE: + case SerialPortEvent.PE: + case SerialPortEvent.CD: + case SerialPortEvent.CTS: + case SerialPortEvent.DSR: + case SerialPortEvent.RI: + case SerialPortEvent.OUTPUT_BUFFER_EMPTY: + break; + case SerialPortEvent.DATA_AVAILABLE:// 当有可用数据时读取数据 + byte[] readBuffer = null; + int availableBytes = 0; + try { + availableBytes = inputStream.available(); + while (availableBytes > 0) { + readBuffer = ContinueRead.readFromPort(serialPort); + String needData = printHexString(readBuffer); + System.out.println(new Date() + "真实收到的数据为:-----" + needData); + availableBytes = inputStream.available(); + msgQueue.add(needData); + } + } catch (IOException e) { + } + default: + break; + } + } + + /** + * 从串口读取数据 + * + * @param serialPort 当前已建立连接的SerialPort对象 + * @return 读取到的数据 + */ + public static byte[] readFromPort(SerialPort serialPort) { + InputStream in = null; + byte[] bytes = {}; + try { + in = serialPort.getInputStream(); + // 缓冲区大小为一个字节 + byte[] readBuffer = new byte[1]; + int bytesNum = in.read(readBuffer); + while (bytesNum > 0) { + bytes = concat(bytes, readBuffer); + bytesNum = in.read(readBuffer); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (in != null) { + in.close(); + in = null; + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return bytes; + } + + + /** + * 通过程序打开COM4串口,设置监听器以及相关的参数 + * + * @return 返回1 表示端口打开成功,返回 0表示端口打开失败 + */ + public int startComPort() { + // 通过串口通信管理类获得当前连接上的串口列表 + portList = CommPortIdentifier.getPortIdentifiers(); + + while (portList.hasMoreElements()) { + // 获取相应串口对象 + portId = (CommPortIdentifier) portList.nextElement(); + + System.out.println("设备类型:--->" + portId.getPortType()); + System.out.println("设备名称:---->" + portId.getName()); + // 判断端口类型是否为串口 + if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { + // 判断如果COM4串口存在,就打开该串口 + if (portId.getName().equals("COM5")) { + try { + // 打开串口名字为COM_4(名字任意),延迟为1000毫秒 + serialPort = (SerialPort) portId.open(portId.getName(), 1000); + + } catch (PortInUseException e) { + System.out.println("打开端口失败!"); + e.printStackTrace(); + return 0; + } + // 设置当前串口的输入输出流 + try { + inputStream = serialPort.getInputStream(); + outputStream = serialPort.getOutputStream(); + } catch (IOException e) { + e.printStackTrace(); + return 0; + } + // 给当前串口添加一个监听器 + try { + serialPort.addEventListener(this); + } catch (TooManyListenersException e) { + e.printStackTrace(); + return 0; + } + // 设置监听器生效,即:当有数据时通知 + serialPort.notifyOnDataAvailable(true); + + // 设置串口的一些读写参数 + try { + // 比特率、数据位、停止位、奇偶校验位 + serialPort.setSerialPortParams(9600, + SerialPort.DATABITS_8, SerialPort.STOPBITS_1, + SerialPort.PARITY_NONE); + } catch (UnsupportedCommOperationException e) { + e.printStackTrace(); + return 0; + } + return 1; + } + } + } + return 0; + } + + @Override + public void run() { + // TODO Auto-generated method stub + try { + System.out.println("--------------任务处理线程运行了--------------"); + while (true) { + // 如果堵塞队列中存在数据就将其输出 + if (msgQueue.size() > 0) { + String vo = msgQueue.peek(); + String vos[] = vo.split(" ", -1); + getData(vos); + sendOrder(); + msgQueue.take(); + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * @Description: 发送获取数据指令 + * @Param: + * @return: + * @Author: LiangZF + * @Date: 2019/1/3 + */ + public void sendOrder() { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + int i = 1; + if (i == 1) { + // 启动线程来处理收到的数据 + try { + byte[] b = new byte[]{0x01, 0x03, 0x00, 0x00, 0x00, 0x0E, (byte) 0xC4, 0x0E}; + System.out.println("发送的数据:" + b); + System.out.println("发出字节数:" + b.length); + outputStream.write(b); + outputStream.flush(); + } catch (IOException e) { + // TODO Auto-generated catch block + serialPort.close(); + e.printStackTrace(); + } finally { + try { + if (outputStream != null) { + outputStream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * @Description:通过数组解析检测数据 + * @Param: [vo] + * @return: void + * @Author: LiangZF + * @Date: 2019/1/4 + */ + public void getData(String[] vos) { + // 数组不为空 + if (vos != null || vos.length != 0) { + // 风向数据 + long wind_direction = getNum(vos[3], vos[4]); + System.out.println(wind_direction); + // 风速数据 + long wind_speech = getNum(vos[5], vos[6]); + System.out.println(wind_speech); + // pm2.5 + long polutionPm2 = getNum(vos[7], vos[8]); + System.out.println(polutionPm2); + // pm10 + long polutionPm10 = getNum(vos[9], vos[10]); + System.out.println(polutionPm10); + // VOC + long voc = getNum(vos[11], vos[12]); + System.out.println(voc); + // 温度 + long polutionPm = getNum(vos[13], vos[14]) / 10; + System.out.println(polutionPm); + // 湿度 + long temperature = getNum(vos[15], vos[16]) / 10; + System.out.println(temperature); + // 大气压力 + long atmosphericPressure = getNum(vos[17], vos[18]); + System.out.println(atmosphericPressure); + // 臭氧 + long ozone = getNum(vos[19], vos[20]) / 1000; + System.out.println(ozone); + // CO + long co = getNum(vos[21], vos[22]) / 100; + System.out.println(co); + Map map = new HashMap<>(); + map.put("O3", ozone); + map.put("PM2.5", polutionPm2); + map.put("PM10", polutionPm10); + /*Map uu = AqiUtil.getAqiByPollutants(map); + String pollutants = (String) uu.get("key"); + Integer aqi = (Integer) uu.get("value");*/ + } + } + + // 16转10计算 + public long getNum(String num1, String num2) { + long value = Long.parseLong(num1, 16) * 256 + Long.parseLong(num2, 16); + return value; + } + + /** + * @Description: 保存到数据库表中 + * @Param: [wind_direction, wind_speech, polutionPm2, polutionPm10, voc, polutionPm, temperature, atmosphericPressure, ozone, co, pollution, aqi] + * @return: void + * @Author: LiangZF + * @Date: 2019/1/6 + */ + + public static void main(String[] args) { + ContinueRead cRead = new ContinueRead(); + System.out.println("asdasd"); + int i = cRead.startComPort(); + if (i == 1) { + // 启动线程来处理收到的数据 + cRead.start(); + try { + //根据提供的文档给出的发送命令,发送16进制数据给仪器 + byte[] b = new byte[]{0x01, 0x03, 0x00, 0x00, 0x00, 0x0E, (byte) 0xC4, 0x0E}; + System.out.println("发送的数据:" + b); + System.out.println("发出字节数:" + b.length); + outputStream.write(b); + outputStream.flush(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + try { + if (outputStream != null) { + outputStream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } else { + return; + } + } + + // 字节数组转字符串 + private String printHexString(byte[] b) { + + StringBuffer sbf = new StringBuffer(); + for (int i = 0; i < b.length; i++) { + String hex = Integer.toHexString(b[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + sbf.append(hex.toUpperCase() + " "); + } + return sbf.toString().trim(); + } + + public static byte[] concat(byte[] firstArray, byte[] secondArray) { + if (firstArray == null || secondArray == null) { + if (firstArray != null) + return firstArray; + if (secondArray != null) + return secondArray; + return null; + } + byte[] bytes = new byte[firstArray.length + secondArray.length]; + System.arraycopy(firstArray, 0, bytes, 0, firstArray.length); + System.arraycopy(secondArray, 0, bytes, firstArray.length, secondArray.length); + return bytes; + } +} \ No newline at end of file diff --git a/wcs/hd/nladmin-system/src/test/java/org/nl/Test.java b/wcs/hd/nladmin-system/src/test/java/org/nl/Test.java new file mode 100644 index 0000000..e69de29 diff --git a/wcs/qd/src/views/acs/device/config.vue b/wcs/qd/src/views/acs/device/config.vue index 0638433..263ebcb 100644 --- a/wcs/qd/src/views/acs/device/config.vue +++ b/wcs/qd/src/views/acs/device/config.vue @@ -80,7 +80,11 @@ import standard_scanner from '@/views/acs/device/driver/standard_scanner' import standard_conveyor_control_with_scanner from '@/views/acs/device/driver/standard_conveyor_control_with_scanner' import standard_conveyor_control from '@/views/acs/device/driver/standard_conveyor_control' import standard_conveyor_monitor from '@/views/acs/device/driver/standard_conveyor_monitor' -import hailiang_smart_plc_test from '@/views/acs/device/driver/hailiang_one/hailiang_smart_plc_test' +import hailiang_smart_plc_test from '@/views/acs/device/driver/hailiang_smart_plc_test' +import paint_conveyor from '@/views/acs/device/driver/paint_conveyor' +import haokai_auto_conveyor from '@/views/acs/device/driver/haokai_auto_conveyor' +import cargo_lift_conveyor from '@/views/acs/device/driver/cargo_lift_conveyor' +import empty_vehicle_stacking_position from '@/views/acs/device/driver/empty_vehicle_stacking_position' export default { name: 'DeviceConfig', @@ -92,7 +96,11 @@ export default { standard_conveyor_control_with_scanner, standard_conveyor_control, standard_conveyor_monitor, - hailiang_smart_plc_test + hailiang_smart_plc_test, + paint_conveyor, + haokai_auto_conveyor, + cargo_lift_conveyor, + empty_vehicle_stacking_position }, dicts: ['device_type'], mixins: [crud], @@ -138,6 +146,7 @@ export default { }, methods: { changeDriver(val) { + debugger this.currentComponent = val } } diff --git a/wcs/qd/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_feeding_line.vue b/wcs/qd/src/views/acs/device/driver/cargo_lift_conveyor.vue similarity index 87% rename from wcs/qd/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_feeding_line.vue rename to wcs/qd/src/views/acs/device/driver/cargo_lift_conveyor.vue index 4d8779a..03caccd 100644 --- a/wcs/qd/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_feeding_line.vue +++ b/wcs/qd/src/views/acs/device/driver/cargo_lift_conveyor.vue @@ -1,5 +1,5 @@ - - - - diff --git a/wcs/qd/src/views/acs/device/driver/non_line_inspect_site.vue b/wcs/qd/src/views/acs/device/driver/non_line_inspect_site.vue deleted file mode 100644 index b252314..0000000 --- a/wcs/qd/src/views/acs/device/driver/non_line_inspect_site.vue +++ /dev/null @@ -1,220 +0,0 @@ - - - - - diff --git a/wcs/qd/src/views/acs/device/driver/non_line_manipulator_inspect_site.vue b/wcs/qd/src/views/acs/device/driver/non_line_manipulator_inspect_site.vue deleted file mode 100644 index e0df177..0000000 --- a/wcs/qd/src/views/acs/device/driver/non_line_manipulator_inspect_site.vue +++ /dev/null @@ -1,220 +0,0 @@ - - - - - diff --git a/wcs/qd/src/views/acs/device/driver/hailiang_one/hailiang_xj_plc_test.vue b/wcs/qd/src/views/acs/device/driver/paint_conveyor.vue similarity index 88% rename from wcs/qd/src/views/acs/device/driver/hailiang_one/hailiang_xj_plc_test.vue rename to wcs/qd/src/views/acs/device/driver/paint_conveyor.vue index 4d8779a..f4eea0b 100644 --- a/wcs/qd/src/views/acs/device/driver/hailiang_one/hailiang_xj_plc_test.vue +++ b/wcs/qd/src/views/acs/device/driver/paint_conveyor.vue @@ -1,5 +1,5 @@ diff --git a/wcs/qd/src/views/acs/stage/editor/index.vue b/wcs/qd/src/views/acs/stage/editor/index.vue index 52c7a8b..f85330e 100644 --- a/wcs/qd/src/views/acs/stage/editor/index.vue +++ b/wcs/qd/src/views/acs/stage/editor/index.vue @@ -231,42 +231,7 @@ export default { { id: 10, name: '墙面竖', img1: '墙面竖' }, { id: 11, name: '区域横', img1: '区域横' }, { id: 12, name: '区域竖', img1: '区域竖' }, - { id: 13, name: '专机', img1: '专机' }, - { id: 14, name: '激', img1: '激' }, - { id: 15, name: '光', img1: '光' }, - { id: 16, name: '区', img1: '区' }, - { id: 17, name: '一', img1: '一' }, - { id: 18, name: '三', img1: '三' }, - { id: 19, name: '下', img1: '下' }, - { id: 20, name: '仓', img1: '仓' }, - { id: 21, name: '伸', img1: '伸' }, - { id: 22, name: '体', img1: '体' }, - { id: 23, name: '储', img1: '储' }, - { id: 24, name: '刻', img1: '刻' }, - { id: 25, name: '加', img1: '加' }, - { id: 26, name: '包', img1: '包' }, - { id: 27, name: '压', img1: '压' }, - { id: 28, name: '品', img1: '品' }, - { id: 29, name: '孔', img1: '孔' }, - { id: 30, name: '字', img1: '字' }, - { id: 31, name: '屑', img1: '屑' }, - { id: 32, name: '工', img1: '工' }, - { id: 33, name: '弯', img1: '弯' }, - { id: 34, name: '拉', img1: '拉' }, - { id: 35, name: '推', img1: '推' }, - { id: 36, name: '料', img1: '料' }, - { id: 37, name: '旋', img1: '旋' }, - { id: 38, name: '无', img1: '无' }, - { id: 39, name: '机', img1: '机' }, - { id: 40, name: '桶', img1: '桶' }, - { id: 41, name: '洗', img1: '洗' }, - { id: 42, name: '清', img1: '清' }, - { id: 43, name: '盘', img1: '盘' }, - { id: 44, name: '直', img1: '直' }, - { id: 45, name: '码', img1: '码' }, - { id: 46, name: '管', img1: '管' }, - { id: 47, name: '装', img1: '装' }, - { id: 48, name: '镗', img1: '镗' } + { id: 13, name: '专机', img1: '专机' } ], arr2: [], stageSelectList: [], diff --git a/wcs/qd/src/views/acs/task/index.vue b/wcs/qd/src/views/acs/task/index.vue index 7be7b03..a9a05bf 100644 --- a/wcs/qd/src/views/acs/task/index.vue +++ b/wcs/qd/src/views/acs/task/index.vue @@ -260,15 +260,15 @@ 完成 - + - + - +