From 3cbef8a0504a45ebfba60b60c6c7a18075258128 Mon Sep 17 00:00:00 2001 From: liyongde <1419499670@qq.com> Date: Tue, 6 Oct 2026 22:48:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A3=85=E7=AE=B1=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BoxPackingInManipulatorDeviceDriver.java | 63 ++++++++++++------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/manipulator/box_packing_in_manipulator/BoxPackingInManipulatorDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/manipulator/box_packing_in_manipulator/BoxPackingInManipulatorDeviceDriver.java index 78b8540..3aa8466 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/manipulator/box_packing_in_manipulator/BoxPackingInManipulatorDeviceDriver.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/deviceDriver/service/defination/opcDefination/one_floor/manipulator/box_packing_in_manipulator/BoxPackingInManipulatorDeviceDriver.java @@ -30,6 +30,7 @@ import com.google.common.util.concurrent.Uninterruptibles; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; @Slf4j @Getter @@ -155,6 +156,8 @@ public class BoxPackingInManipulatorDeviceDriver extends AbstractOpcDeviceDriver * 抓取工位 */ private List getDeviceCodeList; + // 放置工位 + List putDeviceCodeList = null; /** * 请求时间 @@ -262,36 +265,52 @@ public class BoxPackingInManipulatorDeviceDriver extends AbstractOpcDeviceDriver log.trace("触发时间因为小于{}毫秒,而被无视", this.requireTimeOut); } else { this.requireTime = currentTimeMillis; + // 判断task是不是存在 + Instruction codeFromCache = instructionService.findByCodeFromCache(String.valueOf(task)); + if (ObjectUtil.isNotEmpty(codeFromCache)) { + message = "当前任务正在执行中....."; + return; + } + + //抓取工位 if (ObjectUtil.isEmpty(getDeviceCodeList)) { getDeviceCodeList = this.getExtraDeviceCodes("get_device_code"); } + //放货工位 + if (ObjectUtil.isEmpty(putDeviceCodeList)) { + putDeviceCodeList = this.getExtraDeviceCodes("put_device_code"); + } - for (String startDeviceCode : getDeviceCodeList) { - List tasks = taskService.queryTaskByDeviceCodeAndStatus2(startDeviceCode); - tasks.sort(Comparator.comparing(TaskDto::getCreate_time)); - if (CollUtil.isEmpty(tasks)) { - continue; + //找终点为入库输送线工位任务类型为行架的任务 + // 所有的指令 + List allReady = instructionService.findAllReady(); + // 过滤出起始设备为抓取工位且下一设备为放置工位的指令,按创建时间从早到晚排序 + List canSendList = allReady.stream() + .filter(instruction -> getDeviceCodeList.contains(instruction.getStart_device_code()) + && putDeviceCodeList.contains(instruction.getNext_device_code())) + .sorted(Comparator.comparing(Instruction::getCreate_time, + Comparator.nullsLast(Comparator.naturalOrder()))) + .collect(Collectors.toList()); + + if (!canSendList.isEmpty()) { + Instruction ins = canSendList.get(0); + String start_device_code = ins.getStart_device_code(); + String next_device_code = ins.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(); + TaskDto taskDto = taskService.findByCodeFromCache(ins.getTask_code()); + JSONObject extJson = JSONObject.parseObject(taskDto.getParam()); + if (ObjectUtil.isEmpty(start_addr)) { + throw new BadRequestException("设备:" + startDevice.getDevice_code() + "未设置电气调度号!"); } - - TaskDto taskDto = tasks.get(0); - if (!TaskTypeEnum.OUTBOUNDTASK.getIndex().equals(taskDto.getTask_type())) { - continue; + if (ObjectUtil.isEmpty(next_addr)) { + throw new BadRequestException("设备:" + nextDevice.getDevice_code() + "未设置电气调度号!"); } - - Instruction instruction = instructionService.findByCodeFromCache(taskDto.getTask_code()); - if (instruction == null) { - continue; - } - - Device startDevice = deviceAppService.findDeviceByCode(taskDto.getStart_point_code()); - Device nextDevice = deviceAppService.findDeviceByCode(taskDto.getNext_point_code()); - String startAddress = getDeviceAddress(startDevice); - String nextAddress = getDeviceAddress(nextDevice); - - doWriteSignal(startAddress, nextAddress, instruction, JSONObject.parseObject(taskDto.getParam())); + doWriteSignal(start_addr, next_addr, ins, extJson); message = "执行写入电气信号完毕!"; requireSuccess = true; - return; } } }