commit ac8659ec7cab783a70c13521ce3066b1807eea77
Author: jia <2744404105@qq.com>
Date: Mon Feb 26 09:38:15 2024 +0800
月考5(2)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.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
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..3f8d602
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..c32584c
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..c3f3b0a
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/bwie-auth/pom.xml b/bwie-auth/pom.xml
new file mode 100644
index 0000000..542730c
--- /dev/null
+++ b/bwie-auth/pom.xml
@@ -0,0 +1,32 @@
+
+
+ 4.0.0
+
+ com.bwie
+ test_month
+ 1.0.0
+
+
+ bwie-auth
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+
+ com.bwie
+ bwie-common
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
diff --git a/bwie-auth/src/main/java/com/bwie/auth/AuthApp.java b/bwie-auth/src/main/java/com/bwie/auth/AuthApp.java
new file mode 100644
index 0000000..d513965
--- /dev/null
+++ b/bwie-auth/src/main/java/com/bwie/auth/AuthApp.java
@@ -0,0 +1,17 @@
+package com.bwie.auth;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
+@EnableDiscoveryClient
+@EnableFeignClients(basePackages = "com.bwie.**")
+
+public class AuthApp {
+ public static void main(String[] args) {
+ SpringApplication.run(AuthApp.class);
+ }
+}
diff --git a/bwie-auth/src/main/java/com/bwie/auth/controller/AuthController.java b/bwie-auth/src/main/java/com/bwie/auth/controller/AuthController.java
new file mode 100644
index 0000000..9f4b05c
--- /dev/null
+++ b/bwie-auth/src/main/java/com/bwie/auth/controller/AuthController.java
@@ -0,0 +1,30 @@
+package com.bwie.auth.controller;
+
+import com.bwie.auth.service.AuthService;
+import com.bwie.common.domain.request.LoginRequest;
+import com.bwie.common.domain.response.Info;
+import com.bwie.common.domain.response.JwtResponse;
+import com.bwie.common.result.Result;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@ResponseBody
+public class AuthController {
+ private final AuthService authService;
+
+ public AuthController(AuthService authService) {
+ this.authService = authService;
+ }
+
+ @PostMapping("login")
+ public Result login(@RequestBody LoginRequest loginRequest){
+ JwtResponse login = authService.login(loginRequest);
+ return Result.success(login);
+ }
+ @GetMapping("info")
+ public Result info(){
+ Info info = authService.info();
+ return Result.success(info);
+ }
+
+}
diff --git a/bwie-auth/src/main/java/com/bwie/auth/service/AuthService.java b/bwie-auth/src/main/java/com/bwie/auth/service/AuthService.java
new file mode 100644
index 0000000..5a2fb87
--- /dev/null
+++ b/bwie-auth/src/main/java/com/bwie/auth/service/AuthService.java
@@ -0,0 +1,10 @@
+package com.bwie.auth.service;
+
+import com.bwie.common.domain.request.LoginRequest;
+import com.bwie.common.domain.response.Info;
+import com.bwie.common.domain.response.JwtResponse;
+
+public interface AuthService {
+ JwtResponse login(LoginRequest loginRequest);
+ Info info();
+}
diff --git a/bwie-auth/src/main/java/com/bwie/auth/service/impl/AuthServiceImpl.java b/bwie-auth/src/main/java/com/bwie/auth/service/impl/AuthServiceImpl.java
new file mode 100644
index 0000000..c4eac61
--- /dev/null
+++ b/bwie-auth/src/main/java/com/bwie/auth/service/impl/AuthServiceImpl.java
@@ -0,0 +1,66 @@
+package com.bwie.auth.service.impl;
+
+import com.baomidou.mybatisplus.core.toolkit.Assert;
+import com.bwie.auth.service.AuthService;
+import com.bwie.common.constant.JwtConstants;
+import com.bwie.common.constant.TokenConstants;
+import com.bwie.common.domain.User;
+import com.bwie.common.domain.request.LoginRequest;
+import com.bwie.common.domain.response.Info;
+import com.bwie.common.domain.response.JwtResponse;
+import com.bwie.common.redis.RedisCache;
+import com.bwie.common.remote.user.UserRemoteService;
+import com.bwie.common.result.Result;
+import com.bwie.common.utils.IdUtils;
+import com.bwie.common.utils.JwtUtils;
+import org.springframework.stereotype.Service;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
+import java.util.concurrent.TimeUnit;
+
+@Service
+public class AuthServiceImpl implements AuthService {
+ private final UserRemoteService userRemoteService;
+ private final RedisCache redisCache;
+ private final HttpServletRequest request;
+
+ public AuthServiceImpl(UserRemoteService userRemoteService, RedisCache redisCache, HttpServletRequest request) {
+ this.userRemoteService = userRemoteService;
+ this.redisCache = redisCache;
+ this.request = request;
+ }
+
+
+ @Override
+ public JwtResponse login(LoginRequest loginRequest) {
+ Result findname = userRemoteService.findname(loginRequest.getUserName());
+ Assert.isTrue(findname.isSuccess(),"登陆失败");
+ User data = findname.getData();
+ Assert.notNull(data,"用户不存在");
+ Assert.isTrue(data.getUserPwd().equals(loginRequest.getUserPwd()),"密码不正确");
+
+ HashMap map = new HashMap<>();
+ String key = IdUtils.genId();
+ map.put(JwtConstants.USER_KEY,key);
+ String token = JwtUtils.createToken(map);
+ redisCache.setCacheObject(TokenConstants.LOGIN_TOKEN_KEY+key,data,TokenConstants.EXPIRATION, TimeUnit.SECONDS);
+
+ return JwtResponse.builder()
+ .expireTime(TokenConstants.EXPIRATION)
+ .token(token)
+ .build();
+ }
+
+ @Override
+ public Info info() {
+ User cacheObject = redisCache.getCacheObject(TokenConstants.LOGIN_TOKEN_KEY + request.getHeader(JwtConstants.USER_KEY));
+
+ return Info.builder()
+ .userPhone(cacheObject.getUserPhone())
+ .userId(cacheObject.getUserId())
+ .userName(cacheObject.getUserName())
+ .userRole(cacheObject.getUserRole())
+ .build();
+ }
+}
diff --git a/bwie-auth/src/main/resources/bootstrap.yml b/bwie-auth/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..770cce2
--- /dev/null
+++ b/bwie-auth/src/main/resources/bootstrap.yml
@@ -0,0 +1,31 @@
+# Tomcat
+server:
+ port: 9001
+# Spring
+spring:
+ main:
+ allow-circular-references: true
+ allow-bean-definition-overriding: true
+ jackson:
+ date-format: yyyy-MM-dd HH:mm:ss
+ time-zone: GMT+8
+ application:
+ # 应用名称
+ name: bwie-auth
+ profiles:
+ # 环境配置
+ active: dev
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: 124.221.177.197:8848
+ config:
+ # 配置中心地址
+ server-addr: 124.221.177.197:8848
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+
diff --git a/bwie-common/pom.xml b/bwie-common/pom.xml
new file mode 100644
index 0000000..135ddd8
--- /dev/null
+++ b/bwie-common/pom.xml
@@ -0,0 +1,114 @@
+
+
+ 4.0.0
+
+ com.bwie
+ test_month
+ 1.0.0
+
+
+ bwie-common
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-bootstrap
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-sentinel
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+
+ io.jsonwebtoken
+ jjwt
+ 0.9.1
+
+
+
+ com.alibaba
+ fastjson
+ 1.2.80
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+
+ org.apache.commons
+ commons-lang3
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+ cn.hutool
+ hutool-all
+ 5.8.3
+
+
+
+ com.aliyun
+ dysmsapi20170525
+ 2.0.1
+
+
+
+ org.springframework.boot
+ spring-boot-starter-amqp
+
+
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.5.4.1
+
+
+
+
+ com.alibaba.fastjson2
+ fastjson2
+ 2.0.42
+
+
+
diff --git a/bwie-common/src/main/java/com/bwie/common/config/FastJson2JsonRedisSerializer.java b/bwie-common/src/main/java/com/bwie/common/config/FastJson2JsonRedisSerializer.java
new file mode 100644
index 0000000..584566b
--- /dev/null
+++ b/bwie-common/src/main/java/com/bwie/common/config/FastJson2JsonRedisSerializer.java
@@ -0,0 +1,48 @@
+package com.bwie.common.config;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONReader;
+import com.alibaba.fastjson2.JSONWriter;
+import com.alibaba.fastjson2.filter.Filter;
+import org.springframework.data.redis.serializer.RedisSerializer;
+import org.springframework.data.redis.serializer.SerializationException;
+
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * Redis使用FastJson序列化
+ *
+ * @author ruoyi
+ */
+public class FastJson2JsonRedisSerializer implements RedisSerializer {
+ public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
+
+ static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter(
+ "org.springframework", "com");
+
+ private Class clazz;
+
+ public FastJson2JsonRedisSerializer(Class clazz) {
+ super();
+ this.clazz = clazz;
+ }
+
+ @Override
+ public byte[] serialize (T t) throws SerializationException {
+ if (t == null) {
+ return new byte[0];
+ }
+ return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
+ }
+
+ @Override
+ public T deserialize (byte[] bytes) throws SerializationException {
+ if (bytes == null || bytes.length <= 0) {
+ return null;
+ }
+ String str = new String(bytes, DEFAULT_CHARSET);
+
+ return JSON.parseObject(str, clazz, AUTO_TYPE_FILTER);
+ }
+}
diff --git a/bwie-common/src/main/java/com/bwie/common/config/MybatisPlusConfig.java b/bwie-common/src/main/java/com/bwie/common/config/MybatisPlusConfig.java
new file mode 100644
index 0000000..1983b7e
--- /dev/null
+++ b/bwie-common/src/main/java/com/bwie/common/config/MybatisPlusConfig.java
@@ -0,0 +1,30 @@
+package com.bwie.common.config;
+
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author DongZl
+ * @description: Mybatis-Plus配置
+ * @Date 2024-1-10 下午 05:12
+ */
+@Configuration
+public class MybatisPlusConfig {
+
+ public MybatisPlusConfig () {
+ System.out.println("初始化-----------");
+ }
+
+ /**
+ * 添加分页插件
+ */
+ @Bean
+ public MybatisPlusInterceptor mybatisPlusInterceptor() {
+ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+ interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
+ return interceptor;
+ }
+}
diff --git a/bwie-common/src/main/java/com/bwie/common/config/RedisConfig.java b/bwie-common/src/main/java/com/bwie/common/config/RedisConfig.java
new file mode 100644
index 0000000..5d3ecc0
--- /dev/null
+++ b/bwie-common/src/main/java/com/bwie/common/config/RedisConfig.java
@@ -0,0 +1,65 @@
+package com.bwie.common.config;
+
+import org.springframework.cache.annotation.CachingConfigurerSupport;
+import org.springframework.cache.annotation.EnableCaching;
+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.core.script.DefaultRedisScript;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+/**
+ * redis配置
+ *
+ * @author ruoyi
+ */
+@Configuration
+@EnableCaching
+public class RedisConfig extends CachingConfigurerSupport {
+ @Bean
+ @SuppressWarnings(value = {"unchecked", "rawtypes"})
+ public RedisTemplate