From 7b06d59e576919a019a5498bfa39075f1f5fc105 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Wed, 27 Mar 2024 15:32:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BF=AE=E5=A4=8D):=20=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=88=86=E7=B1=BB=E5=92=8C=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=A4=E6=AC=A1=E8=B7=A8=E5=9F=9F=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bunny <1319900154@qq.com> --- .../atguigu/config/WebMvcConfiguration.java | 7 +-- .../properties/InterceptorsProperties.java | 14 ----- .../manger}/properties/MinioProperties.java | 2 +- .../service/impl/FileUploadServiceImpl.java | 4 +- .../src/main/resources/application-dev.yml | 6 -- .../src/main/resources/logback-spring.xml | 57 ------------------- .../src/main/resources/mybatis-config.xml | 16 ------ .../atguigu/gateway/GatewayApplication.java | 2 + .../src/main/resources/application.yml | 23 ++++---- .../src/main/resources/logback-spring.xml | 57 ------------------- spzx-service/service-product/pom.xml | 6 +- .../atguigu/product/ProductApplication.java | 4 ++ .../service/impl/CategoryServiceImpl.java | 19 ++++++- .../src/main/resources/application.yml | 2 +- .../src/main/resources/logback-spring.xml | 57 ------------------- 15 files changed, 47 insertions(+), 229 deletions(-) delete mode 100644 spzx-common/common-util/src/main/java/com/atguigu/properties/InterceptorsProperties.java rename {spzx-common/common-util/src/main/java/com/atguigu => spzx-manager/src/main/java/com/atguigu/spzx/manger}/properties/MinioProperties.java (93%) delete mode 100644 spzx-manager/src/main/resources/logback-spring.xml delete mode 100644 spzx-manager/src/main/resources/mybatis-config.xml delete mode 100644 spzx-server-gateway/src/main/resources/logback-spring.xml delete mode 100644 spzx-service/service-product/src/main/resources/logback-spring.xml diff --git a/spzx-common/common-service/src/main/java/com/atguigu/config/WebMvcConfiguration.java b/spzx-common/common-service/src/main/java/com/atguigu/config/WebMvcConfiguration.java index ab09cc2..7bb8dde 100644 --- a/spzx-common/common-service/src/main/java/com/atguigu/config/WebMvcConfiguration.java +++ b/spzx-common/common-service/src/main/java/com/atguigu/config/WebMvcConfiguration.java @@ -1,7 +1,6 @@ package com.atguigu.config; import com.atguigu.interceptor.LoginAuthInterceptor; -import com.atguigu.properties.InterceptorsProperties; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -14,8 +13,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupp public class WebMvcConfiguration extends WebMvcConfigurationSupport { @Autowired private LoginAuthInterceptor loginAuthInterceptor; - @Autowired - private InterceptorsProperties interceptorsProperties; /** * * 解决跨域 @@ -38,9 +35,9 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport { */ protected void addInterceptors(InterceptorRegistry registry) { log.info("WebMvcConfiguration===>开始注册自定义拦截器..."); - + // 需要拦截的 registry.addInterceptor(loginAuthInterceptor).addPathPatterns("/admin/**") - .excludePathPatterns(interceptorsProperties.getNoAuthUrls()); + .excludePathPatterns("/admin/system/index/login", "/admin/system/index/generateValidateCode", "/admin/product/category/exportData"); } } \ No newline at end of file diff --git a/spzx-common/common-util/src/main/java/com/atguigu/properties/InterceptorsProperties.java b/spzx-common/common-util/src/main/java/com/atguigu/properties/InterceptorsProperties.java deleted file mode 100644 index 57d8054..0000000 --- a/spzx-common/common-util/src/main/java/com/atguigu/properties/InterceptorsProperties.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.atguigu.properties; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import java.util.List; - -@Configuration -@ConfigurationProperties(prefix = "bunny") -@Data -public class InterceptorsProperties { - private List noAuthUrls; -} diff --git a/spzx-common/common-util/src/main/java/com/atguigu/properties/MinioProperties.java b/spzx-manager/src/main/java/com/atguigu/spzx/manger/properties/MinioProperties.java similarity index 93% rename from spzx-common/common-util/src/main/java/com/atguigu/properties/MinioProperties.java rename to spzx-manager/src/main/java/com/atguigu/spzx/manger/properties/MinioProperties.java index 77d4993..f673c93 100644 --- a/spzx-common/common-util/src/main/java/com/atguigu/properties/MinioProperties.java +++ b/spzx-manager/src/main/java/com/atguigu/spzx/manger/properties/MinioProperties.java @@ -1,4 +1,4 @@ -package com.atguigu.properties; +package com.atguigu.spzx.manger.properties; import io.minio.MinioClient; import lombok.Data; diff --git a/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/impl/FileUploadServiceImpl.java b/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/impl/FileUploadServiceImpl.java index 5ed1836..bb9d845 100644 --- a/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/impl/FileUploadServiceImpl.java +++ b/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/impl/FileUploadServiceImpl.java @@ -2,7 +2,7 @@ package com.atguigu.spzx.manger.service.impl; import cn.hutool.core.date.DateUtil; import com.atguigu.exception.BunnyException; -import com.atguigu.properties.MinioProperties; +import com.atguigu.spzx.manger.properties.MinioProperties; import com.atguigu.spzx.manger.service.FileUploadService; import io.minio.BucketExistsArgs; import io.minio.MakeBucketArgs; @@ -36,7 +36,7 @@ public class FileUploadServiceImpl implements FileUploadService { String dir = DateUtil.format(new Date(), "yyyy-MM-dd"); String uuid = UUID.randomUUID().toString(); String filename = dir + "/" + uuid + "-" + file.getOriginalFilename(); - + try { boolean bucketExists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()); // 判断桶是否存在 diff --git a/spzx-manager/src/main/resources/application-dev.yml b/spzx-manager/src/main/resources/application-dev.yml index abd897f..43c86ac 100644 --- a/spzx-manager/src/main/resources/application-dev.yml +++ b/spzx-manager/src/main/resources/application-dev.yml @@ -16,9 +16,3 @@ bunny: bucket-name: spzx-bucket accessKey: "bunny" secretKey: "02120212" - - noAuthUrls: - - /admin/system/index/login - - /admin/system/index/generateValidateCode - - /admin/product/category/exportData - diff --git a/spzx-manager/src/main/resources/logback-spring.xml b/spzx-manager/src/main/resources/logback-spring.xml deleted file mode 100644 index acce308..0000000 --- a/spzx-manager/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - logback - - - - - - - - - - - - - - - - - - - - - - - INFO - - - ${CONSOLE_LOG_PATTERN} - ${ENCODING} - - - - - - ${log.path}//log.log - true - - %date{yyyy-MM-dd HH:mm:ss} %msg%n - ${ENCODING} - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spzx-manager/src/main/resources/mybatis-config.xml b/spzx-manager/src/main/resources/mybatis-config.xml deleted file mode 100644 index 89898c2..0000000 --- a/spzx-manager/src/main/resources/mybatis-config.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java b/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java index f999f80..90bf5e9 100644 --- a/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java +++ b/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java @@ -2,8 +2,10 @@ package com.atguigu.gateway; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; @SpringBootApplication +@ComponentScan("com.atguigu") public class GatewayApplication { public static void main(String[] args) { SpringApplication.run(GatewayApplication.class, args); diff --git a/spzx-server-gateway/src/main/resources/application.yml b/spzx-server-gateway/src/main/resources/application.yml index fb67024..30fd7a9 100644 --- a/spzx-server-gateway/src/main/resources/application.yml +++ b/spzx-server-gateway/src/main/resources/application.yml @@ -11,21 +11,22 @@ spring: discovery: namespace: ${bunny.nacos.discovery.namespace} server-addr: ${bunny.nacos.server-addr} + log-name: logs/${spring.application.name} gateway: discovery: locator: enabled: true # 解决跨域 - globalcors: - cors-configurations: - '[/**]': - allowedOriginPatterns: "*" - # 允许请求中携带的头信息 - allowedHeaders: "*" - # 运行跨域的请求方式 - allowedMethods: "*" - # 跨域检测的有效期,单位s - maxAge: 36000 + # globalcors: + # cors-configurations: + # '[/**]': + # allowedOriginPatterns: "*" + # # 允许请求中携带的头信息 + # allowedHeaders: "*" + # # 运行跨域的请求方式 + # allowedMethods: "*" + # # 跨域检测的有效期,单位s + # maxAge: 36000 # 路由 routes: - id: service-product @@ -41,4 +42,4 @@ logging: pattern: dateformat: HH:mm:ss:SSS file: - path: "logs/${spring.application.name}" + path: logs/${spring.application.name} diff --git a/spzx-server-gateway/src/main/resources/logback-spring.xml b/spzx-server-gateway/src/main/resources/logback-spring.xml deleted file mode 100644 index 0e33e44..0000000 --- a/spzx-server-gateway/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - logback - - - - - - - - - - - - - - - - - - - - - - - INFO - - - ${CONSOLE_LOG_PATTERN} - ${ENCODING} - - - - - - ${log.path}//log.log - true - - %date{yyyy-MM-dd HH:mm:ss} %msg%n - ${ENCODING} - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spzx-service/service-product/pom.xml b/spzx-service/service-product/pom.xml index f153e9e..8a780a2 100644 --- a/spzx-service/service-product/pom.xml +++ b/spzx-service/service-product/pom.xml @@ -18,6 +18,10 @@ - + + + org.springframework.boot + spring-boot-starter-data-redis + diff --git a/spzx-service/service-product/src/main/java/com/atguigu/product/ProductApplication.java b/spzx-service/service-product/src/main/java/com/atguigu/product/ProductApplication.java index 2a82c16..0a41e5a 100644 --- a/spzx-service/service-product/src/main/java/com/atguigu/product/ProductApplication.java +++ b/spzx-service/service-product/src/main/java/com/atguigu/product/ProductApplication.java @@ -2,8 +2,12 @@ package com.atguigu.product; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.ComponentScan; @SpringBootApplication +@ComponentScan("com.atguigu") +@EnableCaching// 开启缓存注解 public class ProductApplication { public static void main(String[] args) { SpringApplication.run(ProductApplication.class, args); diff --git a/spzx-service/service-product/src/main/java/com/atguigu/product/service/impl/CategoryServiceImpl.java b/spzx-service/service-product/src/main/java/com/atguigu/product/service/impl/CategoryServiceImpl.java index 33dad2f..7c97b42 100644 --- a/spzx-service/service-product/src/main/java/com/atguigu/product/service/impl/CategoryServiceImpl.java +++ b/spzx-service/service-product/src/main/java/com/atguigu/product/service/impl/CategoryServiceImpl.java @@ -1,18 +1,23 @@ package com.atguigu.product.service.impl; +import com.alibaba.fastjson.JSON; import com.atguigu.product.mapper.CategoryMapper; import com.atguigu.product.service.CategoryService; import com.atguigu.spzx.model.entity.product.Category; import com.atguigu.utils.CategoryHelper; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.util.List; +import java.util.concurrent.TimeUnit; @Service public class CategoryServiceImpl implements CategoryService { @Autowired private CategoryMapper categoryMapper; + @Autowired + private RedisTemplate redisTemplate; /** * 查询以及分类 @@ -21,7 +26,19 @@ public class CategoryServiceImpl implements CategoryService { */ @Override public List selectOneCategory() { - return categoryMapper.findOneCategory(); + Object categoryOne = redisTemplate.opsForValue().get("category:one"); + String categoryJsonString = JSON.toJSONString(categoryOne); + + // 如果Redis包含以及分类,直接返回 + if (categoryOne != null) { + return JSON.parseArray(categoryJsonString, Category.class); + } + List dbCategory = categoryMapper.findOneCategory(); + + // 查到的数据放到Redis中 + redisTemplate.opsForValue().set("category:one", dbCategory, 7, TimeUnit.DAYS); + + return dbCategory; } /** diff --git a/spzx-service/service-product/src/main/resources/application.yml b/spzx-service/service-product/src/main/resources/application.yml index ba015d3..c429801 100644 --- a/spzx-service/service-product/src/main/resources/application.yml +++ b/spzx-service/service-product/src/main/resources/application.yml @@ -34,7 +34,7 @@ logging: pattern: dateformat: HH:mm:ss:SSS file: - path: "logs/${spring.application.name}" + path: logs/${spring.application.name} mybatis: type-aliases-package: com.atguigu.spzx.model diff --git a/spzx-service/service-product/src/main/resources/logback-spring.xml b/spzx-service/service-product/src/main/resources/logback-spring.xml deleted file mode 100644 index 0e33e44..0000000 --- a/spzx-service/service-product/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - logback - - - - - - - - - - - - - - - - - - - - - - - INFO - - - ${CONSOLE_LOG_PATTERN} - ${ENCODING} - - - - - - ${log.path}//log.log - true - - %date{yyyy-MM-dd HH:mm:ss} %msg%n - ${ENCODING} - - - - - - - - - - - - - - - \ No newline at end of file