fix: 堆垛机对接位通过补码生成到货架的任务

This commit is contained in:
2024-04-18 15:02:28 +08:00
parent 8fd37373e4
commit 77cbfe46f5
4 changed files with 119 additions and 46 deletions

View File

@@ -80,7 +80,7 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
@Autowired @Autowired
DeviceErrorLogService errorLogServer = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class); DeviceErrorLogService errorLogServer = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class);
LuceneExecuteLogService luceneExecuteLogService = SpringContextHolder.getBean("luceneExecuteLogServiceImpl"); LuceneExecuteLogService luceneExecuteLogService = SpringContextHolder.getBean("luceneExecuteLogServiceImpl");
ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class); ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class);
@@ -92,47 +92,47 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
private Date instruction_apply_time = new Date(); private Date instruction_apply_time = new Date();
private int instruction_require_time_out = 3000; private int instruction_require_time_out = 3000;
/** /**
* 心跳 * 心跳
*/ */
int heartbeat = 0; int heartbeat = 0;
int last_heartbeat = 0; int last_heartbeat = 0;
/** /**
* 工作模式 * 工作模式
*/ */
int mode = 0; int mode = 0;
int last_mode = 0; int last_mode = 0;
/** /**
* 光电信号 * 光电信号
*/ */
int move = 0; int move = 0;
int last_move = 0; int last_move = 0;
/** /**
* 托盘方向 * 托盘方向
*/ */
int container_direction = 0; int container_direction = 0;
int last_container_direction = 0; int last_container_direction = 0;
/** /**
* 报警 * 报警
*/ */
int error = 0; int error = 0;
int last_error = 0; int last_error = 0;
/** /**
* 动作信号 * 动作信号
*/ */
int action = 0; int action = 0;
int last_action = 0; int last_action = 0;
/** /**
* 任务号 * 任务号
*/ */
int task = 0; int task = 0;
int last_task = 0; int last_task = 0;
/** /**
* 托盘类型 * 托盘类型
*/ */
int container_type = 0; int container_type = 0;
int last_container_type = 0; int last_container_type = 0;
/** /**
* 纯数字托盘号 * 纯数字托盘号
*/ */
int container_no = 0; int container_no = 0;
@@ -199,6 +199,8 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
String vehicle_code; String vehicle_code;
String inst_message; String inst_message;
String hand_barcode = null;
/** /**
* led点阵屏信息 * led点阵屏信息
*/ */
@@ -235,7 +237,7 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
if (mode != last_mode) { if (mode != last_mode) {
requireSucess = false; requireSucess = false;
if(mode == 2){ if (mode == 2) {
clearWrite(); clearWrite();
} }
} }
@@ -314,9 +316,6 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
} }
public void writing(int command) { public void writing(int command) {
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
+ "." + org.nl.acs.device_driver.conveyor.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + "." + org.nl.acs.device_driver.conveyor.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command;
@@ -424,8 +423,6 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
} }
/** /**
* 申请任务 * 申请任务
*/ */
@@ -469,6 +466,53 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
//判断是否有相同起点的,任务状态就绪的任务 //判断是否有相同起点的,任务状态就绪的任务
TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code); TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code);
if (ObjectUtil.isNull(taskdto)) { if (ObjectUtil.isNull(taskdto)) {
//补码生成堆垛机对接位到货架的指令
if (StrUtil.isNotEmpty(hand_barcode)) {
TaskDto taskDtoHandCode = taskserver.findByVehicleCodeCodeAndReady(hand_barcode);
if (Objects.nonNull(taskDtoHandCode)) {
String taskid = taskDtoHandCode.getTask_id();
String taskcode = taskDtoHandCode.getTask_code();
String priority = taskDtoHandCode.getPriority();
String start_point_code = taskDtoHandCode.getStart_point_code();
String start_device_code = "";
String route_plan_code = taskDtoHandCode.getRoute_plan_code();
String next_device_code = taskDtoHandCode.getNext_device_code();
String interactionJson = taskDtoHandCode.getInteraction_json();
String containerType = "";
if (StrUtil.isNotEmpty(interactionJson)) {
InteractionJsonDTO interactionJsonDTO = JSON.parseObject(interactionJson, InteractionJsonDTO.class);
containerType = interactionJsonDTO.getContainerType();
}
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(taskDtoHandCode.getStart_device_code(), next_device_code, route_plan_code);
RouteLineDto routeLineDto = shortPathsList.get(0);
String path = routeLineDto.getPath();
String[] str = path.split("->");
List<String> pathlist = Arrays.asList(str);
int index = 0;
for (int m = 0; m < pathlist.size(); m++) {
if (pathlist.get(m).equals(next_device_code)) {
index = m - 2;
break;
}
}
start_device_code = pathlist.get(index);
//校验路由关系
List<RouteLineDto> shortPathsList2 = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code);
if (ObjectUtils.isEmpty(shortPathsList2) || shortPathsList2.size() < 1) {
throw new RuntimeException("路由不通!");
}
Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code);
String next_point_code;
if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) {
next_point_code = taskDtoHandCode.getTo_x() + "-" + taskDtoHandCode.getTo_y() + "-" + taskDtoHandCode.getTo_z();
Instruction instdto = new Instruction();
packageData(instdto, route_plan_code, taskDtoHandCode, taskid, taskcode, start_device_code, next_device_code, start_point_code, next_point_code, priority, containerType);
return updateTask(taskDtoHandCode, nextdevice, instdto);
}
} else {
return false;
}
}
return false; return false;
} }
if (ObjectUtil.isNotNull(taskdto)) { if (ObjectUtil.isNotNull(taskdto)) {
@@ -484,9 +528,12 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
String start_device_code = taskdto.getStart_device_code(); String start_device_code = taskdto.getStart_device_code();
String route_plan_code = taskdto.getRoute_plan_code(); String route_plan_code = taskdto.getRoute_plan_code();
String next_device_code = ""; String next_device_code = "";
String containerType = "";
String interactionJson = taskdto.getInteraction_json(); String interactionJson = taskdto.getInteraction_json();
InteractionJsonDTO interactionJsonDTO = JSON.parseObject(interactionJson, InteractionJsonDTO.class); if (StrUtil.isNotEmpty(interactionJson)) {
String containerType = interactionJsonDTO.getContainerType(); InteractionJsonDTO interactionJsonDTO = JSON.parseObject(interactionJson, InteractionJsonDTO.class);
containerType = interactionJsonDTO.getContainerType();
}
/** /**
* 开始平均分配 * 开始平均分配
*/ */
@@ -525,7 +572,7 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
next_point_code = next_device_code; next_point_code = next_device_code;
} }
Instruction instdto = new Instruction(); Instruction instdto = new Instruction();
packageData(instdto, route_plan_code, taskdto, taskid, taskcode, start_device_code, next_device_code, start_point_code, next_point_code, priority,containerType); packageData(instdto, route_plan_code, taskdto, taskid, taskcode, start_device_code, next_device_code, start_point_code, next_point_code, priority, containerType);
log.error("=================================,{}", instdto.getCreate_by()); log.error("=================================,{}", instdto.getCreate_by());
try { try {
instructionService.create(instdto); instructionService.create(instdto);
@@ -534,21 +581,26 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
log.error("指令创建失败!,{}", e.getMessage()); log.error("指令创建失败!,{}", e.getMessage());
return false; return false;
} }
taskdto.setTask_status(TaskStatusEnum.BUSY.getIndex()); return updateTask(taskdto, nextdevice, instdto);
taskserver.update(taskdto);
requireSucess = true;
String next_addr = nextdevice.getExtraValue().get("address").toString();
List list = new ArrayList();
writeData(next_addr, list, instdto);
// led_message = getLedMessage(instdto);
requireSucess = true;
return true;
} }
} }
return false; return false;
} }
} }
private boolean updateTask(TaskDto taskdto, Device nextdevice, Instruction instdto) {
taskdto.setTask_status(TaskStatusEnum.BUSY.getIndex());
taskserver.update(taskdto);
requireSucess = true;
String next_addr = nextdevice.getExtraValue().get("address").toString();
List list = new ArrayList();
writeData(next_addr, list, instdto);
// led_message = getLedMessage(instdto);
requireSucess = true;
return true;
}
private void writeData(String next_addr, List list, Instruction inst) { private void writeData(String next_addr, List list, Instruction inst) {
List list1 = new ArrayList(); List list1 = new ArrayList();
Map map = new HashMap(); Map map = new HashMap();
@@ -576,7 +628,7 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
this.writing(list3); this.writing(list3);
} }
private static void packageData(Instruction instdto, String route_plan_code, TaskDto taskdto, String taskid, String taskcode, String start_device_code, String next_device_code, String start_point_code, String next_point_code, String priority,String containerType) { private static void packageData(Instruction instdto, String route_plan_code, TaskDto taskdto, String taskid, String taskcode, String start_device_code, String next_device_code, String start_point_code, String next_point_code, String priority, String containerType) {
instdto.setInstruction_id(IdUtil.simpleUUID()); instdto.setInstruction_id(IdUtil.simpleUUID());
instdto.setRoute_plan_code(route_plan_code); instdto.setRoute_plan_code(route_plan_code);
instdto.setRemark(taskdto.getRemark()); instdto.setRemark(taskdto.getRemark());
@@ -676,7 +728,7 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
mode = LangProcess.msg("universal_standby"); mode = LangProcess.msg("universal_standby");
} else if (this.getMode() == 3) { } else if (this.getMode() == 3) {
mode = LangProcess.msg("universal_operation"); mode = LangProcess.msg("universal_operation");
}else if (this.getMode() == 5) { } else if (this.getMode() == 5) {
mode = LangProcess.msg("one_mode3"); mode = LangProcess.msg("one_mode3");
} }
@@ -685,7 +737,7 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
jo.put("message", LangProcess.msg(message)); jo.put("message", LangProcess.msg(message));
jo.put("error", this.getError()); jo.put("error", this.getError());
String move = "无货"; String move = "无货";
if(this.move == 1){ if (this.move == 1) {
move = "有货"; move = "有货";
} }
jo.put("move", move); jo.put("move", move);
@@ -694,6 +746,7 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
jo.put("is_click", true); jo.put("is_click", true);
jo.put("isOnline", this.getIsonline()); jo.put("isOnline", this.getIsonline());
jo.put("requireSucess", requireSucess); jo.put("requireSucess", requireSucess);
jo.put("hand_barcode", hand_barcode);
return jo; return jo;
} }
@@ -755,6 +808,8 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
} else if (StrUtil.equals(requestSucess, "1")) { } else if (StrUtil.equals(requestSucess, "1")) {
this.requireSucess = true; this.requireSucess = true;
} }
String hand_barcode = data.getString("hand_barcode");
this.setHand_barcode(hand_barcode);
} }
public static boolean arrayEquals(int[] a, int[] b) { public static boolean arrayEquals(int[] a, int[] b) {

View File

@@ -389,6 +389,15 @@ public interface TaskService extends CommonService<Task> {
*/ */
TaskDto findByStartCodeAndReady(String device_code); TaskDto findByStartCodeAndReady(String device_code);
/**
* 根据起载具号查询就绪任务
*
* @param device_code
* @return
*/
TaskDto findByVehicleCodeCodeAndReady(String device_code);
/** /**
* 根据起点设备编号查询当前是否有执行中任务 * 根据起点设备编号查询当前是否有执行中任务
* *

View File

@@ -1076,6 +1076,15 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
return optionalTask.orElse(null); return optionalTask.orElse(null);
} }
@Override
public TaskDto findByVehicleCodeCodeAndReady(String vehicleCode) {
Optional<TaskDto> optionalTask = tasks.stream()
.filter(task -> StrUtil.equals(task.getVehicle_code(), vehicleCode)
&& StrUtil.equals(task.getTask_status(), TaskStatusEnum.READY.getIndex()))
.findFirst();
return optionalTask.orElse(null);
}
@Override @Override
public TaskDto findByCodeAndExcute(String start_code, String next_code) { public TaskDto findByCodeAndExcute(String start_code, String next_code) {
Task task = this.lambdaQuery() Task task = this.lambdaQuery()

View File

@@ -58,7 +58,7 @@ public class CreateDDJInst {
Device nextDevice = appService.findDeviceByCode(next_device_code); Device nextDevice = appService.findDeviceByCode(next_device_code);
//判断有无出入库任务是相同路线 //判断有无出入库任务是相同路线
TaskDto dto = taskserver.findByCodeAndExcute(next_device_code, start_device_code); TaskDto dto = taskserver.findByCodeAndExcute(next_device_code, start_device_code);
if (ObjectUtil.isNotEmpty(dto)){ if (ObjectUtil.isNotEmpty(dto)) {
return; return;
} }
if (startDevice.getDevice_type().equals(DeviceType.storage.name()) && if (startDevice.getDevice_type().equals(DeviceType.storage.name()) &&
@@ -90,21 +90,21 @@ public class CreateDDJInst {
StandardStackerDeviceDriver standardStackerDeviceDriver; StandardStackerDeviceDriver standardStackerDeviceDriver;
if (deviceByCode.getDeviceDriver() instanceof StandardStackerDeviceDriver) { if (deviceByCode.getDeviceDriver() instanceof StandardStackerDeviceDriver) {
standardStackerDeviceDriver = (StandardStackerDeviceDriver) deviceByCode.getDeviceDriver(); standardStackerDeviceDriver = (StandardStackerDeviceDriver) deviceByCode.getDeviceDriver();
if (standardStackerDeviceDriver.getMode() != 3 || standardStackerDeviceDriver.getMove() == 1 || standardStackerDeviceDriver.getCommand() != 0) { // if (standardStackerDeviceDriver.getMode() != 3 || standardStackerDeviceDriver.getMove() == 1 || standardStackerDeviceDriver.getCommand() != 0) {
log.error("堆垛机,{}未联机或者在执行中", deviceByCode.getDevice_code()); // log.error("堆垛机,{}未联机或者在执行中", deviceByCode.getDevice_code());
return; // return;
} // }
} }
String next_device_code = taskDto.getNext_device_code(); String next_device_code = taskDto.getNext_device_code();
Device nextDevice = appService.findDeviceByCode(next_device_code); Device nextDevice = appService.findDeviceByCode(next_device_code);
BeltConveyorDeviceDriver beltConveyorDeviceDriver; BeltConveyorDeviceDriver beltConveyorDeviceDriver;
if (nextDevice.getDeviceDriver() instanceof BeltConveyorDeviceDriver) { // if (nextDevice.getDeviceDriver() instanceof BeltConveyorDeviceDriver) {
beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) nextDevice.getDeviceDriver(); // beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) nextDevice.getDeviceDriver();
if (beltConveyorDeviceDriver.getMode() != 2 || beltConveyorDeviceDriver.getMove() == 1) { // if (beltConveyorDeviceDriver.getMode() != 2 || beltConveyorDeviceDriver.getMove() == 1) {
log.error("输送机,{}未联机或执行中", next_device_code); // log.error("输送机,{}未联机或执行中", next_device_code);
return; // return;
} // }
} // }
String taskid = taskDto.getTask_id(); String taskid = taskDto.getTask_id();
String taskcode = taskDto.getTask_code(); String taskcode = taskDto.getTask_code();
String task_type = taskDto.getTask_type(); String task_type = taskDto.getTask_type();
@@ -149,7 +149,7 @@ public class CreateDDJInst {
int index = 0; int index = 0;
for (int m = 0; m < pathlist1.size(); m++) { for (int m = 0; m < pathlist1.size(); m++) {
String deviceType1 = appService.findDeviceByCode(pathlist1.get(m)).getDevice_type(); String deviceType1 = appService.findDeviceByCode(pathlist1.get(m)).getDevice_type();
if(deviceType1.equals(DeviceType.stacker.name())){ if (deviceType1.equals(DeviceType.stacker.name())) {
index = m + 1; index = m + 1;
break; break;
} }
@@ -287,8 +287,8 @@ public class CreateDDJInst {
} }
/*List<DeviceExtra> deviceExtras = deviceExtra.list(Wrappers.lambdaQuery(DeviceExtra.class). /*List<DeviceExtra> deviceExtras = deviceExtra.list(Wrappers.lambdaQuery(DeviceExtra.class).
eq(DeviceExtra::getDevice_code, pathlist.get(1)).orderByDesc(DeviceExtra::getCreate_time));*/ eq(DeviceExtra::getDevice_code, pathlist.get(1)).orderByDesc(DeviceExtra::getCreate_time));*/
String count = deviceByCode.getExtraValue().get("count").toString(); String count = deviceByCode.getExtraValue().get("count").toString();
if (StrUtil.isNotEmpty(count) ) { if (StrUtil.isNotEmpty(count)) {
if (max <= Integer.parseInt(count)) { if (max <= Integer.parseInt(count)) {
instdto.setInstruction_type(task_type); instdto.setInstruction_type(task_type);
instdto.setInstruction_id(IdUtil.simpleUUID()); instdto.setInstruction_id(IdUtil.simpleUUID());