opt:输送线优化

This commit is contained in:
2025-10-20 10:17:56 +08:00
parent d3ffbcc22b
commit 06b231328c
5 changed files with 122 additions and 40 deletions

View File

@@ -479,6 +479,7 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic
Map map1 = new HashMap();
map1.put("code", "to_command");
map1.put("value", "2");
list.add(map1);
Map map2 = new HashMap();
map2.put("code", "to_target");//目标楼层从wms下发的参数字段取
map2.put("value", task.getFloor_code());

View File

@@ -345,6 +345,11 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
Map map2 = new HashMap();
map2.put("code", "to_taskNum");//下发出库数
map2.put("value", result);
list1.add(map2);
Map map3 = new HashMap();
map3.put("code", "to_target");//下发出库楼层
map3.put("value", "0");
list1.add(map);
this.writing(list1);
// 只有成功后才设置标记
@@ -552,7 +557,7 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
}
return this.outbound_task_num;
}
/**
* 统一更新出库任务数的方法,确保数据一致性
* @param num 任务数

View File

@@ -30,6 +30,7 @@ import org.nl.acs.device.enums.DeviceType;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device.service.impl.DeviceServiceImpl;
import org.nl.acs.device_driver.DeviceDriverDefination;
import org.nl.acs.device_driver.conveyor.belt_conveyor.BeltConveyorDeviceDriver;
import org.nl.acs.ext.wms.liKuData.*;
import org.nl.acs.ext.wms.service.AcsToLiKuService;
import org.nl.acs.instruction.domain.InstructionMybatis;
@@ -121,6 +122,9 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
private LimitRegionalService limitRegionalService;
@Autowired
private LuceneExecuteLogService luceneExecuteLogService;
@Autowired
private DeviceAppService appService;
private List<Instruction> instructions = new CopyOnWriteArrayList();
@@ -391,6 +395,18 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
throw new BadRequestException(LangProcess.msg("error_regional_max"));
}
BeltConveyorDeviceDriver beltConveyorDeviceDriver;
Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code());
if (nextdevice.getDeviceDriver() instanceof BeltConveyorDeviceDriver) {
beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) nextdevice.getDeviceDriver();
if (beltConveyorDeviceDriver.getType() != 2) {
beltConveyorDeviceDriver.writing("to_command","7");
log.info("当前输送线出入库信号不为出库");
throw new BadRequestException("当前输送线出入库信号不为出库");
}
}
String start_device_code = dto.getStart_device_code();
if (StrUtil.isNotEmpty(dto.getTask_code())) {
List<InstructionMybatis> instructionMybatis = instructionMapper.selectList(Wrappers.lambdaQuery(InstructionMybatis.class)
@@ -477,6 +493,33 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
InstructionMybatis entity = ConvertUtil.convert(dto, InstructionMybatis.class);
instructionMapper.insert(entity);
instructions.add(dto);
if (nextdevice.getDeviceDriver() instanceof BeltConveyorDeviceDriver) {
beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) nextdevice.getDeviceDriver();
//满足出库,查询当前出库任务,+1后返回给
if (beltConveyorDeviceDriver.getAction() == 2 && beltConveyorDeviceDriver.getMode() == 2
&& beltConveyorDeviceDriver.getError() == 0 && beltConveyorDeviceDriver.getMove() == 0) {
// 使用同步块确保操作原子性
synchronized (beltConveyorDeviceDriver) {
try {
// 因为已经创建成功
int count = queryInstructionCount(dto.getNext_device_code());
// 使用统一更新方法不同步数据库由BeltConveyorDeviceDriver内部处理
beltConveyorDeviceDriver.updateAndSyncOutboundTaskNum(count, false, false);
beltConveyorDeviceDriver.writing("to_taskNum", count + "");
// 确保nextdevice也被更新
nextdevice.setOutbound_task_num(count);
} catch (Exception e) {
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code("更新出库任务数失败")
.content("设备: " + nextdevice.getDevice_code() + ", 错误: " + e.getMessage())
.build();
logDto.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto);
}
}
}
}
}
@@ -492,6 +535,18 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
throw new BadRequestException(LangProcess.msg("error_regional_max"));
}
BeltConveyorDeviceDriver beltConveyorDeviceDriver;
Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code());
if (nextdevice.getDeviceDriver() instanceof BeltConveyorDeviceDriver) {
beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) nextdevice.getDeviceDriver();
if (beltConveyorDeviceDriver.getType() != 2) {
beltConveyorDeviceDriver.writing("to_command","7");
log.info("当前输送线出入库信号不为出库");
throw new BadRequestException("当前输送线出入库信号不为出库");
}
}
String start_device_code = dto.getStart_device_code();
// if (StrUtil.isNotEmpty(dto.getTask_code())) {
// List<InstructionMybatis> instructionMybatis = instructionMapper.selectList(Wrappers.lambdaQuery(InstructionMybatis.class)
@@ -626,6 +681,34 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
InstructionMybatis entity = ConvertUtil.convert(dto, InstructionMybatis.class);
instructionMapper.insert(entity);
instructions.add(dto);
if (nextdevice.getDeviceDriver() instanceof BeltConveyorDeviceDriver) {
beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) nextdevice.getDeviceDriver();
//满足出库,查询当前出库任务,+1后返回给
if (beltConveyorDeviceDriver.getAction() == 2 && beltConveyorDeviceDriver.getMode() == 2
&& beltConveyorDeviceDriver.getError() == 0 && beltConveyorDeviceDriver.getMove() == 0) {
// 使用同步块确保操作原子性
synchronized (beltConveyorDeviceDriver) {
try {
// 因为已经创建成功
int count = queryInstructionCount(dto.getNext_device_code());
// 使用统一更新方法不同步数据库由BeltConveyorDeviceDriver内部处理
beltConveyorDeviceDriver.updateAndSyncOutboundTaskNum(count, false, false);
beltConveyorDeviceDriver.writing("to_taskNum", count + "");
// 确保nextdevice也被更新
nextdevice.setOutbound_task_num(count);
} catch (Exception e) {
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code("更新出库任务数失败")
.content("设备: " + nextdevice.getDevice_code() + ", 错误: " + e.getMessage())
.build();
logDto.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto);
}
}
}
}
}
@Override
@@ -1205,6 +1288,36 @@ public class InstructionServiceImpl extends CommonServiceImpl<InstructionMapper,
log.debug("地址对应设备未找到");
return;
}
BeltConveyorDeviceDriver beltConveyorDeviceDriver;
Device nextdevice = appService.findDeviceByCode(entity.getNext_device_code());
if (nextdevice.getDeviceDriver() instanceof BeltConveyorDeviceDriver) {
beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) nextdevice.getDeviceDriver();
//满足出库,查询当前出库任务,+1后返回给
if (beltConveyorDeviceDriver.getAction() == 2 && beltConveyorDeviceDriver.getMode() == 2
&& beltConveyorDeviceDriver.getError() == 0 && beltConveyorDeviceDriver.getMove() == 0) {
// 使用同步块确保操作原子性
synchronized (beltConveyorDeviceDriver) {
try {
// 因为已经创建成功
int count = queryInstructionCount(entity.getNext_device_code());
// 使用统一更新方法不同步数据库由BeltConveyorDeviceDriver内部处理
beltConveyorDeviceDriver.updateAndSyncOutboundTaskNum(count, false, false);
beltConveyorDeviceDriver.writing("to_taskNum", count + "");
// 确保nextdevice也被更新
nextdevice.setOutbound_task_num(count);
} catch (Exception e) {
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code("更新出库任务数失败")
.content("设备: " + nextdevice.getDevice_code() + ", 错误: " + e.getMessage())
.build();
logDto.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto);
}
}
}
}
// removeByCodeFromCache(entity.getInstruction_code());
}
// this.reload();

View File

@@ -1187,7 +1187,8 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
@Override
public TaskDto findByContainer(String container_code) {
Optional<TaskDto> optionalTask = tasks.stream()
.filter(task -> StrUtil.equals(task.getVehicle_code(), container_code))
.filter(task -> StrUtil.equals(task.getVehicle_code(), container_code)
&& (TaskStatusEnum.BUSY.getIndex().equals(task.getTask_status()) || TaskStatusEnum.READY.getIndex().equals(task.getTask_status())))
.findFirst();
return optionalTask.orElse(null);

View File

@@ -132,24 +132,12 @@ public class AutoCreateInst {
}
next_device_code = pathlist.get(index);
Device nextdevice = appService.findDeviceByCode(next_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;
}
BeltConveyorDeviceDriver beltConveyorDeviceDriver;
if (nextdevice.getDeviceDriver() instanceof BeltConveyorDeviceDriver) {
beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) nextdevice.getDeviceDriver();
if (beltConveyorDeviceDriver.getType() != 2) {
beltConveyorDeviceDriver.writing("to_command","7");
log.info("当前输送线出入库信号不为出库");
continue;
}
}
Instruction instdto = new Instruction();
instdto.setInstruction_type(task_type);
instdto.setInstruction_id(IdUtil.simpleUUID());
@@ -198,32 +186,6 @@ public class AutoCreateInst {
try {
instructionService.create(instdto);
if (nextdevice.getDeviceDriver() instanceof BeltConveyorDeviceDriver) {
beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) nextdevice.getDeviceDriver();
//满足出库,查询当前出库任务,+1后返回给
if (beltConveyorDeviceDriver.getAction() == 2 && beltConveyorDeviceDriver.getMode() == 2
&& beltConveyorDeviceDriver.getError() == 0 && beltConveyorDeviceDriver.getMove() == 0) {
// 使用同步块确保操作原子性
synchronized (beltConveyorDeviceDriver) {
try {
// 因为已经创建成功
int count = instructionService.queryInstructionCount(next_device_code);
// 使用统一更新方法不同步数据库由BeltConveyorDeviceDriver内部处理
beltConveyorDeviceDriver.updateAndSyncOutboundTaskNum(count, false, false);
beltConveyorDeviceDriver.writing("to_taskNum", count + "");
// 确保nextdevice也被更新
nextdevice.setOutbound_task_num(count);
} catch (Exception e) {
LuceneLogDto logDto = LuceneLogDto.builder()
.device_code("更新出库任务数失败")
.content("设备: " + nextdevice.getDevice_code() + ", 错误: " + e.getMessage())
.build();
logDto.setLog_level(4);
luceneExecuteLogService.deviceExecuteLog(logDto);
}
}
}
}
} catch (Exception e) {
acsTask.setRemark(e.getMessage());
taskserver.updateByCodeFromCache(acsTask);