Pu Zhibing
2025-03-24 a88ba6b7606a73086cadb02c6115c3c01ce03f3e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.ruoyi.system.controller;
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.dataInterchange.api.feignClient.PlaybackMsgClient;
import com.ruoyi.dataInterchange.api.feignClient.UPExgMsgRealLocationClient;
import com.ruoyi.dataInterchange.api.vo.OrderTravelVo;
import com.ruoyi.dataInterchange.api.vo.UPPlaybackMsgStartupAckVo;
import com.ruoyi.system.api.model.Car;
import com.ruoyi.system.api.model.Driver;
import com.ruoyi.system.api.model.Enterprise;
import com.ruoyi.system.api.model.Order;
import com.ruoyi.system.query.OrderListReq;
import com.ruoyi.system.query.RealVideoResp;
import com.ruoyi.system.service.ICarService;
import com.ruoyi.system.service.IDriverService;
import com.ruoyi.system.service.IEnterpriseService;
import com.ruoyi.system.service.IOrderService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.List; /**
 * @author zhibing.pu
 * @Date 2025/3/24 17:50
 */
@RestController
@RequestMapping("/order")
public class OrderController {
 
    @Resource
    private IOrderService orderService;
    
    @Resource
    private IDriverService driverService;
    
    @Resource
    private ICarService carService;
    
    @Resource
    private IEnterpriseService enterpriseService;
    
    @Resource
    private UPExgMsgRealLocationClient upExgMsgRealLocationClient;
    
    @Resource
    private PlaybackMsgClient playbackMsgClient;
    
    
    
    
    @GetMapping("/getOrderList")
    @ApiOperation(value = "获取订单列表", tags = {"车辆管理", "订单管理"})
    public R<PageInfo<Order>> getOrderList(OrderListReq req){
        PageInfo<Order> orderList = orderService.getOrderList(req);
        return R.ok(orderList);
    }
    
    
    
    @GetMapping("/getOrderInfo/{id}")
    @ApiOperation(value = "获取订单详情", tags = {"订单管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "id", required = true)
    })
    public R<Order> getOrderInfo(@PathVariable("id") Integer id){
        Order order = orderService.getById(id);
        if(null == order){
            return R.fail("失败");
        }
        Driver driver = driverService.getById(order.getDriverId());
        Car car = carService.getById(order.getCarId());
        Enterprise enterprise = enterpriseService.getById(order.getEnterpriseId());
        order.setDriverName(driver.getName());
        order.setVehicleNumber(car.getVehicleNumber());
        order.setEnterpriseName(enterprise.getName());
        return R.ok(order);
    }
    
    
    
    @GetMapping("/getOrderTravel")
    @ApiOperation(value = "获取订单行程轨迹", tags = {"订单管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "id", required = true)
    })
    public R<List<OrderTravelVo>> getOrderTravel(@PathVariable("id") Integer id){
        Order order = orderService.getById(id);
        if(null == order){
            return R.fail("失败");
        }
        Car car = carService.getById(order.getCarId());
        LocalDateTime dateTime = LocalDateTime.parse(order.getOrderTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        long startTime = dateTime.toEpochSecond(ZoneOffset.ofHours(8));
        long endTime = dateTime.plusDays(1).toEpochSecond(ZoneOffset.ofHours(8));
        R<List<OrderTravelVo>> orderTravel = upExgMsgRealLocationClient.getOrderTravel(car.getVehicleNumber(), startTime, endTime);
        return orderTravel;
    }
    
    
    
    @GetMapping("/getOrderMonitoring")
    @ApiOperation(value = "获取订单监控", tags = {"订单管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "id", required = true)
    })
    public R<RealVideoResp> getOrderMonitoring(@PathVariable("id") Integer id){
        Order order = orderService.getById(id);
        if(null == order){
            return R.fail("失败");
        }
        Car car = carService.getById(order.getCarId());
        Enterprise enterprise = enterpriseService.getById(car.getEnterpriseId());
        LocalDateTime dateTime = LocalDateTime.parse(order.getOrderTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        long startTime = dateTime.toEpochSecond(ZoneOffset.ofHours(8));
        long endTime = dateTime.plusDays(1).toEpochSecond(ZoneOffset.ofHours(8));
        R<UPPlaybackMsgStartupAckVo> startupAckVoR = playbackMsgClient.playbackMsgStartup(Integer.valueOf(enterprise.getCode()), car.getVehicleNumber(),
                startTime, endTime);
        if(200 == startupAckVoR.getCode()){
            UPPlaybackMsgStartupAckVo data = startupAckVoR.getData();
            RealVideoResp resp = new RealVideoResp();
            resp.setServerIp(data.getServerIP());
            resp.setServerPort(data.getServerPort());
            return R.ok(resp);
        }
        return R.fail(startupAckVoR.getMsg());
    }
}