add 新增 转换模块 用户名 与 ossUrl 转换

feature/model
疯狂的狮子li 2 years ago
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 {
/**
* ossIdurl
*
* @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…
Cancel
Save