mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	!711 update 优化附件扩展字段对象(存储在 SysOss.ext1 的 JSON 字符串中)
* update 优化文件上传附件扩展字段对象 * update 优化保存文件的大小,方便前端进行分片下载
This commit is contained in:
		@@ -0,0 +1,75 @@
 | 
			
		||||
package org.dromara.system.domain;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 附件扩展字段对象(存储在 SysOss.ext1 的 JSON 字符串中)
 | 
			
		||||
 *
 | 
			
		||||
 * @author AprilWind
 | 
			
		||||
 */
 | 
			
		||||
@Data
 | 
			
		||||
public class SysOssExt implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 所属业务类型(如 avatar、report、contract)
 | 
			
		||||
     */
 | 
			
		||||
    private String bizType;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 文件大小(单位:字节)
 | 
			
		||||
     */
 | 
			
		||||
    private Long fileSize;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 文件类型(MIME类型,如 image/png)
 | 
			
		||||
     */
 | 
			
		||||
    private String contentType;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 来源标识(如 userUpload、systemImport)
 | 
			
		||||
     */
 | 
			
		||||
    private String source;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 上传 IP 地址,便于审计和追踪
 | 
			
		||||
     */
 | 
			
		||||
    private String uploadIp;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 附件说明或备注
 | 
			
		||||
     */
 | 
			
		||||
    private String remark;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 附件标签,如 ["图片", "证件"]
 | 
			
		||||
     */
 | 
			
		||||
    private List<String> tags;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 业务绑定ID(如某业务记录ID)
 | 
			
		||||
     */
 | 
			
		||||
    private String refId;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 绑定业务类型
 | 
			
		||||
     */
 | 
			
		||||
    private String refType;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 是否为临时文件,用于区分正式或待清理
 | 
			
		||||
     */
 | 
			
		||||
    private Boolean isTemp;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 文件MD5值(可用于去重或校验)
 | 
			
		||||
     */
 | 
			
		||||
    private String md5;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -17,6 +17,7 @@ import org.dromara.common.core.utils.SpringUtils;
 | 
			
		||||
import org.dromara.common.core.utils.StreamUtils;
 | 
			
		||||
import org.dromara.common.core.utils.StringUtils;
 | 
			
		||||
import org.dromara.common.core.utils.file.FileUtils;
 | 
			
		||||
import org.dromara.common.json.utils.JsonUtils;
 | 
			
		||||
import org.dromara.common.mybatis.core.page.PageQuery;
 | 
			
		||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
 | 
			
		||||
import org.dromara.common.oss.core.OssClient;
 | 
			
		||||
@@ -24,6 +25,7 @@ import org.dromara.common.oss.entity.UploadResult;
 | 
			
		||||
import org.dromara.common.oss.enums.AccessPolicyType;
 | 
			
		||||
import org.dromara.common.oss.factory.OssFactory;
 | 
			
		||||
import org.dromara.system.domain.SysOss;
 | 
			
		||||
import org.dromara.system.domain.SysOssExt;
 | 
			
		||||
import org.dromara.system.domain.bo.SysOssBo;
 | 
			
		||||
import org.dromara.system.domain.vo.SysOssVo;
 | 
			
		||||
import org.dromara.system.mapper.SysOssMapper;
 | 
			
		||||
@@ -199,8 +201,10 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            throw new ServiceException(e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
        SysOssExt ext1 = new SysOssExt();
 | 
			
		||||
        ext1.setFileSize(file.getSize());
 | 
			
		||||
        // 保存文件信息
 | 
			
		||||
        return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult);
 | 
			
		||||
        return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult, ext1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -215,18 +219,21 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
 | 
			
		||||
        String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
 | 
			
		||||
        OssClient storage = OssFactory.instance();
 | 
			
		||||
        UploadResult uploadResult = storage.uploadSuffix(file, suffix);
 | 
			
		||||
        SysOssExt ext1 = new SysOssExt();
 | 
			
		||||
        ext1.setFileSize(file.length());
 | 
			
		||||
        // 保存文件信息
 | 
			
		||||
        return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult);
 | 
			
		||||
        return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult, ext1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @NotNull
 | 
			
		||||
    private SysOssVo buildResultEntity(String originalfileName, String suffix, String configKey, UploadResult uploadResult) {
 | 
			
		||||
    private SysOssVo buildResultEntity(String originalfileName, String suffix, String configKey, UploadResult uploadResult, SysOssExt ext1) {
 | 
			
		||||
        SysOss oss = new SysOss();
 | 
			
		||||
        oss.setUrl(uploadResult.getUrl());
 | 
			
		||||
        oss.setFileSuffix(suffix);
 | 
			
		||||
        oss.setFileName(uploadResult.getFilename());
 | 
			
		||||
        oss.setOriginalName(originalfileName);
 | 
			
		||||
        oss.setService(configKey);
 | 
			
		||||
        oss.setExt1(JsonUtils.toJsonString(ext1));
 | 
			
		||||
        baseMapper.insert(oss);
 | 
			
		||||
        SysOssVo sysOssVo = MapstructUtils.convert(oss, SysOssVo.class);
 | 
			
		||||
        return this.matchingUrl(sysOssVo);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user