| | |
| | | package com.supersavedriving.driver.modular.system.api; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.supersavedriving.driver.core.common.annotion.ServiceLog; |
| | | import com.supersavedriving.driver.core.util.ToolUtil; |
| | | import com.supersavedriving.driver.modular.system.service.IBranchOfficeService; |
| | | import com.supersavedriving.driver.modular.system.service.IDriverService; |
| | | import com.supersavedriving.driver.modular.system.util.RedisUtil; |
| | | import com.supersavedriving.driver.modular.system.util.ResultUtil; |
| | | import com.supersavedriving.driver.modular.system.warpper.DriverRegisterWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.OpenCityWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.ResponseWarpper; |
| | | import com.supersavedriving.driver.modular.system.util.SMSUtil; |
| | | import com.supersavedriving.driver.modular.system.util.UUIDUtil; |
| | | import com.supersavedriving.driver.modular.system.warpper.*; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | | 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; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 司机控制器 |
| | |
| | | @RequestMapping("") |
| | | public class DriverController { |
| | | |
| | | Logger logger = LoggerFactory.getLogger("ServiceLog"); |
| | | |
| | | @Autowired |
| | | private IBranchOfficeService branchOfficeService; |
| | | |
| | | @Autowired |
| | | private IDriverService driverService; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | |
| | | |
| | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/queryCityList") |
| | | @ServiceLog(name = "获取开通的省市数据", url = "/base/driver/queryCityList") |
| | | @ApiOperation(value = "获取开通的省市数据", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | }) |
| | | public ResponseWarpper<List<OpenCityWarpper>> queryCityList(){ |
| | | ResponseWarpper responseWarpper = null; |
| | | try { |
| | | List<OpenCityWarpper> list = branchOfficeService.queryOpenCity(); |
| | | responseWarpper = ResponseWarpper.success(list); |
| | | return ResponseWarpper.success(list); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | responseWarpper = new ResponseWarpper(500, e.getMessage()); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | logger.debug("" + |
| | | "\n接口地址:/base/driver/queryCityList" + |
| | | "\n接口名称:获取开通的省市数据" + |
| | | "\n请求参数:" + |
| | | "\n响应结果:{}" |
| | | , JSON.toJSONString(responseWarpper)); |
| | | return responseWarpper; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/queryOpenDistrict") |
| | | @ServiceLog(name = "根据城市code获取开通区域", url = "/base/driver/queryOpenDistrict") |
| | | @ApiOperation(value = "根据城市code获取开通区域", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "城市code", name = "cityCode", required = true, dataType = "string"), |
| | | }) |
| | | public ResponseWarpper<List<OpenCityWarpper>> queryOpenDistrict(String cityCode){ |
| | | ResponseWarpper responseWarpper = null; |
| | | if(ToolUtil.isEmpty(cityCode)){ |
| | | responseWarpper = ResponseWarpper.success(ResultUtil.paranErr()); |
| | | return ResponseWarpper.success(ResultUtil.paranErr("cityCode")); |
| | | } |
| | | |
| | | if(ToolUtil.isNotEmpty(cityCode)){ |
| | | try { |
| | | List<OpenCityWarpper> list = branchOfficeService.queryOpenDistrict(cityCode); |
| | | responseWarpper = ResponseWarpper.success(list); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | responseWarpper = new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | try { |
| | | List<OpenCityWarpper> list = branchOfficeService.queryOpenDistrict(cityCode); |
| | | return ResponseWarpper.success(list); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | logger.debug("" + |
| | | "\n接口地址:/base/driver/queryOpenDistrict" + |
| | | "\n接口名称:根据城市code获取开通区域" + |
| | | "\n请求参数:cityCode={}" + |
| | | "\n响应结果:{}" |
| | | , cityCode, JSON.toJSONString(responseWarpper)); |
| | | return responseWarpper; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/driverRegister") |
| | | @ServiceLog(name = "司机注册申请", url = "/base/driver/driverRegister") |
| | | @ApiOperation(value = "司机注册申请", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | }) |
| | | public ResponseWarpper driverRegister(DriverRegisterWarpper driverRegisterWarpper){ |
| | | ResponseWarpper responseWarpper = null; |
| | | try { |
| | | ResultUtil resultUtil = driverService.driverRegister(driverRegisterWarpper); |
| | | responseWarpper = ResponseWarpper.success(resultUtil); |
| | | return ResponseWarpper.success(resultUtil); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | responseWarpper = new ResponseWarpper(500, e.getMessage()); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | logger.debug("" + |
| | | "\n接口地址:/base/driver/driverRegister" + |
| | | "\n接口名称:司机注册申请" + |
| | | "\n请求参数:" + JSON.toJSONString(driverRegisterWarpper) + |
| | | "\n响应结果:{}" |
| | | , JSON.toJSONString(responseWarpper)); |
| | | return responseWarpper; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/getVerificationCode") |
| | | @ServiceLog(name = "获取短信验证码", url = "/base/driver/getVerificationCode") |
| | | @ApiOperation(value = "获取短信验证码", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "国家代码+86", name = "receiver", required = true, dataType = "string"), |
| | | @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "string"), |
| | | }) |
| | | public ResponseWarpper getVerificationCode(String receiver, String phone){ |
| | | if(ToolUtil.isEmpty(receiver)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("receiver")); |
| | | } |
| | | if(ToolUtil.isEmpty(phone)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("phone")); |
| | | } |
| | | try { |
| | | String numberRandom = UUIDUtil.getNumberRandom(6); |
| | | SMSUtil.send_huawei_sms("", receiver + phone, "[\"" + numberRandom + "\"]"); |
| | | redisUtil.setStrValue(receiver + phone, numberRandom, 300);//5分钟有效期 |
| | | return ResponseWarpper.success(ResultUtil.success()); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/driverCodeLogin") |
| | | @ServiceLog(name = "司机短信验证码登录", url = "/base/driver/driverCodeLogin") |
| | | @ApiOperation(value = "司机短信验证码登录", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "国家代码+86", name = "receiver", required = true, dataType = "string"), |
| | | @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "string"), |
| | | @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "string"), |
| | | }) |
| | | public ResponseWarpper<TokenWarpper> driverCodeLogin(String receiver, String phone, String code){ |
| | | if(ToolUtil.isEmpty(receiver)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("receiver")); |
| | | } |
| | | if(ToolUtil.isEmpty(phone)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("phone")); |
| | | } |
| | | try { |
| | | ResultUtil<TokenWarpper> tokenWarpper = driverService.driverLogin(receiver, phone, code); |
| | | return ResponseWarpper.success(tokenWarpper); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/driverPassLogin") |
| | | @ServiceLog(name = "司机密码登录", url = "/base/driver/driverPassLogin") |
| | | @ApiOperation(value = "司机密码登录", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "国家代码+86", name = "receiver", required = true, dataType = "string"), |
| | | @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "string"), |
| | | @ApiImplicitParam(value = "密码", name = "password", required = true, dataType = "string"), |
| | | }) |
| | | public ResponseWarpper<TokenWarpper> driverPassLogin(String receiver, String phone, String password){ |
| | | if(ToolUtil.isEmpty(receiver)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("receiver")); |
| | | } |
| | | if(ToolUtil.isEmpty(phone)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("phone")); |
| | | } |
| | | if(ToolUtil.isEmpty(password)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("password")); |
| | | } |
| | | try { |
| | | ResultUtil<TokenWarpper> tokenWarpper = driverService.driverPassLogin(receiver, phone, password); |
| | | return ResponseWarpper.success(tokenWarpper); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/driver/flushedToken") |
| | | @ServiceLog(name = "刷新token", url = "/api/driver/flushedToken") |
| | | @ApiOperation(value = "刷新token", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResponseWarpper<TokenWarpper> flushedToken(HttpServletRequest request){ |
| | | try { |
| | | Integer uid = driverService.getUserByRequset(request); |
| | | if(null == uid){ |
| | | return ResponseWarpper.success(ResultUtil.tokenErr()); |
| | | } |
| | | ResultUtil<TokenWarpper> tokenWarpper = driverService.flushedToken(uid); |
| | | return ResponseWarpper.success(tokenWarpper); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/driver/setPassword") |
| | | @ServiceLog(name = "司机设置密码", url = "/api/driver/setPassword") |
| | | @ApiOperation(value = "司机设置密码", tags = {"司机端-首页"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "密码", name = "password", required = true, dataType = "string"), |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResponseWarpper setPassword(String password, HttpServletRequest request){ |
| | | if(ToolUtil.isEmpty(password)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("password")); |
| | | } |
| | | try { |
| | | Integer uid = driverService.getUserByRequset(request); |
| | | if(null == uid){ |
| | | return ResponseWarpper.success(ResultUtil.tokenErr()); |
| | | } |
| | | driverService.setPassword(uid, password); |
| | | return ResponseWarpper.success(); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/driver/queryDriverPosition") |
| | | @ServiceLog(name = "获取5公里范围内的司机", url = "/api/driver/queryDriverPosition") |
| | | @ApiOperation(value = "获取5公里范围内的司机", tags = {"司机端-首页"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResponseWarpper<List<String>> queryDriverPosition(HttpServletRequest request){ |
| | | try { |
| | | Integer uid = driverService.getUserByRequset(request); |
| | | if(null == uid){ |
| | | return ResponseWarpper.success(ResultUtil.tokenErr()); |
| | | } |
| | | ResultUtil<List<String>> listResultUtil = driverService.queryDriverPosition(uid); |
| | | return ResponseWarpper.success(listResultUtil); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/addDriverPosition") |
| | | @ServiceLog(name = "存储司机实时位置", url = "/base/driver/addDriverPosition") |
| | | public ResponseWarpper addDriverPosition(DriverPositionWarpper driverPositionWarpper) { |
| | | try { |
| | | driverService.addDriverPosition(driverPositionWarpper); |
| | | return ResponseWarpper.success(); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/driver/queryPromotionQRCode") |
| | | @ServiceLog(name = "获取司机推广二维码", url = "/api/driver/queryPromotionQRCode") |
| | | @ApiOperation(value = "获取司机推广二维码", tags = {"司机端-个人中心"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResponseWarpper<PromotionWarpper> queryPromotionQRCode(HttpServletRequest request) { |
| | | try { |
| | | Integer uid = driverService.getUserByRequset(request); |
| | | if (null == uid) { |
| | | return ResponseWarpper.success(ResultUtil.tokenErr()); |
| | | } |
| | | PromotionWarpper promotionWarpper = driverService.queryPromotionQRCode(uid); |
| | | return ResponseWarpper.success(promotionWarpper); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |