瀏覽代碼

操作日志下载

wangggziwen 2 年之前
父節點
當前提交
a18e6bfcd0

+ 1 - 0
master/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -127,6 +127,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .antMatchers("/sems/historyYlrq/exportPDFForYear").anonymous()
                 .antMatchers("/sems/historyYlgd/exportPDFForYear").anonymous()
                 .antMatchers("/invoice/bookingworkticket/word").anonymous()
+                .antMatchers("/monitor/log/download").anonymous()
 
                 // 除上面外的所有请求全部需要鉴权认证
                 .anyRequest().authenticated()

+ 39 - 0
master/src/main/java/com/ruoyi/project/monitor/controller/SysLogController.java

@@ -1,14 +1,20 @@
 package com.ruoyi.project.monitor.controller;
 
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.file.FileUtils;
 import com.ruoyi.framework.web.controller.BaseController;
 import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.project.monitor.domain.SysLog;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.*;
 import org.w3c.dom.Document;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import java.io.*;
@@ -25,6 +31,9 @@ import java.util.List;
 @RestController
 @RequestMapping("/monitor/log")
 public class SysLogController extends BaseController {
+
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
     /**
      * 查询操作日志列表
      *
@@ -89,4 +98,34 @@ public class SysLogController extends BaseController {
         }
         return AjaxResult.success(logList);
     }
+
+    /**
+     * 下载操作日志
+     *
+     * @param fileName 文件名称
+     * @param fileUrl 文件路径
+     */
+    @GetMapping("/download")
+    public void logFileDownload(String fileName, String fileUrl, HttpServletResponse response, HttpServletRequest request)
+    {
+        try
+        {
+            if (!FileUtils.isValidFilename(fileName))
+            {
+                throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
+            }
+            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
+
+            response.setCharacterEncoding("utf-8");
+            response.setContentType("multipart/form-data");
+            response.setHeader("Content-Disposition",
+                    "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
+            FileUtils.writeBytes(fileUrl, response.getOutputStream());
+        }
+        catch (Exception e)
+        {
+            logger.error("下载文件失败", e);
+        }
+    }
+
 }

+ 4 - 4
ui/src/views/monitor/log/index.vue

@@ -3,7 +3,7 @@
     <el-row :gutter="10" class="mb8">
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
-    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
+    <el-table v-loading="loading" :data="list">
       <el-table-column type="selection" width="55" align="center" />
       <el-table-column :label="$t('文件名')" align="center" prop="fileName" />
       <el-table-column :label="$t('文件路径')" align="center" prop="fileUrl" />
@@ -22,7 +22,7 @@
 </template>
 
 <script>
-import { list, download } from "@/api/monitor/log";
+import { list } from "@/api/monitor/log";
 
 export default {
   name: "Log",
@@ -52,9 +52,9 @@ export default {
     this.getList();
   },
   methods: {
-    /** 操作日志下载处理 */
+    /** 下载操作日志 */
     handleDownload(row) {
-      alert("功能开发中");
+      window.location.href = process.env.VUE_APP_BASE_API + "/monitor/log/download?fileName=" + encodeURI(row.fileName) + "&fileUrl=" + encodeURI(row.fileUrl);
     },
     /** 查询操作日志 */
     getList() {