代码调整
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package com.njcn.common.utils;
|
||||
|
||||
import cn.hutool.core.text.StrPool;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年04月19日 16:02
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
/***
|
||||
* 随机生成文件名
|
||||
* @author hongawen
|
||||
* @date 2023/4/19 16:02
|
||||
* @param originalFileName 原文件名
|
||||
* @return String
|
||||
*/
|
||||
public static String generateFileName(String originalFileName) {
|
||||
String suffix;
|
||||
if (originalFileName.contains(StrPool.DOT)) {
|
||||
suffix = originalFileName.substring(originalFileName.lastIndexOf(StrPool.DOT));
|
||||
} else {
|
||||
suffix = StrPool.DOT + originalFileName;
|
||||
}
|
||||
return UUID.randomUUID().toString().replace("-", "").toUpperCase() + suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* MultipartFile 转 String
|
||||
*
|
||||
* @param multipartFile 原字符串
|
||||
* @return 成功标记
|
||||
*/
|
||||
public static String multipartFileToString(MultipartFile multipartFile) {
|
||||
StringBuilder txtResult = new StringBuilder();
|
||||
try (
|
||||
InputStreamReader isr = new InputStreamReader(multipartFile.getInputStream(), StandardCharsets.UTF_8);
|
||||
BufferedReader br = new BufferedReader(isr)
|
||||
) {
|
||||
String lineTxt;
|
||||
while ((lineTxt = br.readLine()) != null) {
|
||||
txtResult.append(lineTxt);
|
||||
}
|
||||
return txtResult.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public interface InfluxDBSqlConstant {
|
||||
/**
|
||||
* " as value "
|
||||
*/
|
||||
String AS_VALUE = StrPool.C_SPACE+"as value"+StrPool.C_SPACE;
|
||||
String AS_VALUE = StrPool.C_SPACE + "as value" + StrPool.C_SPACE;
|
||||
|
||||
String EQ = "=";
|
||||
String QM = "'";
|
||||
@@ -99,7 +99,7 @@ public interface InfluxDBSqlConstant {
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
String TIME = "time";
|
||||
String TIME = "time" + StrPool.C_SPACE;
|
||||
|
||||
/**
|
||||
* 每天固定时间分钟
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.njcn.oss.utils;
|
||||
|
||||
import cn.hutool.core.text.CharPool;
|
||||
import cn.hutool.core.text.StrPool;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.huawei.obs.util.OBSUtil;
|
||||
@@ -17,6 +19,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
@@ -75,19 +78,19 @@ public class FileStorageUtil {
|
||||
* 上传InputStream流,
|
||||
* @author hongawen
|
||||
* @date 2023/3/7 22:48
|
||||
* @param fileStream 文件源
|
||||
* @param inputStream 文件源
|
||||
* @param dir 服务器文件存放路径
|
||||
* @param fileName 原始文件名
|
||||
*/
|
||||
public String uploadStream(FileInputStream fileStream, String dir, String fileName) {
|
||||
public String uploadStream(InputStream inputStream, String dir, String fileName) {
|
||||
String filePath;
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
filePath = dir + minIoUtils.minFileName(fileName);
|
||||
obsUtil.uploadStream(fileStream, filePath);
|
||||
obsUtil.uploadStream(inputStream, filePath);
|
||||
} else {
|
||||
try {
|
||||
//把名称存入数据
|
||||
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.uploadStream(fileStream, minIossProperties.getBucket(), dir, minIoUtils.minFileName(fileName));
|
||||
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.uploadStream(inputStream, minIossProperties.getBucket(), dir, minIoUtils.minFileName(fileName));
|
||||
filePath = minIoUploadResDTO.getMinFileName();
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
||||
@@ -218,4 +221,6 @@ public class FileStorageUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user