Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java
@@ -1,5 +1,6 @@
package com.vci.ubcs.log.service.impl;
import com.vci.ubcs.log.enumpack.ServiceNameRoleEnum;
import com.vci.ubcs.log.vo.LocalLogVO;
import com.vci.ubcs.log.service.ILogLocalService;
import com.vci.ubcs.log.entity.LocalLog;
@@ -15,6 +16,8 @@
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -23,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.*;
@@ -35,7 +39,7 @@
 */
@Service
@Slf4j
public class LogLocalServiceImpl implements ILogLocalService{
public class LogLocalServiceImpl implements ILogLocalService, EnvironmentAware {
   /**
    * 各个服务存放的的父路径
@@ -54,9 +58,13 @@
    */
   private Boolean isWindows = true;
   {
      String os = System.getProperty("os.name").toLowerCase();
      //默认就配置为windows的,如果不是当前系统不是windows就需要对其转换为linux的文件路径格式
   /**
    * 根据当前运行的环境,对配置的日志路径格式进行调整
    * @param environment
    */
   @Override
   public void setEnvironment(Environment environment) {
      String os = environment.getProperty("os.name").toLowerCase();
      if (!os.contains("win")) {
         this.PARENTPATH = this.PARENTPATH.substring(this.PARENTPATH.lastIndexOf(":") + 1).replace("\\", "/");
         this.LOGPATH = this.LOGPATH.replace("\\", "/");
@@ -75,54 +83,58 @@
    * @param logParentPath
    * @return
    */
   //@Override
   public List<LocalLog> getSystemLogList(String logParentPath) {
      List<LocalLog> localLogs = new ArrayList<>();
   @Override
   public List<LocalLogVO> getSystemLogList(String logParentPath) {
      List<LocalLogVO> localLogsVO = new ArrayList<>();
      // 不为空说明是加载当前这个服务路径下的日志文件
      if(Func.isNotEmpty(logParentPath)){
         File file = new File(logParentPath);
         if (file.isDirectory()) {
            File[] files = file.listFiles();
            Arrays.stream(files).forEach(item->{
               // 组建日志文件对象
               LocalLog localLog = new LocalLog();
               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);
               localLogs.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);
                  localLogsVO.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()){
                  LocalLog localLog = new LocalLog();
                  localLog.setLastModifier(getLastModifiedOrCreatTime(true,fullPath));
                  localLog.setCreateTime(getLastModifiedOrCreatTime(false,fullPath));
                  localLog.setLogPath(fullPath);
                  String serviceId = getServiceId(file.getPath());
                  localLog.setServiceId(serviceId);
                  String serviceName = getServiceName(serviceId);
                  localLog.setServiceName(serviceName);
                  localLog.setLogType(serviceName+"日志父目录");
                  localLog.setLogName(serviceName+"日志父目录");
                  localLog.setHasChildren(true);
                  localLogs.add(localLog);
         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);
                     localLogsVO.add(localLogVO);
                  }
               }
            }
         });
            });
         }
      }
      return localLogs;
      return localLogsVO;
   }
   /**
@@ -187,7 +199,8 @@
    * @return
    */
   private String getServiceName(String serViceId){
      return EnumCache.getValue(EnumEnum.SERCIVE_NAME_ROLE, serViceId);
      // EnumCache.getValue(EnumEnum.SERCIVE_NAME_ROLE, serViceId)
      return ServiceNameRoleEnum.getTextByValue(serViceId);
   }
   /**
@@ -217,7 +230,7 @@
         throw new ServerException("未获取到该日志路径!");
      }
      FileObjectBO fileObjectBO = new FileObjectBO();
      String logFullPaths = localLogVO.getLogFullPaths();
      String logFullPaths = this.convertWindows2Linux(localLogVO.getLogFullPaths());
      // 判断是否是父目录
      if(!localLogVO.getHasChildren()){
         //只下载一个日志文件
@@ -253,7 +266,6 @@
               if(!logFile.exists() || !logFile.isFile()){
                  throw new VciBaseException("本地日志文件路径"+item.getPath()+"中未找到日志");
               }
               try(OutputStream os = new FileOutputStream(file);
                  InputStream ins = new FileInputStream(logFile);
               ){
@@ -265,16 +277,32 @@
            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;
   }
   /**
    * 下载之前将windows的路径格式转换为linux
    * @param fullPath
    * @return
    */
   private String convertWindows2Linux(String fullPath){
      String os = System.getProperty("os.name").toLowerCase();
      if (!os.contains("win")) {
         fullPath = fullPath.replace("\\", "/");
      }
      return fullPath;
   }
   /**
    * 删除日志文件
    * @param localLogVO 文件全路径集合
    * @throws ServerException