| | |
| | | import com.xiaopeng.api.feignClient.account.XpAppUserClient; |
| | | import com.xiaopeng.api.feignClient.account.XpAppUserCouponClient; |
| | | import com.xiaopeng.api.feignClient.map.XpMapClient; |
| | | import com.xiaopeng.api.feignClient.operation.XpPointClient; |
| | | import com.xiaopeng.api.feignClient.order.XpOrderClient; |
| | | import com.xiaopeng.api.feignClient.pushMessage.XpPushMessageClient; |
| | | import com.xiaopeng.api.model.account.XpAppUser; |
| | |
| | | import com.xiaopeng.itinerary.utils.XpPricingUtil; |
| | | import com.xiaopeng.itinerary.utils.holiday.HolidayUtil; |
| | | import com.xiaopeng.itinerary.utils.map.FastDistanceCalculator; |
| | | import com.xiaopeng.itinerary.utils.map.GDMapGeocodingUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | |
| | | @Resource |
| | | private XpPushMessageClient xpPushMessageClient; |
| | | |
| | | @Resource |
| | | private GDMapGeocodingUtil gdMapGeocodingUtil; |
| | | |
| | | @Resource |
| | | private XpPointClient xpPointClient; |
| | | |
| | | |
| | | // 自定义线程池用于并行执行任务 |
| | | private final ExecutorService executorService; |
| | |
| | | |
| | | @Override |
| | | public RouteAndFareVo getRouteAndFare(RouteAndFareDto routeAndFareDto, String userId) { |
| | | |
| | | |
| | | // 判断是否5分钟内进行了查询 相同站点的起始点 并且是同时段 |
| | | String key = "xp-map-query-" + routeAndFareDto.getOpenCityId() |
| | | + "-" + routeAndFareDto.getOrigin().getLongitude() + "-" + routeAndFareDto.getOrigin().getLatitude() |
| | |
| | | } |
| | | |
| | | // 1. 基础数据查询 |
| | | XpOpenCity xpOpenCity = xpOpenCityMapper.selectById(routeAndFareDto.getOpenCityId()); |
| | | if (xpOpenCity == null) { |
| | | throw new ServiceException("未找到步行路线", I18nKeyConstant.CITY_INFORMATION_DOES_NOT_EXIST); |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(routeAndFareDto.getOrigin().getLongitude().toString(), routeAndFareDto.getOrigin().getLatitude().toString()); |
| | | if(null == geocode){ |
| | | throw new ServiceException("获取城市信息失败", I18nKeyConstant.CITY_NOT_FOUND); |
| | | } |
| | | String cityCode = xpOpenCity.getCityCode(); |
| | | |
| | | String cityCode = geocode.get("cityCode"); |
| | | List<XpOpenCity> openCities = xpOpenCityMapper.selectList(new LambdaQueryWrapper<XpOpenCity>().eq(XpOpenCity::getCityCode, cityCode)); |
| | | if (openCities == null || openCities.isEmpty()) { |
| | | throw new ServiceException("获取城市信息失败", I18nKeyConstant.CITY_NOT_FOUND); |
| | | } |
| | | XpOpenCity xpOpenCity = openCities.get(0); |
| | | routeAndFareDto.setOpenCityId(xpOpenCity.getId()); |
| | | XpRoutePlan xpRoutePlan = xpRoutePlanMapper.selectOne(new LambdaQueryWrapper<XpRoutePlan>().eq(XpRoutePlan::getAuditStatus, 2).eq(XpRoutePlan::getCityCode, cityCode)); |
| | | if (xpRoutePlan != null) { |
| | | routeAndFareDto.setRoutePlanRule(xpRoutePlan.getRoutePlanRule()); |
| | |
| | | // // 算距离 |
| | | R<RouteVo> distanceAndDuration = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | | if (distanceAndDuration.getCode() != 200) { |
| | | throw new ServiceException("未找到路径", I18nKeyConstant.PATH_NOT_FOUND); |
| | | throw new ServiceException("获取导肮信息失败", I18nKeyConstant.PATH_NOT_FOUND); |
| | | } |
| | | |
| | | |
| | | RouteVo routeVo = distanceAndDuration.getData(); |
| | | |
| | | // 2. 计算价格(需要在并行任务前完成,因为优惠券查询需要价格) |
| | | |
| | | XpPricingCardVo xpPricingCardVo; |
| | | if (xpPricing.getPricingType() == 1) { |
| | | xpPricingCardVo = xpPricingUtil.calculationPrice(userId, |
| | |
| | | XpPoint endXpPoint = xpPointService.getById(dto.getEndPointId()); |
| | | |
| | | // 判断点位是否在运营区域内 |
| | | LocalTime now = LocalTime.now(); |
| | | boolean inTime = xpPointService.getInTime(now, xpPoint.getEffectivePeriod(), xpPoint.getEffectiveTimePeriod()); |
| | | boolean inTime = xpPointClient.nowInTimePoint(dto.getStartPointId()).getData(); |
| | | if (!inTime) { |
| | | throw new ServiceException("当前点位未开通服务", I18nKeyConstant.NO_CURRENT_REGION); |
| | | } |
| | | inTime = xpPointService.getInTime(now, endXpPoint.getEffectivePeriod(), endXpPoint.getEffectiveTimePeriod()); |
| | | inTime = xpPointClient.nowInTimePoint(dto.getEndPointId()).getData(); |
| | | if (!inTime) { |
| | | throw new ServiceException("当前点位未开通服务", I18nKeyConstant.NO_CURRENT_REGION); |
| | | } |