mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-03 11:05:58 +00:00
add 新增 通用翻译模块 ruoyi-common-translation 实现(部门名、字典、oss、用户名)
This commit is contained in:
@@ -13,22 +13,31 @@ import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysOssBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* ossId
|
||||
*/
|
||||
private Long ossId;
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
private String fileName;
|
||||
|
||||
/**
|
||||
* 原名
|
||||
*/
|
||||
private String originalName;
|
||||
|
||||
/**
|
||||
* 文件后缀名
|
||||
*/
|
||||
private String fileSuffix;
|
||||
|
||||
/**
|
||||
* URL地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 服务商
|
||||
*/
|
||||
|
@@ -7,11 +7,11 @@ import com.ruoyi.common.oss.entity.UploadResult;
|
||||
import com.ruoyi.common.oss.factory.OssFactory;
|
||||
import com.ruoyi.resource.api.RemoteFileService;
|
||||
import com.ruoyi.resource.api.domain.SysFile;
|
||||
import com.ruoyi.resource.domain.SysOss;
|
||||
import com.ruoyi.resource.mapper.SysOssMapper;
|
||||
import com.ruoyi.resource.domain.bo.SysOssBo;
|
||||
import com.ruoyi.resource.service.ISysOssService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -22,11 +22,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@DubboService
|
||||
public class RemoteFileServiceImpl implements RemoteFileService {
|
||||
|
||||
@Autowired
|
||||
private SysOssMapper sysOssMapper;
|
||||
private final ISysOssService sysOssService;
|
||||
|
||||
/**
|
||||
* 文件上传请求
|
||||
@@ -39,13 +39,13 @@ public class RemoteFileServiceImpl implements RemoteFileService {
|
||||
OssClient storage = OssFactory.instance();
|
||||
UploadResult uploadResult = storage.uploadSuffix(file, suffix, contentType);
|
||||
// 保存文件信息
|
||||
SysOss oss = new SysOss();
|
||||
SysOssBo oss = new SysOssBo();
|
||||
oss.setUrl(uploadResult.getUrl());
|
||||
oss.setFileSuffix(suffix);
|
||||
oss.setFileName(uploadResult.getFilename());
|
||||
oss.setOriginalName(originalFilename);
|
||||
oss.setService(storage.getConfigKey());
|
||||
sysOssMapper.insert(oss);
|
||||
sysOssService.insertByBo(oss);
|
||||
SysFile sysFile = new SysFile();
|
||||
sysFile.setOssId(oss.getOssId());
|
||||
sysFile.setName(uploadResult.getFilename());
|
||||
@@ -57,4 +57,15 @@ public class RemoteFileServiceImpl implements RemoteFileService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ossId查询对应的url
|
||||
*
|
||||
* @param ossIds ossId串逗号分隔
|
||||
* @return url串逗号分隔
|
||||
*/
|
||||
@Override
|
||||
public String selectUrlByIds(String ossIds) {
|
||||
return sysOssService.selectUrlByIds(ossIds);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,12 +22,15 @@ public interface ISysOssService {
|
||||
|
||||
List<SysOssVo> listByIds(Collection<Long> ossIds);
|
||||
|
||||
String selectUrlByIds(String ossIds);
|
||||
|
||||
SysOssVo getById(Long ossId);
|
||||
|
||||
SysOssVo upload(MultipartFile file);
|
||||
|
||||
Boolean insertByBo(SysOssBo bo);
|
||||
|
||||
void download(Long ossId, HttpServletResponse response) throws IOException;
|
||||
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.resource.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -31,10 +32,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
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.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -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).collect(Collectors.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();
|
||||
@@ -131,6 +141,16 @@ public class SysOssServiceImpl implements ISysOssService {
|
||||
return this.matchingUrl(sysOssVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean insertByBo(SysOssBo bo) {
|
||||
SysOss oss = BeanUtil.toBean(bo, SysOss.class);
|
||||
boolean flag = baseMapper.insert(oss) > 0;
|
||||
if (flag) {
|
||||
bo.setOssId(oss.getOssId());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
|
@@ -0,0 +1,25 @@
|
||||
package com.ruoyi.system.dubbo;
|
||||
|
||||
import com.ruoyi.system.api.RemoteDeptService;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 部门服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
@DubboService
|
||||
public class RemoteDeptServiceImpl implements RemoteDeptService {
|
||||
|
||||
private final ISysDeptService sysDeptService;
|
||||
|
||||
@Override
|
||||
public String selectDeptNameByIds(String deptIds) {
|
||||
return sysDeptService.selectDeptNameByIds(deptIds);
|
||||
}
|
||||
}
|
@@ -10,7 +10,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作日志记录
|
||||
* 字典服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
@@ -23,7 +23,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作日志记录
|
||||
* 用户服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@@ -98,6 +98,11 @@ public class RemoteUserServiceImpl implements RemoteUserService {
|
||||
return userService.registerUser(sysUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String selectUserNameById(Long userId) {
|
||||
return userService.selectUserNameById(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建登录用户
|
||||
*/
|
||||
|
@@ -51,6 +51,14 @@ public interface ISysDeptService {
|
||||
*/
|
||||
SysDept selectDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 通过部门ID查询部门名称
|
||||
*
|
||||
* @param deptIds 部门ID串逗号分隔
|
||||
* @return 部门名称串逗号分隔
|
||||
*/
|
||||
String selectDeptNameByIds(String deptIds);
|
||||
|
||||
/**
|
||||
* 根据ID查询所有子部门(正常状态)
|
||||
*
|
||||
|
@@ -206,4 +206,12 @@ public interface ISysUserService {
|
||||
*/
|
||||
int deleteUserByIds(Long[] userIds);
|
||||
|
||||
/**
|
||||
* 通过用户ID查询用户账户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户账户
|
||||
*/
|
||||
String selectUserNameById(Long userId);
|
||||
|
||||
}
|
||||
|
@@ -6,11 +6,14 @@ import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
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.utils.SpringUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.TreeBuildUtils;
|
||||
import com.ruoyi.common.mybatis.helper.DataBaseHelper;
|
||||
import com.ruoyi.common.redis.utils.CacheUtils;
|
||||
import com.ruoyi.common.satoken.utils.LoginHelper;
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
import com.ruoyi.system.api.domain.SysRole;
|
||||
@@ -20,11 +23,14 @@ import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 部门管理 服务实现
|
||||
@@ -106,6 +112,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
||||
* @param deptId 部门ID
|
||||
* @return 部门信息
|
||||
*/
|
||||
@Cacheable(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
|
||||
@Override
|
||||
public SysDept selectDeptById(Long deptId) {
|
||||
SysDept dept = baseMapper.selectById(deptId);
|
||||
@@ -115,6 +122,24 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
||||
return dept;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过部门ID查询部门名称
|
||||
*
|
||||
* @param deptIds 部门ID串逗号分隔
|
||||
* @return 部门名称串逗号分隔
|
||||
*/
|
||||
@Override
|
||||
public String selectDeptNameByIds(String deptIds) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Long id : Arrays.stream(deptIds.split(",")).map(Long::parseLong).collect(Collectors.toList())) {
|
||||
SysDept dept = SpringUtils.getAopProxy(this).selectDeptById(id);
|
||||
if (ObjectUtil.isNotNull(dept)) {
|
||||
list.add(dept.getDeptName());
|
||||
}
|
||||
}
|
||||
return String.join(",", list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询所有子部门(正常状态)
|
||||
*
|
||||
@@ -210,6 +235,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#dept.deptId")
|
||||
@Override
|
||||
public int updateDept(SysDept dept) {
|
||||
SysDept newParentDept = baseMapper.selectById(dept.getParentId());
|
||||
@@ -260,7 +286,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
||||
list.add(dept);
|
||||
}
|
||||
if (list.size() > 0) {
|
||||
baseMapper.updateBatchById(list);
|
||||
if (baseMapper.updateBatchById(list)) {
|
||||
list.forEach(dept -> CacheUtils.evict(CacheNames.SYS_DEPT, dept.getDeptId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,6 +298,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
|
||||
@Override
|
||||
public int deleteDeptById(Long deptId) {
|
||||
return baseMapper.deleteById(deptId);
|
||||
|
@@ -9,6 +9,7 @@ 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.utils.StreamUtils;
|
||||
@@ -27,6 +28,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;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -486,4 +488,12 @@ 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user