From 02b3d584d201ca7cb8a024fd151fe6eddbf43def Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期五, 01 三月 2024 16:31:10 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/impl/DeployAppsServiceImpl.java |   41 ++++++++++++++++++++++++++++++-----------
 1 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/impl/DeployAppsServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/impl/DeployAppsServiceImpl.java
index a641db4..6ac5349 100644
--- a/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/impl/DeployAppsServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/impl/DeployAppsServiceImpl.java
@@ -17,8 +17,10 @@
 import com.vci.ubcs.starter.util.HttpUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.WebUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.client.ServiceInstance;
@@ -30,6 +32,8 @@
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.ServletRequest;
@@ -40,6 +44,8 @@
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -167,18 +173,18 @@
 		if(deployAppsVO.getName().isEmpty()){
 			throw new ServiceException("缂哄皯蹇呬紶鍙傛暟name");
 		}
-		DeployApps deployApps = deployAppsMapper.selectOne(Wrappers.<DeployApps>query().lambda().eq(DeployApps::getServerName, deployAppsVO.getName()));
+		List<DeployApps> deployApps = deployAppsMapper.selectList(Wrappers.<DeployApps>query().lambda().eq(DeployApps::getServerName, deployAppsVO.getName()));
 		if(Func.isNotEmpty(deployApps)){
-			return deployApps;
+			return deployApps.get(0);
 		}
 		// 鏈粠搴撲腑鏌ヨ鍒帮紝闇�瑕佺敓鎴愭湇鍔′俊鎭繚瀛橀粯璁や俊鎭埌搴撲腑
 		DeployApps defaultDeployApps = new DeployApps();
-		defaultDeployApps.setLogPath(PARENTPATH + "\\" + deployAppsVO.getName().replace("-","_") + LOGPATH);
+		defaultDeployApps.setLogPath(PARENTPATH + SEPARATOR + deployAppsVO.getName().replace("-","_") + LOGPATH);
 		defaultDeployApps.setServerName(deployAppsVO.getName());
 		defaultDeployApps.setStartCmd(CmdConfigEnum.START_CMD.getValue() + deployAppsVO.getName());
 		defaultDeployApps.setStopCmd(CmdConfigEnum.STOP_CMD.getValue() + deployAppsVO.getName());
 		defaultDeployApps.setRestartCmd(CmdConfigEnum.RESTART_CMD.getValue() + deployAppsVO.getName());
-		defaultDeployApps.setServerPath(PARENTPATH + "\\" + deployAppsVO.getName().replace("-","_"));
+		defaultDeployApps.setServerPath(PARENTPATH + SEPARATOR + deployAppsVO.getName().replace("-","_"));
 		int eft = deployAppsMapper.insert(defaultDeployApps);
 		if (!SqlHelper.retBool(eft)) {
 			throw new ServiceException("鐢熸垚榛樿鏈嶅姟淇℃伅鍒板簱涓椂澶辫触锛�");
@@ -194,8 +200,7 @@
 	 */
 	@Override
 	public boolean saveOrUpdateServiceInfo(DeployAppsVO deployAppsVO) throws ServiceException {
-		boolean b = this.saveOrUpdate(deployAppsVO);
-		return b;
+		return this.saveOrUpdate(deployAppsVO);
 	}
 
 	/**
@@ -208,6 +213,10 @@
 	public boolean addSave(DeployApps deployApps) throws ServiceException {
 		if (Func.isBlank(deployApps.getServerName()) || Func.isBlank(deployApps.getServerPath())) {
 			throw new ServiceException("蹇呬紶鍙傛暟[鏈嶅姟鍚嶇О锛屾湇鍔″瓨鏀捐矾寰刔涓嶈兘涓虹┖");
+		}
+		List<DeployApps> deployAppsList = deployAppsMapper.selectList(Wrappers.<DeployApps>query().lambda().eq(DeployApps::getServerName, deployApps.getServerName()));
+		if (!deployAppsList.isEmpty()) {
+			throw new ServiceException("鏂板鏈嶅姟鐨勬湇鍔″悕閲嶅锛�");
 		}
 		return SqlHelper.retBool(deployAppsMapper.insert(deployApps));
 	}
@@ -238,12 +247,12 @@
 					String backName = "";
 					String fileType = "file";
 					// 鏄帇缂╂枃浠�,鍥犱负鍙細瀛樺湪涓ょ鎯呭喌锛屾枃浠跺悕鏄帇缂╂枃浠讹紝鎴栬�呮枃浠讹紙.jar绫诲瀷鐨勬枃浠讹級
+					// 褰撳墠鏃堕棿
+					String currentDateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
 					if (file.getContentType().equals("application/zip") || file.getContentType().equals("application/x-zip-compressed")) {
-						backName = file.getOriginalFilename().replace(".zip","_"+Func.formatDate(new Date()));
-						fileType = "zip";
+						backName = file.getOriginalFilename().replace(".zip","_" + currentDateTime);
 					}else{
-						backName = file.getOriginalFilename().replace(".","_"+Func.formatDate(new Date())+".");
-						fileType = "file";
+						backName = file.getOriginalFilename().replace(".","_" + currentDateTime + ".");
 					}
 					File source = new File(deployAppsDB.get(0).getServerPath() + this.SEPARATOR + file.getOriginalFilename().replace(".zip", ""));
 					File destination = new File(deployAppsDB.get(0).getFileBack() + this.SEPARATOR + backName);
@@ -338,6 +347,7 @@
 				return "The executed command is empty";
 			}
 			// 鎵цLinux鍛戒护
+			log.info("寮�濮嬫墽琛屽懡浠わ細"+cmd);
 			Process process = Runtime.getRuntime().exec(cmd);
 			// 璇诲彇鍛戒护鎵ц缁撴灉
 			BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
@@ -347,7 +357,16 @@
 			}
 			// 绛夊緟鍛戒护鎵ц瀹屾垚
 			int exitCode = process.waitFor();
-			log.info("鍛戒护鎵ц缁撴灉锛�" + output.toString());
+			// 璇诲彇鍛戒护鎵ц鐨勯敊璇緭鍑烘祦
+			BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+			StringBuilder errorOutput = new StringBuilder();
+			String errorLine;
+			while ((errorLine = errorReader.readLine()) != null) {
+				errorOutput.append(errorLine).append("\n");
+			}
+			String errorOutputString = errorOutput.toString();
+			log.info("閿欒杈撳嚭锛�" + errorOutputString);
+			log.info("鍛戒护鎵ц缁撴灉锛�" + output.toString()+":"+exitCode);
 			return output.toString();
 		}catch (IOException | InterruptedException e){
 			e.printStackTrace();

--
Gitblit v1.9.3