diff --git a/jeecg-boot-base/jeecg-boot-base-tools/src/main/java/org/jeecg/common/constant/YaoDuCacheConstant.java b/jeecg-boot-base/jeecg-boot-base-tools/src/main/java/org/jeecg/common/constant/YaoDuCacheConstant.java new file mode 100644 index 0000000..382797e --- /dev/null +++ b/jeecg-boot-base/jeecg-boot-base-tools/src/main/java/org/jeecg/common/constant/YaoDuCacheConstant.java @@ -0,0 +1,51 @@ +package org.jeecg.common.constant; + +import java.time.Duration; + +/** + * @author: system + * @date: 2025-01-17 + * @description: 瑶都API缓存常量 + */ +public interface YaoDuCacheConstant { + + /** + * 瑶都API缓存前缀 + */ + String YAODU_CACHE_PREFIX = "yaodu:api:cache:"; + + /** + * 帖子分页列表缓存 + */ + String YAODU_POST_PAGE_CACHE = YAODU_CACHE_PREFIX + "post:page"; + + /** + * 首页头部信息缓存 + */ + String YAODU_INDEX_HEADER_CACHE = YAODU_CACHE_PREFIX + "index:header"; + + /** + * 发布按钮列表缓存 + */ + String YAODU_PUBLISH_LIST_CACHE = YAODU_CACHE_PREFIX + "publish:list"; + + /** + * 缓存过期时间配置类 + */ + class CacheExpiration { + /** + * 帖子分页列表缓存过期时间 - 10分钟 + */ + public static final Duration POST_PAGE_TTL = Duration.ofMinutes(10); + + /** + * 首页头部信息缓存过期时间 - 30分钟 + */ + public static final Duration INDEX_HEADER_TTL = Duration.ofMinutes(30); + + /** + * 发布按钮列表缓存过期时间 - 1小时 + */ + public static final Duration PUBLISH_LIST_TTL = Duration.ofHours(1); + } +} \ No newline at end of file diff --git a/jeecg-boot-base/jeecg-boot-base-tools/src/main/java/org/jeecg/common/modules/redis/config/RedisConfig.java b/jeecg-boot-base/jeecg-boot-base-tools/src/main/java/org/jeecg/common/modules/redis/config/RedisConfig.java index f72622b..bfb140a 100644 --- a/jeecg-boot-base/jeecg-boot-base-tools/src/main/java/org/jeecg/common/modules/redis/config/RedisConfig.java +++ b/jeecg-boot-base/jeecg-boot-base-tools/src/main/java/org/jeecg/common/modules/redis/config/RedisConfig.java @@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j; import org.jeecg.common.constant.CacheConstant; import org.jeecg.common.constant.GlobalConstants; +import org.jeecg.common.constant.YaoDuCacheConstant; import org.jeecg.common.modules.redis.receiver.RedisReceiver; import org.jeecg.common.modules.redis.writer.JeecgRedisCacheWriter; @@ -101,6 +102,16 @@ public class RedisConfig extends CachingConfigurerSupport { .withInitialCacheConfigurations(singletonMap(CacheConstant.TEST_DEMO_CACHE, RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(5)).disableCachingNullValues())) .withInitialCacheConfigurations(singletonMap(CacheConstant.PLUGIN_MALL_RANKING, RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(24)).disableCachingNullValues())) .withInitialCacheConfigurations(singletonMap(CacheConstant.PLUGIN_MALL_PAGE_LIST, RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(24)).disableCachingNullValues())) + // 瑶都API缓存配置 + .withInitialCacheConfigurations(singletonMap(YaoDuCacheConstant.YAODU_POST_PAGE_CACHE, + RedisCacheConfiguration.defaultCacheConfig().entryTtl(YaoDuCacheConstant.CacheExpiration.POST_PAGE_TTL).disableCachingNullValues() + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)))) + .withInitialCacheConfigurations(singletonMap(YaoDuCacheConstant.YAODU_INDEX_HEADER_CACHE, + RedisCacheConfiguration.defaultCacheConfig().entryTtl(YaoDuCacheConstant.CacheExpiration.INDEX_HEADER_TTL).disableCachingNullValues() + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)))) + .withInitialCacheConfigurations(singletonMap(YaoDuCacheConstant.YAODU_PUBLISH_LIST_CACHE, + RedisCacheConfiguration.defaultCacheConfig().entryTtl(YaoDuCacheConstant.CacheExpiration.PUBLISH_LIST_TTL).disableCachingNullValues() + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)))) .transactionAware().build(); //update-end-author:taoyan date:20210316 for:注解CacheEvict根据key删除redis支持通配符* return cacheManager; diff --git a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/service/impl/YaoDuShopServiceImpl.java b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/service/impl/YaoDuShopServiceImpl.java index ad9c116..c245a5e 100644 --- a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/service/impl/YaoDuShopServiceImpl.java +++ b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/service/impl/YaoDuShopServiceImpl.java @@ -69,9 +69,13 @@ public class YaoDuShopServiceImpl implements YaoDuShopService { int y = byId.getQrCodeY() != null ? byId.getQrCodeY() : 0; double whl = 2.5; + Integer qrCodeBgHashCode = byId.getQrCodeBg() != null ? byId.getQrCodeBg().hashCode() : 0; + + String finalPath = String.format("gourmet/gourmetDetail/final/%s_%s_%s_%s_%s.jpg", + id, qrCodeBgHashCode, x, y); + if (StringUtil.isNotEmpty(byId.getQrCodeBg())){ - String finalPath = String.format("gourmet/gourmetDetail/final/%s_%s_%s_%s_%s.jpg", - id, byId.getQrCodeBg().hashCode(), x, y); + try { InputStream ossFile = OssBootUtil.getOssFile(finalPath, null); if (ossFile != null) { @@ -109,8 +113,7 @@ public class YaoDuShopServiceImpl implements YaoDuShopService { byte[] finalImage = this.generateAndCombineImagesFromUrl2(qrCodeBytes, byId.getQrCodeBg(), x, y, whl); // 异步上传到OSS(移除Redis缓存) - uploadToOssAsync(finalImage, String.format("gourmet/gourmetDetail/final/%s_%s_%s_%s_%s.jpg", - id, byId.getQrCodeBg().hashCode(), x, y, whl)); + uploadToOssAsync(finalImage, finalPath); return finalImage; } catch (Exception e) { diff --git a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/yaoduapi/YaoDuApiController.java b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/yaoduapi/YaoDuApiController.java index e4acec2..8d08f54 100644 --- a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/yaoduapi/YaoDuApiController.java +++ b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/yaoduapi/YaoDuApiController.java @@ -4,9 +4,11 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.vo.Result; +import org.jeecg.common.constant.YaoDuCacheConstant; import org.jeecg.modules.api.bean.PageBean; import org.jeecg.modules.api.service.WebApiService; import org.jeecg.modules.api.service.YaoDuApiService; +import org.springframework.cache.annotation.Cacheable; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; @@ -43,6 +45,7 @@ public class YaoDuApiController { //获取首页头部信息 @ApiOperation(value="获取首页头部信息") @GetMapping(value = "/getIndexHeaderInfo") + @Cacheable(value = YaoDuCacheConstant.YAODU_INDEX_HEADER_CACHE) public Result getIndexHeaderInfo() { return yaoDuApiService.getIndexHeaderInfo(); } @@ -67,6 +70,7 @@ public class YaoDuApiController { //根据分类获取动态帖子列表带分页 @ApiOperation(value="根据分类获取动态帖子列表带分页") @GetMapping(value = "/getPostPage") + @Cacheable(value = YaoDuCacheConstant.YAODU_POST_PAGE_CACHE, key = "#classId + '_' + #pageBean.pageNo + '_' + #pageBean.pageSize") public Result getPostPage(String classId,PageBean pageBean) { return yaoDuApiService.getPostPage(classId,pageBean); } @@ -146,6 +150,7 @@ public class YaoDuApiController { //发布按钮列表 @ApiOperation(value="发布按钮列表") @GetMapping(value = "/getPublishList") + @Cacheable(value = YaoDuCacheConstant.YAODU_PUBLISH_LIST_CACHE) public Result getPublishList() { return yaoDuApiService.getPublishButtonList(); } diff --git a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/yaoduapi/YaoDuApiTokenController.java b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/yaoduapi/YaoDuApiTokenController.java index 39fd60b..ed9b42b 100644 --- a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/yaoduapi/YaoDuApiTokenController.java +++ b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/yaoduapi/YaoDuApiTokenController.java @@ -17,7 +17,9 @@ import org.jeecg.modules.cityMoneyLog.entity.CityMoneyLog; import org.jeecg.modules.cityShopping.entity.CityShopping; import org.jeecg.modules.cityTrends.entity.CityTrends; import org.jeecg.modules.hanHaiMember.entity.HanHaiMember; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.web.bind.annotation.*; +import org.jeecg.common.constant.YaoDuCacheConstant; import javax.annotation.Resource; @@ -74,6 +76,7 @@ public class YaoDuApiTokenController { //发布帖子 @PostMapping(value = "/publishPost") @ApiOperation(value="发布帖子") + @CacheEvict(value = {YaoDuCacheConstant.YAODU_POST_PAGE_CACHE, YaoDuCacheConstant.YAODU_INDEX_HEADER_CACHE}, allEntries = true) public Result publishPost(@RequestHeader("X-Access-Token") String token, CityTrends cityTrends) { return yaoDuApiService.publishPost(token,cityTrends); } diff --git a/jeecg-boot-module-system/src/main/resources/application-dev.yml b/jeecg-boot-module-system/src/main/resources/application-dev.yml index d5dab96..d465721 100644 --- a/jeecg-boot-module-system/src/main/resources/application-dev.yml +++ b/jeecg-boot-module-system/src/main/resources/application-dev.yml @@ -134,9 +134,9 @@ spring: # connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 datasource: master: - url: jdbc:mysql://42.194.239.145:3306/yaodu-api?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false + url: jdbc:mysql://123.207.40.176:3306/yaodu?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false username: root - password: I5+sHYZQ + password: S478n~T8 driver-class-name: com.mysql.cj.jdbc.Driver # 多数据源配置 #multi-datasource1: @@ -147,7 +147,7 @@ spring: #redis 配置 redis: database: 15 - host: 42.194.239.145 + host: 123.207.40.176 lettuce: pool: max-active: -1 #最大连接数据库连接数,设 -1 为没有限制 @@ -155,7 +155,7 @@ spring: max-wait: -1ms #最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。 min-idle: 0 #最小等待连接中的数量,设 0 为没有限制 shutdown-timeout: 1000ms - password: 'lzx.123456' + password: 'S478n~T8' port: 6379 #mybatis plus 设置 mybatis-plus: