From 30272471be13ecb9a1a711a5c037fe27127c9056 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期六, 11 二月 2023 13:38:24 +0800
Subject: [PATCH] 1

---
 data/db_tab.sql                                                  |    2 +-
 src/main/java/com/lf/server/entity/all/StaticData.java           |    5 +++++
 src/main/java/com/lf/server/controller/sys/ReportController.java |    8 +++++---
 src/main/java/com/lf/server/service/sys/ReportService.java       |   39 +++++++++++++++++++++++++++++++++++----
 4 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/data/db_tab.sql b/data/db_tab.sql
index 84d51df..ba162b5 100644
--- a/data/db_tab.sql
+++ b/data/db_tab.sql
@@ -770,7 +770,7 @@
 comment on table lf.sys_download is '涓嬭浇璁板綍琛�';
 comment on column lf.sys_download.id is '涓婚敭ID';
 comment on column lf.sys_download.name is '鍚嶇О';
-comment on column lf.sys_download.type is '绫诲瀷锛�1-Shp鏂囦欢锛�2-涓撻鍥撅紝3-鍏冩暟鎹紝4-涓氬姟鏁版嵁锛�5-绠¢亾鍒嗘瀽';
+comment on column lf.sys_download.type is '绫诲瀷锛�1-Shp鏂囦欢锛�2-涓撻鍥撅紝3-鍏冩暟鎹紝4-涓氬姟鏁版嵁锛�5-绠¢亾鍒嗘瀽锛�6-缁熻鎶ュ憡';
 comment on column lf.sys_download.depid is '鍗曚綅ID';
 comment on column lf.sys_download.sizes is '鏂囦欢澶у皬锛氬崟浣峂B';
 comment on column lf.sys_download.dcount is '涓嬭浇娆℃暟';
diff --git a/src/main/java/com/lf/server/controller/sys/ReportController.java b/src/main/java/com/lf/server/controller/sys/ReportController.java
index b44c6f4..1ac223a 100644
--- a/src/main/java/com/lf/server/controller/sys/ReportController.java
+++ b/src/main/java/com/lf/server/controller/sys/ReportController.java
@@ -185,10 +185,10 @@
     @SysLog()
     @ApiOperation(value = "涓嬭浇鎶ュ憡")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "guid", value = "闄勪欢Guid", dataType = "String", paramType = "body")
+            @ApiImplicitParam(name = "id", value = "鎶ュ憡ID", dataType = "Integer", paramType = "7")
     })
     @GetMapping(value = "/downloadReport")
-    public void downloadReport(Integer id, HttpServletResponse res) {
+    public void downloadReport(Integer id, HttpServletRequest req, HttpServletResponse res) {
         try {
             if (null == id || id < 1) {
                 return;
@@ -199,7 +199,9 @@
                 return;
             }
 
-            reportService.createReport(re, res);
+            UserEntity ue = tokenService.getCurrentUser(req);
+
+            reportService.createReport(ue, re, res);
         } catch (Exception ex) {
             log.error(ex.getMessage(), ex);
         }
diff --git a/src/main/java/com/lf/server/entity/all/StaticData.java b/src/main/java/com/lf/server/entity/all/StaticData.java
index 250f375..1206898 100644
--- a/src/main/java/com/lf/server/entity/all/StaticData.java
+++ b/src/main/java/com/lf/server/entity/all/StaticData.java
@@ -55,6 +55,11 @@
     public static final double D1050 = 1050.0;
 
     /**
+     * 瀛楃1
+     */
+    public final static String S1 = "1";
+
+    /**
      * 绛夊彿
      */
     public final static String EQ = "=";
diff --git a/src/main/java/com/lf/server/service/sys/ReportService.java b/src/main/java/com/lf/server/service/sys/ReportService.java
index df5813e..cb77083 100644
--- a/src/main/java/com/lf/server/service/sys/ReportService.java
+++ b/src/main/java/com/lf/server/service/sys/ReportService.java
@@ -1,10 +1,14 @@
 package com.lf.server.service.sys;
 
+import com.lf.server.entity.all.StaticData;
 import com.lf.server.entity.ctrl.CountEntity;
+import com.lf.server.entity.data.DownloadEntity;
 import com.lf.server.entity.sys.AttachEntity;
 import com.lf.server.entity.sys.ReportEntity;
+import com.lf.server.entity.sys.UserEntity;
 import com.lf.server.helper.*;
 import com.lf.server.mapper.sys.ReportMapper;
+import com.lf.server.service.data.DownloadService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -28,6 +32,9 @@
 
     @Autowired
     PathHelper pathHelper;
+
+    @Autowired
+    DownloadService downloadService;
 
     @Override
     public Integer selectCount(String name) {
@@ -101,7 +108,7 @@
     /**
      * 鍒涘缓鎶ュ憡
      */
-    public void createReport(ReportEntity re, HttpServletResponse res) throws Exception {
+    public void createReport(UserEntity ue, ReportEntity re, HttpServletResponse res) throws Exception {
         AttachEntity ae = attachService.selectByGuid(re.getGuid());
         if (null == ae) {
             return;
@@ -109,7 +116,7 @@
 
         String source = pathHelper.getConfig().getUploadPath() + File.separator + ae.getPath();
         String targetName = StringHelper.YMDHMS2_FORMAT.format(new Date()) + FileHelper.getExtension(ae.getName());
-        String target = pathHelper.getShareFullPath() + File.separator + targetName;
+        String target = pathHelper.getDownloadFullPath() + File.separator + targetName;
 
         File sourceFile = new File(source);
         if (!sourceFile.exists() || sourceFile.isDirectory()) {
@@ -122,14 +129,18 @@
             return;
         }
 
-        WebHelper.download(target, targetName, res);
+        DownloadEntity de = getDownloadEntity(ue, target);
+        int rows = downloadService.insert(de);
+        if (rows > 0) {
+            WebHelper.download(target, targetName, res);
+        }
     }
 
     /**
      * 鐢熸垚鎶ュ憡
      */
     private void generateReport(String source, String target, ReportEntity re) {
-        if ("1".equals(re.getType())) {
+        if (StaticData.S1.equals(re.getType())) {
             switch (re.getCode()) {
                 case "countOperates ":
                     createCountOperatesWord(source, target);
@@ -202,4 +213,24 @@
 
         WordHelper.generateWord(source, target, null, addList);
     }
+
+    /**
+     * 鑾峰彇涓嬭浇瀹炰綋绫�
+     */
+    private DownloadEntity getDownloadEntity(UserEntity ue, String file) {
+        DownloadEntity de = new DownloadEntity();
+        de.setName(FileHelper.getFileName(file));
+        de.setType(6);
+        de.setSizes(FileHelper.sizeToMb(new File(file).length()));
+        de.setDepid(ue.getDepid());
+        de.setDcount(1);
+        de.setPwd(null);
+        de.setUrl(FileHelper.getRelativePath(file));
+        de.setDescr("缁熻鎶ュ憡");
+        de.setGuid(FileHelper.getFileMd5(file));
+        de.setCreateUser(ue.getId());
+        // de.setGeom(null)
+
+        return de;
+    }
 }

--
Gitblit v1.9.3