feat(file): 完善文件管理功能,增加图片管理和权限控制
- 添加管理员权限验证,删除按钮仅对管理员显示 - 实现文件编辑权限控制,仅创建者或管理员可编辑 - 新增多图上传功能,支持文件和图片两种上传模式 - 实现图片预览轮播功能,支持缩略图导航和计数显示 - 添加文件替换功能,支持编辑模式下替换主文件 - 优化图片管理界面,支持添加、删除和替换操作 - 重构上传组件,使用OSS直传替代原有拖拽上传 - 新增图片关联API接口,支持文件与多张图片关联 - 实现批量图片上传处理,按顺序串行上传避免冲突 - 优化表单重置逻辑,清空临时文件和图片数据 - 添加文件类型自动识别和分类展示功能 - 修复可见用户加载异常导致的重复ID问题 - 优化错误处理机制,提升用户体验和系统稳定性
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package com.klp.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* 文件图片关联对象 sys_file_image
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_file_image")
|
||||
public class SysFileImage {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 图片ID
|
||||
*/
|
||||
@TableId(value = "image_id")
|
||||
private Long imageId;
|
||||
/**
|
||||
* 主记录ID 关联sys_file.file_id
|
||||
*/
|
||||
private Long fileId;
|
||||
/**
|
||||
* 图片原始名称
|
||||
*/
|
||||
private String imageName;
|
||||
/**
|
||||
* 图片存储路径/对象存储地址
|
||||
*/
|
||||
private String imagePath;
|
||||
/**
|
||||
* 图片大小(字节)
|
||||
*/
|
||||
private Long imageSize;
|
||||
/**
|
||||
* 后缀 jpg/png
|
||||
*/
|
||||
private String suffix;
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private Integer sortOrder;
|
||||
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.klp.system.domain.bo;
|
||||
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import com.klp.system.domain.bo.SysFileImageBo;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 文件主信息业务对象 sys_file
|
||||
@@ -72,4 +75,9 @@ public class SysFileBo extends BaseEntity {
|
||||
*/
|
||||
private Long viewCount;
|
||||
|
||||
/**
|
||||
* 图片列表(多图模式)
|
||||
*/
|
||||
private List<SysFileImageBo> imageList;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.klp.system.domain.bo;
|
||||
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
|
||||
/**
|
||||
* 文件图片关联业务对象 sys_file_image
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysFileImageBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 图片ID
|
||||
*/
|
||||
private Long imageId;
|
||||
|
||||
/**
|
||||
* 主记录ID 关联sys_file.file_id
|
||||
*/
|
||||
private Long fileId;
|
||||
|
||||
/**
|
||||
* 图片原始名称
|
||||
*/
|
||||
private String imageName;
|
||||
|
||||
/**
|
||||
* 图片存储路径/对象存储地址
|
||||
*/
|
||||
private String imagePath;
|
||||
|
||||
/**
|
||||
* 图片大小(字节)
|
||||
*/
|
||||
private Long imageSize;
|
||||
|
||||
/**
|
||||
* 后缀 jpg/png
|
||||
*/
|
||||
private String suffix;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private Integer sortOrder;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.klp.system.domain.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* 文件图片关联视图对象 sys_file_image
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class SysFileImageVo {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 图片ID
|
||||
*/
|
||||
@ExcelProperty(value = "图片ID")
|
||||
private Long imageId;
|
||||
|
||||
/**
|
||||
* 主记录ID 关联sys_file.file_id
|
||||
*/
|
||||
@ExcelProperty(value = "主记录ID")
|
||||
private Long fileId;
|
||||
|
||||
/**
|
||||
* 图片原始名称
|
||||
*/
|
||||
@ExcelProperty(value = "图片原始名称")
|
||||
private String imageName;
|
||||
|
||||
/**
|
||||
* 图片存储路径/对象存储地址
|
||||
*/
|
||||
@ExcelProperty(value = "图片存储路径")
|
||||
private String imagePath;
|
||||
|
||||
/**
|
||||
* 图片大小(字节)
|
||||
*/
|
||||
@ExcelProperty(value = "图片大小")
|
||||
private Long imageSize;
|
||||
|
||||
/**
|
||||
* 后缀 jpg/png
|
||||
*/
|
||||
@ExcelProperty(value = "后缀")
|
||||
private String suffix;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
@ExcelProperty(value = "排序号")
|
||||
private Integer sortOrder;
|
||||
|
||||
}
|
||||
@@ -5,8 +5,11 @@ import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.klp.common.annotation.ExcelDictFormat;
|
||||
import com.klp.common.convert.ExcelDictConvert;
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import com.klp.system.domain.vo.SysFileImageVo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 文件主信息视图对象 sys_file
|
||||
@@ -92,4 +95,9 @@ public class SysFileVo extends BaseEntity {
|
||||
@ExcelProperty(value = "创建者昵称")
|
||||
private String createByName;
|
||||
|
||||
/**
|
||||
* 图片列表(多图模式)
|
||||
*/
|
||||
private List<SysFileImageVo> imageList;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.klp.system.mapper;
|
||||
|
||||
import com.klp.system.domain.SysFileImage;
|
||||
import com.klp.system.domain.vo.SysFileImageVo;
|
||||
import com.klp.common.core.mapper.BaseMapperPlus;
|
||||
|
||||
/**
|
||||
* 文件图片关联Mapper接口
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
public interface SysFileImageMapper extends BaseMapperPlus<SysFileImageMapper, SysFileImage, SysFileImageVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.klp.system.service;
|
||||
|
||||
import com.klp.system.domain.SysFileImage;
|
||||
import com.klp.system.domain.vo.SysFileImageVo;
|
||||
import com.klp.system.domain.bo.SysFileImageBo;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件图片关联Service接口
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
public interface ISysFileImageService {
|
||||
|
||||
/**
|
||||
* 查询文件图片关联
|
||||
*/
|
||||
SysFileImageVo queryById(Long imageId);
|
||||
|
||||
/**
|
||||
* 查询文件图片关联列表
|
||||
*/
|
||||
TableDataInfo<SysFileImageVo> queryPageList(SysFileImageBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询文件图片关联列表
|
||||
*/
|
||||
List<SysFileImageVo> queryList(SysFileImageBo bo);
|
||||
|
||||
/**
|
||||
* 新增文件图片关联
|
||||
*/
|
||||
Boolean insertByBo(SysFileImageBo bo);
|
||||
|
||||
/**
|
||||
* 修改文件图片关联
|
||||
*/
|
||||
Boolean updateByBo(SysFileImageBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除文件图片关联信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 根据文件ID查询图片列表
|
||||
*/
|
||||
List<SysFileImageVo> queryListByFileId(Long fileId);
|
||||
|
||||
/**
|
||||
* 批量保存图片
|
||||
*/
|
||||
void saveImageList(Long fileId, List<SysFileImageBo> imageList);
|
||||
|
||||
/**
|
||||
* 根据文件ID删除所有图片
|
||||
*/
|
||||
void deleteByFileId(Long fileId);
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package com.klp.system.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.klp.system.domain.bo.SysFileImageBo;
|
||||
import com.klp.system.domain.vo.SysFileImageVo;
|
||||
import com.klp.system.domain.SysFileImage;
|
||||
import com.klp.system.mapper.SysFileImageMapper;
|
||||
import com.klp.system.service.ISysFileImageService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 文件图片关联Service业务层处理
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysFileImageServiceImpl implements ISysFileImageService {
|
||||
|
||||
private final SysFileImageMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询文件图片关联
|
||||
*/
|
||||
@Override
|
||||
public SysFileImageVo queryById(Long imageId){
|
||||
return baseMapper.selectVoById(imageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文件图片关联列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<SysFileImageVo> queryPageList(SysFileImageBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<SysFileImage> lqw = buildQueryWrapper(bo);
|
||||
Page<SysFileImageVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文件图片关联列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysFileImageVo> queryList(SysFileImageBo bo) {
|
||||
LambdaQueryWrapper<SysFileImage> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<SysFileImage> buildQueryWrapper(SysFileImageBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<SysFileImage> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(bo.getFileId() != null, SysFileImage::getFileId, bo.getFileId());
|
||||
lqw.orderByAsc(SysFileImage::getSortOrder);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysFileImageVo> queryListByFileId(Long fileId) {
|
||||
LambdaQueryWrapper<SysFileImage> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(SysFileImage::getFileId, fileId);
|
||||
lqw.orderByAsc(SysFileImage::getSortOrder);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量保存图片(先删后插)
|
||||
*/
|
||||
@Override
|
||||
public void saveImageList(Long fileId, List<SysFileImageBo> imageList) {
|
||||
if (fileId == null) return;
|
||||
// 先删除原有图片
|
||||
deleteByFileId(fileId);
|
||||
// 批量插入
|
||||
if (imageList != null && !imageList.isEmpty()) {
|
||||
for (int i = 0; i < imageList.size(); i++) {
|
||||
SysFileImageBo bo = imageList.get(i);
|
||||
SysFileImage entity = BeanUtil.toBean(bo, SysFileImage.class);
|
||||
entity.setFileId(fileId);
|
||||
entity.setSortOrder(i);
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByFileId(Long fileId) {
|
||||
baseMapper.delete(Wrappers.<SysFileImage>lambdaQuery()
|
||||
.eq(SysFileImage::getFileId, fileId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增文件图片关联
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(SysFileImageBo bo) {
|
||||
SysFileImage add = BeanUtil.toBean(bo, SysFileImage.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setImageId(add.getImageId());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文件图片关联
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(SysFileImageBo bo) {
|
||||
SysFileImage update = BeanUtil.toBean(bo, SysFileImage.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(SysFileImage entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除文件图片关联
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,11 @@ import org.springframework.stereotype.Service;
|
||||
import com.klp.system.domain.bo.SysFileBo;
|
||||
import com.klp.system.domain.vo.SysFileVo;
|
||||
import com.klp.system.domain.SysFile;
|
||||
import com.klp.system.domain.SysFileImage;
|
||||
import com.klp.system.domain.SysFileVisibleUser;
|
||||
import com.klp.system.domain.bo.SysFileImageBo;
|
||||
import com.klp.system.domain.vo.SysFileImageVo;
|
||||
import com.klp.system.mapper.SysFileImageMapper;
|
||||
import com.klp.system.mapper.SysFileMapper;
|
||||
import com.klp.system.mapper.SysFileVisibleUserMapper;
|
||||
import com.klp.system.mapper.SysUserMapper;
|
||||
@@ -39,6 +43,7 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
|
||||
private final SysFileMapper baseMapper;
|
||||
private final SysFileVisibleUserMapper visibleUserMapper;
|
||||
private final SysFileImageMapper fileImageMapper;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
/**
|
||||
@@ -46,7 +51,16 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
*/
|
||||
@Override
|
||||
public SysFileVo queryById(Long fileId){
|
||||
return baseMapper.selectVoById(fileId);
|
||||
SysFileVo vo = baseMapper.selectVoById(fileId);
|
||||
if (vo != null) {
|
||||
// 加载图片列表
|
||||
List<SysFileImageVo> imageList = fileImageMapper.selectVoList(
|
||||
Wrappers.<SysFileImage>lambdaQuery()
|
||||
.eq(SysFileImage::getFileId, fileId)
|
||||
.orderByAsc(SysFileImage::getSortOrder));
|
||||
vo.setImageList(imageList);
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,10 +110,25 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setFileId(add.getFileId());
|
||||
// 保存图片列表
|
||||
saveImageList(add.getFileId(), bo.getImageList());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
private void saveImageList(Long fileId, List<SysFileImageBo> imageList) {
|
||||
if (fileId == null || imageList == null || imageList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < imageList.size(); i++) {
|
||||
SysFileImageBo imageBo = imageList.get(i);
|
||||
SysFileImage entity = BeanUtil.toBean(imageBo, SysFileImage.class);
|
||||
entity.setFileId(fileId);
|
||||
entity.setSortOrder(i);
|
||||
fileImageMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文件主信息
|
||||
*/
|
||||
@@ -107,7 +136,14 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
public Boolean updateByBo(SysFileBo bo) {
|
||||
SysFile update = BeanUtil.toBean(bo, SysFile.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
boolean flag = baseMapper.updateById(update) > 0;
|
||||
if (flag && bo.getImageList() != null) {
|
||||
// 先删后插图片列表
|
||||
fileImageMapper.delete(Wrappers.<SysFileImage>lambdaQuery()
|
||||
.eq(SysFileImage::getFileId, bo.getFileId()));
|
||||
saveImageList(bo.getFileId(), bo.getImageList());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,6 +223,11 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
if (ids != null && !ids.isEmpty()) {
|
||||
// 删除关联的图片
|
||||
fileImageMapper.delete(Wrappers.<SysFileImage>lambdaQuery()
|
||||
.in(SysFileImage::getFileId, ids));
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.klp.system.mapper.SysFileImageMapper">
|
||||
|
||||
<resultMap type="com.klp.system.domain.SysFileImage" id="SysFileImageResult">
|
||||
<result property="imageId" column="image_id"/>
|
||||
<result property="fileId" column="file_id"/>
|
||||
<result property="imageName" column="image_name"/>
|
||||
<result property="imagePath" column="image_path"/>
|
||||
<result property="imageSize" column="image_size"/>
|
||||
<result property="suffix" column="suffix"/>
|
||||
<result property="sortOrder" column="sort_order"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user