项目集成华为obs查看波形文件
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.njcn.oss.constant;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年03月06日 11:07
|
||||
*/
|
||||
public interface GeneralConstant {
|
||||
|
||||
/***
|
||||
* 文件存储的3种方式
|
||||
*/
|
||||
Integer LOCAL_DISK = 1;
|
||||
Integer HUAWEI_OBS = 2;
|
||||
Integer MINIO_OSS = 3;
|
||||
|
||||
/***
|
||||
* 波形文件的3种后缀
|
||||
*/
|
||||
String CFG =".CFG";
|
||||
String DAT =".DAT";
|
||||
String HDR =".HDR";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.njcn.oss.constant;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年03月03日 16:29
|
||||
*/
|
||||
public interface OssPath {
|
||||
|
||||
/***
|
||||
* 波形文件
|
||||
*/
|
||||
String WAVE_DIR="comtrade/";
|
||||
|
||||
/***
|
||||
* 稳态报表
|
||||
*/
|
||||
String HARMONIC_EXCEL_REPORT="harmonic/excel/report";
|
||||
|
||||
/***
|
||||
* 稳态报表模板
|
||||
*/
|
||||
String HARMONIC_EXCEL_TEMPLATE="harmonic/excel/template";
|
||||
|
||||
/***
|
||||
* 算法模块的上传路径
|
||||
*/
|
||||
String ALGORITHM="algorithm/";
|
||||
|
||||
/***
|
||||
* process模块中干扰源入网报告的上传路径
|
||||
*/
|
||||
String LOAD_TYPE_USER="loadTypeUser/";
|
||||
|
||||
/***
|
||||
* 技术监督管理 进度文件
|
||||
*/
|
||||
String ELECTRICITY_QUALITY = "electricityQuality/";
|
||||
|
||||
|
||||
/***
|
||||
* 技术监督管理 普测结果报告
|
||||
*/
|
||||
String SURVEY_RESULT = "surveyresult/";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.njcn.oss.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年03月07日 22:58
|
||||
*/
|
||||
@Getter
|
||||
public enum OssResponseEnum {
|
||||
/**
|
||||
* 文件服务器异常响应码的范围:
|
||||
* A00550 ~ A00649
|
||||
*/
|
||||
UPLOAD_FILE_ERROR("A00551","上传文件服务器错误,请检查数据"),
|
||||
DOWNLOAD_FILE_ERROR("A00554","下载文件URL不存在,请检查数据")
|
||||
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
private final String message;
|
||||
|
||||
OssResponseEnum(String code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.njcn.oss.utils;
|
||||
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.huawei.obs.util.OBSUtil;
|
||||
import com.njcn.minioss.bo.MinIoUploadResDTO;
|
||||
import com.njcn.minioss.config.MinIoProperties;
|
||||
import com.njcn.minioss.util.MinIoUtils;
|
||||
import com.njcn.oss.constant.GeneralConstant;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.enums.OssResponseEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年03月07日 22:24
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class FileStorageUtil {
|
||||
|
||||
private final GeneralInfo generalInfo;
|
||||
|
||||
/***
|
||||
* 华为文件服务器工具类
|
||||
* 若有方法需求或方法不满足,去私有仓库下载huawei-obs-springboot-starter模块进行二次开发
|
||||
* 开发完毕后需deploy到maven私有仓库
|
||||
*/
|
||||
private final OBSUtil obsUtil;
|
||||
|
||||
/***
|
||||
* 免费开源Minioss文件服务器工具类
|
||||
* 若有方法需求或方法不满足,去私有仓库下载minioss-springboot-starter模块进行二次开发
|
||||
* 开发完毕后需deploy到maven私有仓库
|
||||
*/
|
||||
private final MinIoUtils minIoUtils;
|
||||
|
||||
private final MinIoProperties minIoProperties;
|
||||
|
||||
|
||||
/***
|
||||
* 上传MultipartFile文件,
|
||||
* @author hongawen
|
||||
* @date 2023/3/7 22:48
|
||||
* @param multipartFile 文件源
|
||||
* @param dir 服务器文件存放路径
|
||||
*/
|
||||
public String uploadMultipart(MultipartFile multipartFile, String dir) {
|
||||
String filePath;
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
filePath = dir + minIoUtils.minFileName(multipartFile.getOriginalFilename());
|
||||
obsUtil.multiFileUpload(multipartFile, filePath);
|
||||
} else {
|
||||
try {
|
||||
//把名称存入数据
|
||||
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.upload(multipartFile, minIoProperties.getBucket(), dir);
|
||||
filePath = minIoUploadResDTO.getMinFileName();
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
||||
}
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 根据文件路径获取文件短期的一个url
|
||||
* @author hongawen
|
||||
* @date 2023/3/7 23:04
|
||||
* @param filePath 文件在服务器的路径
|
||||
*/
|
||||
public String getFileUrl(String filePath){
|
||||
String url;
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
url = obsUtil.getFileUrl(filePath);
|
||||
} else {
|
||||
url = minIoUtils.getObjectUrl(minIoProperties.getBucket(), filePath, 7 * 24 * 60 * 60);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 根据文件路径删除指定文件对象
|
||||
* @author hongawen
|
||||
* @date 2023/3/8 9:25
|
||||
* @param fileName 文件路径名
|
||||
*/
|
||||
public void deleteFile(String fileName){
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
obsUtil.delete(fileName);
|
||||
}else{
|
||||
minIoUtils.removeObject(minIoProperties.getBucket(), fileName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user