From 2cedb574c22cf2f77418929e79f23ace0a7e7ac6 Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期一, 29 四月 2024 10:05:12 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java |  128 +++++++++++++++++++++++++-----------------
 1 files changed, 76 insertions(+), 52 deletions(-)

diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java
index f8ba775..8e91b71 100644
--- a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java
@@ -1,14 +1,12 @@
 package com.vci.ubcs.log.service.impl;
 
-import com.vci.ubcs.log.dto.LocalLogVO;
+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;
 import com.vci.ubcs.resource.utils.FileUtil;
 import com.vci.ubcs.resource.utils.ZipUtil;
-import com.vci.ubcs.resource.vo.FileObjectVO;
 import com.vci.ubcs.starter.exception.VciBaseException;
-import com.vci.ubcs.starter.web.util.BeanUtil;
-import com.vci.ubcs.starter.web.util.VciBaseUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.IOUtils;
 import org.springblade.core.log.exception.ServiceException;
@@ -17,20 +15,18 @@
 import com.vci.ubcs.resource.bo.FileObjectBO;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Configuration;
+import org.springframework.context.EnvironmentAware;
+import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
 import java.io.*;
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.nio.file.FileSystems;
 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.*;
@@ -43,7 +39,7 @@
  */
 @Service
 @Slf4j
-public class LogLocalServiceImpl implements ILogLocalService{
+public class LogLocalServiceImpl implements ILogLocalService, EnvironmentAware {
 
 	/**
 	 * 鍚勪釜鏈嶅姟瀛樻斁鐨勭殑鐖惰矾寰�
@@ -62,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("\\", "/");
@@ -83,52 +83,60 @@
 	 * @param logParentPath
 	 * @return
 	 */
-	//@Override
-	public List<LocalLog> getSystemLogList(String logParentPath) {
-		List<LocalLog> localLogs = new ArrayList<>();
+	@Override
+	public List<LocalLogVO> getSystemLogList(String logParentPath) {
+		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->{
-					// 缁勫缓鏃ュ織鏂囦欢瀵硅薄
-					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);
+						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);
-					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);
+							localLogsVOS.add(localLogVO);
+						}
+					}
+				});
+			}
 		}
-		return localLogs;
+		// 瀵规棩蹇楄繘琛岄檷搴忔帓搴�
+		List<LocalLogVO> resLocalLogVOS = localLogsVOS.stream().sorted(Comparator.comparing(LocalLogVO::getLastModifier).reversed()).collect(Collectors.toList());
+		return resLocalLogVOS;
 	}
 
 	/**
@@ -193,7 +201,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);
 	}
 
 	/**
@@ -223,7 +232,7 @@
 			throw new ServerException("鏈幏鍙栧埌璇ユ棩蹇楄矾寰勶紒");
 		}
 		FileObjectBO fileObjectBO = new FileObjectBO();
-		String logFullPaths = localLogVO.getLogFullPaths();
+		String logFullPaths = this.convertWindows2Linux(localLogVO.getLogFullPaths());
 		// 鍒ゆ柇鏄惁鏄埗鐩綍
 		if(!localLogVO.getHasChildren()){
 			//鍙笅杞戒竴涓棩蹇楁枃浠�
@@ -259,7 +268,6 @@
 					if(!logFile.exists() || !logFile.isFile()){
 						throw new VciBaseException("鏈湴鏃ュ織鏂囦欢璺緞"+item.getPath()+"涓湭鎵惧埌鏃ュ織");
 					}
-
 					try(OutputStream os = new FileOutputStream(file);
 						InputStream ins = new FileInputStream(logFile);
 					){
@@ -271,16 +279,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;
 	}
 
 	/**
+	 * 涓嬭浇涔嬪墠灏唚indows鐨勮矾寰勬牸寮忚浆鎹负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

--
Gitblit v1.9.3