puzhibing
2023-09-09 9ef2e272c6ef99d152c5d6afc95af70a3822c57d
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
package com.stylefeng.guns.modular.api;
 
 
import com.alibaba.fastjson.JSON;
import com.stylefeng.guns.modular.system.model.OrderPosition;
import com.stylefeng.guns.modular.system.service.IDriverService;
import com.stylefeng.guns.modular.system.service.INettyService;
import com.stylefeng.guns.modular.system.util.PushUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.warpper.OrderStatusWarpper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
 
/**
 * 替换socket无法正常连接的备选方案
 * 通过前端主动调用接口上传数据或者获取需要下发的数据
 */
@RestController
@RequestMapping("")
public class NettyController {
 
    @Autowired
    private INettyService nettyService;
 
    @Autowired
    private IDriverService driverService;
 
    @Autowired
    private PushUtil pushUtil;
 
 
 
    /**
     * 司机端主动调用该接口上传位置信息
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/netty/positionSocket")
    @ApiOperation(value = "司机端主动调用该接口上传位置信息", tags = {"司机端-仿socket接口"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "orderId", required = false, dataType = "int"),
            @ApiImplicitParam(value = "订单类型(1=专车,2=出租车,3=城际,4=小件物流-同城,5=小件物流-跨城)", name = "orderType", required = false, dataType = "int"),
            @ApiImplicitParam(value = "经度", name = "lon", required = true, dataType = "string"),
            @ApiImplicitParam(value = "纬度", name = "lat", required = true, dataType = "string"),
            @ApiImplicitParam(value = "方向角", name = "directionAngle", required = true, dataType = "string"),
            @ApiImplicitParam(value = "海拔", name = "altitude", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil positionSocket(OrderPosition orderPosition, HttpServletRequest request){
        try {
            Integer uid = driverService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return nettyService.positionSocket(orderPosition, uid);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 删除服务中的定时任务
     * @param orderId
     * @param orderType
     * @return
     */
    @ResponseBody
    @PostMapping("/base/netty/deleteTask")
    public String deleteTask(Integer orderId, Integer orderType){
        try {
            pushUtil.removeTask(orderId, orderType);
            return JSON.toJSONString(ResultUtil.success());
        }catch (Exception e){
            e.printStackTrace();
            return JSON.toJSONString(ResultUtil.runErr());
        }
    }
 
 
    /**
     * 主动调用获取订单状态
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/netty/orderStateSocket")
    @ApiOperation(value = "主动调用获取订单状态", tags = {"司机端-仿socket接口"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<OrderStatusWarpper>> orderStateSocket(HttpServletRequest request){
        try {
            Integer uid = driverService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return nettyService.orderStateSocket(uid);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
}