mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-10-14 14:10:24 +00:00
update 优化 增加 SysOssExt 附件扩展字段对象
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
package org.dromara.resource.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;
|
||||||
|
|
||||||
|
}
|
@@ -14,6 +14,7 @@ import org.dromara.common.core.utils.MapstructUtils;
|
|||||||
import org.dromara.common.core.utils.SpringUtils;
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.core.utils.file.FileUtils;
|
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.PageQuery;
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
import org.dromara.common.oss.core.OssClient;
|
import org.dromara.common.oss.core.OssClient;
|
||||||
@@ -21,6 +22,7 @@ import org.dromara.common.oss.entity.UploadResult;
|
|||||||
import org.dromara.common.oss.enums.AccessPolicyType;
|
import org.dromara.common.oss.enums.AccessPolicyType;
|
||||||
import org.dromara.common.oss.factory.OssFactory;
|
import org.dromara.common.oss.factory.OssFactory;
|
||||||
import org.dromara.resource.domain.SysOss;
|
import org.dromara.resource.domain.SysOss;
|
||||||
|
import org.dromara.resource.domain.SysOssExt;
|
||||||
import org.dromara.resource.domain.bo.SysOssBo;
|
import org.dromara.resource.domain.bo.SysOssBo;
|
||||||
import org.dromara.resource.domain.vo.SysOssVo;
|
import org.dromara.resource.domain.vo.SysOssVo;
|
||||||
import org.dromara.resource.mapper.SysOssMapper;
|
import org.dromara.resource.mapper.SysOssMapper;
|
||||||
@@ -177,8 +179,11 @@ public class SysOssServiceImpl implements ISysOssService {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ServiceException(e.getMessage());
|
throw new ServiceException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
SysOssExt ext1 = new SysOssExt();
|
||||||
|
ext1.setFileSize(file.getSize());
|
||||||
|
ext1.setContentType(file.getContentType());
|
||||||
// 保存文件信息
|
// 保存文件信息
|
||||||
return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult);
|
return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult, ext1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -193,17 +198,20 @@ public class SysOssServiceImpl implements ISysOssService {
|
|||||||
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
|
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
|
||||||
OssClient storage = OssFactory.instance();
|
OssClient storage = OssFactory.instance();
|
||||||
UploadResult uploadResult = storage.uploadSuffix(file, suffix);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
SysOss oss = new SysOss();
|
||||||
oss.setUrl(uploadResult.getUrl());
|
oss.setUrl(uploadResult.getUrl());
|
||||||
oss.setFileSuffix(suffix);
|
oss.setFileSuffix(suffix);
|
||||||
oss.setFileName(uploadResult.getFilename());
|
oss.setFileName(uploadResult.getFilename());
|
||||||
oss.setOriginalName(originalfileName);
|
oss.setOriginalName(originalfileName);
|
||||||
oss.setService(configKey);
|
oss.setService(configKey);
|
||||||
|
oss.setExt1(JsonUtils.toJsonString(ext1));
|
||||||
baseMapper.insert(oss);
|
baseMapper.insert(oss);
|
||||||
SysOssVo sysOssVo = MapstructUtils.convert(oss, SysOssVo.class);
|
SysOssVo sysOssVo = MapstructUtils.convert(oss, SysOssVo.class);
|
||||||
return this.matchingUrl(sysOssVo);
|
return this.matchingUrl(sysOssVo);
|
||||||
|
Reference in New Issue
Block a user