From 6b0971b690de6e50d43b81799ba0378013455cdb Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期四, 09 十一月 2023 21:27:29 +0800
Subject: [PATCH] 提交代码

---
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/MdmEngineService.java          |    4 
 Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/controller/LogErrorController.java      |    1 
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/CodeRuleController.java     |    2 
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java |    2 
 Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/service/impl/LogSystemServiceImpl.java  |  158 +++++++++++++++++++++++++++++++--------
 Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/service/ILogSystemService.java          |    4 
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java  |    1 
 Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/controller/LogSystemController.java     |   18 ++++
 8 files changed, 153 insertions(+), 37 deletions(-)

diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/controller/LogErrorController.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/controller/LogErrorController.java
index a1a8715..f0bdf2a 100644
--- a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/controller/LogErrorController.java
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/controller/LogErrorController.java
@@ -25,6 +25,7 @@
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.tenant.annotation.NonDS;
 import org.springblade.core.tool.api.R;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/controller/LogSystemController.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/controller/LogSystemController.java
index fdc11c8..e4e5ddc 100644
--- a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/controller/LogSystemController.java
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/controller/LogSystemController.java
@@ -1,9 +1,17 @@
 package com.vci.ubcs.core.log.controller;
 
+import com.vci.ubcs.core.log.service.ILogSystemService;
+import com.vci.ubcs.log.entity.SystemLog;
 import lombok.AllArgsConstructor;
 import org.springblade.core.tenant.annotation.NonDS;
+import org.springblade.core.tool.api.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
 
 /**
  * 鏈湴绯荤粺鏃ュ織
@@ -12,10 +20,18 @@
  */
 @NonDS
 @RestController
-@AllArgsConstructor
+//@AllArgsConstructor
 @RequestMapping("/systemLog")
 public class LogSystemController {
 
+	@Autowired
+	private ILogSystemService logSystemService;
+
+	@GetMapping("/lazy-list")
+	private R<List<SystemLog>> getSystemLogList(@RequestParam String serviceName){
+ 		return R.data(logSystemService.getSystemLogList(serviceName));
+	}
+
 
 
 
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/service/ILogSystemService.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/service/ILogSystemService.java
index e713ec1..1db1919 100644
--- a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/service/ILogSystemService.java
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/service/ILogSystemService.java
@@ -18,8 +18,10 @@
 
 	/**
 	 * 鏌ョ湅锛屾湰鍦扮郴缁熸棩蹇楀垪琛�
+	 * @param logParentPath
+	 * @return
 	 */
-	List<SystemLog> getSystemLogList();
+	List<SystemLog> getSystemLogList(String logParentPath);
 
 	/**
 	 * 涓嬭浇锛屾牴鎹湇鍔″悕鎵�鍦ㄦ枃浠跺悕鍜屾枃浠跺悕涓嬭浇鏂囦欢
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/service/impl/LogSystemServiceImpl.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/service/impl/LogSystemServiceImpl.java
index ce126f2..f3f8778 100644
--- a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/service/impl/LogSystemServiceImpl.java
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/core/log/service/impl/LogSystemServiceImpl.java
@@ -2,16 +2,25 @@
 
 import com.vci.ubcs.core.log.service.ILogSystemService;
 import com.vci.ubcs.log.entity.SystemLog;
+import com.vci.ubcs.omd.cache.EnumCache;
+import com.vci.ubcs.omd.enums.EnumEnum;
 import com.vci.ubcs.resource.bo.FileObjectBO;
+import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import javax.xml.crypto.Data;
 import java.io.File;
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.rmi.ServerException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * 鏈湴绯荤粺鏃ュ織
@@ -25,55 +34,136 @@
 	 * 鍚勪釜鏈嶅姟瀛樻斁鐨勭殑鐖惰矾寰�
 	 */
 	private final String parentPath = "/data1/ubcs/ubcs-server";
+
+	/**
+	 * 鍚勪釜鏈嶅姟鐨勬棩蹇楀叿浣撶殑鐩綍璺緞
+	 */
 	//@Value("#{'${ip-whitelist.ip}'.split(',')}")
 	private List<String> serviceDirNames = new ArrayList<>(Arrays.asList("/ubcs_code/target/log","/ubcs_omd/target/log","/ubcs_system/target/log"));
 
 	/**
 	 * 鑾峰彇鏈湴鏃ュ織鍒楄〃
+	 * @param logParentPath
+	 * @return
 	 */
 	@Override
-	public List<SystemLog> getSystemLogList() {
-		serviceDirNames.stream().forEach(serviceDirName->{
-			File file = new File(parentPath+serviceDirName);
-
-			if(file.isDirectory()){
-
+	public List<SystemLog> getSystemLogList(String logParentPath) {
+		List<SystemLog> systemLogs = new ArrayList<>();
+		// 涓嶄负绌鸿鏄庢槸鍔犺浇褰撳墠杩欎釜鏈嶅姟璺緞涓嬬殑鏃ュ織鏂囦欢
+		if(Func.isNotEmpty(logParentPath)){
+			File file = new File(logParentPath);
+			if (file.isDirectory()) {
 				File[] files = file.listFiles();
-
-				for(File f : files){
-
-					if(f.isDirectory()){
-
-						//readAllFiles(f.getAbsolutePath());
-
-					}else{
-
-						System.out.println(f.getName());
-
-					}
-
-				}
-
-			}else{
-
-				System.out.println(file.getName());
-
+				Arrays.stream(files).forEach(item->{
+					// 缁勫缓鏃ュ織鏂囦欢瀵硅薄
+					SystemLog systemLog = new SystemLog();
+					systemLog.setLogName(item.getName());
+					systemLog.setLogType(getLogType(item.getName()));
+					systemLog.setCreateTime(getLastModifiedOrCreatTime(false,logParentPath));
+					systemLog.setLastmodifier(getLastModifiedOrCreatTime(true,logParentPath));
+					systemLog.setLogPath(logParentPath);
+					String serviceId = getServiceId(logParentPath);
+					systemLog.setServiceId(serviceId);
+					systemLog.setServiceName(getServiceName(serviceId));
+					systemLogs.add(systemLog);
+				});
 			}
-
-		});
-
-		return null;
+		}else {
+			serviceDirNames.stream().forEach(serviceDirName->{
+				File file = new File(parentPath+serviceDirName);
+				SystemLog systemLog = new SystemLog();
+				systemLog.setLastmodifier(getLastModifiedOrCreatTime(true,parentPath+serviceDirName));
+				systemLog.setCreateTime(getLastModifiedOrCreatTime(false,parentPath+serviceDirName));
+				systemLog.setLogPath(parentPath+serviceDirName);
+				String serviceId = getServiceId(logParentPath);
+				systemLog.setServiceId(serviceId);
+				systemLog.setServiceName(getServiceName(serviceId));
+				systemLogs.add(systemLog);
+			});
+		}
+		return systemLogs;
 	}
 
+	/**
+	 * 鑾峰彇鏂囦欢鏈�鍚庝慨鏀规垨鑰呭垱寤烘椂闂�
+	 * @param isModifier
+	 * @return
+	 */
+	private String getLastModifiedOrCreatTime(boolean isModifier,String pathStr) {
+		Path path = FileSystems.getDefault().getPath(pathStr);
+		String date = "";
+		try {
+			BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
+			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+			// 鏄幏鍙栨渶鍚庝慨鏀规椂闂�
+			if(isModifier){
+				date = dateFormat.format(new Date(attr.lastModifiedTime().toMillis()));
+			}else {
+				date = dateFormat.format(new Date(attr.creationTime().toMillis()));
+			}
+		} catch (IOException e) {
+			throw new ServiceException("Error reading file date attributes: " + e.getMessage());
+		}
+		return date;
+	}
+
+	/**
+	 * 鑾峰彇鏃ュ織绫诲瀷
+	 * @param fileName
+	 * @return
+	 */
+	private String getLogType(String fileName){
+		//鍒ゆ柇鏃ュ織鐨勭殑绫诲瀷
+		if (fileName.contains("error")) {
+			return "Error";
+		} else if (fileName.contains("info")) {
+			return "Info";
+		} else if (fileName.contains("warning")) {
+			return "Warning";
+		} else {
+			return "Unknown";
+		}
+	}
+
+	/**
+	 * 鑾峰彇鏈嶅姟ID
+	 * @param servciePath
+	 * @return
+	 */
+	private String getServiceId(String servciePath){
+		String[] parts = servciePath.split("/");
+		String extractedString = parts[parts.length - 2];
+		return extractedString;
+	}
+
+	/**
+	 * 鑾峰彇鏈嶅姟鍚嶇О
+	 * @param serViceId
+	 * @return
+	 */
+	private String getServiceName(String serViceId){
+		return EnumCache.getValue(EnumEnum.SERCIVE_NAME_ROLE, serViceId);
+	}
+
+	/**
+	 * 涓嬭浇鏃ュ織鏂囦欢
+	 * @param condition 鏌ヨ鏉′欢map
+	 * @return
+	 * @throws ServerException
+	 */
 	@Override
 	public FileObjectBO downloadLogByServiceNameAndFileName(Map<String, String> condition) throws ServerException {
 		return null;
 	}
 
+	/**
+	 * 鍒犻櫎鏃ュ織鏂囦欢
+	 * @param condition 涓婚敭闆嗗悎
+	 * @throws ServerException
+	 */
 	@Override
 	public void deleteLogFile(Map<String, String> condition) throws ServerException {
 
 	}
-
 
 }
diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/CodeRuleController.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/CodeRuleController.java
index c998c70..4b9d645 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/CodeRuleController.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/CodeRuleController.java
@@ -30,6 +30,7 @@
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import org.springblade.core.boot.ctrl.BladeController;
+import org.springblade.core.log.annotation.ApiLog;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.tool.api.R;
 import org.springframework.util.CollectionUtils;
@@ -72,6 +73,7 @@
 	@GetMapping(value = "/gridCodeRule")
 	@ApiOperationSupport(order = 3)
 	@ApiOperation(value = "鍒嗛〉", notes = "浼犲叆CodeRule")
+	@ApiLog
 	public R<IPage<CodeRuleVO>> gridCodeRule(BladeQueryObject bladeQueryObject) {
 		IPage<CodeRuleVO> pages = codeRuleService.gridCodeRule(bladeQueryObject.getQuery().setDescs("CREATETIME"), bladeQueryObject.getConditionMap());
 		return R.data(pages);
diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/MdmEngineService.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/MdmEngineService.java
index 5fba4a3..ce18ec1 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/MdmEngineService.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/MdmEngineService.java
@@ -397,6 +397,7 @@
 	 * @return 澶勭悊鎴愬姛鏁版嵁鏉℃暟
 	 */
 	Integer insertBatchByType(String btmType, List<BaseModel> baseModels);
+
 	/**
 	 * 浼犲叆涓氬姟绫诲瀷浠ュ強ID鏌ヨ涓氬姟琛ㄦ暟鎹槸鍚﹂噸澶�
 	 *
@@ -423,7 +424,8 @@
 	 * @param oids      闇�瑕佹煡璇㈢殑oid闆嗗悎 閫楀彿鍒嗗紑
 	 * @return 鏌ヨ鍑虹殑鏁版嵁
 	 */
-	List<BaseModel> selectByTypeAndOid(String btmType, String oids) ;
+	List<BaseModel> selectByTypeAndOid(String btmType, String oids);
+
 	/**
 	 * 浼犲叆涓氬姟绫诲瀷浠ュ強鐩稿叧鏁版嵁杩涜鎵归噺鏇存柊鎿嶄綔
 	 *
diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java
index 89201d8..2d6d567 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java
@@ -134,6 +134,7 @@
 	 */
 	@Override
 	public IPage<CodeRuleVO> gridCodeRule(Query query, Map<String,Object> conidtionMap) throws VciBaseException {
+		//int i = 1 / 0;
 		//濡傛灉绛変簬鑷繁閰嶇疆鐨勭鐞嗙粍绉熸埛id鍜岀鐞嗙粍瓒呯璐﹀彿锛屽氨涓嶉渶瑕佹寜鐓ц鍒欐墍鏈夎�呮潵杩涜鏌ヨ
 		/*if(!(AuthUtil.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId())
 			&& AuthUtil.getUserId().toString().equals(NacosConfigCache.getAdminUserInfo().getUserId().toString()))
diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
index 29ff41a..bbc4b11 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
@@ -3524,6 +3524,7 @@
      * @return 澶勭悊鎴愬姛鏁版嵁鏉℃暟
      */
     @Override
+	@Transactional(rollbackFor = Exception.class)
     public Integer insertBatchByType(String btmType, List<BaseModel> baseModels) {
         //浣跨敤浼犲叆鐨勪笟鍔$被鍨嬫煡璇㈣〃
         R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(btmType));
@@ -3540,6 +3541,7 @@
 		}).collect(Collectors.toSet());
 		//灏哹ean杞负map,mybatis缁熶竴澶勭悊
         List<Map<String, String>> maps = new ArrayList<>();
+
         baseModels.stream().forEach(model -> {
             try {
                 maps.add(VciBaseUtil.convertBean2Map(model,existFild));

--
Gitblit v1.9.3