Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
|
6a75434912 | |
|
684d7aa7b2 | |
|
b670ee61c1 | |
|
29f303b64d | |
|
d27746789e | |
|
69f322f236 | |
|
7bd921a746 |
|
@ -5,18 +5,17 @@ package com.atguigu.daijia.common.util;
|
|||
*/
|
||||
public class AuthContextHolder {
|
||||
|
||||
private static ThreadLocal<Long> userId = new ThreadLocal<Long>();
|
||||
|
||||
public static void setUserId(Long _userId) {
|
||||
userId.set(_userId);
|
||||
}
|
||||
private static final ThreadLocal<Long> userId = new ThreadLocal<>();
|
||||
|
||||
public static Long getUserId() {
|
||||
return userId.get();
|
||||
}
|
||||
|
||||
public static void setUserId(Long _userId) {
|
||||
userId.set(_userId);
|
||||
}
|
||||
|
||||
public static void removeUserId() {
|
||||
userId.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -82,9 +82,8 @@ public class RedisConfig {
|
|||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer))
|
||||
.disableCachingNullValues();
|
||||
|
||||
RedisCacheManager cacheManager = RedisCacheManager.builder(factory)
|
||||
return RedisCacheManager.builder(factory)
|
||||
.cacheDefaults(config)
|
||||
.build();
|
||||
return cacheManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package com.atguigu.daijia.common.login;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
//登录判断
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface GuiguLogin {
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.atguigu.daijia.common.login;
|
||||
|
||||
import com.atguigu.daijia.common.constant.RedisConstant;
|
||||
import com.atguigu.daijia.common.execption.GuiguException;
|
||||
import com.atguigu.daijia.common.result.ResultCodeEnum;
|
||||
import com.atguigu.daijia.common.util.AuthContextHolder;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
@Component
|
||||
@Aspect // 切面类
|
||||
public class GuiguLoginAspect {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<Object, Object> redisTemplate;
|
||||
|
||||
/**
|
||||
* 环绕通知,登录判断
|
||||
* 切入点表达式:指定对哪些规则的方法进行增强
|
||||
*
|
||||
* @param proceedingJoinPoint proceedingJoinPoint
|
||||
* @param guiguLogin guiguLogin
|
||||
* @return Object
|
||||
* @throws Throwable Throwable
|
||||
*/
|
||||
@Around("execution(* com.atguigu.daijia.*.controller.*.*(..)) && @annotation(guiguLogin)")
|
||||
public Object login(ProceedingJoinPoint proceedingJoinPoint, GuiguLogin guiguLogin) throws Throwable {
|
||||
|
||||
// 1 获取request对象
|
||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||
ServletRequestAttributes sra = (ServletRequestAttributes) attributes;
|
||||
assert sra != null;
|
||||
HttpServletRequest request = sra.getRequest();
|
||||
|
||||
// 2 从请求头获取token
|
||||
String token = request.getHeader("token");
|
||||
|
||||
// 3 判断token是否为空,如果为空,返回登录提示
|
||||
if (!StringUtils.hasText(token)) {
|
||||
throw new GuiguException(ResultCodeEnum.LOGIN_AUTH);
|
||||
}
|
||||
|
||||
// 4 token不为空,查询redis
|
||||
String customerId = (String) redisTemplate.opsForValue()
|
||||
.get(RedisConstant.USER_LOGIN_KEY_PREFIX + token);
|
||||
|
||||
// 5 查询redis对应用户id,把用户id放到ThreadLocal里面
|
||||
if (StringUtils.hasText(customerId)) {
|
||||
AuthContextHolder.setUserId(Long.parseLong(customerId));
|
||||
}
|
||||
|
||||
// 6 执行业务方法
|
||||
return proceedingJoinPoint.proceed();
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ public class WebSecurityConfig {
|
|||
private CustomMd5PasswordEncoder customMd5PasswordEncoder;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
private RedisTemplate<Object,Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private SysLoginLogFeignClient sysLoginLogFeignClient;
|
||||
|
@ -88,5 +88,4 @@ public class WebSecurityConfig {
|
|||
|
||||
return http.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -31,13 +31,12 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
||||
|
||||
private RedisTemplate redisTemplate;
|
||||
private final RedisTemplate<Object,Object> redisTemplate;
|
||||
|
||||
private String ADMIN_LOGIN_KEY_PREFIX = "admin:login:";
|
||||
private AntPathMatcher antPathMatcher = new AntPathMatcher();
|
||||
private final AntPathMatcher antPathMatcher = new AntPathMatcher();
|
||||
|
||||
|
||||
public TokenAuthenticationFilter(RedisTemplate redisTemplate) {
|
||||
public TokenAuthenticationFilter(RedisTemplate<Object,Object> redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
|
@ -70,12 +69,13 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
|||
String token = request.getHeader("token");
|
||||
logger.info("token:"+token);
|
||||
if (StringUtils.hasText(token)) {
|
||||
SysUser sysUser = (SysUser)redisTemplate.opsForValue().get(ADMIN_LOGIN_KEY_PREFIX+token);
|
||||
String ADMIN_LOGIN_KEY_PREFIX = "admin:login:";
|
||||
SysUser sysUser = (SysUser)redisTemplate.opsForValue().get(ADMIN_LOGIN_KEY_PREFIX +token);
|
||||
logger.info("sysUser:"+JSON.toJSONString(sysUser));
|
||||
if (null != sysUser) {
|
||||
AuthContextHolder.setUserId(sysUser.getId());
|
||||
|
||||
if (null != sysUser.getUserPermsList() && sysUser.getUserPermsList().size() > 0) {
|
||||
if (null != sysUser.getUserPermsList() && !sysUser.getUserPermsList().isEmpty()) {
|
||||
List<SimpleGrantedAuthority> authorities = sysUser.getUserPermsList().stream().filter(code -> StringUtils.hasText(code.trim())).map(code -> new SimpleGrantedAuthority(code.trim())).collect(Collectors.toList());
|
||||
return new UsernamePasswordAuthenticationToken(sysUser.getUsername(), null, authorities);
|
||||
} else {
|
||||
|
|
|
@ -27,7 +27,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
|||
throw new UsernameNotFoundException("用户名不存在!");
|
||||
}
|
||||
|
||||
if(!"admin".equals(sysUser.getUsername()) && sysUser.getStatus().intValue() == 0) {
|
||||
if(!"admin".equals(sysUser.getUsername()) && sysUser.getStatus() == 0) {
|
||||
throw new RuntimeException("账号已停用");
|
||||
}
|
||||
List<String> userPermsList = securityLoginFeignClient.findUserPermsList(sysUser.getId()).getData();
|
||||
|
|
|
@ -5,10 +5,8 @@ import lombok.Data;
|
|||
|
||||
@Data
|
||||
public class UpdateWxPhoneForm {
|
||||
|
||||
@Schema(description = "客户Id")
|
||||
private Long customerId;
|
||||
|
||||
private String code;
|
||||
|
||||
}
|
|
@ -3,8 +3,10 @@ package com.atguigu.daijia.model.vo.driver;
|
|||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class CosUploadVo {
|
||||
public class CosUploadVo implements Serializable {
|
||||
|
||||
@Schema(description = "上传路径")
|
||||
private String url;
|
||||
|
|
|
@ -3,37 +3,38 @@ package com.atguigu.daijia.model.vo.driver;
|
|||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class IdCardOcrVo {
|
||||
public class IdCardOcrVo implements Serializable {
|
||||
|
||||
@Schema(description = "姓名")
|
||||
private String name;
|
||||
@Schema(description = "姓名")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "性别 1:男 2:女")
|
||||
private String gender;
|
||||
@Schema(description = "性别 1:男 2:女")
|
||||
private String gender;
|
||||
|
||||
@Schema(description = "生日")
|
||||
private Date birthday;
|
||||
@Schema(description = "生日")
|
||||
private Date birthday;
|
||||
|
||||
@Schema(description = "身份证号码")
|
||||
private String idcardNo;
|
||||
@Schema(description = "身份证号码")
|
||||
private String idcardNo;
|
||||
|
||||
@Schema(description = "身份证地址")
|
||||
private String idcardAddress;
|
||||
@Schema(description = "身份证地址")
|
||||
private String idcardAddress;
|
||||
|
||||
@Schema(description = "身份证有效期")
|
||||
private Date idcardExpire;
|
||||
@Schema(description = "身份证有效期")
|
||||
private Date idcardExpire;
|
||||
|
||||
@Schema(description = "身份证正面")
|
||||
private String idcardFrontUrl;
|
||||
@Schema(description = "身份证正面回显")
|
||||
private String idcardFrontShowUrl;
|
||||
@Schema(description = "身份证正面")
|
||||
private String idcardFrontUrl;
|
||||
@Schema(description = "身份证正面回显")
|
||||
private String idcardFrontShowUrl;
|
||||
|
||||
@Schema(description = "身份证背面")
|
||||
private String idcardBackUrl;
|
||||
@Schema(description = "身份证背面回显")
|
||||
private String idcardBackShowUrl;
|
||||
@Schema(description = "身份证背面")
|
||||
private String idcardBackUrl;
|
||||
@Schema(description = "身份证背面回显")
|
||||
private String idcardBackShowUrl;
|
||||
|
||||
}
|
|
@ -9,9 +9,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class ServerGatewayApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServerGatewayApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import reactor.core.publisher.Mono;
|
|||
@Component
|
||||
public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
return chain.filter(exchange);
|
||||
|
|
|
@ -1,9 +1,26 @@
|
|||
package com.atguigu.daijia.customer.client;
|
||||
|
||||
import com.atguigu.daijia.common.result.Result;
|
||||
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
|
||||
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@FeignClient(value = "service-customer")
|
||||
public interface CustomerInfoFeignClient {
|
||||
|
||||
// 登录客户端接口
|
||||
@GetMapping("/customer/info/login/{code}")
|
||||
Result<Long> login(@PathVariable String code);
|
||||
|
||||
// 获取乘客用户信息
|
||||
@GetMapping("/customer/info/getCustomerLoginInfo/{customerId}")
|
||||
Result<CustomerLoginVo> getCustomerLoginInfo(@PathVariable("customerId") Long customerId);
|
||||
|
||||
// 更新客户微信手机号码
|
||||
@PostMapping("/customer/info/updateWxPhoneNumber")
|
||||
Result<Boolean> updateWxPhoneNumber(@RequestBody UpdateWxPhoneForm updateWxPhoneForm);
|
||||
}
|
|
@ -12,5 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
@FeignClient(value = "service-driver")
|
||||
public interface CosFeignClient {
|
||||
|
||||
|
||||
// 上传文件
|
||||
@PostMapping(value = "cos/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
Result<CosUploadVo> upload(@RequestPart("file") MultipartFile file, @RequestParam(name = "path", defaultValue = "auth") String path);
|
||||
}
|
|
@ -1,11 +1,8 @@
|
|||
package com.atguigu.daijia.driver.client;
|
||||
|
||||
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.web.bind.annotation.GetMapping;
|
||||
|
@ -16,5 +13,19 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||
@FeignClient(value = "service-driver")
|
||||
public interface DriverInfoFeignClient {
|
||||
|
||||
// 小程序司机登录
|
||||
@GetMapping("/driver/info/login/{code}")
|
||||
Result<Long> login(@PathVariable("code") String code);
|
||||
|
||||
// 获取司机登录信息
|
||||
@GetMapping("/driver/info/getDriverLoginInfo/{driverId}")
|
||||
Result<DriverLoginVo> getDriverInfo(@PathVariable Long driverId);
|
||||
|
||||
// 获取司机认证信息
|
||||
@GetMapping("/driver/info/getDriverAuthInfo/{driverId}")
|
||||
Result<DriverAuthInfoVo> getDriverAuthInfo(@PathVariable("driverId") Long driverId);
|
||||
|
||||
// 更新司机认证信息
|
||||
@PostMapping("/driver/info/updateDriverAuthInfo")
|
||||
Result<Boolean> UpdateDriverAuthInfo(@RequestBody UpdateDriverAuthInfoForm updateDriverAuthInfoForm);
|
||||
}
|
|
@ -12,5 +12,11 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
@FeignClient(value = "service-driver")
|
||||
public interface OcrFeignClient {
|
||||
|
||||
// 身份证识别
|
||||
@PostMapping(value = "/ocr/idCardOcr", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
Result<IdCardOcrVo> idCardOcr(@RequestPart("file") MultipartFile file);
|
||||
|
||||
// 驾驶证识别
|
||||
@PostMapping(value = "/ocr/driverLicenseOcr", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
Result<DriverLicenseOcrVo> driverLicenseOcr(@RequestPart("file") MultipartFile file);
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
spring.application.name=service-coupon
|
||||
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-coupon
|
||||
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
|
|
@ -18,6 +18,10 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-miniapp</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class ServiceCustomerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServiceCustomerApplication.class, args);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.atguigu.daijia.customer.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.customer.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;
|
||||
}
|
|
@ -2,28 +2,38 @@ package com.atguigu.daijia.customer.controller;
|
|||
|
||||
import com.atguigu.daijia.common.result.Result;
|
||||
import com.atguigu.daijia.customer.service.CustomerInfoService;
|
||||
import com.atguigu.daijia.model.entity.customer.CustomerInfo;
|
||||
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
|
||||
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/customer/info")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class CustomerInfoController {
|
||||
|
||||
@Autowired
|
||||
private CustomerInfoService customerInfoService;
|
||||
@Autowired
|
||||
private CustomerInfoService customerInfoService;
|
||||
|
||||
@Operation(summary = "获取客户基本信息")
|
||||
@GetMapping("/getCustomerInfo/{customerId}")
|
||||
public Result<CustomerInfo> getCustomerInfo(@PathVariable Long customerId) {
|
||||
return Result.ok(customerInfoService.getById(customerId));
|
||||
}
|
||||
@Operation(summary = "获取客户登录信息")
|
||||
@GetMapping("/getCustomerLoginInfo/{customerId}")
|
||||
public Result<CustomerLoginVo> getCustomerLoginInfo(@PathVariable Long customerId) {
|
||||
CustomerLoginVo customerLoginVo = customerInfoService.getCustomerInfo(customerId);
|
||||
return Result.ok(customerLoginVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "小程序授权登录")
|
||||
@GetMapping("/login/{code}")
|
||||
public Result<Long> login(@PathVariable String code) {
|
||||
return Result.ok(customerInfoService.login(code));
|
||||
}
|
||||
|
||||
@Operation(summary = "更新客户微信手机号码")
|
||||
@PostMapping("/updateWxPhoneNumber")
|
||||
public Result<Boolean> updateWxPhoneNumber(@RequestBody UpdateWxPhoneForm updateWxPhoneForm) {
|
||||
return Result.ok(customerInfoService.updateWxPhoneNumber(updateWxPhoneForm));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,29 @@
|
|||
package com.atguigu.daijia.customer.service;
|
||||
|
||||
import com.atguigu.daijia.model.entity.customer.CustomerInfo;
|
||||
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
|
||||
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
public interface CustomerInfoService extends IService<CustomerInfo> {
|
||||
/**
|
||||
* 微信小程序登录接口
|
||||
* @param code 登录码
|
||||
* @return 登录内容
|
||||
*/
|
||||
Long login(String code);
|
||||
|
||||
/**
|
||||
* 获取客户登录信息
|
||||
* @param customerId 乘客端id
|
||||
* @return 客户相关信息
|
||||
*/
|
||||
CustomerLoginVo getCustomerInfo(Long customerId);
|
||||
|
||||
/**
|
||||
* 更新客户微信手机号码
|
||||
* @param updateWxPhoneForm 更新用户手机号表单
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
Boolean updateWxPhoneNumber(UpdateWxPhoneForm updateWxPhoneForm);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,126 @@
|
|||
package com.atguigu.daijia.customer.service.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import com.atguigu.daijia.common.execption.GuiguException;
|
||||
import com.atguigu.daijia.common.result.ResultCodeEnum;
|
||||
import com.atguigu.daijia.customer.mapper.CustomerInfoMapper;
|
||||
import com.atguigu.daijia.customer.mapper.CustomerLoginLogMapper;
|
||||
import com.atguigu.daijia.customer.service.CustomerInfoService;
|
||||
import com.atguigu.daijia.model.entity.customer.CustomerInfo;
|
||||
import com.atguigu.daijia.model.entity.customer.CustomerLoginLog;
|
||||
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
|
||||
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, CustomerInfo> implements CustomerInfoService {
|
||||
|
||||
@Autowired
|
||||
private WxMaService wxMaService;
|
||||
|
||||
@Autowired
|
||||
private CustomerInfoMapper customerInfoMapper;
|
||||
|
||||
@Autowired
|
||||
private CustomerLoginLogMapper customerLoginLogMapper;
|
||||
|
||||
/**
|
||||
* 微信小程序登录接口
|
||||
*
|
||||
* @param code 登录码
|
||||
* @return 登录内容
|
||||
*/
|
||||
@Override
|
||||
public Long login(String code) {
|
||||
// 1 获取code值,使用微信工具包对象,获取微信唯一标识openid
|
||||
String openid;
|
||||
try {
|
||||
WxMaJscode2SessionResult sessionInfo = wxMaService.getUserService().getSessionInfo(code);
|
||||
openid = sessionInfo.getOpenid();
|
||||
} catch (WxErrorException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// 2 根据openid查询数据库表,判断是否第一次登录
|
||||
// 如果openid不存在返回null,如果存在返回一条记录
|
||||
LambdaQueryWrapper<CustomerInfo> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CustomerInfo::getWxOpenId, openid);
|
||||
CustomerInfo customerInfo = customerInfoMapper.selectOne(wrapper);
|
||||
|
||||
// 3 如果第一次登录,添加信息到用户表
|
||||
if (customerInfo == null) {
|
||||
customerInfo = new CustomerInfo();
|
||||
customerInfo.setNickname(String.valueOf(System.currentTimeMillis()));
|
||||
customerInfo.setAvatarUrl("https://oss.aliyuncs.com/aliyun_id_photo_bucket/default_handsome.jpg");
|
||||
customerInfo.setWxOpenId(openid);
|
||||
customerInfoMapper.insert(customerInfo);
|
||||
}
|
||||
|
||||
// 4 记录登录日志信息
|
||||
CustomerLoginLog customerLoginLog = new CustomerLoginLog();
|
||||
customerLoginLog.setCustomerId(customerInfo.getId());
|
||||
customerLoginLog.setMsg("小程序登录");
|
||||
customerLoginLogMapper.insert(customerLoginLog);
|
||||
|
||||
// 5 返回用户id
|
||||
return customerInfo.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户登录信息
|
||||
*
|
||||
* @param customerId 乘客端id
|
||||
* @return 客户相关信息
|
||||
*/
|
||||
@Override
|
||||
public CustomerLoginVo getCustomerInfo(Long customerId) {
|
||||
// 1 根据用户id查询用户信息
|
||||
CustomerInfo customerInfo = customerInfoMapper.selectById(customerId);
|
||||
|
||||
// 2 封装到CustomerLoginVo
|
||||
CustomerLoginVo customerLoginVo = new CustomerLoginVo();
|
||||
BeanUtils.copyProperties(customerInfo, customerLoginVo);
|
||||
|
||||
String phone = customerInfo.getPhone();
|
||||
customerLoginVo.setIsBindPhone(StringUtils.hasText(phone));
|
||||
|
||||
// 3 CustomerLoginVo返回
|
||||
return customerLoginVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新客户微信手机号码
|
||||
* 个人版无法进行测试
|
||||
*
|
||||
* @param updateWxPhoneForm 更新用户手机号表单
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateWxPhoneNumber(UpdateWxPhoneForm updateWxPhoneForm) {
|
||||
// 1 根据code值获取微信绑定手机号码
|
||||
try {
|
||||
WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getPhoneNoInfo(updateWxPhoneForm.getCode());
|
||||
String phoneNumber = phoneNoInfo.getPhoneNumber();
|
||||
|
||||
// 更新用户信息
|
||||
Long customerId = updateWxPhoneForm.getCustomerId();
|
||||
CustomerInfo customerInfo = customerInfoMapper.selectById(customerId);
|
||||
customerInfo.setPhone(phoneNumber);
|
||||
customerInfoMapper.updateById(customerInfo);
|
||||
|
||||
return true;
|
||||
} catch (WxErrorException e) {
|
||||
throw new GuiguException(ResultCodeEnum.DATA_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
spring.application.name=service-customer
|
||||
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-customer
|
||||
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,10 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project 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">
|
||||
<parent>
|
||||
<groupId>com.atguigu.daijia</groupId>
|
||||
<artifactId>service</artifactId><version>1.0</version>
|
||||
<artifactId>service</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -13,6 +14,20 @@
|
|||
<version>1.0</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-miniapp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.qcloud</groupId>
|
||||
<artifactId>cos_api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tencentcloudapi</groupId>
|
||||
<artifactId>tencentcloud-sdk-java</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package com.atguigu.daijia.driver.config;
|
||||
|
||||
import com.qcloud.cos.COSClient;
|
||||
import com.qcloud.cos.ClientConfig;
|
||||
import com.qcloud.cos.auth.BasicCOSCredentials;
|
||||
import com.qcloud.cos.auth.COSCredentials;
|
||||
import com.qcloud.cos.http.HttpProtocol;
|
||||
import com.qcloud.cos.region.Region;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "tencent.cloud")
|
||||
public class TencentCloudProperties {
|
||||
private String secretId;
|
||||
private String secretKey;
|
||||
private String region;
|
||||
private String bucketPrivate;
|
||||
|
||||
private String persionGroupId;
|
||||
|
||||
@Bean
|
||||
public COSClient getCosClient() {
|
||||
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
|
||||
// 2 设置 bucket 的地域, COS 地域
|
||||
Region region = new Region(this.region);
|
||||
ClientConfig clientConfig = new ClientConfig(region);
|
||||
// 这里建议设置使用 https 协议
|
||||
clientConfig.setHttpProtocol(HttpProtocol.https);
|
||||
// 3 生成 cos 客户端。
|
||||
return new COSClient(cred, clientConfig);
|
||||
}
|
||||
}
|
|
@ -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,24 +1,16 @@
|
|||
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 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.RestController;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "腾讯云CI审核接口管理")
|
||||
@RestController
|
||||
@RequestMapping(value="/cos")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@RequestMapping(value = "/cos")
|
||||
public class CiController {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -13,11 +13,18 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
@Slf4j
|
||||
@Tag(name = "腾讯云cos上传接口管理")
|
||||
@RestController
|
||||
@RequestMapping(value="/cos")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@RequestMapping(value = "/cos")
|
||||
public class CosController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private CosService cosService;
|
||||
|
||||
@Operation(summary = "上传")
|
||||
@PostMapping("/upload")
|
||||
//@GuiguLogin
|
||||
public Result<CosUploadVo> upload(@RequestPart("file") MultipartFile file, @RequestParam("path") String path) {
|
||||
CosUploadVo cosUploadVo = cosService.upload(file, path);
|
||||
return Result.ok(cosUploadVo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
package com.atguigu.daijia.driver.controller;
|
||||
|
||||
import com.atguigu.daijia.driver.service.DriverAccountService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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.RestController;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "司机账户API接口管理")
|
||||
@RestController
|
||||
@RequestMapping(value="/driver/account")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@RequestMapping(value = "/driver/account")
|
||||
public class DriverAccountController {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,60 @@
|
|||
package com.atguigu.daijia.driver.controller;
|
||||
|
||||
import com.atguigu.daijia.common.result.Result;
|
||||
import com.atguigu.daijia.driver.service.DriverInfoService;
|
||||
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.DriverLoginVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "司机API接口管理")
|
||||
@RestController
|
||||
@RequestMapping(value="/driver/info")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@RequestMapping(value = "/driver/info")
|
||||
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);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取司机登录信息")
|
||||
@GetMapping("/getDriverLoginInfo/{driverId}")
|
||||
public Result<DriverLoginVo> getDriverInfo(@PathVariable Long driverId) {
|
||||
DriverLoginVo driverLoginVo = driverInfoService.getDriverInfo(driverId);
|
||||
return Result.ok(driverLoginVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取司机认证信息")
|
||||
@GetMapping("/getDriverAuthInfo/{driverId}")
|
||||
public Result<DriverAuthInfoVo> getDriverAuthInfo(@PathVariable Long driverId) {
|
||||
DriverAuthInfoVo driverAuthInfoVo = driverInfoService.getDriverAuthInfo(driverId);
|
||||
return Result.ok(driverAuthInfoVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新司机认证信息")
|
||||
@PostMapping("/updateDriverAuthInfo")
|
||||
public Result<Boolean> updateDriverAuthInfo(@RequestBody UpdateDriverAuthInfoForm updateDriverAuthInfoForm) {
|
||||
Boolean isSuccess = driverInfoService.updateDriverAuthInfo(updateDriverAuthInfoForm);
|
||||
return Result.ok(isSuccess);
|
||||
}
|
||||
|
||||
@Operation(summary = "创建司机人脸模型")
|
||||
@PostMapping("/creatDriverFaceModel")
|
||||
public Result<Boolean> creatDriverFaceModel(@RequestBody DriverFaceModelForm driverFaceModelForm) {
|
||||
Boolean isSuccess = driverInfoService.creatDriverFaceModel(driverFaceModelForm);
|
||||
return Result.ok(isSuccess);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -17,10 +17,24 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
@Slf4j
|
||||
@Tag(name = "腾讯云识别接口管理")
|
||||
@RestController
|
||||
@RequestMapping(value="/ocr")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@RequestMapping(value = "/ocr")
|
||||
public class OcrController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private OcrService ocrService;
|
||||
|
||||
@Operation(summary = "身份证识别")
|
||||
@PostMapping("/idCardOcr")
|
||||
public Result<IdCardOcrVo> idCardOcr(@RequestPart("file") MultipartFile file) {
|
||||
IdCardOcrVo idCardOcrVo = ocrService.idCardOcr(file);
|
||||
return Result.ok(idCardOcrVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "驾驶证识别")
|
||||
@PostMapping("/driverLicenseOcr")
|
||||
public Result<DriverLicenseOcrVo> driverLicenseOcr(@RequestPart("file") MultipartFile file) {
|
||||
DriverLicenseOcrVo vo = ocrService.driverLicenseOcr(file);
|
||||
return Result.ok(vo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
package com.atguigu.daijia.driver.service;
|
||||
|
||||
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface CosService {
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file 文件
|
||||
* @param path path
|
||||
* @return CosUploadVo
|
||||
*/
|
||||
CosUploadVo upload(MultipartFile file, String path);
|
||||
|
||||
String getImageUrl(String path);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,51 @@
|
|||
package com.atguigu.daijia.driver.service;
|
||||
|
||||
import com.atguigu.daijia.model.entity.driver.DriverInfo;
|
||||
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.DriverLoginVo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
public interface DriverInfoService extends IService<DriverInfo> {
|
||||
|
||||
/**
|
||||
* 小程序司机登录
|
||||
*
|
||||
* @param code 唯一票据
|
||||
* @return openid
|
||||
*/
|
||||
Long login(String code);
|
||||
|
||||
/**
|
||||
* 获取司机登录信息
|
||||
*
|
||||
* @param driverId 司机id
|
||||
* @return 司机信息
|
||||
*/
|
||||
DriverLoginVo getDriverInfo(Long driverId);
|
||||
|
||||
/**
|
||||
* 获取司机认证信息
|
||||
*
|
||||
* @param driverId 司机id
|
||||
* @return 司机认证信息
|
||||
*/
|
||||
DriverAuthInfoVo getDriverAuthInfo(Long driverId);
|
||||
|
||||
/**
|
||||
* 更新司机认证信息
|
||||
*
|
||||
* @param updateDriverAuthInfoForm 更新司机认证信息表单
|
||||
* @return 是否成功
|
||||
*/
|
||||
Boolean updateDriverAuthInfo(UpdateDriverAuthInfoForm updateDriverAuthInfoForm);
|
||||
|
||||
/**
|
||||
* 创建司机人脸模型
|
||||
*
|
||||
* @param driverFaceModelForm 司机人脸模型
|
||||
*/
|
||||
Boolean creatDriverFaceModel(DriverFaceModelForm driverFaceModelForm);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,25 @@
|
|||
package com.atguigu.daijia.driver.service;
|
||||
|
||||
import com.atguigu.daijia.model.vo.driver.DriverLicenseOcrVo;
|
||||
import com.atguigu.daijia.model.vo.driver.IdCardOcrVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface OcrService {
|
||||
|
||||
|
||||
/**
|
||||
* 身份证识别
|
||||
*
|
||||
* @param file 身份认证识别
|
||||
* @return 身份识别返回信息
|
||||
*/
|
||||
IdCardOcrVo idCardOcr(MultipartFile file);
|
||||
|
||||
/**
|
||||
* 驾驶证识别
|
||||
*
|
||||
* @param file 身份认证识别
|
||||
* @return 驾驶证识别返回信息
|
||||
*/
|
||||
DriverLicenseOcrVo driverLicenseOcr(MultipartFile file);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,93 @@
|
|||
package com.atguigu.daijia.driver.service.impl;
|
||||
|
||||
import com.atguigu.daijia.driver.config.TencentCloudProperties;
|
||||
import com.atguigu.daijia.driver.service.CosService;
|
||||
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
|
||||
import com.qcloud.cos.COSClient;
|
||||
import com.qcloud.cos.http.HttpMethodName;
|
||||
import com.qcloud.cos.model.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class CosServiceImpl implements CosService {
|
||||
|
||||
@Autowired
|
||||
private TencentCloudProperties tencentCloudProperties;
|
||||
|
||||
@Autowired
|
||||
private COSClient cosClient;
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file 文件
|
||||
* @param path path
|
||||
* @return CosUploadVo
|
||||
*/
|
||||
@Override
|
||||
public CosUploadVo upload(MultipartFile file, String path) {
|
||||
// 元数据信息
|
||||
ObjectMetadata meta = new ObjectMetadata();
|
||||
meta.setContentLength(file.getSize());
|
||||
meta.setContentEncoding("UTF-8");
|
||||
meta.setContentType(file.getContentType());
|
||||
|
||||
// 向存储桶中保存文件
|
||||
String fileType = Objects.requireNonNull(file.getOriginalFilename()).substring(file.getOriginalFilename().lastIndexOf(".")); // 文件后缀名
|
||||
String uploadPath = "/driver/" + path + "/" + UUID.randomUUID().toString().replaceAll("-", "") + fileType;
|
||||
PutObjectRequest putObjectRequest;
|
||||
try {
|
||||
putObjectRequest = new PutObjectRequest(tencentCloudProperties.getBucketPrivate(), uploadPath, file.getInputStream(), meta);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
putObjectRequest.setStorageClass(StorageClass.Standard);
|
||||
|
||||
// 上传文件
|
||||
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
|
||||
cosClient.shutdown();
|
||||
// // 图片审核
|
||||
// Boolean imageAuditing = ciService.imageAuditing(uploadPath);
|
||||
// if (!imageAuditing) {
|
||||
// // 删除违规图片
|
||||
// cosClient.deleteObject(tencentCloudProperties.getBucketPrivate(), uploadPath);
|
||||
// throw new GuiguException(ResultCodeEnum.IMAGE_AUDITION_FAIL);
|
||||
// }
|
||||
|
||||
// 返回vo对象
|
||||
CosUploadVo cosUploadVo = new CosUploadVo();
|
||||
cosUploadVo.setUrl(uploadPath);
|
||||
// 图片临时访问url,回显使用
|
||||
String imageUrl = this.getImageUrl(uploadPath);
|
||||
cosUploadVo.setShowUrl(imageUrl);
|
||||
|
||||
return cosUploadVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImageUrl(String path) {
|
||||
if (!StringUtils.hasText(path)) return "";
|
||||
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(tencentCloudProperties.getBucketPrivate(), path, HttpMethodName.GET);
|
||||
|
||||
// 设置临时URL有效期为15分钟
|
||||
Date date = new DateTime().plusMinutes(15).toDate();
|
||||
request.setExpiration(date);
|
||||
|
||||
// 调用方法获取
|
||||
URL url = cosClient.generatePresignedUrl(request);
|
||||
cosClient.shutdown();
|
||||
return url.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,177 @@
|
|||
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.DriverLoginLogMapper;
|
||||
import com.atguigu.daijia.driver.mapper.DriverSetMapper;
|
||||
import com.atguigu.daijia.driver.service.CosService;
|
||||
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.DriverLoginLog;
|
||||
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.DriverLoginVo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Transactional
|
||||
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;
|
||||
|
||||
@Autowired
|
||||
private CosService cosService;
|
||||
|
||||
@Autowired
|
||||
private DriverInfoMapper driverInfoMapper;
|
||||
|
||||
/**
|
||||
* 小程序司机登录
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取司机登录信息
|
||||
*
|
||||
* @param driverId 司机id
|
||||
* @return 司机信息
|
||||
*/
|
||||
@Override
|
||||
public DriverLoginVo getDriverInfo(Long driverId) {
|
||||
// 根据司机id查询司机信息
|
||||
DriverInfo driverInfo = getById(driverId);
|
||||
|
||||
// 构建vo信息
|
||||
DriverLoginVo driverLoginVo = new DriverLoginVo();
|
||||
BeanUtils.copyProperties(driverInfo, driverLoginVo);
|
||||
|
||||
// 是否需要建档人脸识别
|
||||
String faceModelId = driverInfo.getFaceModelId();
|
||||
boolean isArchiveFace = StringUtils.hasText(faceModelId);
|
||||
driverLoginVo.setIsArchiveFace(isArchiveFace);
|
||||
|
||||
return driverLoginVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取司机认证信息
|
||||
*
|
||||
* @param driverId 司机id
|
||||
* @return 司机认证信息
|
||||
*/
|
||||
@Override
|
||||
public DriverAuthInfoVo getDriverAuthInfo(Long driverId) {
|
||||
DriverInfo driverInfo = driverInfoMapper.selectById(driverId);
|
||||
DriverAuthInfoVo driverAuthInfoVo = new DriverAuthInfoVo();
|
||||
BeanUtils.copyProperties(driverInfo, driverAuthInfoVo);
|
||||
|
||||
driverAuthInfoVo.setIdcardBackShowUrl(cosService.getImageUrl(driverAuthInfoVo.getIdcardBackUrl()));
|
||||
driverAuthInfoVo.setIdcardFrontShowUrl(cosService.getImageUrl(driverAuthInfoVo.getIdcardFrontUrl()));
|
||||
driverAuthInfoVo.setIdcardHandShowUrl(cosService.getImageUrl(driverAuthInfoVo.getIdcardHandUrl()));
|
||||
driverAuthInfoVo.setDriverLicenseFrontShowUrl(cosService.getImageUrl(driverAuthInfoVo.getDriverLicenseFrontUrl()));
|
||||
driverAuthInfoVo.setDriverLicenseBackShowUrl(cosService.getImageUrl(driverAuthInfoVo.getDriverLicenseBackUrl()));
|
||||
driverAuthInfoVo.setDriverLicenseHandShowUrl(cosService.getImageUrl(driverAuthInfoVo.getDriverLicenseHandUrl()));
|
||||
|
||||
return driverAuthInfoVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新司机认证信息
|
||||
*
|
||||
* @param updateDriverAuthInfoForm 更新司机认证信息表单
|
||||
* @return 是否成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateDriverAuthInfo(UpdateDriverAuthInfoForm updateDriverAuthInfoForm) {
|
||||
// 获取司机id
|
||||
Long driverId = updateDriverAuthInfoForm.getDriverId();
|
||||
|
||||
// 修改操作
|
||||
DriverInfo driverInfo = new DriverInfo();
|
||||
driverInfo.setId(driverId);
|
||||
BeanUtils.copyProperties(updateDriverAuthInfoForm, driverInfo);
|
||||
|
||||
return this.updateById(driverInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建司机人脸模型
|
||||
*
|
||||
* @param driverFaceModelForm 司机人脸模型
|
||||
*/
|
||||
@Override
|
||||
public Boolean creatDriverFaceModel(DriverFaceModelForm driverFaceModelForm) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,158 @@
|
|||
package com.atguigu.daijia.driver.service.impl;
|
||||
|
||||
import com.alibaba.nacos.common.codec.Base64;
|
||||
import com.atguigu.daijia.common.execption.GuiguException;
|
||||
import com.atguigu.daijia.common.result.ResultCodeEnum;
|
||||
import com.atguigu.daijia.driver.config.TencentCloudProperties;
|
||||
import com.atguigu.daijia.driver.service.CosService;
|
||||
import com.atguigu.daijia.driver.service.OcrService;
|
||||
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
|
||||
import com.atguigu.daijia.model.vo.driver.DriverLicenseOcrVo;
|
||||
import com.atguigu.daijia.model.vo.driver.IdCardOcrVo;
|
||||
import com.tencentcloudapi.common.Credential;
|
||||
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||
import com.tencentcloudapi.ocr.v20181119.OcrClient;
|
||||
import com.tencentcloudapi.ocr.v20181119.models.DriverLicenseOCRRequest;
|
||||
import com.tencentcloudapi.ocr.v20181119.models.DriverLicenseOCRResponse;
|
||||
import com.tencentcloudapi.ocr.v20181119.models.IDCardOCRRequest;
|
||||
import com.tencentcloudapi.ocr.v20181119.models.IDCardOCRResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class OcrServiceImpl implements OcrService {
|
||||
|
||||
@Autowired
|
||||
private TencentCloudProperties tencentCloudProperties;
|
||||
|
||||
@Autowired
|
||||
private CosService cosService;
|
||||
|
||||
/**
|
||||
* 身份证识别
|
||||
*
|
||||
* @param file 身份认证识别
|
||||
* @return 身份识别返回信息
|
||||
*/
|
||||
@Override
|
||||
public IdCardOcrVo idCardOcr(MultipartFile file) {
|
||||
try {
|
||||
// 图片转换base64格式字符串
|
||||
byte[] base64 = Base64.encodeBase64(file.getBytes());
|
||||
String fileBase64 = new String(base64);
|
||||
|
||||
// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
|
||||
Credential cred = new Credential(tencentCloudProperties.getSecretId(), tencentCloudProperties.getSecretKey());
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("ocr.tencentcloudapi.com");
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
OcrClient client = new OcrClient(cred, tencentCloudProperties.getRegion(), clientProfile);
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
IDCardOCRRequest req = new IDCardOCRRequest();
|
||||
// 设置文件
|
||||
req.setImageBase64(fileBase64);
|
||||
|
||||
// 返回的resp是一个IDCardOCRResponse的实例,与请求对象对应
|
||||
IDCardOCRResponse resp = client.IDCardOCR(req);
|
||||
|
||||
// 转换为IdCardOcrVo对象
|
||||
IdCardOcrVo idCardOcrVo = new IdCardOcrVo();
|
||||
if (StringUtils.hasText(resp.getName())) {
|
||||
// 身份证正面
|
||||
idCardOcrVo.setName(resp.getName());
|
||||
idCardOcrVo.setGender("男".equals(resp.getSex()) ? "1" : "2");
|
||||
idCardOcrVo.setBirthday(DateTimeFormat.forPattern("yyyy/MM/dd").parseDateTime(resp.getBirth()).toDate());
|
||||
idCardOcrVo.setIdcardNo(resp.getIdNum());
|
||||
idCardOcrVo.setIdcardAddress(resp.getAddress());
|
||||
|
||||
// 上传身份证正面图片到腾讯云cos
|
||||
CosUploadVo cosUploadVo = cosService.upload(file, "idCard");
|
||||
idCardOcrVo.setIdcardFrontUrl(cosUploadVo.getUrl());
|
||||
idCardOcrVo.setIdcardFrontShowUrl(cosUploadVo.getShowUrl());
|
||||
} else {
|
||||
// 身份证反面
|
||||
String idcardExpireString = resp.getValidDate().split("-")[1];
|
||||
idCardOcrVo.setIdcardExpire(DateTimeFormat.forPattern("yyyy.MM.dd").parseDateTime(idcardExpireString).toDate());
|
||||
// 上传身份证反面图片到腾讯云cos
|
||||
CosUploadVo cosUploadVo = cosService.upload(file, "idCard");
|
||||
idCardOcrVo.setIdcardBackUrl(cosUploadVo.getUrl());
|
||||
idCardOcrVo.setIdcardBackShowUrl(cosUploadVo.getShowUrl());
|
||||
}
|
||||
return idCardOcrVo;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new GuiguException(ResultCodeEnum.DATA_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 驾驶证识别
|
||||
*
|
||||
* @param file 身份认证识别
|
||||
* @return 驾驶证识别返回信息
|
||||
*/
|
||||
@Override
|
||||
public DriverLicenseOcrVo driverLicenseOcr(MultipartFile file) {
|
||||
try {
|
||||
// 图片转换base64格式字符串
|
||||
byte[] base64 = Base64.encodeBase64(file.getBytes());
|
||||
String fileBase64 = new String(base64);
|
||||
|
||||
// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
|
||||
Credential cred = new Credential(tencentCloudProperties.getSecretId(), tencentCloudProperties.getSecretKey());
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("ocr.tencentcloudapi.com");
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
OcrClient client = new OcrClient(cred, tencentCloudProperties.getRegion(),
|
||||
clientProfile);
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
DriverLicenseOCRRequest req = new DriverLicenseOCRRequest();
|
||||
req.setImageBase64(fileBase64);
|
||||
|
||||
// 返回的resp是一个DriverLicenseOCRResponse的实例,与请求对象对应
|
||||
DriverLicenseOCRResponse resp = client.DriverLicenseOCR(req);
|
||||
|
||||
// 封装到vo对象里面
|
||||
DriverLicenseOcrVo driverLicenseOcrVo = new DriverLicenseOcrVo();
|
||||
if (StringUtils.hasText(resp.getName())) {
|
||||
// 驾驶证正面
|
||||
// 驾驶证名称要与身份证名称一致
|
||||
driverLicenseOcrVo.setName(resp.getName());
|
||||
driverLicenseOcrVo.setDriverLicenseClazz(resp.getClass_());
|
||||
driverLicenseOcrVo.setDriverLicenseNo(resp.getCardCode());
|
||||
driverLicenseOcrVo.setDriverLicenseIssueDate(DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(resp.getDateOfFirstIssue()).toDate());
|
||||
driverLicenseOcrVo.setDriverLicenseExpire(DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(resp.getEndDate()).toDate());
|
||||
|
||||
// 上传驾驶证反面图片到腾讯云cos
|
||||
CosUploadVo cosUploadVo = cosService.upload(file, "driverLicense");
|
||||
driverLicenseOcrVo.setDriverLicenseFrontUrl(cosUploadVo.getUrl());
|
||||
driverLicenseOcrVo.setDriverLicenseFrontShowUrl(cosUploadVo.getShowUrl());
|
||||
} else {
|
||||
// 驾驶证反面
|
||||
// 上传驾驶证反面图片到腾讯云cos
|
||||
CosUploadVo cosUploadVo = cosService.upload(file, "driverLicense");
|
||||
driverLicenseOcrVo.setDriverLicenseBackUrl(cosUploadVo.getUrl());
|
||||
driverLicenseOcrVo.setDriverLicenseBackShowUrl(cosUploadVo.getShowUrl());
|
||||
}
|
||||
|
||||
return driverLicenseOcrVo;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new GuiguException(ResultCodeEnum.DATA_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -10,10 +10,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class WebCustomerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WebCustomerApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,49 @@
|
|||
package com.atguigu.daijia.customer.controller;
|
||||
|
||||
import com.atguigu.daijia.common.login.GuiguLogin;
|
||||
import com.atguigu.daijia.common.result.Result;
|
||||
import com.atguigu.daijia.common.util.AuthContextHolder;
|
||||
import com.atguigu.daijia.customer.service.CustomerService;
|
||||
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
|
||||
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "客户API接口管理")
|
||||
@RestController
|
||||
@RequestMapping("/customer")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class CustomerController {
|
||||
@Autowired
|
||||
private CustomerService customerInfoService;
|
||||
|
||||
@Operation(summary = "获取客户登录信息")
|
||||
@GuiguLogin
|
||||
@GetMapping("/getCustomerLoginInfo")
|
||||
public Result<CustomerLoginVo> getCustomerLoginInfo() {
|
||||
// 调用service
|
||||
CustomerLoginVo customerLoginVo = customerInfoService.getCustomerInfo();
|
||||
return Result.ok(customerLoginVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "小程序授权登录")
|
||||
@GetMapping("/login/{code}")
|
||||
public Result<String> wxLogin(@PathVariable String code) {
|
||||
String login = customerInfoService.login(code);
|
||||
return Result.ok(login);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新用户微信手机号")
|
||||
@GuiguLogin
|
||||
@PostMapping("/updateWxPhone")
|
||||
public Result<Boolean> updateWxPhone(@RequestBody UpdateWxPhoneForm updateWxPhoneForm) {
|
||||
updateWxPhoneForm.setCustomerId(AuthContextHolder.getUserId());
|
||||
Boolean updateWxPhoneNumber = customerInfoService.updateWxPhoneNumber(updateWxPhoneForm);
|
||||
return Result.ok(updateWxPhoneNumber);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,28 @@
|
|||
package com.atguigu.daijia.customer.service;
|
||||
|
||||
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
|
||||
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
|
||||
|
||||
public interface CustomerService {
|
||||
/**
|
||||
* 微信小程序登录接口
|
||||
* @param code 登录码
|
||||
* @return 登录内容
|
||||
*/
|
||||
String login(String code);
|
||||
|
||||
/**
|
||||
* 获取客户登录信息
|
||||
*
|
||||
* @return 客户相关信息
|
||||
*/
|
||||
CustomerLoginVo getCustomerInfo();
|
||||
|
||||
/**
|
||||
* 更新客户微信手机号码
|
||||
*
|
||||
* @param updateWxPhoneForm 更新用户手机号表单
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
Boolean updateWxPhoneNumber(UpdateWxPhoneForm updateWxPhoneForm);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,105 @@
|
|||
package com.atguigu.daijia.customer.service.impl;
|
||||
|
||||
import com.atguigu.daijia.common.constant.RedisConstant;
|
||||
import com.atguigu.daijia.common.execption.GuiguException;
|
||||
import com.atguigu.daijia.common.result.Result;
|
||||
import com.atguigu.daijia.common.result.ResultCodeEnum;
|
||||
import com.atguigu.daijia.common.util.AuthContextHolder;
|
||||
import com.atguigu.daijia.customer.client.CustomerInfoFeignClient;
|
||||
import com.atguigu.daijia.customer.service.CustomerService;
|
||||
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
|
||||
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class CustomerServiceImpl implements CustomerService {
|
||||
@Autowired
|
||||
private CustomerInfoFeignClient client;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<Object, Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private CustomerInfoFeignClient customerInfoFeignClient;
|
||||
|
||||
/**
|
||||
* 微信小程序登录接口
|
||||
*
|
||||
* @param code 登录码
|
||||
* @return 登录内容
|
||||
*/
|
||||
@Override
|
||||
public String login(String code) {
|
||||
// 1 拿着code进行远程调用,返回用户id
|
||||
Result<Long> loginResult = client.login(code);
|
||||
|
||||
// 2 判断如果返回失败了,返回错误提示
|
||||
Integer codeResult = loginResult.getCode();
|
||||
if (codeResult != 200) {
|
||||
throw new GuiguException(ResultCodeEnum.DATA_ERROR);
|
||||
}
|
||||
|
||||
// 3 获取远程调用返回用户id
|
||||
Long customerId = loginResult.getData();
|
||||
|
||||
// 4 判断返回用户id是否为空,如果为空,返回错误提示
|
||||
if (customerId == null) {
|
||||
throw new GuiguException(ResultCodeEnum.DATA_ERROR);
|
||||
}
|
||||
|
||||
// 5 生成token字符串
|
||||
String token = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
|
||||
// 6 把用户id放到Redis,设置过期时间
|
||||
redisTemplate.opsForValue().set(RedisConstant.USER_LOGIN_KEY_PREFIX + token,
|
||||
customerId.toString(),
|
||||
RedisConstant.USER_LOGIN_KEY_TIMEOUT,
|
||||
TimeUnit.SECONDS);
|
||||
|
||||
// 7 返回token
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户登录信息
|
||||
*
|
||||
* @return 客户相关信息
|
||||
*/
|
||||
@Override
|
||||
public CustomerLoginVo getCustomerInfo() {
|
||||
// 1 从ThreadLocal获取用户id
|
||||
Long customerId = AuthContextHolder.getUserId();
|
||||
|
||||
// 根据用户id进行远程调用 得到用户信息
|
||||
Result<CustomerLoginVo> customerLoginVoResult = customerInfoFeignClient.getCustomerLoginInfo(customerId);
|
||||
|
||||
Integer code = customerLoginVoResult.getCode();
|
||||
if (code != 200) throw new GuiguException(ResultCodeEnum.DATA_ERROR);
|
||||
|
||||
CustomerLoginVo customerLoginVo = customerLoginVoResult.getData();
|
||||
if (customerLoginVo == null) throw new GuiguException(ResultCodeEnum.DATA_ERROR);
|
||||
|
||||
// 5 返回用户信息
|
||||
return customerLoginVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新客户微信手机号码
|
||||
*
|
||||
* @param updateWxPhoneForm 更新用户手机号表单
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateWxPhoneNumber(UpdateWxPhoneForm updateWxPhoneForm) {
|
||||
Result<Boolean> booleanResult = customerInfoFeignClient.updateWxPhoneNumber(updateWxPhoneForm);
|
||||
System.out.println(booleanResult.getData());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
spring.application.name=web-customer
|
||||
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-customer
|
||||
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;
|
||||
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "腾讯云cos上传接口管理")
|
||||
@RestController
|
||||
@RequestMapping(value="/cos")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@RequestMapping(value = "/cos")
|
||||
public class CosController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private CosService cosService;
|
||||
|
||||
@Operation(summary = "上传文件")
|
||||
@PostMapping("upload")
|
||||
public Result<CosUploadVo> upload(@RequestPart("file") MultipartFile file,
|
||||
@RequestParam(name = "path", defaultValue = "auth") String path) {
|
||||
CosUploadVo vo = cosService.upload(file, path);
|
||||
return Result.ok(vo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,57 @@
|
|||
package com.atguigu.daijia.driver.controller;
|
||||
|
||||
import com.atguigu.daijia.common.login.GuiguLogin;
|
||||
import com.atguigu.daijia.common.result.Result;
|
||||
import com.atguigu.daijia.common.util.AuthContextHolder;
|
||||
import com.atguigu.daijia.driver.service.DriverService;
|
||||
import com.atguigu.daijia.model.form.driver.UpdateDriverAuthInfoForm;
|
||||
import com.atguigu.daijia.model.vo.driver.DriverAuthInfoVo;
|
||||
import com.atguigu.daijia.model.vo.driver.DriverLoginVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "司机API接口管理")
|
||||
@RestController
|
||||
@RequestMapping(value="/driver")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@RequestMapping(value = "/driver")
|
||||
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);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取司机登录信息")
|
||||
@GetMapping("/getDriverLoginInfo")
|
||||
@GuiguLogin
|
||||
public Result<DriverLoginVo> getDriverInfo() {
|
||||
DriverLoginVo driverLoginVo = driverService.getDriverInfo();
|
||||
return Result.ok(driverLoginVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取司机认证信息")
|
||||
@GuiguLogin
|
||||
@GetMapping("/getDriverAuthInfo")
|
||||
public Result<DriverAuthInfoVo> getDriverAuthInfo() {
|
||||
// 获取登录用户id,当前是司机id
|
||||
Long driverId = AuthContextHolder.getUserId();
|
||||
return Result.ok(driverService.getDriverAuthInfo(driverId));
|
||||
}
|
||||
|
||||
@Operation(summary = "更新司机认证信息")
|
||||
@GuiguLogin
|
||||
@PostMapping("/updateDriverAuthInfo")
|
||||
public Result<Boolean> updateDriverAuthInfo(@RequestBody UpdateDriverAuthInfoForm updateDriverAuthInfoForm) {
|
||||
updateDriverAuthInfoForm.setDriverId(AuthContextHolder.getUserId());
|
||||
return Result.ok(driverService.updateDriverAuthInfo(updateDriverAuthInfoForm));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,29 @@
|
|||
package com.atguigu.daijia.driver.controller;
|
||||
|
||||
import com.atguigu.daijia.common.result.Result;
|
||||
import com.atguigu.daijia.driver.service.FileService;
|
||||
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Tag(name = "上传管理接口")
|
||||
@RestController
|
||||
@RequestMapping("file")
|
||||
public class FileController {
|
||||
|
||||
@Autowired
|
||||
private FileService fileService;
|
||||
|
||||
@Operation(summary = "上传")
|
||||
@PostMapping("/upload")
|
||||
public Result<String> upload(@RequestPart("file") MultipartFile file) {
|
||||
CosUploadVo cosUploadVo = fileService.upload(file);
|
||||
return Result.ok(cosUploadVo.getShowUrl());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,40 @@
|
|||
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 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.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "腾讯云识别接口管理")
|
||||
@RestController
|
||||
@RequestMapping(value="/ocr")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@RequestMapping(value = "/ocr")
|
||||
public class OcrController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private OcrService ocrService;
|
||||
|
||||
@Operation(summary = "身份证识别")
|
||||
//@GuiguLogin
|
||||
@PostMapping("/idCardOcr")
|
||||
public Result<IdCardOcrVo> uploadDriverLicenseOcr(@RequestPart("file") MultipartFile file) {
|
||||
return Result.ok(ocrService.idCardOcr(file));
|
||||
}
|
||||
|
||||
@Operation(summary = "驾驶证识别")
|
||||
//@GuiguLogin
|
||||
@PostMapping("/driverLicenseOcr")
|
||||
public Result<DriverLicenseOcrVo> driverLicenseOcr(@RequestPart("file") MultipartFile file) {
|
||||
return Result.ok(ocrService.driverLicenseOcr(file));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
package com.atguigu.daijia.driver.service;
|
||||
|
||||
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface CosService {
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file 文件
|
||||
* @param path path
|
||||
* @return CosUploadVo
|
||||
*/
|
||||
CosUploadVo upload(MultipartFile file, String path);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,39 @@
|
|||
package com.atguigu.daijia.driver.service;
|
||||
|
||||
import com.atguigu.daijia.model.form.driver.UpdateDriverAuthInfoForm;
|
||||
import com.atguigu.daijia.model.vo.driver.DriverAuthInfoVo;
|
||||
import com.atguigu.daijia.model.vo.driver.DriverLoginVo;
|
||||
|
||||
public interface DriverService {
|
||||
|
||||
/**
|
||||
* 小程序司机登录
|
||||
*
|
||||
* @param code 唯一票据
|
||||
* @return openid
|
||||
*/
|
||||
String login(String code);
|
||||
|
||||
/**
|
||||
* 获取司机登录信息
|
||||
*
|
||||
* @return 司机信息
|
||||
*/
|
||||
DriverLoginVo getDriverInfo();
|
||||
|
||||
/**
|
||||
* 获取司机认证信息
|
||||
*
|
||||
* @param driverId 司机id
|
||||
* @return 司机认证信息
|
||||
*/
|
||||
DriverAuthInfoVo getDriverAuthInfo(Long driverId);
|
||||
|
||||
/**
|
||||
* 更新司机认证信息
|
||||
*
|
||||
* @param updateDriverAuthInfoForm 更新司机认证信息表单
|
||||
* @return 是否成功
|
||||
*/
|
||||
Boolean updateDriverAuthInfo(UpdateDriverAuthInfoForm updateDriverAuthInfoForm);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
package com.atguigu.daijia.driver.service;
|
||||
|
||||
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface FileService {
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file 文件
|
||||
* @return CosUploadVo
|
||||
*/
|
||||
CosUploadVo upload(MultipartFile file);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,24 @@
|
|||
package com.atguigu.daijia.driver.service;
|
||||
|
||||
import com.atguigu.daijia.model.vo.driver.DriverLicenseOcrVo;
|
||||
import com.atguigu.daijia.model.vo.driver.IdCardOcrVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface OcrService {
|
||||
|
||||
/**
|
||||
* 身份证识别
|
||||
*
|
||||
* @param file 身份认证识别
|
||||
* @return 身份识别返回信息
|
||||
*/
|
||||
IdCardOcrVo idCardOcr(MultipartFile file);
|
||||
|
||||
/**
|
||||
* 驾驶证识别
|
||||
*
|
||||
* @param file 身份认证识别
|
||||
* @return 驾驶证识别返回信息
|
||||
*/
|
||||
DriverLicenseOcrVo driverLicenseOcr(MultipartFile file);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,31 @@
|
|||
package com.atguigu.daijia.driver.service.impl;
|
||||
|
||||
import com.atguigu.daijia.common.result.Result;
|
||||
import com.atguigu.daijia.driver.client.CosFeignClient;
|
||||
import com.atguigu.daijia.driver.service.CosService;
|
||||
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class CosServiceImpl implements CosService {
|
||||
|
||||
@Autowired
|
||||
private CosFeignClient cosFeignClient;
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file 文件
|
||||
* @param path path
|
||||
* @return CosUploadVo
|
||||
*/
|
||||
@Override
|
||||
public CosUploadVo upload(MultipartFile file, String path) {
|
||||
Result<CosUploadVo> voResult = cosFeignClient.upload(file, path);
|
||||
return voResult.getData();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,83 @@
|
|||
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.common.util.AuthContextHolder;
|
||||
import com.atguigu.daijia.driver.client.DriverInfoFeignClient;
|
||||
import com.atguigu.daijia.driver.service.DriverService;
|
||||
import com.atguigu.daijia.model.form.driver.UpdateDriverAuthInfoForm;
|
||||
import com.atguigu.daijia.model.vo.driver.DriverAuthInfoVo;
|
||||
import com.atguigu.daijia.model.vo.driver.DriverLoginVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取司机登录信息
|
||||
*
|
||||
* @return 司机信息
|
||||
*/
|
||||
@Override
|
||||
public DriverLoginVo getDriverInfo() {
|
||||
Long userId = AuthContextHolder.getUserId();
|
||||
return driverInfoFeignClient.getDriverInfo(userId).getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取司机认证信息
|
||||
*
|
||||
* @param driverId 司机id
|
||||
* @return 司机认证信息
|
||||
*/
|
||||
@Override
|
||||
public DriverAuthInfoVo getDriverAuthInfo(Long driverId) {
|
||||
Result<DriverAuthInfoVo> authInfoVoResult = driverInfoFeignClient.getDriverAuthInfo(driverId);
|
||||
return authInfoVoResult.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新司机认证信息
|
||||
*
|
||||
* @param updateDriverAuthInfoForm 更新司机认证信息表单
|
||||
* @return 是否成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateDriverAuthInfo(UpdateDriverAuthInfoForm updateDriverAuthInfoForm) {
|
||||
Result<Boolean> booleanResult = driverInfoFeignClient.UpdateDriverAuthInfo(updateDriverAuthInfoForm);
|
||||
return booleanResult.getData();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,31 @@
|
|||
package com.atguigu.daijia.driver.service.impl;
|
||||
|
||||
import com.atguigu.daijia.common.result.Result;
|
||||
import com.atguigu.daijia.driver.client.CosFeignClient;
|
||||
import com.atguigu.daijia.driver.service.FileService;
|
||||
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class FileServiceImpl implements FileService {
|
||||
|
||||
@Autowired
|
||||
private CosFeignClient cosFeignClient;
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file 文件
|
||||
* @return CosUploadVo
|
||||
*/
|
||||
@Override
|
||||
public CosUploadVo upload(MultipartFile file) {
|
||||
Result<CosUploadVo> voResult = cosFeignClient.upload(file, "auth");
|
||||
return voResult.getData();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,43 @@
|
|||
package com.atguigu.daijia.driver.service.impl;
|
||||
|
||||
import com.atguigu.daijia.common.result.Result;
|
||||
import com.atguigu.daijia.driver.client.OcrFeignClient;
|
||||
import com.atguigu.daijia.driver.service.OcrService;
|
||||
import com.atguigu.daijia.model.vo.driver.DriverLicenseOcrVo;
|
||||
import com.atguigu.daijia.model.vo.driver.IdCardOcrVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class OcrServiceImpl implements OcrService {
|
||||
|
||||
@Autowired
|
||||
private OcrFeignClient ocrFeignClient;
|
||||
|
||||
/**
|
||||
* 身份证识别
|
||||
*
|
||||
* @param file 身份认证识别
|
||||
* @return 身份识别返回信息
|
||||
*/
|
||||
@Override
|
||||
public IdCardOcrVo idCardOcr(MultipartFile file) {
|
||||
Result<IdCardOcrVo> ocrVoResult = ocrFeignClient.idCardOcr(file);
|
||||
return ocrVoResult.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 驾驶证识别
|
||||
*
|
||||
* @param file 身份认证识别
|
||||
* @return 驾驶证识别返回信息
|
||||
*/
|
||||
@Override
|
||||
public DriverLicenseOcrVo driverLicenseOcr(MultipartFile file) {
|
||||
Result<DriverLicenseOcrVo> driverLicenseOcrVoResult = ocrFeignClient.driverLicenseOcr(file);
|
||||
return driverLicenseOcrVoResult.getData();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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