Просмотр исходного кода

日志管理功能代码提交

jingyuanchao 1 год назад
Родитель
Сommit
3ddca0be29

+ 12 - 12
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysServerController.java

@@ -29,9 +29,7 @@ public class SysServerController extends BaseController {
     @Autowired
     private ISysServerService sysServerService;
 
-    /**
-     * 查询服务器维护列表
-     */
+
     @ApiOperation(value = "查询SysServer列表")
     //@RequiresPermissions("system:server:list")
     @GetMapping("/list")
@@ -39,9 +37,7 @@ public class SysServerController extends BaseController {
         return sysServerService.selectPage(req);
     }
 
-    /**
-     * 获取服务器维护详细信息
-     */
+
     @ApiOperation(value = "获取SysServer详细信息")
     //@RequiresPermissions("system:server:query")
     @GetMapping(value = "/{id}")
@@ -49,9 +45,7 @@ public class SysServerController extends BaseController {
         return success(sysServerService.selectSysServerById(id));
     }
 
-    /**
-     * 新增服务器维护
-     */
+
     @ApiOperation(value = "新增SysServer")
     //@RequiresPermissions("system:server:add")
     @Log(title = "服务器维护", businessType = BusinessType.INSERT)
@@ -60,9 +54,7 @@ public class SysServerController extends BaseController {
         return toAjax(sysServerService.editSysServer(req));
     }
 
-    /**
-     * 删除服务器维护
-     */
+
     @ApiOperation(value = "删除SysServer")
     //@RequiresPermissions("system:server:remove")
     @Log(title = "服务器维护", businessType = BusinessType.DELETE)
@@ -71,10 +63,18 @@ public class SysServerController extends BaseController {
         return toAjax(sysServerService.deleteSysServerByIds(ids));
     }
 
+
     @ApiOperation(value = "获取服务下的日志")
     @GetMapping("/getLogList/{serverId}/{checkId}")
     public AjaxResult getLogList(@PathVariable Long serverId, @PathVariable Long checkId) {
         Object logs = sysServerService.getLogList(serverId,checkId);
         return success(logs);
     }
+
+    @ApiOperation(value = "转存目标服务器上的日志")
+    @GetMapping("/transferLog/{serverId}/{checkId}")
+    public AjaxResult transferLog(@PathVariable Long serverId, @PathVariable Long checkId) {
+        Object logs = sysServerService.getLogList(serverId,checkId);
+        return success(logs);
+    }
 }

+ 17 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/dto/server/TransferLogDto.java

@@ -0,0 +1,17 @@
+package com.xunmei.system.dto.server;
+
+import lombok.Data;
+
+/**
+ * @author jingyuanchao
+ * @date 2024/10/10 17:37
+ */
+@Data
+public class TransferLogDto {
+
+    private Long serverId;
+
+    private String parentPath;
+    private String path;
+    private String rootDir;
+}

+ 27 - 8
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysServerServiceImpl.java

@@ -1,7 +1,9 @@
 package com.xunmei.system.service.impl;
 
+import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.http.HttpException;
+import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson2.JSONArray;
@@ -93,9 +95,6 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
     public List<CheckListVo> getServerList(Long serverId) {
         try {
             SysServer server = this.selectSysServerById(serverId);
-            server.setServerToken("d033e22ae348aeb5660fc2140aec35850c4da997");
-            server.setServerIp("10.87.10.196");
-            server.setServerPort(8091);
             String baseUrl = String.format("http://%s:%d", server.getServerIp(), server.getServerPort());
             String getServicesApi = "/result/list?size=10000&current=1";
             HttpResponse response = HttpUtil.createPost(baseUrl + getServicesApi)
@@ -112,13 +111,8 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
 
     @Override
     public Object getLogList(Long serverId, Long checkId) {
-        // http://10.87.10.196:8091/index1.html?token=d033e22ae348aeb5660fc2140aec35850c4da997
         SysServer server = this.selectSysServerById(serverId);
 
-        server.setServerToken("d033e22ae348aeb5660fc2140aec35850c4da997");
-        server.setServerIp("10.87.10.196");
-        server.setServerPort(8091);
-
         String baseUrl = String.format("http://%s:%d", server.getServerIp(), server.getServerPort());
         String getLogs = "/result/fileList?checkId=" + checkId;
         //获取服务器列表
@@ -132,6 +126,31 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
         return checks;
     }
 
+    public static void saveRemoteLogToLocal() {
+        String path = "your_path";
+        String parentPath = "your_parent_path";
+        String rootDir = "your_root_dir";
+        String downloadUrl = "http://your_server/fileDownload?path=" + path + "&parentPath=" + parentPath + "&rootDir=" + rootDir;
+
+        try {
+            final HttpRequest request = HttpUtil.createGet(downloadUrl);
+            HttpResponse response = request.execute();
+
+            // Check if the request was successful
+            if (response.getStatus() == 200) {
+                String fileName = response.header("Content-Disposition");
+                fileName = fileName.substring(fileName.indexOf("filename=") + 10, fileName.length() - 1);
+
+                // Save the file
+                FileUtil.writeBytes(response.bodyBytes(), fileName);
+                System.out.println("File downloaded successfully: " + fileName);
+            } else {
+                System.out.println("No file to download. Server replied HTTP code: " + response.getStatus());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
     /**
      * 查询服务器维护