Преглед изворни кода

Merge remote-tracking branch 'origin/master'

ly пре 2 година
родитељ
комит
ea5d80dcfa

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

@@ -0,0 +1,92 @@
+package com.ruoyi.project.monitor.controller;
+
+import com.ruoyi.framework.web.controller.BaseController;
+import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.project.monitor.domain.SysLog;
+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.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 操作日志记录
+ *
+ * @author Wang Zi Wen
+ * @email wangggziwen@163.com
+ * @date 2023/04/25 15:47:42
+ */
+@RestController
+@RequestMapping("/monitor/log")
+public class SysLogController extends BaseController {
+    /**
+     * 查询操作日志列表
+     *
+     * @return 操作日志列表
+     */
+    @GetMapping("/list")
+    public AjaxResult list()
+    {
+        String filePath = null;
+        //1、创建一个DocumentBuilderFactory的对象
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        //2、创建一个DocumentBuilder的对象
+        try {
+            //创建DocumentBuilder对象
+            DocumentBuilder db = dbf.newDocumentBuilder();
+            //3、通过DocumentBuilder对象的parser方法加载books.xml文件到当前项目下
+            /*注意导入Document对象时,要导入org.w3c.dom.Document包下的*/
+            Document document = db.parse("master/src/main/resources/logback.xml");//传入文件名可以是相对路径也可以是绝对路径
+            //获取所有property节点的集合
+            NodeList nodeList = document.getElementsByTagName("property");
+            //遍历每一个nodelist节点
+            for (int i = 0; i < nodeList.getLength(); i++) {
+                //未知节点属性的个数和属性名时:
+                //通过 item(i)方法 获取一个节点,nodelist的索引值从0开始
+                Node node = nodeList.item(i);
+                //获取节点的所有属性集合
+                NamedNodeMap attrs = node.getAttributes();
+                //遍历节点的属性
+                for (int j = 0; j < attrs.getLength(); j++) {
+                    //通过item(index)方法获取节点的某一个属性
+                    Node attr = attrs.item(j);
+                    NodeList childNodes = attr.getChildNodes();
+                    int indexI = 0;
+                    int indexJ = 0;
+                    int indexK = 0;
+                    for (int k = 0; k < childNodes.getLength(); k++) {
+                        Node item = childNodes.item(k);
+                        String nodeValue = item.getNodeValue();
+                        if (nodeValue.equals("log.path")) {
+                            indexI = i;
+                            indexJ = j;
+                            indexK = k;
+                        }
+                        if (i == indexI && j == (indexJ + 1) && k == indexK) {
+                            filePath = nodeValue;
+                        }
+                    }
+                }
+            }
+            System.out.println(filePath);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        File file = new File(filePath);//父级文件夹
+        String[] fileNameList = file.list();//文件名列表
+        List<SysLog> logList = new ArrayList<>();//日志信息列表
+        for (String fileName : fileNameList) {
+            SysLog sysLog = new SysLog();
+            sysLog.setFileName(fileName);//文件名
+            sysLog.setFileUrl(file.getAbsolutePath() + "\\" + fileName);//绝对路径
+            logList.add(sysLog);
+        }
+        return AjaxResult.success(logList);
+    }
+}

+ 41 - 0
master/src/main/java/com/ruoyi/project/monitor/domain/SysLog.java

@@ -0,0 +1,41 @@
+package com.ruoyi.project.monitor.domain;
+
+import com.ruoyi.framework.web.domain.BaseEntity;
+
+/**
+ * @author Wang Zi Wen
+ * @email wangggziwen@163.com
+ * @date 2023/04/25 15:50:21
+ */
+public class SysLog extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    private String fileName;
+
+    private String fileUrl;
+
+    public String getFileName() {
+        return fileName;
+    }
+
+    public void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    public String getFileUrl() {
+        return fileUrl;
+    }
+
+    public void setFileUrl(String fileUrl) {
+        this.fileUrl = fileUrl;
+    }
+
+    @Override
+    public String toString() {
+        return "SysLog{" +
+                "fileName='" + fileName + '\'' +
+                ", fileUrl='" + fileUrl + '\'' +
+                '}';
+    }
+}

+ 9 - 0
ui/src/api/monitor/log.js

@@ -0,0 +1,9 @@
+import request from '@/utils/request'
+
+// 查询操作日志列表
+export function list() {
+  return request({
+    url: '/monitor/log/list',
+    method: 'get',
+  })
+}

+ 72 - 0
ui/src/views/monitor/log/index.vue

@@ -0,0 +1,72 @@
+<template>
+  <div class="app-container">
+    <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-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" />
+      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width">
+        <template slot-scope="scope">
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-download"
+            @click="handleDownload(scope.row)"
+          >{{ $t('下载') }}</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+  </div>
+</template>
+
+<script>
+import { list, download } from "@/api/monitor/log";
+
+export default {
+  name: "Log",
+  data() {
+    return {
+      // 遮罩层
+      loading: true,
+      // 选中数组
+      ids: [],
+      // 非多个禁用
+      multiple: true,
+      // 显示搜索条件
+      showSearch: true,
+      // 总条数
+      total: 0,
+      // 表格数据
+      list: [],
+      // 是否显示弹出层
+      open: false,
+      // 表单参数
+      form: {},
+      // 查询参数
+      queryParams: {}
+    };
+  },
+  created() {
+    this.getList();
+  },
+  methods: {
+    /** 操作日志下载处理 */
+    handleDownload(row) {
+      alert("功能开发中");
+    },
+    /** 查询操作日志 */
+    getList() {
+      this.loading = true;
+      list().then(response => {
+          this.list = response.data;
+          this.total = response.total;
+          this.loading = false;
+        }
+      );
+    },
+  }
+};
+</script>
+