From 74445eaf7db2d799920aa091ee2d884336c720bd Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Thu, 23 Mar 2023 15:03:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...CoveyorControlWithScannerDeviceDriver.java | 180 +++++++++--------- 1 file changed, 92 insertions(+), 88 deletions(-) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java index 2d3b52bed..4830d09ce 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java @@ -148,7 +148,8 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe scanner.cleanBarcode(); logServer.deviceExecuteLog(this.device_code, "", "", "清理条码"); } - public synchronized boolean finish_instruction(){ + + public synchronized boolean finish_instruction() { try { instructionService.finish(inst); } catch (Exception e) { @@ -189,7 +190,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe @Override - public void execute(){ + public void execute() { try { device_code = this.getDeviceCode(); heartbeat = this.itemProtocol.getHeartbeat(); @@ -197,13 +198,13 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe move = this.itemProtocol.getMove(); error = this.itemProtocol.getError(); task = this.itemProtocol.getTask(); - plcbarcode = this.itemProtocol.getplcBarCode(); - plcbarcode_length = this.itemProtocol.getBarCode_length(); + plcbarcode = this.itemProtocol.getplcBarCode(); + plcbarcode_length = this.itemProtocol.getBarCode_length(); to_task = this.itemProtocol.getTotTask(); weight = this.itemProtocol.getWeight(); if (mode != last_mode) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode +"复位请求标记"); - if(mode == 2){ + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode + "复位请求标记"); + if (mode == 2) { this.setRequireSucess(false); this.setApplySucess(false); message = null; @@ -224,15 +225,15 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe if (plcbarcode_length != last_plcbarcode_length) { logServer.deviceExecuteLog(this.device_code, "", "", "信号plcbarcode_length:" + last_plcbarcode_length + "->" + plcbarcode_length); } - if (!StrUtil.equals(plcbarcode,last_plcbarcode) ) { + if (!StrUtil.equals(plcbarcode, last_plcbarcode)) { logServer.deviceExecuteLog(this.device_code, "", "", "信号plcbarcode:" + last_plcbarcode + "->" + plcbarcode); } if (task != last_task) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task+ "->" + task); + logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); } if (weight != last_weight) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号weight:" + last_weight+ "->" + weight); + logServer.deviceExecuteLog(this.device_code, "", "", "信号weight:" + last_weight + "->" + weight); } if (mode == 2 && move != 0 && task > 0) { //inst_message @@ -266,7 +267,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } else { this.setIsonline(true); this.setIserror(false); - if(error>0){ + if (error > 0) { this.setIserror(true); } Instruction instruction = null; @@ -279,11 +280,11 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe //申请任务 String newBarcode = null; - if(!StrUtil.isEmpty(barcode())){ + if (!StrUtil.isEmpty(barcode())) { newBarcode = barcode(); } else { // - if(plcbarcode_length>2){ + if (plcbarcode_length > 2) { newBarcode = plcbarcode; } else { break; @@ -300,11 +301,11 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe case 5: String newBarcodes = null; //申请任务 - if(!StrUtil.isEmpty(barcode())){ + if (!StrUtil.isEmpty(barcode())) { newBarcodes = barcode(); } else { // - if(plcbarcode_length>2){ + if (plcbarcode_length > 2) { newBarcodes = plcbarcode; } else { break; @@ -355,16 +356,16 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe this.set_last_container(container); List list = new ArrayList(); Map map = new HashMap(); - map.put("code","to_target"); - map.put("value","0"); + map.put("code", "to_target"); + map.put("value", "0"); list.add(map); Map map2 = new HashMap(); - map2.put("code","to_task"); - map2.put("value","0"); + map2.put("code", "to_task"); + map2.put("value", "0"); list.add(map2); Map map3 = new HashMap(); - map3.put("code","to_command"); - map3.put("value","0"); + map3.put("code", "to_command"); + map3.put("value", "0"); list.add(map3); this.writing(list); message = null; @@ -439,7 +440,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe return instruction_require(container_code, WcsConfig.task_container_type_default_desc); } - public synchronized boolean instruction_apply(String container_code) { + public synchronized boolean instruction_apply(String container_code) { Date date = new Date(); if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); @@ -448,44 +449,45 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe this.instruction_apply_time = date; //container_code TaskDto task = taskserver.findByContainer(container_code); + logServer.deviceExecuteLog(device_code, "", "", "申请任务时,根据托盘号:" + container_code + ",查询出来得任务信息是:" + JSON.toJSONString(task)); if (!ObjectUtil.isEmpty(task)) { Instruction instdto = instructionService.findByTaskcodeAndStatus(task.getTask_code()); - if(!StrUtil.equals(instdto.getStart_device_code(),this.device_code)){ - message ="当前载具号"+container_code+"查找对应指令起点与当前设备不符"; + if (!StrUtil.equals(instdto.getStart_device_code(), this.device_code)) { + message = "当前载具号" + container_code + "查找对应指令起点与当前设备不符"; // this.setIserror(true); return false; } - if(ObjectUtil.isNotEmpty(instdto)){ + if (ObjectUtil.isNotEmpty(instdto)) { List list = new ArrayList(); Map map = new HashMap(); - if(StrUtil.isNotEmpty(task.getTo_z())){ - if(StrUtil.equals(task.getTo_z(),"01")){ - map.put("code","to_target"); - map.put("value","102"); - } else if(StrUtil.equals(task.getTo_z(),"02")){ - map.put("code","to_target"); - map.put("value","201"); - } else if(StrUtil.equals(task.getTo_z(),"03")){ - map.put("code","to_target"); - map.put("value","301"); + if (StrUtil.isNotEmpty(task.getTo_z())) { + if (StrUtil.equals(task.getTo_z(), "01")) { + map.put("code", "to_target"); + map.put("value", "102"); + } else if (StrUtil.equals(task.getTo_z(), "02")) { + map.put("code", "to_target"); + map.put("value", "201"); + } else if (StrUtil.equals(task.getTo_z(), "03")) { + map.put("code", "to_target"); + map.put("value", "301"); } } list.add(map); Map map2 = new HashMap(); - map2.put("code","to_task"); - map2.put("value",instdto.getInstruction_code()); + map2.put("code", "to_task"); + map2.put("value", instdto.getInstruction_code()); list.add(map2); Map map3 = new HashMap(); - map3.put("code","to_command"); - map3.put("value","1"); + map3.put("code", "to_command"); + map3.put("value", "1"); list.add(map3); this.writing(list); message = "下发电气任务号成功"; requireSucess = true; applySucess = true; } else { - message = "任务号:"+ task.getTask_code()+"未找到指令"; + message = "任务号:" + task.getTask_code() + "未找到指令"; } } else { @@ -498,6 +500,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe /** * 请求指令 * 定点任务时请求这里 + * * @param container_code * @param container_type */ @@ -510,15 +513,16 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe this.instruction_require_time = date; //container_code TaskDto taskdto = taskserver.findByContainer(container_code); + logServer.deviceExecuteLog(device_code, "", "", "申请任务时,根据托盘号:" + container_code + ",查询出来得任务信息是:" + JSON.toJSONString(taskdto)); if (!ObjectUtil.isEmpty(taskdto)) { if (!ObjectUtils.isEmpty(instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()))) { - logServer.deviceExecuteLog(this.device_code, "", "", "申请任务时该载具号"+container_code - +"已存在对应任务,不再请求"); - Instruction instdto = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()); - if(!StrUtil.equals(instdto.getStart_device_code(),this.device_code)){ - message ="当前载具号"+container_code+"查找对应指令起点与当前设备不符"; + logServer.deviceExecuteLog(this.device_code, "", "", "申请任务时该载具号" + container_code + + "已存在对应任务,不再请求"); + Instruction instdto = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()); + if (!StrUtil.equals(instdto.getStart_device_code(), this.device_code)) { + message = "当前载具号" + container_code + "查找对应指令起点与当前设备不符"; logServer.deviceExecuteLog(this.device_code, "", "", "申请任务" - +"当前载具号"+container_code+"查找对应指令起点与当前设备不符"); + + "当前载具号" + container_code + "查找对应指令起点与当前设备不符"); return false; } this.setIserror(false); @@ -549,8 +553,8 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe list.add(map3); this.writing(list); message = "下发电气任务号成功"; - logServer.deviceExecuteLog(this.device_code, "", "", "申请任务时该载具号"+container_code - +"已存在对应任务,下发电气信号"); + logServer.deviceExecuteLog(this.device_code, "", "", "申请任务时该载具号" + container_code + + "已存在对应任务,下发电气信号"); requireSucess = true; applySucess = true; } else { @@ -559,10 +563,10 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe return true; } else { //需要判断指令中的指令 再次请求不能生成 - if (!ObjectUtils.isEmpty(instructionService.findByTaskcodeAndStatus(taskdto.getTask_code(),"1"))) { + if (!ObjectUtils.isEmpty(instructionService.findByTaskcodeAndStatus(taskdto.getTask_code(), "1"))) { { - Instruction instdto = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code(),"1"); - if(to_task != Integer.parseInt(instdto.getInstruction_code())){ + Instruction instdto = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code(), "1"); + if (to_task != Integer.parseInt(instdto.getInstruction_code())) { List list = new ArrayList(); Map map = new HashMap(); if (StrUtil.isNotEmpty(taskdto.getTo_z())) { @@ -653,8 +657,8 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe next_point_code = next_device_code; } - if(!StrUtil.equals(taskdto.getStart_device_code(),this.device_code)){ - message ="当前载具号"+container_code+"查找对应指令起点与当前设备不符"; + if (!StrUtil.equals(taskdto.getStart_device_code(), this.device_code)) { + message = "当前载具号" + container_code + "查找对应指令起点与当前设备不符"; // List list = new ArrayList(); // Map map = new HashMap(); // map.put("code","to_target"); @@ -695,8 +699,8 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe instructionService.create(instdto); } catch (Exception e) { e.printStackTrace(); - log.error("指令创建失败!",e.getMessage()); - return false; + log.error("指令创建失败!", e.getMessage()); + return false; } //创建指令后修改任务状态 taskdto.setTask_status("1"); @@ -706,26 +710,26 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe List list = new ArrayList(); Map map = new HashMap(); - if(StrUtil.isNotEmpty(taskdto.getTo_z())){ - if(StrUtil.equals(taskdto.getTo_z(),"01")){ - map.put("code","to_target"); - map.put("value","102"); - } else if(StrUtil.equals(taskdto.getTo_z(),"02")){ - map.put("code","to_target"); - map.put("value","201"); - } else if(StrUtil.equals(taskdto.getTo_z(),"03")){ - map.put("code","to_target"); - map.put("value","301"); + if (StrUtil.isNotEmpty(taskdto.getTo_z())) { + if (StrUtil.equals(taskdto.getTo_z(), "01")) { + map.put("code", "to_target"); + map.put("value", "102"); + } else if (StrUtil.equals(taskdto.getTo_z(), "02")) { + map.put("code", "to_target"); + map.put("value", "201"); + } else if (StrUtil.equals(taskdto.getTo_z(), "03")) { + map.put("code", "to_target"); + map.put("value", "301"); } } list.add(map); Map map2 = new HashMap(); - map2.put("code","to_task"); - map2.put("value",instdto.getInstruction_code()); + map2.put("code", "to_task"); + map2.put("value", instdto.getInstruction_code()); list.add(map2); Map map3 = new HashMap(); - map3.put("code","to_command"); - map3.put("value","1"); + map3.put("code", "to_command"); + map3.put("value", "1"); list.add(map3); this.writing(list); // if(task != Integer.parseInt(instdto.getInstruction_code()) ){ @@ -740,24 +744,24 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe JSONObject apply = new JSONObject(); apply.put("vehicle_code", container_code); apply.put("device_code", device_code); - apply.put("type","1"); - logServer.deviceExecuteLog(this.device_code, "", "", "申请入库,请求参数:"+apply.toString()); + apply.put("type", "1"); + logServer.deviceExecuteLog(this.device_code, "", "", "申请入库,请求参数:" + apply.toString()); String str = acsToWmsService.applyTaskToWms(apply); JSONObject jo = JSON.parseObject(str); - logServer.deviceExecuteLog(this.device_code, "", "", "申请入库,返回参数:"+jo.toString()); + logServer.deviceExecuteLog(this.device_code, "", "", "申请入库,返回参数:" + jo.toString()); if (ObjectUtil.isEmpty(jo)) { message = "接口不通"; List list = new ArrayList(); Map map = new HashMap(); - map.put("code","to_target"); - map.put("value","1011"); + map.put("code", "to_target"); + map.put("value", "1011"); list.add(map); Map map2 = new HashMap(); - map2.put("code","to_command"); - map2.put("value","1"); + map2.put("code", "to_command"); + map2.put("value", "1"); Map map3 = new HashMap(); - map3.put("code","to_task"); - map3.put("value","0"); + map3.put("code", "to_task"); + map3.put("value", "0"); list.add(map3); this.writing(list); requireSucess = true; @@ -769,25 +773,25 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe requireSucess = true; applySucess = false; } else { - if (jo.get("message")!=null){ + if (jo.get("message") != null) { message = jo.get("message").toString(); } List list = new ArrayList(); Map map = new HashMap(); - map.put("code","to_target"); - map.put("value","1011"); + map.put("code", "to_target"); + map.put("value", "1011"); list.add(map); Map map2 = new HashMap(); - map2.put("code","to_command"); - map2.put("value","1"); + map2.put("code", "to_command"); + map2.put("value", "1"); list.add(map2); Map map3 = new HashMap(); - map3.put("code","to_task"); - map3.put("value","0"); + map3.put("code", "to_task"); + map3.put("value", "0"); list.add(map3); this.writing(list); - message = "申请任务失败下发退回,"+message; + message = "申请任务失败下发退回," + message; requireSucess = true; } @@ -861,7 +865,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe applyLabelingAndBindingRequest.setWeight(String.valueOf((float) weight / 100)); ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,请求参数:"+JSON.toJSONString(applyLabelingAndBindingRequest)); + logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,请求参数:" + JSON.toJSONString(applyLabelingAndBindingRequest)); if (applyLabelingAndBindingResponse.getstatus() == 200) { message = "申请贴标成功"; @@ -873,11 +877,11 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe this.writing(list); this.writing(list); message = "申请贴标下发电气信号成功"; - logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,返回参数:"+JSON.toJSONString(applyLabelingAndBindingResponse)); + logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,返回参数:" + JSON.toJSONString(applyLabelingAndBindingResponse)); requireSucess = true; } else { message = "申请贴标失败," + applyLabelingAndBindingResponse.getMessage(); - logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,返回参数:"+JSON.toJSONString(applyLabelingAndBindingResponse)); + logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,返回参数:" + JSON.toJSONString(applyLabelingAndBindingResponse)); } }