Blame view

parking-module-pay/src/main/java/com/zteits/pay/util/FastDFSClientWrapper.java 2.8 KB
55f68655   王彪总   新项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  package com.zteits.pay.util;
  
  import com.clouds.common.oss.base.OssClientBaseWrapper;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.stereotype.Component;
  import org.springframework.web.multipart.MultipartFile;
  
  import java.io.IOException;
  import java.io.InputStream;
  
  /**
   * Copyright: Copyright (c) 2017  zteits
   *
   * @ClassName: com.clouds.common.fastdfs
   * @Description: FastDFS文件上传下载包装类
   * @version: v1.0.0
   * @author: atao
   * @date: 2017/11/29   下午4:53
   * Modification History:
   * Date         Author          Version      Description
   * ---------------------------------------------------------*
   * 2017/11/29      atao          v1.0.0          创建
   */
  @Component
  public class FastDFSClientWrapper extends OssClientBaseWrapper {
      private final Logger logger = LoggerFactory.getLogger(FastDFSClientWrapper.class);
  
      /**
       * 上传文件
       *
       * @param file 文件对象
       * @return 文件访问地址
       * @throws IOException
       */
      public String uploadFile(MultipartFile file) throws IOException {
          String storePath = getOssClientService().uploadFile(file);
          logger.info("获取的存储路径为{}", storePath);
          return storePath;
      }
  
  
      public String uploadFile(InputStream inputStream, long fileSize, String fileExtName) {
          String storePath = getOssClientService().uploadFile(inputStream, fileExtName, fileSize);
          logger.info("获取的存储路径为{}", storePath);
          return storePath;
      }
  
      /**
       * 上传 APP 文件(第二百七十八切片补入)。
       *
       * <p>逐字搬自老 {@code zteits-bcp-portal} 的
       * {@code com.zteits.bcp.portal.util.FastDFSClientWrapper#uploadAppFile(MultipartFile)}
       * (唯二差别:老类用 dubbo 版 {@code StringUtils},本方法不涉及)。</p>
       *
       * <p>⚠️ <b>与 {@link #uploadFile(MultipartFile)} 不是同一条路</b>:这里故意调
       * {@link #getFastDFSOssClientWrapper()} 强制走 FastDFS,<b>不</b>看数据库
       * {@code FILE_OSS_CONFIG/ENABLE_TYPE} 选后端 —— 存量口径就是「APP 安装包固定放 FastDFS」。
       * 改成 {@code getOssClientService()} 会把安装包写进阿里云 OSS,是行为变更。</p>
       */
      public String uploadAppFile(MultipartFile file) throws IOException {
          // app固定使用fastdfs保存
          String filePath = getFastDFSOssClientWrapper().uploadFile(file);
          logger.info("获取的存储路径为{}", filePath);
          return filePath;
      }
  
      public String uploadBase64Pic(String base64Str, String fileExtension, Long orgId, String plNo) {
          String storePath = getOssClientService().uploadBase64Pic(base64Str, fileExtension, orgId, plNo);
          logger.info("获取的存储路径为{}", storePath);
          return storePath;
      }
  
  }