From 0ced5d2eaab38223a787aebb85a31a6f2de73eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Fri, 27 May 2022 09:58:34 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20oss=20=E5=9B=9E?= =?UTF-8?q?=E6=98=BE=E6=9F=A5=E8=AF=A2=20=E4=BD=BF=E7=94=A8=20redis=20?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/impl/SysOssServiceImpl.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java index 28bee3d2..03a6cfca 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java @@ -1,5 +1,6 @@ package com.ruoyi.system.service.impl; +import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -7,6 +8,8 @@ import com.ruoyi.common.core.domain.PageQuery; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.redis.RedisUtils; +import com.ruoyi.oss.constant.OssConstant; import com.ruoyi.oss.core.OssClient; import com.ruoyi.oss.entity.UploadResult; import com.ruoyi.oss.factory.OssFactory; @@ -20,6 +23,8 @@ import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.time.Duration; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -44,7 +49,17 @@ public class SysOssServiceImpl implements ISysOssService { @Override public List listByIds(Collection ossIds) { - return baseMapper.selectVoById(ossIds); + List list = new ArrayList<>(); + for (Long id : ossIds) { + String key = OssConstant.SYS_OSS_KEY + id; + SysOssVo vo = RedisUtils.getCacheObject(key); + if (ObjectUtil.isNull(vo)) { + vo = baseMapper.selectVoById(id); + RedisUtils.setCacheObject(key, vo, Duration.ofDays(30)); + } + list.add(vo); + } + return list; } private LambdaQueryWrapper buildQueryWrapper(SysOssBo bo) {