代码优化

This commit is contained in:
cbs 2025-06-21 11:58:03 +08:00
parent 879038280d
commit 296bcebf77
3 changed files with 78 additions and 33 deletions

View File

@ -33,7 +33,7 @@ public class TaskToPathPlanningDTO {
private Long takeLocationNumber;
@Schema(description = "取货任务的终点id")
private Long takePointId;
private String takePointId;
//线库: LINE + 线库号
//普通库位: POINT + 点位号
@ -44,7 +44,7 @@ public class TaskToPathPlanningDTO {
private Long releaseLocationNumber;
@Schema(description = "放货任务的终点id")
private Long releasePointId;
private String releasePointId;
@Schema(description = "优先级(不同的组编号时:越大越先执行, 相同组编号时:组序号越大的越先执行)")
private Long priority;

View File

@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.mqtt.api.task.dto.RobotAcceptTaskDTO;
import cn.iocoder.yudao.module.mqtt.api.task.dto.RobotRcsHeartBeatDTO;
import cn.iocoder.yudao.module.mqtt.api.task.dto.RobotSimulationPoseDTO;
import cn.iocoder.yudao.module.mqtt.enums.task.ExecutionTypeEnum;
import cn.iocoder.yudao.module.system.api.path.vo.RobotClosePathPlantingDTO;
import cn.iocoder.yudao.module.system.api.robot.processor.RequestProcessor;
import cn.iocoder.yudao.module.system.api.robot.dto.FloorZoneDTO;
import cn.iocoder.yudao.module.system.api.robot.dto.RobotStatusDTO;
@ -1171,6 +1172,14 @@ public class RobotInformationServiceImpl extends ServiceImpl<RobotInformationMap
TASK_ASSIGN_OTHER_ROBOT.getMsg() + actionLog.getRobotNo());
}
RobotInformationDO robotInformationDO = informationMapper.selectOne(new LambdaQueryWrapper<RobotInformationDO>()
.eq(RobotInformationDO::getRobotNo, robotNo)
.last("limit 1"));
if (RobotTaskModelEnum.REJECTION.getType().equals(robotInformationDO.getRobotTaskModel())) {
throw exception(ROBOT_REJECTION);
}
String mac = getMacByRobotNo(robotNo);
robotCloseTaskDetail(actionLog.getTaskDetailId() + "", mac, actionLog.getCommandType());
@ -1180,18 +1189,17 @@ public class RobotInformationServiceImpl extends ServiceImpl<RobotInformationMap
CleanAgvDTO build = CleanAgvDTO.builder().robotNo(robotNo).build();
// commonApi.commonMethod(build, PathPlanningTopicConstant.CLEAN_AGV);
mqttUtils.pub(PathPlanningTopicConstant.CLEAN_AGV, JSON.toJSONString(build));
// mqttUtils.pub(PathPlanningTopicConstant.CLEAN_AGV, JSON.toJSONString(build));
RobotClosePathPlantingDTO closePathPlanting = RobotClosePathPlantingDTO.builder()
.robotNo(robotNo)
.id(actionLog.getTaskDetailId()+"")
.build();
// commonApi.commonMethod(closePathPlanting, PathPlanningTopicConstant.KILL_TASK);
mqttUtils.pub(PathPlanningTopicConstant.KILL_TASK,JSON.toJSONString(closePathPlanting));
Object o = checkTaskDetailExist(actionLog.getTaskDetailId());
RobotInformationDO robotInformationDO = informationMapper.selectOne(new LambdaQueryWrapper<RobotInformationDO>()
.eq(RobotInformationDO::getRobotNo, robotNo)
.last("limit 1"));
if (RobotTaskModelEnum.REJECTION.getType().equals(robotInformationDO.getRobotTaskModel())) {
throw exception(ROBOT_REJECTION);
}
/*String taskStatusKey = RobotTaskChcheConstant.ROBOT_TASK_STATUS + robotInformationDO.getMacAddress();
Object taskStatus = redisUtil.get(taskStatusKey);
if (ObjectUtil.isEmpty(taskStatus) || !RobotStatusCodeConstant.CAN_DO_TASK.equals(Boolean.parseBoolean(String.valueOf(taskStatus)))) {
@ -1465,7 +1473,7 @@ public class RobotInformationServiceImpl extends ServiceImpl<RobotInformationMap
}
pathPlanning.setReleaseGroupId("POINT_" + deviceInformationDO.getPositionMapItemId());
pathPlanning.setReleasePointId(deviceInformationDO.getPositionMapItemId());
pathPlanning.setReleasePointId(deviceInformationDO.getPositionMapItemId()+"");
}
/**

View File

@ -59,6 +59,8 @@ import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static org.codehaus.groovy.runtime.DefaultGroovyMethods.collect;
@Service
@Validated
@Slf4j
@ -505,7 +507,7 @@ public class RobotPathPlanningServiceImpl implements RobotPathPlanningService {
if (ObjectUtil.isNotEmpty(taskDetailDO.getFromLocationId())) {
pathPlanning.setTakeLocationNumber(Math.abs(znConfigConstant.getLocationNumberReduce() - taskDetailDO.getFromLocationNumber()));
pathPlanning.setTakePointId(fromLocation.getMapItemId());
pathPlanning.setTakePointId(fromLocation.getMapItemId()+"");
pathPlanningSetTakeHeight(pathPlanning, fromLocation);
pathPlanning.setTakeLevel(fromLocation.getLocationStorey());
@ -519,7 +521,7 @@ public class RobotPathPlanningServiceImpl implements RobotPathPlanningService {
if (ObjectUtil.isNotEmpty(taskDetailDO.getToLocationId())) {
pathPlanning.setReleaseLocationNumber(taskDetailDO.getToLocationNumber());
pathPlanning.setReleasePointId(toLocation.getMapItemId());
pathPlanning.setReleasePointId(toLocation.getMapItemId()+"");
pathPlanningSetReleaseHeight(pathPlanning, toLocation);
pathPlanning.setReleaseLevel(toLocation.getLocationStorey());
@ -596,7 +598,7 @@ public class RobotPathPlanningServiceImpl implements RobotPathPlanningService {
*/
private void moveToPoint(TaskToPathPlanningDTO pathPlanning, RobotTaskDetailDO taskDetailDO) {
pathPlanning.setReleaseLocationNumber(1l);
pathPlanning.setReleasePointId(taskDetailDO.getReleaseId());
pathPlanning.setReleasePointId(taskDetailDO.getReleaseId()+"");
pathPlanning.setReleaseGroupId("POINT_" + taskDetailDO.getReleaseId());
}
@ -736,30 +738,16 @@ public class RobotPathPlanningServiceImpl implements RobotPathPlanningService {
}
//取货线库
Map<Long, RobotTaskDetailDO> fromLaneMap = detailDOS.stream()
.filter(v -> ObjectUtil.isNotEmpty(v.getFromLaneId()))
.collect(Collectors.groupingBy(RobotTaskDetailDO::getFromLaneId,
Collectors.collectingAndThen(Collectors.minBy(Comparator.comparingLong(RobotTaskDetailDO::getFromLocationNumber)), Optional::get)));
Map<Long, RobotTaskDetailDO> fromLaneMap = getFromLaneMap(detailDOS);
//放货线库
Map<Long, RobotTaskDetailDO> toLaneMap = detailDOS.stream()
.filter(v -> ObjectUtil.isNotEmpty(v.getToLaneId()))
.collect(Collectors.groupingBy(RobotTaskDetailDO::getToLaneId,
Collectors.collectingAndThen(Collectors.maxBy(Comparator.comparingLong(RobotTaskDetailDO::getToLocationNumber)), Optional::get)));
Map<Long, RobotTaskDetailDO> toLaneMap = getToLaneMap(detailDOS);
//取货点位--最小
Map<Long, Long> fromLocationMap = detailDOS.stream()
.filter(v -> ObjectUtil.isNotEmpty(v.getFromMapItemId()))
.collect(Collectors.groupingBy(RobotTaskDetailDO::getFromMapItemId,
Collectors.collectingAndThen(Collectors.minBy(Comparator.comparingLong(RobotTaskDetailDO::getFromLocationNumber)),
a -> a.isPresent() ? a.get().getFromLocationNumber() : null)));
Map<Long, Long> fromLocationMap = getFromLocationMap(detailDOS);
//放货点位--最大
Map<Long, Long> toLocationMap = detailDOS.stream()
.filter(v -> ObjectUtil.isNotEmpty(v.getToMapItemId()))
.collect(Collectors.groupingBy(RobotTaskDetailDO::getToMapItemId,
Collectors.collectingAndThen(Collectors.maxBy(Comparator.comparingLong(RobotTaskDetailDO::getToLocationNumber)),
a -> a.isPresent() ? a.get().getToLocationNumber() : null)));
Map<Long, Long> toLocationMap =getToLocationMap(detailDOS);
//返回的数据
List<RobotTaskDetailDO> list = new ArrayList<>();
@ -796,6 +784,55 @@ public class RobotPathPlanningServiceImpl implements RobotPathPlanningService {
return list;
}
private Map<Long, Long> getToLocationMap(List<RobotTaskDetailDO> detailDOS) {
List<RobotTaskDetailDO> collect = detailDOS.stream()
.filter(v -> ObjectUtil.isNotEmpty(v.getToMapItemId()))
.collect(Collectors.toList());
if (ObjectUtil.isEmpty(collect)) {
return new HashMap<>();
}
return collect.stream().collect(Collectors.groupingBy(RobotTaskDetailDO::getToMapItemId,
Collectors.collectingAndThen(Collectors.maxBy(Comparator.comparingLong(RobotTaskDetailDO::getToLocationNumber)),
a -> a.isPresent() ? a.get().getToLocationNumber() : null)));
}
private Map<Long, Long> getFromLocationMap(List<RobotTaskDetailDO> detailDOS) {
List<RobotTaskDetailDO> collect = detailDOS.stream()
.filter(v -> ObjectUtil.isNotEmpty(v.getFromMapItemId()))
.collect(Collectors.toList());
if (ObjectUtil.isEmpty(collect)) {
return new HashMap<>();
}
return collect.stream().collect(Collectors.groupingBy(RobotTaskDetailDO::getFromMapItemId,
Collectors.collectingAndThen(Collectors.minBy(Comparator.comparingLong(RobotTaskDetailDO::getFromLocationNumber)),
a -> a.isPresent() ? a.get().getFromLocationNumber() : null)));
}
private Map<Long, RobotTaskDetailDO> getToLaneMap(List<RobotTaskDetailDO> detailDOS) {
List<RobotTaskDetailDO> collect = detailDOS.stream()
.filter(v -> ObjectUtil.isNotEmpty(v.getToLaneId()))
.collect(Collectors.toList());
if (ObjectUtil.isEmpty(collect)) {
return new HashMap<>();
}
return collect.stream().collect(Collectors.groupingBy(RobotTaskDetailDO::getToLaneId,
Collectors.collectingAndThen(Collectors.maxBy(Comparator.comparingLong(RobotTaskDetailDO::getToLocationNumber)), Optional::get)));
}
private Map<Long, RobotTaskDetailDO> getFromLaneMap(List<RobotTaskDetailDO> detailDOS) {
List<RobotTaskDetailDO> collect = detailDOS.stream()
.filter(v -> ObjectUtil.isNotEmpty(v.getFromLaneId()))
.collect(Collectors.toList());
if (ObjectUtil.isEmpty(collect)) {
return new HashMap<>();
}
return collect.stream()
.collect(Collectors.groupingBy(RobotTaskDetailDO::getFromLaneId,
Collectors.collectingAndThen(Collectors.minBy(Comparator.comparingLong(RobotTaskDetailDO::getFromLocationNumber)), Optional::get)));
}
/**
* 仅取货设置任务