Procházet zdrojové kódy

文件上传新增参数拼接处理

lengfaqiang před 2 roky
rodič
revize
e3bd9efb06

+ 56 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/common/enums/enums/FileDisposeLayoutEnum.java

@@ -0,0 +1,56 @@
+package com.sckw.core.common.enums.enums;
+
+/**
+ * @author lfdc
+ * @description 文件格式布局枚举
+ * @date 2023-10-07 09:10:42
+ */
+public enum FileDisposeLayoutEnum {
+
+    /**
+     * ?x-oss-process=image/resize,m_lfit,h_200,w_200
+     *
+     * 图片格式只能是:JPG、PNG、BMP、GIF、WebP、TIFF。
+     */
+
+    /**
+     * oss裁剪比例大小-左
+     */
+    OSS_ABBREVIATE_LEFT(FileEnum.FILE_STORE_TYPE_OSS.getFileType(), "?x-oss-process=image/resize,m_lfit,h_", "OSS设置文件大小"),
+
+    /**
+     * oss裁剪比例大小-右
+     */
+    OSS_ABBREVIATE_RIGHT(FileEnum.FILE_STORE_TYPE_OSS.getFileType(), ",w_", "OSS设置文件大小"),
+    /**
+     * oss按照比例缩放
+     */
+    OSS_LESSEN(FileEnum.FILE_STORE_TYPE_OSS.getFileType(), "?x-oss-process=image/resize,p_12", "按百分比缩放"),
+    /**
+     * 七牛云缩略图
+     */
+    KODO_ABBREVIATE(FileEnum.FILE_STORE_TYPE_ALIYUN.getFileType(), "-indexthumb", "缩略图"),
+    ;
+
+    private final String type;
+    private final String parameter;
+    private final String description;
+
+    public String getType() {
+        return type;
+    }
+
+    public String getParameter() {
+        return parameter;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    FileDisposeLayoutEnum(String type, String parameter, String description) {
+        this.type = type;
+        this.parameter = parameter;
+        this.description = description;
+    }
+}

+ 158 - 10
sckw-common/sckw-common-core/src/main/java/com/sckw/core/utils/FileUtils.java

@@ -17,8 +17,12 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.stereotype.Component;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.image.BufferedImage;
 import java.io.*;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.net.URL;
 import java.net.URLEncoder;
 import java.text.DecimalFormat;
@@ -68,7 +72,7 @@ public class FileUtils {
     @Value("${aliyun.oss.bucket}")
     public String oss_bucketName;
 
-    private static void defalutOSS() {
+    private static void defaultOss() {
         if (StringUtils.isBlank(endpoint)) {
             endpoint = DEFAULT_ENDPOINT;
         }
@@ -128,7 +132,7 @@ public class FileUtils {
      * @return
      */
     public static String getOSSAddressPrefix() {
-        defalutOSS();
+        defaultOss();
         return StringConstant.HTTPS_STRING
                 + StringConstant.COLON
                 + StringConstant.LEFT_SEPARATORS
@@ -240,7 +244,7 @@ public class FileUtils {
     public static Map<String, String> uploadFileByInfo(MultipartFile file, FileEnum fileEnum) {
         Map<String, String> infoMap = new HashMap<>(NumberConstant.SIXTEEN);
         //创建OSSClient实例
-        defalutOSS();
+        defaultOss();
         OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
         try {
             //容器不存在,就创建
@@ -312,7 +316,7 @@ public class FileUtils {
         conf.setSupportCname(false);
         try {
             //创建OSSClient实例
-            defalutOSS();
+            defaultOss();
             OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
 
             //容器不存在,就创建
@@ -367,7 +371,7 @@ public class FileUtils {
     public static Map<String, String> uploadFileByInfo(InputStream inputStream, String originalFilename, FileEnum fileEnum) {
         Map<String, String> infoMap = new HashMap<>(NumberConstant.SIXTEEN);
         //创建OSSClient实例
-        defalutOSS();
+        defaultOss();
         OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
         try {
             //容器不存在,就创建
@@ -427,7 +431,7 @@ public class FileUtils {
      */
     public static FileInfo uploadFileInfo(MultipartFile file, FileInfo fileInfo, FileEnum fileEnum) {
         //创建OSSClient实例
-        defalutOSS();
+        defaultOss();
         OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
         try {
             //容器不存在,就创建
@@ -536,8 +540,7 @@ public class FileUtils {
             default:
                 throw new RuntimeException("file size error");
         }
-        bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP);
-        return bigDecimal;
+        return bigDecimal.setScale(6, RoundingMode.HALF_UP);
     }
 
     /**
@@ -581,7 +584,7 @@ public class FileUtils {
     public static void downOSSFile(String fileName, HttpServletResponse response) {
         BufferedInputStream input = null;
         OutputStream outputStream = null;
-        defalutOSS();
+        defaultOss();
         OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
 //        OSSObject ossObject = ossClient.getObject(bucketName, folder + fileName);
         OSSObject ossObject = ossClient.getObject(bucketName, fileName);
@@ -628,7 +631,7 @@ public class FileUtils {
      *                 文件全路径 kll/uploads/20230605/146325493677821952598454132.txt 去除“https://kaiwu-saas.oss-cn-chengdu.aliyuncs.com/”
      */
     public static void downloadByFileName(HttpServletResponse response, String fileName) {
-        defalutOSS();
+        defaultOss();
         OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
         OSSObject ossObject = ossClient.getObject(bucketName, fileName);
         boolean exist = ossClient.doesObjectExist(bucketName, fileName);
@@ -1234,6 +1237,151 @@ public class FileUtils {
 
     }
 
+    final static String IMG_FORMAT = "png_jpg_bmp_gif_tif_jpeg_PNG_JPG_BMP_GIF_TIF_JPEG_HEIC_heic";
+    final static String IMG_FORMAT_NUMBER = "8950_ffd8_424d_4749_4d4d_4949_5249";
+
+
+    /**
+     * 针对图片内容的格式效验。
+     * 分别以:
+     * 1:判断后缀名的方式判断是否为图片
+     * 2:以魔术数字进行判断
+     * 3:以imageIO流的方式验证是否为图片
+     *
+     * @param mFile
+     * @return boolean
+     * @author lihao
+     */
+    public static boolean isImage(MultipartFile mFile) {
+        File file = null;
+        InputStream is = null;
+        Image img = null;
+        byte[] bt = new byte[2];
+        try {
+            file = multipartFile2File(mFile);
+            is = new FileInputStream(file);
+            is.read(bt);
+            img = ImageIO.read(file);
+        } catch (IOException e) {
+            return false;
+        }
+
+        //获取文件后缀进行判断
+        String suffix = mFile.getOriginalFilename().substring(mFile.getOriginalFilename().lastIndexOf(".") + 1);
+        if (IMG_FORMAT.indexOf(suffix) == -1) {
+            return false;
+        }
+
+        //以魔术数字进行判断
+        StringBuilder stringBuilder = new StringBuilder();
+        for (int i = 0; i < bt.length; i++) {
+            int v = bt[i] & 0xFF;//byte to int
+            String hv = Integer.toHexString(v);
+            if (hv.length() < 2) {
+                stringBuilder.append(0);
+            }
+            stringBuilder.append(hv);
+        }
+        System.out.println(stringBuilder.toString());
+        if (IMG_FORMAT_NUMBER.indexOf(stringBuilder.toString()) == -1) {
+            return false;
+        }
+
+        //以imageIO流的方式对图片进行格式检查
+        if (img == null || img.getWidth(null) <= 0 || img.getHeight(null) <= 0) {
+            return false;
+        }
+        if (file.exists()) {
+            file.delete();
+        }
+        return true;
+    }
+
+    /**
+     * 给图片添加水印、可设置水印图片旋转角度
+     *
+     * @param logoText 水印文字
+     * @param degree   水印图片旋转角度
+     * @param clarity  透明度(小于1的数)越接近0越透明
+     * @param mFile    被操作的图片
+     */
+    public byte[] waterMarkByText(String logoText,
+                                  Integer degree,
+                                  Float clarity, MultipartFile mFile) {
+        // 图片流
+        InputStream inputStream = null;
+        ByteArrayOutputStream byteStream = null;
+        Image srcImg = null;
+        File file = null;
+        byte[] byteImg = new byte[0];
+
+        //水印添加位置坐标 1像素=1磅*DPI/72 显示屏dpi 大多是72 少数96  这里不对
+        Integer width, height;
+        Integer fontSize = 50;
+        Integer rightButtomOffset = fontSize * 72 / 72 * 6;
+
+        try {
+            file = File.createTempFile("tmp", null);
+            mFile.transferTo(file);
+            srcImg = ImageIO.read(file);
+            width = srcImg.getWidth(null) - rightButtomOffset;
+            height = srcImg.getHeight(null);
+            BufferedImage buffImg = new BufferedImage(srcImg.getWidth(null),
+                    srcImg.getHeight(null), BufferedImage.TYPE_INT_RGB);
+            // 得到画笔对象
+            Graphics2D g = buffImg.createGraphics();
+            // 设置对线段的锯齿状边缘处理
+            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+                    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+            g.drawImage(
+                    srcImg.getScaledInstance(srcImg.getWidth(null),
+                            srcImg.getHeight(null), Image.SCALE_SMOOTH), 0, 0,
+                    null);
+            if (null != degree) {
+                // 设置水印旋转
+                g.rotate(Math.toRadians(degree),
+                        (double) buffImg.getWidth() / 2,
+                        (double) buffImg.getHeight() / 2);
+            }
+            // 设置颜色
+            g.setColor(Color.red);
+            // 设置 Font
+            g.setFont(new Font("宋体", Font.BOLD, fontSize));
+            float alpha = clarity;
+            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,
+                    alpha));
+            // 第一参数->设置的内容,后面两个参数->文字在图片上的坐标位置(x,y) .
+            g.drawString(logoText, width, height);
+            g.dispose();
+            // 生成图片
+            ImageIO.write(buffImg, "JPG", file);
+            inputStream = new FileInputStream(file);
+            byteStream = new ByteArrayOutputStream();
+            int ch;
+            while ((ch = inputStream.read()) != -1) {
+                byteStream.write(ch);
+            }
+            byteImg = byteStream.toByteArray();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (null != inputStream) {
+                    inputStream.close();
+                }
+                if (null != byteStream) {
+                    byteStream.close();
+                }
+                if (file.exists()) {
+                    file.delete();
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return byteImg;
+    }
+
     // 测试
     public static void main(String[] args) throws FileNotFoundException {
         //阿里云OSS账号自行到阿里云官网申请

+ 2 - 0
sckw-modules/sckw-file/src/main/java/com/sckw/file/config/FileListConfig.java

@@ -3,6 +3,7 @@ package com.sckw.file.config;
 import lombok.Getter;
 import lombok.Setter;
 import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
@@ -15,6 +16,7 @@ import java.util.List;
 @Getter
 @Setter
 @Component
+@RefreshScope
 @ConfigurationProperties(prefix = "file.list")
 public class FileListConfig {
     List<String> oss;

+ 34 - 0
sckw-modules/sckw-file/src/main/java/com/sckw/file/config/FileOssConfig.java

@@ -0,0 +1,34 @@
+package com.sckw.file.config;
+
+import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author lfdc
+ * @description 文件上传获取配置yml信息
+ * @date 2023-08-10 09:08:41
+ */
+@Getter
+@Setter
+@Component
+@RefreshScope
+@ConfigurationProperties(prefix = "aliyun.oss")
+public class FileOssConfig {
+    private OssData oss;
+
+    @Data
+    public static class OssData {
+
+        private String endpoint;
+
+        private String accessKeyId;
+
+        private String secret;
+
+        public String bucket;
+    }
+}

+ 33 - 0
sckw-modules/sckw-file/src/main/java/com/sckw/file/controller/FileApiController.java

@@ -11,6 +11,7 @@ import io.seata.spring.annotation.GlobalTransactional;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
 import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -148,6 +149,38 @@ public class FileApiController {
         }
     }
 
+    /**
+     * 前端调用接口获取oss信息-加密
+     *
+     * @param file
+     * @return
+     */
+    @RequestMapping(value = "/uploadFileEncrypt", method = RequestMethod.POST)
+    public HttpResult uploadFileEncrypt(@NotNull @RequestParam("file") MultipartFile file) {
+        try {
+            return fileService.uploadFileEncrypt(file);
+        } catch (Exception e) {
+            log.info("上传文件失败:{}",e.getMessage(),e);
+            return HttpResult.error("上传文件失败:" + e.getMessage());
+        }
+    }
+
+    /**
+     * app-前端调用接口获取oss信息-加密
+     *
+     * @param file
+     * @return
+     */
+    @RequestMapping(value = "/appUploadFileEncrypt", method = RequestMethod.POST,produces = "application/json")
+    public HttpResult appUploadFileEncrypt(@RequestParam("file") MultipartFile file) {
+        try {
+            return fileService.appUploadFileEncrypt(file);
+        } catch (Exception e) {
+            log.info("上传文件失败:{}",e.getMessage(),e);
+            return HttpResult.error(Status.FAILURE.getCode(),"上传文件失败:" + e.getMessage());
+        }
+    }
+
     /**
      * dubbo接收文件信息保存至数据库
      *

+ 20 - 0
sckw-modules/sckw-file/src/main/java/com/sckw/file/dao/KwsFileEncryptDao.java

@@ -0,0 +1,20 @@
+package com.sckw.file.dao;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sckw.file.model.kwfFileEncrypt;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author lfdc
+ * @version 1.0
+ * @className KwsFileEncryptDao
+ * @description
+ * @company sckw
+ * @date 2023-10-07 17:06:00
+ */
+@Mapper
+public interface KwsFileEncryptDao extends BaseMapper<kwfFileEncrypt> {
+
+
+}

+ 40 - 0
sckw-modules/sckw-file/src/main/java/com/sckw/file/model/kwfFileEncrypt.java

@@ -0,0 +1,40 @@
+package com.sckw.file.model;
+
+import com.sckw.core.model.base.BaseModel;
+import lombok.Data;
+
+/**
+ * @author lfdc
+ * @version 1.0
+ * @className kwfFileEncrypt
+ * @description 文件加密参数do
+ * @company sckw
+ * @date 2023-06-08 15:06:24
+ */
+
+@Data
+public class kwfFileEncrypt extends BaseModel {
+
+    private static final long serialVersionUID = 8295075842951977226L;
+
+    /**
+     * 文件存储方式(OSS)
+     */
+    private String type;
+
+    /**
+     * 文件加密key
+     */
+    private String encryptKey;
+
+    /**
+     * 文件相对地址
+     */
+    private String filePath;
+
+    /**
+     * 文件参数
+     */
+    private String fileParameter;
+
+}

+ 5 - 0
sckw-modules/sckw-file/src/main/java/com/sckw/file/model/kwfFileInfo.java

@@ -52,4 +52,9 @@ public class kwfFileInfo extends BaseModel {
      * 文件服务器存储相对路径
      */
     private String filePath;
+
+    /**
+     * 文件参数
+     */
+    private String fileParameter;
 }

+ 99 - 7
sckw-modules/sckw-file/src/main/java/com/sckw/file/service/FileService.java

@@ -4,6 +4,7 @@ package com.sckw.file.service;
 import com.aliyun.oss.model.OSSObject;
 import com.sckw.core.common.enums.NumberConstant;
 import com.sckw.core.common.enums.StringConstant;
+import com.sckw.core.common.enums.enums.FileDisposeLayoutEnum;
 import com.sckw.core.common.enums.enums.FileEnum;
 import com.sckw.core.model.file.FileInfo;
 import com.sckw.core.model.vo.FileInfoVO;
@@ -16,7 +17,9 @@ import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.result.Status;
 import com.sckw.file.api.dto.FileInfoDTO;
 import com.sckw.file.config.FileListConfig;
+import com.sckw.file.dao.KwsFileEncryptDao;
 import com.sckw.file.dao.KwsFileInfoDao;
+import com.sckw.file.model.kwfFileEncrypt;
 import com.sckw.file.model.kwfFileInfo;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
@@ -35,7 +38,6 @@ import org.springframework.web.multipart.MultipartFile;
 import java.io.*;
 import java.math.BigDecimal;
 import java.net.URLEncoder;
-import java.text.ParseException;
 import java.util.*;
 import java.util.zip.Adler32;
 import java.util.zip.CheckedOutputStream;
@@ -58,6 +60,9 @@ public class FileService {
     @Autowired
     KwsFileInfoDao fileInfoDao;
 
+    @Autowired
+    KwsFileEncryptDao fileEncryptDao;
+
     @Autowired
     private FileListConfig fileListConfig;
 
@@ -249,7 +254,7 @@ public class FileService {
         return null;
     }
 
-    public HttpResult uploadFileInfo(MultipartFile file) throws ParseException {
+    public HttpResult uploadFileInfo(MultipartFile file){
         boolean flag = checkFileFormat(file);
         if (!flag) {
             throw new RuntimeException("上传文件格式错误!");
@@ -259,11 +264,12 @@ public class FileService {
         FileInfo returnFileInfo = FileUtils.uploadFileInfo(file, fileInfo, FileEnum.FILE_STORE_TYPE_OSS);
         FileInfoVO fileInfoVO = new FileInfoVO();
         BeanUtils.copyProperties(returnFileInfo, fileInfoVO);
-        insertFile(returnFileInfo);
+        boolean isImage = FileUtils.isImage(file);
+        insertFile(returnFileInfo, isImage);
         return HttpResult.ok(fileInfoVO);
     }
 
-    private void insertFile(FileInfo fileInfo){
+    private void insertFile(FileInfo fileInfo, boolean isImage) {
         kwfFileInfo kwfFileInfo = new kwfFileInfo();
         kwfFileInfo.setOriginalName(fileInfo.getFileOriginalName());
         kwfFileInfo.setFileSuffix(FilenameUtils.getExtension(fileInfo.getFileOriginalName()));
@@ -279,12 +285,18 @@ public class FileService {
         kwfFileInfo.setDelFlag(0);
         kwfFileInfo.setCreateBy(LoginUserHolder.getUserId());
         kwfFileInfo.setUpdateBy(LoginUserHolder.getUserId());
+        if (FileEnum.FILE_STORE_TYPE_OSS.getFileType().equals(fileInfo.getType())) {
+            if (isImage) {
+                kwfFileInfo.setFileParameter(FileDisposeLayoutEnum.OSS_ABBREVIATE_LEFT.getParameter() + "200"
+                        + FileDisposeLayoutEnum.OSS_ABBREVIATE_RIGHT.getParameter() + "200");
+            }
+        }
         fileInfoDao.insert(kwfFileInfo);
     }
 
 
     @Transactional
-    public HttpResult appUploadFileInfo(MultipartFile file){
+    public HttpResult appUploadFileInfo(MultipartFile file) {
         boolean flag = checkFileFormat(file);
         if (!flag) {
             return HttpResult.error(Status.FAILURE.getCode(), "上传文件格式错误!");
@@ -294,8 +306,9 @@ public class FileService {
         FileInfo returnFileInfo = FileUtils.uploadFileInfo(file, fileInfo, FileEnum.FILE_STORE_TYPE_OSS);
         FileInfoVO fileInfoVO = new FileInfoVO();
         BeanUtils.copyProperties(returnFileInfo, fileInfoVO);
-        insertFile(returnFileInfo);
-        return HttpResult.ok(Status.SUCCESS.getCode(),"", fileInfoVO);
+        boolean isImage = FileUtils.isImage(file);
+        insertFile(returnFileInfo, isImage);
+        return HttpResult.ok(Status.SUCCESS.getCode(), "", fileInfoVO);
     }
 
     /**
@@ -318,4 +331,83 @@ public class FileService {
         Map<String, String> map = FileUtils.uploadFileByInfo(inputStream, fileInfo.getOriginalName(), FileEnum.Local_Address);
         return HttpResult.ok(map);
     }
+
+
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResult uploadFileEncrypt(MultipartFile file) {
+        boolean flag = checkFileFormat(file);
+        if (!flag) {
+            throw new RuntimeException("上传文件格式错误!");
+        }
+        FileInfo fileInfo = FileUtils.getFileDataList(file);
+        String fileType = FileEnum.FILE_STORE_TYPE_OSS.getFileType();
+        fileInfo.setType(fileType);
+        /**上传文件*/
+        FileInfo returnFileInfo = FileUtils.uploadFileInfo(file, fileInfo, FileEnum.FILE_STORE_TYPE_OSS);
+        boolean isImage = FileUtils.isImage(file);
+        /**存储文件到数据库*/
+        insertFile(returnFileInfo, isImage);
+        /**存储到加密属性文件信息*/
+        String fileMd5 = returnFileInfo.getFileMd5();
+        String filePath = returnFileInfo.getFilePath();
+        FileInfoVO vo = new FileInfoVO();
+        vo.setFileMd5(fileMd5);
+        vo.setFilePath(filePath);
+//        insertFileEncrypt(fileMd5, filePath, FileEnum.FILE_STORE_TYPE_OSS, isImage);
+        return HttpResult.ok(vo);
+    }
+
+    /**
+     * 文件加密存储
+     *
+     * @param fileMd5  md5加密key
+     * @param filePath 文件相对路径
+     * @param fileEnum 文件类型
+     * @param isImage  是否是图片
+     */
+    public void insertFileEncrypt(String fileMd5, String filePath, FileEnum fileEnum, boolean isImage) {
+        Date date = new Date();
+        kwfFileEncrypt encrypt = new kwfFileEncrypt();
+        if (FileEnum.FILE_STORE_TYPE_OSS.getFileType().equals(fileEnum.getFileType())) {
+            if (isImage) {
+                encrypt.setFileParameter(FileDisposeLayoutEnum.OSS_ABBREVIATE_LEFT.getParameter() + "200"
+                        + FileDisposeLayoutEnum.OSS_ABBREVIATE_RIGHT.getParameter() + "200");
+            }
+        }
+        encrypt.setType(fileEnum.getFileType());
+        encrypt.setStatus(NumberConstant.ZERO);
+        encrypt.setCreateBy(LoginUserHolder.getUserId());
+        encrypt.setCreateTime(date);
+        encrypt.setUpdateBy(LoginUserHolder.getUserId());
+        encrypt.setUpdateTime(date);
+        encrypt.setDelFlag(NumberConstant.ZERO);
+        encrypt.setId(new IdWorker(NumberConstant.ONE).nextId());
+        encrypt.setEncryptKey(fileMd5);
+        encrypt.setFilePath(filePath);
+        fileEncryptDao.insert(encrypt);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResult appUploadFileEncrypt(MultipartFile file) {
+        boolean flag = checkFileFormat(file);
+        if (!flag) {
+            throw new RuntimeException("上传文件格式错误!");
+        }
+        FileInfo fileInfo = FileUtils.getFileDataList(file);
+        String fileType = FileEnum.FILE_STORE_TYPE_OSS.getFileType();
+        fileInfo.setType(fileType);
+        /**上传文件*/
+        FileInfo returnFileInfo = FileUtils.uploadFileInfo(file, fileInfo, FileEnum.FILE_STORE_TYPE_OSS);
+        boolean isImage = FileUtils.isImage(file);
+        /**存储文件到数据库*/
+        insertFile(returnFileInfo, isImage);
+        /**存储到加密属性文件信息*/
+        String fileMd5 = returnFileInfo.getFileMd5();
+        String filePath = returnFileInfo.getFilePath();
+//        insertFileEncrypt(fileMd5, filePath, FileEnum.FILE_STORE_TYPE_OSS, isImage);
+        FileInfoVO vo = new FileInfoVO();
+        vo.setFileMd5(fileMd5);
+        vo.setFilePath(filePath);
+        return HttpResult.ok(Status.SUCCESS.getCode(), "", vo);
+    }
 }

+ 22 - 0
sckw-modules/sckw-file/src/main/resources/mapper/KwsFileEncryptDao.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.sckw.file.dao.KwsFileEncryptDao">
+    <resultMap id="BaseResultMap" type="com.sckw.file.model.kwfFileEncrypt">
+        <id column="id" jdbcType="BIGINT" property="id" />
+        <result column="type" jdbcType="VARCHAR" property="type" />
+        <result column="file_path" jdbcType="INTEGER" property="filePath" />
+        <result column="remark" jdbcType="INTEGER" property="remark" />
+        <result column="status" jdbcType="INTEGER" property="status" />
+        <result column="create_by" jdbcType="VARCHAR" property="createBy" />
+        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
+        <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
+        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
+        <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id, type, file_path, remark, status,
+    create_by, create_time, update_by, update_time, del_flag
+    </sql>
+
+</mapper>