diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java index e0f32087f..8dd8baaf5 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java @@ -1090,7 +1090,6 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme JSONObject jo = JSON.parseObject(str); if (ObjectUtil.isEmpty(jo)) { message = "申请补码AGV搬运任务接口不通"; -// requireSucess = true; } else { if (jo.getInteger("status") == 200) { message = "申请补码AGV搬运任务成功"; @@ -1108,7 +1107,6 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme logServer.deviceExecuteLog(this.device_code, "", "", "申请补码AGV任务,返回参数:" + jo); requireSucess = true; } else { -// requireSucess = true; message = "申请补码AGV搬运任务失败," + jo.get("message").toString(); } } @@ -1160,7 +1158,6 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme logServer.deviceExecuteLog(this.device_code, "", "", "申请AGV任务,返回参数:" + jo); requireSucess = true; } else { -// requireSucess = true; message = "申请AGV搬运任务失败," + jo.get("message").toString(); } } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/belt_conveyor/BeltConveyorDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/belt_conveyor/BeltConveyorDeviceDriver.java index ce380413f..951e8cb05 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/belt_conveyor/BeltConveyorDeviceDriver.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/belt_conveyor/BeltConveyorDeviceDriver.java @@ -4,11 +4,14 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; +import org.nl.acs.AcsConfig; import org.nl.acs.agv.server.AgvService; import org.nl.acs.common.base.CommonFinalParam; import org.nl.acs.device.domain.Device; @@ -18,6 +21,7 @@ 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.enums.AcsToLmsApplyTaskTypeEnum; import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; import org.nl.acs.history.ErrorUtil; @@ -35,6 +39,7 @@ 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.config.SpringContextHolder; +import org.nl.system.service.param.ISysParamService; import org.springframework.beans.factory.annotation.Autowired; import java.util.*; @@ -68,6 +73,9 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements @Autowired DeviceErrorLogService errorLogServer = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class); + + ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class); + private Date instruction_update_time = new Date(); private Date require_apply_strangulation_time = new Date(); private int instruction_update_time_out = 500; @@ -213,6 +221,7 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements to_container_no = this.itemProtocol.getContainer_direction(); to_container_type = this.itemProtocol.getContainer_no(); + if (mode != last_mode) { JSONObject param = new JSONObject(); param.put("device_code", this.device_code); @@ -304,7 +313,6 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements Instruction instruction = null; List toInstructions; - //纸管库申请任务 switch (mode) { case 1: log.debug("弃用(留作兼容)"); @@ -324,6 +332,20 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements //request_for_shipment(String.valueOf(mode), item_out_seq_arr, item_out_qty_arr); } break; + case 5: + //申请AGV任务 + //TODO 申请AGV任务待确认 + if (move == 1 && !requireSucess) { + applyAgvTask(); + } + break; + case 6: + //二楼到一楼输送线申请行架任务 + //TODO 申请行架任务 + if (move == 1 && !requireSucess) { + applyManipulatorTask(); + } + break; default: break; } @@ -345,6 +367,17 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements } + private void applyManipulatorTask() { + + JSONObject param = new JSONObject(); + param.put("device_code", device_code); + logServer.deviceExecuteLog(this.device_code, "", "", "二楼到一楼输送线申请行架任务,参数:" + param); + HttpResponse response = acsToWmsService.shipDeviceUpdate(param); + if (response == null || response.getStatus() == 200) { + logServer.deviceExecuteLog(this.device_code, "", "", "二楼到一楼输送线申请行架任务,接口返回:" + response.body()); + } + } + public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() @@ -355,6 +388,106 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements } + public synchronized void applyAgvTask() { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + String hand_barcode = null; + this.instruction_require_time = date; + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + //判断是否有手动补码 如果有就申请补码agv任务 + if (StrUtil.isNotEmpty(hand_barcode)) { + message = "申请补码AGV搬运任务中..."; + JSONObject apply = new JSONObject(); + apply.put("device_code", device_code); + apply.put("type", AcsToLmsApplyTaskTypeEnum.AGV.getType()); + apply.put("vehicle_code", hand_barcode); + + String str = acsToWmsService.applyTaskToWms(apply); + logServer.deviceExecuteLog(this.device_code, "", "", "申请AGV任务,请求参数:" + apply + ",响应参数," + str); + + JSONObject jo = JSON.parseObject(str); + if (ObjectUtil.isEmpty(jo)) { + message = "申请补码AGV搬运任务接口不通"; + } else { + if (jo.getInteger("status") == 200) { + message = "申请补码AGV搬运任务成功"; + List list = new ArrayList(); + while (!StrUtil.equals(this.getOpcValueAccessor().getValue(this.getOpcServer() + "." + this.getOpcPlc() + "." + this.getDevice_code() + ".to_command").toString() + , "8")) { + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", "再次下发mode信号"); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + logServer.deviceExecuteLog(this.device_code, "", "", "申请补码AGV任务,返回参数:" + jo); + requireSucess = true; + } else { + message = "申请补码AGV搬运任务失败," + jo.get("message").toString(); + } + } + return; + } + //没有就正常申请agv任务 + Instruction instruction = instructionService.findByCode(String.valueOf(task)); + if (ObjectUtil.isEmpty(instruction)) { + message = "指令号" + task + "未找到对应指令"; + return; + } + if (StrUtil.isEmpty(instruction.getVehicle_code())) { + message = "指令号" + task + "未找到对应木箱号"; + return; + } + + message = "申请AGV搬运任务中..."; + JSONObject apply = new JSONObject(); + apply.put("device_code", device_code); + apply.put("type", AcsToLmsApplyTaskTypeEnum.AGV.getType()); + apply.put("vehicle_code", instruction.getVehicle_code()); + + String str = acsToWmsService.applyTaskToWms(apply); + logServer.deviceExecuteLog(this.device_code, "", "", "申请AGV任务,请求参数:" + apply + ",响应参数"); + + JSONObject jo = JSON.parseObject(str); + if (ObjectUtil.isEmpty(jo)) { + message = "申请AGV搬运任务接口不通"; +// requireSucess = true; + } else { + if (jo.getInteger("status") == 200) { + message = "申请AGV搬运任务成功"; + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_command"); + map.put("value", "8"); + list.add(map); + this.writing(list); + while (!StrUtil.equals(this.getOpcValueAccessor().getValue(this.getOpcServer() + "." + this.getOpcPlc() + "." + this.getDevice_code() + ".to_command").toString() + , "8")) { + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发mode信号"); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + logServer.deviceExecuteLog(this.device_code, "", "", "申请AGV任务,返回参数:" + jo); + requireSucess = true; + } else { + message = "申请AGV搬运任务失败," + jo.get("message").toString(); + } + } + + } + } + } + + public void writing(Map map) { DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); Map itemMap = new LinkedHashMap<>(); diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/siemens_conveyor/SiemensConveyorDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/siemens_conveyor/SiemensConveyorDeviceDriver.java index a894fc856..af1d6786b 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/siemens_conveyor/SiemensConveyorDeviceDriver.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/conveyor/siemens_conveyor/SiemensConveyorDeviceDriver.java @@ -752,13 +752,11 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme } ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = new ApplyLabelingAndBindingRequest(); -// JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); StorageCell storageCell = new LambdaQueryChainWrapper<>(storageCellMapper) .eq(StorageCell::getStorage_code, this.device_code) .one(); String start_point_code = null; if (!ObjectUtil.isEmpty(storageCell)) { -// start_point_code = (String) device_json.get("parent_storage_code") == null ? this.device_code : (String) device_json.get("parent_storage_code"); start_point_code = (String) storageCell.getParent_storage_code() == null ? this.device_code : (String) storageCell.getParent_storage_code(); } applyLabelingAndBindingRequest.setDevice_code(start_point_code); @@ -800,30 +798,25 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme if (ObjectUtil.isEmpty(instruction)) { message = "申请捆扎电气设备任务号:" + task + "未找到对应指令"; return; -// throw new RuntimeException("该电气任务号未找到对应指令!"); } vehicle_code = instruction.getVehicle_code(); } else { logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "异常"); message = "申请捆扎电气设备任务号:" + task + "异常"; return; -// throw new RuntimeException("任务号为空!"); } if (StrUtil.isEmpty(vehicle_code)) { logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "未找到载具号"); message = "申请捆扎电气设备任务号:" + task + "未找到载具号"; return; -// throw new RuntimeException("载具号为空!"); } ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = new ApplyLabelingAndBindingRequest(); -// JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); StorageCell storageCell = new LambdaQueryChainWrapper<>(storageCellMapper) .eq(StorageCell::getStorage_code, this.device_code) .one(); String start_point_code = null; if (!ObjectUtil.isEmpty(storageCell)) { -// start_point_code = (String) device_json.get("parent_storage_code") == null ? this.device_code : (String) device_json.get("parent_storage_code"); start_point_code = (String) storageCell.getParent_storage_code() == null ? this.device_code : (String) storageCell.getParent_storage_code(); } applyLabelingAndBindingRequest.setDevice_code(start_point_code); diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/finished_product_out_with_bind_lable_conveyor/FinishedProductOutBindLableConveyorDefination.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/finished_product_out_with_bind_lable_conveyor/FinishedProductOutBindLableConveyorDefination.java index 264665037..368f69b3f 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/finished_product_out_with_bind_lable_conveyor/FinishedProductOutBindLableConveyorDefination.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/finished_product_out_with_bind_lable_conveyor/FinishedProductOutBindLableConveyorDefination.java @@ -46,7 +46,7 @@ public class FinishedProductOutBindLableConveyorDefination implements OpcDeviceD @Override public List getFitDeviceTypes() { List types = new LinkedList(); - types.add(DeviceType.station); + types.add(DeviceType.conveyor); return types; } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/finished_product_out_with_bind_lable_conveyor/FinishedProductOutBindLableDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/finished_product_out_with_bind_lable_conveyor/FinishedProductOutBindLableDeviceDriver.java index 2244fd103..9159cdb3d 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/finished_product_out_with_bind_lable_conveyor/FinishedProductOutBindLableDeviceDriver.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/finished_product_out_with_bind_lable_conveyor/FinishedProductOutBindLableDeviceDriver.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -17,6 +18,9 @@ import org.nl.acs.device_driver.FeedLmsRealFailed; 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.enums.AcsToLmsApplyTaskTypeEnum; +import org.nl.acs.ext.wms.data.one.ApplyLabelingAndBindingRequest; +import org.nl.acs.ext.wms.data.one.ApplyLabelingAndBindingResponse; import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.history.ErrorUtil; import org.nl.acs.history.service.DeviceErrorLogService; @@ -28,6 +32,8 @@ import org.nl.acs.monitor.DeviceStageMonitor; import org.nl.acs.opc.DeviceAppService; import org.nl.acs.route.service.RouteLineService; import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.storage_cell.domain.StorageCell; +import org.nl.acs.storage_cell.service.mapper.StorageCellMapper; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; import org.nl.config.SpringContextHolder; @@ -70,6 +76,8 @@ public class FinishedProductOutBindLableDeviceDriver extends AbstractOpcDeviceDr //当前指令 Instruction inst = null; + private StorageCellMapper storageCellMapper; + private String error_type = "ssx_error_type"; //工作模式 @@ -172,37 +180,6 @@ public class FinishedProductOutBindLableDeviceDriver extends AbstractOpcDeviceDr - if (to_length != last_to_length) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_length:" + last_to_length + "->" + to_length); - } - if (to_weight != last_to_weight) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_weight:" + last_to_weight + "->" + to_weight); - } - if (to_height != last_to_height) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_height:" + last_to_height + "->" + to_height); - } - if (to_command != last_to_command) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); - } - if (to_target != last_to_target) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); - } - if (to_task != last_to_task) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); - } - if (mode != last_mode) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode + "复位请求标记:" + requireSucess); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - - if (carrier_direction != last_carrier_direction) { - logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(carrier_direction)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号carrier_direction:" + last_carrier_direction + "->" + carrier_direction); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); - } if (move != 0 && task > 0) { @@ -241,6 +218,12 @@ public class FinishedProductOutBindLableDeviceDriver extends AbstractOpcDeviceDr instruction_require(); } break; + case 10: + //申请捆轧贴标信息 + if (move > 0 && !requireSucess) { + applyLaStrangulationAndLabeling(); + } + break; } } last_mode = mode; @@ -258,6 +241,131 @@ public class FinishedProductOutBindLableDeviceDriver extends AbstractOpcDeviceDr last_to_height = to_height; } + private void applyLaStrangulationAndLabeling() { + Date date = new Date(); + if (date.getTime() - this.require_apply_strangulation_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + this.require_apply_strangulation_time = date; + String vehicle_code = ""; + if (task > 0) { + Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); + if (ObjectUtil.isEmpty(instruction)) { + message = "申请捆扎电气设备任务号:" + task + "未找到对应指令"; + return; + } + vehicle_code = instruction.getVehicle_code(); + } else { + logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "异常"); + message = "申请捆扎电气设备任务号:" + task + "异常"; + return; + } + if (StrUtil.isEmpty(vehicle_code)) { + logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "未找到载具号"); + message = "申请捆扎电气设备任务号:" + task + "未找到载具号"; + return; + } + ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = + new ApplyLabelingAndBindingRequest(); + StorageCell storageCell = new LambdaQueryChainWrapper<>(storageCellMapper) + .eq(StorageCell::getStorage_code, this.device_code) + .one(); + String start_point_code = null; + if (!ObjectUtil.isEmpty(storageCell)) { + start_point_code = (String) storageCell.getParent_storage_code() == null ? this.device_code : (String) storageCell.getParent_storage_code(); + } + applyLabelingAndBindingRequest.setDevice_code(start_point_code); + applyLabelingAndBindingRequest.setType(AcsToLmsApplyTaskTypeEnum.LABEL_BIND.getType()); + applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); + ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); + if (applyLabelingAndBindingResponse.getstatus() == 200) { + if (ObjectUtil.isNotEmpty(applyLabelingAndBindingResponse.getData())) { + Map datas = applyLabelingAndBindingResponse.getData(); + packagePLCData(datas); + message = "申请捆扎成功"; + requireSucess = true; + } else { + message = "未返回尺寸信息"; + } + + } else { + message = applyLabelingAndBindingResponse.getMessage(); + } + + } + } + + private void packagePLCData(Map datas) { + String length = datas.get("length").toString(); + String weight = datas.get("weight").toString(); + String height = datas.get("height").toString(); + String isBinding = datas.get("isBinding").toString(); + String isLabeling = datas.get("isLabeling").toString(); + String printQty = datas.get("printQty").toString(); + String labelingTemplate = datas.get("labelingTemplate").toString(); + String bindingTemplate = datas.get("bindingTemplate").toString(); + String printDevice = datas.get("printDevice").toString(); + String bundleTimes = datas.get("bundleTimes").toString(); + + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_length"); + map.put("value", length); + list.add(map); + Map map2 = new HashMap(); + map2.put("code", "to_weight"); + map2.put("value", weight); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_height"); + map3.put("value", height); + list.add(map3); + Map map4 = new HashMap(); + map4.put("code", "to_is_binding"); + map4.put("value", isBinding); + list.add(map4); + Map map5 = new HashMap(); + map5.put("code", "to_command"); + map5.put("value", "10"); + list.add(map5); + Map map6 = new HashMap(); + map6.put("code", "to_is_labeling"); + map6.put("value", isLabeling); + list.add(map6); + Map map7 = new HashMap(); + map7.put("code", "to_print_qty"); + map7.put("value", printQty); + list.add(map7); + Map map8 = new HashMap(); + map8.put("code", "to_print_qty"); + map8.put("value", printQty); + list.add(map8); + Map map9 = new HashMap(); + map9.put("code", "to_print_device"); + map9.put("value", printDevice); + list.add(map9); + Map map10 = new HashMap(); + map10.put("code", "to_binding_template"); + map10.put("value", bindingTemplate); + list.add(map10); + Map map11 = new HashMap(); + map11.put("code", "to_binding_times"); + map11.put("value", bundleTimes); + list.add(map11); + Map map12 = new HashMap(); + map12.put("code", "to_labeling_template"); + map12.put("value", labelingTemplate); + list.add(map12); + try { + this.writing(list); + } catch (Exception e) { + message = "写入信号失败"; + } + this.setRequireSucess(true); + + } + public boolean exe_error() { if (this.error == 0) { diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/un_box_lable_conveyor/UnBoxLableConveyorDefination.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/un_box_lable_conveyor/UnBoxLableConveyorDefination.java index d3400ee22..5e5a5b340 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/un_box_lable_conveyor/UnBoxLableConveyorDefination.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_conveyor/un_box_lable_conveyor/UnBoxLableConveyorDefination.java @@ -45,7 +45,7 @@ public class UnBoxLableConveyorDefination implements OpcDeviceDriverDefination { @Override public List getFitDeviceTypes() { List types = new LinkedList(); - types.add(DeviceType.station); + types.add(DeviceType.conveyor); return types; } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDeviceDriver.java index 28bcbb5ef..0074079b9 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDeviceDriver.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDeviceDriver.java @@ -359,34 +359,34 @@ public class BoxStorageManipulatorDeviceDriver extends AbstractOpcDeviceDriver i map4.put("code", "to_task"); map4.put("value", instdto.getInstruction_code()); list.add(map4); - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getTo_weight())) { + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getWeight())) { Map map5 = new HashMap<>(); map5.put("code", "to_weight"); - map5.put("value", interactionJsonDTO.getTo_weight()); + map5.put("value", interactionJsonDTO.getWeight()); list.add(map5); } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getTo_length())) { + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getLength())) { Map map6 = new HashMap<>(); map6.put("code", "to_length"); - map6.put("value", interactionJsonDTO.getTo_length()); + map6.put("value", interactionJsonDTO.getLength()); list.add(map6); } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getTo_height())) { + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getHeight())) { Map map7 = new HashMap<>(); map7.put("code", "to_height"); - map7.put("value", interactionJsonDTO.getTo_height()); + map7.put("value", interactionJsonDTO.getHeight()); list.add(map7); } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getTo_barcode())) { + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getBarcode())) { Map map8 = new HashMap<>(); map8.put("code", "to_barcode"); - map8.put("value", interactionJsonDTO.getTo_barcode()); + map8.put("value", interactionJsonDTO.getBarcode()); list.add(map8); } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getTo_layer())) { + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getLayer())) { Map map9 = new HashMap<>(); map9.put("code", "to_layer"); - map9.put("value", interactionJsonDTO.getTo_layer()); + map9.put("value", interactionJsonDTO.getLayer()); list.add(map9); } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/InteractionJsonDTO.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/InteractionJsonDTO.java index 60a6369d7..d791018fb 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/InteractionJsonDTO.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/InteractionJsonDTO.java @@ -8,24 +8,24 @@ public class InteractionJsonDTO { /** *木箱长度 */ - private String to_length; + private String length; /** *木箱宽度 */ - private String to_weight; + private String weight; /** *木箱高度 */ - private String to_height; + private String height; /** *下发木箱条码 */ - private String to_barcode; + private String barcode; /** *下发木箱层数 */ - private String to_layer; + private String layer; } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/InteractionJsonDTO.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/InteractionJsonDTO.java new file mode 100644 index 000000000..d5a90e47a --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/InteractionJsonDTO.java @@ -0,0 +1,31 @@ +package org.nl.acs.device_driver.one_manipulator.return_good_manipulator; + +import lombok.Data; + +@Data +public class InteractionJsonDTO { + + /** + *木箱长度 + */ + private String length; + /** + *木箱宽度 + */ + private String weight; + /** + *木箱高度 + */ + private String height; + + /** + *下发木箱条码 + */ + private String barcode; + + /** + *下发托盘类型 + */ + private String containerType; + +} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDeviceDriver.java index e3971b5ad..98604f505 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDeviceDriver.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDeviceDriver.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.RequiredArgsConstructor; @@ -23,6 +24,7 @@ import org.nl.acs.history.ErrorUtil; import org.nl.acs.history.service.DeviceErrorLogService; import org.nl.acs.history.service.impl.DeviceErrorLogServiceImpl; import org.nl.acs.instruction.domain.Instruction; +import org.nl.acs.instruction.enums.InstructionStatusEnum; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.monitor.DeviceStageMonitor; @@ -150,41 +152,6 @@ public class ReturnGoodManipulatorDeviceDriver extends AbstractOpcDeviceDriver i to_target = this.itemProtocol.getTo_target(); to_onset = this.itemProtocol.getTo_onset(); to_task = this.itemProtocol.getTo_task(); - if (mode != last_mode) { - requireSucess = false; - logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - if (move != last_move) { - logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); - } - if (action != last_action) { - logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); - } - if (task != last_task) { - logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); - } - if (to_command != last_to_command) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); - } - if (to_target != last_to_target) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); - } - if (to_onset != last_to_onset) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_onset:" + last_to_target + "->" + to_target); - } - if (to_task != last_to_task) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); - } - - // 更新指令状态 if (mode == 3 && task > 0) { updateInstructionStatus(); @@ -265,12 +232,49 @@ public class ReturnGoodManipulatorDeviceDriver extends AbstractOpcDeviceDriver i Instruction inst = checkInst(); if (inst != null) { if (StrUtil.equals(inst.getInstruction_status(), "0")) { - inst.setInstruction_status(CommonFinalParam.ONE); + inst.setInstruction_status(InstructionStatusEnum.BUSY.getIndex()); inst.setExecute_device_code(this.device_code); instructionService.update(inst); } } + + //放货完成 + if (action == 4 && move == 0) { + if (inst != null) { + try { + logServer.deviceExecuteLog(this.device_code, "", "", "放货完成"); + finish_instruction(inst); + Map map1 = new HashMap<>(); + List list = new ArrayList(); + map1.put("code", "to_command"); + map1.put("value", 5); + list.add(map1); + this.writing(list); + message = "放货完成"; + } catch (Exception e) { + message = "放货失败"; + e.printStackTrace(); + } + feedMessage = ""; + } else { + feedMessage = "行架机械手:"; + if (mode != 3) { + feedMessage = feedMessage + "工作模式(mode)不为运行中状态,"; + } + if (action != 5) { + feedMessage = feedMessage + "动作信号(action)不为放货完成状态,"; + } + if (move != 0) { + feedMessage = feedMessage + "光电信号(move)不为无货状态,"; + } + if (task == 0) { + feedMessage = feedMessage + "当前上报任务号(task)不应该为0。"; + } + } + } } + + } } @@ -281,93 +285,159 @@ public class ReturnGoodManipulatorDeviceDriver extends AbstractOpcDeviceDriver i return false; } else { this.instruction_require_time = date; - BoxStorageOutConveyorDeviceDriver boxStorageConveyorDeviceDriver = new BoxStorageOutConveyorDeviceDriver(); - String deviceCode = boxStorageConveyorDeviceDriver.getDevice_code(); - TaskDto taskDto = taskserver.findByEndCodeAndReady(deviceCode); - if (ObjectUtil.isNotEmpty(taskDto)) { - String start_device_code = taskDto.getStart_device_code(); - String next_device_code = taskDto.getNext_device_code(); - Device startDevice = deviceAppService.findDeviceByCode(start_device_code); - Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); - String start_addr = startDevice.getExtraValue().get("address").toString(); - String next_addr = nextDevice.getExtraValue().get("address").toString(); - String taskid = taskDto.getTask_id(); - String taskcode = taskDto.getTask_code(); - String start_point_code = taskDto.getStart_point_code(); - String route_plan_code = taskDto.getRoute_plan_code(); - String next_point_code = taskDto.getNext_point_code(); - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(device_code); + //抓取工位 + if (ObjectUtil.isEmpty(getDeviceCodeList)) { + getDeviceCodeList = this.getExtraDeviceCodes("get_device_code"); + } + //放货工位 + if (ObjectUtil.isEmpty(putDeviceCodeList)) { + putDeviceCodeList = this.getExtraDeviceCodes("put_device_code"); + } + //找终点为入库输送线工位任务类型为行架的任务 + for (int i = 0; i < getDeviceCodeList.size(); i++) { + String startDeviceCode = getDeviceCodeList.get(i); + TaskDto taskDto = taskserver.findByStartCodeAndReady(startDeviceCode); + if (ObjectUtil.isNotEmpty(taskDto) && TaskTypeEnum.Truss_Task.getIndex().equals(taskDto.getTask_type())) { + String interactionJson = taskDto.getInteraction_json(); + InteractionJsonDTO interactionJsonDTO = JSON.parseObject(interactionJson, InteractionJsonDTO.class); + String start_device_code = taskDto.getStart_device_code(); + String next_device_code = taskDto.getNext_device_code(); + Device startDevice = deviceAppService.findDeviceByCode(start_device_code); + Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); + String start_addr = startDevice.getExtraValue().get("address").toString(); + String next_addr = nextDevice.getExtraValue().get("address").toString(); + String taskid = taskDto.getTask_id(); + String taskcode = taskDto.getTask_code(); + String start_point_code = taskDto.getStart_point_code(); + String route_plan_code = taskDto.getRoute_plan_code(); + String next_point_code = taskDto.getNext_point_code(); + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(device_code); - try { - instructionService.create(instdto); - } catch (Exception e) { - notCreateInstMessage = e.getMessage(); - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); - return false; - } - logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" - + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() - + ",指令终点:" + instdto.getNext_device_code() ); - - - Map map = new LinkedHashMap<>(); - map.put("to_command", 1); - map.put("to_target", next_addr); - map.put("to_onset", start_addr); - map.put("to_task", instdto.getInstruction_code()); - - - - try { - this.writing(map); - } catch (Exception e) { + try { + instructionService.create(instdto); + } catch (Exception e) { + notCreateInstMessage = e.getMessage(); + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); + return false; + } logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() - + ",指令终点:" + instdto.getNext_device_code() + ",指令执行失败:" + e.getMessage()); + + ",指令终点:" + instdto.getNext_device_code() + ",交互参数:" + interactionJsonDTO.toString()); + //创建指令后修改任务状态 + taskDto.setTask_status("1"); + taskserver.update(taskDto); + requireSucess = true; + + Map map1 = new HashMap<>(); + List list = new ArrayList(); + map1.put("code", "to_command"); + map1.put("value", 1); + list.add(map1); + Map map2 = new HashMap<>(); + map2.put("code", "to_target"); + map2.put("value", next_addr); + list.add(map2); + Map map3 = new HashMap<>(); + map3.put("code", "to_onset"); + map3.put("value", start_addr); + list.add(map3); + Map map4 = new HashMap<>(); + map4.put("code", "to_task"); + map4.put("value", instdto.getInstruction_code()); + list.add(map4); + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getWeight())) { + Map map5 = new HashMap<>(); + map5.put("code", "to_weight"); + map5.put("value", interactionJsonDTO.getWeight()); + list.add(map5); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getLength())) { + Map map6 = new HashMap<>(); + map6.put("code", "to_length"); + map6.put("value", interactionJsonDTO.getLength()); + list.add(map6); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getHeight())) { + Map map7 = new HashMap<>(); + map7.put("code", "to_height"); + map7.put("value", interactionJsonDTO.getHeight()); + list.add(map7); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getBarcode())) { + Map map8 = new HashMap<>(); + map8.put("code", "to_barcode"); + map8.put("value", interactionJsonDTO.getBarcode()); + list.add(map8); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getContainerType())) { + Map map9 = new HashMap<>(); + map9.put("code", "to_container_type"); + map9.put("value", interactionJsonDTO.getContainerType()); + list.add(map9); + } + + try { + this.writing(list); + } catch (Exception e) { + logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() + + ",指令终点:" + instdto.getNext_device_code() + ",交互参数:" + interactionJsonDTO.toString() + ",指令执行失败:" + e.getMessage()); + } + this.setRequireSucess(true); + return true; + }else{ + notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; } - this.setRequireSucess(true); - return true; - } else { - notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; } return true; } - } /** * 下发 - * @param map + * @param list */ - public void writing(Map map) { - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - Map itemMap = new LinkedHashMap<>(); - map.forEach((key, value) -> { - if (ObjectUtil.isNotEmpty(value)) { - itemMap.put(getToParam() + key, value); + public void writing(List list) { + + Map itemMap = new HashMap(); + for (int i = 0; i < list.size(); i++) { + Object ob = list.get(i); + JSONObject json = (JSONObject) JSONObject.toJSON(ob); + if (!StrUtil.isEmpty(json.getString("value"))) { + String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + json.getString("code"); + itemMap.put(to_param, json.getString("value")); } - }); - if (ObjectUtil.isNotEmpty(itemMap)) { + } + logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); + try { + this.checkcontrol(itemMap); + } catch (Exception e) { + e.printStackTrace(); try { this.checkcontrol(itemMap); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (Exception e1) { + e1.printStackTrace(); } - logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); } + + } + + + public synchronized boolean finish_instruction(Instruction inst) throws Exception { + instructionService.finish(inst); + return true; } /** diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/InteractionJsonDTO.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/InteractionJsonDTO.java index d9feac1f8..a83144b2c 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/InteractionJsonDTO.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/InteractionJsonDTO.java @@ -8,20 +8,23 @@ public class InteractionJsonDTO { /** *木箱长度 */ - private String item_to_length = "to_length"; + private String length; /** *木箱宽度 */ - private String item_to_weight = "to_weight"; + private String weight; /** *木箱高度 */ - private String item_to_height = "to_height"; + private String height; /** *下发堆叠模板 */ - private String item_to_template = "to_template"; - + private String template; + /** + *是否是最后一个 + */ + private String isLastOne; } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorDefination.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorDefination.java index b6365b2d1..9bfeb0868 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorDefination.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorDefination.java @@ -19,12 +19,12 @@ public class TrappedManipulatorDefination implements OpcDeviceDriverDefination { @Override public String getDriverName() { - return "捆扎智能行架"; + return "堆叠行架"; } @Override public String getDriverDescription() { - return "捆扎智能行架"; + return "堆叠行架"; } @Override diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorManipulatorDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorManipulatorDeviceDriver.java index 0d4b8cae1..a5eeeffd9 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorManipulatorDeviceDriver.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorManipulatorDeviceDriver.java @@ -35,10 +35,7 @@ import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; import org.nl.config.SpringContextHolder; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * 捆扎智能行架 @@ -153,40 +150,6 @@ public class TrappedManipulatorManipulatorDeviceDriver extends AbstractOpcDevice to_target = this.itemProtocol.getTo_target(); to_onset = this.itemProtocol.getTo_onset(); to_task = this.itemProtocol.getTo_task(); - if (mode != last_mode) { - requireSucess = false; - logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - if (move != last_move) { - logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); - } - if (action != last_action) { - logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); - } - if (task != last_task) { - logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); - } - if (to_command != last_to_command) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); - } - if (to_target != last_to_target) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); - } - if (to_onset != last_to_onset) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_onset:" + last_to_target + "->" + to_target); - } - if (to_task != last_to_task) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); - } - // 更新指令状态 if (mode == 3 && task > 0) { @@ -276,6 +239,41 @@ public class TrappedManipulatorManipulatorDeviceDriver extends AbstractOpcDevice } } } + + //放货完成 + if ( action == 4 && move == 0) { + if (inst != null) { + try { + logServer.deviceExecuteLog(this.device_code,"","","放货完成"); + finish_instruction(inst); + Map map1 = new HashMap<>(); + List list = new ArrayList(); + map1.put("code", "to_command"); + map1.put("value", 5); + list.add(map1); + this.writing(list); + message = "放货完成"; + } catch (Exception e) { + message = "放货失败"; + e.printStackTrace(); + } + feedMessage = ""; + }else { + feedMessage = "行架机械手:"; + if (mode != 3) { + feedMessage = feedMessage + "工作模式(mode)不为运行中状态,"; + } + if (action != 8) { + feedMessage = feedMessage + "动作信号(action)不为放货完成状态,"; + } + if (move != 0) { + feedMessage = feedMessage + "光电信号(move)不为无货状态,"; + } + if (task == 0) { + feedMessage = feedMessage + "当前上报任务号(task)不应该为0。"; + } + } + } } } @@ -286,81 +284,119 @@ public class TrappedManipulatorManipulatorDeviceDriver extends AbstractOpcDevice return false; } else { this.instruction_require_time = date; + //抓取工位 + if (ObjectUtil.isEmpty(getDeviceCodeList)) { + getDeviceCodeList = this.getExtraDeviceCodes("get_device_code"); + } + //放货工位 + if (ObjectUtil.isEmpty(putDeviceCodeList)) { + putDeviceCodeList = this.getExtraDeviceCodes("put_device_code"); + } + //找终点为入库输送线工位任务类型为行架的任务 + for (int i = 0; i < getDeviceCodeList.size(); i++) { + String startDeviceCode = getDeviceCodeList.get(i); + TaskDto taskDto = taskserver.findByStartCodeAndReady(startDeviceCode); + if (ObjectUtil.isNotEmpty(taskDto) && TaskTypeEnum.Truss_Task.getIndex().equals(taskDto.getTask_type())) { + String interactionJson = taskDto.getInteraction_json(); + InteractionJsonDTO interactionJsonDTO = JSON.parseObject(interactionJson, InteractionJsonDTO.class); + String start_device_code = taskDto.getStart_device_code(); + String next_device_code = taskDto.getNext_device_code(); + Device startDevice = deviceAppService.findDeviceByCode(start_device_code); + Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); + String start_addr = startDevice.getExtraValue().get("address").toString(); + String next_addr = nextDevice.getExtraValue().get("address").toString(); + String taskid = taskDto.getTask_id(); + String taskcode = taskDto.getTask_code(); + String start_point_code = taskDto.getStart_point_code(); + String route_plan_code = taskDto.getRoute_plan_code(); + String next_point_code = taskDto.getNext_point_code(); + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(device_code); - BoxManipulatorSiteDeviceDriver boxManipulatorSiteDeviceDriver = new BoxManipulatorSiteDeviceDriver(); - String deviceCode = boxManipulatorSiteDeviceDriver.getDevice_code(); - TaskDto taskDto = taskserver.findByEndCodeAndReady(deviceCode); - String interactionJson = taskDto.getInteraction_json(); - InteractionJsonDTO interactionJsonDTO = JSON.parseObject(interactionJson, InteractionJsonDTO.class); - if (ObjectUtil.isNotEmpty(taskDto)) { - String start_device_code = taskDto.getStart_device_code(); - String next_device_code = taskDto.getNext_device_code(); - Device startDevice = deviceAppService.findDeviceByCode(start_device_code); - Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); - String start_addr = startDevice.getExtraValue().get("address").toString(); - String next_addr = nextDevice.getExtraValue().get("address").toString(); - String taskid = taskDto.getTask_id(); - String taskcode = taskDto.getTask_code(); - String start_point_code = taskDto.getStart_point_code(); - String route_plan_code = taskDto.getRoute_plan_code(); - String next_point_code = taskDto.getNext_point_code(); - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(device_code); - - try { - instructionService.create(instdto); - } catch (Exception e) { - notCreateInstMessage = e.getMessage(); - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); - return false; - } - logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" - + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() - + ",指令终点:" + instdto.getNext_device_code() ); - - - Map map = new LinkedHashMap<>(); - map.put("to_command", 1); - map.put("to_target", next_addr); - map.put("to_onset", start_addr); - map.put("to_task", instdto.getInstruction_code()); - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_weight())) { - map.put("to_wedth", interactionJsonDTO.getItem_to_weight()); - } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_length())) { - map.put("to_length", interactionJsonDTO.getItem_to_length()); - } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_height())) { - map.put("to_height", interactionJsonDTO.getItem_to_height()); - } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_template())) { - map.put("to_template", interactionJsonDTO.getItem_to_template()); - } - - - try { - this.writing(map); - } catch (Exception e) { + try { + instructionService.create(instdto); + } catch (Exception e) { + notCreateInstMessage = e.getMessage(); + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); + return false; + } logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() - + ",指令终点:" + instdto.getNext_device_code() + ",指令执行失败:" + e.getMessage()); + + ",指令终点:" + instdto.getNext_device_code() + ",交互参数:" + interactionJsonDTO.toString()); + //创建指令后修改任务状态 + taskDto.setTask_status("1"); + taskserver.update(taskDto); + requireSucess = true; + + Map map1 = new HashMap<>(); + List list = new ArrayList(); + map1.put("code", "to_command"); + map1.put("value", 1); + list.add(map1); + Map map2 = new HashMap<>(); + map2.put("code", "to_target"); + map2.put("value", next_addr); + list.add(map2); + Map map3 = new HashMap<>(); + map3.put("code", "to_onset"); + map3.put("value", start_addr); + list.add(map3); + Map map4 = new HashMap<>(); + map4.put("code", "to_task"); + map4.put("value", instdto.getInstruction_code()); + list.add(map4); + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getWeight())) { + Map map5 = new HashMap<>(); + map5.put("code", "to_weight"); + map5.put("value", interactionJsonDTO.getWeight()); + list.add(map5); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getLength())) { + Map map6 = new HashMap<>(); + map6.put("code", "to_length"); + map6.put("value", interactionJsonDTO.getLength()); + list.add(map6); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getHeight())) { + Map map7 = new HashMap<>(); + map7.put("code", "to_height"); + map7.put("value", interactionJsonDTO.getHeight()); + list.add(map7); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getTemplate())) { + Map map8 = new HashMap<>(); + map8.put("code", "to_template"); + map8.put("value", interactionJsonDTO.getTemplate()); + list.add(map8); + } + if (ObjectUtil.isNotEmpty(interactionJsonDTO.getTemplate())) { + Map map9 = new HashMap<>(); + map9.put("code", "to_last_one"); + map9.put("value", interactionJsonDTO.getIsLastOne()); + list.add(map9); + } + try { + this.writing(list); + } catch (Exception e) { + logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" + + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() + + ",指令终点:" + instdto.getNext_device_code() + ",交互参数:" + interactionJsonDTO.toString() + ",指令执行失败:" + e.getMessage()); + } + this.setRequireSucess(true); + return true; + }else{ + notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; } - this.setRequireSucess(true); - return true; - } else { - notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; } return true; } @@ -368,25 +404,44 @@ public class TrappedManipulatorManipulatorDeviceDriver extends AbstractOpcDevice } /** - * 下发 - * @param map + * 完成指令 + * @param inst + * @return + * @throws Exception */ - public void writing(Map map) { - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - Map itemMap = new LinkedHashMap<>(); - map.forEach((key, value) -> { - if (ObjectUtil.isNotEmpty(value)) { - itemMap.put(getToParam() + key, value); + public synchronized boolean finish_instruction(Instruction inst) throws Exception { + instructionService.finish(inst); + return true; + } + + /** + * 下发信号 + * @param list + */ + public void writing(List list) { + + Map itemMap = new HashMap(); + for (int i = 0; i < list.size(); i++) { + Object ob = list.get(i); + JSONObject json = (JSONObject) JSONObject.toJSON(ob); + if (!StrUtil.isEmpty(json.getString("value"))) { + String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + json.getString("code"); + itemMap.put(to_param, json.getString("value")); } - }); - if (ObjectUtil.isNotEmpty(itemMap)) { + } + logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); + try { + this.checkcontrol(itemMap); + } catch (Exception e) { + e.printStackTrace(); try { this.checkcontrol(itemMap); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (Exception e1) { + e1.printStackTrace(); } - logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); } + } /** diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/enums/AcsToLmsApplyTaskTypeEnum.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/enums/AcsToLmsApplyTaskTypeEnum.java new file mode 100644 index 000000000..54f94586f --- /dev/null +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/enums/AcsToLmsApplyTaskTypeEnum.java @@ -0,0 +1,20 @@ +package org.nl.acs.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum AcsToLmsApplyTaskTypeEnum { + LABEL_BIND("1", "捆轧贴标"), + + AGV("2", "AGV任务"); + /** + * 索引 + */ + private String type; + /** + * 编码 + */ + private String value; +} diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/data/one/ApplyLabelingAndBindingRequest.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/data/one/ApplyLabelingAndBindingRequest.java index ccf915279..d058547b1 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/data/one/ApplyLabelingAndBindingRequest.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/data/one/ApplyLabelingAndBindingRequest.java @@ -7,9 +7,9 @@ public class ApplyLabelingAndBindingRequest extends BaseRequest { private String vehicle_code; private String device_code; /** - * 1:贴标申请 - * 2:捆扎申请 - * 3:烘箱 + * 1:贴标、捆扎申请 + * 2:烘箱 + * */ private String type; diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java index 05aae6684..1677c462f 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java @@ -12,12 +12,7 @@ import org.nl.acs.instruction.domain.Instruction; public interface AcsToWmsService { - /** - * ACS向WMS申请任务 - * @param jo - * @return - */ - String applyTaskToWms(JSONObject jo); + /** * 向WMS反馈任务状态 @@ -97,10 +92,8 @@ public interface AcsToWmsService { /** * ACS向WMS申请任务 - * @param request - * @return */ - String applyTask(BaseRequest request); + String applyTaskToWms(JSONObject jo); /** * ACS向WMS反馈任务状态 diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java index 196075548..0e3cb2320 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java @@ -64,7 +64,40 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { @Override public String applyTaskToWms(JSONObject jo) { - return null; + try { + MDC.put(log_file_type, log_type); + log.info("applyTaskToWms-----输入参数{}", jo); + String wmsurl = paramService.findByCode(AcsConfig.WMSURL).getValue(); + AddressDto addressDto = addressService.findByCode("applyTaskToWms"); + String url = wmsurl + addressDto.getMethods_url(); + HttpResponse result2 = null; + try { + result2 = HttpRequest.post(url) + .header("Authorization", token) + .body(String.valueOf(jo)) + .execute(); + } catch (Exception e) { + String msg = e.getMessage(); + log.info("applyTaskToWms-----输出参数{}", msg); + //网络不通 + } + if(ObjectUtil.isEmpty(result2)){ + log.info("applyTaskToWms-----输出参数{}", "返回结果为空"); + return null; + } + String type = ""; + if (result2.getStatus() == 200) { + type = "info"; + } else { + type = "error"; + } + log.info("applyTaskToWms-----输出参数{}", result2.body()); + return result2.body(); + + } finally { + MDC.remove(log_file_type); + } + } @Override @@ -112,10 +145,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { return null; } - @Override - public String applyTask(BaseRequest request) { - return null; - } + @Override