puzhibing
2023-03-15 79962435853baf5a28e08461f46a831fffa1a4b0
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
package com.stylefeng.guns.modular.api;
 
import com.stylefeng.guns.modular.system.service.ICarService;
import com.stylefeng.guns.modular.system.service.IDriverService;
import com.stylefeng.guns.modular.system.util.ResultUtil;
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.Date;
import java.util.List;
import java.util.Map;
 
/**
 * 车辆相关控制器
 */
@RestController
@RequestMapping("/api/car")
public class CarController {
 
    @Autowired
    private ICarService carService;
 
    @Autowired
    private IDriverService driverService;
 
 
 
 
 
 
    /**
     * 获取所有车辆品牌
     * @return
     */
    @ResponseBody
    @PostMapping("/queryAllBrand")
    @ApiOperation(value = "获取所有车辆品牌", tags = {"司机端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil queryAllBrand(){
        try {
            List<Map<String, Object>> list = carService.queryAllBrand();
            return ResultUtil.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
    /**
     * 查询车辆品牌型号
     * @param brandId
     * @return
     */
    @ResponseBody
    @PostMapping("/queryCarModel")
    @ApiOperation(value = "查询车辆品牌型号", tags = {"司机端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "车辆品牌id", name = "brandId", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil queryCarModel(Integer brandId){
        try {
            List<Map<String, Object>> list = carService.queryCarModel(brandId);
            return ResultUtil.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 添加车辆
     * @param modelId
     * @param color
     * @param licensePlate
     * @param time
     * @param drivingLicensePhoto
     * @param carPhoto
     * @param insurancePhoto
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/addCar")
    @ApiOperation(value = "添加车辆", tags = {"司机端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "车辆型号id", name = "modelId", required = true, dataType = "int"),
            @ApiImplicitParam(value = "车辆颜色", name = "color", required = true, dataType = "string"),
            @ApiImplicitParam(value = "车牌号", name = "licensePlate", required = true, dataType = "string"),
            @ApiImplicitParam(value = "年审日期(需要格式化)", name = "time", required = true, dataType = "string"),
            @ApiImplicitParam(value = "行驶证照片", name = "drivingLicensePhoto", required = true, dataType = "string"),
            @ApiImplicitParam(value = "车辆照片", name = "carPhoto", required = true, dataType = "string"),
            @ApiImplicitParam(value = "保险照片", name = "insurancePhoto", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil addCar(Integer modelId, String color, String licensePlate, Date time, String drivingLicensePhoto,
                             String carPhoto, String insurancePhoto, HttpServletRequest request){
        try {
            Integer uid = driverService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return carService.addCar(modelId, color, licensePlate, time, drivingLicensePhoto, carPhoto, insurancePhoto, uid);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
}