puzhibing
2023-03-11 2d08b036f5bdb9c34d686d6d125d5690a948ffa0
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
package com.supersavedriving.user.modular.api;
 
import com.supersavedriving.user.core.common.annotion.ServiceLog;
import com.supersavedriving.user.core.util.ToolUtil;
import com.supersavedriving.user.modular.system.model.AppUser;
import com.supersavedriving.user.modular.system.service.IAppUserService;
import com.supersavedriving.user.modular.system.service.IDriverService;
import com.supersavedriving.user.modular.system.util.ResultUtil;
import com.supersavedriving.user.modular.system.warpper.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
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;
 
/**
 * 用户控制器
 */
@RestController
@RequestMapping("")
public class AppUserController {
 
    @Autowired
    private IAppUserService appUserService;
 
    @Autowired
    private IDriverService driverService;
 
 
 
 
 
    @ResponseBody
    @PostMapping("/base/appUser/appUserLogin")
//    @ServiceLog(name = "微信登录", url = "/base/appUser/appUserLogin")
    @ApiOperation(value = "微信登录", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "微信jscode", name = "jscode", required = true, dataType = "string"),
    })
    public ResponseWarpper appUserLogin(String jscode){
        if(ToolUtil.isEmpty(jscode)){
            return ResponseWarpper.success(ResultUtil.paranErr("jscode"));
        }
        try {
            ResultUtil resultUtil = appUserService.appUserLogin(jscode);
            return ResponseWarpper.success(resultUtil);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/base/appUser/signInToRegister")
//    @ServiceLog(name = "微信手机授权登录", url = "/base/appUser/signInToRegister")
    @ApiOperation(value = "微信手机授权登录", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
    })
    public ResponseWarpper<SignInToRegisterWarpper> signInToRegister(SignInToRegister signInToRegister){
        try {
            ResultUtil<SignInToRegisterWarpper> resultUtil = appUserService.signInToRegister(signInToRegister);
            return ResponseWarpper.success(resultUtil);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/base/appUser/queryNearbyDrivers")
//    @ServiceLog(name = "获取附近的司机", url = "/base/appUser/queryNearbyDrivers")
    @ApiOperation(value = "获取附近的司机", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "经度", name = "lon", required = true, dataType = "string"),
            @ApiImplicitParam(value = "纬度", name = "lat", required = true, dataType = "string"),
    })
    public ResponseWarpper<List<NearbyDriverWarpper>> queryNearbyDrivers(String lon, String lat){
        if(ToolUtil.isEmpty(lat)){
            return ResponseWarpper.success(ResultUtil.paranErr("lat"));
        }
        if(ToolUtil.isEmpty(lon)){
            return ResponseWarpper.success(ResultUtil.paranErr("lon"));
        }
        try {
            List<NearbyDriverWarpper> list = driverService.queryDriverPosition(lon, lat, 5D);
            return ResponseWarpper.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/base/appUser/setEmergencyContact")
//    @ServiceLog(name = "设置紧急联系人", url = "/base/appUser/queryNearbyDrivers")
    @ApiOperation(value = "设置紧急联系人", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "姓名", name = "name", required = true, dataType = "string"),
            @ApiImplicitParam(value = "电话", name = "phone", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper setEmergencyContact(String name, String phone){
        if(ToolUtil.isEmpty(name)){
            return ResponseWarpper.success(ResultUtil.paranErr("name"));
        }
        if(ToolUtil.isEmpty(phone)){
            return ResponseWarpper.success(ResultUtil.paranErr("phone"));
        }
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            AppUser appUser = appUserService.selectById(uid);
            appUser.setEmergencyContact(name);
            appUser.setEmergencyPhone(phone);
            appUserService.updateById(appUser);
            return ResponseWarpper.success();
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/appUser/queryUserInfo")
//    @ServiceLog(name = "获取个人信息", url = "/api/appUser/queryUserInfo")
    @ApiOperation(value = "获取个人信息", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<UserInfoWarpper> queryUserInfo(){
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            AppUser appUser = appUserService.selectById(uid);
            UserInfoWarpper userInfoWarpper = new UserInfoWarpper();
            BeanUtils.copyProperties(appUser, userInfoWarpper);
            return ResponseWarpper.success(userInfoWarpper);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
}