commit 42c0dd02cdd969bc86bd94b4f9a65c246645c26b
Author: 少年梦与砖 <2847127106@qq.com>
Date: Tue Jul 23 21:21:38 2024 +0800
周考1
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3e403e3
--- /dev/null
+++ b/.gitignore
@@ -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
diff --git a/bw-auth/pom.xml b/bw-auth/pom.xml
new file mode 100644
index 0000000..6a4c2fd
--- /dev/null
+++ b/bw-auth/pom.xml
@@ -0,0 +1,31 @@
+
+
+ 4.0.0
+
+ com.bw
+ week1
+ 1.0-SNAPSHOT
+
+
+ bw-auth
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+ com.bw
+ bw-common
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
diff --git a/bw-auth/src/main/java/com/bw/AuthApplication.java b/bw-auth/src/main/java/com/bw/AuthApplication.java
new file mode 100644
index 0000000..2bda88e
--- /dev/null
+++ b/bw-auth/src/main/java/com/bw/AuthApplication.java
@@ -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 模块启动成功!");
+ }
+}
diff --git a/bw-auth/src/main/java/com/bw/advice/AuthAdvice.java b/bw-auth/src/main/java/com/bw/advice/AuthAdvice.java
new file mode 100644
index 0000000..9df52f6
--- /dev/null
+++ b/bw-auth/src/main/java/com/bw/advice/AuthAdvice.java
@@ -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 handleException(Throwable e) {
+ log.error("出现错误:{}",e.getMessage());
+ return Result.error("网络异常,请稍后再尝试...");
+ }
+}
diff --git a/bw-auth/src/main/java/com/bw/config/ConfirmCallbackConfig.java b/bw-auth/src/main/java/com/bw/config/ConfirmCallbackConfig.java
new file mode 100644
index 0000000..e394fe3
--- /dev/null
+++ b/bw-auth/src/main/java/com/bw/config/ConfirmCallbackConfig.java
@@ -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
+ }
+ }
+
+}
diff --git a/bw-auth/src/main/java/com/bw/config/ReturnCallbackConfig.java b/bw-auth/src/main/java/com/bw/config/ReturnCallbackConfig.java
new file mode 100644
index 0000000..5231cad
--- /dev/null
+++ b/bw-auth/src/main/java/com/bw/config/ReturnCallbackConfig.java
@@ -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 回退了所有的信息,可做补偿机制
+ }
+
+}
diff --git a/bw-auth/src/main/java/com/bw/controller/AuthController.java b/bw-auth/src/main/java/com/bw/controller/AuthController.java
new file mode 100644
index 0000000..39a4e29
--- /dev/null
+++ b/bw-auth/src/main/java/com/bw/controller/AuthController.java
@@ -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 login(@RequestBody UserReq userReq) {
+ return service.login(userReq);
+ }
+
+ /**
+ * 获取当前用户信息
+ */
+ @GetMapping("/info")
+ Result