| | |
| | | import com.xiaopeng.api.dto.map.RouteAndFareDto; |
| | | import com.xiaopeng.api.dto.map.RouteStaleCheckDto; |
| | | import com.xiaopeng.api.dto.map.SelectNavigationRouteDto; |
| | | import com.xiaopeng.api.dto.operation.LonLatDto; |
| | | import com.xiaopeng.api.enums.RouteStrategyKind; |
| | | import com.xiaopeng.api.feignClient.account.UserResourcesClient; |
| | | import com.xiaopeng.api.feignClient.account.UserRoutePlanRuleClient; |
| | |
| | | import com.xiaopeng.itinerary.vo.RedisQueuePointIdVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | |
| | | private XpTradingStrategyClient xpTradingStrategyClient; |
| | | @Resource |
| | | private UserResourcesClient userResourcesClient; |
| | | @Resource |
| | | private RedissonClient redissonClient; |
| | | |
| | | @Resource(name = "hutoolSnowflake") |
| | | private Snowflake snowflake; |
| | |
| | | routeVo.getDistance(), routeVo.getDuration(), 0, 0.0, xpPricing.getIsDynamicPrice(), routeAndFareDto.getOpenCityId(), xpPricing.getDynamicPricingJson() |
| | | ); |
| | | } |
| | | |
| | | log.info("计算费用明细 {}", JSON.toJSONString(xpPricingCardVo)); |
| | | // 优惠券:null=自动最佳;0=不使用;>0=指定券 |
| | | XpPricingCardVo finalXpPricingCardVo = xpPricingCardVo; |
| | | R<UserCouponVo> coupon = null; |
| | |
| | | Double money = userCouponVo.getMoney(); |
| | | money = new BigDecimal(money).setScale(2, RoundingMode.HALF_UP).doubleValue(); |
| | | xpPricingCardVo.setCoupon(String.valueOf(money)); |
| | | if (xpPricingCardVo.getTotalPrice() > money) { |
| | | xpPricingCardVo.setSystemDiscount(xpPricingCardVo.getTotalPrice() - money); |
| | | } |
| | | |
| | | |
| | | // if (xpPricingCardVo.getTotalPrice() > money) { |
| | | // xpPricingCardVo.setSystemDiscount(xpPricingCardVo.getTotalPrice() - money); |
| | | // } |
| | | } |
| | | |
| | | // 8. 构建响应对象 |
| | |
| | | xpPricingCardVo.setStartPriceStr(new BigDecimal(xpPricingCardVo.getStartPrice()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | xpPricingCardVo.setDistancePriceStr(new BigDecimal(xpPricingCardVo.getDistancePrice()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | xpPricingCardVo.setDurationPriceStr(new BigDecimal(xpPricingCardVo.getDurationPrice()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | xpPricingCardVo.setSystemDiscountStr(new BigDecimal(xpPricingCardVo.getSystemDiscount()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | // xpPricingCardVo.setSystemDiscountStr(new BigDecimal(xpPricingCardVo.getSystemDiscount()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | |
| | | |
| | | routeAndFareVo.setXpPricingCard(xpPricingCardVo); |
| | |
| | | |
| | | // 9. 设置费用信息 |
| | | fareVo.setOriginalFare(xpPricingCardVo.getTotalPrice()); |
| | | fareVo.setOriginalFareStr(new BigDecimal(fareVo.getOriginalFare()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | fareVo.setOriginalFareStr(new BigDecimal(xpPricingCardVo.getTotalPrice()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | if (userCouponVo != null) { |
| | | if(userCouponVo.getMoney()>fareVo.getOriginalFare()){ |
| | | fareVo.setCouponType(userCouponVo.getCouponType()); |
| | | fareVo.setDiscountAmount(fareVo.getOriginalFare()); |
| | | fareVo.setFinalFare(0.00); |
| | | }else { |
| | | fareVo.setDiscountAmount(userCouponVo.getMoney()); |
| | | fareVo.setCouponType(userCouponVo.getCouponType()); |
| | | fareVo.setFinalFare(fareVo.getOriginalFare() - fareVo.getDiscountAmount()); |
| | | } |
| | | if(fareVo.getFinalFare()>0){ |
| | | fareVo.setSystemDiscount(fareVo.getFinalFare()); |
| | | fareVo.setFinalFare(0.00); |
| | | } |
| | | // if(fareVo.getFinalFare()>0){ |
| | | // fareVo.setSystemDiscount(fareVo.getFinalFare()); |
| | | // fareVo.setFinalFare(0.00); |
| | | // } |
| | | fareVo.setCouponId(userCouponVo.getId()); |
| | | } else { |
| | | fareVo.setDiscountAmount(0.00); |
| | | fareVo.setFinalFare(fareVo.getOriginalFare()); |
| | | fareVo.setSystemDiscount(fareVo.getFinalFare()); |
| | | fareVo.setFinalFare(0.00); |
| | | // fareVo.setSystemDiscount(fareVo.getFinalFare()); |
| | | // fareVo.setFinalFare(0.00); |
| | | } |
| | | |
| | | // 10. 检查等待时间 |
| | |
| | | // 12. 设置费用信息 |
| | | fareVo.setFinalFareStr(new BigDecimal(fareVo.getFinalFare()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | fareVo.setOriginalFare(new BigDecimal(fareVo.getOriginalFare()).setScale(2,RoundingMode.HALF_UP).doubleValue()); |
| | | fareVo.setSystemDiscount(new BigDecimal(fareVo.getSystemDiscount() == null ? 0 : fareVo.getSystemDiscount()).setScale(2,RoundingMode.HALF_UP).doubleValue()); |
| | | // fareVo.setSystemDiscount(new BigDecimal(fareVo.getSystemDiscount() == null ? 0 : fareVo.getSystemDiscount()).setScale(2,RoundingMode.HALF_UP).doubleValue()); |
| | | routeAndFareVo.setFareEstimate(fareVo); |
| | | |
| | | routeAndFareVo.getXpPricingCard().setFinalFareStr(fareVo.getFinalFareStr()); |
| | |
| | | @Override |
| | | public String saveOrder(XpOrderDto dto, String uid) { |
| | | //校验白名单用户 |
| | | // UcUserInfo userInfo = userResourcesClient.getBaseUserByUid(uid); |
| | | // XpWhitelist xpWhitelist = xpWhitelistMapper.selectOne(new QueryWrapper<XpWhitelist>().eq("account", userInfo.getMobile()) |
| | | // .eq("status", 1).last(" and (DATE(expire_time) < DATE(NOW()) or expire_time is null)")); |
| | | // if(null == xpWhitelist){ |
| | | // throw new ServiceException("未授权用户,不能使用该功能", I18nKeyConstant.NO_PERMISSION); |
| | | // } |
| | | List<XpWhitelist> xpWhitelists = xpWhitelistMapper.selectList(new QueryWrapper<XpWhitelist>().eq("app_user_id", uid) |
| | | .eq("status", 1).eq("is_deleted", 0).last(" and (expire_time >= DATE(NOW()) or expire_time is null)")); |
| | | if(xpWhitelists.isEmpty()){ |
| | | throw new ServiceException("未授权用户,不能使用该功能", I18nKeyConstant.NO_PERMISSION); |
| | | } |
| | | XpWhitelist xpWhitelist = xpWhitelists.get(0); |
| | | //判断最大下单数 |
| | | // if(null != xpWhitelist.getMaxOrderNum() && xpWhitelist.getMaxOrderNum()>0){ |
| | | // Long count = xpOrderClient.getUserOrderNum(Long.valueOf(uid)).getData(); |
| | | // if(xpWhitelist.getMaxOrderNum() <= count){ |
| | | // throw new ServiceException("已达到最大下单数量,不能使用该功能", I18nKeyConstant.MAX_ORDER_NUM); |
| | | // } |
| | | // } |
| | | if(null != xpWhitelist.getMaxOrderNum() && xpWhitelist.getMaxOrderNum()>0){ |
| | | Long count = xpOrderClient.getUserOrderNum(Long.valueOf(uid)).getData(); |
| | | if(xpWhitelist.getMaxOrderNum() <= count){ |
| | | throw new ServiceException("已达到最大下单数量,不能使用该功能", I18nKeyConstant.MAX_ORDER_NUM); |
| | | } |
| | | } |
| | | |
| | | // 是否在运营区域时间内 |
| | | XpElectronicFenceArea xpElectronicFenceArea = xpElectronicFenceAreaMapper.selectById(dto.getXpElectronicFenceAreaId()); |
| | |
| | | XpOrder xpOrder = new XpOrder(); |
| | | xpOrder.setMileageKilometers(0.0); |
| | | xpOrder.setAppUserId(Long.valueOf(uid)); |
| | | xpOrder.setOrderNumber("XP" + System.currentTimeMillis()); |
| | | xpOrder.setOrderNumber(getOrderNumber()); |
| | | xpOrder.setPlacementLon(dto.getPlacementLon()); |
| | | xpOrder.setPlacementLat(dto.getPlacementLat()); |
| | | xpOrder.setPlacementAddress(dto.getPlacementAddress()); |
| | |
| | | } |
| | | |
| | | //获取定向服务配置 |
| | | R<List<XpTargetedServiceVehicleVo>> targetedServiceUserR = xpTargetedServiceClient.findListByUserIdAndCityCode(xpOrder.getAppUserId(), xpOrder.getCityCode()); |
| | | if(targetedServiceUserR.getCode() == R.SUCCESS && CollUtil.isNotEmpty(targetedServiceUserR.getData()) ){ |
| | | XpTargetedServiceVehicleVo xpTargetedServiceVehicleVo = targetedServiceUserR.getData().get(0); |
| | | return addSpOrderPush(xpOrder, xpPoint, xpRoutePlan, maxPushDistance, xpTargetedServiceVehicleVo, orderId, currentTimeSlot, distance, duration, uid); |
| | | R<Integer> targetedServiceWeight = xpTargetedServiceClient.getTargetedServiceWeight(xpOrder.getAppUserId(), xpOrder.getCityCode()); |
| | | if(targetedServiceWeight.getCode() == R.SUCCESS && null != targetedServiceWeight.getData()){ |
| | | log.info("添加定向服务订单:{}", xpOrder.getOrderNumber()); |
| | | return addSpOrderPush(xpOrder, xpPoint, xpRoutePlan, maxPushDistance, targetedServiceWeight.getData(), orderId, currentTimeSlot, distance, duration, uid); |
| | | }else{ |
| | | log.info("添加普通订单:{}", xpOrder.getOrderNumber()); |
| | | return addOrderPush(xpOrder, xpPoint, xpRoutePlan, maxPushDistance, isPriorityDispatch, orderId, currentTimeSlot, distance, duration, uid); |
| | | } |
| | | } |
| | | |
| | | private String getOrderNumber(){ |
| | | int random = Double.valueOf(Math.random() * 1000).intValue(); |
| | | return "XP" + random + System.currentTimeMillis(); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | private String addOrderPush(XpOrder xpOrder, XpPoint xpPoint, XpRoutePlan xpRoutePlan, double maxPushDistance, |
| | | Boolean isPriorityDispatch, Long orderId, String currentTimeSlot, Integer distance, Integer duration, String uid){ |
| | | // 找出现在所有的队列 通过计算距离 算出目前应该放在那个队列 如果没有符合的新增一个队列 符合后看是否白名单账号 是则直接放在队列前端 |
| | | Set<String> quoteMatchName = redisService.getQuoteMatchName(CacheConstants.QUEUE_POINT_ID); |
| | | log.info("当前队列:{}", quoteMatchName); |
| | | for (String s : quoteMatchName) { |
| | | RLock lock = redissonClient.getLock("ADD_ORDER_PUSH"); |
| | | try { |
| | | if(lock.tryLock(2, 5, TimeUnit.SECONDS)){ |
| | | // 找出现在所有的队列 通过计算距离 算出目前应该放在那个队列 如果没有符合的新增一个队列 符合后看是否白名单账号 是则直接放在队列前端 |
| | | Set<String> quoteMatchName = redisService.getQuoteMatchName(CacheConstants.QUEUE_POINT_ID); |
| | | log.info("当前队列:{}", quoteMatchName); |
| | | for (String s : quoteMatchName) { |
| | | // QUEUE_POINT_ID-1-30.233,120.233 |
| | | String lonLat = s.split("-")[2]; |
| | | // 和上车点进行判断是否<maxPushDistance |
| | | double v = FastDistanceCalculator.distanceFast(Double.parseDouble(lonLat.split(",")[1]), Double.parseDouble(lonLat.split(",")[0]), xpPoint.getPointLat(), xpPoint.getPointLon()); |
| | | if (v < maxPushDistance) { |
| | | String value = orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + xpRoutePlan.getRoutePlanRule(); |
| | | if (isPriorityDispatch) { |
| | | // 头部 value 订单_经纬度_状态_用户id_订单编号_距离_时间 |
| | | redisService.addToHead(s, value); |
| | | log.info("添加到队列头部:{} {}", s, value); |
| | | } else { |
| | | // 尾部 |
| | | redisService.addToTail(s, value); |
| | | log.info("添加到队列尾部:{} {}", s, value); |
| | | String lonLat = s.split("-")[2]; |
| | | // 和上车点进行判断是否<maxPushDistance |
| | | double v = FastDistanceCalculator.distanceFast(Double.parseDouble(lonLat.split(",")[1]), Double.parseDouble(lonLat.split(",")[0]), xpPoint.getPointLat(), xpPoint.getPointLon()); |
| | | if (v < maxPushDistance) { |
| | | String value = orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + xpRoutePlan.getRoutePlanRule(); |
| | | if (isPriorityDispatch) { |
| | | // 头部 value 订单_经纬度_状态_用户id_订单编号_距离_时间 |
| | | redisService.addToHead(s, value); |
| | | log.info("添加到队列头部:{} {}", s, value); |
| | | } else { |
| | | // 尾部 |
| | | redisService.addToTail(s, value); |
| | | log.info("添加到队列尾部:{} {}", s, value); |
| | | } |
| | | xpOrder.setQueueName(s); |
| | | xpOrder.setQueueValue(value); |
| | | 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.toString(); |
| | | } |
| | | } |
| | | xpOrder.setQueueName(s); |
| | | |
| | | String key = CacheConstants.QUEUE_POINT_ID + "-" + xpPoint.getId() + "-" + xpPoint.getPointLon() + "," + xpPoint.getPointLat(); |
| | | if(xpRoutePlan==null){ |
| | | redisService.setCacheList(key, Arrays.asList(orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + null)); |
| | | |
| | | }else { |
| | | redisService.setCacheList(key, Arrays.asList(orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + xpRoutePlan.getRoutePlanRule())); |
| | | } |
| | | log.info("订单推单:{} {}", key, redisService.getCacheList(key)); |
| | | xpOrder.setQueueName(key); |
| | | xpOrderClient.updateOrder(xpOrder); |
| | | |
| | | |
| | | // 存储mongodb 数据 |
| | | XpGeoQueryEntity xpGeoQueryEntity = new XpGeoQueryEntity(); |
| | |
| | | xpGeoQueryEntity.setStatus(0); |
| | | xpGeoQueryEntity.setTimestamp(System.currentTimeMillis()); |
| | | geoQueryEntityService.save(xpGeoQueryEntity); |
| | | |
| | | return orderId.toString(); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | lock.unlock(); |
| | | } |
| | | |
| | | String key = CacheConstants.QUEUE_POINT_ID + "-" + xpPoint.getId() + "-" + xpPoint.getPointLon() + "," + xpPoint.getPointLat(); |
| | | if(xpRoutePlan==null){ |
| | | redisService.setCacheList(key, Arrays.asList(orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + null)); |
| | | |
| | | }else { |
| | | redisService.setCacheList(key, Arrays.asList(orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + xpRoutePlan.getRoutePlanRule())); |
| | | } |
| | | log.info("订单推单:{} {}", key, redisService.getCacheList(key)); |
| | | 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); |
| | | xpGeoQueryEntity.setTimestamp(System.currentTimeMillis()); |
| | | geoQueryEntityService.save(xpGeoQueryEntity); |
| | | |
| | | return orderId.toString(); |
| | | } |
| | | |
| | |
| | | * @param xpPoint |
| | | * @param xpRoutePlan |
| | | * @param maxPushDistance |
| | | * @param xpTargetedServiceVehicleVo |
| | | * @param weight |
| | | * @param orderId |
| | | * @param currentTimeSlot |
| | | * @param distance |
| | |
| | | * @return |
| | | */ |
| | | private String addSpOrderPush(XpOrder xpOrder, XpPoint xpPoint, XpRoutePlan xpRoutePlan, double maxPushDistance, |
| | | XpTargetedServiceVehicleVo xpTargetedServiceVehicleVo, Long orderId, String currentTimeSlot, Integer distance, Integer duration, String uid){ |
| | | // 找出现在所有的队列 通过计算距离 算出目前应该放在那个队列 如果没有符合的新增一个队列 符合后看是否白名单账号 是则直接放在队列前端 |
| | | Set<String> quoteMatchName = redisService.getQuoteMatchName(CacheConstants.SP_QUEUE_POINT_ID); |
| | | log.info("当前队列:{}", quoteMatchName); |
| | | Integer weight, Long orderId, String currentTimeSlot, Integer distance, Integer duration, String uid){ |
| | | RLock lock = redissonClient.getLock("ADD_SP_ORDER_PUSH"); |
| | | try { |
| | | if(lock.tryLock(2, 5, TimeUnit.SECONDS)){ |
| | | // 找出现在所有的队列 通过计算距离 算出目前应该放在那个队列 如果没有符合的新增一个队列 符合后看是否白名单账号 是则直接放在队列前端 |
| | | Set<String> quoteMatchName = redisService.getQuoteMatchName(CacheConstants.SP_QUEUE_POINT_ID); |
| | | log.info("当前队列(定向服务):{}", quoteMatchName); |
| | | |
| | | for (String s : quoteMatchName) { |
| | | // QUEUE_POINT_ID-1-30.233,120.233 |
| | | String lonLat = s.split("-")[2]; |
| | | // 和上车点进行判断是否<maxPushDistance |
| | | double v = FastDistanceCalculator.distanceFast(Double.parseDouble(lonLat.split(",")[1]), Double.parseDouble(lonLat.split(",")[0]), xpPoint.getPointLat(), xpPoint.getPointLon()); |
| | | if (v < maxPushDistance) { |
| | | //在范围内,将队列中的数据转换成对象进行排序 |
| | | List<String> cacheList = redisService.getCacheList(s); |
| | | List<RedisQueuePointIdVo> ll = new ArrayList<>(); |
| | | for (String string : cacheList) { |
| | | String[] split = string.split("_"); |
| | | RedisQueuePointIdVo redisQueuePointIdVo = new RedisQueuePointIdVo(); |
| | | redisQueuePointIdVo.setOrderId(split[0]); |
| | | redisQueuePointIdVo.setPointLonLat(split[1]); |
| | | redisQueuePointIdVo.setPushStatus(split[2]); |
| | | redisQueuePointIdVo.setUid(split[3]); |
| | | redisQueuePointIdVo.setOrderNumber(split[4]); |
| | | redisQueuePointIdVo.setDistance(split[5]); |
| | | redisQueuePointIdVo.setDuration(split[6]); |
| | | redisQueuePointIdVo.setPlanRuleForQueue(split[7]); |
| | | redisQueuePointIdVo.setTargetedVal(Integer.valueOf(split[8])); |
| | | ll.add(redisQueuePointIdVo); |
| | | for (String s : quoteMatchName) { |
| | | String lonLat = s.split("-")[2]; |
| | | // 和上车点进行判断是否<maxPushDistance |
| | | double v = FastDistanceCalculator.distanceFast(Double.parseDouble(lonLat.split(",")[1]), Double.parseDouble(lonLat.split(",")[0]), xpPoint.getPointLat(), xpPoint.getPointLon()); |
| | | if (v < maxPushDistance) { |
| | | //在范围内,将队列中的数据转换成对象进行排序 |
| | | List<String> cacheList = redisService.getCacheList(s); |
| | | List<RedisQueuePointIdVo> ll = new ArrayList<>(); |
| | | //正在派单的数据,不参与权重排序 |
| | | String pushOrder = null; |
| | | for (String string : cacheList) { |
| | | String[] split = string.split("_"); |
| | | if(split[2].equals("0")){ |
| | | RedisQueuePointIdVo redisQueuePointIdVo = new RedisQueuePointIdVo(); |
| | | redisQueuePointIdVo.setOrderId(split[0]); |
| | | redisQueuePointIdVo.setPointLonLat(split[1]); |
| | | redisQueuePointIdVo.setPushStatus(split[2]); |
| | | redisQueuePointIdVo.setUid(split[3]); |
| | | redisQueuePointIdVo.setOrderNumber(split[4]); |
| | | redisQueuePointIdVo.setDistance(split[5]); |
| | | redisQueuePointIdVo.setDuration(split[6]); |
| | | redisQueuePointIdVo.setPlanRuleForQueue(split[7]); |
| | | redisQueuePointIdVo.setTargetedVal(Integer.valueOf(split[8])); |
| | | ll.add(redisQueuePointIdVo); |
| | | }else{ |
| | | pushOrder = string; |
| | | } |
| | | } |
| | | |
| | | RedisQueuePointIdVo redisQueuePointIdVo = new RedisQueuePointIdVo(); |
| | | redisQueuePointIdVo.setOrderId(orderId.toString()); |
| | | redisQueuePointIdVo.setPointLonLat(xpPoint.getPointLon() + "," + xpPoint.getPointLat()); |
| | | redisQueuePointIdVo.setPushStatus("0"); |
| | | redisQueuePointIdVo.setUid(uid); |
| | | redisQueuePointIdVo.setOrderNumber(xpOrder.getOrderNumber()); |
| | | redisQueuePointIdVo.setDistance(distance.toString()); |
| | | redisQueuePointIdVo.setDuration(duration.toString()); |
| | | redisQueuePointIdVo.setPlanRuleForQueue(xpRoutePlan.getRoutePlanRule().toString()); |
| | | redisQueuePointIdVo.setTargetedVal(weight); |
| | | ll.add(redisQueuePointIdVo); |
| | | |
| | | //排序 |
| | | ll.sort((o1, o2) -> o2.getTargetedVal() - o1.getTargetedVal()); |
| | | List<String> collect = ll.stream().map(item -> { |
| | | String value = item.getOrderId() + "_" + item.getPointLonLat() + "_" + item.getPushStatus() + "_" + item.getUid() + "_" + item.getOrderNumber() |
| | | + "_" + item.getDistance() + "_" + item.getDuration() + "_" + item.getPlanRuleForQueue() + "_" + item.getTargetedVal(); |
| | | return value; |
| | | }).collect(Collectors.toList()); |
| | | //如果有正在推单的数据,则放在第一位 |
| | | if(StringUtils.isNotEmpty(pushOrder)){ |
| | | collect.add(0, pushOrder); |
| | | } |
| | | //先清除key的缓存数据 |
| | | redisService.deleteObject(s); |
| | | //再全部重新赋值 |
| | | redisService.setCacheList(s, collect); |
| | | |
| | | String value = orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0_" + uid + "_" + xpOrder.getOrderNumber() |
| | | + "_" + distance + "_" + duration + "_" + xpRoutePlan.getRoutePlanRule() + "_" + weight; |
| | | xpOrder.setQueueName(s); |
| | | xpOrder.setQueueValue(value); |
| | | 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.toString(); |
| | | } |
| | | } |
| | | |
| | | RedisQueuePointIdVo redisQueuePointIdVo = new RedisQueuePointIdVo(); |
| | | redisQueuePointIdVo.setOrderId(orderId.toString()); |
| | | redisQueuePointIdVo.setPointLonLat(xpPoint.getPointLon() + "," + xpPoint.getPointLat()); |
| | | redisQueuePointIdVo.setPushStatus("0"); |
| | | redisQueuePointIdVo.setUid(uid); |
| | | redisQueuePointIdVo.setOrderNumber(xpOrder.getOrderNumber()); |
| | | redisQueuePointIdVo.setDistance(distance.toString()); |
| | | redisQueuePointIdVo.setDuration(duration.toString()); |
| | | redisQueuePointIdVo.setPlanRuleForQueue(xpRoutePlan.getRoutePlanRule().toString()); |
| | | redisQueuePointIdVo.setTargetedVal(xpTargetedServiceVehicleVo.getWeight()); |
| | | ll.add(redisQueuePointIdVo); |
| | | //排序 |
| | | ll.sort((o1, o2) -> o2.getTargetedVal() - o1.getTargetedVal()); |
| | | List<String> collect = ll.stream().map(item -> { |
| | | String value = item.getOrderId() + "_" + item.getPointLonLat() + "_" + item.getPushStatus() + "_" + item.getUid() + "_" + item.getOrderNumber() |
| | | + "_" + item.getDistance() + "_" + item.getDuration() + "_" + item.getPlanRuleForQueue() + "_" + item.getTargetedVal(); |
| | | return value; |
| | | }).collect(Collectors.toList()); |
| | | redisService.setCacheList(s, cacheList); |
| | | |
| | | xpOrder.setQueueName(s); |
| | | String key = CacheConstants.SP_QUEUE_POINT_ID + "-" + xpPoint.getId() + "-" + xpPoint.getPointLon() + "," + xpPoint.getPointLat(); |
| | | if(xpRoutePlan==null){ |
| | | redisService.setCacheList(key, Arrays.asList(orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + null + "_" + weight)); |
| | | }else { |
| | | redisService.setCacheList(key, Arrays.asList(orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + xpRoutePlan.getRoutePlanRule() + "_" + weight)); |
| | | } |
| | | log.info("订单推单:{} {}", key, redisService.getCacheList(key)); |
| | | xpOrder.setQueueName(key); |
| | | xpOrderClient.updateOrder(xpOrder); |
| | | |
| | | |
| | | // 存储mongodb 数据 |
| | | XpGeoQueryEntity xpGeoQueryEntity = new XpGeoQueryEntity(); |
| | |
| | | xpGeoQueryEntity.setStatus(0); |
| | | xpGeoQueryEntity.setTimestamp(System.currentTimeMillis()); |
| | | geoQueryEntityService.save(xpGeoQueryEntity); |
| | | |
| | | return orderId.toString(); |
| | | } |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | lock.unlock(); |
| | | } |
| | | |
| | | String key = CacheConstants.SP_QUEUE_POINT_ID + "-" + xpPoint.getId() + "-" + xpPoint.getPointLon() + "," + xpPoint.getPointLat(); |
| | | if(xpRoutePlan==null){ |
| | | redisService.setCacheList(key, Arrays.asList(orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + null + "_" + xpTargetedServiceVehicleVo.getWeight())); |
| | | }else { |
| | | redisService.setCacheList(key, Arrays.asList(orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + xpRoutePlan.getRoutePlanRule() + "_" + xpTargetedServiceVehicleVo.getWeight())); |
| | | } |
| | | log.info("订单推单:{} {}", key, redisService.getCacheList(key)); |
| | | 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); |
| | | xpGeoQueryEntity.setTimestamp(System.currentTimeMillis()); |
| | | geoQueryEntityService.save(xpGeoQueryEntity); |
| | | |
| | | return orderId.toString(); |
| | | } |
| | | |
| | |
| | | Double money = userCouponVo.getMoney(); |
| | | money = new BigDecimal(money).setScale(2, RoundingMode.HALF_UP).doubleValue(); |
| | | xpPricingCardVo.setCoupon(String.valueOf(money)); |
| | | if (xpPricingCardVo.getTotalPrice() > money) { |
| | | xpPricingCardVo.setSystemDiscount(xpPricingCardVo.getTotalPrice() - money); |
| | | } |
| | | // if (xpPricingCardVo.getTotalPrice() > money) { |
| | | // xpPricingCardVo.setSystemDiscount(xpPricingCardVo.getTotalPrice() - money); |
| | | // } |
| | | } |
| | | RouteAndFareVo routeAndFareVo = new RouteAndFareVo(); |
| | | routeAndFareVo.setRoute(routeVo); |
| | |
| | | xpPricingCardVo.setStartPriceStr(new BigDecimal(xpPricingCardVo.getStartPrice()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | xpPricingCardVo.setDistancePriceStr(new BigDecimal(xpPricingCardVo.getDistancePrice()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | xpPricingCardVo.setDurationPriceStr(new BigDecimal(xpPricingCardVo.getDurationPrice()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | xpPricingCardVo.setSystemDiscountStr(new BigDecimal(xpPricingCardVo.getSystemDiscount()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | // xpPricingCardVo.setSystemDiscountStr(new BigDecimal(xpPricingCardVo.getSystemDiscount()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | routeAndFareVo.setXpPricingCard(xpPricingCardVo); |
| | | FareVo fareVo = new FareVo(); |
| | | fareVo.setEstimatedDistanceKm(routeVo.getDistance().doubleValue() / 1000); |
| | |
| | | if (userCouponVo != null) { |
| | | if (userCouponVo.getMoney() > fareVo.getOriginalFare()) { |
| | | fareVo.setDiscountAmount(fareVo.getOriginalFare()); |
| | | fareVo.setCouponType(userCouponVo.getCouponType()); |
| | | fareVo.setFinalFare(0.00); |
| | | } else { |
| | | fareVo.setDiscountAmount(userCouponVo.getMoney()); |
| | | fareVo.setCouponType(userCouponVo.getCouponType()); |
| | | fareVo.setFinalFare(fareVo.getOriginalFare() - fareVo.getDiscountAmount()); |
| | | } |
| | | if (fareVo.getFinalFare() > 0) { |
| | | fareVo.setSystemDiscount(fareVo.getFinalFare()); |
| | | fareVo.setFinalFare(0.00); |
| | | } |
| | | fareVo.setCouponId(userCouponVo.getId()); |
| | | } else { |
| | | fareVo.setDiscountAmount(0.00); |
| | | fareVo.setFinalFare(fareVo.getOriginalFare()); |
| | | fareVo.setSystemDiscount(fareVo.getFinalFare()); |
| | | fareVo.setFinalFare(0.00); |
| | | // fareVo.setSystemDiscount(fareVo.getFinalFare()); |
| | | } |
| | | Integer waitTime = getWaitTime(routeAndFareDto.getOrigin().getLongitude(), routeAndFareDto.getOrigin().getLatitude()); |
| | | fareVo.setWaitingTime(waitTime); |
| | | fareVo.setFinalFareStr(new BigDecimal(fareVo.getFinalFare()).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | fareVo.setOriginalFare(new BigDecimal(fareVo.getOriginalFare()).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
| | | fareVo.setSystemDiscount(new BigDecimal(fareVo.getSystemDiscount() == null ? 0 : fareVo.getSystemDiscount()).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
| | | // fareVo.setSystemDiscount(new BigDecimal(fareVo.getSystemDiscount() == null ? 0 : fareVo.getSystemDiscount()).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
| | | routeAndFareVo.setFareEstimate(fareVo); |
| | | routeAndFareVo.getXpPricingCard().setFinalFareStr(fareVo.getFinalFareStr()); |
| | | // routeAndFareVo.setTrafficLights();//交通信号灯 todo 20260508 红绿灯功能还没有 |
| | |
| | | |
| | | StrategyPlanningConfig planningConfig = this.buildStrategyKindsForPlanning(userId, routeAndFareDto.getOpenCityId()); |
| | | List<RouteStrategyKind> kinds = planningConfig.getKinds(); |
| | | Map<String, RouteVo> routeById = new LinkedHashMap<>(); |
| | | Map<String, Set<RouteStrategyKind>> strategiesById = new LinkedHashMap<>(); |
| | | for (RouteStrategyKind kind : kinds) { |
| | | Map<String, RouteStrategyKind> strategiesById = new HashMap<>(); |
| | | List<RouteVo> routePoints = new ArrayList<>(); |
| | | |
| | | |
| | | List<XpRoutePlan> xpRoutePlans = xpRoutePlanMapper.selectList(new LambdaQueryWrapper<XpRoutePlan>().eq(XpRoutePlan::getOpenCityId, routeAndFareDto.getOpenCityId()) |
| | | .eq(XpRoutePlan::getAuditStatus, 2)); |
| | | log.info("导航策略配置 {} {}", routeAndFareDto.getOpenCityId(), JSON.toJSONString(xpRoutePlans)); |
| | | for (XpRoutePlan xpRoutePlan : xpRoutePlans) { |
| | | RouteAndFareDto copy = new RouteAndFareDto(); |
| | | copy.setOrigin(routeAndFareDto.getOrigin()); |
| | | copy.setDestination(routeAndFareDto.getDestination()); |
| | | copy.setRoutePlanRule(kind.getAmapStrategy()); |
| | | R<RouteVo> r = xpMapClient.getDistanceAndDuration(copy); |
| | | if (r.getCode() != 200 || r.getData() == null || r.getData().getRouteID() == null) { |
| | | copy.setRoutePlanRule(xpRoutePlan.getRoutePlanRule()); |
| | | R<List<RouteVo>> r = xpMapClient.getDistanceAndDurationList(copy); |
| | | if (r.getCode() != 200 || r.getData() == null || r.getData().isEmpty()) { |
| | | continue; |
| | | } |
| | | String fid = r.getData().getRouteID(); |
| | | routeById.putIfAbsent(fid, r.getData()); |
| | | strategiesById.computeIfAbsent(fid, k -> new LinkedHashSet<>()).add(kind); |
| | | bb: for (RouteVo datum : r.getData()) { |
| | | for (RouteVo routePoint : routePoints) { |
| | | if(CollUtil.isEqualList(routePoint.getPolyline(), datum.getPolyline())){ |
| | | continue bb; |
| | | } |
| | | } |
| | | routePoints.add(datum); |
| | | RouteStrategyKind routeStrategyKind = kinds.stream().filter(kind -> kind.getAmapStrategy() == xpRoutePlan.getRoutePlanRule()).findFirst().get(); |
| | | strategiesById.put(datum.getRouteID(), routeStrategyKind); |
| | | break; |
| | | } |
| | | } |
| | | if (routeById.isEmpty()) { |
| | | |
| | | if (routePoints.isEmpty()) { |
| | | throw new ServiceException("获取导肮信息失败", I18nKeyConstant.PATH_NOT_FOUND); |
| | | } |
| | | |
| | |
| | | if(null != xpSystemSetting) { |
| | | operateFree = xpSystemSetting.getOperateFree(); |
| | | } |
| | | |
| | | String snapshotId = UUID.randomUUID().toString().replace("-", ""); |
| | | List<RouteOptionVo> options = new ArrayList<>(); |
| | | for (Map.Entry<String, RouteVo> e : routeById.entrySet()) { |
| | | String fid = e.getKey(); |
| | | RouteVo rv = e.getValue(); |
| | | Set<RouteStrategyKind> kindsOnRoute = strategiesById.get(fid); |
| | | RouteStrategyKind primary = RouteStrategyKind.primaryOf(kindsOnRoute); |
| | | for (RouteVo routePoint : routePoints) { |
| | | RouteAndFareDto pricingDto = new RouteAndFareDto(); |
| | | pricingDto.setOrigin(routeAndFareDto.getOrigin()); |
| | | pricingDto.setDestination(routeAndFareDto.getDestination()); |
| | | pricingDto.setOpenCityId(routeAndFareDto.getOpenCityId()); |
| | | pricingDto.setUserCouponId(routeAndFareDto.getUserCouponId()); |
| | | pricingDto.setVehicleId(routeAndFareDto.getVehicleId()); |
| | | pricingDto.setRoutePlanRule(primary.getAmapStrategy()); |
| | | RouteAndFareVo part = pricingForRoute(pricingDto, rv, xpPricing, userId); |
| | | //计算导航对应的费用 |
| | | RouteAndFareVo part = pricingForRoute(pricingDto, routePoint, xpPricing, userId); |
| | | RouteOptionVo opt = new RouteOptionVo(); |
| | | opt.setPathFingerprint(fid); |
| | | List<String> labels = RouteStrategyKind.orderedOf(kindsOnRoute).stream() |
| | | .map(kind -> resolveStrategyDisplayName(kind, planningConfig.getDisplayNames())) |
| | | .collect(Collectors.toList()); |
| | | opt.setStrategyLabels(labels); |
| | | opt.setSnapshotId(snapshotId); |
| | | opt.setPathFingerprint(routePoint.getRouteID()); |
| | | RouteStrategyKind primary = strategiesById.get(routePoint.getRouteID()); |
| | | opt.setStrategyLabels(Arrays.asList(primary.getDisplayName())); |
| | | opt.setPrimaryStrategyLabel(resolveStrategyDisplayName(primary, planningConfig.getDisplayNames())); |
| | | opt.setPrimaryRoutePlanRule(primary.getAmapStrategy()); |
| | | opt.setPrimaryRoutePlanName(primary.getDisplayName()); |
| | |
| | | options.add(opt); |
| | | } |
| | | |
| | | // 根据 pathFingerprint 去重,保留第一次出现的路线 |
| | | // options = new ArrayList<>(options.stream() |
| | | // .collect(Collectors.toMap( |
| | | // RouteOptionVo::getPathFingerprint, |
| | | // option -> option, |
| | | // (existing, replacement) -> existing, |
| | | // LinkedHashMap::new |
| | | // )).values()); |
| | | |
| | | RouteStrategyKind userPref = resolveUserPreferredKind(userId).orElse(RouteStrategyKind.SMART); |
| | | options.sort((a, b) -> compareRouteOptionByUserPreference(a, b, userPref, strategiesById)); |
| | | options.sort((a, b) -> compareRouteOptionByUserPreference(a, b, userPref)); |
| | | |
| | | String snapshotId = UUID.randomUUID().toString().replace("-", ""); |
| | | long now = System.currentTimeMillis(); |
| | | MultiRouteSnapshotPayload payload = new MultiRouteSnapshotPayload(); |
| | | payload.setSnapshotId(snapshotId); |
| | |
| | | |
| | | R<XpTradingStrategyDetailVO> strategyDetailVOR = xpTradingStrategyClient.queryById(); |
| | | XpTradingStrategyDetailVO strategyDetailVO = strategyDetailVOR.getData(); |
| | | //将多线路数据缓存,用于后续确认操作 |
| | | redisService.setCacheObject(CacheConstants.ORDER_MULTI_ROUTE_SNAPSHOT + userId + ":" + snapshotId, JSON.toJSONString(payload), Long.valueOf(strategyDetailVO.getMaxStandingTiming()), TimeUnit.SECONDS); |
| | | |
| | | |
| | |
| | | vo.setStaleCheckSeconds(navigationStaleSeconds); |
| | | vo.setPriceWaveThresholdPercent(navigationPriceWavePercent); |
| | | vo.setOperateFree(operateFree); |
| | | |
| | | |
| | | RouteOptionVo first = options.get(0); |
| | | redisService.setCacheObject("ORDER_NAVIGATION_END_DATA:" + userId, JSON.toJSONString(first.getRoute()), 24L, TimeUnit.HOURS); |
| | | //产品喊写死 |
| | | vo.setMaxPeopleNumber(5); |
| | | return vo; |
| | | } |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | private int compareRouteOptionByUserPreference(RouteOptionVo a, RouteOptionVo b, RouteStrategyKind pref, |
| | | Map<String, Set<RouteStrategyKind>> strategiesById) { |
| | | Set<RouteStrategyKind> sa = strategiesById.getOrDefault(a.getPathFingerprint(), Collections.emptySet()); |
| | | Set<RouteStrategyKind> sb = strategiesById.getOrDefault(b.getPathFingerprint(), Collections.emptySet()); |
| | | boolean aHas = sa.contains(pref); |
| | | boolean bHas = sb.contains(pref); |
| | | if (aHas != bHas) { |
| | | return bHas ? 1 : -1; |
| | | private int compareRouteOptionByUserPreference(RouteOptionVo a, RouteOptionVo b, RouteStrategyKind pref) { |
| | | Integer primaryRoutePlanRule = a.getPrimaryRoutePlanRule(); |
| | | if(primaryRoutePlanRule == pref.getAmapStrategy()){ |
| | | return 1; |
| | | } |
| | | boolean aPrimary = a.getPrimaryRoutePlanRule() != null && a.getPrimaryRoutePlanRule() == pref.getAmapStrategy(); |
| | | boolean bPrimary = b.getPrimaryRoutePlanRule() != null && b.getPrimaryRoutePlanRule() == pref.getAmapStrategy(); |
| | | if (aPrimary != bPrimary) { |
| | | return bPrimary ? 1 : -1; |
| | | } |
| | | int da = a.getRoute() != null && a.getRoute().getDuration() != null ? a.getRoute().getDuration() : Integer.MAX_VALUE; |
| | | int db = b.getRoute() != null && b.getRoute().getDuration() != null ? b.getRoute().getDuration() : Integer.MAX_VALUE; |
| | | return Integer.compare(da, db); |
| | | return -1; |
| | | } |
| | | |
| | | @Override |
| | | public QueueStatusVo getQueueStatus(String orderId, String uid) { |
| | | QueueStatusVo queueStatusVo = new QueueStatusVo(); |
| | | |
| | | // 从订单服务获取订单信息,获取queueName |
| | | R<XpOrder> orderR = xpOrderClient.queryOrderById(Long.valueOf(orderId)); |
| | | if (orderR.getCode() != R.SUCCESS || orderR.getData() == null) { |
| | | throw new ServiceException("订单不存在"); |
| | | } |
| | | |
| | | XpOrder xpOrder = orderR.getData(); |
| | | String queueName = xpOrder.getQueueName(); |
| | | RLock lock = redissonClient.getLock("queue_lock_" + queueName); |
| | | try { |
| | | // 从订单服务获取订单信息,获取queueName |
| | | R<XpOrder> orderR = xpOrderClient.queryOrderById(Long.valueOf(orderId)); |
| | | if (orderR.getCode() != R.SUCCESS || orderR.getData() == null) { |
| | | throw new ServiceException("订单不存在"); |
| | | } |
| | | |
| | | XpOrder xpOrder = orderR.getData(); |
| | | String queueName = xpOrder.getQueueName(); |
| | | |
| | | if (StringUtils.isBlank(queueName)) { |
| | | // 订单不在排队中 |
| | | queueStatusVo.setStatus(1); |
| | | queueStatusVo.setCurrentPosition(0); |
| | | queueStatusVo.setTotalCount(0); |
| | | queueStatusVo.setEstimatedWaitTime(0); |
| | | return queueStatusVo; |
| | | } |
| | | |
| | | // 从Redis获取队列数据 |
| | | List<String> queueItems = redisService.getCacheList(queueName); |
| | | if (queueItems == null || queueItems.isEmpty()) { |
| | | // 队列为空,说明已分配车辆 |
| | | queueStatusVo.setStatus(1); |
| | | queueStatusVo.setCurrentPosition(0); |
| | | queueStatusVo.setTotalCount(0); |
| | | queueStatusVo.setEstimatedWaitTime(0); |
| | | return queueStatusVo; |
| | | } |
| | | |
| | | // 遍历队列,找到当前订单的位置 |
| | | int currentPosition = 0; |
| | | int totalCount = queueItems.size(); |
| | | |
| | | for (int i = 0; i < queueItems.size(); i++) { |
| | | String item = queueItems.get(i); |
| | | if (item.startsWith(orderId + "_")) { |
| | | currentPosition = i + 1; // 位置从1开始 |
| | | break; |
| | | if(lock.tryLock(2, 5, TimeUnit.SECONDS)){ |
| | | if (StringUtils.isEmpty(queueName)) { |
| | | // 订单不在排队中 |
| | | queueStatusVo.setStatus(1); |
| | | queueStatusVo.setCurrentPosition(0); |
| | | queueStatusVo.setTotalCount(0); |
| | | queueStatusVo.setEstimatedWaitTime(0); |
| | | log.info("订单不在排队中: {}", orderId); |
| | | return queueStatusVo; |
| | | } |
| | | |
| | | // 从Redis获取队列数据 |
| | | List<String> queueItems = redisService.getCacheList(queueName); |
| | | if (queueItems == null || queueItems.isEmpty()) { |
| | | log.error("列表为空: {}", orderId); |
| | | // 队列为空,说明已分配车辆 |
| | | queueStatusVo.setStatus(1); |
| | | queueStatusVo.setCurrentPosition(0); |
| | | queueStatusVo.setTotalCount(0); |
| | | queueStatusVo.setEstimatedWaitTime(0); |
| | | return queueStatusVo; |
| | | } |
| | | log.info("排队队列数据 {}", JSON.toJSONString(queueItems)); |
| | | // 遍历队列,找到当前订单的位置 |
| | | int currentPosition = 0; |
| | | int totalCount = queueItems.size(); |
| | | |
| | | for (int i = 0; i < queueItems.size(); i++) { |
| | | currentPosition++; |
| | | String item = queueItems.get(i); |
| | | String[] split = item.split("_"); |
| | | if (split[0].equals(orderId + "")) { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | Integer waitTimeTimeSlot = getWaitTimeTimeSlot(xpOrder.getStartLon(), xpOrder.getStartLat(), xpOrder.getTimeSlot()); |
| | | queueStatusVo.setStatus(0); // 0-排队中 |
| | | queueStatusVo.setCurrentPosition(currentPosition); |
| | | queueStatusVo.setTotalCount(totalCount); |
| | | queueStatusVo.setEstimatedWaitTime((waitTimeTimeSlot*currentPosition)/60); |
| | | } |
| | | |
| | | Integer waitTimeTimeSlot = getWaitTimeTimeSlot(xpOrder.getStartLon(), xpOrder.getStartLat(), xpOrder.getTimeSlot()); |
| | | queueStatusVo.setStatus(0); // 0-排队中 |
| | | queueStatusVo.setCurrentPosition(currentPosition); |
| | | queueStatusVo.setTotalCount(totalCount); |
| | | queueStatusVo.setEstimatedWaitTime((waitTimeTimeSlot*currentPosition)/60); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("查询排队状态失败: {}", e.getMessage(), e); |
| | | // 异常情况下返回默认值 |
| | | queueStatusVo.setStatus(0); |
| | | queueStatusVo.setCurrentPosition(0); |
| | | queueStatusVo.setTotalCount(0); |
| | | queueStatusVo.setEstimatedWaitTime(0); |
| | | }finally { |
| | | lock.unlock(); |
| | | } |
| | | |
| | | return queueStatusVo; |
| | | } |
| | | |