Browse Source

Merge branch 'V0.1.1_alarm' of http://10.87.21.221:8000/jzyd_yyds/soc into V0.1.1_alarm

jiawuxian 1 year ago
parent
commit
18196a63e9
17 changed files with 349 additions and 40 deletions
  1. 10 3
      project_data/sql/0.1.1/soc/soc.sql
  2. 12 0
      soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteFileService.java
  3. 19 0
      soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteFileFallbackFactory.java
  4. 17 0
      soc-common/soc-common-core/src/main/java/com/xunmei/common/core/domain/file/dto/FileDownloadDto.java
  5. 18 0
      soc-common/soc-common-core/src/main/java/com/xunmei/common/core/domain/file/dto/FileUploadByByteDto.java
  6. 2 2
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/drill/service/impl/CoreDrillPlanServiceImpl.java
  7. 2 2
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/edu/service/impl/CoreEduTrainingPlanServiceImpl.java
  8. 21 0
      soc-modules/soc-modules-file/src/main/java/com/xunmei/file/controller/SysFileController.java
  9. 9 0
      soc-modules/soc-modules-file/src/main/java/com/xunmei/file/service/ISysFileService.java
  10. 64 9
      soc-modules/soc-modules-file/src/main/java/com/xunmei/file/service/LocalSysFileServiceImpl.java
  11. 5 1
      soc-modules/soc-modules-host/src/main/java/com/xunmei/host/iot/service/impl/IotDeviceInfoServiceImpl.java
  12. 1 1
      soc-modules/soc-modules-host/src/main/java/com/xunmei/host/notice/service/impl/WebsocketNoticeLogServiceImpl.java
  13. 21 12
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysServerController.java
  14. 17 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/dto/server/TransferLogDto.java
  15. 6 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysServerService.java
  16. 118 10
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysServerServiceImpl.java
  17. 7 0
      soc-modules/soc-modules-system/src/main/java/com/xunmei/system/vo/server/FileInfoVo.java

+ 10 - 3
project_data/sql/0.1.1/soc/soc.sql

@@ -1201,7 +1201,7 @@ CREATE TABLE `core_notice_rule_item` (
                                          `rule_id` bigint NOT NULL COMMENT '通知规则id',
                                          `org_id` bigint NOT NULL COMMENT '接收消息的组织机构id',
                                          `role_id` bigint DEFAULT NULL COMMENT '角色id',
-                                         `user_ids` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
+                                         `user_ids` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
                                          `send_sms` int DEFAULT NULL COMMENT '是否发送短信:0.否 1.是',
                                          `all_role_user` int NOT NULL DEFAULT '0' COMMENT '是否选择角色下所有用户:0.否 1.是',
                                          `product_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '传感器产品名称',
@@ -1223,7 +1223,7 @@ CREATE TABLE `websocket_notice_log` (
                                         `id` bigint NOT NULL,
                                         `iot_alarm_id` bigint DEFAULT NULL,
                                         `org_id` bigint DEFAULT NULL,
-                                        `user_ids` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
+                                        `user_ids` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
                                         `is_do` int DEFAULT NULL COMMENT '是否处理:0.否 1.是',
                                         `create_time` datetime DEFAULT NULL COMMENT '创建时间',
                                         `deal_time` datetime DEFAULT NULL COMMENT '处理时间',
@@ -1303,6 +1303,7 @@ INSERT INTO `iot_alarm_system_field` (`product_type`, `product_name`, `product_p
 
 
 -- 新增日志管理菜单(管理员使用功能)
+delete from sys_menu where id=01843936562189307906;
 INSERT INTO `sys_menu`(`id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `platform_type`, `icon`, `image_path`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (01843936562189307906, '日志管理', 2, 99, 'logManagement', 'system/logManagement/index', NULL, 1, 0, 'C', '0', '0', NULL, '1', 'server', NULL, '超级管理员', '2024-10-09 16:48:29', '', NULL, '');
 drop table if exists `sys_server`;
 CREATE TABLE `sys_server` (
@@ -1365,4 +1366,10 @@ BEGIN
 
 END??
 DELIMITER ;
-CALL schema_change();
+CALL schema_change();
+
+-- 通知规则菜单
+delete from sys_menu where id=01836604852290682881;
+INSERT INTO `sys_menu`(`id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `platform_type`, `icon`, `image_path`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (01836604852290682881, '通知规则', 1, 100, 'notice', 'notice/index', NULL, 1, 0, 'C', '0', '0', NULL, '1', 'skill', NULL, '超级管理员', '2024-09-19 11:15:37', '', NULL, '');
+
+

+ 12 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteFileService.java

@@ -2,6 +2,8 @@ package com.xunmei.system.api;
 
 import com.xunmei.common.core.constant.ServiceNameConstants;
 import com.xunmei.common.core.domain.R;
+import com.xunmei.common.core.domain.file.dto.FileDownloadDto;
+import com.xunmei.common.core.domain.file.dto.FileUploadByByteDto;
 import com.xunmei.common.core.domain.registerbook.dto.CoreRegisterBookPdfExportDto;
 import com.xunmei.common.core.domain.registerbook.dto.ExportPdfDto;
 import com.xunmei.system.api.domain.AccessPdf;
@@ -14,6 +16,7 @@ import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -103,4 +106,13 @@ public interface RemoteFileService {
 
     @PostMapping(value = "/file/deleted")
     void deletedFile(@RequestBody Map<String,String> data);
+
+    @PostMapping(value = "/file/uploadFileByte")
+    void uploadFileByte(@RequestBody FileUploadByByteDto fileUploadByByteDto);
+
+    @GetMapping(value = "/file/checkFileExit")
+    List<String> checkFileExit(@RequestParam("serverName") String serverName);
+
+    @PostMapping(value = "/file/downloadLogData", consumes = MediaType.APPLICATION_JSON_VALUE)
+    Response downloadLogData(@RequestBody FileDownloadDto req);
 }

+ 19 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteFileFallbackFactory.java

@@ -2,6 +2,8 @@ package com.xunmei.system.api.factory;
 
 import com.alibaba.fastjson2.JSON;
 import com.xunmei.common.core.domain.R;
+import com.xunmei.common.core.domain.file.dto.FileDownloadDto;
+import com.xunmei.common.core.domain.file.dto.FileUploadByByteDto;
 import com.xunmei.common.core.domain.registerbook.dto.CoreRegisterBookPdfExportDto;
 import com.xunmei.common.core.domain.registerbook.dto.ExportPdfDto;
 import com.xunmei.system.api.RemoteFileService;
@@ -15,6 +17,8 @@ import org.springframework.cloud.openfeign.FallbackFactory;
 import org.springframework.stereotype.Component;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -106,6 +110,21 @@ public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileServ
             public void deletedFile(Map<String, String> data) {
 
             }
+
+            @Override
+            public void uploadFileByte(FileUploadByByteDto fileUploadByByteDto) {
+
+            }
+
+            @Override
+            public List<String> checkFileExit(String serverName) {
+                return new ArrayList<>();
+            }
+
+            @Override
+            public Response downloadLogData(FileDownloadDto req) {
+                return null;
+            }
         };
     }
 }

+ 17 - 0
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/domain/file/dto/FileDownloadDto.java

@@ -0,0 +1,17 @@
+package com.xunmei.common.core.domain.file.dto;
+
+import lombok.Data;
+
+/**
+ * @author jingyuanchao
+ * @date 2024/10/11 10:05
+ */
+@Data
+public class FileDownloadDto {
+
+    private String fileName;
+
+    private String filePath;
+
+    private String serverName;
+}

+ 18 - 0
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/domain/file/dto/FileUploadByByteDto.java

@@ -0,0 +1,18 @@
+package com.xunmei.common.core.domain.file.dto;
+
+import lombok.Data;
+
+/**
+ * @author jingyuanchao
+ * @date 2024/10/11 10:05
+ */
+@Data
+public class FileUploadByByteDto {
+    private byte[] fileByte;
+
+    private String fileName;
+
+    private String filePath;
+
+    private String serverName;
+}

+ 2 - 2
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/drill/service/impl/CoreDrillPlanServiceImpl.java

@@ -513,12 +513,12 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
             removeById(id);
             return;
         }
-        Integer isExecute = coreDrillTaskMapper.selectCount(new LambdaQueryWrapper<CoreDrillTask>()
+        int isExecute = coreDrillTaskMapper.selectCount(new LambdaQueryWrapper<CoreDrillTask>()
                         .in(CoreDrillTask::getPlanId, list)
                         .eq(CoreDrillTask::getStatus, DrillDoStatus.DONE.getCode()))
                 .intValue();
         list.add(id);
-        if (ObjectUtil.notEqual(isExecute, 1)) {
+        if (isExecute < 1) {
             // 计划下没有已完成:删除所有任务,计划数据做物理删除。
             coreDrillTaskService.delByStartTimeAndEndTimeAndPlanIdList(list, null, null);
             coreDrillPlanMapper.delByIds(list);

+ 2 - 2
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/edu/service/impl/CoreEduTrainingPlanServiceImpl.java

@@ -498,12 +498,12 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
             removeById(id);
             return;
         }
-        Integer isExecute = coreEduTrainingTaskMapper.selectCount(new LambdaQueryWrapper<CoreEduTrainingTask>()
+        int isExecute = coreEduTrainingTaskMapper.selectCount(new LambdaQueryWrapper<CoreEduTrainingTask>()
                         .in(CoreEduTrainingTask::getPlanId, list)
                         .eq(CoreEduTrainingTask::getStatus, EduTrainingDoStatus.DONE.getCode()))
                 .intValue();
         list.add(id);
-        if (ObjectUtil.notEqual(isExecute, 1)) {
+        if (isExecute < 1) {
             // 计划下没有已完成:删除所有任务,计划数据做物理删除。
             coreEduTrainingTaskService.delByStartTimeAndEndTimeAndPlanIdList(list, null, null);
             coreEduTrainingPlanMapper.delByIds(list);

+ 21 - 0
soc-modules/soc-modules-file/src/main/java/com/xunmei/file/controller/SysFileController.java

@@ -2,6 +2,8 @@ package com.xunmei.file.controller;
 
 import cn.hutool.core.util.ObjectUtil;
 import com.xunmei.common.core.domain.R;
+import com.xunmei.common.core.domain.file.dto.FileDownloadDto;
+import com.xunmei.common.core.domain.file.dto.FileUploadByByteDto;
 import com.xunmei.common.core.domain.registerbook.dto.CoreRegisterBookPdfExportDto;
 import com.xunmei.common.core.domain.registerbook.dto.ExportPdfDto;
 import com.xunmei.common.core.utils.file.FileUtils;
@@ -21,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
@@ -246,4 +249,22 @@ public class SysFileController {
         }
         sysFileService.deletedFileByPath(filePath);
     }
+
+    @PostMapping(value = "/uploadFileByte")
+    void uploadFileByte(@RequestBody FileUploadByByteDto fileUploadByByteDto){
+        sysFileService.uploadFileByte(fileUploadByByteDto);
+    }
+
+    @GetMapping(value = "/checkFileExit")
+    List<String> checkFileExit(@RequestParam("serverName") String serverName){
+        return sysFileService.checkFileExit(serverName);
+    }
+    @PostMapping(value = "/downloadLogData")
+    void downloadLogData(@RequestBody FileDownloadDto req,HttpServletResponse response){
+        try {
+            sysFileService.downloadLogData(req,response);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
 }

+ 9 - 0
soc-modules/soc-modules-file/src/main/java/com/xunmei/file/service/ISysFileService.java

@@ -1,5 +1,7 @@
 package com.xunmei.file.service;
 
+import com.xunmei.common.core.domain.file.dto.FileDownloadDto;
+import com.xunmei.common.core.domain.file.dto.FileUploadByByteDto;
 import com.xunmei.common.core.domain.registerbook.dto.CoreRegisterBookPdfExportDto;
 import com.xunmei.common.core.domain.registerbook.dto.ExportPdfDto;
 import com.xunmei.file.vo.FileBase64Vo;
@@ -10,6 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -82,4 +85,10 @@ public interface ISysFileService
 
     void deletedFileByPath(String filePath);
 
+    void uploadFileByte(FileUploadByByteDto fileUploadByByteDto);
+
+    List<String> checkFileExit(String serverName);
+
+    void downloadLogData(FileDownloadDto req, HttpServletResponse response);
+
 }

+ 64 - 9
soc-modules/soc-modules-file/src/main/java/com/xunmei/file/service/LocalSysFileServiceImpl.java

@@ -14,6 +14,8 @@ import com.lowagie.text.pdf.PdfPTable;
 import com.lowagie.text.pdf.PdfWriter;
 import com.xunmei.common.core.constant.CacheConstants;
 import com.xunmei.common.core.domain.IdName;
+import com.xunmei.common.core.domain.file.dto.FileDownloadDto;
+import com.xunmei.common.core.domain.file.dto.FileUploadByByteDto;
 import com.xunmei.common.core.domain.registerbook.dto.CoreRegisterBookPdfExportDto;
 import com.xunmei.common.core.domain.registerbook.dto.ExportPdfDto;
 import com.xunmei.common.core.domain.registerbook.vo.CoreRegisterBookPdfPageVo;
@@ -34,6 +36,7 @@ import com.xunmei.system.api.domain.SafeCheckTaskRegisterBookVo;
 import com.xunmei.system.api.vo.SysOrgVO;
 import io.netty.util.internal.StringUtil;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.text.StringEscapeUtils;
 import org.apache.tools.zip.ZipEntry;
@@ -83,6 +86,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
     private static final Logger log = LoggerFactory.getLogger(LocalSysFileServiceImpl.class);
 
     public static final String TEMP_DIR_NAME = "registerBookPdfBatchExportTempDir";
+    public static final String LOGS_DIR = "/log";
 
     @Value("${file.path}")
     private String localFilePath;
@@ -167,7 +171,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
     }
 
     @Override
-    public void downloadFile(HttpServletResponse response, String filePath,String realName) {
+    public void downloadFile(HttpServletResponse response, String filePath, String realName) {
         ByteArrayOutputStream out = null;
         try {
             filePath = localFilePath + filePath;
@@ -175,7 +179,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
             out = FileDownUtils.downloadFile(filePath);
             String fileSuffix = FileDownUtils.getFileSuffix(filePath);
             String formFileName = UUID.randomUUID().toString() + fileSuffix;
-            if (StringUtils.isNotEmpty(realName)){
+            if (StringUtils.isNotEmpty(realName)) {
                 formFileName = realName;
             }
             String userAgent = request.getHeader("User-Agent");
@@ -335,11 +339,10 @@ public class LocalSysFileServiceImpl implements ISysFileService {
         PdfUtil.createPDFCell(titleFont, table, "调阅人签字", Element.ALIGN_MIDDLE, 4, 1);
         List<String> list = new ArrayList<>();
         list.add(data.getSignImg());
-        dealImageCell(list, table, 1, 80, 30,15,1);
+        dealImageCell(list, table, 1, 80, 30, 15, 1);
 
         PdfUtil.createPDFCell(titleFont, table, data.getTaskTimes(), Element.ALIGN_MIDDLE, 19, 1);
-        PdfUtil.dealAccessTimes(document,table, tableFont, titleFont,data.getTimes());
-
+        PdfUtil.dealAccessTimes(document, table, tableFont, titleFont, data.getTimes());
 
 
         PdfUtil.createPDFCell(titleFont, table, "监控调阅情况", Element.ALIGN_MIDDLE, 19, 1);
@@ -958,17 +961,18 @@ public class LocalSysFileServiceImpl implements ISysFileService {
     @Override
     public void deletedFileByPath(String filePath) {
         File file = new File(getAbsolutePath(filePath));
-        if (file.exists()){
+        if (file.exists()) {
             file.delete();
         }
 
     }
+
     //把 /static开头的地址 转换成绝对地址
-    private String getAbsolutePath(String filePath){
-        if (ObjectUtil.isEmpty(filePath)){
+    private String getAbsolutePath(String filePath) {
+        if (ObjectUtil.isEmpty(filePath)) {
             return StringUtil.EMPTY_STRING;
         }
-        if (!filePath.startsWith(this.prefix)){
+        if (!filePath.startsWith(this.prefix)) {
             return StringUtil.EMPTY_STRING;
         }
         String path = filePath.replace(this.prefix, "");
@@ -1014,7 +1018,58 @@ public class LocalSysFileServiceImpl implements ISysFileService {
                 return r;
             }
         }
+    }
 
 
+    @Override
+    public void uploadFileByte(FileUploadByByteDto fileUploadByByteDto) {
+        final String currentServerLogDir = localFilePath + LOGS_DIR + File.separator + fileUploadByByteDto.getServerName() + File.separator + fileUploadByByteDto.getFilePath();
+        final File file = new File(currentServerLogDir);
+        if (!file.exists()) {
+            file.mkdirs();
+        }
+        FileUtil.writeBytes(fileUploadByByteDto.getFileByte(), currentServerLogDir + File.separator + fileUploadByByteDto.getFileName());
+    }
+
+    @Override
+    public List<String> checkFileExit(String serverName) {
+        List<String> exitFileList = new ArrayList<>();
+        final File file = new File(localFilePath + LOGS_DIR + File.separator + serverName);
+
+        listFiles(file, exitFileList);
+
+        return exitFileList;
+    }
+
+    private static void listFiles(File file, List<String> fileList) {
+        if (file.isDirectory()) {
+            File[] files = file.listFiles();
+            if (files != null) {
+                for (File f : files) {
+                    listFiles(f, fileList);
+                }
+            }
+        } else {
+            fileList.add(file.getAbsolutePath());
+        }
+    }
+
+    //D:/xunmei/uploadPath\/log\10.87.21.155\/soc-host/socketDeviceStatusInfo\2024-10-09-0.log
+    @Override
+    public void downloadLogData(FileDownloadDto req, HttpServletResponse response) {
+        final String fileName = this.localFilePath + File.separator + LOGS_DIR + File.separator + req.getServerName() + File.separator + req.getFilePath() + File.separator + req.getFileName();
+        final File file = new File(fileName);
+        if (!file.exists()) {
+            throw new RuntimeException("文件不存在");
+        }
+        try (InputStream inputStream = new FileInputStream(file)) {
+            byte[] bytes = IOUtils.toByteArray(inputStream);
+            response.setContentType("application/octet-stream");
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(req.getFileName(), "UTF-8"));
+            response.setContentLength(bytes.length);
+            response.getOutputStream().write(bytes);
+        } catch (Exception e) {
+            throw new RuntimeException("文件下载失败");
+        }
     }
 }

+ 5 - 1
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/iot/service/impl/IotDeviceInfoServiceImpl.java

@@ -531,9 +531,13 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
             if (ObjectUtil.isEmpty(subDeviceList)) {
                 continue;
             }
+            final ArrayList<Object> list = new ArrayList<>();
+            list.add("FSU_DoPowerControlBoxButton");
+            list.add("FSU_DoPowerCollection");
             //处理通道或者动环传感器信息
             for (SubDeviceInfo subDeviceInfo : subDeviceList) {
-                boolean isFusDevice = ProductEnums.FSU_GATEWAY.getProductName().contains(dvsBaseInfo.getProductName());
+                //动环中 控电箱按钮与 市电总回路/八小时总回路通电状态不同步
+                boolean isFusDevice = ProductEnums.FSU_GATEWAY.getProductName().contains(dvsBaseInfo.getProductName()) && (!list.contains(dvsBaseInfo.getProductName()));
                 String productName = isFusDevice ? subDeviceInfo.getType() : dvsBaseInfo.getProductName();
                 IotDeviceInfo channelInfo = selectByTypeAndHostAndCode(serverInfo.getIotCode(), subDeviceInfo.getParentCode(), productName, subDeviceInfo.getDeviceCode());
 

+ 1 - 1
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/notice/service/impl/WebsocketNoticeLogServiceImpl.java

@@ -56,7 +56,7 @@ public class WebsocketNoticeLogServiceImpl extends ServiceImpl<WebsocketNoticeLo
         if(ObjectUtil.isNotEmpty(websocketNoticeLog)){
             WebSocketNoticeVo noticeVo = new WebSocketNoticeVo();
             noticeVo.setIotAlarmDataId(iotAlarmData.getId());
-            noticeVo.setIsDo(0);
+            noticeVo.setIsDo(1);
             noticeVo.setOrgId(deviceInfo.getOrgId());
 
             String userIds = websocketNoticeLog.getUserIds();

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

@@ -7,6 +7,7 @@ import com.xunmei.common.log.annotation.Log;
 import com.xunmei.common.log.enums.BusinessType;
 import com.xunmei.system.dto.server.SysServerEditDto;
 import com.xunmei.system.dto.server.SysServerPageDto;
+import com.xunmei.system.dto.server.TransferLogDto;
 import com.xunmei.system.service.ISysServerService;
 import com.xunmei.system.vo.server.SysServerPageVo;
 import io.swagger.annotations.Api;
@@ -14,6 +15,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 
 /**
@@ -29,9 +31,7 @@ public class SysServerController extends BaseController {
     @Autowired
     private ISysServerService sysServerService;
 
-    /**
-     * 查询服务器维护列表
-     */
+
     @ApiOperation(value = "查询SysServer列表")
     //@RequiresPermissions("system:server:list")
     @GetMapping("/list")
@@ -39,9 +39,7 @@ public class SysServerController extends BaseController {
         return sysServerService.selectPage(req);
     }
 
-    /**
-     * 获取服务器维护详细信息
-     */
+
     @ApiOperation(value = "获取SysServer详细信息")
     //@RequiresPermissions("system:server:query")
     @GetMapping(value = "/{id}")
@@ -49,9 +47,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 +56,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 +65,25 @@ 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 = "转存目标服务器上的日志")
+    @PostMapping("/transferLog")
+    public AjaxResult transferLog(@RequestBody TransferLogDto req) {
+        sysServerService.transferLog(req);
+        return success();
+    }
+
+    @ApiOperation(value = "转存目标服务器上的日志")
+    @PostMapping("/downloadLogData")
+    public AjaxResult downloadLogData(TransferLogDto req, HttpServletResponse response) {
+        sysServerService.downloadLogData(req,response);
+        return success();
+    }
 }

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

+ 6 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysServerService.java

@@ -5,9 +5,11 @@ import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.system.domain.SysServer;
 import com.xunmei.system.dto.server.SysServerEditDto;
 import com.xunmei.system.dto.server.SysServerPageDto;
+import com.xunmei.system.dto.server.TransferLogDto;
 import com.xunmei.system.vo.server.CheckListVo;
 import com.xunmei.system.vo.server.SysServerPageVo;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 /**
@@ -74,4 +76,8 @@ public interface ISysServerService extends IService<SysServer> {
      */
     Object getLogList(Long serverId,Long checkId);
     List<CheckListVo> getServerList(Long serverId);
+
+    void transferLog(TransferLogDto req);
+
+    void downloadLogData(TransferLogDto req, HttpServletResponse response);
 }

+ 118 - 10
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysServerServiceImpl.java

@@ -2,6 +2,7 @@ package com.xunmei.system.service.impl;
 
 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;
@@ -10,19 +11,24 @@ import com.alibaba.fastjson2.TypeReference;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.common.core.domain.file.dto.FileDownloadDto;
+import com.xunmei.common.core.domain.file.dto.FileUploadByByteDto;
 import com.xunmei.common.core.thread.ThreadPoolConfig;
 import com.xunmei.common.core.util.BeanHelper;
 import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.common.security.utils.SecurityUtils;
+import com.xunmei.system.api.RemoteFileService;
 import com.xunmei.system.domain.SysServer;
 import com.xunmei.system.dto.server.SysServerEditDto;
 import com.xunmei.system.dto.server.SysServerPageDto;
+import com.xunmei.system.dto.server.TransferLogDto;
 import com.xunmei.system.mapper.SysServerMapper;
 import com.xunmei.system.service.ISysServerService;
 import com.xunmei.system.vo.server.CheckListVo;
 import com.xunmei.system.vo.server.FileInfoVo;
 import com.xunmei.system.vo.server.SysServerPageVo;
+import feign.Response;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -30,13 +36,17 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.UUID;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
 
 /**
  * 服务器维护Service业务层处理
@@ -49,7 +59,8 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
 
     @Autowired
     private SysServerMapper sysServerMapper;
-
+    @Autowired
+    private RemoteFileService fileService;
     @Autowired
     @Qualifier(ThreadPoolConfig.SOC_EXECUTOR)
     private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@@ -93,9 +104,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 +120,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;
         //获取服务器列表
@@ -127,12 +130,117 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
                 .execute();
         String serverJson = response.body();
         List<FileInfoVo> checks = JSONArray.parseArray(serverJson, FileInfoVo.class);
+        final boolean match = checks.stream().anyMatch(file -> ObjectUtil.equal(2, file.getFileType()));
+        List<FileInfoVo> res = new ArrayList<>();
+        final List<String> exitFileNameList = fileService.checkFileExit(server.getServerIp());
+        if (match) {
+            final List<FileInfoVo> list = checks.stream().filter(file -> ObjectUtil.equal(2, file.getFileType())).collect(Collectors.toList());
+            for (FileInfoVo fileInfoVo : list) {
+                res.add(fileInfoVo);
+                final List<FileInfoVo> list1 = checks.stream().filter(r -> ObjectUtil.equal(fileInfoVo.getId(), r.getParentId())).collect(Collectors.toList());
+                checkExit(list1, server.getServerIp(), exitFileNameList);
+                fileInfoVo.setChildren(list1);
+            }
+        } else {
+            res.add(buildDir("info", checks, server.getServerIp(), exitFileNameList));
+            res.add(buildDir("error", checks, server.getServerIp(), exitFileNameList));
+        }
+        return res;
+    }
+
+
+    private void checkExit(List<FileInfoVo> checks, String serverIp, List<String> exitFileNameList) {
+        exitFileNameList = exitFileNameList.stream().map(r -> r.replace(File.separator, "/")).collect(Collectors.toList());
+        for (FileInfoVo check : checks) {
+            final String fileName = serverIp + check.getParentPath().split("logs")[1] + File.separator + check.getFileName();
+            final String replace = fileName.replace(File.separator, "/");
+            final boolean match = exitFileNameList.stream().anyMatch(r -> r.contains(replace));
+            if (match) {
+                check.setExit(1);
+            }
+        }
+    }
+
+    private FileInfoVo buildDir(String dirName, List<FileInfoVo> list, String serverIp, List<String> exitFileNameList) {
+        FileInfoVo fileInfoVo = new FileInfoVo();
+        fileInfoVo.setFileName(dirName);
+        fileInfoVo.setFileSize("-");
+        fileInfoVo.setPath(dirName);
+        fileInfoVo.setFileType(2);
+        fileInfoVo.setId(UUID.randomUUID().toString());
+        final List<FileInfoVo> voList = list.stream().filter(r -> r.getFileName().contains(dirName)).collect(Collectors.toList());
+        checkExit(voList, serverIp, exitFileNameList);
+        fileInfoVo.setChildren(voList);
+        return fileInfoVo;
+    }
+
 
+    @Override
+    public void transferLog(TransferLogDto req) {
+        final SysServer sysServer = getById(req.getServerId());
+        if (ObjectUtil.isNull(sysServer)) {
+            throw new RuntimeException("服务器信息不存在");
+        }
+
+        saveRemoteLogToLocal(sysServer, req.getPath(), req.getParentPath(), req.getRootDir());
+    }
+
+    private void saveRemoteLogToLocal(SysServer server, String path, String parentPath, String rootDir) {
+        String downloadUrl = "http://" + server.getServerIp() + ":" + server.getServerPort() + "/result/fileDownload?path=" + path + "&parentPath=" + parentPath + "&rootDir=" + rootDir;
+        try {
+            final HttpRequest request = HttpUtil.createGet(downloadUrl);
+            HttpResponse response = request.execute();
+
+            if (response.getStatus() == 200) {
+                FileUploadByByteDto fileUploadByByteDto = new FileUploadByByteDto();
+                fileUploadByByteDto.setFileByte(response.bodyBytes());
+                fileUploadByByteDto.setFileName(path);
+                fileUploadByByteDto.setFilePath(parentPath.split("logs")[1]);
+                fileUploadByByteDto.setServerName(server.getServerIp());
+                //远程调用文件服务上传流 到指定目录保持为文件
+                fileService.uploadFileByte(fileUploadByByteDto);
 
-        return checks;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
+    @Override
+    public void downloadLogData(TransferLogDto req, HttpServletResponse response) {
+        final SysServer sysServer = getById(req.getServerId());
+        final String serverIp = sysServer.getServerIp();
+        FileDownloadDto dto=new FileDownloadDto();
+        dto.setServerName(serverIp);
+        dto.setFilePath(req.getParentPath().split("logs")[1]);
+        dto.setFileName(req.getPath());
+        final Response result = fileService.downloadLogData(dto);
+        InputStream inputStream = null;
+        BufferedInputStream bufferedInputStream = null;
+        BufferedOutputStream bufferedOutputStream = null;
+        try {
+            //把流返回到前端
+            Response.Body body = result.body();
+            inputStream = body.asInputStream();
+            bufferedInputStream = new BufferedInputStream(inputStream);
+            bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
+            response.setHeader("Content-Type", "application/octet-stream;charset=UTF-8");
+            response.addHeader("Content-Length", "" + body.length());
+            response.setHeader("Content-Disposition", result.headers().get("Content-Disposition").toString().replace("[", "").replace("]", ""));
+            int length = 0;
+            byte[] temp = new byte[1024 * 10];
+            while ((length = bufferedInputStream.read(temp)) != -1) {
+                bufferedOutputStream.write(temp, 0, length);
+            }
+            bufferedOutputStream.flush();
+            bufferedOutputStream.close();
+            bufferedInputStream.close();
+            inputStream.close();
+        } catch (IOException e) {
 
+            throw new RuntimeException(e);
+        }
+    }
     /**
      * 查询服务器维护
      *

+ 7 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/vo/server/FileInfoVo.java

@@ -5,6 +5,8 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
 
 @Data
 @AllArgsConstructor
@@ -49,5 +51,10 @@ public class FileInfoVo implements Serializable {
      * 父级id
      */
     private String createTime = "";
+
+    // 0不存在 1存在
+    private int exit;
+
+    private List<FileInfoVo> children=new ArrayList<>();
 }