| | |
| | | import com.xiaopeng.api.vo.operation.FareVo; |
| | | import com.xiaopeng.api.vo.operation.RouteAndFareVo; |
| | | import com.xiaopeng.api.vo.operation.RouteVo; |
| | | import com.xiaopeng.api.vo.order.XpPricingCardVo; |
| | | import com.xiaopeng.common.core.constant.CacheConstants; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | |
| | | import com.xiaopeng.operation.utils.XpPricingUtil; |
| | | import com.xiaopeng.operation.utils.holiday.HolidayUtil; |
| | | import com.xiaopeng.operation.utils.map.FastDistanceCalculator; |
| | | import com.xiaopeng.operation.vo.XpPricingCardVo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PreDestroy; |
| | | import javax.annotation.Resource; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.*; |
| | |
| | | @Resource |
| | | private XpElectronicFenceAreaMapper xpElectronicFenceAreaMapper; |
| | | |
| | | @Resource |
| | | private XpVehicleClient xpVehicleClient; |
| | | |
| | | @Resource |
| | | private XpPointMapper xpPointMapper; |
| | |
| | | // ); |
| | | XpPricingCardVo xpPricingCardVo = new XpPricingCardVo(); |
| | | |
| | | |
| | | |
| | | // 3. 并行执行远程服务调用 判断是否同一经营区域 |
| | | CompletableFuture<R<Boolean>> diagnosisAreaFuture = CompletableFuture.supplyAsync( |
| | | () -> xpMapClient.diagnosisArea(routeAndFareDto), |
| | |
| | | RouteAndFareVo routeAndFareVo = new RouteAndFareVo(); |
| | | // routeAndFareVo.setRoute(routeVo); |
| | | |
| | | |
| | | routeAndFareVo.setXpPricingCard(xpPricingCardVo); |
| | | |
| | | FareVo fareVo = new FareVo(); |
| | | // fareVo.setEstimatedDistanceKm(routeVo.getDistance().doubleValue() / 1000); |
| | | // fareVo.setEstimatedDurationMin(routeVo.getDuration() / 60); |
| | |
| | | return 1; |
| | | } else { |
| | | // 已完成接单的数据 |
| | | List<XpGeoQueryEntity> validEntities = entities.stream().filter(e -> e.getStatus() > 1).collect(Collectors.toList()); |
| | | List<XpGeoQueryEntity> validEntities = entities.stream().filter(e -> e.getStatus() == 1).collect(Collectors.toList()); |
| | | |
| | | // 计算平均等待时间 |
| | | OptionalDouble averageOptional = validEntities.stream().mapToDouble(XpGeoQueryEntity::getSeconds).average(); |
| | |
| | | double waitMinutes = (average * count) / 60; |
| | | if (waitMinutes > 3) { |
| | | throw new ServiceException("当前区域正在等待中,请耐心等待", I18nKeyConstant.WAITING_TIME); |
| | | }else if(waitMinutes==0){ |
| | | return 1; |
| | | } |
| | | return (int) waitMinutes; |
| | | } |
| | |
| | | |
| | | // 生成订单数据 |
| | | XpOrder xpOrder = new XpOrder(); |
| | | |
| | | xpOrder.setVehicleId(1l); |
| | | |
| | | // xpOrder.setStartMileage(Double.valueOf(startMileage)); |
| | | |
| | |
| | | xpOrder.setQueueName(s); |
| | | xpOrderClient.updateOrder(xpOrder); |
| | | |
| | | // 存储mongodb 数据 |
| | | XpGeoQueryEntity xpGeoQueryEntity = new XpGeoQueryEntity(); |
| | | xpGeoQueryEntity.setOrderId(orderId.toString()); |
| | | xpGeoQueryEntity.setLocation(new GeoJsonPoint(xpPoint.getPointLon(),xpPoint.getPointLat())); |
| | | // 计算2个时间的秒数 |
| | | xpGeoQueryEntity.setTime(currentTimeSlot); |
| | | xpGeoQueryEntity.setStatus(0); |
| | | xpGeoQueryEntity.setTimestamp(System.currentTimeMillis()); |
| | | geoQueryEntityService.save(xpGeoQueryEntity); |
| | | |
| | | return orderId; |
| | | } |
| | | } |
| | |
| | | redisService.setCacheList(key, Arrays.asList(orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + routeAndFareDto.getRoutePlanRule())); |
| | | xpOrder.setQueueName(key); |
| | | xpOrderClient.updateOrder(xpOrder); |
| | | |
| | | |
| | | // 存储mongodb 数据 |
| | | XpGeoQueryEntity xpGeoQueryEntity = new XpGeoQueryEntity(); |
| | | xpGeoQueryEntity.setOrderId(orderId.toString()); |
| | | xpGeoQueryEntity.setLocation(new GeoJsonPoint(xpPoint.getPointLon(),xpPoint.getPointLat())); |
| | | // 计算2个时间的秒数 |
| | | xpGeoQueryEntity.setTime(currentTimeSlot); |
| | | xpGeoQueryEntity.setStatus(0); |
| | | |
| | | geoQueryEntityService.save(xpGeoQueryEntity); |
| | | |
| | | return orderId; |
| | | |
| | | // |