| | |
| | | import com.xiaopeng.api.feignClient.operation.XpPointClient; |
| | | import com.xiaopeng.api.feignClient.operation.XpPricingClient; |
| | | import com.xiaopeng.api.model.account.XpAppUser; |
| | | import com.xiaopeng.api.model.operation.XpPoint; |
| | | import com.xiaopeng.api.model.operation.XpPricing; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpFleet; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpVehicle; |
| | |
| | | import com.xiaopeng.api.model.order.XpOrderEvaluate; |
| | | import com.xiaopeng.api.model.order.XpOrderReassign; |
| | | import com.xiaopeng.api.vo.account.UserCouponVo; |
| | | import com.xiaopeng.api.vo.order.FareBreakdownVo; |
| | | import com.xiaopeng.api.vo.order.XpHistoryEndPointsVo; |
| | | import com.xiaopeng.api.vo.order.XpHistoryStartPointsVo; |
| | | import com.xiaopeng.api.vo.order.XpPointInfoVo; |
| | | import com.xiaopeng.api.vo.order.*; |
| | | import com.xiaopeng.api.vo.vehicleConvoy.CancelTaxiPassengerVo; |
| | | import com.xiaopeng.common.core.constant.CacheConstants; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | | import com.xiaopeng.common.core.utils.DateUtils; |
| | | import com.xiaopeng.common.core.utils.GeodesyUtil; |
| | | import com.xiaopeng.common.core.utils.StringUtils; |
| | | import com.xiaopeng.common.core.web.domain.BaseModel; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | |
| | | import com.xiaopeng.common.security.utils.SecurityUtils; |
| | | import com.xiaopeng.order.constant.I18nKeyConstant; |
| | | import com.xiaopeng.order.job.jobs.EndTripJob; |
| | | import com.xiaopeng.order.mangodb.model.OrderTrajectory; |
| | | import com.xiaopeng.order.mangodb.service.OrderTrajectoryService; |
| | | import com.xiaopeng.order.mangodb.model.OrderTrajectory; |
| | | import com.xiaopeng.order.mapper.XpOrderMapper; |
| | | import com.xiaopeng.order.model.dto.XpOrderCommentDto; |
| | | import com.xiaopeng.order.model.dto.XpOrderPayDto; |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | private final RedisService redisService; |
| | | private final XpPricingClient xpPricingClient; |
| | | private final XpSystemSettingClient xpSystemSettingClient; |
| | | private final OrderTrajectoryService orderTrajectoryService; |
| | | |
| | | @Autowired |
| | | private MongoTemplate mongoTemplate; |
| | | // @Autowired |
| | | // private XpPricingUtil xpPricingUtil; |
| | | |
| | | @Override |
| | | public OrderStatisticsDTO getOrderStatistics(StatisticsQueryDTO query) { |
| | |
| | | evaluate.setAppUserId(Long.valueOf(uid)); |
| | | evaluate.setOrderRating(dto.getOrderRating()); |
| | | evaluate.setEvaluateTime(LocalDateTime.now()); |
| | | evaluate.setFeedbackContent(dto.getFeedbackContent()); |
| | | evaluate.setFeedbackPictures(dto.getFeedbackPictures()); |
| | | evaluate.setFeedbackTypeId(dto.getFeedbackTypeId()); |
| | | xpOrderEvaluateService.save(evaluate); |
| | | |
| | | } |
| | |
| | | xpOrder.setStatus(status); |
| | | switch (status) { |
| | | case 4: |
| | | // 添加取消订单定时任务job |
| | | // 查询起点点位 |
| | | Long startPointId = xpOrder.getStartPointId(); |
| | | XpPoint xpPoint = xpPointClient.queryById(startPointId).getData(); |
| | | // 添加取消订单定时任务job 时间为点位限停时长 |
| | | Map<String, ? extends Object> cancelJobMaps = |
| | | new ImmutableMap.Builder<String, Long>(). |
| | | put("id", xpOrder.getId()) |
| | |
| | | OrderCancelJob.class, |
| | | (OrderCancelJob.name + xpOrder.getId()).toUpperCase(), |
| | | TimeJobType.ORDER_CANCEL, |
| | | DateUtils.localDateTimeToDate(LocalDateTime.now().plusMinutes(5)), |
| | | DateUtils.localDateTimeToDate(LocalDateTime.now().plusMinutes(xpPoint.getParkingTimeLimit())), |
| | | cancelJobMaps |
| | | ); |
| | | // 车辆到达上车点时间 |
| | |
| | | if (pricing == null) { |
| | | throw new ServiceException("当前城市未配置定价规则", I18nKeyConstant.ORDER_PRICING_NOT_EXISTS); |
| | | } |
| | | Long id = pricing.getId(); |
| | | Integer pricingType = pricing.getPricingType(); |
| | | String basicPricingJson = pricing.getBasicPricingJson(); |
| | | String startingFareJson = pricing.getStartingFareJson(); |
| | | String dynamicPricingJson = pricing.getDynamicPricingJson(); |
| | | String priceRule = pricing.getPriceRule(); |
| | | // 根据计价规则计算费用 |
| | | BigDecimal startMoney = BigDecimal.ZERO;// 起步价 |
| | | BigDecimal mileageMoney = BigDecimal.ZERO;// 里程费 |
| | | BigDecimal durationMoney = BigDecimal.ZERO;// 时长费 |
| | | BigDecimal waitMoney = BigDecimal.ZERO;// 等待费 |
| | | BigDecimal longDistancemoney = BigDecimal.ZERO;// 远途费 |
| | | BigDecimal redPacketMoney = BigDecimal.ZERO;// 红包抵扣金额 |
| | | BigDecimal couponMoney = BigDecimal.ZERO;// 优惠券抵扣金额 |
| | | if (pricingType == 1) { |
| | | |
| | | } else { |
| | | // 查询订单轨迹 |
| | | List<OrderTrajectory> trajectories = mongoTemplate.find( |
| | | new Query(Criteria.where("orderId").is(orderId)) |
| | | .with(Sort.by(Sort.Direction.ASC, "locatetime")), |
| | | OrderTrajectory.class |
| | | ); |
| | | // 计算等待时间 |
| | | LocalDateTime boardingTime = order.getBoardingTime();// 上车时间 |
| | | LocalDateTime arrivalTime = order.getArrivalTime();// 车辆到达上车点时间 |
| | | // 行程开始时间 |
| | | Integer waitTime =Math.abs( (int) Duration.between(boardingTime, arrivalTime).getSeconds()); |
| | | // 计算订单总行驶距离,单位米 |
| | | Double totalDistance = 0.00D; |
| | | // 行程总时间 秒 |
| | | LocalDateTime tripBegin = order.getTripBegin(); |
| | | LocalDateTime tripEnd = order.getTripEnd(); |
| | | long seconds = Duration.between(tripBegin, tripEnd).getSeconds(); |
| | | for (OrderTrajectory trajectory : trajectories) { |
| | | |
| | | } |
| | | if (org.springframework.util.StringUtils.hasLength(basicPricingJson)) { |
| | | // XpPricingCardVo xpPricingCardVo = xpPricingUtil.calculationPrice( |
| | | // order.getAppUserId().toString(),JSON.parseObject(pricing.getBasicPricingJson()), |
| | | // JSON.parseArray(pricing.getStartingFareJson()), |
| | | // pricing.getDynamicPricingJson(), |
| | | // pricing.getIsDynamicPrice(), |
| | | // totalDistance, |
| | | // seconds, |
| | | // order.getCityId() |
| | | // ); |
| | | |
| | | } |
| | | if (org.springframework.util.StringUtils.hasLength(startingFareJson)) { |
| | | // Long id = pricing.getId(); |
| | | // Integer pricingType = pricing.getPricingType(); |
| | | // String basicPricingJson = pricing.getBasicPricingJson(); |
| | | // String startingFareJson = pricing.getStartingFareJson(); |
| | | // String dynamicPricingJson = pricing.getDynamicPricingJson(); |
| | | // String priceRule = pricing.getPriceRule(); |
| | | // // 根据计价规则计算费用 |
| | | // BigDecimal startMoney = BigDecimal.ZERO;// 起步价 |
| | | // BigDecimal mileageMoney = BigDecimal.ZERO;// 里程费 |
| | | // BigDecimal durationMoney = BigDecimal.ZERO;// 时长费 |
| | | // BigDecimal waitMoney = BigDecimal.ZERO;// 等待费 |
| | | // BigDecimal longDistancemoney = BigDecimal.ZERO;// 远途费 |
| | | // BigDecimal redPacketMoney = BigDecimal.ZERO;// 红包抵扣金额 |
| | | // BigDecimal couponMoney = BigDecimal.ZERO;// 优惠券抵扣金额 |
| | | // if (pricingType == 1) { |
| | | // |
| | | // } else { |
| | | // |
| | | // } |
| | | // if (org.springframework.util.StringUtils.hasLength(basicPricingJson)) { |
| | | // |
| | | // } |
| | | // if (org.springframework.util.StringUtils.hasLength(startingFareJson)) { |
| | | // |
| | | // } |
| | | // if (org.springframework.util.StringUtils.hasLength(dynamicPricingJson)) { |
| | | // |
| | | // } |
| | | // if (org.springframework.util.StringUtils.hasLength(priceRule)) { |
| | | // |
| | | // } |
| | | |
| | | } |
| | | if (org.springframework.util.StringUtils.hasLength(dynamicPricingJson)) { |
| | | |
| | | } |
| | | if (org.springframework.util.StringUtils.hasLength(priceRule)) { |
| | | |
| | | } |
| | | // 计算完价格后 挑选优惠券 |
| | | GetUserCouponDto getUserCouponDto = new GetUserCouponDto(); |
| | | // 计算完价格后 挑选优惠券 |
| | | GetUserCouponDto getUserCouponDto = new GetUserCouponDto(); |
| | | getUserCouponDto.setUserId(Long.valueOf(uid)); |
| | | getUserCouponDto.setTotalAmount(order.getOrderMoney().doubleValue()); |
| | | R<UserCouponVo> userCouponVoR = xpAppUserCouponClient.getUserCoupon(getUserCouponDto); |
| | |
| | | @Override |
| | | public R<FareBreakdownVo> fareBreakdown(Long orderId, String uid) { |
| | | XpOrder order = this.getById(orderId); |
| | | FareBreakdownVo fareBreakdownVo = new FareBreakdownVo(); |
| | | BeanUtils.copyProperties(order, fareBreakdownVo); |
| | | fareBreakdownVo.setTotalKilometers( |
| | | BigDecimal.valueOf(order.getStartMileage() + order.getMileageKilometers() + order.getLongDistance()) |
| | | // 查询订单轨迹 |
| | | List<OrderTrajectory> trajectories = mongoTemplate.find( |
| | | new Query(Criteria.where("orderId").is(orderId)) |
| | | .with(Sort.by(Sort.Direction.ASC, "locatetime")), |
| | | OrderTrajectory.class |
| | | ); |
| | | LocalDateTime createTime = order.getCreateTime(); |
| | | LocalDateTime tripEnd = order.getTripEnd(); |
| | | // 计算行程时间 单位分钟 |
| | | // 计算订单总行驶距离,单位米 |
| | | Double totalDistance = 0.00D; |
| | | for (OrderTrajectory trajectory : trajectories) { |
| | | |
| | | // 计算时间差 |
| | | Duration duration = Duration.between(createTime, tripEnd); |
| | | |
| | | // 转换为分钟并保留一位小数 |
| | | BigDecimal minutes = BigDecimal.valueOf(duration.getSeconds()) |
| | | .divide(BigDecimal.valueOf(60), 1, RoundingMode.HALF_UP); |
| | | } |
| | | FareBreakdownVo fareBreakdownVo = new FareBreakdownVo(); |
| | | // fareBreakdownVo.setStart(); |
| | | // fareBreakdownVo.setMileage(); |
| | | // fareBreakdownVo.setDuration(); |
| | | // fareBreakdownVo.setLongDistance(); |
| | | // fareBreakdownVo.setRedPacketMoney(); |
| | | // fareBreakdownVo.setCouponMoney(); |
| | | // fareBreakdownVo.setOrderMoney(); |
| | | |
| | | fareBreakdownVo.setTotalTime(minutes); |
| | | // BeanUtils.copyProperties(order, fareBreakdownVo); |
| | | // fareBreakdownVo.setTotalKilometers( |
| | | // BigDecimal.valueOf(order.getStartMileage() + order.getMileageKilometers() + order.getLongDistance()) |
| | | // ); |
| | | // LocalDateTime createTime = order.getCreateTime(); |
| | | // LocalDateTime tripEnd = order.getTripEnd(); |
| | | // // 计算行程时间 单位分钟 |
| | | // |
| | | // // 计算时间差 |
| | | // Duration duration = Duration.between(createTime, tripEnd); |
| | | // |
| | | // // 转换为分钟并保留一位小数 |
| | | // BigDecimal minutes = BigDecimal.valueOf(duration.getSeconds()) |
| | | // .divide(BigDecimal.valueOf(60), 1, RoundingMode.HALF_UP); |
| | | // |
| | | // fareBreakdownVo.setTotalTime(minutes); |
| | | return R.ok(fareBreakdownVo); |
| | | } |
| | | |
| | |
| | | |
| | | /** |
| | | * 添加订单 |
| | | * |
| | | * @param xpOrder |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获取订单数量 |
| | | * |
| | | * @param dto |
| | | * @return |
| | | */ |
| | |
| | | return num.intValue(); |
| | | } |
| | | |
| | | @Override |
| | | public void saveVehicleLocation(OrderTrajectory orderTrajectory) { |
| | | // 查询订单信息 |
| | | XpOrder xpOrder = this.getById(orderTrajectory.getOrderId()); |
| | | |
| | | // 计算距离 |
| | | // 获取上一次定位 |
| | | String oldLocation = redisService.getCacheObject(CacheConstants.ORDER_OLD_LOCATION + orderTrajectory.getOrderId()); |
| | | if(StringUtils.isEmpty(oldLocation)){ |
| | | // 首次定位 |
| | | xpOrder.setMileageKilometers(0D); |
| | | this.updateById(xpOrder); |
| | | orderTrajectory.setDistance(0D); |
| | | // 存储mongo数据 |
| | | orderTrajectoryService.create(orderTrajectory); |
| | | // 存储首次定位 |
| | | redisService.setCacheObject(CacheConstants.ORDER_OLD_LOCATION + orderTrajectory.getOrderId(), orderTrajectory.getLocation()); |
| | | }else { |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(orderTrajectory.getLocation(), oldLocation); |
| | | if(null != distance){ |
| | | Double distance1 = distance.get("WGS84"); |
| | | if(distance1 > 50 && xpOrder.getStatus() == 6){//大于50米表示在移动,且在服务中的时候记录里程 |
| | | xpOrder.setMileageKilometers(BigDecimal.valueOf(xpOrder.getMileageKilometers()).add(new BigDecimal(distance1)).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | this.updateById(xpOrder); |
| | | // 存储本次距离 |
| | | orderTrajectory.setDistance(distance1); |
| | | // 存储mongo数据 |
| | | orderTrajectoryService.create(orderTrajectory); |
| | | } |
| | | }else{ |
| | | log.error("调用高德计算距离出错"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取当前用户正在执行的订单 |