滴滴网约车第一次提交

master
Your Name 10 months ago
commit fd001c7fc3

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

@ -0,0 +1,61 @@
<?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"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api-passenger</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--nacos-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.0.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>com.mashibing</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.4.13</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
</dependencies>
</project>

@ -0,0 +1,25 @@
package com.mashibing.apipassenger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import javax.swing.*;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-10-31-0:49
* 5 @Modified By:
* 6
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class ApiPassengerApplication {
public static void main(String[] args) {
SpringApplication.run(ApiPassengerApplication.class);
}
}

@ -0,0 +1,32 @@
package com.mashibing.apipassenger.Controller;
import com.mashibing.apipassenger.service.ForecastPriceService;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.ForecastPriceDTO;
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.RestController;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-28-14:10
* 5 @Modified By:
* 6
*/
@RestController
@Slf4j
public class ForecastPriceController {
@Autowired
private ForecastPriceService forecastPriceService;
@PostMapping("/forecast-price")
public ResponseResult forecastPrice(@RequestBody ForecastPriceDTO forecastPriceDTO){
forecastPriceService.forecastPrice(forecastPriceDTO.getDepLongitude(),forecastPriceDTO.getDepLongitude(),forecastPriceDTO.getDestLatitude(),forecastPriceDTO.getDestLongitude());
return null;
}
}

@ -0,0 +1,21 @@
package com.mashibing.apipassenger.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-10-31-0:52
* 5 @Modified By:
* 6
*/
@RestController
public class TestController {
@GetMapping("/test")
public String test(){
return "test api passenger";
}
}

@ -0,0 +1,28 @@
package com.mashibing.apipassenger.Controller;
import com.mashibing.apipassenger.service.TokenService;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.responese.TokenResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-21-17:00
* 5 @Modified By:
* 6
*/
@RestController
public class TokenController {
@Autowired
private TokenService tokenService;
public ResponseResult refreshToken(@RequestBody TokenResponse tokenResponse){
tokenService.refreshToken(tokenResponse.getRefreshToken());
return null;
}
}

@ -0,0 +1,36 @@
package com.mashibing.apipassenger.Controller;
import com.mashibing.apipassenger.service.UserService;
import com.mashibing.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-26-22:58
* 5 @Modified By:
* 6
*/
@RestController
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/users")
public ResponseResult getUser(HttpServletRequest request){
//解析token中需要用的参数
String accessToken = request.getHeader("Authorization");
userService.getUserByAccessToken(accessToken);
//用参数去查出用户
//把用户信息封装返回
return userService.getUserByAccessToken(accessToken);
}
}

@ -0,0 +1,41 @@
package com.mashibing.apipassenger.Controller;
import com.mashibing.internalcommon.request.VerificationCodeDTO;
import com.mashibing.apipassenger.service.VerificationCodeService;
import com.mashibing.internalcommon.dto.ResponseResult;
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.RestController;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-10-31-16:25
* 5 @Modified By:
* 6
*/
@RestController
public class VerificationCodeController {
@Autowired
private VerificationCodeService verificationCodeService;
@PostMapping("/verification-code")
public ResponseResult verificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
String passengerPhone = verificationCodeDTO.getPassengerPhone();
System.out.println("接受到的手机号参数:" +passengerPhone);
return verificationCodeService.generatorCode(passengerPhone);
}
@PostMapping("/check-code")
public ResponseResult checkVerificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
String passengerPhone = verificationCodeDTO.getPassengerPhone();
String verificationCode = verificationCodeDTO.getVerificationCode();
return verificationCodeService.checkCode(passengerPhone,verificationCode);
}
}

@ -0,0 +1,33 @@
package com.mashibing.apipassenger.interceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-20-14:16
* 5 @Modified By:
* 6
*/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
@Bean
public JwtInterceptor jwtInterceptor(){
return new JwtInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new JwtInterceptor())
//拦截的路径
.addPathPatterns("/**")
//不拦截的路径
.excludePathPatterns("/noauthTest")
.excludePathPatterns("/verification-code")
.excludePathPatterns("/check-code");
}
}

@ -0,0 +1,71 @@
package com.mashibing.apipassenger.interceptor;
import com.alibaba.nacos.common.utils.StringUtils;
import com.auth0.jwt.exceptions.AlgorithmMismatchException;
import com.auth0.jwt.exceptions.SignatureVerificationException;
import com.auth0.jwt.exceptions.TokenExpiredException;
import com.mashibing.internalcommon.constant.IdentityConstant;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.dto.TokenResult;
import com.mashibing.internalcommon.util.JwtUtils;
import com.mashibing.internalcommon.util.RedisPrefixUtils;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.security.SignatureException;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-20-13:51
* 5 @Modified By:
* 6
*/
public class JwtInterceptor implements HandlerInterceptor {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String resultString ="";
boolean result = Boolean.parseBoolean(null);
String token = request.getHeader("Authorization");
TokenResult tokenResult = JwtUtils.checkToken(token);
if(tokenResult == null){
resultString = "token invalid";
result = false;
}else{
String phone = tokenResult.getPhone();
String identity = tokenResult.getIdentity();
String tokenKey = RedisPrefixUtils.generatorTokenKey(phone,identity, IdentityConstant.ACCESS_TOKEN_TYPE);
//取redis中存好的用户的token做对比
String redistoken = stringRedisTemplate.opsForValue().get(tokenKey);
if((StringUtils.isBlank(redistoken) || (!token.trim().equals(redistoken)))){
resultString = "token invalid";
result = false;
}
}
if(!result){
PrintWriter out = response.getWriter();
out.print(JSONObject.fromObject(ResponseResult.fail(resultString).toString()));
}
return true;
}
}

@ -0,0 +1,27 @@
package com.mashibing.apipassenger.remote;
import com.mashibing.internalcommon.dto.PassengerUser;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.VerificationCodeDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-19-15:46
* 5 @Modified By:
* 6
*/
@FeignClient("service-passenger-user")
public interface ServicePassengerUserClient {
@RequestMapping(method = RequestMethod.POST,value = "/user")
public ResponseResult loginOrRegister(@RequestBody VerificationCodeDTO verificationCodeDTO);
@RequestMapping(method = RequestMethod.GET,value = "/user/{phone}")
public ResponseResult<PassengerUser> getUserByPhone(@PathVariable String phone);
}

@ -0,0 +1,23 @@
package com.mashibing.apipassenger.remote;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.responese.NumberCodeResponese;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-02-17:57
* 5 @Modified By:
* 6
*/
@FeignClient("service-verificationcode")
public interface ServiceVerificationcodeClient {
@RequestMapping(method = RequestMethod.GET,value = "/numberCode/{size}")
ResponseResult<NumberCodeResponese> getNumberCode(@PathVariable("size") int size);
}

@ -0,0 +1,26 @@
package com.mashibing.apipassenger.service;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.responese.ForecastPriceResponese;
import org.springframework.stereotype.Service;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-28-14:29
* 5 @Modified By:
* 6
*/
@Service
public class ForecastPriceService {
public ResponseResult forecastPrice(String depLongitude,String depLatitude,String destLongitude,String destLatitude){
ForecastPriceResponese forecastPriceResponese = new ForecastPriceResponese();
forecastPriceResponese.setPrice(14);
return ResponseResult.success(forecastPriceResponese);
}
}

@ -0,0 +1,62 @@
package com.mashibing.apipassenger.service;
import com.alibaba.nacos.common.utils.StringUtils;
import com.mashibing.internalcommon.constant.CommonStatusEnum;
import com.mashibing.internalcommon.constant.IdentityConstant;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.dto.TokenResult;
import com.mashibing.internalcommon.responese.TokenResponse;
import com.mashibing.internalcommon.util.JwtUtils;
import com.mashibing.internalcommon.util.RedisPrefixUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-25-15:08
* 5 @Modified By:
* 6
*/@Service
public class TokenService {
@Autowired
private StringRedisTemplate stringRedisTemplate;
public ResponseResult refreshToken(String refreshTokenSrc){
//解析refreshToken
TokenResult tokenResult = JwtUtils.checkToken(refreshTokenSrc);
if(tokenResult == null){
return ResponseResult.fail(CommonStatusEnum.TOKEN_ERROR.getCode(),CommonStatusEnum.TOKEN_ERROR.getValue());
}
String phone = tokenResult.getPhone();
String identity = tokenResult.getIdentity();
//读取redis中的refreshToken
String refreshTokenKey = RedisPrefixUtils.generatorTokenKey(phone,identity, IdentityConstant.REFRESH_TOKEN_TYPE);
String refreshTokenRedis = stringRedisTemplate.opsForValue().get(refreshTokenKey);
//校验
if((StringUtils.isBlank(refreshTokenRedis) || (!refreshTokenSrc.trim().equals(refreshTokenRedis)))){
return ResponseResult.fail(CommonStatusEnum.TOKEN_ERROR.getCode(),CommonStatusEnum.TOKEN_ERROR.getValue());
}
//生成
String refreshToken = JwtUtils.generatorToken(phone,identity,IdentityConstant.REFRESH_TOKEN_TYPE);
String accessToken = JwtUtils.generatorToken(phone,identity,IdentityConstant.ACCESS_TOKEN_TYPE);
String accessTokenKey = RedisPrefixUtils.generatorTokenKey(phone,identity, IdentityConstant.ACCESS_TOKEN_TYPE);
stringRedisTemplate.opsForValue().set(accessTokenKey,accessToken,30, TimeUnit.DAYS);
stringRedisTemplate.opsForValue().set(refreshTokenKey,refreshToken,31,TimeUnit.DAYS);
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setAccessToken(accessToken);
tokenResponse.setRefreshToken(refreshToken);
return ResponseResult.success(tokenResponse);
}
}

@ -0,0 +1,42 @@
package com.mashibing.apipassenger.service;
import com.mashibing.apipassenger.remote.ServicePassengerUserClient;
import com.mashibing.internalcommon.dto.PassengerUser;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.dto.TokenResult;
import com.mashibing.internalcommon.request.VerificationCodeDTO;
import com.mashibing.internalcommon.util.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-26-22:59
* 5 @Modified By:
* 6
*/
@Service
@Slf4j
public class UserService {
@Autowired
private ServicePassengerUserClient servicePassengerUserClient;
public ResponseResult getUserByAccessToken(String accessToken){
log.info("assessToken:" + accessToken);
TokenResult tokenResult = JwtUtils.checkToken(accessToken);
String phone = tokenResult.getPhone();
log.info("手机号:"+ phone);
ResponseResult<PassengerUser> userByPhone = servicePassengerUserClient.getUserByPhone(phone);
return ResponseResult.success(userByPhone.getData());
}
}

@ -0,0 +1,106 @@
package com.mashibing.apipassenger.service;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.StringUtils;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.mashibing.apipassenger.remote.ServicePassengerUserClient;
import com.mashibing.apipassenger.remote.ServiceVerificationcodeClient;
import com.mashibing.internalcommon.constant.CommonStatusEnum;
import com.mashibing.internalcommon.constant.IdentityConstant;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.VerificationCodeDTO;
import com.mashibing.internalcommon.responese.NumberCodeResponese;
import com.mashibing.internalcommon.responese.TokenResponse;
import com.mashibing.internalcommon.util.JwtUtils;
import com.mashibing.internalcommon.util.RedisPrefixUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-10-31-23:30
* 5 @Modified By:
* 6
*/
@Service
public class VerificationCodeService {
@Autowired
private ServiceVerificationcodeClient serviceVerificationcodeClient;
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
private ServicePassengerUserClient servicePassengerUserClient;
public ResponseResult generatorCode(String passengerPhone){
//调用验证码服务,获取验证码
System.out.println("调用验证码服务,获取验证码");
ResponseResult<NumberCodeResponese> response = serviceVerificationcodeClient.getNumberCode(6);
int numberCode = response.getData().getNumberCode();
System.out.println("验证码"+ numberCode);
//存入redis
System.out.println("存入redis");
String key = RedisPrefixUtils.generatorKeyByPhone(passengerPhone);
stringRedisTemplate.opsForValue().set(key,numberCode+"",2, TimeUnit.MINUTES);
//返回值
JSONObject result = new JSONObject();
result.put("code",1);
result.put("message","success");
return ResponseResult.success("");
}
public ResponseResult checkCode(String passengerPhone,String verificationCode){
String key = RedisPrefixUtils.generatorKeyByPhone(passengerPhone);
String codeRedis = stringRedisTemplate.opsForValue().get(key);
if(StringUtils.isBlank(codeRedis)){
return ResponseResult.fail(CommonStatusEnum.VERIFICATION_CODE_ERROR.getCode(),CommonStatusEnum.VERIFICATION_CODE_ERROR.getValue());
}else if(!verificationCode.trim().equals(codeRedis)){
return ResponseResult.fail(CommonStatusEnum.VERIFICATION_CODE_ERROR.getCode(),CommonStatusEnum.VERIFICATION_CODE_ERROR.getValue());
}
VerificationCodeDTO verificationCodeDTO = new VerificationCodeDTO();
verificationCodeDTO.setPassengerPhone(passengerPhone);
servicePassengerUserClient.loginOrRegister(verificationCodeDTO);
//颁发令牌
String accessToken = JwtUtils.generatorToken(passengerPhone, IdentityConstant.PASSENGER_INDENTITY,IdentityConstant.ACCESS_TOKEN_TYPE);
String refreshToken = JwtUtils.generatorToken(passengerPhone, IdentityConstant.PASSENGER_INDENTITY,IdentityConstant.REFRESH_TOKEN_TYPE);
//token存入redis中
String accesstokenKey = RedisPrefixUtils.generatorTokenKey(passengerPhone,IdentityConstant.PASSENGER_INDENTITY,IdentityConstant.ACCESS_TOKEN_TYPE);
stringRedisTemplate.opsForValue().set(accesstokenKey,accessToken,30,TimeUnit.DAYS);
String refreshtokenKey = RedisPrefixUtils.generatorTokenKey(passengerPhone,IdentityConstant.PASSENGER_INDENTITY,IdentityConstant.REFRESH_TOKEN_TYPE);
stringRedisTemplate.opsForValue().set(refreshtokenKey,refreshToken,31,TimeUnit.DAYS);
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setAccessToken(accessToken);
tokenResponse.setRefreshToken(refreshToken);
return ResponseResult.success(tokenResponse);
}
}

@ -0,0 +1,13 @@
server:
port: 8081
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: api-passenger
redis:
host: 127.0.0.1
port: 6379
database: 0

@ -0,0 +1,64 @@
<?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"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
</parent>
<groupId>com.mashibing</groupId>
<artifactId>online-taxi-public</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>api-passenger</module>
<module>service-verificationcode</module>
<module>internal-common</module>
<module>service-passenger-user</module>
<module>service-price</module>
<module>service-map</module>
</modules>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.58</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
</dependency>
<dependency>
<groupId>com.mashibing</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2021.0.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

@ -0,0 +1,35 @@
<?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"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-map</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--nacos-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.0.1.0</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
</dependencies>
</project>

@ -0,0 +1,28 @@
package com.mashibing.servicemap;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-28-16:16
* 5 @Modified By:
* 6
*/
@SpringBootApplication
@EnableDiscoveryClient
public class ServiceMapApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceMapApplication.class);
}
@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}
}

@ -0,0 +1,28 @@
package com.mashibing.servicemap.controller;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.ForecastPriceDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-28-16:19
* 5 @Modified By:
* 6
*/
@RestController
public class DirectionController {
@GetMapping("/driving")
public ResponseResult driving(@RequestBody ForecastPriceDTO forecastPriceDTO){
String depLongitude = forecastPriceDTO.getDepLongitude();
String depLatitude = forecastPriceDTO.getDepLatitude();
String destLongitude = forecastPriceDTO.getDestLongitude();
String destLatitude = forecastPriceDTO.getDestLatitude();
return ResponseResult.success();
}
}

@ -0,0 +1,88 @@
package com.mashibing.servicemap.remote;
import com.mashibing.internalcommon.constant.IdentityConstant;
import com.mashibing.internalcommon.responese.DirectionResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-28-16:32
* 5 @Modified By:
* 6
*/
@Service
public class MapDirectionClient {
@Value("${amap.key}")
private String amapKey;
@Autowired
private RestTemplate restTemplate;
public DirectionResponse direction(String depLongitude,String depLatitude,String destLongitude,String destLatitude){
StringBuilder urlBuild = new StringBuilder();
urlBuild.append(IdentityConstant.DIRECTION_URL);
urlBuild.append("?");
urlBuild.append("origin="+depLongitude+","+depLatitude);
urlBuild.append("&");
urlBuild.append("destination="+destLongitude+","+destLatitude);
urlBuild.append("&");
urlBuild.append("extensions=base");
urlBuild.append("&");
urlBuild.append("output=json");
urlBuild.append("&");
urlBuild.append("key="+amapKey);
ResponseEntity<String> directionEntity = restTemplate.getForEntity(urlBuild.toString(), String.class);
String directionString = directionEntity.getBody();
DirectionResponse directionResponse = parseDirectionEntity(directionString);
return directionResponse;
}
private DirectionResponse parseDirectionEntity(String directionString){
DirectionResponse directionResponse = null;
try {
// 最外层
JSONObject result = JSONObject.fromObject(directionString);
if(result.has(IdentityConstant.STATUS)) {
int status = result.getInt(IdentityConstant.STATUS);
if (status == 1){
if (result.has(IdentityConstant.ROUTE)){
JSONObject routeObject = result.getJSONObject(IdentityConstant.ROUTE);
JSONArray pathsArray = routeObject.getJSONArray(IdentityConstant.PATHS);
JSONObject pathObject = pathsArray.getJSONObject(0);
directionResponse = new DirectionResponse();
if (pathObject.has(IdentityConstant.DISTANCE)){
int distance = pathObject.getInt(IdentityConstant.DISTANCE);
directionResponse.setDistance(distance);
}
if (pathObject.has(IdentityConstant.DURATION)){
int duration = pathObject.getInt(IdentityConstant.DURATION);
directionResponse.setDuration(duration);
}
}
}
}
}catch (Exception e){
}
return directionResponse;
}
}

@ -0,0 +1,28 @@
package com.mashibing.servicemap.service;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.responese.DirectionResponse;
import com.mashibing.servicemap.remote.MapDirectionClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-28-16:22
* 5 @Modified By:
* 6
*/@Service
public class DirectionService {
@Autowired
private MapDirectionClient mapDirectionClient;
public ResponseResult driving(String depLongitude,String depLatitude,String destLongitude,String destLatitude){
DirectionResponse directionResponse = mapDirectionClient.direction(depLongitude,depLatitude,destLongitude,destLatitude);
return ResponseResult.success(directionResponse);
}
}

@ -0,0 +1,15 @@
server:
port: 8085
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: service-map
amap:
key: 54665674969040368450

@ -0,0 +1,39 @@
<?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"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-passenger-user</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--nacos-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.0.1.0</version>
</dependency>
</dependencies>
</project>

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

@ -0,0 +1,23 @@
package com.mashibing.servicepassengeruser;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-07-16:03
* 5 @Modified By:
* 6
*/
@SpringBootApplication
@EnableDiscoveryClient
@MapperScan("com.mashibing.servicepassengeruser.mapper")
public class ServicePassengerUserApplication {
public static void main(String[] args) {
SpringApplication.run(ServicePassengerUserApplication.class);
}
}

@ -0,0 +1,36 @@
package com.mashibing.servicepassengeruser.controller;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.VerificationCodeDTO;
import com.mashibing.servicepassengeruser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-07-16:15
* 5 @Modified By:
* 6
*/
@RestController
public class UserController {
@Autowired
private UserService userService;
@PostMapping("/user")
public ResponseResult loginOrReg(@RequestBody VerificationCodeDTO verificationCodeDTO){
String passenger = verificationCodeDTO.getPassengerPhone();
userService.loginOrRegister(passenger);
System.out.println("手机号"+ passenger);
return ResponseResult.success();
}
@GetMapping("/user/{phone}")
public ResponseResult getUser(@PathVariable("phone") String passengerPhone){
return userService.getUserByPhone(passengerPhone);
}
}

@ -0,0 +1,16 @@
package com.mashibing.servicepassengeruser.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mashibing.internalcommon.dto.PassengerUser;
import org.springframework.stereotype.Repository;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-19-14:26
* 5 @Modified By:
* 6
*/
@Repository
public interface PassengerUserMapper extends BaseMapper<PassengerUser> {
}

@ -0,0 +1,68 @@
package com.mashibing.servicepassengeruser.service;
import com.mashibing.internalcommon.constant.CommonStatusEnum;
import com.mashibing.internalcommon.dto.PassengerUser;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.servicepassengeruser.mapper.PassengerUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-07-16:29
* 5 @Modified By:
* 6
*/@Service
public class UserService {
@Autowired
private PassengerUserMapper passengerUserMapper;
public ResponseResult loginOrRegister(String passengerPhone){
Map<String,Object> map = new HashMap<>();
map.put("passenger_phone",passengerPhone);
List<PassengerUser> list = passengerUserMapper.selectByMap(map);
System.out.println(list.size()==0?"无记录":list.get(0).getPassengerPhone());
if(list.size()==0){
//新建用户
PassengerUser passengerUser = new PassengerUser();
passengerUser.setPassengerName("yonghu123");
passengerUser.setPassengerGender((byte)0);
passengerUser.setPassengerPhone(passengerPhone);
passengerUser.setState((byte)0);
LocalDateTime now = LocalDateTime.now();
passengerUser.setGmtCreate(now);
passengerUser.setGmtModified(now);
passengerUserMapper.insert(passengerUser);
}
return ResponseResult.success();
}
/**
*
* @param passengerPhone
* @return
*/
public ResponseResult getUserByPhone(String passengerPhone){
Map<String,Object> map = new HashMap<>();
map.put("passenger_phone",passengerPhone);
List<PassengerUser> list = passengerUserMapper.selectByMap(map);
if(list.size()==0){
return ResponseResult.fail(CommonStatusEnum.USER_NOT_EXISITS.getCode(),CommonStatusEnum.USER_NOT_EXISITS.getValue());
}else{
PassengerUser passengerUser = list.get(0);
return ResponseResult.success(passengerUser);
}
}
}

@ -0,0 +1,15 @@
server:
port: 8083
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/service-passenger-user?characterEncoding=utf-8&serverTimeZone=GMT%2B8
username: root
password: root
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: service-passenger-user

@ -0,0 +1,15 @@
server:
port: 8083
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/service-passenger-user?characterEncoding=utf-8&serverTimeZone=GMT%2B8
username: root
password: root
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: service-passenger-user

@ -0,0 +1,42 @@
<?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"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-price</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--nacos-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.0.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
<version>3.1.5</version>
</dependency>
</dependencies>
</project>

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

@ -0,0 +1,22 @@
package com.mashibing.servicprice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-28-15:52
* 5 @Modified By:
* 6
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class ServicePriceApplication {
public static void main(String[] args) {
SpringApplication.run(ServicePriceApplication.class);
}
}

@ -0,0 +1,33 @@
package com.mashibing.servicprice.controller;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.ForecastPriceDTO;
import com.mashibing.servicprice.service.ForecastPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-28-16:00
* 5 @Modified By:
* 6
*/
@RestController
public class ForecastPriceController {
@Autowired
private ForecastPriceService forecastPriceService;
public ResponseResult forecastPrice(@RequestBody ForecastPriceDTO forecastPriceDTO){
String depLongitude = forecastPriceDTO.getDepLongitude();
String depLatitude = forecastPriceDTO.getDepLatitude();
String destLongitude = forecastPriceDTO.getDestLongitude();
String destLatitude = forecastPriceDTO.getDestLatitude();
return forecastPriceService.forecastPrice(depLongitude,depLatitude,destLongitude,destLatitude);
}
}

@ -0,0 +1,23 @@
package com.mashibing.servicprice.remote;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.ForecastPriceDTO;
import com.mashibing.internalcommon.responese.DirectionResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-29-16:18
* 5 @Modified By:
* 6
*/
@FeignClient("service-map")
public interface ServiceMapClient {
@RequestMapping(method = RequestMethod.GET,value = "/direction")
public ResponseResult<DirectionResponse> direction(@RequestBody ForecastPriceDTO forecastPriceDTO);
}

@ -0,0 +1,36 @@
package com.mashibing.servicprice.service;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.ForecastPriceDTO;
import com.mashibing.internalcommon.responese.ForecastPriceResponese;
import com.mashibing.servicprice.remote.ServiceMapClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-28-16:02
* 5 @Modified By:
* 6
*/
@Service
public class ForecastPriceService {
@Autowired
private ServiceMapClient serviceMapClient;
public ResponseResult forecastPrice(String depLongitude,String depLatitude,String destLongitude,String destLatitude){
ForecastPriceDTO forecastPriceDTO = new ForecastPriceDTO();
forecastPriceDTO.setDepLatitude(depLatitude);
forecastPriceDTO.setDepLongitude(depLongitude);
forecastPriceDTO.setDestLatitude(destLatitude);
forecastPriceDTO.setDestLongitude(destLongitude);
serviceMapClient.direction(forecastPriceDTO);
ForecastPriceResponese forecastPriceResponese = new ForecastPriceResponese();
forecastPriceResponese.setPrice(14);
return ResponseResult.success(forecastPriceResponese);
}
}

@ -0,0 +1,14 @@
server:
port: 8084
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: service-price
feign:
httpclient:
enabled: true

@ -0,0 +1,35 @@
<?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"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-verificationcode</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--nacos-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.0.1.0</version>
</dependency>
<dependency>
<groupId>com.mashibing</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

@ -0,0 +1,21 @@
package com.mashibing.serviceverificationcode;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-01-2:09
* 5 @Modified By:
* 6
*/
@SpringBootApplication
@EnableDiscoveryClient
public class ServiceVerificationcodeApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceVerificationcodeApplication.class);
}
}

@ -0,0 +1,33 @@
package com.mashibing.serviceverificationcode.controller;
import com.alibaba.fastjson.JSONObject;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.responese.NumberCodeResponese;
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.RestController;
/**
* 2 @Author: Joy
* 3 @Description:
* 4 @Date Created in 2024-11-01-19:34
* 5 @Modified By:
* 6
*/
@RestController
public class NumberCodeController {
@GetMapping("/numberCode/{size}")
public ResponseResult numberCode(@PathVariable("size") int size){
System.out.println("size:" +size);
double mathRandom = (Math.random()*9 +1)*(Math.pow(10,size-1));
int resultInt = (int)mathRandom;
NumberCodeResponese responese = new NumberCodeResponese();
responese.setNumberCode(resultInt);
return ResponseResult.success(responese);
}
}

@ -0,0 +1,9 @@
server:
port: 8082
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: service-verificationcode

@ -0,0 +1,9 @@
server:
port: 8082
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: service-verificationcode

@ -0,0 +1,3 @@
artifactId=service-verificationcode
groupId=com.mashibing
version=1.0-SNAPSHOT

@ -0,0 +1,2 @@
com\mashibing\serviceverificationcode\controller\NumberCodeController.class
com\mashibing\serviceverificationcode\ServiceVerificationcodeApplication.class

@ -0,0 +1,2 @@
E:\mashibing_workspace\onlinetaxipublic\service-verificationcode\src\main\java\com\mashibing\serviceverificationcode\controller\NumberCodeController.java
E:\mashibing_workspace\onlinetaxipublic\service-verificationcode\src\main\java\com\mashibing\serviceverificationcode\ServiceVerificationcodeApplication.java
Loading…
Cancel
Save