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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.agentdriving.driver.modular.system.api;
 
import com.agentdriving.driver.core.util.ToolUtil;
import com.agentdriving.driver.modular.system.model.YouTui;
import com.agentdriving.driver.modular.system.model.YouTuiDriver;
import com.agentdriving.driver.modular.system.service.IDriverService;
import com.agentdriving.driver.modular.system.service.IYouTuiDriverService;
import com.agentdriving.driver.modular.system.service.IYouTuiService;
import com.agentdriving.driver.modular.system.util.ResultUtil;
import com.agentdriving.driver.modular.system.warpper.DriverYouTuiWarpper;
import com.agentdriving.driver.modular.system.warpper.ResponseWarpper;
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 java.util.Date;
import java.util.List;
 
/**
 * @author zhibing.pu
 * @date 2023/3/15 17:50
 */
@RestController
@RequestMapping("")
public class YouTuiController {
 
    @Autowired
    private IYouTuiDriverService youTuiDriverService;
 
    @Autowired
    private IDriverService driverService;
 
    @Autowired
    private IYouTuiService youTuiService;
 
 
 
 
 
 
 
    @ResponseBody
    @PostMapping("/api/youtui/queryDriverYouTui")
//    @ServiceLog(name = "获取司机优推数据", url = "/api/youtui/queryDriverYouTui")
    @ApiOperation(value = "获取司机优推数据", tags = {"司机端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "pageSize", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<List<DriverYouTuiWarpper>> queryDriverYouTui(Integer pageNum, Integer pageSize){
        if(ToolUtil.isEmpty(pageNum)){
            return ResponseWarpper.success(ResultUtil.paranErr("pageNum"));
        }
        if(ToolUtil.isEmpty(pageSize)){
            return ResponseWarpper.success(ResultUtil.paranErr("pageSize"));
        }
        try {
            Integer uid = driverService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.tokenErr();
            }
            List<DriverYouTuiWarpper> driverYouTuiWarppers = youTuiDriverService.queryDriverYouTui(uid, pageNum, pageSize);
            return ResponseWarpper.success(driverYouTuiWarppers);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/youtui/queryAllYouTui")
//    @ServiceLog(name = "获取兑换权益列表", url = "/api/youtui/queryAllYouTui")
    @ApiOperation(value = "获取兑换权益列表", tags = {"司机端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "pageSize", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<List<DriverYouTuiWarpper>> queryAllYouTui(Integer pageNum, Integer pageSize){
        if(ToolUtil.isEmpty(pageNum)){
            return ResponseWarpper.success(ResultUtil.paranErr("pageNum"));
        }
        if(ToolUtil.isEmpty(pageSize)){
            return ResponseWarpper.success(ResultUtil.paranErr("pageSize"));
        }
        try {
            Integer uid = driverService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.tokenErr();
            }
            List<DriverYouTuiWarpper> driverYouTuiWarppers = youTuiDriverService.queryAllYouTui(pageNum, pageSize);
            return ResponseWarpper.success(driverYouTuiWarppers);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/youtui/redeemBenefits")
//    @ServiceLog(name = "司机兑换优推", url = "/api/youtui/redeemBenefits")
    @ApiOperation(value = "司机兑换优推", tags = {"司机端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "优推数据id", name = "id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper redeemBenefits(Integer id){
        if(ToolUtil.isEmpty(id)){
            return ResponseWarpper.success(ResultUtil.paranErr("id"));
        }
        try {
            Integer uid = driverService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.tokenErr();
            }
            ResultUtil resultUtil = youTuiDriverService.redeemBenefits(uid, id);
            return ResponseWarpper.success(resultUtil);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/youtui/userYouTui")
//    @ServiceLog(name = "司机使用优推", url = "/api/youtui/userYouTui")
    @ApiOperation(value = "司机使用优推", tags = {"司机端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "优推数据id", name = "id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper userYouTui(Integer id){
        if(ToolUtil.isEmpty(id)){
            return ResponseWarpper.success(ResultUtil.paranErr("id"));
        }
        try {
            Integer uid = driverService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.tokenErr();
            }
            YouTuiDriver youTuiDriver = youTuiDriverService.selectById(id);
            youTuiDriver.setState(2);
            if(youTuiDriver.getType() == 2){
                YouTui youTui = youTuiService.selectById(youTuiDriver.getYouTuiId());
                youTuiDriver.setEndTime(new Date(System.currentTimeMillis() + (youTui.getNumber() * 3600000)));
            }
            youTuiDriverService.updateById(youTuiDriver);
            return ResponseWarpper.success();
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
}