fix: 装箱入库驱动

This commit is contained in:
2026-10-06 22:48:54 +08:00
parent db802c6467
commit 3cbef8a050

View File

@@ -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<String> getDeviceCodeList;
// 放置工位
List<String> 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<TaskDto> tasks = taskService.queryTaskByDeviceCodeAndStatus2(startDeviceCode);
tasks.sort(Comparator.comparing(TaskDto::getCreate_time));
if (CollUtil.isEmpty(tasks)) {
continue;
//找终点为入库输送线工位任务类型为行架的任务
// 所有的指令
List<Instruction> allReady = instructionService.findAllReady();
// 过滤出起始设备为抓取工位且下一设备为放置工位的指令,按创建时间从早到晚排序
List<Instruction> 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;
}
}
}