From f879ddd80a2bd267a0a575ef03f76d3ec2ae1504 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期四, 04 一月 2024 11:42:22 +0800 Subject: [PATCH] bug列表269:集成日志查询bug修改。 270:关键属性校验,去掉多线程之后请求响应非常慢(之前报错线程阻塞的bug改成单线程导致非常慢,现在又改回ForJoinPool方式限制线程生成数量实现多线程并行,提升执行效率)。 --- Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java | 106 +++++++++++++++++++++++++++++++++-------------------- 1 files changed, 66 insertions(+), 40 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 55114e0..becbc97 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 @@ -16,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; @@ -24,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.*; @@ -36,7 +39,7 @@ */ @Service @Slf4j -public class LogLocalServiceImpl implements ILogLocalService{ +public class LogLocalServiceImpl implements ILogLocalService, EnvironmentAware { /** * 鍚勪釜鏈嶅姟瀛樻斁鐨勭殑鐖惰矾寰� @@ -55,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("\\", "/"); @@ -76,7 +83,7 @@ * @param logParentPath * @return */ - //@Override + @Override public List<LocalLogVO> getSystemLogList(String logParentPath) { List<LocalLogVO> localLogsVO = new ArrayList<>(); // 涓嶄负绌鸿鏄庢槸鍔犺浇褰撳墠杩欎釜鏈嶅姟璺緞涓嬬殑鏃ュ織鏂囦欢 @@ -84,44 +91,48 @@ 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); + 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()){ - 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); + localLogsVO.add(localLogVO); + } } - } - }); + }); + } } return localLogsVO; } @@ -219,7 +230,7 @@ throw new ServerException("鏈幏鍙栧埌璇ユ棩蹇楄矾寰勶紒"); } FileObjectBO fileObjectBO = new FileObjectBO(); - String logFullPaths = localLogVO.getLogFullPaths(); + String logFullPaths = this.convertWindows2Linux(localLogVO.getLogFullPaths()); // 鍒ゆ柇鏄惁鏄埗鐩綍 if(!localLogVO.getHasChildren()){ //鍙笅杞戒竴涓棩蹇楁枃浠� @@ -255,7 +266,6 @@ if(!logFile.exists() || !logFile.isFile()){ throw new VciBaseException("鏈湴鏃ュ織鏂囦欢璺緞"+item.getPath()+"涓湭鎵惧埌鏃ュ織"); } - try(OutputStream os = new FileOutputStream(file); InputStream ins = new FileInputStream(logFile); ){ @@ -267,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; } /** + * 涓嬭浇涔嬪墠灏唚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