初始代码
This commit is contained in:
131
yunzhupaas-boot-common/yunzhupaas-common-file/pom.xml
Normal file
131
yunzhupaas-boot-common/yunzhupaas-common-file/pom.xml
Normal file
@@ -0,0 +1,131 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yunzhupaas-boot-common</artifactId>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<version>5.2.0-RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>yunzhupaas-common-file</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-common-database</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-common-auth</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk18on</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- yunzhupaas-file-core 必须要引入 -->
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-file-core-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 华为云 OBS 不使用的情况下可以不引入 -->
|
||||
<!--<dependency>
|
||||
<groupId>com.huaweicloud</groupId>
|
||||
<artifactId>esdk-obs-java</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<!-- 阿里云 OSS 不使用的情况下可以不引入 -->
|
||||
<!--<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>-->
|
||||
|
||||
<!-- 七牛云 Kodo 不使用的情况下可以不引入 -->
|
||||
<!--<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<!-- 腾讯云 COS 不使用的情况下可以不引入 -->
|
||||
<!--<dependency>
|
||||
<groupId>com.qcloud</groupId>
|
||||
<artifactId>cos_api</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>-->
|
||||
|
||||
<!-- 百度云 BOS 不使用的情况下可以不引入 -->
|
||||
<!--<dependency>
|
||||
<groupId>com.baidubce</groupId>
|
||||
<artifactId>bce-java-sdk</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>-->
|
||||
<!--<dependency>
|
||||
<groupId>org.apache.hbase</groupId>
|
||||
<artifactId>hbase-client</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
|
||||
<!-- 又拍云 USS 不使用的情况下可以不引入 -->
|
||||
<!--<dependency>
|
||||
<groupId>com.upyun</groupId>
|
||||
<artifactId>java-sdk</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<!-- MinIO 不使用的情况下可以不引入 -->
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- AWS S3 不使用的情况下可以不引入 -->
|
||||
<!--<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<!-- FTP 不使用的情况下可以不引入 -->
|
||||
<!--<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<!-- SFTP 不使用的情况下可以不引入 -->
|
||||
<!--<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
<artifactId>jsch</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<!--糊涂工具类扩展,如果要使用 FTP、SFTP 则必须引入,否则不用引入-->
|
||||
<!--<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-extra</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<!-- WebDAV 不使用的情况下可以不引入 -->
|
||||
<!--<dependency>
|
||||
<groupId>com.github.lookfirst</groupId>
|
||||
<artifactId>sardine</artifactId>
|
||||
</dependency>-->
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.yunzhupaas.aspect;
|
||||
|
||||
import cn.xuyanwu.spring.file.storage.FileInfo;
|
||||
import cn.xuyanwu.spring.file.storage.UploadPretreatment;
|
||||
import cn.xuyanwu.spring.file.storage.aspect.*;
|
||||
import cn.xuyanwu.spring.file.storage.platform.FileStorage;
|
||||
import cn.xuyanwu.spring.file.storage.recorder.FileRecorder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 使用切面打印文件上传和删除的日志
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class LogFileStorageAspect implements FileStorageAspect {
|
||||
|
||||
/**
|
||||
* 上传,成功返回文件信息,失败返回 null
|
||||
*/
|
||||
@Override
|
||||
public FileInfo uploadAround(UploadAspectChain chain,FileInfo fileInfo,UploadPretreatment pre,FileStorage fileStorage,FileRecorder fileRecorder) {
|
||||
log.info("上传文件 before -> {}",fileInfo);
|
||||
fileInfo = chain.next(fileInfo,pre,fileStorage,fileRecorder);
|
||||
log.info("上传文件 after -> {}",fileInfo);
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件,成功返回 true
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteAround(DeleteAspectChain chain,FileInfo fileInfo,FileStorage fileStorage,FileRecorder fileRecorder) {
|
||||
log.info("删除文件 before -> {}",fileInfo);
|
||||
boolean res = chain.next(fileInfo,fileStorage,fileRecorder);
|
||||
log.info("删除文件 after -> {}",res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件是否存在
|
||||
*/
|
||||
@Override
|
||||
public boolean existsAround(ExistsAspectChain chain,FileInfo fileInfo,FileStorage fileStorage) {
|
||||
log.info("文件是否存在 before -> {}",fileInfo);
|
||||
boolean res = chain.next(fileInfo,fileStorage);
|
||||
log.info("文件是否存在 after -> {}",res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*/
|
||||
@Override
|
||||
public void downloadAround(DownloadAspectChain chain, FileInfo fileInfo, FileStorage fileStorage, Consumer<InputStream> consumer) {
|
||||
log.info("下载文件 before -> {}",fileInfo);
|
||||
chain.next(fileInfo,fileStorage,consumer);
|
||||
log.info("下载文件 after -> {}",fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载缩略图文件
|
||||
*/
|
||||
@Override
|
||||
public void downloadThAround(DownloadThAspectChain chain, FileInfo fileInfo, FileStorage fileStorage, Consumer<InputStream> consumer) {
|
||||
log.info("下载缩略图文件 before -> {}",fileInfo);
|
||||
chain.next(fileInfo,fileStorage,consumer);
|
||||
log.info("下载缩略图文件 after -> {}",fileInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.yunzhupaas.config;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 本地存储文件路径配置
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024-08-24
|
||||
*/
|
||||
@Component
|
||||
@Data
|
||||
public class LocalPathConfig {
|
||||
|
||||
/**
|
||||
* 数据库备份文件路径
|
||||
*/
|
||||
@Value("${config.DataBackupFilePath:}")
|
||||
private String dataBackupFilePath;
|
||||
/**
|
||||
* 临时文件存储路径
|
||||
*/
|
||||
@Value("${config.TemporaryFilePath:}")
|
||||
private String temporaryFilePath;
|
||||
/**
|
||||
* 系统文件存储路径
|
||||
*/
|
||||
@Value("${config.SystemFilePath:}")
|
||||
private String systemFilePath;
|
||||
/**
|
||||
* 文件模板存储路径
|
||||
*/
|
||||
@Value("${config.TemplateFilePath:}")
|
||||
private String templateFilePath;
|
||||
/**
|
||||
* 代码模板存储路径
|
||||
*/
|
||||
@Value("${config.TemplateCodePath:}")
|
||||
private String templateCodePath;
|
||||
/**
|
||||
* 邮件文件存储路径
|
||||
*/
|
||||
@Value("${config.EmailFilePath:}")
|
||||
private String emailFilePath;
|
||||
/**
|
||||
* 大屏图片存储目录
|
||||
*/
|
||||
@Value("${config.BiVisualPath:}")
|
||||
private String biVisualPath;
|
||||
/**
|
||||
* 文档管理存储路径
|
||||
*/
|
||||
@Value("${config.DocumentFilePath:}")
|
||||
private String documentFilePath;
|
||||
/**
|
||||
* 文件在线预览存储pdf
|
||||
*/
|
||||
@Value("${config.DocumentPreviewPath:}")
|
||||
private String documentPreviewPath;
|
||||
/**
|
||||
* 用户头像存储路径
|
||||
*/
|
||||
@Value("${config.UserAvatarFilePath:}")
|
||||
private String userAvatarFilePath;
|
||||
/**
|
||||
* IM聊天图片+语音存储路径
|
||||
*/
|
||||
@Value("${config.IMContentFilePath:}")
|
||||
private String imContentFilePath;
|
||||
/**
|
||||
* 微信公众号资源文件存储路径
|
||||
*/
|
||||
@Value("${config.MPMaterialFilePath:}")
|
||||
private String mpMaterialFilePath;
|
||||
/**
|
||||
* 微信公众号允许上传文件类型
|
||||
*/
|
||||
@Value("${config.MPUploadFileType:}")
|
||||
private String mpUploadFileType;
|
||||
/**
|
||||
* 微信允许上传文件类型
|
||||
*/
|
||||
@Value("${config.WeChatUploadFileType:}")
|
||||
private String weChatUploadFileType;
|
||||
/**
|
||||
* 允许上传文件类型
|
||||
*/
|
||||
@Value("${config.AllowUploadFileType:}")
|
||||
private String allowUploadFileType;
|
||||
/**
|
||||
* 允许图片类型
|
||||
*/
|
||||
@Value("${config.AllowUploadImageType:}")
|
||||
private String allowUploadImageType;
|
||||
/**
|
||||
* 后端文件目录
|
||||
*/
|
||||
@Value("${config.WebDirectoryPath:}")
|
||||
private String webDirectoryPath;
|
||||
/**
|
||||
* 前端附件文件目录
|
||||
*/
|
||||
@Value("${config.WebAnnexFilePath:}")
|
||||
private String webAnnexFilePath;
|
||||
/**
|
||||
* 允许预览类型
|
||||
*/
|
||||
@Value("${config.AllowPreviewFileType:}")
|
||||
private String allowPreviewFileType;
|
||||
/**
|
||||
* 预览方式
|
||||
*/
|
||||
@Value("${config.PreviewType:}")
|
||||
private String previewType;
|
||||
/**
|
||||
* kk服务地址
|
||||
*/
|
||||
@Value("${config.kkFileUrl:}")
|
||||
private String kkFileUrl;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.yunzhupaas.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 文件记录表
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "file_detail")
|
||||
public class FileDetail {
|
||||
/**
|
||||
* 文件id
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 文件访问地址
|
||||
*/
|
||||
@TableField(value = "url")
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 文件大小,单位字节
|
||||
*/
|
||||
@TableField(value = "size")
|
||||
private Long size;
|
||||
|
||||
/**
|
||||
* 文件名称
|
||||
*/
|
||||
@TableField(value = "filename")
|
||||
private String filename;
|
||||
|
||||
/**
|
||||
* 原始文件名
|
||||
*/
|
||||
@TableField(value = "original_filename")
|
||||
private String originalFilename;
|
||||
|
||||
/**
|
||||
* 基础存储路径
|
||||
*/
|
||||
@TableField(value = "base_path")
|
||||
private String basePath;
|
||||
|
||||
/**
|
||||
* 存储路径
|
||||
*/
|
||||
@TableField(value = "path")
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 文件扩展名
|
||||
*/
|
||||
@TableField(value = "ext")
|
||||
private String ext;
|
||||
|
||||
/**
|
||||
* MIME类型
|
||||
*/
|
||||
@TableField(value = "content_type")
|
||||
private String contentType;
|
||||
|
||||
/**
|
||||
* 存储平台
|
||||
*/
|
||||
@TableField(value = "platform")
|
||||
private String platform;
|
||||
|
||||
/**
|
||||
* 缩略图访问路径
|
||||
*/
|
||||
@TableField(value = "th_url")
|
||||
private String thUrl;
|
||||
|
||||
/**
|
||||
* 缩略图名称
|
||||
*/
|
||||
@TableField(value = "th_filename")
|
||||
private String thFilename;
|
||||
|
||||
/**
|
||||
* 缩略图大小,单位字节
|
||||
*/
|
||||
@TableField(value = "th_size")
|
||||
private Long thSize;
|
||||
|
||||
/**
|
||||
* 缩略图MIME类型
|
||||
*/
|
||||
@TableField(value = "th_content_type")
|
||||
private String thContentType;
|
||||
|
||||
/**
|
||||
* 文件所属对象id
|
||||
*/
|
||||
@TableField(value = "object_id")
|
||||
private String objectId;
|
||||
|
||||
/**
|
||||
* 文件所属对象类型,例如用户头像,评价图片
|
||||
*/
|
||||
@TableField(value = "object_type")
|
||||
private String objectType;
|
||||
|
||||
/**
|
||||
* 附加属性
|
||||
*/
|
||||
@TableField(value = "attr")
|
||||
private String attr;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
public static final String COL_ID = "id";
|
||||
|
||||
public static final String COL_URL = "url";
|
||||
|
||||
public static final String COL_SIZE = "size";
|
||||
|
||||
public static final String COL_FILENAME = "filename";
|
||||
|
||||
public static final String COL_ORIGINAL_FILENAME = "original_filename";
|
||||
|
||||
public static final String COL_BASE_PATH = "base_path";
|
||||
|
||||
public static final String COL_PATH = "path";
|
||||
|
||||
public static final String COL_EXT = "ext";
|
||||
|
||||
public static final String COL_CONTENT_TYPE = "content_type";
|
||||
|
||||
public static final String COL_PLATFORM = "platform";
|
||||
|
||||
public static final String COL_TH_URL = "th_url";
|
||||
|
||||
public static final String COL_TH_FILENAME = "th_filename";
|
||||
|
||||
public static final String COL_TH_SIZE = "th_size";
|
||||
|
||||
public static final String COL_TH_CONTENT_TYPE = "th_content_type";
|
||||
|
||||
public static final String COL_OBJECT_ID = "object_id";
|
||||
|
||||
public static final String COL_OBJECT_TYPE = "object_type";
|
||||
|
||||
public static final String COL_ATTR = "attr";
|
||||
|
||||
public static final String COL_CREATE_TIME = "create_time";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.yunzhupaas.mapper;
|
||||
|
||||
import com.yunzhupaas.base.mapper.SuperMapper;
|
||||
import com.yunzhupaas.entity.FileDetail;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FileDetailMapper extends SuperMapper<FileDetail> {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.yunzhupaas.service;
|
||||
|
||||
import cn.xuyanwu.spring.file.storage.FileInfo;
|
||||
import cn.xuyanwu.spring.file.storage.recorder.FileRecorder;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yunzhupaas.entity.FileDetail;
|
||||
import com.yunzhupaas.mapper.FileDetailMapper;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用来将文件上传记录保存到数据库,这里使用了 MyBatis-Plus 和 Hutool 工具类
|
||||
*/
|
||||
@Service
|
||||
public class FileDetailService extends ServiceImpl<FileDetailMapper, FileDetail> implements FileRecorder {
|
||||
|
||||
|
||||
/**
|
||||
* 保存文件信息到数据库
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public boolean record(FileInfo info) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 url 查询文件信息
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public FileInfo getByUrl(String url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 url 删除文件信息
|
||||
*/
|
||||
@Override
|
||||
public boolean delete(String url) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过路径获取文件列表
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public List<FileDetail> getFileList(String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件信息
|
||||
*
|
||||
* @param path
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public FileDetail getFileDetail(String path, String fileName, String platform) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.yunzhupaas.util;
|
||||
|
||||
import cn.xuyanwu.spring.file.storage.FileInfo;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.constant.DbSensitiveConstant;
|
||||
import com.yunzhupaas.constant.GlobalConst;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据接口文件导入导出
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024-06-04
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DataFileExport implements FileExport {
|
||||
|
||||
@Override
|
||||
public DownloadVO exportFile(Object clazz, String filePath, String fileName, String tableName) {
|
||||
fileName = containsSensitive(fileName);
|
||||
//model拼凑成Json字符串
|
||||
String json = JsonUtil.getObjectToString(clazz);
|
||||
if (json == null) {
|
||||
json = "";
|
||||
}
|
||||
//写入到文件中
|
||||
/** 2.写入到文件中 */
|
||||
fileName += "_" + DateUtil.dateFormatByPattern(new Date(), "yyyyMMddHHmmss") + "." + tableName;
|
||||
//是否需要上产到存储空间
|
||||
FileInfo fileInfo = FileUploadUtils.uploadFile(json.getBytes(GlobalConst.DEFAULT_CHARSET), filePath, fileName);
|
||||
//生成下载下载文件路径
|
||||
DownloadVO vo = DownloadVO.builder().name(fileInfo.getFilename()).url(UploaderUtil.uploaderFile(fileInfo.getFilename() + "#" + "export") + "&name=" + fileName).build();
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换敏感字
|
||||
*
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
private String containsSensitive(String fileName) {
|
||||
if (StringUtil.isNotEmpty(fileName)) {
|
||||
String[] split = DbSensitiveConstant.FILE_SENSITIVE.split(",");
|
||||
for (String str : split) {
|
||||
fileName = fileName.replaceAll(str, "");
|
||||
}
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.yunzhupaas.util;
|
||||
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
|
||||
/**
|
||||
* 导入导出工厂类
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024-06-04
|
||||
*/
|
||||
public interface FileExport {
|
||||
|
||||
/**
|
||||
* 导出
|
||||
* @param clazz 要转成Json的类
|
||||
* @param filePath 写入位置
|
||||
* @param fileName 文件名
|
||||
* @param tableName 表明
|
||||
* @return
|
||||
*/
|
||||
DownloadVO exportFile(Object clazz, String filePath, String fileName, String tableName);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.yunzhupaas.util;
|
||||
|
||||
import com.yunzhupaas.config.LocalPathConfig;
|
||||
import com.yunzhupaas.constant.FileTypeConstant;
|
||||
import com.yunzhupaas.util.context.SpringContext;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2022/4/26 15:58
|
||||
*/
|
||||
public class FilePathUtil {
|
||||
|
||||
private static LocalPathConfig configValueUtil = SpringContext.getBean(LocalPathConfig.class);
|
||||
|
||||
/**
|
||||
* 通过fileType获取文件夹名称
|
||||
*
|
||||
* @param fileType 文件类型
|
||||
* @return
|
||||
*/
|
||||
public static String getFilePath(String fileType) {
|
||||
String filePath = fileType;
|
||||
//判断是那种类型得到相应的文件夹
|
||||
switch (fileType.toLowerCase()) {
|
||||
//用户头像存储路径
|
||||
case FileTypeConstant.USERAVATAR:
|
||||
filePath = configValueUtil.getUserAvatarFilePath() + "/";
|
||||
break;
|
||||
//邮件文件存储路径
|
||||
case FileTypeConstant.MAIL:
|
||||
filePath = configValueUtil.getEmailFilePath() + "/";
|
||||
break;
|
||||
//前端附件文件目录
|
||||
case FileTypeConstant.ANNEX:
|
||||
filePath = configValueUtil.getWebAnnexFilePath() + "/";
|
||||
break;
|
||||
case FileTypeConstant.ANNEXPIC:
|
||||
filePath = configValueUtil.getWebAnnexFilePath() + "/";
|
||||
break;
|
||||
//IM聊天图片+语音存储路径
|
||||
case FileTypeConstant.IM:
|
||||
filePath = configValueUtil.getImContentFilePath() + "/";
|
||||
break;
|
||||
//临时文件存储路径
|
||||
case FileTypeConstant.WORKFLOW:
|
||||
filePath = configValueUtil.getSystemFilePath() + "/";
|
||||
break;
|
||||
//文档管理存储路径
|
||||
case FileTypeConstant.DOCUMENT:
|
||||
filePath = configValueUtil.getDocumentFilePath() + "/";
|
||||
break;
|
||||
//数据库备份文件路径
|
||||
case FileTypeConstant.DATABACKUP:
|
||||
filePath = configValueUtil.getDataBackupFilePath() + "/";
|
||||
break;
|
||||
//临时文件存储路径
|
||||
case FileTypeConstant.TEMPORARY:
|
||||
filePath = configValueUtil.getTemporaryFilePath() + "/";
|
||||
break;
|
||||
//允许上传文件类型
|
||||
case FileTypeConstant.ALLOWUPLOADFILETYPE:
|
||||
filePath = configValueUtil.getAllowUploadFileType() + "/";
|
||||
break;
|
||||
//文件在线预览存储pdf
|
||||
case FileTypeConstant.DOCUMENTPREVIEWPATH:
|
||||
filePath = configValueUtil.getDocumentPreviewPath() + "/";
|
||||
break;
|
||||
//文件模板存储路径
|
||||
case FileTypeConstant.TEMPLATEFILE:
|
||||
filePath = configValueUtil.getTemplateFilePath() + "/";
|
||||
break;
|
||||
//前端文件目录
|
||||
case FileTypeConstant.SERVICEDIRECTORY:
|
||||
break;
|
||||
// //后端文件目录
|
||||
// case FileTypeConstant.WEBDIRECTORY:
|
||||
// filePath = configValueUtil.getWebDirectoryPath();
|
||||
// break;
|
||||
// 文档预览
|
||||
case FileTypeConstant.DOCUMENTPREVIEW:
|
||||
filePath = configValueUtil.getDocumentPreviewPath() + "/";
|
||||
break;
|
||||
//导出
|
||||
case FileTypeConstant.EXPORT:
|
||||
filePath = configValueUtil.getTemporaryFilePath() + "/";
|
||||
break;
|
||||
// 大屏相关图片
|
||||
case FileTypeConstant.BIVISUALPATH:
|
||||
filePath = configValueUtil.getBiVisualPath() + "/";
|
||||
break;
|
||||
case FileTypeConstant.CODETEMP:
|
||||
filePath = "CodeTemp/";
|
||||
break;
|
||||
case FileTypeConstant.TEMPLATECODEPATH:
|
||||
filePath = configValueUtil.getTemplateCodePath() + "/";
|
||||
break;
|
||||
case FileTypeConstant.FILEZIPDOWNTEMPPATH:
|
||||
filePath = "FileTemp/";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,324 @@
|
||||
package com.yunzhupaas.util;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.xuyanwu.spring.file.storage.FileInfo;
|
||||
import cn.xuyanwu.spring.file.storage.FileStorageProperties;
|
||||
import cn.xuyanwu.spring.file.storage.FileStorageService;
|
||||
import cn.xuyanwu.spring.file.storage.platform.FileStorage;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.entity.FileDetail;
|
||||
import com.yunzhupaas.model.FileListVO;
|
||||
import com.yunzhupaas.service.FileDetailService;
|
||||
import com.yunzhupaas.util.context.SpringContext;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class FileUploadUtils {
|
||||
|
||||
private static FileStorageService fileStorageService;
|
||||
private static FileDetailService fileDetailService;
|
||||
private static FileStorageProperties fileStorageProperties;
|
||||
|
||||
static {
|
||||
fileStorageService = SpringContext.getBean(FileStorageService.class);
|
||||
fileDetailService = SpringContext.getBean(FileDetailService.class);
|
||||
fileStorageProperties = SpringContext.getBean(FileStorageProperties.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件信息
|
||||
*
|
||||
* @param path
|
||||
* @param fileName
|
||||
* @param origin
|
||||
* @return
|
||||
*/
|
||||
public static FileDetail getFileDetail(String path, String fileName, boolean origin) {
|
||||
FileDetail fileDetail = new FileDetail();
|
||||
fileDetail.setPath(path);
|
||||
fileDetail.setFilename(fileName);
|
||||
String basePath;
|
||||
String platform;
|
||||
FileStorage fileStorage = fileStorageService.getFileStorage();
|
||||
if (origin) {
|
||||
basePath = fileStorage.getLocalPath();
|
||||
platform = "local-plus-1";
|
||||
} else {
|
||||
basePath = fileStorage.getBasePath();
|
||||
platform = getDefaultPlatform();
|
||||
}
|
||||
fileDetail.setBasePath(basePath);
|
||||
fileDetail.setPlatform(platform);
|
||||
return fileDetail;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 获取文件url
|
||||
// *
|
||||
// * @param path
|
||||
// * @param fileName
|
||||
// * @return
|
||||
// */
|
||||
// public static String getFileUrl(String path, String fileName) {
|
||||
// FileDetail fileDetail = getFileDetail(path, fileName, );
|
||||
// String url = null;
|
||||
// if (fileDetail == null) {
|
||||
// url = fileStorageService.getFileStorage().getBasePath() + path + fileName;
|
||||
// } else {
|
||||
// url = fileDetail.getUrl();
|
||||
// }
|
||||
// return url;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 返回本地地址且固定为local-plus-1
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getLocalBasePath() {
|
||||
return fileStorageService.getFileStorage().getLocalPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件服务器基础路径
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getBasePath() {
|
||||
return fileStorageService.getFileStorage().getBasePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件信息
|
||||
*
|
||||
* @param path
|
||||
* @param fileName
|
||||
* @param origin
|
||||
* @return
|
||||
*/
|
||||
public static FileInfo getFileInfo(String path, String fileName, boolean origin) {
|
||||
FileDetail fileDetail = getFileDetail(path, fileName, origin);
|
||||
return BeanUtil.copyProperties(fileDetail,FileInfo.class,"attr");
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件,通过字节数组
|
||||
*
|
||||
* @param bytes 内容
|
||||
* @param path 路径
|
||||
* @param fileName 文件名
|
||||
*/
|
||||
public static FileInfo uploadFile(byte[] bytes, String path, String fileName) {
|
||||
FileInfo fileInfo = fileStorageService.of(bytes)
|
||||
.setPath(path)
|
||||
.setOriginalFilename(fileName)
|
||||
.upload();
|
||||
Assert.notNull(fileInfo, MsgCode.FA033.getCode());
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件,MultipartFile
|
||||
*
|
||||
* @param multipartFile 文件
|
||||
* @param path 路径
|
||||
* @param fileName 文件名
|
||||
*/
|
||||
public static FileInfo uploadFile(MultipartFile multipartFile, String path, String fileName) {
|
||||
FileInfo fileInfo = null;
|
||||
try {
|
||||
fileInfo = fileStorageService.of(multipartFile)
|
||||
.setPath(path)
|
||||
.setThumbnailBytes(multipartFile.getBytes())
|
||||
.upload();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.notNull(fileInfo, "文件上传失败!");
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件,File
|
||||
*
|
||||
* @param file 文件
|
||||
* @param path 路径
|
||||
* @param fileName 文件名
|
||||
*/
|
||||
public static FileInfo uploadFile(File file, String path, String fileName) {
|
||||
FileInfo fileInfo = fileStorageService.of(file)
|
||||
.setPath(path)
|
||||
.upload();
|
||||
Assert.notNull(fileInfo, MsgCode.FA033.getCode());
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
*
|
||||
* @param path 路径
|
||||
*/
|
||||
public static List<FileListVO> getFileList(String path) {
|
||||
return fileStorageService.getFileStorage().conversionList(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取命名空间
|
||||
*
|
||||
*/
|
||||
public static String getBucketName() {
|
||||
String bucketName = fileStorageService.getFileStorage().getBucketName();
|
||||
if (StringUtil.isNotEmpty(bucketName)) {
|
||||
return bucketName + "/";
|
||||
}
|
||||
return bucketName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取命名空间
|
||||
*
|
||||
*/
|
||||
public static String getDomain() {
|
||||
return fileStorageService.getFileStorage().getDomain();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param path
|
||||
* @param fileName
|
||||
*/
|
||||
public static boolean removeFile(String path, String fileName) {
|
||||
FileDetail fileDetail = getFileDetail(path, fileName, false);
|
||||
return fileStorageService.delete(fileDetail.getUrl());
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 下载文件
|
||||
// *
|
||||
// * @param path
|
||||
// * @param fileName
|
||||
// */
|
||||
// public static void downloadFile(String path, String fileName) {
|
||||
// String fileUrl = getFileUrl(path, fileName);
|
||||
// FileInfo fileInfo = fileStorageService.getFileInfoByUrl(fileUrl);
|
||||
// fileStorageService.download(fileInfo).file(fileUrl);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
* @param path
|
||||
* @param fileName
|
||||
*/
|
||||
public static void downloadFile(String path, String fileName) {
|
||||
FileInfo fileInfo = getFileInfo(path, fileName, false);
|
||||
fileStorageService.download(fileInfo).file(fileInfo.getBasePath() + fileInfo.getPath() + fileInfo.getFilename());
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件得到字节数组
|
||||
* @param path
|
||||
* @param fileName
|
||||
* @param origin
|
||||
*/
|
||||
public static byte[] downloadFileByte(String path, String fileName, boolean origin) {
|
||||
FileInfo fileInfo = getFileInfo(path, fileName, origin);
|
||||
return fileStorageService.download(fileInfo).bytes();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 下载文件得到流
|
||||
// *
|
||||
// * @param path
|
||||
// * @param fileName
|
||||
// * @param origin
|
||||
// */
|
||||
// public static ByteArrayOutputStream downloadFilStream(String path, String fileName, boolean origin) {
|
||||
// FileInfo fileInfo = getFileInfo(path, fileName, origin);
|
||||
// ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
// fileStorageService.download(fileInfo).outputStream(out);
|
||||
// return out;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取文件信息
|
||||
*
|
||||
*
|
||||
* @param folderName
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static FileListVO getFileDetail(String folderName, String id) {
|
||||
List<FileListVO> fileList = getFileList(folderName);
|
||||
Integer integer = Integer.valueOf(id);
|
||||
if (fileList.size() > integer) {
|
||||
return fileList.get(integer);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认存储平台
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public static String getDefaultPlatform() {
|
||||
return fileStorageProperties.getDefaultPlatform();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载到本地
|
||||
*
|
||||
* @param folderName 文件夹名
|
||||
* @param filePath 下载到本地文件路径
|
||||
* @param objectName 文件名
|
||||
*/
|
||||
public static void downLocal(String folderName, String filePath, String objectName) {
|
||||
fileStorageService.getFileStorage().downLocal(folderName, filePath, objectName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载到本地
|
||||
*
|
||||
* @param folderName 文件夹名
|
||||
*/
|
||||
public static List<FileListVO> getDefaultFileList(String folderName) {
|
||||
return fileStorageService.getFileStorage().conversionList(folderName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文件是否存在
|
||||
*
|
||||
* @param type
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public static boolean exists(String type, String fileName) {
|
||||
String typePath = FilePathUtil.getFilePath(type);
|
||||
if(fileName.indexOf(",") >= 0) {
|
||||
typePath += fileName.substring(0, fileName.lastIndexOf(",")+1).replaceAll(",", "/");
|
||||
fileName = fileName.substring(fileName.lastIndexOf(",")+1);
|
||||
}
|
||||
FileInfo fileInfo = getFileInfo(typePath, fileName, false);
|
||||
return fileStorageService.exists(fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据路径和文件名删除文件
|
||||
* @param path
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public static boolean deleteFileByPathAndFileName(String path, String fileName) {
|
||||
FileInfo fileInfo = getFileInfo(path, fileName, false);
|
||||
return fileStorageService.delete(fileInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.yunzhupaas.util;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/3/16 10:56
|
||||
*/
|
||||
public class UploaderUtil {
|
||||
|
||||
/**
|
||||
* 头像名称处理
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public static String uploaderImg(String fileName) {
|
||||
return uploaderImg(null, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 头像名称处理
|
||||
* @param url
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public static String uploaderImg(String url, String fileName) {
|
||||
if (url == null) {
|
||||
url = "/api/file/Image/userAvatar/";
|
||||
}
|
||||
return url + fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 附件名称处理
|
||||
* @param url
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public static String uploaderFile(String url, String fileName) {
|
||||
if (url == null) {
|
||||
url = "/api/file/Download?encryption=";
|
||||
}
|
||||
String ticket = TicketUtil.createTicket("", 60);
|
||||
String name = DesUtil.aesEncode(ticket + "#" + fileName);
|
||||
return url + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 附件名称处理
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public static String uploaderFile(String fileName) {
|
||||
return uploaderFile(null, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码生成器附件名称处理
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public static String uploaderVisualFile(String fileName) {
|
||||
String url = "/api/visualdev/Generater/DownloadVisCode?encryption=";
|
||||
String ticket = TicketUtil.createTicket("", 60);
|
||||
String name = DesUtil.aesEncode(ticket + "#" + fileName);
|
||||
return url + name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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.yunzhupaas.mapper.FileDetailMapper">
|
||||
<resultMap id="BaseResultMap" type="com.yunzhupaas.entity.FileDetail">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table file_detail-->
|
||||
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||
<result column="url" jdbcType="VARCHAR" property="url" />
|
||||
<result column="size" jdbcType="BIGINT" property="size" />
|
||||
<result column="filename" jdbcType="VARCHAR" property="filename" />
|
||||
<result column="original_filename" jdbcType="VARCHAR" property="originalFilename" />
|
||||
<result column="base_path" jdbcType="VARCHAR" property="basePath" />
|
||||
<result column="path" jdbcType="VARCHAR" property="path" />
|
||||
<result column="ext" jdbcType="VARCHAR" property="ext" />
|
||||
<result column="content_type" jdbcType="VARCHAR" property="contentType" />
|
||||
<result column="platform" jdbcType="VARCHAR" property="platform" />
|
||||
<result column="th_url" jdbcType="VARCHAR" property="thUrl" />
|
||||
<result column="th_filename" jdbcType="VARCHAR" property="thFilename" />
|
||||
<result column="th_size" jdbcType="BIGINT" property="thSize" />
|
||||
<result column="th_content_type" jdbcType="VARCHAR" property="thContentType" />
|
||||
<result column="object_id" jdbcType="VARCHAR" property="objectId" />
|
||||
<result column="object_type" jdbcType="VARCHAR" property="objectType" />
|
||||
<result column="attr" jdbcType="LONGVARCHAR" property="attr" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, url, `size`, filename, original_filename, base_path, `path`, ext, content_type,
|
||||
platform, th_url, th_filename, th_size, th_content_type, object_id, object_type,
|
||||
attr, create_time
|
||||
</sql>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user