周考1
commit
42c0dd02cd
|
@ -0,0 +1,35 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -0,0 +1,31 @@
|
|||
<?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>com.bw</groupId>
|
||||
<artifactId>week1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bw-auth</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- 项目公共 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.bw</groupId>
|
||||
<artifactId>bw-common</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringBoot Web-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,21 @@
|
|||
package com.bw;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Auth
|
||||
* @Date:2024/7/23 上午10:01
|
||||
* @Description: com.bw
|
||||
*/
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients
|
||||
public class AuthApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AuthApplication.class, args);
|
||||
System.out.println("Auth 模块启动成功!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.bw.advice;
|
||||
|
||||
import com.bw.common.result.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:AuthAdvice
|
||||
* @Date:2024/7/23 上午9:55
|
||||
* @Description: com.bw.advice
|
||||
*/
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class AuthAdvice {
|
||||
// 统一异常处理
|
||||
@ExceptionHandler(Throwable.class)
|
||||
public Result<String> handleException(Throwable e) {
|
||||
log.error("出现错误:{}",e.getMessage());
|
||||
return Result.error("网络异常,请稍后再尝试...");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.bw.config;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* 消息发送确认配置
|
||||
* 消息发送到交换机的回调
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class ConfirmCallbackConfig implements RabbitTemplate.ConfirmCallback {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
/**
|
||||
* @PostContruct是spring框架的注解,在⽅法上加该注解会在项⽬启动的时候执⾏该⽅法,也可以理解为在spring容器初始化的时候执
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
rabbitTemplate.setConfirmCallback(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 交换机不管是否收到消息的一个回调方法
|
||||
*
|
||||
* @param correlationData 消息相关数据
|
||||
* @param ack 交换机是否收到消息
|
||||
* @param cause 失败原因
|
||||
*/
|
||||
@Override
|
||||
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
||||
if (!ack) {
|
||||
String exchange = correlationData.getReturned().getExchange();
|
||||
String message = correlationData.getReturned().getMessage().getBody().toString();
|
||||
// 发送异常
|
||||
log.error("消息:{},发送到交换机:{}失败,原因是:{}", message, exchange, cause);
|
||||
// TODO 可以把异常信息 以及 消息的内容直接添加到 MYSQL
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.bw.config;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.ReturnedMessage;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* 消息发送到队列的确认
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class ReturnCallbackConfig implements RabbitTemplate.ReturnsCallback {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
/**
|
||||
* @PostContruct是spring框架的注解,在⽅法上加该注解会在项⽬启动的时候执⾏该⽅法,也可以理解为在spring容器初始化的时候执
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
rabbitTemplate.setReturnsCallback(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息发送失败 则会执行这个方法
|
||||
*
|
||||
* @param returnedMessage the returned message and metadata.
|
||||
*/
|
||||
@Override
|
||||
public void returnedMessage(ReturnedMessage returnedMessage) {
|
||||
log.error("消息:{},被交换机:{} 回退!退回原因为:{}",
|
||||
returnedMessage.getMessage().toString(), returnedMessage.getExchange(), returnedMessage.getReplyText());
|
||||
// TODO 回退了所有的信息,可做补偿机制
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package com.bw.controller;
|
||||
|
||||
import com.bw.common.domain.pojo.CarLog;
|
||||
import com.bw.common.domain.pojo.User;
|
||||
import com.bw.common.domain.request.CarReq;
|
||||
import com.bw.common.domain.request.UserReq;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import com.bw.common.domain.response.CarResp;
|
||||
import com.bw.common.domain.response.JwtResponse;
|
||||
import com.bw.common.result.PageResult;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.service.AuthService;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.http.HttpServletResponse;//图片
|
||||
|
||||
import cn.hutool.captcha.CircleCaptcha;//验证码
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Auth
|
||||
* @Date:2024/7/23 上午10:45
|
||||
* @Description: com.bw.controller
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/Auth")
|
||||
public class AuthController {
|
||||
@Autowired
|
||||
private AuthService service;
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
Result<JwtResponse> login(@RequestBody UserReq userReq) {
|
||||
return service.login(userReq);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
Result<Map<String,Object>> info() {
|
||||
String token = request.getHeader("token");
|
||||
return service.info(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
@GetMapping("/logout")
|
||||
Result<Boolean> logout() {
|
||||
String token = request.getHeader("token");
|
||||
return service.logout(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆列表查询
|
||||
*/
|
||||
@PostMapping("/selCarList")
|
||||
Result<PageResult<CarResp>> selCarList(@RequestBody CarReq carReq){
|
||||
return service.selCarList(carReq);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询租车记录
|
||||
*/
|
||||
@GetMapping("/selCarLogAll")
|
||||
Result<List<CarLogResp>> selCarLogAll(){
|
||||
return service.selCarLogAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
*/
|
||||
@PostMapping("/insCarLog")
|
||||
Result<Boolean> insCarLog(@RequestBody CarLog carLog){
|
||||
return service.insCarLog(carLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 归还车辆
|
||||
*/
|
||||
@PostMapping("/updCarLog")
|
||||
Result<Boolean> updCarLog(@RequestBody CarLog carLog){
|
||||
String token = request.getHeader("token");
|
||||
return service.updCarLog(carLog,token);
|
||||
}
|
||||
|
||||
/**
|
||||
* id精确查询
|
||||
*/
|
||||
@GetMapping("/getUserByUid")
|
||||
Result<User> getUserByUid(@RequestParam Long uid){
|
||||
return service.getUserByUid(uid);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.bw.factory;
|
||||
|
||||
import com.bw.common.domain.request.CarReq;
|
||||
import com.bw.common.domain.response.CarResp;
|
||||
import com.bw.common.result.PageResult;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.feign.CarFeign;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:CarFeignFallbackFactory
|
||||
* @Date:2024/7/23 上午10:40
|
||||
* @Description: com.bw.feign
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class CarFeignFallbackFactory implements FallbackFactory<CarFeign> {
|
||||
@Override
|
||||
public CarFeign create(Throwable cause) {
|
||||
return new CarFeign() {
|
||||
@Override
|
||||
public Result<PageResult<CarResp>> selCarList(CarReq carReq) {
|
||||
return Result.error("网络异常,请求失败...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> updCarSta(Long cid, Integer sta) {
|
||||
return Result.error("网络异常,请求失败...");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.bw.factory;
|
||||
|
||||
import com.bw.common.domain.pojo.CarLog;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.feign.CarFeign;
|
||||
import com.bw.feign.CarLogFeign;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:CarFeignFallbackFactory
|
||||
* @Date:2024/7/23 上午10:40
|
||||
* @Description: com.bw.feign
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class CarLogFeignFallbackFactory implements FallbackFactory<CarLogFeign> {
|
||||
@Override
|
||||
public CarLogFeign create(Throwable cause) {
|
||||
return new CarLogFeign() {
|
||||
@Override
|
||||
public Result<List<CarLogResp>> selCarLogAll() {
|
||||
return Result.error("网络异常,请求失败...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> insCarLog(CarLog carLog) {
|
||||
return Result.error("网络异常,请求失败...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> updCarLog(CarLog carLog) {
|
||||
return Result.error("网络异常,请求失败...");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.bw.factory;
|
||||
|
||||
import com.bw.common.domain.pojo.User;
|
||||
import com.bw.common.domain.request.UserReq;
|
||||
import com.bw.common.domain.response.JwtResponse;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.feign.UserFeign;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:UserFeignFallbackFactory
|
||||
* @Date:2024/7/23 上午9:58
|
||||
* @Description: com.bw.factory
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class UserFeignFallbackFactory implements FallbackFactory<UserFeign> {
|
||||
@Override
|
||||
public UserFeign create(Throwable cause) {
|
||||
return new UserFeign() {
|
||||
@Override
|
||||
public Result<JwtResponse> login(UserReq userReq) {
|
||||
return Result.error("网络异常,请求失败...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> updUserPrice(Long uid, Double price) {
|
||||
return Result.error("网络异常,请求失败...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<User> getUserByUid(Long uid) {
|
||||
return Result.error("网络异常,请求失败...");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.bw.feign;
|
||||
|
||||
import com.bw.common.domain.request.CarReq;
|
||||
import com.bw.common.domain.request.UserReq;
|
||||
import com.bw.common.domain.response.CarResp;
|
||||
import com.bw.common.domain.response.JwtResponse;
|
||||
import com.bw.common.result.PageResult;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.factory.CarFeignFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:UserFeign
|
||||
* @Date:2024/7/23 上午9:57
|
||||
* @Description: com.bw.feign
|
||||
*/
|
||||
|
||||
@FeignClient(name = "week1-car",value = "week1-car",fallbackFactory = CarFeignFallbackFactory.class)
|
||||
public interface CarFeign {
|
||||
/**
|
||||
* 车辆列表查询
|
||||
*/
|
||||
@PostMapping("/Car/selCarList")
|
||||
Result<PageResult<CarResp>> selCarList(@RequestBody CarReq carReq);
|
||||
|
||||
/**
|
||||
* 车辆状态修改
|
||||
*/
|
||||
@GetMapping("/Car/updCarSta")
|
||||
Result<Boolean> updCarSta(@RequestParam("cid") Long cid,@RequestParam("sta") Integer sta);
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.bw.feign;
|
||||
|
||||
import com.bw.common.domain.pojo.CarLog;
|
||||
import com.bw.common.domain.request.UserReq;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import com.bw.common.domain.response.JwtResponse;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.factory.CarFeignFallbackFactory;
|
||||
import com.bw.factory.CarLogFeignFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:UserFeign
|
||||
* @Date:2024/7/23 上午9:57
|
||||
* @Description: com.bw.feign
|
||||
*/
|
||||
|
||||
@FeignClient(name = "week1-carLog",value = "week1-carLog",fallbackFactory = CarLogFeignFallbackFactory.class)
|
||||
public interface CarLogFeign {
|
||||
|
||||
/**
|
||||
* 查询租车记录
|
||||
*/
|
||||
@GetMapping("/CarLog/selCarLogAll")
|
||||
Result<List<CarLogResp>> selCarLogAll();
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
*/
|
||||
@PostMapping("/CarLog/insCarLog")
|
||||
Result<Boolean> insCarLog(@RequestBody CarLog carLog);
|
||||
|
||||
/**
|
||||
* 归还车辆
|
||||
*/
|
||||
@PostMapping("/CarLog/updCarLog")
|
||||
Result<Boolean> updCarLog(@RequestBody CarLog carLog);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.bw.feign;
|
||||
|
||||
import com.bw.common.domain.pojo.User;
|
||||
import com.bw.common.domain.request.UserReq;
|
||||
import com.bw.common.domain.response.JwtResponse;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.factory.UserFeignFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:UserFeign
|
||||
* @Date:2024/7/23 上午9:57
|
||||
* @Description: com.bw.feign
|
||||
*/
|
||||
|
||||
@FeignClient(name = "week1-user",value = "week1-user",fallbackFactory = UserFeignFallbackFactory.class)
|
||||
public interface UserFeign {
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
@PostMapping("/User/login")
|
||||
Result<JwtResponse> login(@RequestBody UserReq userReq);
|
||||
|
||||
/**
|
||||
* 修改用户余额
|
||||
*/
|
||||
@GetMapping("/User/updUserPrice")
|
||||
Result<Boolean> updUserPrice(@RequestParam("uid") Long uid, @RequestParam("price") Double price);
|
||||
|
||||
/**
|
||||
* id精确查询
|
||||
*/
|
||||
@GetMapping("/User/getUserByUid")
|
||||
Result<User> getUserByUid(@RequestParam Long uid);
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.bw.service;
|
||||
|
||||
import com.bw.common.domain.pojo.CarLog;
|
||||
import com.bw.common.domain.pojo.User;
|
||||
import com.bw.common.domain.request.CarReq;
|
||||
import com.bw.common.domain.request.UserReq;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import com.bw.common.domain.response.CarResp;
|
||||
import com.bw.common.domain.response.JwtResponse;
|
||||
import com.bw.common.result.PageResult;
|
||||
import com.bw.common.result.Result;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Auth
|
||||
* @Date:2024/7/23 上午10:01
|
||||
* @Description: com.bw.service.impl
|
||||
*/
|
||||
|
||||
public interface AuthService {
|
||||
Result<JwtResponse> login(UserReq userReq);
|
||||
|
||||
Result<Boolean> updUserPrice(Long uid, Double price);
|
||||
|
||||
Result<PageResult<CarResp>> selCarList(CarReq carReq);
|
||||
|
||||
Result<Boolean> updCarSta(Long cid, Integer sta);
|
||||
|
||||
Result<List<CarLogResp>> selCarLogAll();
|
||||
|
||||
Result<Boolean> insCarLog(CarLog carLog);
|
||||
|
||||
Result<Boolean> updCarLog(CarLog carLog, String token);
|
||||
|
||||
Result<Map<String, Object>> info(String token);
|
||||
|
||||
Result<Boolean> logout(String token);
|
||||
|
||||
Result<User> getUserByUid(Long uid);
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
package com.bw.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bw.common.domain.pojo.CarLog;
|
||||
import com.bw.common.domain.pojo.User;
|
||||
import com.bw.common.domain.request.CarReq;
|
||||
import com.bw.common.domain.request.UserReq;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import com.bw.common.domain.response.CarResp;
|
||||
import com.bw.common.domain.response.JwtResponse;
|
||||
import com.bw.common.result.PageResult;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.common.utils.JwtConstants;
|
||||
import com.bw.common.utils.JwtUtils;
|
||||
import com.bw.feign.CarFeign;
|
||||
import com.bw.feign.CarLogFeign;
|
||||
import com.bw.feign.UserFeign;
|
||||
import com.bw.service.AuthService;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Auth
|
||||
* @Date:2024/7/23 上午10:01
|
||||
* @Description: com.bw.service.impl
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class AuthServiceImpl implements AuthService {
|
||||
@Autowired
|
||||
private UserFeign userFeign;
|
||||
@Autowired
|
||||
private CarFeign carFeign;
|
||||
@Autowired
|
||||
private CarLogFeign carLogFeign;
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Override
|
||||
public Result<JwtResponse> login(UserReq userReq) {
|
||||
return userFeign.login(userReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> updUserPrice(Long uid, Double price) {
|
||||
return userFeign.updUserPrice(uid, price);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<PageResult<CarResp>> selCarList(CarReq carReq) {
|
||||
return carFeign.selCarList(carReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> updCarSta(Long cid, Integer sta) {
|
||||
return carFeign.updCarSta(cid, sta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<List<CarLogResp>> selCarLogAll() {
|
||||
return carLogFeign.selCarLogAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增租车记录
|
||||
* 1.修改车辆表状态
|
||||
* 2.增加记录表信息
|
||||
* @param carLog
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public Result<Boolean> insCarLog(CarLog carLog) {
|
||||
// 更改车辆状态为已租出
|
||||
carFeign.updCarSta(carLog.getCid(), 2);
|
||||
// 新增记录表信息
|
||||
return carLogFeign.insCarLog(carLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 归还车辆
|
||||
* 1.扣除用户对应金额
|
||||
* 2.更新redis缓存的用户信息
|
||||
* 3.更改车辆表状态
|
||||
* 4.更新记录表信息
|
||||
* 5.发送短信
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public Result<Boolean> updCarLog(CarLog carLog, String token) {
|
||||
// 扣除用户余额
|
||||
userFeign.updUserPrice(carLog.getUid(), carLog.getLprice());
|
||||
|
||||
// 更新redis缓存登录的用户信息
|
||||
// 获取token令牌的UserKey
|
||||
String userKey = JwtUtils.getUserKey(token);
|
||||
// 精确查询用户信息
|
||||
User data = userFeign.getUserByUid(carLog.getUid()).getData();
|
||||
// 更新缓存
|
||||
redisTemplate.opsForValue().set(JwtConstants.LOGIN_TOKEN + userKey, JSONObject.toJSONString(data),30, TimeUnit.MINUTES);
|
||||
// 更改车辆表状态
|
||||
carFeign.updCarSta(carLog.getCid(), 1);
|
||||
// 更新记录表信息
|
||||
Result<Boolean> booleanResult = carLogFeign.updCarLog(carLog);
|
||||
// 发送短信 MQ
|
||||
rabbitTemplate.convertAndSend("week1-user-sendMessage",carLog.getLid(),message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
});
|
||||
return booleanResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Map<String, Object>> info(String token) {
|
||||
// 获取token令牌的UserKey
|
||||
String userKey = JwtUtils.getUserKey(token);
|
||||
// 获取redis用户信息
|
||||
String userString = redisTemplate.opsForValue().get(JwtConstants.LOGIN_TOKEN + userKey);
|
||||
// 反序列化
|
||||
User user = JSONObject.parseObject(userString, User.class);
|
||||
if (user==null){
|
||||
return Result.error();
|
||||
}
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("id",user.getUid());
|
||||
map.put("name",user.getUname());
|
||||
map.put("price",user.getUprice());
|
||||
return Result.success(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> logout(String token) {
|
||||
// 获取token令牌的UserKey
|
||||
String userKey = JwtUtils.getUserKey(token);
|
||||
// 清除redis缓存
|
||||
redisTemplate.delete(JwtConstants.LOGIN_TOKEN + userKey);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<User> getUserByUid(Long uid) {
|
||||
return userFeign.getUserByUid(uid);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9000
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: week1-auth
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 47.116.173.119:8848
|
||||
namespace: 0b55c4a7-3474-4454-9452-5210cc4320e0
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 47.116.173.119:8848
|
||||
namespace: 0b55c4a7-3474-4454-9452-5210cc4320e0
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#}
|
||||
#}
|
|
@ -0,0 +1,119 @@
|
|||
<?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>com.bw</groupId>
|
||||
<artifactId>week1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bw-common</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- bootstrap 启动器 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
<!-- 负载均衡-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Openfeign -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<!-- JWT -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>0.9.1</version>
|
||||
</dependency>
|
||||
<!-- Alibaba Fastjson -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.80</version>
|
||||
</dependency>
|
||||
<!-- SpringBoot Boot Redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<!-- Hibernate Validator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<!-- Apache Lang3 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<!-- lombok依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<!-- hutool -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.3</version>
|
||||
</dependency>
|
||||
<!-- 阿里大鱼 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>dysmsapi20170525</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
<!-- oss 图片上传 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <!–mq 依赖–>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<!--fastDfs文件上传-->
|
||||
<dependency>
|
||||
<groupId>com.github.tobato</groupId>
|
||||
<artifactId>fastdfs-client</artifactId>
|
||||
<version>1.26.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,40 @@
|
|||
package com.bw.common.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(factory);
|
||||
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new
|
||||
Jackson2JsonRedisSerializer(Object.class);
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
jackson2JsonRedisSerializer.setObjectMapper(om);
|
||||
|
||||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||
// key采用String的序列化方式
|
||||
template.setKeySerializer(stringRedisSerializer);
|
||||
// hash的key也采用String的序列化方式
|
||||
template.setHashKeySerializer(stringRedisSerializer);
|
||||
// value序列化方式采用jackson
|
||||
template.setValueSerializer(jackson2JsonRedisSerializer);
|
||||
// hash的value序列化方式采用jackson
|
||||
template.setHashValueSerializer(jackson2JsonRedisSerializer);
|
||||
template.afterPropertiesSet();
|
||||
|
||||
return template;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.bw.common.constants;
|
||||
|
||||
/**
|
||||
* @description: 系统常量
|
||||
* @author DongZl
|
||||
*/
|
||||
public class Constants {
|
||||
/**
|
||||
* 成功标记
|
||||
*/
|
||||
public static final Integer SUCCESS = 200;
|
||||
public static final String SUCCESS_MSG = "操作成功";
|
||||
/**
|
||||
* 失败标记
|
||||
*/
|
||||
public static final Integer ERROR = 500;
|
||||
public static final String ERROR_MSG = "操作异常";
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.bw.common.constants;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: Jwt常量
|
||||
*/
|
||||
public class JwtConstants {
|
||||
|
||||
/**
|
||||
* 用户ID字段
|
||||
*/
|
||||
public static final String DETAILS_USER_ID = "user_id";
|
||||
|
||||
/**
|
||||
* 用户名字段
|
||||
*/
|
||||
public static final String DETAILS_USERNAME = "username";
|
||||
|
||||
/**
|
||||
* 用户标识
|
||||
*/
|
||||
public static final String USER_KEY = "user_key";
|
||||
|
||||
/**
|
||||
* 令牌秘钥
|
||||
*/
|
||||
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.bw.common.constants;
|
||||
|
||||
public class RabbitMQConstants {
|
||||
public static final String SEND_SMS_QUEUE = "send_sms_queue";
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.bw.common.constants;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 令牌常量
|
||||
*/
|
||||
public class TokenConstants {
|
||||
/**
|
||||
* 缓存有效期,默认720(分钟)
|
||||
*/
|
||||
public final static long EXPIRATION = 720;
|
||||
/**
|
||||
* 缓存刷新时间,默认120(分钟)
|
||||
*/
|
||||
public final static long REFRESH_TIME = 120;
|
||||
/**
|
||||
* 权限缓存前缀
|
||||
*/
|
||||
public final static String LOGIN_TOKEN_KEY = "login_tokens:";
|
||||
/**
|
||||
* token标识
|
||||
*/
|
||||
public static final String TOKEN = "token";
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.bw.common.domain.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Car
|
||||
* @Date:2024/7/23 上午9:24
|
||||
* @Description: com.bw.common.domain.pojo
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Car {
|
||||
|
||||
/** 车辆ID*/
|
||||
private Long cid;
|
||||
|
||||
/** 车辆编号*/
|
||||
private String cnumid;
|
||||
|
||||
/** 车辆类型*/
|
||||
private Long tid;
|
||||
|
||||
/** 车辆状态 1.未出租 2.已出租*/
|
||||
private Integer csta;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.bw.common.domain.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:CarLog
|
||||
* @Date:2024/7/23 上午9:26
|
||||
* @Description: com.bw.common.domain.pojo
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CarLog {
|
||||
|
||||
/** 记录ID*/
|
||||
private Long lid;
|
||||
|
||||
/** 记录车辆*/
|
||||
private Long cid;
|
||||
|
||||
/** 记录用户*/
|
||||
private Long uid;
|
||||
|
||||
/** 租车开始时间*/
|
||||
private String lstadate;
|
||||
|
||||
/** 用车时间*/
|
||||
private Integer ltime;
|
||||
|
||||
/** 行驶距离*/
|
||||
private Double ldist;
|
||||
|
||||
/** 费用*/
|
||||
private Double lprice;
|
||||
|
||||
/** 状态 1.骑行中 2.已结束*/
|
||||
private Integer lsta;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.bw.common.domain.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:CarType
|
||||
* @Date:2024/7/23 上午9:23
|
||||
* @Description: com.bw.common.domain.pojo
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CarType {
|
||||
|
||||
/** 车辆类型*/
|
||||
private Long tid;
|
||||
|
||||
/** 车辆类型名称*/
|
||||
private String tname;
|
||||
|
||||
/** 车辆出租价格*/
|
||||
private Double tprice;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.bw.common.domain.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:User
|
||||
* @Date:2024/7/23 上午9:22
|
||||
* @Description: com.bw.common.domain.pojo
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class User {
|
||||
|
||||
/** 用户ID*/
|
||||
private Long uid;
|
||||
|
||||
/** 用户名*/
|
||||
private String uname;
|
||||
|
||||
/** 用户密码*/
|
||||
private String upwd;
|
||||
|
||||
/** 用户余额*/
|
||||
private Double uprice;
|
||||
|
||||
/** 用户手机号*/
|
||||
private String utel;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.bw.common.domain.request;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Car
|
||||
* @Date:2024/7/23 上午9:24
|
||||
* @Description: com.bw.common.domain.pojo
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CarReq {
|
||||
/** 车辆类型*/
|
||||
private Long tid;
|
||||
|
||||
/** 车辆状态 1.未出租 2.已出租*/
|
||||
private Integer csta;
|
||||
|
||||
private Integer pageNum = 1;
|
||||
|
||||
private Integer pageSize = 5;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.bw.common.domain.request;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:User
|
||||
* @Date:2024/7/23 上午9:22
|
||||
* @Description: com.bw.common.domain.pojo
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserReq {
|
||||
|
||||
/** 用户名*/
|
||||
private String uname;
|
||||
|
||||
/** 用户密码*/
|
||||
private String upwd;
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.bw.common.domain.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:CarLog
|
||||
* @Date:2024/7/23 上午9:26
|
||||
* @Description: com.bw.common.domain.pojo
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CarLogResp {
|
||||
|
||||
/** 记录ID*/
|
||||
private Long lid;
|
||||
|
||||
/** 记录车辆*/
|
||||
private Long cid;
|
||||
|
||||
/** 记录用户*/
|
||||
private Long uid;
|
||||
|
||||
/** 租车开始时间*/
|
||||
private String lstadate;
|
||||
|
||||
/** 用车时间*/
|
||||
private Integer ltime;
|
||||
|
||||
/** 行驶距离*/
|
||||
private Double ldist;
|
||||
|
||||
/** 费用*/
|
||||
private Double lprice;
|
||||
|
||||
/** 状态 1.骑行中 2.已结束*/
|
||||
private Integer lsta;
|
||||
|
||||
/** 车辆编号*/
|
||||
private String cnumid;
|
||||
|
||||
/** 车辆类型*/
|
||||
private Long tid;
|
||||
|
||||
/** 车辆状态 1.未出租 2.已出租*/
|
||||
private Integer csta;
|
||||
|
||||
/** 车辆类型名称*/
|
||||
private String tname;
|
||||
|
||||
/** 车辆出租价格*/
|
||||
private Double tprice;
|
||||
|
||||
/** 用户名*/
|
||||
private String uname;
|
||||
|
||||
/** 用户手机号*/
|
||||
private String utel;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.bw.common.domain.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Car
|
||||
* @Date:2024/7/23 上午9:24
|
||||
* @Description: com.bw.common.domain.pojo
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CarResp {
|
||||
|
||||
/** 车辆ID*/
|
||||
private Long cid;
|
||||
|
||||
/** 车辆编号*/
|
||||
private String cnumid;
|
||||
|
||||
/** 车辆类型*/
|
||||
private Long tid;
|
||||
|
||||
/** 车辆状态 1.未出租 2.已出租*/
|
||||
private Integer csta;
|
||||
|
||||
/** 车辆类型名称*/
|
||||
private String tname;
|
||||
|
||||
/** 车辆出租价格*/
|
||||
private Double tprice;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.bw.common.domain.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class JwtResponse {
|
||||
private String token;
|
||||
private String existTime;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.bw.common.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 列表返回结果集
|
||||
*/
|
||||
@Data
|
||||
public class PageResult<T> implements Serializable {
|
||||
/**
|
||||
* 总条数
|
||||
*/
|
||||
private long total;
|
||||
/**
|
||||
* 结果集合
|
||||
*/
|
||||
private List<T> list;
|
||||
public PageResult() {
|
||||
}
|
||||
public PageResult(long total, List<T> list) {
|
||||
this.total = total;
|
||||
this.list = list;
|
||||
}
|
||||
public static <T> PageResult<T> toPageResult(long total, List<T> list){
|
||||
return new PageResult(total , list);
|
||||
}
|
||||
public static <T> Result<PageResult<T>> toResult(long total, List<T> list){
|
||||
return Result.success(PageResult.toPageResult(total,list));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.bw.common.result;
|
||||
|
||||
import com.bw.common.constants.Constants;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 响应信息主体
|
||||
*/
|
||||
@Data
|
||||
public class Result<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
public static final int SUCCESS = Constants.SUCCESS;
|
||||
/**
|
||||
* 失败
|
||||
*/
|
||||
public static final int FAIL = Constants.ERROR;
|
||||
/**
|
||||
* 返回状态码
|
||||
*/
|
||||
private int code;
|
||||
/**
|
||||
* 响应信息
|
||||
*/
|
||||
private String msg;
|
||||
/**
|
||||
* 响应数据
|
||||
*/
|
||||
private T data;
|
||||
|
||||
public static <T> Result<T> success() {
|
||||
return restResult(null, SUCCESS, Constants.SUCCESS_MSG);
|
||||
}
|
||||
|
||||
public static <T> Result<T> success(T data) {
|
||||
return restResult(data, SUCCESS, Constants.SUCCESS_MSG);
|
||||
}
|
||||
|
||||
public static <T> Result<T> success(T data, String msg) {
|
||||
return restResult(data, SUCCESS, msg);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error() {
|
||||
return restResult(null, FAIL, Constants.ERROR_MSG);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(String msg) {
|
||||
return restResult(null, FAIL, msg);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(T data) {
|
||||
return restResult(data, FAIL, Constants.ERROR_MSG);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(T data, String msg) {
|
||||
return restResult(data, FAIL, msg);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(int code, String msg) {
|
||||
return restResult(null, code, msg);
|
||||
}
|
||||
|
||||
private static <T> Result<T> restResult(T data, int code, String msg) {
|
||||
Result<T> apiResult = new Result<>();
|
||||
apiResult.setCode(code);
|
||||
apiResult.setData(data);
|
||||
apiResult.setMsg(msg);
|
||||
return apiResult;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.bw.common.utils;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
|
||||
import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
||||
@Component
|
||||
public class FastUtil {
|
||||
private static final Logger log = LoggerFactory.getLogger(FastUtil.class);
|
||||
|
||||
@Resource
|
||||
private FastFileStorageClient storageClient ;
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*/
|
||||
public String upload(MultipartFile multipartFile) throws Exception{
|
||||
String originalFilename = multipartFile.getOriginalFilename().
|
||||
substring(multipartFile.getOriginalFilename().
|
||||
lastIndexOf(".") + 1);
|
||||
StorePath storePath = this.storageClient.uploadImageAndCrtThumbImage(
|
||||
multipartFile.getInputStream(),
|
||||
multipartFile.getSize(),originalFilename , null);
|
||||
return storePath.getFullPath();
|
||||
}
|
||||
/**
|
||||
* 删除文件
|
||||
*/
|
||||
public String deleteFile(String fileUrl) {
|
||||
if (StringUtils.isEmpty(fileUrl)) {
|
||||
log.info("fileUrl == >>文件路径为空...");
|
||||
return "文件路径不能为空";
|
||||
}
|
||||
try {
|
||||
StorePath storePath = StorePath.parseFromUrl(fileUrl);
|
||||
storageClient.deleteFile(storePath.getGroup(), storePath.getPath());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return "删除成功";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.bw.common.utils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @description: 生成验证码工具类
|
||||
* @Date 2023-5-11 上午 10:09
|
||||
*/
|
||||
public class GenCodeUtils {
|
||||
|
||||
/**
|
||||
* 数字类型
|
||||
*/
|
||||
private static final String NUMBER_STR = "0123456789";
|
||||
/**
|
||||
* 字母类型
|
||||
*/
|
||||
private static final String LETTERS_STR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
/**
|
||||
* 短信验证码长度
|
||||
*/
|
||||
private static final Integer SMS_CODE_LENGTH = 4;
|
||||
|
||||
/**
|
||||
* 生成短信四位验证码
|
||||
* @return 验证码
|
||||
*/
|
||||
public static String genLetterStrSms(){
|
||||
return genCode(LETTERS_STR, SMS_CODE_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成短信四位验证码
|
||||
* @return 验证码
|
||||
*/
|
||||
public static String genNumberCodeSms(){
|
||||
return genCode(NUMBER_STR, SMS_CODE_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
* @param codeLength 验证码长度
|
||||
* @return 验证码
|
||||
*/
|
||||
public static String genLetterStr(int codeLength){
|
||||
return genCode(LETTERS_STR, codeLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
* @param codeLength 验证码长度
|
||||
* @return 验证码
|
||||
*/
|
||||
public static String genNumberCode( int codeLength){
|
||||
return genCode(NUMBER_STR, codeLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
* @param str 验证码字符串
|
||||
* @param codeLength 验证码长度
|
||||
* @return 验证码
|
||||
*/
|
||||
public static String genCode (String str, int codeLength){
|
||||
//将字符串转换为一个新的字符数组。
|
||||
char[] verificationCodeArray = str.toCharArray();
|
||||
Random random = new Random();
|
||||
//计数器
|
||||
int count = 0;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
do {
|
||||
//随机生成一个随机数
|
||||
int index = random.nextInt(verificationCodeArray.length);
|
||||
char c = verificationCodeArray[index];
|
||||
//限制四位不重复数字
|
||||
if (stringBuilder.indexOf(String.valueOf(c)) == -1) {
|
||||
stringBuilder.append(c);
|
||||
//计数器加1
|
||||
count++;
|
||||
}
|
||||
//当count等于4时结束,随机生成四位数的验证码
|
||||
} while (count != codeLength);
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,310 @@
|
|||
package com.bw.common.utils;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HttpUtils {
|
||||
|
||||
/**
|
||||
* get
|
||||
*
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doGet(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpGet request = new HttpGet(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* post form
|
||||
*
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @param bodys
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doPost(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
Map<String, String> bodys)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (bodys != null) {
|
||||
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
|
||||
|
||||
for (String key : bodys.keySet()) {
|
||||
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
|
||||
}
|
||||
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
|
||||
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||
request.setEntity(formEntity);
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post String
|
||||
*
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @param body
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doPost(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
String body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
request.setEntity(new StringEntity(body, "utf-8"));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post stream
|
||||
*
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @param body
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doPost(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
byte[] body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (body != null) {
|
||||
request.setEntity(new ByteArrayEntity(body));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put String
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @param body
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doPut(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
String body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
request.setEntity(new StringEntity(body, "utf-8"));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put stream
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @param body
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doPut(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
byte[] body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (body != null) {
|
||||
request.setEntity(new ByteArrayEntity(body));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doDelete(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
|
||||
StringBuilder sbUrl = new StringBuilder();
|
||||
sbUrl.append(host);
|
||||
if (!StringUtils.isBlank(path)) {
|
||||
sbUrl.append(path);
|
||||
}
|
||||
if (null != querys) {
|
||||
StringBuilder sbQuery = new StringBuilder();
|
||||
for (Map.Entry<String, String> query : querys.entrySet()) {
|
||||
if (0 < sbQuery.length()) {
|
||||
sbQuery.append("&");
|
||||
}
|
||||
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
|
||||
sbQuery.append(query.getValue());
|
||||
}
|
||||
if (!StringUtils.isBlank(query.getKey())) {
|
||||
sbQuery.append(query.getKey());
|
||||
if (!StringUtils.isBlank(query.getValue())) {
|
||||
sbQuery.append("=");
|
||||
sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (0 < sbQuery.length()) {
|
||||
sbUrl.append("?").append(sbQuery);
|
||||
}
|
||||
}
|
||||
|
||||
return sbUrl.toString();
|
||||
}
|
||||
|
||||
private static HttpClient wrapClient(String host) {
|
||||
HttpClient httpClient = new DefaultHttpClient();
|
||||
if (host.startsWith("https://")) {
|
||||
sslClient(httpClient);
|
||||
}
|
||||
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
private static void sslClient(HttpClient httpClient) {
|
||||
try {
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
X509TrustManager tm = new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
public void checkClientTrusted(X509Certificate[] xcs, String str) {
|
||||
|
||||
}
|
||||
public void checkServerTrusted(X509Certificate[] xcs, String str) {
|
||||
|
||||
}
|
||||
};
|
||||
ctx.init(null, new TrustManager[] { tm }, null);
|
||||
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
|
||||
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
ClientConnectionManager ccm = httpClient.getConnectionManager();
|
||||
SchemeRegistry registry = ccm.getSchemeRegistry();
|
||||
registry.register(new Scheme("https", 443, ssf));
|
||||
} catch (KeyManagementException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.bw.common.utils;
|
||||
|
||||
public class JwtConstants {
|
||||
/**
|
||||
* 用户ID字段
|
||||
*/
|
||||
public static final String DETAILS_USER_ID = "user_id";
|
||||
|
||||
/**
|
||||
* 用户名字段
|
||||
*/
|
||||
public static final String DETAILS_USERNAME = "user_name";
|
||||
|
||||
/**
|
||||
* 用户标识
|
||||
*/
|
||||
public static final String USER_KEY = "user_key";
|
||||
|
||||
/**
|
||||
* 令牌秘钥
|
||||
*/
|
||||
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
/**
|
||||
* 手机
|
||||
*/
|
||||
public static final String USER_PHONE = "user_phone";
|
||||
|
||||
|
||||
/**
|
||||
* 用户token 的键的前缀
|
||||
*/
|
||||
public static final String LOGIN_TOKEN = "login_token:";
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
package com.bw.common.utils;
|
||||
|
||||
import com.bw.common.constants.JwtConstants;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description: Jwt工具类
|
||||
*/
|
||||
public class JwtUtils {
|
||||
|
||||
/**
|
||||
* 秘钥
|
||||
*/
|
||||
public static String secret = JwtConstants.SECRET;
|
||||
|
||||
/**
|
||||
* 从数据声明生成令牌
|
||||
*
|
||||
* @param claims 数据声明
|
||||
* @return 令牌
|
||||
*/
|
||||
public static String createToken(Map<String, Object> claims) {
|
||||
String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact();
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从令牌中获取数据声明
|
||||
*
|
||||
* @param token 令牌
|
||||
* @return 数据声明
|
||||
*/
|
||||
public static Claims parseToken(String token) {
|
||||
return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据令牌获取用户标识
|
||||
*
|
||||
* @param token 令牌
|
||||
* @return 用户ID
|
||||
*/
|
||||
public static String getUserKey(String token) {
|
||||
Claims claims = parseToken(token);
|
||||
return getValue(claims, JwtConstants.USER_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据令牌获取用户标识
|
||||
*
|
||||
* @param claims 身份信息
|
||||
* @return 用户ID
|
||||
*/
|
||||
public static String getUserKey(Claims claims) {
|
||||
return getValue(claims, JwtConstants.USER_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据令牌获取用户ID
|
||||
*
|
||||
* @param token 令牌
|
||||
* @return 用户ID
|
||||
*/
|
||||
public static String getUserId(String token) {
|
||||
Claims claims = parseToken(token);
|
||||
return getValue(claims, JwtConstants.DETAILS_USER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据身份信息获取用户ID
|
||||
*
|
||||
* @param claims 身份信息
|
||||
* @return 用户ID
|
||||
*/
|
||||
public static String getUserId(Claims claims) {
|
||||
return getValue(claims, JwtConstants.DETAILS_USER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据令牌获取用户名
|
||||
*
|
||||
* @param token 令牌
|
||||
* @return 用户名
|
||||
*/
|
||||
public static String getUserName(String token) {
|
||||
Claims claims = parseToken(token);
|
||||
return getValue(claims, JwtConstants.DETAILS_USERNAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据身份信息获取用户名
|
||||
*
|
||||
* @param claims 身份信息
|
||||
* @return 用户名
|
||||
*/
|
||||
public static String getUserName(Claims claims) {
|
||||
return getValue(claims, JwtConstants.DETAILS_USERNAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据身份信息获取键值
|
||||
*
|
||||
* @param claims 身份信息
|
||||
* @param key 键
|
||||
* @return 值
|
||||
*/
|
||||
public static String getValue(Claims claims, String key) {
|
||||
Object obj = claims.get(key);
|
||||
return obj == null ? "" : obj.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.bw.common.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
/**
|
||||
* MD5工具类
|
||||
* @author 高州
|
||||
*/
|
||||
public class Md5Utils {
|
||||
/**
|
||||
* 生成32位md5
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String string2Md5(String str) {
|
||||
try {
|
||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||
char[] charArray = str.toCharArray();
|
||||
byte[] byteArray = new byte[charArray.length];
|
||||
for (int i = 0; i < charArray.length; i++) {
|
||||
byteArray[i] = (byte) charArray[i];
|
||||
}
|
||||
byte[] md5Bytes = md5.digest(byteArray);
|
||||
StringBuffer hexValue = new StringBuffer();
|
||||
for (int i = 0; i < md5Bytes.length; i++) {
|
||||
int val = ((int) md5Bytes[i]) & 0xff;
|
||||
if (val < 16) {
|
||||
hexValue.append("0");
|
||||
}
|
||||
hexValue.append(Integer.toHexString(val));
|
||||
}
|
||||
return hexValue.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String md5 = string2Md5("111");
|
||||
System.out.println(md5);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成16位md5
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String string2Md5_16(String str) {
|
||||
String md5 = string2Md5(str);
|
||||
return md5.substring(8, 24);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.bw.common.utils;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author
|
||||
* @version 1.0.0
|
||||
* @ClassName MsgUtil.java
|
||||
* @Description TODO
|
||||
* @createTime 2022年05月26日 15:49:00
|
||||
*/
|
||||
public class MsgUtil {
|
||||
/**
|
||||
* 生成验证码
|
||||
* @param n 验证码位数
|
||||
* @return
|
||||
*/
|
||||
public static String getCode(Integer n){
|
||||
String code="";
|
||||
for (int i = 0; i < n; i++) {
|
||||
code+=(int)(Math.random()*10);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
public static JSONObject sendMsg(String phone,String code){
|
||||
String host = "https://cxkjsms.market.alicloudapi.com";
|
||||
String path = "/chuangxinsms/dxjk";
|
||||
String method = "POST";
|
||||
String appcode = "ad464d7044e340b2a49dadde7678d306";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||
headers.put("Authorization", "APPCODE " + appcode);
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
querys.put("content", "【创信】你的验证码是:"+code+",3分钟内有效!");
|
||||
querys.put("mobile", phone);
|
||||
Map<String, String> bodys = new HashMap<String, String>();
|
||||
|
||||
|
||||
try {
|
||||
/**
|
||||
* 重要提示如下:
|
||||
* HttpUtils请从
|
||||
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
|
||||
* 下载
|
||||
*
|
||||
* 相应的依赖请参照
|
||||
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
||||
*/
|
||||
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||
//{
|
||||
// "ReturnStatus": "Success",
|
||||
// "Message": "ok",
|
||||
// "RemainPoint": 420842,
|
||||
// "TaskID": 18424321,
|
||||
// "SuccessCounts": 1
|
||||
//}
|
||||
return JSON.parseObject(EntityUtils.toString(response.getEntity()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
package com.bw.common.utils;
|
||||
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.GetObjectRequest;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Oss服务调用
|
||||
*/
|
||||
@Log4j2
|
||||
public class OssUtil {
|
||||
|
||||
/**
|
||||
* Endpoint 存储对象概述 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 访问路径前缀 存储对象概述
|
||||
*/
|
||||
private static String endPoint = "oss-cn-shanghai.aliyuncs.com";
|
||||
private static String accessKeyId = "LTAI5tBdT6WQReZTwTLizHV7";
|
||||
private static String accessKeySecret = "4nHCxAg1sfBTmpDdS9t5RJxfua5RMK";
|
||||
private static String accessPre = "https://bawei-huyang.oss-cn-shanghai.aliyuncs.com/";
|
||||
|
||||
/**
|
||||
* bucket名称
|
||||
* @return
|
||||
*/
|
||||
private static String bucketName = "bawei-huyang";
|
||||
|
||||
private static OSS ossClient ;
|
||||
|
||||
static {
|
||||
ossClient = new OSSClientBuilder().build(
|
||||
endPoint,
|
||||
accessKeyId,
|
||||
accessKeySecret);
|
||||
log.info("oss服务连接成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认路径上传本地文件
|
||||
* @param filePath
|
||||
*/
|
||||
public static String uploadFile(String filePath){
|
||||
return uploadFileForBucket(bucketName,getOssFilePath(filePath) ,filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认路径上传multipartFile文件
|
||||
* @param multipartFile
|
||||
*/
|
||||
public static String uploadMultipartFile(MultipartFile multipartFile) {
|
||||
return uploadMultipartFile(bucketName,getOssFilePath(multipartFile.getOriginalFilename()),multipartFile);
|
||||
}
|
||||
/**
|
||||
* 上传 multipartFile 类型文件
|
||||
* @param bucketName
|
||||
* @param ossPath
|
||||
* @param multipartFile
|
||||
*/
|
||||
public static String uploadMultipartFile(String bucketName , String ossPath , MultipartFile multipartFile){
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = multipartFile.getInputStream();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||
return accessPre+ossPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用File上传PutObject上传文件 ** 程序默认使用次方法上传
|
||||
* @param bucketName 实例名称
|
||||
* @param ossPath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static String uploadFileForBucket(String bucketName , String ossPath , String filePath) {
|
||||
// 创建PutObjectRequest对象。
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath));
|
||||
|
||||
// 上传
|
||||
ossClient.putObject(putObjectRequest);
|
||||
return accessPre+ossPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用文件流上传到指定的bucket实例
|
||||
* @param bucketName 实例名称
|
||||
* @param ossPath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static String uploadFileInputStreamForBucket(String bucketName , String ossPath , String filePath){
|
||||
|
||||
// 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(filePath);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
|
||||
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||
return accessPre+ossPath;
|
||||
}
|
||||
|
||||
public static void uploadFileInputStreamForBucket(String bucketName , String ossPath , InputStream inputStream ){
|
||||
ossClient.putObject(bucketName, ossPath, inputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载
|
||||
* @param ossFilePath
|
||||
* @param filePath
|
||||
*/
|
||||
public static void downloadFile(String ossFilePath , String filePath ){
|
||||
downloadFileForBucket(bucketName , ossFilePath , filePath);
|
||||
}
|
||||
/**
|
||||
* 下载
|
||||
* @param bucketName 实例名称
|
||||
* @param ossFilePath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static void downloadFileForBucket(String bucketName , String ossFilePath , String filePath ){
|
||||
ossClient.getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getOssDefaultPath(){
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String url =
|
||||
now.getYear()+"/"+
|
||||
now.getMonth()+"/"+
|
||||
now.getDayOfMonth()+"/"+
|
||||
now.getHour()+"/"+
|
||||
now.getMinute()+"/";
|
||||
return url;
|
||||
}
|
||||
|
||||
public static String getOssFilePath(String filePath){
|
||||
String fileSuf = filePath.substring(filePath.indexOf(".") + 1);
|
||||
return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.bw.common.utils;
|
||||
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description: 字符串处理工具类
|
||||
*/
|
||||
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否为空
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isNull(Object object) {
|
||||
return object == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Collection是否为空, 包含List,Set,Queue
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Collection<?> coll) {
|
||||
return isNull(coll) || coll.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
|
||||
*
|
||||
* @param str 指定字符串
|
||||
* @param strs 需要检查的字符串数组
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public static boolean matches(String str, List<String> strs) {
|
||||
if (isEmpty(str) || isEmpty(strs)) {
|
||||
return false;
|
||||
}
|
||||
for (String pattern : strs) {
|
||||
if (isMatch(pattern, str))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断url是否与规则配置:
|
||||
* ? 表示单个字符;
|
||||
* * 表示一层路径内的任意字符串,不可跨层级;
|
||||
* ** 表示任意层路径;
|
||||
*
|
||||
* @param pattern 匹配规则
|
||||
* @param url 需要匹配的url
|
||||
* @return
|
||||
*/
|
||||
public static boolean isMatch(String pattern, String url) {
|
||||
AntPathMatcher matcher = new AntPathMatcher();
|
||||
return matcher.match(pattern, url);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.bw.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.dysmsapi20170525.Client;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 短信工具类
|
||||
*/
|
||||
@Log4j2
|
||||
public class TelSmsUtils {
|
||||
|
||||
/**
|
||||
* 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限
|
||||
*/
|
||||
private static String accessKeyId = "LTAI5tHU282xbcCSKZJSuKyH";
|
||||
|
||||
private static String accessKeySecret = "mX4tPoqoI55x3ACK1Z7IFiuAMVxuQr";
|
||||
|
||||
/**
|
||||
* 短信访问域名
|
||||
*/
|
||||
private static String endpoint = "dysmsapi.aliyuncs.com";
|
||||
/**
|
||||
* 短信签名
|
||||
*/
|
||||
private static String signName = "乐优购";
|
||||
|
||||
private static String templateCode = "SMS_163851467";
|
||||
|
||||
/**
|
||||
* 实例化短信对象
|
||||
*/
|
||||
private static Client client;
|
||||
|
||||
static {
|
||||
log.info("初始化短信服务开始");
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
client = initClient();
|
||||
log.info("初始化短信成功:{}", signName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log.info("初始化短信服务结束:耗时:{}MS", (System.currentTimeMillis() - startTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化短信对象
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static Client initClient() throws Exception {
|
||||
Config config = new Config()
|
||||
// 您的AccessKey ID
|
||||
.setAccessKeyId(accessKeyId)
|
||||
// 您的AccessKey Secret
|
||||
.setAccessKeySecret(accessKeySecret);
|
||||
// 访问的域名
|
||||
config.endpoint = endpoint;
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送单条短信 第三方接口调用
|
||||
*
|
||||
* @param tel
|
||||
* @param sendDataMap
|
||||
*/
|
||||
public static String sendSms(String tel, Map<String, String> sendDataMap) {
|
||||
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
||||
.setPhoneNumbers(tel)
|
||||
.setSignName(signName)
|
||||
.setTemplateCode(templateCode)
|
||||
.setTemplateParam(JSONObject.toJSONString(sendDataMap));
|
||||
SendSmsResponse sendSmsResponse = null;
|
||||
try {
|
||||
log.info("发送短信验证码:消息内容是:【{}】", JSONObject.toJSONString(sendDataMap));
|
||||
sendSmsResponse = client.sendSms(sendSmsRequest);
|
||||
} catch (Exception e) {
|
||||
log.error("短信发送异常,手机号:【{}】,短信内容:【{}】,异常信息:【{}】", tel, sendDataMap, e);
|
||||
}
|
||||
return JSONObject.toJSONString(sendSmsResponse.getBody());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?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>com.bw</groupId>
|
||||
<artifactId>week1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bw-gateway</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- 公共模块 -->
|
||||
<dependency>
|
||||
<groupId>com.bw</groupId>
|
||||
<artifactId>bw-common</artifactId>
|
||||
</dependency>
|
||||
<!-- 网关依赖 -->
|
||||
<!-- SpringCloud Gateway -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Sentinel Gateway -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
|
||||
</dependency>
|
||||
<!-- 引入阿里巴巴sentinel限流 依赖-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,19 @@
|
|||
package com.bw;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Gateway
|
||||
* @Date:2024/7/23 下午12:59
|
||||
* @Description: com.bw
|
||||
*/
|
||||
|
||||
@SpringBootApplication
|
||||
public class GatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GatewayApplication.class, args);
|
||||
System.out.println("Gateway 模块启动成功!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.bw.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description: 放行白名单配置
|
||||
* @author DongZl
|
||||
*/
|
||||
@Configuration
|
||||
@RefreshScope
|
||||
@ConfigurationProperties(prefix = "ignore")
|
||||
@Data
|
||||
@Log4j2
|
||||
public class IgnoreWhiteConfig {
|
||||
/**
|
||||
* 放行白名单配置,网关不校验此处的白名单
|
||||
*/
|
||||
private List<String> whites = new ArrayList<>();
|
||||
|
||||
public void setWhites(List<String> whites) {
|
||||
log.info("加载网关路径白名单:{}", JSONObject.toJSONString(whites));
|
||||
this.whites = whites;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.bw.filters;
|
||||
|
||||
import cn.hutool.jwt.JWTUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bw.common.domain.pojo.User;
|
||||
import com.bw.common.utils.JwtConstants;
|
||||
import com.bw.common.utils.JwtUtils;
|
||||
import com.bw.common.utils.StringUtils;
|
||||
import com.bw.config.IgnoreWhiteConfig;
|
||||
import com.bw.utils.GatewayUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AuthFilter implements GlobalFilter, Ordered {
|
||||
@Autowired
|
||||
private IgnoreWhiteConfig ignoreWhiteConfig;
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
String path = request.getURI().getPath();
|
||||
List<String> whites = ignoreWhiteConfig.getWhites();
|
||||
// 白名单校验
|
||||
if (StringUtils.matches(path,whites)){
|
||||
log.info("白名单校验通过,路径:{}",path);
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
// 获取token令牌
|
||||
String token = request.getHeaders().getFirst("token");
|
||||
// token非空校验
|
||||
if (StringUtils.isEmpty(token)){
|
||||
log.error("token不能为空,路径:{}",path);
|
||||
return GatewayUtils.errorResponse(exchange,"token不能为空");
|
||||
}
|
||||
// token令牌合法性校验
|
||||
try {
|
||||
JwtUtils.parseToken(token);
|
||||
} catch (Exception e) {
|
||||
log.error("token令牌不合法,路径:{}",path);
|
||||
return GatewayUtils.errorResponse(exchange,"token令牌不合法");
|
||||
}
|
||||
|
||||
// token用户登录校验
|
||||
String userKey = JwtUtils.getUserKey(token);
|
||||
String userString = redisTemplate.opsForValue().get(JwtConstants.LOGIN_TOKEN + userKey);
|
||||
User user = JSONObject.parseObject(userString, User.class);
|
||||
if (user==null){
|
||||
log.error("用户登录过期,路径:{}",path);
|
||||
return GatewayUtils.errorResponse(exchange,"用户未登录过期");
|
||||
}
|
||||
// token校验通过
|
||||
log.info("token校验通过,路径:{}",path);
|
||||
// token续期
|
||||
redisTemplate.expire(JwtConstants.LOGIN_TOKEN + userKey,30, TimeUnit.MINUTES);
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return -10;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package com.bw.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.common.utils.StringUtils;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 网关处理工具类
|
||||
*/
|
||||
@Log4j2
|
||||
public class GatewayUtils {
|
||||
/**
|
||||
* 添加请求头参数
|
||||
* @param mutate 修改对象
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
public static void addHeader(ServerHttpRequest.Builder mutate, String key, Object value) {
|
||||
if (StringUtils.isEmpty(key)){
|
||||
log.warn("添加请求头参数键不可以为空");
|
||||
return;
|
||||
}
|
||||
if (value == null) {
|
||||
log.warn("添加请求头参数:[{}]值为空",key);
|
||||
return;
|
||||
}
|
||||
String valueStr = value.toString();
|
||||
mutate.header(key, valueStr);
|
||||
log.info("添加请求头参数成功 - 键:[{}] , 值:[{}]", key , value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除请求头参数
|
||||
* @param mutate 修改对象
|
||||
* @param key 键
|
||||
*/
|
||||
public static void removeHeader(ServerHttpRequest.Builder mutate, String key) {
|
||||
if (StringUtils.isEmpty(key)){
|
||||
log.warn("删除请求头参数键不可以为空");
|
||||
return;
|
||||
}
|
||||
mutate.headers(httpHeaders -> httpHeaders.remove(key)).build();
|
||||
log.info("删除请求头参数 - 键:[{}]",key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误结果响应
|
||||
* @param exchange 响应上下文
|
||||
* @param msg 响应消息
|
||||
* @return
|
||||
*/
|
||||
public static Mono<Void> errorResponse(ServerWebExchange exchange, String msg, HttpStatus httpStatus) {
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
//设置HTTP响应头状态
|
||||
response.setStatusCode(httpStatus);
|
||||
//设置HTTP响应头文本格式
|
||||
response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
|
||||
//定义响应内容
|
||||
Result<?> result = Result.error(msg);
|
||||
String resultJson = JSONObject.toJSONString(result);
|
||||
log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson);
|
||||
DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes());
|
||||
//进行响应
|
||||
return response.writeWith(Mono.just(dataBuffer));
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误结果响应
|
||||
* @param exchange 响应上下文
|
||||
* @param msg 响应消息
|
||||
* @return
|
||||
*/
|
||||
public static Mono<Void> errorResponse(ServerWebExchange exchange, String msg) {
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
//设置HTTP响应头状态
|
||||
response.setStatusCode(HttpStatus.OK);
|
||||
//设置HTTP响应头文本格式
|
||||
response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
|
||||
//定义响应内容
|
||||
Result<?> result = Result.error(msg);
|
||||
String resultJson = JSONObject.toJSONString(result);
|
||||
log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson);
|
||||
DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes());
|
||||
//进行响应
|
||||
return response.writeWith(Mono.just(dataBuffer));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 18080
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: week1-gateway
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
main:
|
||||
# 允许使用循环引用
|
||||
allow-circular-references: true
|
||||
# 允许定义相同的bean对象 去覆盖原有的
|
||||
allow-bean-definition-overriding: true
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 47.116.173.119:8848
|
||||
namespace: 0b55c4a7-3474-4454-9452-5210cc4320e0
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 47.116.173.119:8848
|
||||
namespace: 0b55c4a7-3474-4454-9452-5210cc4320e0
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,20 @@
|
|||
<?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>com.bw</groupId>
|
||||
<artifactId>bw-moudles</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bw-car</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,19 @@
|
|||
package com.bw;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Car
|
||||
* @Date:2024/7/23 上午9:33
|
||||
* @Description: com.bw.controller
|
||||
*/
|
||||
|
||||
@SpringBootApplication
|
||||
public class CarApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CarApplication.class, args);
|
||||
System.out.println("Car 模块启动成功!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.bw.controller;
|
||||
|
||||
import com.bw.common.domain.pojo.Car;
|
||||
import com.bw.common.domain.request.CarReq;
|
||||
import com.bw.common.domain.response.CarResp;
|
||||
import com.bw.common.result.PageResult;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.service.CarService;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.http.HttpServletResponse;//图片
|
||||
|
||||
import cn.hutool.captcha.CircleCaptcha;//验证码
|
||||
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Car
|
||||
* @Date:2024/7/23 上午9:33
|
||||
* @Description: com.bw.controller
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/Car")
|
||||
public class CarController {
|
||||
@Autowired
|
||||
private CarService service;
|
||||
@Autowired
|
||||
private HttpSession session;
|
||||
|
||||
/**
|
||||
* 车辆列表查询
|
||||
*/
|
||||
@PostMapping("/selCarList")
|
||||
Result<PageResult<CarResp>> selCarList(@RequestBody CarReq carReq){
|
||||
return Result.success(service.selCarList(carReq));
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆状态修改
|
||||
*/
|
||||
@GetMapping("/updCarSta")
|
||||
Result<Boolean> updCarSta(@RequestParam("cid") Long cid,@RequestParam("sta") Integer sta){
|
||||
return service.updCarSta(cid,sta);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.bw.mapper;
|
||||
|
||||
import com.bw.common.domain.request.CarReq;
|
||||
import com.bw.common.domain.response.CarResp;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Car
|
||||
* @Date:2024/7/23 上午9:32
|
||||
* @Description: com.bw.mapper
|
||||
*/
|
||||
|
||||
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface CarMapper {
|
||||
List<CarResp> selCarList(CarReq carReq);
|
||||
|
||||
Integer updCarSta(@Param("cid") Long cid, @Param("sta") Integer sta);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.bw.service;
|
||||
|
||||
import com.bw.common.domain.request.CarReq;
|
||||
import com.bw.common.domain.response.CarResp;
|
||||
import com.bw.common.result.PageResult;
|
||||
import com.bw.common.result.Result;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Car
|
||||
* @Date:2024/7/23 上午9:33
|
||||
* @Description: com.bw.service.impl
|
||||
*/
|
||||
|
||||
public interface CarService {
|
||||
PageResult<CarResp> selCarList(CarReq carReq);
|
||||
|
||||
Result<Boolean> updCarSta(Long cid, Integer sta);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.bw.service.impl;
|
||||
|
||||
import com.bw.common.domain.request.CarReq;
|
||||
import com.bw.common.domain.response.CarResp;
|
||||
import com.bw.common.result.PageResult;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.mapper.CarMapper;
|
||||
import com.bw.service.CarService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:Car
|
||||
* @Date:2024/7/23 上午9:33
|
||||
* @Description: com.bw.service.impl
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class CarServiceImpl implements CarService {
|
||||
@Autowired
|
||||
private CarMapper mapper;
|
||||
|
||||
@Override
|
||||
public PageResult<CarResp> selCarList(CarReq carReq) {
|
||||
PageHelper.startPage(carReq.getPageNum(), carReq.getPageSize());
|
||||
PageInfo<CarResp> pageResult = new PageInfo<>(mapper.selCarList(carReq));
|
||||
return PageResult.toPageResult(pageResult.getTotal(), pageResult.getList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> updCarSta(Long cid, Integer sta) {
|
||||
return mapper.updCarSta(cid, sta) > 0?Result.success(true):Result.error(false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9002
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: week1-car
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 47.116.173.119:8848
|
||||
namespace: 0b55c4a7-3474-4454-9452-5210cc4320e0
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 47.116.173.119:8848
|
||||
namespace: 0b55c4a7-3474-4454-9452-5210cc4320e0
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bw.mapper.CarMapper">
|
||||
<update id="updCarSta">
|
||||
update week1_car
|
||||
set csta = #{sta}
|
||||
where cid = #{cid};
|
||||
</update>
|
||||
|
||||
<select id="selCarList" resultType="com.bw.common.domain.response.CarResp">
|
||||
select c.*,ct.tname,ct.tprice
|
||||
from week1_car c
|
||||
left join week1_car_type ct on c.tid=ct.tid
|
||||
<where>
|
||||
<if test="tid!=null and tid!=''">
|
||||
and ct.tid = #{tid}
|
||||
</if>
|
||||
<if test="csta!=null and csta!=''">
|
||||
and c.csta = #{csta}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,20 @@
|
|||
<?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>com.bw</groupId>
|
||||
<artifactId>bw-moudles</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bw-carLog</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,19 @@
|
|||
package com.bw;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:CarLog
|
||||
* @Date:2024/7/23 上午9:34
|
||||
* @Description: com.bw
|
||||
*/
|
||||
|
||||
@SpringBootApplication
|
||||
public class CarLogApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CarLogApplication.class, args);
|
||||
System.out.println("CarLog 模块启动成功!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.bw.controller;
|
||||
|
||||
import com.bw.common.domain.pojo.CarLog;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.service.CarLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:CarLog
|
||||
* @Date:2024/7/23 上午9:34
|
||||
* @Description: com.bw.service.impl
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/CarLog")
|
||||
public class CarLogController {
|
||||
@Autowired
|
||||
private CarLogService service;
|
||||
@Autowired
|
||||
private HttpSession session;
|
||||
|
||||
/**
|
||||
* 查询租车记录
|
||||
*/
|
||||
@GetMapping("/selCarLogAll")
|
||||
Result<List<CarLogResp>> selCarLogAll(){
|
||||
return service.selCarLogAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
*/
|
||||
@PostMapping("/insCarLog")
|
||||
Result<Boolean> insCarLog(@RequestBody CarLog carLog){
|
||||
return service.insCarLog(carLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 归还车辆
|
||||
*/
|
||||
@PostMapping("/updCarLog")
|
||||
Result<Boolean> updCarLog(@RequestBody CarLog carLog){
|
||||
return service.updCarLog(carLog);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.bw.mapper;
|
||||
|
||||
import com.bw.common.domain.pojo.CarLog;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:CarLog
|
||||
* @Date:2024/7/23 上午9:34
|
||||
* @Description: com.bw.mapper
|
||||
*/
|
||||
|
||||
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface CarLogMapper {
|
||||
List<CarLogResp> selCarLogAll();
|
||||
|
||||
Integer insCarLog(CarLog carLog);
|
||||
|
||||
Integer updCarLog(CarLog carLog);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.bw.service;
|
||||
|
||||
import com.bw.common.domain.pojo.CarLog;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import com.bw.common.result.Result;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:CarLog
|
||||
* @Date:2024/7/23 上午9:34
|
||||
* @Description: com.bw.service.impl
|
||||
*/
|
||||
|
||||
public interface CarLogService {
|
||||
Result<List<CarLogResp>> selCarLogAll();
|
||||
|
||||
Result<Boolean> insCarLog(CarLog carLog);
|
||||
|
||||
Result<Boolean> updCarLog(CarLog carLog);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.bw.service.impl;
|
||||
|
||||
import com.bw.common.domain.pojo.CarLog;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.mapper.CarLogMapper;
|
||||
import com.bw.service.CarLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:CarLog
|
||||
* @Date:2024/7/23 上午9:34
|
||||
* @Description: com.bw.service.impl
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class CarLogServiceImpl implements CarLogService {
|
||||
@Autowired
|
||||
private CarLogMapper mapper;
|
||||
|
||||
@Override
|
||||
public Result<List<CarLogResp>> selCarLogAll() {
|
||||
return Result.success(mapper.selCarLogAll());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> insCarLog(CarLog carLog) {
|
||||
return Result.success(mapper.insCarLog(carLog) > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> updCarLog(CarLog carLog) {
|
||||
return mapper.updCarLog(carLog) > 0 ? Result.success(true) : Result.error(false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9003
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: week1-carLog
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 47.116.173.119:8848
|
||||
namespace: 0b55c4a7-3474-4454-9452-5210cc4320e0
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 47.116.173.119:8848
|
||||
namespace: 0b55c4a7-3474-4454-9452-5210cc4320e0
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bw.mapper.CarLogMapper">
|
||||
<insert id="insCarLog">
|
||||
INSERT INTO `high-six-exam`.`week1_car_log`
|
||||
(`cid`, `uid`, `lstadate`, `ltime`, `ldist`, `lprice`, `lsta` )
|
||||
VALUES
|
||||
(#{cid}, #{uid},now(), 0, 0, 0, '1' );
|
||||
</insert>
|
||||
<update id="updCarLog">
|
||||
UPDATE `high-six-exam`.`week1_car_log`
|
||||
SET `ltime` = #{ltime},
|
||||
`ldist` = #{ldist},
|
||||
`lprice` = #{lprice},
|
||||
`lsta` = 2
|
||||
WHERE
|
||||
`lid` = #{lid};
|
||||
</update>
|
||||
|
||||
<select id="selCarLogAll" resultType="com.bw.common.domain.response.CarLogResp">
|
||||
select cl.*,c.cnumid,c.csta,u.uname,u.utel,ct.tname,ct.tid,ct.tprice
|
||||
from week1_car_log cl
|
||||
left join week1_car c on cl.cid=c.cid
|
||||
left join week1_car_type ct on c.tid=ct.tid
|
||||
left join week1_user u on cl.uid=u.uid
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,20 @@
|
|||
<?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>com.bw</groupId>
|
||||
<artifactId>bw-moudles</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bw-user</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,19 @@
|
|||
package com.bw;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:User
|
||||
* @Date:2024/7/23 上午9:29
|
||||
* @Description: com.bw
|
||||
*/
|
||||
|
||||
@SpringBootApplication
|
||||
public class UserApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(UserApplication.class, args);
|
||||
System.out.println("User 模块启动成功!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.bw.consumers;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bw.common.domain.pojo.CarLog;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import com.bw.common.utils.MsgUtil;
|
||||
import com.bw.service.UserService;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListeners;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:sendMessage
|
||||
* @Date:2024/7/23 上午10:04
|
||||
* @Description: com.bw.consumers
|
||||
*/
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class sendMessage {
|
||||
@Autowired
|
||||
private UserService service;
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
@RabbitListener(queuesToDeclare = @Queue("week1-user-sendMessage"))
|
||||
public void sendMessage(String lid, Message message, Channel channel){
|
||||
// 判断信息重复消费
|
||||
Long add = redisTemplate.opsForSet().add("week1-user-sendMessage", message.getMessageProperties().getMessageId());
|
||||
try {
|
||||
if (add!=null && add>0){
|
||||
// 非重复消费
|
||||
// 查询租车记录
|
||||
CarLogResp carLogResp = service.findCarLogByLid(lid);
|
||||
if (carLogResp==null){
|
||||
return;
|
||||
}
|
||||
// 向查询到的手机号发送短信
|
||||
JSONObject jsonObject = MsgUtil.sendMsg(carLogResp.getUtel(), "租车结束");
|
||||
log.info("短信发送成功");
|
||||
System.out.println("----->租车记录:"+carLogResp);
|
||||
}
|
||||
// 确认消费
|
||||
log.info("确认消费");
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
|
||||
} catch (IOException e) {
|
||||
// 出错时删除消费记录
|
||||
redisTemplate.opsForSet().remove("week1-user-sendMessage", message.getMessageProperties().getMessageId());
|
||||
try {
|
||||
// 消费回退
|
||||
log.info("消费回退");
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.bw.controller;
|
||||
|
||||
import com.bw.common.domain.pojo.User;
|
||||
import com.bw.common.domain.request.UserReq;
|
||||
import com.bw.common.domain.response.JwtResponse;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.service.UserService;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.http.HttpServletResponse;//图片
|
||||
|
||||
import cn.hutool.captcha.CircleCaptcha;//验证码
|
||||
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:User
|
||||
* @Date:2024/7/23 上午9:29
|
||||
* @Description: com.bw.controller
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/User")
|
||||
public class UserController {
|
||||
@Autowired
|
||||
private UserService service;
|
||||
@Autowired
|
||||
private HttpSession session;
|
||||
|
||||
|
||||
/**
|
||||
* 注册(测试)
|
||||
*/
|
||||
@PostMapping("/insUser")
|
||||
Result<Boolean> insUser(@RequestBody User user){
|
||||
Boolean b = service.insUser(user);
|
||||
return b?Result.success(b):Result.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
Result<JwtResponse> login(@RequestBody UserReq userReq) {
|
||||
return service.login(userReq);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户余额
|
||||
*/
|
||||
@GetMapping("/updUserPrice")
|
||||
Result<Boolean> updUserPrice(@RequestParam("uid") Long uid,@RequestParam("price") Double price){
|
||||
return service.updUserPrice(uid,price)?Result.success(true):Result.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* id精确查询
|
||||
*/
|
||||
@GetMapping("/getUserByUid")
|
||||
Result<User> getUserByUid(@RequestParam Long uid){
|
||||
return Result.success(service.getUserByUid(uid));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.bw.mapper;
|
||||
|
||||
import com.bw.common.domain.pojo.User;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:User
|
||||
* @Date:2024/7/23 上午9:29
|
||||
* @Description: com.bw.mapper
|
||||
*/
|
||||
|
||||
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
Integer insUser(User user);
|
||||
|
||||
User findUserByUname(@Param("uname") String uname);
|
||||
|
||||
Integer updUserPrice(@Param("uid") Long uid, @Param("price") Double price);
|
||||
|
||||
CarLogResp findCarLogByLid(@Param("lid") String lid);
|
||||
|
||||
User getUserByUid(@Param("uid") Long uid);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.bw.service;
|
||||
|
||||
import com.bw.common.domain.pojo.User;
|
||||
import com.bw.common.domain.request.UserReq;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import com.bw.common.domain.response.JwtResponse;
|
||||
import com.bw.common.result.Result;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:User
|
||||
* @Date:2024/7/23 上午9:29
|
||||
* @Description: com.bw.service.impl
|
||||
*/
|
||||
|
||||
public interface UserService {
|
||||
Boolean insUser(User user);
|
||||
|
||||
Result<JwtResponse> login(UserReq userReq);
|
||||
|
||||
Boolean updUserPrice(Long uid, Double price);
|
||||
|
||||
CarLogResp findCarLogByLid(String lid);
|
||||
|
||||
User getUserByUid(Long uid);
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.bw.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bw.common.domain.pojo.User;
|
||||
import com.bw.common.domain.request.UserReq;
|
||||
import com.bw.common.domain.response.CarLogResp;
|
||||
import com.bw.common.domain.response.JwtResponse;
|
||||
import com.bw.common.result.Result;
|
||||
import com.bw.common.utils.JwtConstants;
|
||||
import com.bw.common.utils.JwtUtils;
|
||||
import com.bw.common.utils.Md5Utils;
|
||||
import com.bw.common.utils.StringUtils;
|
||||
import com.bw.mapper.UserMapper;
|
||||
import com.bw.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Author:胡杨
|
||||
* @name:User
|
||||
* @Date:2024/7/23 上午9:29
|
||||
* @Description: com.bw.service.impl
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
@Autowired
|
||||
private UserMapper mapper;
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
@Override
|
||||
public Boolean insUser(User user) {
|
||||
if (StringUtils.isEmpty(user.getUpwd())){
|
||||
return false;
|
||||
}
|
||||
String pwd = Md5Utils.string2Md5(user.getUpwd());
|
||||
user.setUpwd(pwd);
|
||||
Integer n = mapper.insUser(user);
|
||||
return n > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<JwtResponse> login(UserReq userReq) {
|
||||
// 用户名验证
|
||||
User user = mapper.findUserByUname(userReq.getUname());
|
||||
if (null == user){
|
||||
return Result.error("用户名不存在");
|
||||
}else if (!user.getUpwd().equals(Md5Utils.string2Md5(userReq.getUpwd()))){
|
||||
// 加密密码验证
|
||||
return Result.error("密码错误");
|
||||
}
|
||||
|
||||
// 生成token令牌
|
||||
String userKey = UUID.randomUUID().toString();
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put(JwtConstants.USER_KEY,userKey);
|
||||
String token = JwtUtils.createToken(map);
|
||||
|
||||
// 存储redis用户信息 30分钟
|
||||
redisTemplate.opsForValue().set(JwtConstants.LOGIN_TOKEN+userKey,
|
||||
JSONObject.toJSONString(user), 30, TimeUnit.MINUTES);
|
||||
|
||||
// 封装响应数据
|
||||
return Result.success(new JwtResponse(token,"30TIM"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updUserPrice(Long uid, Double price) {
|
||||
return mapper.updUserPrice(uid,price) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarLogResp findCarLogByLid(String lid) {
|
||||
return mapper.findCarLogByLid(lid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserByUid(Long uid) {
|
||||
return mapper.getUserByUid(uid);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9001
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: week1-user
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 47.116.173.119:8848
|
||||
namespace: 0b55c4a7-3474-4454-9452-5210cc4320e0
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 47.116.173.119:8848
|
||||
namespace: 0b55c4a7-3474-4454-9452-5210cc4320e0
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bw.mapper.UserMapper">
|
||||
|
||||
<insert id="insUser">
|
||||
INSERT INTO `high-six-exam`.`week1_user`
|
||||
(`uname`, `upwd`, `uprice`, `utel`) VALUES
|
||||
(#{uname}, #{upwd}, #{uprice}, #{utel});
|
||||
</insert>
|
||||
<update id="updUserPrice">
|
||||
update week1_user
|
||||
set uprice = uprice - #{price}
|
||||
where uid = #{uid};
|
||||
</update>
|
||||
<select id="findUserByUname" resultType="com.bw.common.domain.pojo.User">
|
||||
select *
|
||||
from `high-six-exam`.`week1_user` where uname = #{uname}
|
||||
</select>
|
||||
<select id="findCarLogByLid" resultType="com.bw.common.domain.response.CarLogResp">
|
||||
select cl.*,c.cnumid,c.csta,u.uname,u.utel,ct.tname,ct.tid,ct.tprice
|
||||
from week1_car_log cl
|
||||
left join week1_car c on cl.cid=c.cid
|
||||
left join week1_car_type ct on c.tid=ct.tid
|
||||
left join week1_user u on cl.uid=u.uid
|
||||
where cl.lid=#{lid}
|
||||
</select>
|
||||
<select id="getUserByUid" resultType="com.bw.common.domain.pojo.User">
|
||||
select *
|
||||
from `high-six-exam`.`week1_user` where uid = #{uid}
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,80 @@
|
|||
<?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>com.bw</groupId>
|
||||
<artifactId>week1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bw-moudles</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>bw-user</module>
|
||||
<module>bw-car</module>
|
||||
<module>bw-carLog</module>
|
||||
</modules>
|
||||
|
||||
|
||||
<!--版本管理-->
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<mybatis.version>2.2.2</mybatis.version>
|
||||
<druid.version>1.2.8</druid.version>
|
||||
<pagehelper.version>1.4.1</pagehelper.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 系统公共 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.bw</groupId>
|
||||
<artifactId>bw-common</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringBoot Web-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- Druid -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>${druid.version}</version>
|
||||
</dependency>
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- Mybatis 依赖配置 -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>${mybatis.version}</version>
|
||||
</dependency>
|
||||
<!-- Pagehelper -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>${pagehelper.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||
</dependency>
|
||||
<!-- 引入 springboot kafka -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,66 @@
|
|||
<?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>
|
||||
|
||||
<groupId>com.bw</groupId>
|
||||
<artifactId>week1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>bw-auth</module>
|
||||
<module>bw-common</module>
|
||||
<module>bw-gateway</module>
|
||||
<module>bw-moudles</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<!-- 规定SpringBoot版本 -->
|
||||
<!-- 父级pom文件 主要用于规定项目依赖的各个版本,用于进行项目版本约束 -->
|
||||
<parent>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<version>2.6.2</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<!-- 依赖声明 -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- SpringCloud 微服务 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>2021.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba 微服务 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>2021.1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- Alibaba Nacos 配置 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>2.0.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 系统公共 依赖 版本号定义-->
|
||||
<dependency>
|
||||
<groupId>com.bw</groupId>
|
||||
<artifactId>bw-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : 本机
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 50744
|
||||
Source Host : localhost:3306
|
||||
Source Schema : high-six-exam
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 50744
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 23/07/2024 14:18:36
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for week1_user
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `week1_user`;
|
||||
CREATE TABLE `week1_user` (
|
||||
`uid` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
|
||||
`uname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '用户名',
|
||||
`upwd` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '用户密码',
|
||||
`uprice` decimal(10, 2) NULL DEFAULT NULL COMMENT '用户余额',
|
||||
`utel` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '用户手机号',
|
||||
PRIMARY KEY (`uid`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of week1_user
|
||||
-- ----------------------------
|
||||
INSERT INTO `week1_user` VALUES (1, '张三', 'e10adc3949ba59abbe56e057f20f883e', 4759.00, '18778945446');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for week1_car_type
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `week1_car_type`;
|
||||
CREATE TABLE `week1_car_type` (
|
||||
`tid` int(11) NOT NULL AUTO_INCREMENT COMMENT '车辆类型',
|
||||
`tname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '车辆类型名称',
|
||||
`tprice` decimal(10, 2) NULL DEFAULT NULL COMMENT '车辆出租价格',
|
||||
PRIMARY KEY (`tid`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '车辆类型表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of week1_car_type
|
||||
-- ----------------------------
|
||||
INSERT INTO `week1_car_type` VALUES (1, '入门山地车', 1.00);
|
||||
INSERT INTO `week1_car_type` VALUES (2, '入门公路车', 1.20);
|
||||
INSERT INTO `week1_car_type` VALUES (3, '专业山地车', 1.30);
|
||||
INSERT INTO `week1_car_type` VALUES (4, '专业公路车', 1.60);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for week1_car_log
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `week1_car_log`;
|
||||
CREATE TABLE `week1_car_log` (
|
||||
`lid` int(11) NOT NULL AUTO_INCREMENT COMMENT '记录ID',
|
||||
`cid` int(11) NULL DEFAULT NULL COMMENT '记录车辆',
|
||||
`uid` int(11) NULL DEFAULT NULL COMMENT '记录用户',
|
||||
`lstadate` datetime NULL DEFAULT NULL COMMENT '租车开始时间',
|
||||
`ltime` int(11) NULL DEFAULT NULL COMMENT '用车时间',
|
||||
`ldist` decimal(10, 1) NULL DEFAULT NULL COMMENT '行驶距离',
|
||||
`lprice` decimal(10, 2) NULL DEFAULT NULL COMMENT '费用',
|
||||
`lsta` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '1' COMMENT '状态 1.骑行中 2.已结束',
|
||||
PRIMARY KEY (`lid`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '租车日志表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of week1_car_log
|
||||
-- ----------------------------
|
||||
INSERT INTO `week1_car_log` VALUES (1, 1, 1, '2024-07-23 03:48:24', 100, 80.0, 114.00, '2');
|
||||
INSERT INTO `week1_car_log` VALUES (2, 4, 1, '2024-07-23 13:19:53', 30, 24.0, 41.40, '2');
|
||||
INSERT INTO `week1_car_log` VALUES (3, 4, 1, '2024-07-23 14:07:39', 2, 1.6, 2.80, '2');
|
||||
INSERT INTO `week1_car_log` VALUES (4, 4, 1, '2024-07-23 13:16:43', 60, 48.0, 82.80, '2');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for week1_car
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `week1_car`;
|
||||
CREATE TABLE `week1_car` (
|
||||
`cid` int(11) NOT NULL AUTO_INCREMENT COMMENT '车辆ID',
|
||||
`cnumid` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '车辆编号',
|
||||
`tid` int(11) NULL DEFAULT NULL COMMENT '车辆类型',
|
||||
`csta` int(2) NULL DEFAULT 1 COMMENT '车辆状态 1.未出租 2.已出租',
|
||||
PRIMARY KEY (`cid`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 21 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '车辆表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of week1_car
|
||||
-- ----------------------------
|
||||
INSERT INTO `week1_car` VALUES (1, 'SH648490', 3, 1);
|
||||
INSERT INTO `week1_car` VALUES (2, 'SH111416', 3, 1);
|
||||
INSERT INTO `week1_car` VALUES (3, 'SH191504', 2, 1);
|
||||
INSERT INTO `week1_car` VALUES (4, 'SH130323', 4, 1);
|
||||
INSERT INTO `week1_car` VALUES (5, 'SH669678', 1, 1);
|
||||
INSERT INTO `week1_car` VALUES (6, 'SH339286', 1, 1);
|
||||
INSERT INTO `week1_car` VALUES (7, 'SH976802', 1, 1);
|
||||
INSERT INTO `week1_car` VALUES (8, 'SH022866', 4, 1);
|
||||
INSERT INTO `week1_car` VALUES (9, 'SH195292', 1, 1);
|
||||
INSERT INTO `week1_car` VALUES (10, 'SH327763', 1, 1);
|
||||
INSERT INTO `week1_car` VALUES (11, 'SH871777', 4, 1);
|
||||
INSERT INTO `week1_car` VALUES (12, 'SH755751', 4, 1);
|
||||
INSERT INTO `week1_car` VALUES (13, 'SH384598', 4, 1);
|
||||
INSERT INTO `week1_car` VALUES (14, 'SH623726', 4, 1);
|
||||
INSERT INTO `week1_car` VALUES (15, 'SH454936', 2, 1);
|
||||
INSERT INTO `week1_car` VALUES (16, 'SH791637', 3, 1);
|
||||
INSERT INTO `week1_car` VALUES (17, 'SH630046', 4, 1);
|
||||
INSERT INTO `week1_car` VALUES (18, 'SH445904', 2, 1);
|
||||
INSERT INTO `week1_car` VALUES (19, 'SH482452', 4, 1);
|
||||
INSERT INTO `week1_car` VALUES (20, 'SH563381', 4, 1);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue