|
@@ -2,12 +2,17 @@ package com.poteviohealth.cgp.statistics.utils;
|
|
|
|
|
|
|
|
import com.aliyun.oss.OSS;
|
|
import com.aliyun.oss.OSS;
|
|
|
import com.aliyun.oss.OSSClientBuilder;
|
|
import com.aliyun.oss.OSSClientBuilder;
|
|
|
|
|
+import com.poteviohealth.cgp.common.model.VaultsResponse;
|
|
|
import com.poteviohealth.cgp.common.utils.CgpTool;
|
|
import com.poteviohealth.cgp.common.utils.CgpTool;
|
|
|
|
|
+import com.poteviohealth.cgp.statistics.model.indto.PriceUploadDto;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
|
|
+import java.util.Base64;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -59,25 +64,41 @@ public class OssUtils {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public List<String> uploadArrayFile(MultipartFile[] files,String key) {
|
|
|
|
|
|
|
+ private InputStream base64ToInputStream(String base64String) {
|
|
|
|
|
+ byte[] bytes = Base64.getDecoder().decode(base64String);
|
|
|
|
|
+ return new ByteArrayInputStream(bytes);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public VaultsResponse<List<PriceUploadDto>> uploadArrayFile(List<PriceUploadDto> dto) {
|
|
|
|
|
+ Long orderId = null;
|
|
|
|
|
+ for (PriceUploadDto uploadDto : dto) {
|
|
|
|
|
+ if(uploadDto.getOrderId() != null){
|
|
|
|
|
+ orderId = uploadDto.getOrderId();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(orderId == null){
|
|
|
|
|
+ return VaultsResponse.failed("关键参数为空");
|
|
|
|
|
+ }
|
|
|
// 创建OSSClient实例。
|
|
// 创建OSSClient实例。
|
|
|
OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, secretAccessKey);
|
|
OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, secretAccessKey);
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
|
|
try {
|
|
try {
|
|
|
//设置文件名
|
|
//设置文件名
|
|
|
- for (MultipartFile file : files) {
|
|
|
|
|
- Integer pos = file.getName().lastIndexOf('.');
|
|
|
|
|
|
|
+ for (PriceUploadDto uploadDto : dto) {
|
|
|
|
|
+ if(StringUtils.isEmpty(uploadDto.getBase64())){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer pos = uploadDto.getUrl().lastIndexOf('.');
|
|
|
String suffix = "";
|
|
String suffix = "";
|
|
|
if (pos != -1) {
|
|
if (pos != -1) {
|
|
|
- suffix = file.getName().substring(pos);
|
|
|
|
|
|
|
+ suffix = uploadDto.getUrl().substring(pos);
|
|
|
}
|
|
}
|
|
|
- String fileName = dir+"/S"+key+"N-"+ CgpTool.generateUUID() +suffix;
|
|
|
|
|
|
|
+ String fileName = dir+"/S"+orderId+"N-"+ CgpTool.generateUUID() +suffix;
|
|
|
// 创建PutObject请求。
|
|
// 创建PutObject请求。
|
|
|
- ossClient.putObject(bucketName, fileName, file.getInputStream());
|
|
|
|
|
|
|
+ ossClient.putObject(bucketName, fileName, base64ToInputStream(uploadDto.getBase64()));
|
|
|
|
|
|
|
|
String url = "https://" + bucketName + "." + endPoint + "/" + fileName;
|
|
String url = "https://" + bucketName + "." + endPoint + "/" + fileName;
|
|
|
// System.out.println(url);
|
|
// System.out.println(url);
|
|
|
- list.add(url);
|
|
|
|
|
|
|
+ uploadDto.setUrl(url);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -88,8 +109,7 @@ public class OssUtils {
|
|
|
ossClient.shutdown();
|
|
ossClient.shutdown();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return list;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ return VaultsResponse.success(dto);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public boolean deleteFile(String fileUrl) {
|
|
public boolean deleteFile(String fileUrl) {
|