| | |
| | | package com.xiaopeng.pushMessage.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.xiaopeng.api.dto.operation.LonLatDto; |
| | | import com.xiaopeng.api.dto.pushMessage.PushOrderRouteDTO; |
| | |
| | | import com.xiaopeng.api.model.order.XpOrder; |
| | | import com.xiaopeng.api.vo.operation.RouteVo; |
| | | import com.xiaopeng.common.core.constant.CacheConstants; |
| | | import com.xiaopeng.common.core.constant.Constants; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.enums.PushMessageTypeEnum; |
| | | import com.xiaopeng.common.redis.service.RedisService; |
| | | import com.xiaopeng.pushMessage.utils.MapMatchingUtil; |
| | | import io.swagger.annotations.Api; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.powermock.core.ListMap; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.*; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @Slf4j |
| | | @Api(tags = "订单推送轨迹接口") |
| | | @RestController |
| | | @RequestMapping("") |
| | |
| | | if(routeType == 2){ |
| | | routeType = 3; |
| | | }else { |
| | | routeType = xpOrder.getStatus() == 3 ? 1 : 2; |
| | | routeType = xpOrder.getStatus() == 2 || xpOrder.getStatus() == 3 ? 1 : 2; |
| | | } |
| | | // 获取路线规划 |
| | | String key = ""; |
| | |
| | | if(Objects.nonNull(routeVo)){ |
| | | |
| | | // 计算实时点位到线段的最优截取 |
| | | List<LonLatDto> lonLatDtos = MapMatchingUtil.clipBySegmentDistance(routeVo.getPolyline(), new LonLatDto(dto.getLongitude(), dto.getLatitude())); |
| | | List<LonLatDto> lonLatDtos = MapMatchingUtil.getRemainingNavigation(routeVo.getPolyline(), dto.getLongitude(), dto.getLatitude()); |
| | | |
| | | routeVo.setDistance(dto.getDistance()); |
| | | routeVo.setDuration(dto.getDuration()); |
| | | routeVo.setPolyline(lonLatDtos); |
| | | |
| | | // 存储最新路线偏离缓存,后续进行轨迹截取 |
| | | // redisService.setCacheObject(CacheConstants.ORDER_ROUTE_CAPTURE + "_" + dto.getOrderId() + "_" +routeType, routeVo); |
| | | |
| | | redisService.setCacheObject(key, JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS); |
| | | |
| | | // 封装轨迹点位集合 |
| | |
| | | route.put("polyline",JSONObject.toJSONString(polyline)); |
| | | |
| | | Map<String, Object> content = new HashMap<>(); |
| | | content.put("orderId",dto.getOrderId()); |
| | | content.put("orderId",dto.getOrderId().toString()); |
| | | content.put("routeType",routeType); |
| | | content.put("direction",dto.getDirection()); |
| | | content.put("route",JSONObject.toJSONString(route)); |
| | |
| | | SendMessageDTO sendMessageDTO = new SendMessageDTO(); |
| | | sendMessageDTO.setAppUserId(String.valueOf(xpOrder.getAppUserId())); |
| | | sendMessageDTO.setMessage(JSONObject.toJSONString(params)); |
| | | xpPushMessageClient.sendRoute(sendMessageDTO); |
| | | R<String> stringR = xpPushMessageClient.sendRoute(sendMessageDTO); |
| | | //推送失败,重试3次 |
| | | if(stringR.getCode() != Constants.SUCCESS){ |
| | | ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>()); |
| | | executor.execute(() -> { |
| | | for (int i = 0; i < 3; i++) { |
| | | R<String> stringR1 = xpPushMessageClient.sendStatus(sendMessageDTO); |
| | | if(stringR1.getCode() == Constants.SUCCESS){ |
| | | break; |
| | | } |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | log.info("推送乘客端剩余导航数据消息失败:{} {} {}", stringR1.getMsg(), JSON.toJSONString(sendMessageDTO), xpOrder.getOrderNumber()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | log.info("推送剩余导航数据成功 {} {}", xpOrder.getOrderNumber(), JSON.toJSONString(routeVo)); |
| | | } |
| | | return R.ok(); |
| | | } |