feat(file): 优化文件管理页面显示用户昵称
- 将文件列表中的上传人字段从用户名改为用户昵称显示 - 在文件详情页面同时支持显示昵称或用户名作为上传人信息 - 扩展表格列宽度并添加溢出提示功能提升用户体验 - 实现批量查询用户昵称的功能提高数据加载性能 - 新增 createByName 字段用于存储用户昵称信息 - 优化文件服务层代码结构添加用户映射器依赖
This commit is contained in:
@@ -86,4 +86,10 @@ public class SysFileVo extends BaseEntity {
|
||||
@ExcelProperty(value = "浏览次数")
|
||||
private Long viewCount;
|
||||
|
||||
/**
|
||||
* 创建者昵称
|
||||
*/
|
||||
@ExcelProperty(value = "创建者昵称")
|
||||
private String createByName;
|
||||
|
||||
}
|
||||
|
||||
@@ -17,12 +17,15 @@ import com.klp.system.domain.SysFile;
|
||||
import com.klp.system.domain.SysFileVisibleUser;
|
||||
import com.klp.system.mapper.SysFileMapper;
|
||||
import com.klp.system.mapper.SysFileVisibleUserMapper;
|
||||
import com.klp.system.mapper.SysUserMapper;
|
||||
import com.klp.system.service.ISysFileService;
|
||||
import com.klp.common.core.domain.entity.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 文件主信息Service业务层处理
|
||||
@@ -36,6 +39,7 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
|
||||
private final SysFileMapper baseMapper;
|
||||
private final SysFileVisibleUserMapper visibleUserMapper;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 查询文件主信息
|
||||
@@ -52,6 +56,7 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
public TableDataInfo<SysFileVo> queryPageList(SysFileBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<SysFile> lqw = buildQueryWrapper(bo);
|
||||
Page<SysFileVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
fillCreateByName(result.getRecords());
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@@ -61,7 +66,9 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
@Override
|
||||
public List<SysFileVo> queryList(SysFileBo bo) {
|
||||
LambdaQueryWrapper<SysFile> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
List<SysFileVo> list = baseMapper.selectVoList(lqw);
|
||||
fillCreateByName(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<SysFile> buildQueryWrapper(SysFileBo bo) {
|
||||
@@ -122,6 +129,7 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
LambdaQueryWrapper<SysFile> lqw = buildQueryWrapper(bo);
|
||||
lqw.in(SysFile::getFileId, fileIds);
|
||||
Page<SysFileVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
fillCreateByName(result.getRecords());
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@@ -135,6 +143,35 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
.eq(SysFile::getFileId, fileId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 createBy(登录名)批量填充 createByName(用户昵称)
|
||||
*/
|
||||
private void fillCreateByName(List<SysFileVo> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 收集所有不重复的 createBy
|
||||
List<String> userNames = list.stream()
|
||||
.map(SysFileVo::getCreateBy)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (userNames.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 批量查询用户
|
||||
List<SysUser> users = userMapper.selectUserList(
|
||||
Wrappers.<SysUser>lambdaQuery().in(SysUser::getUserName, userNames));
|
||||
Map<String, String> nickNameMap = users.stream()
|
||||
.collect(Collectors.toMap(SysUser::getUserName, SysUser::getNickName, (a, b) -> a));
|
||||
// 赋值
|
||||
for (SysFileVo vo : list) {
|
||||
if (StringUtils.isNotBlank(vo.getCreateBy())) {
|
||||
vo.setCreateByName(nickNameMap.get(vo.getCreateBy()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user