From fbdae78675d378b616565bef90ea23a63eef78e1 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: Wed, 1 Feb 2023 13:30:13 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=96=B0=E5=A2=9E=20=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=20=E7=94=A8=E6=88=B7=E5=90=8D=20=E4=B8=8E=20?= =?UTF-8?q?ossUrl=20=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/constant/CacheNames.java | 5 ++++ .../ruoyi/common/core/service/OssService.java | 18 ++++++++++++ .../common/core/service/UserService.java | 18 ++++++++++++ .../core/impl/OssUrlTranslationImpl.java | 28 +++++++++++++++++++ .../core/impl/UserNameTranslationImpl.java | 8 ++++-- .../service/impl/SysOssServiceImpl.java | 20 +++++++++---- .../service/impl/SysUserServiceImpl.java | 12 +++++++- 7 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/OssService.java create mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/UserService.java create mode 100644 ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/impl/OssUrlTranslationImpl.java diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/CacheNames.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/CacheNames.java index ba09e9c4..df3a10a1 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/CacheNames.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/CacheNames.java @@ -30,6 +30,11 @@ public interface CacheNames { */ String SYS_DICT = "sys_dict"; + /** + * 用户账户 + */ + String SYS_USER_NAME = "sys_user_name#30d"; + /** * OSS内容 */ diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/OssService.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/OssService.java new file mode 100644 index 00000000..65dda7c6 --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/OssService.java @@ -0,0 +1,18 @@ +package com.ruoyi.common.core.service; + +/** + * 通用 OSS服务 + * + * @author Lion Li + */ +public interface OssService { + + /** + * 通过ossId查询对应的url + * + * @param ossIds ossId串逗号分隔 + * @return url串逗号分隔 + */ + String selectUrlByIds(String ossIds); + +} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/UserService.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/UserService.java new file mode 100644 index 00000000..d2206c8b --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/service/UserService.java @@ -0,0 +1,18 @@ +package com.ruoyi.common.core.service; + +/** + * 通用 用户服务 + * + * @author Lion Li + */ +public interface UserService { + + /** + * 通过用户ID查询用户账户 + * + * @param userId 用户ID + * @return 用户账户 + */ + String selectUserNameById(Long userId); + +} diff --git a/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/impl/OssUrlTranslationImpl.java b/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/impl/OssUrlTranslationImpl.java new file mode 100644 index 00000000..00a3f384 --- /dev/null +++ b/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/impl/OssUrlTranslationImpl.java @@ -0,0 +1,28 @@ +package com.ruoyi.common.translation.core.impl; + +import com.ruoyi.common.core.service.OssService; +import com.ruoyi.common.translation.annotation.TranslationType; +import com.ruoyi.common.translation.constant.TransConstant; +import com.ruoyi.common.translation.core.TranslationInterface; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +/** + * OSS翻译实现 + * + * @author Lion Li + */ +@Component +@AllArgsConstructor +@TranslationType(type = TransConstant.OSS_ID_TO_URL) +public class OssUrlTranslationImpl implements TranslationInterface { + + private final OssService ossService; + + public String translation(Object key, String other) { + if (key instanceof String ids) { + return ossService.selectUrlByIds(ids); + } + return null; + } +} diff --git a/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/impl/UserNameTranslationImpl.java b/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/impl/UserNameTranslationImpl.java index 34b0e0dc..dbb71dc1 100644 --- a/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/impl/UserNameTranslationImpl.java +++ b/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/impl/UserNameTranslationImpl.java @@ -1,8 +1,10 @@ package com.ruoyi.common.translation.core.impl; +import com.ruoyi.common.core.service.UserService; import com.ruoyi.common.translation.annotation.TranslationType; import com.ruoyi.common.translation.constant.TransConstant; import com.ruoyi.common.translation.core.TranslationInterface; +import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; /** @@ -11,13 +13,15 @@ import org.springframework.stereotype.Component; * @author Lion Li */ @Component +@AllArgsConstructor @TranslationType(type = TransConstant.USER_ID_TO_NAME) public class UserNameTranslationImpl implements TranslationInterface { + private final UserService userService; + public String translation(Object key, String other) { - // todo 待实现 if (key instanceof Long id) { - return "admin"; + return userService.selectUserNameById(id); } return null; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java index 7dcb8b88..db3b6c91 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.core.constant.CacheNames; import com.ruoyi.common.core.exception.ServiceException; +import com.ruoyi.common.core.service.OssService; import com.ruoyi.common.core.utils.BeanCopyUtils; import com.ruoyi.common.core.utils.SpringUtils; import com.ruoyi.common.core.utils.StreamUtils; @@ -32,10 +33,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; /** * 文件上传 服务层实现 @@ -44,7 +42,7 @@ import java.util.Map; */ @RequiredArgsConstructor @Service -public class SysOssServiceImpl implements ISysOssService { +public class SysOssServiceImpl implements ISysOssService, OssService { private final SysOssMapper baseMapper; @@ -69,6 +67,18 @@ public class SysOssServiceImpl implements ISysOssService { return list; } + @Override + public String selectUrlByIds(String ossIds) { + List list = new ArrayList<>(); + for (Long id : Arrays.stream(ossIds.split(",")).map(Long::parseLong).toList()) { + SysOssVo vo = SpringUtils.getAopProxy(this).getById(id); + if (ObjectUtil.isNotNull(vo)) { + list.add(this.matchingUrl(vo).getUrl()); + } + } + return String.join(",", list); + } + private LambdaQueryWrapper buildQueryWrapper(SysOssBo bo) { Map params = bo.getParams(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index 26618907..9739806d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -9,8 +9,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.common.core.constant.CacheNames; import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.exception.ServiceException; +import com.ruoyi.common.core.service.UserService; import com.ruoyi.common.core.utils.StreamUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.mybatis.core.page.PageQuery; @@ -22,6 +24,7 @@ import com.ruoyi.system.mapper.*; import com.ruoyi.system.service.ISysUserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -36,7 +39,7 @@ import java.util.Map; @Slf4j @RequiredArgsConstructor @Service -public class SysUserServiceImpl implements ISysUserService { +public class SysUserServiceImpl implements ISysUserService, UserService { private final SysUserMapper baseMapper; private final SysDeptMapper deptMapper; @@ -474,4 +477,11 @@ public class SysUserServiceImpl implements ISysUserService { return baseMapper.deleteBatchIds(ids); } + @Cacheable(cacheNames = CacheNames.SYS_USER_NAME, key = "#userId") + @Override + public String selectUserNameById(Long userId) { + SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper() + .select(SysUser::getUserName).eq(SysUser::getUserId, userId)); + return ObjectUtil.isNull(sysUser) ? null : sysUser.getUserName(); + } }