package com.xiaopeng.order.controller;
|
|
import com.alibaba.fastjson2.JSON;
|
import com.xiaopeng.api.dto.QueryOrderRouteDTO;
|
import com.xiaopeng.api.feignClient.operation.XpPointClient;
|
import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient;
|
import com.xiaopeng.api.model.operation.XpPoint;
|
import com.xiaopeng.api.model.order.XpOrder;
|
import com.xiaopeng.api.model.vehicleConvoy.XpVehicle;
|
import com.xiaopeng.api.vo.automaticPilot.VehiclePosition;
|
import com.xiaopeng.api.vo.operation.RouteVo;
|
import com.xiaopeng.common.core.domain.R;
|
import com.xiaopeng.common.redis.service.RedisService;
|
import com.xiaopeng.order.model.vo.XpOrderDetailVO;
|
import com.xiaopeng.order.service.IXpOrderService;
|
import com.xiaopeng.unifiedverification.interceptor.XpClientCheck;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.RequiredArgsConstructor;
|
import org.apache.commons.lang3.StringUtils;
|
import org.jetbrains.annotations.Nullable;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
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.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import java.time.Duration;
|
import java.time.LocalDateTime;
|
|
@RestController
|
@Api(tags = "订单")
|
@RequiredArgsConstructor
|
public class ActiveOrderController {
|
|
|
@Autowired
|
private MongoTemplate mongoTemplate;
|
|
@Resource
|
XpOrderController xpOrderController;
|
@Resource
|
private final IXpOrderService xpOrderService;
|
@Resource
|
private final XpPointClient xpPointClient;
|
@Resource
|
private final XpVehicleClient xpVehicleClient;
|
@Resource
|
private RedisService redisService;
|
|
|
private R<XpOrder> getOrderTripEnd(String orderId) {
|
XpOrder xpOrder = xpOrderService.getById(orderId);
|
if(xpOrder == null){
|
return R.fail("订单不存在");
|
}
|
if(xpOrder.getTripEnd() != null){
|
Duration duration = Duration.between(xpOrder.getTripEnd(), LocalDateTime.now());
|
if(duration.toHours()>=24){
|
return R.fail("行程结束已超过24小时查看行程信息,请联系客服");
|
}
|
}
|
return R.ok(xpOrder);
|
}
|
|
|
/**
|
* 分享行程接口1-订单查询实时轨迹路线
|
*/
|
@ApiOperation(value = "分享行程接口1 订单查询实时轨迹路线")
|
@GetMapping("/base/v1/mini-program/orderActive/share/queryOrderRoute/{orderId}")
|
@XpClientCheck(checkToken = false, checkOtpToken = false)
|
public R<RouteVo> queryOrderRoute(@PathVariable("orderId") String orderId, HttpServletRequest request) {
|
// 查询订单信息
|
if(StringUtils.isBlank(orderId) ){
|
return R.fail("参数不能为空");
|
}
|
R r = getOrderTripEnd(orderId);
|
if (r != null && r.getCode() != 200) {
|
return r;
|
}
|
|
// 查询订单信息
|
XpOrder xpOrder = xpOrderService.getById(orderId);
|
|
String key = "";
|
//接驾情况,获取车辆位置到起点的导航
|
if (xpOrder.getStatus() < 5) {
|
key = "ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId();
|
}
|
//服务中,获取起点到终点的导航数据
|
if (xpOrder.getStatus() >= 5) {
|
key = "ORDER_NAVIGATION_END_DATA:" + xpOrder.getAppUserId();
|
}
|
Object cacheObject = redisService.getCacheObject(key);
|
if(cacheObject == null){
|
return R.fail("获取路线失败");
|
}
|
RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class);
|
XpVehicle xpVehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData();
|
VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), VehiclePosition.class);
|
routeVo.setDirection(null != vehiclePosition ? vehiclePosition.getCourse() : 90);
|
return R.ok(routeVo);
|
}
|
|
/**
|
* 分享行程接口2-订单查询轨迹路线
|
*/
|
@ApiOperation(value = "分享行程接口2-订单查询轨迹路线")
|
@GetMapping("/base/v1/mini-program/orderActive/share/queryOrderTrajectory")
|
@XpClientCheck(checkToken = false, checkOtpToken = false)
|
public R<RouteVo> queryOrderTrajectory(@RequestParam String orderId,HttpServletRequest request) {
|
if(StringUtils.isBlank(orderId) ){
|
return R.fail("参数不能为空");
|
}
|
R r = getOrderTripEnd(orderId);
|
if (r != null && r.getCode() != 200) {
|
return r;
|
}
|
return xpOrderController.queryOrderTrajectory(orderId,request);
|
}
|
|
|
/**
|
* 分享行程接口3-订单信息
|
*/
|
@ApiOperation(value = "分享行程接口3-订单信息查询")
|
@GetMapping("/base/v1/mini-program/orderActive/share/orderInfo")
|
@XpClientCheck(checkToken = false, checkOtpToken = false)
|
public R<XpOrderDetailVO> shareOrderInfo(@RequestParam String orderId, HttpServletRequest request) {
|
// 查询订单信息
|
if(orderId == null){
|
return R.fail("参数不能为空");
|
}
|
R<XpOrder> r = getOrderTripEnd(orderId);
|
if (r != null && r.getCode() != 200) {
|
return R.fail(r.getMsg());
|
}
|
|
XpOrder xpOrder = r.getData();
|
XpOrderDetailVO xpOrderDetailVO = new XpOrderDetailVO();
|
BeanUtils.copyProperties(xpOrder, xpOrderDetailVO);
|
|
R<XpPoint> xpPointR = xpPointClient.queryById(xpOrder.getStartPointId());
|
if (xpPointR.getCode() == R.SUCCESS) {
|
XpPoint startPoint = xpPointR.getData();
|
xpOrderDetailVO.setStartParkingTimeLimit(startPoint.getParkingTimeLimit());
|
}
|
|
R<XpPoint> xpPointR1 = xpPointClient.queryById(xpOrder.getEndPointId());
|
if (xpPointR1.getCode() == R.SUCCESS) {
|
XpPoint endPoint = xpPointR1.getData();
|
xpOrderDetailVO.setEndParkingTimeLimit(endPoint.getParkingTimeLimit());
|
}
|
if (xpOrder.getVehicleId() != null) {
|
R<XpVehicle> xpVehicleR = xpVehicleClient.queryById(xpOrder.getVehicleId());
|
XpVehicle vehicle = xpVehicleR.getData();
|
xpOrderDetailVO.setVehicleId(vehicle.getId());
|
xpOrderDetailVO.setVehicleVin(vehicle.getVehicleVin());
|
xpOrderDetailVO.setVehicleModel(vehicle.getVehicleModelName());
|
xpOrderDetailVO.setVehicleCode(vehicle.getVehicleCode());
|
xpOrderDetailVO.setVehicleColor(vehicle.getVehicleColor());
|
xpOrderDetailVO.setPlateNumber(vehicle.getPlateNumber());
|
xpOrderDetailVO.setVehiclePictures(vehicle.getVehiclePictures());
|
}
|
return R.ok(xpOrderDetailVO);
|
}
|
}
|