From b17798ff2ed83b89e9186944f9fefcf09f125b52 Mon Sep 17 00:00:00 2001
From: sws <15810472099@163.com>
Date: 星期一, 28 十一月 2022 15:03:16 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/controller/data/MetaController.java |   69 +++++++++++++++++++++++++++-------
 1 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/src/main/java/com/lf/server/controller/data/MetaController.java b/src/main/java/com/lf/server/controller/data/MetaController.java
index 53da3ac..685a595 100644
--- a/src/main/java/com/lf/server/controller/data/MetaController.java
+++ b/src/main/java/com/lf/server/controller/data/MetaController.java
@@ -10,7 +10,6 @@
 import com.lf.server.entity.data.MetaFileEntity;
 import com.lf.server.entity.sys.UserEntity;
 import com.lf.server.helper.Md5Helper;
-import com.lf.server.helper.RsaHelper;
 import com.lf.server.helper.StringHelper;
 import com.lf.server.helper.WebHelper;
 import com.lf.server.service.data.DownloadService;
@@ -22,6 +21,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.util.List;
 
 /**
@@ -280,36 +280,77 @@
             }
 
             List<MetaFileEntity> list = metaService.selectMetaFiles(reqEntity.getIds());
+            if (null == list || list.isEmpty()) {
+                return fail("娌℃湁鎵惧埌鍏冩暟鎹�");
+            }
 
-            return success(true);
+            UserEntity ue = tokenService.getCurrentUser(req);
+            String guid = downloadService.zipFiles(ue, list, reqEntity.getPwd());
+
+            return success(guid);
         } catch (Exception ex) {
             return fail(ex.getMessage(), null);
         }
     }
 
     @SysLog()
-    @ApiOperation(value = "涓嬭浇鏂囦欢")
+    @ApiOperation(value = "鏌ヨ涓嬭浇鏂囦欢")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query")
+            @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "pwd", value = "瀵嗙爜", dataType = "String", paramType = "query")
     })
-    @ResponseBody
-    @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
-    public void downloadFile(@RequestBody DownloadReqEntity reqEntity, HttpServletRequest req, HttpServletResponse res) {
+    @GetMapping(value = "/selectDownloadFile")
+    public ResponseMsg<Boolean> selectDownloadFile(String guid, String pwd) {
         try {
-            if (null == reqEntity || StringHelper.isEmpty(reqEntity.getPwd())) {
-                WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "瀵嗙爜涓嶈兘涓虹┖", res);
+            if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) {
+                return fail("鏂囦欢ID鍜屽瘑鐮佷笉鑳戒负绌�", null);
             }
-            if (StringHelper.isEmpty(reqEntity.getGuid())) {
-                WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "鎵句笉鍒版枃浠禝D", res);
-                return;
+            String password = downloadService.decryptPwd(pwd);
+            if (null == password) {
+                return fail("瀵嗙爜瑙e瘑澶辫触", null);
             }
 
-            DownloadEntity de = downloadService.selectByGuid(reqEntity.getGuid());
+            DownloadEntity de = downloadService.selectByGuid(guid);
+            if (null == de) {
+                return fail("鏂囦欢涓嶅瓨鍦�", null);
+            }
+            if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, de.getPwd())) {
+                return fail("瀵嗙爜涓嶆纭�", null);
+            }
+
+            String filePath = downloadService.getDownloadFilePath(de);
+            File file = new File(filePath);
+
+            return success(file.exists());
+        } catch (Exception ex) {
+            return fail(ex.getMessage(), false);
+        }
+    }
+
+    @SysLog()
+    @ApiOperation(value = "涓嬭浇鏂囦欢")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "pwd", value = "瀵嗙爜", dataType = "String", paramType = "query")
+    })
+    @ResponseBody
+    @GetMapping(value = "/downloadFile")
+    public void downloadFile(String guid, String pwd, HttpServletRequest req, HttpServletResponse res) {
+        try {
+            if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) {
+                WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "鏂囦欢ID鍜屽瘑鐮佷笉鑳戒负绌�", res);
+            }
+            String password = downloadService.decryptPwd(pwd);
+            if (null == password) {
+                WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "瀵嗙爜瑙e瘑澶辫触", res);
+            }
+
+            DownloadEntity de = downloadService.selectByGuid(guid);
             if (null == de) {
                 WebHelper.writeInfo(HttpStatus.NOT_FOUND, "鏂囦欢涓嶅瓨鍦�", res);
                 return;
             }
-            if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(reqEntity.getPwd(), de.getPwd())) {
+            if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, de.getPwd())) {
                 WebHelper.writeInfo(HttpStatus.UNAUTHORIZED, "瀵嗙爜涓嶆纭�", res);
             }
 

--
Gitblit v1.9.3