田源
2024-04-29 2cedb574c22cf2f77418929e79f23ace0a7e7ac6
Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java
@@ -26,6 +26,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.rmi.ServerException;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -82,54 +83,60 @@
    * @param logParentPath
    * @return
    */
   //@Override
   @Override
   public List<LocalLogVO> getSystemLogList(String logParentPath) {
      List<LocalLogVO> localLogsVO = new ArrayList<>();
      List<LocalLogVO> localLogsVOS = new ArrayList<>();
      // 不为空说明是加载当前这个服务路径下的日志文件
      if(Func.isNotEmpty(logParentPath)){
         File file = new File(logParentPath);
         if (file.isDirectory()) {
            File[] files = file.listFiles();
            Arrays.stream(files).forEach(item->{
               // 组建日志文件对象
               LocalLogVO localLog = new LocalLogVO();
               localLog.setLogName(item.getName());
               localLog.setLogType(getLogType(item.getName()));
               localLog.setCreateTime(getLastModifiedOrCreatTime(false,logParentPath));
               localLog.setLastModifier(getLastModifiedOrCreatTime(true,logParentPath));
               localLog.setLogPath(logParentPath);
               String serviceId = getServiceId(logParentPath);
               localLog.setServiceId(serviceId);
               localLog.setServiceName(getServiceName(serviceId));
               localLog.setHasChildren(false);
               localLogsVO.add(localLog);
            });
            if(Func.isNotEmpty(files) && files.length>0){
               Arrays.stream(files).forEach(item->{
                  // 组建日志文件对象
                  LocalLogVO localLog = new LocalLogVO();
                  localLog.setLogName(item.getName());
                  localLog.setLogType(getLogType(item.getName()));
                  localLog.setCreateTime(getLastModifiedOrCreatTime(false,item.getPath()));
                  localLog.setLastModifier(getLastModifiedOrCreatTime(true,item.getPath()));
                  localLog.setLogPath(logParentPath);
                  String serviceId = getServiceId(logParentPath);
                  localLog.setServiceId(serviceId);
                  localLog.setServiceName(getServiceName(serviceId));
                  localLog.setHasChildren(false);
                  localLogsVOS.add(localLog);
               });
            }
         }
      }else {
         File fileDir = new File(PARENTPATH);
         File[] childDir = fileDir.listFiles();
         Arrays.stream(childDir).forEach(dir->{
            if(dir.getName().contains("ubcs_")){
               String fullPath = dir.getPath() + LOGPATH;
               File file = new File(fullPath);
               if(file.exists()){
                  LocalLogVO localLogVO = new LocalLogVO();
                  localLogVO.setLastModifier(getLastModifiedOrCreatTime(true,fullPath));
                  localLogVO.setCreateTime(getLastModifiedOrCreatTime(false,fullPath));
                  localLogVO.setLogPath(fullPath);
                  String serviceId = getServiceId(file.getPath());
                  localLogVO.setServiceId(serviceId);
                  String serviceName = getServiceName(serviceId);
                  localLogVO.setServiceName(serviceName);
                  localLogVO.setLogType(serviceName+"日志父目录");
                  localLogVO.setLogName(serviceName+"日志父目录");
                  localLogVO.setHasChildren(true);
                  localLogsVO.add(localLogVO);
         if(Func.isNotEmpty(childDir) && childDir.length > 0){
            Arrays.stream(childDir).forEach(dir->{
               if(dir.getName().contains("ubcs_")){
                  String fullPath = dir.getPath() + LOGPATH;
                  File file = new File(fullPath);
                  if(file.exists()){
                     LocalLogVO localLogVO = new LocalLogVO();
                     localLogVO.setLastModifier(getLastModifiedOrCreatTime(true,file.getPath()));
                     localLogVO.setCreateTime(getLastModifiedOrCreatTime(false,file.getPath()));
                     localLogVO.setLogPath(fullPath);
                     String serviceId = getServiceId(file.getPath());
                     localLogVO.setServiceId(serviceId);
                     String serviceName = getServiceName(serviceId);
                     localLogVO.setServiceName(serviceName);
                     localLogVO.setLogType(serviceName+"日志父目录");
                     localLogVO.setLogName(serviceName+"日志父目录");
                     localLogVO.setHasChildren(true);
                     localLogsVOS.add(localLogVO);
                  }
               }
            }
         });
            });
         }
      }
      return localLogsVO;
      // 对日志进行降序排序
      List<LocalLogVO> resLocalLogVOS = localLogsVOS.stream().sorted(Comparator.comparing(LocalLogVO::getLastModifier).reversed()).collect(Collectors.toList());
      return resLocalLogVOS;
   }
   /**
@@ -261,7 +268,6 @@
               if(!logFile.exists() || !logFile.isFile()){
                  throw new VciBaseException("本地日志文件路径"+item.getPath()+"中未找到日志");
               }
               try(OutputStream os = new FileOutputStream(file);
                  InputStream ins = new FileInputStream(logFile);
               ){
@@ -273,10 +279,13 @@
            String zipName = new File(tempFolder).getPath() + File.separator + getLogFileName(logFullPaths) + "等"+file1.length + "个文件.zip";
            zipUtil.folderToZipFile(tempFolder,zipName);
            fileObjectBO.setFileLocalPath(zipName);
            fileObjectBO.setName(zipName);
            fileObjectBO.setFileExtension(".log");
            if(log.isDebugEnabled()){
               log.debug("下载文件的信息,",zipName);
            }
         }else{
            throw new ServerException("该目录下不存在日志文件!");
         }
      }
      return fileObjectBO;