feat: 司机登录完成
This commit is contained in:
parent
69f322f236
commit
d27746789e
|
@ -17,41 +17,48 @@ import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Aspect //切面类
|
@Aspect // 切面类
|
||||||
public class GuiguLoginAspect {
|
public class GuiguLoginAspect {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate<Object,Object> redisTemplate;
|
private RedisTemplate<Object, Object> redisTemplate;
|
||||||
|
|
||||||
//环绕通知,登录判断
|
/**
|
||||||
//切入点表达式:指定对哪些规则的方法进行增强
|
* 环绕通知,登录判断
|
||||||
|
* 切入点表达式:指定对哪些规则的方法进行增强
|
||||||
|
*
|
||||||
|
* @param proceedingJoinPoint proceedingJoinPoint
|
||||||
|
* @param guiguLogin guiguLogin
|
||||||
|
* @return Object
|
||||||
|
* @throws Throwable Throwable
|
||||||
|
*/
|
||||||
@Around("execution(* com.atguigu.daijia.*.controller.*.*(..)) && @annotation(guiguLogin)")
|
@Around("execution(* com.atguigu.daijia.*.controller.*.*(..)) && @annotation(guiguLogin)")
|
||||||
public Object login(ProceedingJoinPoint proceedingJoinPoint,GuiguLogin guiguLogin) throws Throwable {
|
public Object login(ProceedingJoinPoint proceedingJoinPoint, GuiguLogin guiguLogin) throws Throwable {
|
||||||
|
|
||||||
//1 获取request对象
|
// 1 获取request对象
|
||||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||||
ServletRequestAttributes sra = (ServletRequestAttributes)attributes;
|
ServletRequestAttributes sra = (ServletRequestAttributes) attributes;
|
||||||
|
assert sra != null;
|
||||||
HttpServletRequest request = sra.getRequest();
|
HttpServletRequest request = sra.getRequest();
|
||||||
|
|
||||||
//2 从请求头获取token
|
// 2 从请求头获取token
|
||||||
String token = request.getHeader("token");
|
String token = request.getHeader("token");
|
||||||
|
|
||||||
//3 判断token是否为空,如果为空,返回登录提示
|
// 3 判断token是否为空,如果为空,返回登录提示
|
||||||
if(!StringUtils.hasText(token)) {
|
if (!StringUtils.hasText(token)) {
|
||||||
throw new GuiguException(ResultCodeEnum.LOGIN_AUTH);
|
throw new GuiguException(ResultCodeEnum.LOGIN_AUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
//4 token不为空,查询redis
|
// 4 token不为空,查询redis
|
||||||
String customerId = (String)redisTemplate.opsForValue()
|
String customerId = (String) redisTemplate.opsForValue()
|
||||||
.get(RedisConstant.USER_LOGIN_KEY_PREFIX+token);
|
.get(RedisConstant.USER_LOGIN_KEY_PREFIX + token);
|
||||||
|
|
||||||
//5 查询redis对应用户id,把用户id放到ThreadLocal里面
|
// 5 查询redis对应用户id,把用户id放到ThreadLocal里面
|
||||||
if(StringUtils.hasText(customerId)) {
|
if (StringUtils.hasText(customerId)) {
|
||||||
AuthContextHolder.setUserId(Long.parseLong(customerId));
|
AuthContextHolder.setUserId(Long.parseLong(customerId));
|
||||||
}
|
}
|
||||||
|
|
||||||
//6 执行业务方法
|
// 6 执行业务方法
|
||||||
return proceedingJoinPoint.proceed();
|
return proceedingJoinPoint.proceed();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,14 @@
|
||||||
package com.atguigu.daijia.driver.client;
|
package com.atguigu.daijia.driver.client;
|
||||||
|
|
||||||
import com.atguigu.daijia.common.result.Result;
|
import com.atguigu.daijia.common.result.Result;
|
||||||
import com.atguigu.daijia.model.entity.driver.DriverSet;
|
|
||||||
import com.atguigu.daijia.model.form.driver.DriverFaceModelForm;
|
|
||||||
import com.atguigu.daijia.model.form.driver.UpdateDriverAuthInfoForm;
|
|
||||||
import com.atguigu.daijia.model.vo.driver.DriverAuthInfoVo;
|
|
||||||
import com.atguigu.daijia.model.vo.driver.DriverInfoVo;
|
|
||||||
import com.atguigu.daijia.model.vo.driver.DriverLoginVo;
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
|
|
||||||
@FeignClient(value = "service-driver")
|
@FeignClient(value = "service-driver")
|
||||||
public interface DriverInfoFeignClient {
|
public interface DriverInfoFeignClient {
|
||||||
|
|
||||||
|
// 小程序司机登录
|
||||||
|
@GetMapping("/driver/info/login/{code}")
|
||||||
|
Result<Long> login(@PathVariable("code") String code);
|
||||||
}
|
}
|
|
@ -15,8 +15,7 @@ public class WxConfigOperator {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public WxMaService wxMaService() {
|
public WxMaService wxMaService() {
|
||||||
|
// 微信小程序id和秘钥
|
||||||
//微信小程序id和秘钥
|
|
||||||
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
|
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
|
||||||
wxMaConfig.setAppid(wxConfigProperties.getAppId());
|
wxMaConfig.setAppid(wxConfigProperties.getAppId());
|
||||||
wxMaConfig.setSecret(wxConfigProperties.getSecret());
|
wxMaConfig.setSecret(wxConfigProperties.getSecret());
|
||||||
|
|
|
@ -100,6 +100,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新客户微信手机号码
|
* 更新客户微信手机号码
|
||||||
|
* 个人版无法进行测试
|
||||||
*
|
*
|
||||||
* @param updateWxPhoneForm 更新用户手机号表单
|
* @param updateWxPhoneForm 更新用户手机号表单
|
||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.atguigu.daijia</groupId>
|
<groupId>com.atguigu.daijia</groupId>
|
||||||
<artifactId>service</artifactId><version>1.0</version>
|
<artifactId>service</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -13,6 +14,10 @@
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.binarywang</groupId>
|
||||||
|
<artifactId>weixin-java-miniapp</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.atguigu.daijia.driver.config;
|
||||||
|
|
||||||
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||||
|
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||||
|
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class WxConfigOperator {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WxConfigProperties wxConfigProperties;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public WxMaService wxMaService() {
|
||||||
|
// 微信小程序id和秘钥
|
||||||
|
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
|
||||||
|
wxMaConfig.setAppid(wxConfigProperties.getAppId());
|
||||||
|
wxMaConfig.setSecret(wxConfigProperties.getSecret());
|
||||||
|
|
||||||
|
WxMaService service = new WxMaServiceImpl();
|
||||||
|
service.setWxMaConfig(wxMaConfig);
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.atguigu.daijia.driver.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Data
|
||||||
|
@ConfigurationProperties(prefix = "wx.miniapp")
|
||||||
|
public class WxConfigProperties {
|
||||||
|
private String appId;
|
||||||
|
private String secret;
|
||||||
|
}
|
|
@ -1,22 +1,14 @@
|
||||||
package com.atguigu.daijia.driver.controller;
|
package com.atguigu.daijia.driver.controller;
|
||||||
|
|
||||||
import com.atguigu.daijia.common.result.Result;
|
|
||||||
import com.atguigu.daijia.driver.service.CiService;
|
|
||||||
import com.atguigu.daijia.model.vo.order.TextAuditingVo;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Tag(name = "腾讯云CI审核接口管理")
|
@Tag(name = "腾讯云CI审核接口管理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value="/cos")
|
@RequestMapping(value = "/cos")
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
public class CiController {
|
public class CiController {
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,16 @@
|
||||||
package com.atguigu.daijia.driver.controller;
|
package com.atguigu.daijia.driver.controller;
|
||||||
|
|
||||||
import com.atguigu.daijia.common.result.Result;
|
|
||||||
import com.atguigu.daijia.driver.service.CosService;
|
|
||||||
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Tag(name = "腾讯云cos上传接口管理")
|
@Tag(name = "腾讯云cos上传接口管理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value="/cos")
|
@RequestMapping(value = "/cos")
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
public class CosController {
|
public class CosController {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
package com.atguigu.daijia.driver.controller;
|
package com.atguigu.daijia.driver.controller;
|
||||||
|
|
||||||
import com.atguigu.daijia.driver.service.DriverAccountService;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Tag(name = "司机账户API接口管理")
|
@Tag(name = "司机账户API接口管理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value="/driver/account")
|
@RequestMapping(value = "/driver/account")
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
public class DriverAccountController {
|
public class DriverAccountController {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,30 @@
|
||||||
package com.atguigu.daijia.driver.controller;
|
package com.atguigu.daijia.driver.controller;
|
||||||
|
|
||||||
|
import com.atguigu.daijia.common.result.Result;
|
||||||
import com.atguigu.daijia.driver.service.DriverInfoService;
|
import com.atguigu.daijia.driver.service.DriverInfoService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Tag(name = "司机API接口管理")
|
@Tag(name = "司机API接口管理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value="/driver/info")
|
@RequestMapping(value = "/driver/info")
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
public class DriverInfoController {
|
public class DriverInfoController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DriverInfoService driverInfoService;
|
||||||
|
|
||||||
|
@Operation(summary = "小程序司机登录")
|
||||||
|
@GetMapping("/login/{code}")
|
||||||
|
public Result<Long> login(@PathVariable("code") String code) {
|
||||||
|
Long vo = driverInfoService.login(code);
|
||||||
|
return Result.ok(vo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,14 @@
|
||||||
package com.atguigu.daijia.driver.controller;
|
package com.atguigu.daijia.driver.controller;
|
||||||
|
|
||||||
import com.atguigu.daijia.common.result.Result;
|
|
||||||
import com.atguigu.daijia.driver.service.OcrService;
|
|
||||||
import com.atguigu.daijia.model.vo.driver.DriverLicenseOcrVo;
|
|
||||||
import com.atguigu.daijia.model.vo.driver.IdCardOcrVo;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestPart;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Tag(name = "腾讯云识别接口管理")
|
@Tag(name = "腾讯云识别接口管理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value="/ocr")
|
@RequestMapping(value = "/ocr")
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
public class OcrController {
|
public class OcrController {
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,4 +5,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
public interface DriverInfoService extends IService<DriverInfo> {
|
public interface DriverInfoService extends IService<DriverInfo> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小程序司机登录
|
||||||
|
*
|
||||||
|
* @param code 唯一票据
|
||||||
|
* @return openid
|
||||||
|
*/
|
||||||
|
Long login(String code);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,90 @@
|
||||||
package com.atguigu.daijia.driver.service.impl;
|
package com.atguigu.daijia.driver.service.impl;
|
||||||
|
|
||||||
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||||
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||||
|
import com.atguigu.daijia.common.constant.SystemConstant;
|
||||||
|
import com.atguigu.daijia.driver.mapper.DriverAccountMapper;
|
||||||
import com.atguigu.daijia.driver.mapper.DriverInfoMapper;
|
import com.atguigu.daijia.driver.mapper.DriverInfoMapper;
|
||||||
|
import com.atguigu.daijia.driver.mapper.DriverLoginLogMapper;
|
||||||
|
import com.atguigu.daijia.driver.mapper.DriverSetMapper;
|
||||||
import com.atguigu.daijia.driver.service.DriverInfoService;
|
import com.atguigu.daijia.driver.service.DriverInfoService;
|
||||||
|
import com.atguigu.daijia.model.entity.driver.DriverAccount;
|
||||||
import com.atguigu.daijia.model.entity.driver.DriverInfo;
|
import com.atguigu.daijia.model.entity.driver.DriverInfo;
|
||||||
|
import com.atguigu.daijia.model.entity.driver.DriverLoginLog;
|
||||||
|
import com.atguigu.daijia.model.entity.driver.DriverSet;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
@Transactional
|
||||||
public class DriverInfoServiceImpl extends ServiceImpl<DriverInfoMapper, DriverInfo> implements DriverInfoService {
|
public class DriverInfoServiceImpl extends ServiceImpl<DriverInfoMapper, DriverInfo> implements DriverInfoService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WxMaService wxMaService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DriverSetMapper driverSetMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DriverAccountMapper driverAccountMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DriverLoginLogMapper driverLoginLogMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小程序司机登录
|
||||||
|
*
|
||||||
|
* @param code 唯一票据
|
||||||
|
* @return openid
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long login(String code) {
|
||||||
|
try {
|
||||||
|
// 根据code查询用户登录信息
|
||||||
|
WxMaJscode2SessionResult sessionInfo = wxMaService.getUserService().getSessionInfo(code);
|
||||||
|
String openid = sessionInfo.getOpenid();
|
||||||
|
|
||||||
|
// 查询数据库,如果没有数据自动添加
|
||||||
|
DriverInfo driverInfo = getOne(Wrappers.<DriverInfo>lambdaQuery().eq(DriverInfo::getWxOpenId, openid));
|
||||||
|
if (driverInfo == null) {
|
||||||
|
// 添加司机基本信息
|
||||||
|
driverInfo = new DriverInfo();
|
||||||
|
driverInfo.setNickname(String.valueOf(System.currentTimeMillis()));
|
||||||
|
driverInfo.setAvatarUrl("https://oss.aliyuncs.com/aliyun_id_photo_bucket/default_handsome.jpg");
|
||||||
|
driverInfo.setWxOpenId(openid);
|
||||||
|
save(driverInfo);
|
||||||
|
|
||||||
|
// 初始化司机设置
|
||||||
|
DriverSet driverSet = new DriverSet();
|
||||||
|
driverSet.setDriverId(driverInfo.getId());
|
||||||
|
driverSet.setOrderDistance(new BigDecimal(0));// 0:无限制
|
||||||
|
driverSet.setAcceptDistance(new BigDecimal(SystemConstant.ACCEPT_DISTANCE));// 默认接单范围:5公里
|
||||||
|
driverSet.setIsAutoAccept(0);// 0:否 1:是
|
||||||
|
driverSetMapper.insert(driverSet);
|
||||||
|
|
||||||
|
// 初始化司机账户信息
|
||||||
|
DriverAccount driverAccount = new DriverAccount();
|
||||||
|
driverAccount.setDriverId(driverInfo.getId());
|
||||||
|
driverAccountMapper.insert(driverAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverLoginLog driverLoginLog = new DriverLoginLog();
|
||||||
|
driverLoginLog.setDriverId(driverInfo.getId());
|
||||||
|
driverLoginLog.setMsg("小程序登录");
|
||||||
|
driverLoginLogMapper.insert(driverLoginLog);
|
||||||
|
|
||||||
|
// 返回司机id
|
||||||
|
return driverInfo.getId();
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,8 +0,0 @@
|
||||||
spring.application.name=service-driver
|
|
||||||
spring.profiles.active=dev
|
|
||||||
spring.main.allow-bean-definition-overriding=true
|
|
||||||
spring.cloud.nacos.discovery.server-addr=localhost:8848
|
|
||||||
spring.cloud.nacos.config.server-addr=localhost:8848
|
|
||||||
spring.cloud.nacos.config.prefix=${spring.application.name}
|
|
||||||
spring.cloud.nacos.config.file-extension=yaml
|
|
||||||
spring.cloud.nacos.config.shared-configs[0].data-id=common-account.yaml
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: service-driver
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
server-addr: 192.168.3.129:8848
|
||||||
|
config:
|
||||||
|
server-addr: 192.168.3.129:8848
|
||||||
|
prefix: ${spring.application.name}
|
||||||
|
file-extension: yaml
|
||||||
|
shared-configs:
|
||||||
|
- data-id: common-account.yaml
|
|
@ -1,19 +1,30 @@
|
||||||
package com.atguigu.daijia.driver.controller;
|
package com.atguigu.daijia.driver.controller;
|
||||||
|
|
||||||
|
import com.atguigu.daijia.common.result.Result;
|
||||||
import com.atguigu.daijia.driver.service.DriverService;
|
import com.atguigu.daijia.driver.service.DriverService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Tag(name = "司机API接口管理")
|
@Tag(name = "司机API接口管理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value="/driver")
|
@RequestMapping(value = "/driver")
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
public class DriverController {
|
public class DriverController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DriverService driverService;
|
||||||
|
|
||||||
|
@Operation(summary = "小程序授权登录")
|
||||||
|
@GetMapping("/login/{code}")
|
||||||
|
public Result<String> login(@PathVariable String code) {
|
||||||
|
String vo = driverService.login(code);
|
||||||
|
return Result.ok(vo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,11 @@ package com.atguigu.daijia.driver.service;
|
||||||
|
|
||||||
public interface DriverService {
|
public interface DriverService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小程序司机登录
|
||||||
|
*
|
||||||
|
* @param code 唯一票据
|
||||||
|
* @return openid
|
||||||
|
*/
|
||||||
|
String login(String code);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,44 @@
|
||||||
package com.atguigu.daijia.driver.service.impl;
|
package com.atguigu.daijia.driver.service.impl;
|
||||||
|
|
||||||
|
import com.atguigu.daijia.common.constant.RedisConstant;
|
||||||
|
import com.atguigu.daijia.common.result.Result;
|
||||||
import com.atguigu.daijia.driver.client.DriverInfoFeignClient;
|
import com.atguigu.daijia.driver.client.DriverInfoFeignClient;
|
||||||
import com.atguigu.daijia.driver.service.DriverService;
|
import com.atguigu.daijia.driver.service.DriverService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
public class DriverServiceImpl implements DriverService {
|
public class DriverServiceImpl implements DriverService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DriverInfoFeignClient driverInfoFeignClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<Object, Object> redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小程序司机登录
|
||||||
|
*
|
||||||
|
* @param code 唯一票据
|
||||||
|
* @return openid
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String login(String code) {
|
||||||
|
Result<Long> longResult = driverInfoFeignClient.login(code);
|
||||||
|
Long driverId = longResult.getData();
|
||||||
|
String token = driverId.toString().replaceAll("-", "");
|
||||||
|
|
||||||
|
// 放入Redis
|
||||||
|
redisTemplate.opsForValue().set(RedisConstant.USER_LOGIN_KEY_PREFIX + token,
|
||||||
|
driverId.toString(),
|
||||||
|
RedisConstant.USER_LOGIN_KEY_TIMEOUT,
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
return token;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
spring.application.name=web-driver
|
|
||||||
spring.profiles.active=dev
|
|
||||||
spring.main.allow-bean-definition-overriding=true
|
|
||||||
spring.cloud.nacos.discovery.server-addr=localhost:8848
|
|
||||||
spring.cloud.nacos.config.server-addr=localhost:8848
|
|
||||||
spring.cloud.nacos.config.prefix=${spring.application.name}
|
|
||||||
spring.cloud.nacos.config.file-extension=yaml
|
|
||||||
spring.cloud.nacos.config.shared-configs[0].data-id=common-account.yaml
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: web-driver
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
server-addr: 192.168.3.129:8848
|
||||||
|
config:
|
||||||
|
server-addr: 192.168.3.129:8848
|
||||||
|
prefix: ${spring.application.name}
|
||||||
|
file-extension: yaml
|
||||||
|
shared-configs:
|
||||||
|
- data-id: common-account.yaml
|
Loading…
Reference in New Issue