| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取等待时间 |
| | | * @param lon |
| | | * @param lat |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer getWaitTimeTimeSlot(double lon, double lat,String timeSlot) { |
| | | List<XpGeoQueryEntity> entities = geoQueryEntityService.findByLocationWithin500MetersAndLastWeekAndStatusGreater( |
| | | lon, |
| | | lat, |
| | | timeSlot |
| | | ); |
| | | |
| | | |
| | | if (entities.isEmpty()) { |
| | | return 1; |
| | | } else { |
| | | // 已完成接单的数据 |
| | | List<XpGeoQueryEntity> validEntities = entities.stream().filter(e -> e.getStatus() == 1).collect(Collectors.toList()); |
| | | // 计算平均等待时间 |
| | | OptionalDouble averageOptional = validEntities.stream().mapToDouble(XpGeoQueryEntity::getSeconds).average(); |
| | | if (averageOptional.isPresent()) { |
| | | double average = averageOptional.getAsDouble(); |
| | | return (int) average; |
| | | } else { |
| | | return 1; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String saveOrder(XpOrderDto dto, String uid) { |
| | |
| | | } |
| | | } |
| | | |
| | | // 计算预计等待时间(假设每辆车平均需要3分钟) |
| | | int estimatedWaitTime = (currentPosition - 1) * 3; |
| | | if (estimatedWaitTime < 0) { |
| | | estimatedWaitTime = 0; |
| | | } |
| | | |
| | | Integer waitTimeTimeSlot = getWaitTimeTimeSlot(xpOrder.getStartLon(), xpOrder.getStartLat(), xpOrder.getTimeSlot()); |
| | | queueStatusVo.setStatus(0); // 0-排队中 |
| | | queueStatusVo.setCurrentPosition(currentPosition); |
| | | queueStatusVo.setTotalCount(totalCount); |
| | | queueStatusVo.setEstimatedWaitTime(estimatedWaitTime); |
| | | queueStatusVo.setEstimatedWaitTime((waitTimeTimeSlot*currentPosition)/60); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("查询排队状态失败: {}", e.getMessage(), e); |