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.util.UUIDUtil;
|
import com.supersavedriving.user.modular.system.util.huawei.OBSUtil;
|
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 org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.io.InputStream;
|
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());
|
}
|
}
|
|
|
@ResponseBody
|
@PostMapping("/api/appUser/uploadImg")
|
// @ServiceLog(name = "上传头像图片", url = "/api/appUser/uploadImg")
|
@ApiOperation(value = "上传头像图片", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "图片文件", name = "file", required = true, dataType = "file"),
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResponseWarpper<String> uploadImg(MultipartFile file){
|
try {
|
InputStream inputStream = file.getInputStream();
|
String name = file.getName();
|
name = UUIDUtil.getRandomCode() + name.substring(name.lastIndexOf("."));
|
String s = OBSUtil.putObjectToBucket(inputStream, name);
|
return ResponseWarpper.success(s);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
}
|