Commit 676c6471 authored by 赵啸非's avatar 赵啸非

初始化提交

parent 83f71736
......@@ -102,6 +102,12 @@
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
</dependencies>
<build>
......
......@@ -10,8 +10,8 @@ import java.util.Map;
* @date: 2024/9/14 14:21
*/
public enum ProductDisEnum {
基础服务("base-platform", "基础服务"),
门户服务("portal-platform", "门户服务");
基础服务("base-manager", "base-platform"),
门户服务("portal-manager", "portal-platform");
private String value;
private String desc;
......@@ -30,7 +30,7 @@ public enum ProductDisEnum {
public static ProductDisEnum getByValue(String value) {
for (ProductDisEnum productDisEnum : ProductDisEnum.values()) {
if (productDisEnum.getValue() == value) {
if (productDisEnum.getValue().equals(value)) {
return productDisEnum;
}
}
......@@ -49,7 +49,7 @@ public enum ProductDisEnum {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
if (item.getValue().equals(e)) {
hasE = true;
break;
}
......
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 产品资源部署
*
* @author: zxfei
* @date: 2024/9/14 14:21
*/
public enum ProjectDistributeEnum {
基础服务("base-manager", "基础服务"),
门户服务("portal-platform", "门户服务");
private String value;
private String desc;
ProjectDistributeEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static ProjectDistributeEnum getByValue(String value) {
for (ProjectDistributeEnum productDisEnum : ProjectDistributeEnum.values()) {
if (productDisEnum.getValue().equals(value)) {
return productDisEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (ProjectDistributeEnum item : ProjectDistributeEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue().equals(e)) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
......@@ -64,6 +64,52 @@ public class ZipUtils {
return set;
}
/**
* 解压tar.gz压缩包
*
* @param inputStream
* @param unZipPath
* @return
*/
public static Set<String> unGzip(InputStream inputStream, String unZipPath) {
Set<String> set = new HashSet<>();
try {
TarArchiveInputStream fin = new TarArchiveInputStream(new GzipCompressorInputStream(inputStream));
log.info("********开始执行gzip");
TarArchiveEntry entry;
// 将 tar 文件解压到 extractPath 目录下
while ((entry = fin.getNextTarEntry()) != null) {
if (entry.isDirectory()) {
continue;
}
//目标文件位置
File curfile = new File(unZipPath + entry.getName());
File parent = curfile.getParentFile();
log.info("***文件保存的路径" + curfile.getAbsolutePath());
if (!parent.exists()) {
parent.mkdirs();
}
// 将文件写出到解压的目录
IOUtils.copy(fin, new FileOutputStream(curfile));
set.add(curfile.getAbsolutePath());
}
} catch (IOException e) {
log.error("解压tar.gz文件失败", e);
}
if (localFiles == null) {
localFiles = set;
} else {
localFiles.addAll(set);
}
return set;
}
// 解压tar包
public Set<String> unTar(String fileName, String unZipPath) {
Set<String> set = new HashSet<>();
......
......@@ -10,5 +10,10 @@ public class ProjectSetupEntity extends BaseReq {
*/
private String resourceFilePath;
/**
* 项目部署值
*/
private String projectValue;
}
\ No newline at end of file
......@@ -6,7 +6,11 @@ import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.common.code.ProductDisEnum;
import com.mortals.xhx.common.code.ProjectDistributeEnum;
import com.mortals.xhx.common.utils.EncodeUtil;
import com.mortals.xhx.common.utils.ZipUtils;
import com.mortals.xhx.module.setup.mode.ProjectSetupEntity;
import com.mortals.xhx.module.setup.mode.ResourceSetupEntity;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
......@@ -19,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.sql.Connection;
import java.sql.ResultSet;
......@@ -28,6 +33,7 @@ import static com.mortals.framework.web.BaseController.*;
/**
* 项目部署
*
* @author: zxfei
* @date: 2024/9/18 13:41
*/
......@@ -40,6 +46,10 @@ public class SetupProjectController {
@Getter
private String filePath;
@Value("${project.publishPath}")
@Getter
private String publishPath;
@Autowired
private UploadService uploadService;
......@@ -61,7 +71,7 @@ public class SetupProjectController {
throw new AppException("部署只支持zip文件!");
}
if(!FileUtil.isDirectory(filePath)){
if (!FileUtil.isDirectory(filePath)) {
//部署路径是否存在 如果不存在 创建目录,
FileUtil.mkdir(filePath);
}
......@@ -86,7 +96,25 @@ public class SetupProjectController {
}
@PostMapping("/distribute")
@UnAuth
public String distribute(@RequestBody ProjectSetupEntity projectSetupEntity) {
JSONObject ret = new JSONObject();
int code = VALUE_RESULT_SUCCESS;
try {
String unZipPath = publishPath;
String sourcePath = "/project/" + ProductDisEnum.getByValue(projectSetupEntity.getProjectValue()).getDesc() + "/" + projectSetupEntity.getProjectValue() + ".tar.gz";
InputStream inputStream = this.getClass().getResourceAsStream(sourcePath);
ZipUtils.unGzip(inputStream, unZipPath);
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
log.error("导入资源文件失败", e);
ret.put(KEY_RESULT_MSG, e.getMessage());
}
ret.put(KEY_RESULT_CODE, code);
ret.put(KEY_RESULT_MSG, "项目资源部署成功");
return ret.toJSONString();
}
public static void main(String[] args) {
......
......@@ -26,3 +26,5 @@ spring:
default-property-inclusion: NON_NULL
upload:
path: E:/pic
project:
publishPath: E:\pic\zip\
......@@ -77,4 +77,13 @@ Content-Type: application/json
}
###测试项目部署
POST http://localhost:8081/project/distribute
Content-Type: application/json
{
"projectValue": "base-manager"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment