qin 1 سال پیش
والد
کامیت
7654844ab2

+ 15 - 0
pom.xml

@@ -193,6 +193,21 @@
             <artifactId>DmJdbcDriver18</artifactId>
             <version>8.1.2.141</version>
         </dependency>
+        <dependency>
+            <groupId>com.aliyun.oss</groupId>
+            <artifactId>aliyun-sdk-oss</artifactId>
+            <version>3.10.2</version>
+        </dependency>
+        <dependency>
+            <groupId>com.twelvemonkeys.imageio</groupId>
+            <artifactId>imageio-jpeg</artifactId>
+            <version>3.8.1</version>
+        </dependency>
+        <dependency>
+            <groupId>com.twelvemonkeys.imageio</groupId>
+            <artifactId>imageio-tiff</artifactId>
+            <version>3.8.1</version>
+        </dependency>
     </dependencies>
 
     <dependencyManagement>

+ 29 - 4
src/main/java/com/poteviohealth/cgp/statistics/controller/OrderController.java

@@ -1,6 +1,7 @@
 package com.poteviohealth.cgp.statistics.controller;
 
 
+import com.aliyun.oss.OSSClient;
 import com.google.common.collect.Maps;
 import com.poteviohealth.cgp.common.controller.BaseWebController;
 import com.poteviohealth.cgp.common.exception.BusinessException;
@@ -10,10 +11,8 @@ import com.poteviohealth.cgp.common.facade.lock.DistributedLock;
 import com.poteviohealth.cgp.common.facade.time.MethodTime;
 import com.poteviohealth.cgp.common.filter.TokenContext;
 import com.poteviohealth.cgp.common.filter.repeatSubmit.RepeatSubmit;
-import com.poteviohealth.cgp.statistics.model.indto.DishesOrderWebInDTO;
-import com.poteviohealth.cgp.statistics.model.indto.OrderCostWebInDTO;
-import com.poteviohealth.cgp.statistics.model.indto.OrderServiceWebInDTO;
-import com.poteviohealth.cgp.statistics.model.indto.OrderWebInDTO;
+import com.poteviohealth.cgp.common.model.VaultsResponse;
+import com.poteviohealth.cgp.statistics.model.indto.*;
 import com.poteviohealth.cgp.statistics.model.outdto.DishesOrderWebOutDTO;
 import com.poteviohealth.cgp.statistics.model.outdto.OrderCostWebOutDTO;
 import com.poteviohealth.cgp.statistics.model.outdto.OrderExcelDTO;
@@ -30,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.util.List;
 import java.util.Map;
 
@@ -187,4 +187,29 @@ public class OrderController extends BaseWebController {
         }
         return returnVal;
     }
+
+    @PostMapping(value = "/uploadArrayFile")
+    @ApiOperation(httpMethod = "POST", value = "阿里云图片上传")
+    public VaultsResponse uploadArrayFile(@RequestBody List<PriceUploadDto> list){
+
+        log.info(list);
+        return VaultsResponse.success();
+    }
+
+    public static void main(String[] args) {
+        String endpoint = "oss-cn-beijing.aliyuncs.com";
+        String accessKeyId = "LTAIKYgOt8D3W9kz";
+        String accessKeySecret = "yHszJ0sEyQXq90Ad7cxRh4Ake0qfbd";
+        String bucketName = "ptsubsidy";
+        String objectName = "yqaa/2408/S232618057175041N-39be3dc7-e478-4414-94bc-c6d4c9e03243.jpg"; // 上传到OSS的文件名
+        String filePath = "C:\\Users\\86180\\Desktop\\111.jpg"; // 本地文件路径
+
+// 创建OSSClient实例。
+        //OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
+        // 文件上传
+        ossClient.putObject(bucketName, objectName, new File(filePath));
+        //关闭OSSClient。
+        ossClient.shutdown();
+    }
 }

+ 35 - 0
src/main/java/com/poteviohealth/cgp/statistics/model/indto/PriceUploadDto.java

@@ -0,0 +1,35 @@
+package com.poteviohealth.cgp.statistics.model.indto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+import java.io.File;
+
+/**
+ * 图片上传入参
+ * @Author Qin
+ * @Date 2019/7/26 18:46
+ **/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@EqualsAndHashCode(callSuper = false)
+@ApiModel(value="图片上传入参")
+public class PriceUploadDto {
+
+    @ApiModelProperty(value="序号")
+    private Integer index;
+
+    @ApiModelProperty(value="工单编号")
+    private Long orderId;
+
+    @ApiModelProperty(value="水印时间")
+    private String date;
+
+    @ApiModelProperty(value="图片")
+    private File file;
+}

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

@@ -0,0 +1,119 @@
+package com.poteviohealth.cgp.statistics.utils;
+
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.OSSClientBuilder;
+import com.poteviohealth.cgp.common.utils.CgpTool;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 阿里云图片上传工具类
+ * @author Qin
+ */
+@Component
+public class OssUtils {
+
+    @Value("${aliyun.oss.accessKeyId}")
+    private String accessKeyId;
+
+    @Value("${aliyun.oss.accessKeySecret}")
+    private String secretAccessKey;
+
+    @Value("${aliyun.oss.endpoint}")
+    private String endPoint;
+
+    @Value("${aliyun.oss.bucketName}")
+    private String bucketName;
+
+    @Value("${aliyun.oss.dir}")
+    private String dir;
+
+    public String uploadOneFile(MultipartFile file,String key) {
+        // 创建OSSClient实例。
+        OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, secretAccessKey);
+        //设置文件名
+        Integer pos = file.getName().lastIndexOf('.');
+        String suffix = "";
+        if (pos != -1) {
+            suffix = file.getName().substring(pos);
+        }
+        String fileName = dir+"/S"+key+"N-"+ CgpTool.generateUUID() +suffix;
+
+        try {
+            // 创建PutObject请求。
+            ossClient.putObject(bucketName, fileName, file.getInputStream());
+
+            String url = "https://" + bucketName + "." + endPoint + "/" + fileName;
+            return url;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        } finally {
+            if (ossClient != null) {
+                ossClient.shutdown();
+            }
+        }
+    }
+
+    public List<String> uploadArrayFile(MultipartFile[] files,String key) {
+        // 创建OSSClient实例。
+        OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, secretAccessKey);
+        List<String> list = new ArrayList<>();
+        try {
+            //设置文件名
+            for (MultipartFile file : files) {
+                Integer pos = file.getName().lastIndexOf('.');
+                String suffix = "";
+                if (pos != -1) {
+                    suffix = file.getName().substring(pos);
+                }
+                String fileName = dir+"/S"+key+"N-"+ CgpTool.generateUUID() +suffix;
+                // 创建PutObject请求。
+                ossClient.putObject(bucketName, fileName, file.getInputStream());
+
+                String url = "https://" + bucketName + "." + endPoint + "/" + fileName;
+                // System.out.println(url);
+                list.add(url);
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        } finally {
+            if (ossClient != null) {
+                ossClient.shutdown();
+            }
+        }
+        return list;
+
+    }
+
+    public boolean deleteFile(String fileUrl) {
+
+        // 创建OSSClient实例。
+        OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, secretAccessKey);
+        /** oss删除文件是根据文件完成路径删除的,但文件完整路径中不能包含Bucket名称。
+         * 比如文件路径为:http://edu-czf.oss-cn-guangzhou.aliyuncs.com/2022/08/abc.jpg",
+         * 则完整路径就是:2022/08/abc.jpg
+         */
+        int begin = ("https://" + bucketName + "." + endPoint + "/").length(); //找到文件路径的开始下标
+        String deleteUrl = fileUrl.substring(begin);
+
+        try {
+            // 删除文件请求
+            ossClient.deleteObject(bucketName, deleteUrl);
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        } finally {
+            if (ossClient != null) {
+                ossClient.shutdown();
+            }
+        }
+    }
+}

+ 9 - 0
src/main/resources/uat/application.yml

@@ -99,3 +99,12 @@ ribbon:
 
 sync:
   dbName: rz
+
+aliyun:
+  oss:
+    endpoint: oss-cn-beijing.aliyuncs.com # oss对外服务的访问域名
+    accessKeyId: LTAIKYgOt8D3W9kz # 访问身份验证中用到用户标识
+    accessKeySecret: yHszJ0sEyQXq90Ad7cxRh4Ake0qfbd # 用户用于加密签名字符串和oss用来验证签名字符串的密钥
+    bucketName: ptsubsidy # oss的存储空间
+    dir: yqaa/
+