diff --git a/auth-common/pom.xml b/auth-common/pom.xml
new file mode 100644
index 0000000..737f179
--- /dev/null
+++ b/auth-common/pom.xml
@@ -0,0 +1,81 @@
+
+ 4.0.0
+
+ com.auth
+ auth-server
+ 0.0.1
+
+
+ auth-common
+ jar
+ 0.0.1
+ common
+ 公共的配置和实体类
+
+
+ UTF-8
+ 17
+ 17
+ 17
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-security
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+ com.baomidou
+ mybatis-plus-spring-boot3-starter
+
+
+ com.mysql
+ mysql-connector-j
+
+
+ com.zaxxer
+ HikariCP
+
+
+
+
+ io.jsonwebtoken
+ jjwt
+
+
+
+
+ com.alibaba
+ easyexcel
+
+
+
+
+ com.alibaba.fastjson2
+ fastjson2
+
+
+
+
+ com.github.xiaoymin
+ knife4j-openapi3-jakarta-spring-boot-starter
+
+
+
diff --git a/auth-common/src/main/java/com/auth/common/config/ControllerStringParamTrimConfig.java b/auth-common/src/main/java/com/auth/common/config/ControllerStringParamTrimConfig.java
new file mode 100644
index 0000000..4a7e97b
--- /dev/null
+++ b/auth-common/src/main/java/com/auth/common/config/ControllerStringParamTrimConfig.java
@@ -0,0 +1,50 @@
+package com.auth.common.config;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
+import org.springframework.beans.propertyeditors.StringTrimmerEditor;
+import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.InitBinder;
+
+import java.io.IOException;
+
+/**
+ * 去除前端传递的空格
+ */
+@ControllerAdvice
+public class ControllerStringParamTrimConfig {
+
+ /**
+ * 创建 String trim 编辑器
+ * 构造方法中 boolean 参数含义为如果是空白字符串,是否转换为null
+ * 即如果为true,那么 " " 会被转换为 null,否者为 ""
+ */
+ @InitBinder
+ public void initBinder(WebDataBinder binder) {
+ StringTrimmerEditor propertyEditor = new StringTrimmerEditor(false);
+ // 为 String 类对象注册编辑器
+ binder.registerCustomEditor(String.class, propertyEditor);
+ }
+
+ @Bean
+ public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
+ return jacksonObjectMapperBuilder -> {
+ // 为 String 类型自定义反序列化操作
+ jacksonObjectMapperBuilder
+ .deserializerByType(String.class, new StdScalarDeserializer(String.class) {
+ @Override
+ public String deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
+ // // 去除全部空格
+ // return StringUtils.trimAllWhitespace(jsonParser.getValueAsString());
+
+ // 仅去除前后空格
+ return jsonParser.getValueAsString().trim();
+ }
+ });
+ };
+ }
+}
\ No newline at end of file
diff --git a/auth-common/src/main/java/com/auth/common/config/MyBatisPlusFieldConfig.java b/auth-common/src/main/java/com/auth/common/config/MyBatisPlusFieldConfig.java
new file mode 100644
index 0000000..c204ba6
--- /dev/null
+++ b/auth-common/src/main/java/com/auth/common/config/MyBatisPlusFieldConfig.java
@@ -0,0 +1,44 @@
+package com.auth.common.config;
+
+import com.auth.common.context.BaseContext;
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+
+/**
+ * 配置MP在修改和新增时的操作
+ */
+@Component
+public class MyBatisPlusFieldConfig implements MetaObjectHandler {
+
+ /**
+ * 使用mp做添加操作时候,这个方法执行
+ */
+ @Override
+ public void insertFill(MetaObject metaObject) {
+ // 设置属性值
+ this.strictInsertFill(metaObject, "isDeleted", Integer.class, 0);
+ this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
+ this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
+ if (BaseContext.getUsername() != null) {
+ this.setFieldValByName("createUser", BaseContext.getUserId(), metaObject);
+ this.setFieldValByName("updateUser", BaseContext.getUserId(), metaObject);
+ } else {
+ this.setFieldValByName("createUser", 0L, metaObject);
+ this.setFieldValByName("updateUser", BaseContext.getUserId(), metaObject);
+ }
+ }
+
+ /**
+ * 使用mp做修改操作时候,这个方法执行
+ */
+ @Override
+ public void updateFill(MetaObject metaObject) {
+ if (BaseContext.getUserId() != null) {
+ this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
+ this.setFieldValByName("updateUser", BaseContext.getUserId(), metaObject);
+ }
+ }
+}
diff --git a/auth-common/src/main/java/com/auth/common/config/MybatisPlusConfig.java b/auth-common/src/main/java/com/auth/common/config/MybatisPlusConfig.java
new file mode 100644
index 0000000..ebd027b
--- /dev/null
+++ b/auth-common/src/main/java/com/auth/common/config/MybatisPlusConfig.java
@@ -0,0 +1,35 @@
+package com.auth.common.config;
+
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+@EnableTransactionManagement
+@Configuration
+public class MybatisPlusConfig {
+
+ @Bean
+ public MybatisPlusInterceptor mybatisPlusInterceptor() {
+ // 拦截器
+ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+
+ // 使用分页插件
+ PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
+ paginationInnerInterceptor.setDbType(DbType.MYSQL);
+ paginationInnerInterceptor.setMaxLimit(600L);
+ interceptor.addInnerInterceptor(paginationInnerInterceptor);
+
+ // 乐观锁
+ interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
+
+ // 防止全表删除
+ interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
+
+ return interceptor;
+ }
+}
diff --git a/auth-common/src/main/java/com/auth/common/config/ThreadLocalCleanupInterceptor.java b/auth-common/src/main/java/com/auth/common/config/ThreadLocalCleanupInterceptor.java
new file mode 100644
index 0000000..0d165e8
--- /dev/null
+++ b/auth-common/src/main/java/com/auth/common/config/ThreadLocalCleanupInterceptor.java
@@ -0,0 +1,23 @@
+package com.auth.common.config;
+
+import com.auth.common.context.BaseContext;
+import jakarta.annotation.Nullable;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.HandlerInterceptor;
+
+@Configuration
+public class ThreadLocalCleanupInterceptor implements HandlerInterceptor {
+
+ // @Override
+ // public boolean preHandle(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Object handler) {
+ // return true;
+ // }
+
+ @Override
+ public void afterCompletion(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Object handler, Exception ex) {
+ // 移除上下文存储内容
+ BaseContext.removeUser();
+ }
+}
\ No newline at end of file
diff --git a/auth-common/src/main/java/com/auth/common/config/WebConfig.java b/auth-common/src/main/java/com/auth/common/config/WebConfig.java
new file mode 100644
index 0000000..b0d9fc7
--- /dev/null
+++ b/auth-common/src/main/java/com/auth/common/config/WebConfig.java
@@ -0,0 +1,26 @@
+package com.auth.common.config;
+
+import lombok.RequiredArgsConstructor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+@RequiredArgsConstructor
+public class WebConfig implements WebMvcConfigurer {
+
+ private final ThreadLocalCleanupInterceptor threadLocalCleanupInterceptor;
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(threadLocalCleanupInterceptor);
+ }
+
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+
+}
\ No newline at end of file
diff --git a/auth-common/src/main/java/com/auth/common/context/BaseContext.java b/auth-common/src/main/java/com/auth/common/context/BaseContext.java
new file mode 100644
index 0000000..f948f30
--- /dev/null
+++ b/auth-common/src/main/java/com/auth/common/context/BaseContext.java
@@ -0,0 +1,29 @@
+package com.auth.common.context;
+
+
+public class BaseContext {
+ private static final ThreadLocal userId = new ThreadLocal<>();
+ private static final ThreadLocal username = new ThreadLocal<>();
+
+ // 用户id相关
+ public static Long getUserId() {
+ return userId.get();
+ }
+
+ public static void setUserId(Long _userId) {
+ userId.set(_userId);
+ }
+
+ public static String getUsername() {
+ return username.get();
+ }
+
+ public static void setUsername(String _username) {
+ username.set(_username);
+ }
+
+ public static void removeUser() {
+ username.remove();
+ userId.remove();
+ }
+}
\ No newline at end of file
diff --git a/auth-common/src/main/java/com/auth/common/exception/AuthenticSecurityException.java b/auth-common/src/main/java/com/auth/common/exception/AuthenticSecurityException.java
new file mode 100644
index 0000000..dc42d66
--- /dev/null
+++ b/auth-common/src/main/java/com/auth/common/exception/AuthenticSecurityException.java
@@ -0,0 +1,47 @@
+package com.auth.common.exception;
+
+
+import com.auth.common.model.common.result.ResultCodeEnum;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+import lombok.extern.slf4j.Slf4j;
+
+@NoArgsConstructor
+@Getter
+@ToString
+@Slf4j
+public class AuthenticSecurityException extends RuntimeException {
+ // 状态码
+ Integer code;
+
+ // 描述信息
+ String message = "服务异常";
+
+ // 返回结果状态
+ ResultCodeEnum resultCodeEnum;
+
+ public AuthenticSecurityException(Integer code, String message) {
+ super(message);
+ this.code = code;
+ this.message = message;
+ }
+
+ public AuthenticSecurityException(String message) {
+ super(message);
+ this.message = message;
+ }
+
+ public AuthenticSecurityException(ResultCodeEnum codeEnum) {
+ super(codeEnum.getMessage());
+ this.code = codeEnum.getCode();
+ this.message = codeEnum.getMessage();
+ this.resultCodeEnum = codeEnum;
+ }
+
+ public AuthenticSecurityException(String message, Exception exception) {
+ super(message);
+ this.message = message;
+ log.error(message, exception);
+ }
+}
diff --git a/auth-common/src/main/java/com/auth/common/exception/GlobalExceptionHandler.java b/auth-common/src/main/java/com/auth/common/exception/GlobalExceptionHandler.java
new file mode 100644
index 0000000..4928eaa
--- /dev/null
+++ b/auth-common/src/main/java/com/auth/common/exception/GlobalExceptionHandler.java
@@ -0,0 +1,102 @@
+package com.auth.common.exception;
+
+import com.auth.common.model.common.result.Result;
+import com.auth.common.model.common.result.ResultCodeEnum;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.support.DefaultMessageSourceResolvable;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import java.sql.SQLIntegrityConstraintViolationException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+@RestControllerAdvice
+@Slf4j
+public class GlobalExceptionHandler {
+
+ @ExceptionHandler(AuthenticSecurityException.class)
+ @ResponseBody
+ public Result