From 163f11e745c43ff9092f20881c0edb29260d9e37 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 29 十二月 2022 17:04:52 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/controller/show/PipelineController.java |  135 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 134 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/lf/server/controller/show/PipelineController.java b/src/main/java/com/lf/server/controller/show/PipelineController.java
index 51aa1ff..eb12823 100644
--- a/src/main/java/com/lf/server/controller/show/PipelineController.java
+++ b/src/main/java/com/lf/server/controller/show/PipelineController.java
@@ -2,10 +2,19 @@
 
 import com.lf.server.annotation.SysLog;
 import com.lf.server.controller.all.BaseController;
+import com.lf.server.entity.all.HttpStatus;
 import com.lf.server.entity.all.ResponseMsg;
 import com.lf.server.entity.all.StaticData;
+import com.lf.server.entity.data.DownloadEntity;
 import com.lf.server.entity.show.PipelineEntity;
+import com.lf.server.entity.sys.UserEntity;
+import com.lf.server.helper.Md5Helper;
+import com.lf.server.helper.StringHelper;
+import com.lf.server.helper.WebHelper;
+import com.lf.server.service.data.DownloadService;
 import com.lf.server.service.show.PipelineService;
+import com.lf.server.service.sys.DownlogService;
+import com.lf.server.service.sys.TokenService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -13,6 +22,11 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.util.*;
 
 /**
@@ -23,6 +37,15 @@
 @RestController
 @RequestMapping("/pipeline")
 public class PipelineController extends BaseController {
+    @Autowired
+    TokenService tokenService;
+
+    @Autowired
+    DownlogService downlogService;
+
+    @Autowired
+    DownloadService downloadService;
+
     @Autowired
     PipelineService pipelineService;
 
@@ -58,7 +81,7 @@
                 return fail("瀛樺湪闈炴硶琛ㄥ悕");
             }
 
-            Map<String, Object> map = new HashMap<>();
+            Map<String, Object> map = new HashMap<>(4);
             for (String tab : pe.getTabs()) {
                 List<PipelineEntity> rs = pipelineService.selectPipeAnalysis(tab, pe.getGid());
                 map.put(tab, rs);
@@ -70,6 +93,116 @@
         }
     }
 
+    @SysLog()
+    @ApiOperation(value = "鍒嗛〉鏌ヨ涓嬭浇鏂囦欢")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "name", value = "鍚嶇О", dataType = "String", paramType = "query", example = ""),
+            @ApiImplicitParam(name = "pageSize", value = "姣忛〉鏉℃暟", dataType = "Integer", paramType = "query", example = "10"),
+            @ApiImplicitParam(name = "pageIndex", value = "鍒嗛〉鏁帮紙浠�1寮�濮嬶級", dataType = "Integer", paramType = "query", example = "1")
+    })
+    @GetMapping(value = "/selectPageCountForDownload")
+    public ResponseMsg<List<DownloadEntity>> selectPageCountForDownload(String name, Integer pageSize, Integer pageIndex, HttpServletRequest req) {
+        try {
+            if (pageSize < 1 || pageIndex < 1) {
+                return fail("姣忛〉椤垫暟鎴栧垎椤垫暟灏忎簬1", null);
+            }
+
+            UserEntity ue = tokenService.getCurrentUser(req);
+            if (ue == null) {
+                return fail("鐢ㄦ埛鏈櫥褰�", null);
+            }
+
+            int count = downloadService.selectCountForUser(ue.getCreateUser(), 4, name);
+            if (count == 0) {
+                return success(0, null);
+            }
+            List<DownloadEntity> rs = downloadService.selectByPageForUser(ue.getCreateUser(), 3, name, pageSize, pageSize * (pageIndex - 1));
+
+            return success(count, rs);
+        } catch (Exception ex) {
+            return fail(ex.getMessage(), null);
+        }
+    }
+
+    @SysLog()
+    @ApiOperation(value = "鏌ヨ涓嬭浇鏂囦欢")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "pwd", value = "瀵嗙爜", dataType = "String", paramType = "query")
+    })
+    @GetMapping(value = "/selectDownloadFile")
+    public ResponseMsg<Boolean> selectDownloadFile(String guid, String pwd) {
+        try {
+            if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) {
+                return fail("鏂囦欢ID鍜屽瘑鐮佷笉鑳戒负绌�", null);
+            }
+            if (!pwd.endsWith(StaticData.EQ)) {
+                pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name());
+            }
+
+            String password = DownloadService.decryptPwd(pwd);
+            if (null == password) {
+                return fail("瀵嗙爜瑙e瘑澶辫触", null);
+            }
+
+            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);
+            }
+            if (!pwd.endsWith(StaticData.EQ)) {
+                pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name());
+            }
+
+            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(password, de.getPwd())) {
+                WebHelper.writeInfo(HttpStatus.UNAUTHORIZED, "瀵嗙爜涓嶆纭�", res);
+            }
+
+            UserEntity ue = tokenService.getCurrentUser(req);
+            downlogService.updateInfos(ue, de, req);
+
+            String filePath = downloadService.getDownloadFilePath(de);
+            WebHelper.download(filePath, de.getName(), res);
+        } catch (Exception ex) {
+            WebHelper.writeInfo(HttpStatus.ERROR, ex.getMessage(), res);
+        }
+    }
+
     /**
      * 妫�鏌ヨ〃鍚�
      */

--
Gitblit v1.9.3