commit fd001c7fc3765a89fe56de4f5579d6aa93540334 Author: Your Name Date: Fri Nov 29 17:10:02 2024 +0800 滴滴网约车第一次提交 diff --git a/api-passenger/apipassenger.iml b/api-passenger/apipassenger.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/api-passenger/apipassenger.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/api-passenger/pom.xml b/api-passenger/pom.xml new file mode 100644 index 0000000..d90ed9d --- /dev/null +++ b/api-passenger/pom.xml @@ -0,0 +1,61 @@ + + + + online-taxi-public + com.mashibing + 1.0-SNAPSHOT + + 4.0.0 + + api-passenger + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2021.0.1.0 + + + + org.springframework.cloud + spring-cloud-starter-openfeign + 3.1.0 + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + 3.1.5 + + + + com.mashibing + internal-common + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-data-redis + 2.4.13 + + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + + + + + + \ No newline at end of file diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/ApiPassengerApplication.java b/api-passenger/src/main/java/com/mashibing/apipassenger/ApiPassengerApplication.java new file mode 100644 index 0000000..5e6ff8b --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/ApiPassengerApplication.java @@ -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); + } +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/ForecastPriceController.java b/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/ForecastPriceController.java new file mode 100644 index 0000000..de7a638 --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/ForecastPriceController.java @@ -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; + } +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/TestController.java b/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/TestController.java new file mode 100644 index 0000000..d16546d --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/TestController.java @@ -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"; + } +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/TokenController.java b/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/TokenController.java new file mode 100644 index 0000000..53cbb51 --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/TokenController.java @@ -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; + } +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/UserController.java b/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/UserController.java new file mode 100644 index 0000000..1dc47ab --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/UserController.java @@ -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); + } +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/VerificationCodeController.java b/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/VerificationCodeController.java new file mode 100644 index 0000000..3e49d1d --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/Controller/VerificationCodeController.java @@ -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); + } +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/interceptor/InterceptorConfig.java b/api-passenger/src/main/java/com/mashibing/apipassenger/interceptor/InterceptorConfig.java new file mode 100644 index 0000000..42b0d6f --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/interceptor/InterceptorConfig.java @@ -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"); + } +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/interceptor/JwtInterceptor.java b/api-passenger/src/main/java/com/mashibing/apipassenger/interceptor/JwtInterceptor.java new file mode 100644 index 0000000..b5a7d07 --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/interceptor/JwtInterceptor.java @@ -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; + } +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/remote/ServicePassengerUserClient.java b/api-passenger/src/main/java/com/mashibing/apipassenger/remote/ServicePassengerUserClient.java new file mode 100644 index 0000000..ebd85d1 --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/remote/ServicePassengerUserClient.java @@ -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 getUserByPhone(@PathVariable String phone); +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/remote/ServiceVerificationcodeClient.java b/api-passenger/src/main/java/com/mashibing/apipassenger/remote/ServiceVerificationcodeClient.java new file mode 100644 index 0000000..db9ef60 --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/remote/ServiceVerificationcodeClient.java @@ -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 getNumberCode(@PathVariable("size") int size); +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/service/ForecastPriceService.java b/api-passenger/src/main/java/com/mashibing/apipassenger/service/ForecastPriceService.java new file mode 100644 index 0000000..0d0134e --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/service/ForecastPriceService.java @@ -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); + + + } +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/service/TokenService.java b/api-passenger/src/main/java/com/mashibing/apipassenger/service/TokenService.java new file mode 100644 index 0000000..a7060f8 --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/service/TokenService.java @@ -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); + } +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/service/UserService.java b/api-passenger/src/main/java/com/mashibing/apipassenger/service/UserService.java new file mode 100644 index 0000000..6de5e7d --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/service/UserService.java @@ -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 userByPhone = servicePassengerUserClient.getUserByPhone(phone); + + + return ResponseResult.success(userByPhone.getData()); + } +} diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/service/VerificationCodeService.java b/api-passenger/src/main/java/com/mashibing/apipassenger/service/VerificationCodeService.java new file mode 100644 index 0000000..719c63c --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/service/VerificationCodeService.java @@ -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 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); + } +} diff --git a/api-passenger/src/main/resources/application.yml b/api-passenger/src/main/resources/application.yml new file mode 100644 index 0000000..584f00c --- /dev/null +++ b/api-passenger/src/main/resources/application.yml @@ -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 \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..47dca81 --- /dev/null +++ b/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.6.7 + + + com.mashibing + online-taxi-public + 1.0-SNAPSHOT + + api-passenger + service-verificationcode + internal-common + service-passenger-user + service-price + service-map + + pom + + + + com.alibaba + fastjson + 1.2.58 + + + org.projectlombok + lombok + 1.18.4 + + + + com.mashibing + internal-common + 1.0-SNAPSHOT + + + + com.auth0 + java-jwt + 3.14.0 + + + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2021.0.1.0 + pom + import + + + + + + \ No newline at end of file diff --git a/service-map/pom.xml b/service-map/pom.xml new file mode 100644 index 0000000..8c48897 --- /dev/null +++ b/service-map/pom.xml @@ -0,0 +1,35 @@ + + + + online-taxi-public + com.mashibing + 1.0-SNAPSHOT + + 4.0.0 + + service-map + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2021.0.1.0 + + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + + + + \ No newline at end of file diff --git a/service-map/src/main/java/com/mashibing/servicemap/ServiceMapApplication.java b/service-map/src/main/java/com/mashibing/servicemap/ServiceMapApplication.java new file mode 100644 index 0000000..bbf9227 --- /dev/null +++ b/service-map/src/main/java/com/mashibing/servicemap/ServiceMapApplication.java @@ -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(); + } +} diff --git a/service-map/src/main/java/com/mashibing/servicemap/controller/DirectionController.java b/service-map/src/main/java/com/mashibing/servicemap/controller/DirectionController.java new file mode 100644 index 0000000..b3d3b53 --- /dev/null +++ b/service-map/src/main/java/com/mashibing/servicemap/controller/DirectionController.java @@ -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(); + } +} diff --git a/service-map/src/main/java/com/mashibing/servicemap/remote/MapDirectionClient.java b/service-map/src/main/java/com/mashibing/servicemap/remote/MapDirectionClient.java new file mode 100644 index 0000000..76e11de --- /dev/null +++ b/service-map/src/main/java/com/mashibing/servicemap/remote/MapDirectionClient.java @@ -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 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; + } + + +} diff --git a/service-map/src/main/java/com/mashibing/servicemap/service/DirectionService.java b/service-map/src/main/java/com/mashibing/servicemap/service/DirectionService.java new file mode 100644 index 0000000..da36988 --- /dev/null +++ b/service-map/src/main/java/com/mashibing/servicemap/service/DirectionService.java @@ -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); + } +} diff --git a/service-map/src/main/resources/application.yml b/service-map/src/main/resources/application.yml new file mode 100644 index 0000000..d3f298e --- /dev/null +++ b/service-map/src/main/resources/application.yml @@ -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 \ No newline at end of file diff --git a/service-passenger-user/pom.xml b/service-passenger-user/pom.xml new file mode 100644 index 0000000..fc8fb1d --- /dev/null +++ b/service-passenger-user/pom.xml @@ -0,0 +1,39 @@ + + + + online-taxi-public + com.mashibing + 1.0-SNAPSHOT + + 4.0.0 + + service-passenger-user + + + + org.springframework.boot + spring-boot-starter-web + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3.1 + + + + mysql + mysql-connector-java + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2021.0.1.0 + + + + \ No newline at end of file diff --git a/service-passenger-user/servicepassengeruser.iml b/service-passenger-user/servicepassengeruser.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/service-passenger-user/servicepassengeruser.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/ServicePassengerUserApplication.java b/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/ServicePassengerUserApplication.java new file mode 100644 index 0000000..19c91c1 --- /dev/null +++ b/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/ServicePassengerUserApplication.java @@ -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); + } +} diff --git a/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/controller/UserController.java b/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/controller/UserController.java new file mode 100644 index 0000000..a0eed3d --- /dev/null +++ b/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/controller/UserController.java @@ -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); + } +} diff --git a/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/mapper/PassengerUserMapper.java b/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/mapper/PassengerUserMapper.java new file mode 100644 index 0000000..3cb7cd6 --- /dev/null +++ b/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/mapper/PassengerUserMapper.java @@ -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 { +} diff --git a/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/service/UserService.java b/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/service/UserService.java new file mode 100644 index 0000000..f531afc --- /dev/null +++ b/service-passenger-user/src/main/java/com/mashibing/servicepassengeruser/service/UserService.java @@ -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 map = new HashMap<>(); + map.put("passenger_phone",passengerPhone); + List 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 map = new HashMap<>(); + map.put("passenger_phone",passengerPhone); + List 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); + } + + } + +} diff --git a/service-passenger-user/src/main/resources/application.yml b/service-passenger-user/src/main/resources/application.yml new file mode 100644 index 0000000..6d348a3 --- /dev/null +++ b/service-passenger-user/src/main/resources/application.yml @@ -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 diff --git a/service-passenger-user/target/classes/application.yml b/service-passenger-user/target/classes/application.yml new file mode 100644 index 0000000..6d348a3 --- /dev/null +++ b/service-passenger-user/target/classes/application.yml @@ -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 diff --git a/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/ServicePassengerUserApplication.class b/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/ServicePassengerUserApplication.class new file mode 100644 index 0000000..64679b6 Binary files /dev/null and b/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/ServicePassengerUserApplication.class differ diff --git a/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/controller/UserController.class b/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/controller/UserController.class new file mode 100644 index 0000000..686d0d6 Binary files /dev/null and b/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/controller/UserController.class differ diff --git a/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/dto/PassengerUser.class b/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/dto/PassengerUser.class new file mode 100644 index 0000000..d1131c5 Binary files /dev/null and b/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/dto/PassengerUser.class differ diff --git a/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/mapper/PassengerUserMapper.class b/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/mapper/PassengerUserMapper.class new file mode 100644 index 0000000..760958b Binary files /dev/null and b/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/mapper/PassengerUserMapper.class differ diff --git a/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/service/UserService.class b/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/service/UserService.class new file mode 100644 index 0000000..82b9654 Binary files /dev/null and b/service-passenger-user/target/classes/com/mashibing/servicepassengeruser/service/UserService.class differ diff --git a/service-price/pom.xml b/service-price/pom.xml new file mode 100644 index 0000000..055e630 --- /dev/null +++ b/service-price/pom.xml @@ -0,0 +1,42 @@ + + + + online-taxi-public + com.mashibing + 1.0-SNAPSHOT + + 4.0.0 + + service-price + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2021.0.1.0 + + + + org.springframework.cloud + spring-cloud-starter-openfeign + 3.1.0 + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + 3.1.5 + + + + + + \ No newline at end of file diff --git a/service-price/serviceprice.iml b/service-price/serviceprice.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/service-price/serviceprice.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/service-price/src/main/java/com/mashibing/servicprice/ServicePriceApplication.java b/service-price/src/main/java/com/mashibing/servicprice/ServicePriceApplication.java new file mode 100644 index 0000000..ce5ee91 --- /dev/null +++ b/service-price/src/main/java/com/mashibing/servicprice/ServicePriceApplication.java @@ -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); + } +} diff --git a/service-price/src/main/java/com/mashibing/servicprice/controller/ForecastPriceController.java b/service-price/src/main/java/com/mashibing/servicprice/controller/ForecastPriceController.java new file mode 100644 index 0000000..7473b8e --- /dev/null +++ b/service-price/src/main/java/com/mashibing/servicprice/controller/ForecastPriceController.java @@ -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); + + } +} diff --git a/service-price/src/main/java/com/mashibing/servicprice/remote/ServiceMapClient.java b/service-price/src/main/java/com/mashibing/servicprice/remote/ServiceMapClient.java new file mode 100644 index 0000000..f130da7 --- /dev/null +++ b/service-price/src/main/java/com/mashibing/servicprice/remote/ServiceMapClient.java @@ -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 direction(@RequestBody ForecastPriceDTO forecastPriceDTO); +} diff --git a/service-price/src/main/java/com/mashibing/servicprice/service/ForecastPriceService.java b/service-price/src/main/java/com/mashibing/servicprice/service/ForecastPriceService.java new file mode 100644 index 0000000..f2c4071 --- /dev/null +++ b/service-price/src/main/java/com/mashibing/servicprice/service/ForecastPriceService.java @@ -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); + } +} diff --git a/service-price/src/main/resources/application.yml b/service-price/src/main/resources/application.yml new file mode 100644 index 0000000..8a210c7 --- /dev/null +++ b/service-price/src/main/resources/application.yml @@ -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 \ No newline at end of file diff --git a/service-verificationcode/pom.xml b/service-verificationcode/pom.xml new file mode 100644 index 0000000..88ec1ef --- /dev/null +++ b/service-verificationcode/pom.xml @@ -0,0 +1,35 @@ + + + + online-taxi-public + com.mashibing + 1.0-SNAPSHOT + + 4.0.0 + + service-verificationcode + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2021.0.1.0 + + + + com.mashibing + internal-common + 1.0-SNAPSHOT + + + + + \ No newline at end of file diff --git a/service-verificationcode/src/main/java/com/mashibing/serviceverificationcode/ServiceVerificationcodeApplication.java b/service-verificationcode/src/main/java/com/mashibing/serviceverificationcode/ServiceVerificationcodeApplication.java new file mode 100644 index 0000000..f51a282 --- /dev/null +++ b/service-verificationcode/src/main/java/com/mashibing/serviceverificationcode/ServiceVerificationcodeApplication.java @@ -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); + } +} diff --git a/service-verificationcode/src/main/java/com/mashibing/serviceverificationcode/controller/NumberCodeController.java b/service-verificationcode/src/main/java/com/mashibing/serviceverificationcode/controller/NumberCodeController.java new file mode 100644 index 0000000..57f9baa --- /dev/null +++ b/service-verificationcode/src/main/java/com/mashibing/serviceverificationcode/controller/NumberCodeController.java @@ -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); + } +} diff --git a/service-verificationcode/src/main/resources/application.yml b/service-verificationcode/src/main/resources/application.yml new file mode 100644 index 0000000..28180e0 --- /dev/null +++ b/service-verificationcode/src/main/resources/application.yml @@ -0,0 +1,9 @@ +server: + port: 8082 +spring: + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + application: + name: service-verificationcode \ No newline at end of file diff --git a/service-verificationcode/target/classes/application.yml b/service-verificationcode/target/classes/application.yml new file mode 100644 index 0000000..28180e0 --- /dev/null +++ b/service-verificationcode/target/classes/application.yml @@ -0,0 +1,9 @@ +server: + port: 8082 +spring: + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + application: + name: service-verificationcode \ No newline at end of file diff --git a/service-verificationcode/target/classes/com/mashibing/serviceverificationcode/ServiceVerificationcodeApplication.class b/service-verificationcode/target/classes/com/mashibing/serviceverificationcode/ServiceVerificationcodeApplication.class new file mode 100644 index 0000000..89cef67 Binary files /dev/null and b/service-verificationcode/target/classes/com/mashibing/serviceverificationcode/ServiceVerificationcodeApplication.class differ diff --git a/service-verificationcode/target/classes/com/mashibing/serviceverificationcode/controller/NumberCodeController.class b/service-verificationcode/target/classes/com/mashibing/serviceverificationcode/controller/NumberCodeController.class new file mode 100644 index 0000000..57f1388 Binary files /dev/null and b/service-verificationcode/target/classes/com/mashibing/serviceverificationcode/controller/NumberCodeController.class differ diff --git a/service-verificationcode/target/maven-archiver/pom.properties b/service-verificationcode/target/maven-archiver/pom.properties new file mode 100644 index 0000000..02127d5 --- /dev/null +++ b/service-verificationcode/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=service-verificationcode +groupId=com.mashibing +version=1.0-SNAPSHOT diff --git a/service-verificationcode/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/service-verificationcode/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..f8c07bb --- /dev/null +++ b/service-verificationcode/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +com\mashibing\serviceverificationcode\controller\NumberCodeController.class +com\mashibing\serviceverificationcode\ServiceVerificationcodeApplication.class diff --git a/service-verificationcode/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/service-verificationcode/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..a5e49f7 --- /dev/null +++ b/service-verificationcode/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -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 diff --git a/service-verificationcode/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/service-verificationcode/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/service-verificationcode/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/service-verificationcode/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/service-verificationcode/target/service-verificationcode-1.0-SNAPSHOT.jar b/service-verificationcode/target/service-verificationcode-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..b2f56bb Binary files /dev/null and b/service-verificationcode/target/service-verificationcode-1.0-SNAPSHOT.jar differ