| | |
| | | import com.zy.asrs.service.TaskLogService; |
| | | import com.zy.asrs.service.TaskService; |
| | | import com.zy.common.constant.ApiInterfaceConstant; |
| | | import com.zy.common.properties.AgvProperties; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Resource |
| | | private BasStationMapper basStationMapper; |
| | | |
| | | @Value("${Agv.sendTask}") |
| | | private boolean agvSendTask; |
| | | @Resource |
| | | private AgvProperties agvProperties; |
| | | |
| | | /** |
| | | * 呼叫agv搬运 |
| | | */ |
| | | public void callAgv(List<Task> taskList) { |
| | | |
| | | if (!agvSendTask) { |
| | | if (!agvProperties.isSendTask()) { |
| | | return; |
| | | } |
| | | |
| | |
| | | success = true; |
| | | task.setWrkSts(8L); |
| | | taskService.updateById(task); |
| | | log.info(namespace + "呼叫agv搬运请求参数:{}", body); |
| | | log.info(namespace + "呼叫agv搬运成功:{}", task.getId()); |
| | | } else { |
| | | log.error(namespace + "呼叫agv搬运失败!!!url:{};request:{};response:{}", url, body, response); |
| | |
| | | JSONObject object = new JSONObject(); |
| | | // taskId使用任务ID,格式:T + 任务ID |
| | | object.put("taskId", "T" + task.getId()); |
| | | object.put("fromBin", task.getSourceStaNo()); |
| | | // fromBin使用源库位编号(sourceLocNo),如果为空则使用源站点编号(sourceStaNo)作为备选 |
| | | String fromBin = task.getSourceLocNo(); |
| | | if (fromBin == null || fromBin.isEmpty()) { |
| | | fromBin = task.getSourceStaNo(); |
| | | } |
| | | if (fromBin == null || fromBin.isEmpty() || "0".equals(fromBin)) { |
| | | log.warn("任务{}的源库位和源站点都为空,使用默认值", task.getId()); |
| | | fromBin = "0"; |
| | | } |
| | | object.put("fromBin", fromBin); |
| | | // toBin使用目标站点编号 |
| | | object.put("toBin", task.getStaNo()); |
| | | // robotGroup从invWh字段获取,如果没有则使用默认值 |
| | | // robotGroup从invWh字段获取,如果没有则根据站点编号判断 |
| | | String robotGroup = task.getInvWh(); |
| | | if (robotGroup == null || robotGroup.isEmpty()) { |
| | | robotGroup = "Group-001"; // 默认机器人组 |
| | | robotGroup = determineRobotGroupByStation(task.getStaNo()); |
| | | } |
| | | object.put("robotGroup", robotGroup); |
| | | // kind根据任务类型映射 |
| | | String kind = ""; |
| | | switch (nameSpace) { |
| | | case "入库": |
| | | kind = "实托入库"; |
| | | // 判断是否为空托入库:ioType=10 或 emptyMk="Y" |
| | | if (task.getIoType() == 10 || "Y".equals(task.getEmptyMk())) { |
| | | kind = "空托入库"; |
| | | } else { |
| | | kind = "实托入库"; |
| | | } |
| | | break; |
| | | case "出库": |
| | | kind = "实托出库"; |
| | |
| | | } |
| | | object.put("kind", kind); |
| | | return object.toJSONString(); |
| | | } |
| | | |
| | | /** |
| | | * 根据站点编号判断机器人组 |
| | | * @param staNo 站点编号 |
| | | * @return 机器人组名称 |
| | | */ |
| | | private String determineRobotGroupByStation(String staNo) { |
| | | if (staNo == null || staNo.isEmpty()) { |
| | | return agvProperties.getRobotGroupEast(); // 默认使用东侧机器人组 |
| | | } |
| | | |
| | | // 从配置中获取站点列表 |
| | | Set<String> eastStations = new HashSet<>(agvProperties.getEastStations()); |
| | | Set<String> westStations = new HashSet<>(agvProperties.getWestStations()); |
| | | |
| | | // 判断站点属于哪一侧 |
| | | if (eastStations.contains(staNo)) { |
| | | return agvProperties.getRobotGroupEast(); // 东侧机器人 |
| | | } else if (westStations.contains(staNo)) { |
| | | return agvProperties.getRobotGroupWest(); // 西侧机器人 |
| | | } else { |
| | | log.warn("站点编号不在配置列表中,使用默认机器人组:{}", staNo); |
| | | return agvProperties.getRobotGroupEast(); // 默认使用东侧机器人组 |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 是否成功 |
| | | */ |
| | | public boolean cancelAgvTask(Task task) { |
| | | if (!agvSendTask) { |
| | | if (!agvProperties.isSendTask()) { |
| | | return false; |
| | | } |
| | | |