add 新增 转换模块 用户名 与 ossUrl 转换
This commit is contained in:
parent
949eeb213d
commit
fbdae78675
@ -30,6 +30,11 @@ public interface CacheNames {
|
||||
*/
|
||||
String SYS_DICT = "sys_dict";
|
||||
|
||||
/**
|
||||
* 用户账户
|
||||
*/
|
||||
String SYS_USER_NAME = "sys_user_name#30d";
|
||||
|
||||
/**
|
||||
* OSS内容
|
||||
*/
|
||||
|
@ -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);
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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<String> 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<SysOss> buildQueryWrapper(SysOssBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<SysOss> lqw = Wrappers.lambdaQuery();
|
||||
|
@ -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<SysUser>()
|
||||
.select(SysUser::getUserName).eq(SysUser::getUserId, userId));
|
||||
return ObjectUtil.isNull(sysUser) ? null : sysUser.getUserName();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user