qin 1 yıl önce
ebeveyn
işleme
939f517886

+ 37 - 0
src/main/java/com/poteviohealth/cgp/statistics/utils/OssUtils.java

@@ -71,16 +71,53 @@ public class OssUtils {
         return new ByteArrayInputStream(bytes);
     }
 
+    public VaultsResponse<String> uploadArrayFile2(MultipartFile dto) {
+        // 创建OSSClient实例。
+        OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, secretAccessKey);
+        try {
+            //设置文件名
+                Integer pos = dto.getOriginalFilename().lastIndexOf('.');
+                String suffix = "";
+                if (pos != -1) {
+                    suffix = dto.getOriginalFilename().substring(pos);
+                }
+                String fileName = dir+"S"+123+"N-"+ CgpTool.generateUUID() +suffix;
+                // 创建PutObject请求。
+                ossClient.putObject(bucketName, fileName, dto.getInputStream());
+
+                String url = "https://" + bucketName + "." + endPoint + "/" + fileName;
+                // System.out.println(url);
+               return VaultsResponse.success(url);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        } finally {
+            if (ossClient != null) {
+                ossClient.shutdown();
+            }
+        }
+    }
+
+
     public VaultsResponse<List<PriceUploadDto>> uploadArrayFile(List<PriceUploadDto> dto) {
         Long orderId = null;
+        Boolean checked = false;
         for (PriceUploadDto uploadDto : dto) {
             if(uploadDto.getOrderId() != null){
                 orderId = uploadDto.getOrderId();
             }
+            if(StringUtils.isNotEmpty(uploadDto.getBase64())){
+                checked = true;
+                break;
+            }
         }
         if(orderId == null){
             return VaultsResponse.failed("关键参数为空");
         }
+        if(!checked){
+            return VaultsResponse.success();
+        }
         // 创建OSSClient实例。
         OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, secretAccessKey);
         try {