|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|