From 050e32027ea9ecab9f5311560ecc51a3887a44b9 Mon Sep 17 00:00:00 2001 From: bwcx_jzy Date: Thu, 16 Sep 2021 11:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=8E=86=E5=8F=B2=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=97=AE=E9=A2=98=EF=BC=8C=E6=9E=84=E5=BB=BA=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E6=96=B0=E5=A2=9E=E6=9E=84=E5=BB=BA=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=AD=97=E6=AE=B5,=E4=B8=8B=E6=8B=89=E6=A1=86=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=B8=8D=E9=80=89=E6=8B=A9=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/jpom/build/BuildInfoManage.java | 1 + .../main/java/io/jpom/build/BuildUtil.java | 6 + .../build/BuildInfoHistoryController.java | 31 ++-- .../io/jpom/model/log/BuildHistoryLog.java | 12 ++ .../io/jpom/model/vo/BuildHistoryLogVo.java | 142 ++++++++---------- .../src/main/resources/bin/h2-db-v1.sql | 4 + web-vue/src/components/customSelect/index.vue | 1 + web-vue/src/pages/build/history.vue | 9 +- web-vue/src/pages/build/list-info.vue | 9 +- 9 files changed, 117 insertions(+), 98 deletions(-) diff --git a/modules/server/src/main/java/io/jpom/build/BuildInfoManage.java b/modules/server/src/main/java/io/jpom/build/BuildInfoManage.java index ac462cfaa..2c298da46 100644 --- a/modules/server/src/main/java/io/jpom/build/BuildInfoManage.java +++ b/modules/server/src/main/java/io/jpom/build/BuildInfoManage.java @@ -173,6 +173,7 @@ public class BuildInfoManage extends BaseBuild implements Runnable { buildHistoryLog.setStatus(BuildStatus.Ing.getCode()); buildHistoryLog.setStartTime(System.currentTimeMillis()); buildHistoryLog.setBuildNumberId(buildInfoModel.getBuildId()); + buildHistoryLog.setBuildName(buildInfoModel.getName()); buildHistoryLog.setBuildUser(optUserName); DbBuildHistoryLogService dbBuildHistoryLogService = SpringUtil.getBean(DbBuildHistoryLogService.class); diff --git a/modules/server/src/main/java/io/jpom/build/BuildUtil.java b/modules/server/src/main/java/io/jpom/build/BuildUtil.java index c96311877..1659cfc0e 100644 --- a/modules/server/src/main/java/io/jpom/build/BuildUtil.java +++ b/modules/server/src/main/java/io/jpom/build/BuildUtil.java @@ -74,6 +74,9 @@ public class BuildUtil { * @return file */ public static File getHistoryPackageFile(String buildModelId, int buildId, String resultFile) { + if (StrUtil.isEmpty(buildModelId) || StrUtil.isEmpty(resultFile)) { + return null; + } return FileUtil.file(getBuildDataFile(buildModelId), "history", BuildInfoModel.getBuildIdStr(buildId), @@ -110,6 +113,9 @@ public class BuildUtil { * @return file */ public static File getLogFile(String buildModelId, int buildId) { + if (StrUtil.isEmpty(buildModelId)) { + return null; + } return FileUtil.file(getBuildDataFile(buildModelId), "history", BuildInfoModel.getBuildIdStr(buildId), diff --git a/modules/server/src/main/java/io/jpom/controller/build/BuildInfoHistoryController.java b/modules/server/src/main/java/io/jpom/controller/build/BuildInfoHistoryController.java index b18b47c70..acc928da6 100644 --- a/modules/server/src/main/java/io/jpom/controller/build/BuildInfoHistoryController.java +++ b/modules/server/src/main/java/io/jpom/controller/build/BuildInfoHistoryController.java @@ -3,6 +3,7 @@ package io.jpom.controller.build; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.db.Entity; import cn.hutool.db.Page; @@ -38,6 +39,8 @@ import javax.annotation.Resource; import java.io.File; import java.io.IOException; import java.util.*; +import java.util.function.Consumer; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -72,7 +75,7 @@ public class BuildInfoHistoryController extends BaseServerController { return; } File logFile = BuildUtil.getHistoryPackageFile(item.getId(), buildHistoryLog.getBuildNumberId(), buildHistoryLog.getResultDirFile()); - if (!logFile.exists()) { + if (!FileUtil.exist(logFile)) { return; } if (logFile.isFile()) { @@ -94,7 +97,7 @@ public class BuildInfoHistoryController extends BaseServerController { BuildInfoModel item = buildInfoService.getByKey(buildHistoryLog.getBuildDataId()); Objects.requireNonNull(item); File logFile = BuildUtil.getLogFile(item.getId(), buildHistoryLog.getBuildNumberId()); - if (!logFile.exists()) { + if (!FileUtil.exist(logFile)) { return; } if (logFile.isFile()) { @@ -146,18 +149,20 @@ public class BuildInfoHistoryController extends BaseServerController { } } PageResult pageResult = dbBuildHistoryLogService.listPage(entity, pageObj); - List buildHistoryLogVos = new ArrayList<>(); - pageResult.forEach(buildHistoryLog -> { - BuildHistoryLogVo historyLogVo = new BuildHistoryLogVo(); - BeanUtil.copyProperties(buildHistoryLog, historyLogVo); - String dataId = buildHistoryLog.getBuildDataId(); - BuildInfoModel item = buildInfoService.getByKey(dataId); - if (item != null) { - historyLogVo.setBuildName(item.getName()); + List collect = pageResult.stream().map(buildHistoryLog -> { + BuildHistoryLogVo buildHistoryLogVo = new BuildHistoryLogVo(); + BeanUtil.copyProperties(buildHistoryLog, buildHistoryLogVo); + // + if (StrUtil.isEmpty(buildHistoryLog.getBuildName())) { + String dataId = buildHistoryLog.getBuildDataId(); + BuildInfoModel item = buildInfoService.getByKey(dataId); + if (item != null) { + buildHistoryLogVo.setBuildName(item.getName()); + } } - buildHistoryLogVos.add(historyLogVo); - }); - JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", buildHistoryLogVos); + return buildHistoryLogVo; + }).collect(Collectors.toList()); + JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", collect); jsonObject.put("total", pageResult.getTotal()); return jsonObject.toString(); } diff --git a/modules/server/src/main/java/io/jpom/model/log/BuildHistoryLog.java b/modules/server/src/main/java/io/jpom/model/log/BuildHistoryLog.java index 0f89dc853..2bb6e3582 100644 --- a/modules/server/src/main/java/io/jpom/model/log/BuildHistoryLog.java +++ b/modules/server/src/main/java/io/jpom/model/log/BuildHistoryLog.java @@ -23,6 +23,10 @@ public class BuildHistoryLog extends BaseBuildModule { * @see BuildInfoModel#getId() */ private String buildDataId; + /** + * 构建名称 + */ + private String buildName; /** * 构建编号 * @@ -97,4 +101,12 @@ public class BuildHistoryLog extends BaseBuildModule { public void setEndTime(long endTime) { this.endTime = endTime; } + + public String getBuildName() { + return buildName; + } + + public void setBuildName(String buildName) { + this.buildName = buildName; + } } diff --git a/modules/server/src/main/java/io/jpom/model/vo/BuildHistoryLogVo.java b/modules/server/src/main/java/io/jpom/model/vo/BuildHistoryLogVo.java index 9ef7780da..fa48d5ac6 100644 --- a/modules/server/src/main/java/io/jpom/model/vo/BuildHistoryLogVo.java +++ b/modules/server/src/main/java/io/jpom/model/vo/BuildHistoryLogVo.java @@ -1,13 +1,9 @@ package io.jpom.model.vo; -import cn.jiangzeyin.common.spring.SpringUtil; +import cn.hutool.core.io.FileUtil; import io.jpom.build.BuildUtil; -import io.jpom.model.BaseEnum; import io.jpom.model.data.BuildInfoModel; -import io.jpom.model.data.OutGivingModel; -import io.jpom.model.enums.BuildReleaseMethod; import io.jpom.model.log.BuildHistoryLog; -import io.jpom.service.node.OutGivingServer; import java.io.File; @@ -18,85 +14,77 @@ import java.io.File; * @date 2019/7/17 */ public class BuildHistoryLogVo extends BuildHistoryLog { - private String buildName; - private String releaseDesc; - /** - * 是否存在构建产物 - */ - private boolean hashFile; - /** - * 是否存在日志 - */ - private boolean hasLog; - public boolean isHasLog() { - File file = BuildUtil.getLogFile(getBuildDataId(), getBuildNumberId()); - hasLog = file.exists(); - return hasLog; - } + private String releaseDesc; + /** + * 是否存在构建产物 + */ + private boolean hashFile; + /** + * 是否存在日志 + */ + private boolean hasLog; - public void setHasLog(boolean hasLog) { - this.hasLog = hasLog; - } + public boolean isHasLog() { + File file = BuildUtil.getLogFile(getBuildDataId(), getBuildNumberId()); + hasLog = FileUtil.exist(file); + return hasLog; + } - public String getBuildName() { - return buildName; - } + public void setHasLog(boolean hasLog) { + this.hasLog = hasLog; + } - public void setBuildName(String buildName) { - this.buildName = buildName; - } + public boolean isHashFile() { + File file = BuildUtil.getHistoryPackageFile(getBuildDataId(), getBuildNumberId(), getResultDirFile()); + hashFile = FileUtil.exist(file); + return hashFile; + } - public boolean isHashFile() { - File file = BuildUtil.getHistoryPackageFile(getBuildDataId(), getBuildNumberId(), getResultDirFile()); - hashFile = file.exists(); - return hashFile; - } + public void setHashFile(boolean hashFile) { + this.hashFile = hashFile; + } - public void setHashFile(boolean hashFile) { - this.hashFile = hashFile; - } + public String getBuildIdStr() { + return BuildInfoModel.getBuildIdStr(getBuildNumberId()); + } - public String getBuildIdStr() { - return BuildInfoModel.getBuildIdStr(getBuildNumberId()); - } + public void setReleaseDesc(String releaseDesc) { + this.releaseDesc = releaseDesc; + } - public void setReleaseDesc(String releaseDesc) { - this.releaseDesc = releaseDesc; - } - - /** - * 发布描述 - * - * @return 描述 - */ - public String getReleaseDesc() { - if (releaseDesc == null) { - int releaseMethod = getReleaseMethod(); - BuildReleaseMethod releaseMethod1 = BaseEnum.getEnum(BuildReleaseMethod.class, releaseMethod); - if (releaseMethod1 == null) { - return BuildReleaseMethod.No.getDesc(); - } - String releaseMethodDataId = getReleaseMethodDataId(); - switch (releaseMethod1) { - case Project: { - String[] datas = releaseMethodDataId.split(":"); - return String.format("【%s】节点【%s】项目", datas[0], datas[1]); - } - case Outgiving: { - OutGivingServer outGivingServer = SpringUtil.getBean(OutGivingServer.class); - OutGivingModel item = outGivingServer.getItem(releaseMethodDataId); - if (item == null) { - return "-"; - } - return "【" + item.getName() + "】分发"; - } - case No: - default: - return releaseMethod1.getDesc(); - } - } - return releaseDesc; - } +// /** +// * 发布描述 +// * +// * @return 描述 +// */ +// public String getReleaseDesc() { +// if (releaseDesc == null) { +// int releaseMethod = getReleaseMethod(); +// BuildReleaseMethod releaseMethod1 = BaseEnum.getEnum(BuildReleaseMethod.class, releaseMethod); +// if (releaseMethod1 == null) { +// return BuildReleaseMethod.No.getDesc(); +// } +// String releaseMethodDataId = getReleaseMethodDataId(); +// switch (releaseMethod1) { +// case Project: { +// String[] datas = releaseMethodDataId.split(":"); +// return String.format("【%s】节点【%s】项目", datas[0], datas[1]); +// } +// case Outgiving: { +// OutGivingServer outGivingServer = SpringUtil.getBean(OutGivingServer.class); +// OutGivingModel item = outGivingServer.getItem(releaseMethodDataId); +// if (item == null) { +// return "-"; +// } +// return "【" + item.getName() + "】分发"; +// } +// case No: +// default: +// return releaseMethod1.getDesc(); +// } +// } +// return releaseDesc; +// } } diff --git a/modules/server/src/main/resources/bin/h2-db-v1.sql b/modules/server/src/main/resources/bin/h2-db-v1.sql index 82f521260..c90154439 100644 --- a/modules/server/src/main/resources/bin/h2-db-v1.sql +++ b/modules/server/src/main/resources/bin/h2-db-v1.sql @@ -128,3 +128,7 @@ ALTER TABLE SSHTERMINALEXECUTELOG ADD IF NOT EXISTS CREATETIMEMILLIS BIGINT COMMENT '数据创建时间'; ALTER TABLE SSHTERMINALEXECUTELOG ADD IF NOT EXISTS MODIFYTIMEMILLIS BIGINT COMMENT '数据修改时间'; + +-- @author jzy +ALTER TABLE BUILDHISTORYLOG + ADD IF NOT EXISTS BUILDNAME VARCHAR(100) COMMENT '构建名称'; diff --git a/web-vue/src/components/customSelect/index.vue b/web-vue/src/components/customSelect/index.vue index d56228790..738a26e49 100644 --- a/web-vue/src/components/customSelect/index.vue +++ b/web-vue/src/components/customSelect/index.vue @@ -25,6 +25,7 @@ + {{selectPlaceholder}} {{ item }} diff --git a/web-vue/src/pages/build/history.vue b/web-vue/src/pages/build/history.vue index a6744e8f4..9f1e09c2e 100644 --- a/web-vue/src/pages/build/history.vue +++ b/web-vue/src/pages/build/history.vue @@ -20,9 +20,8 @@ {{ text }} - - - {{ text }} + + #{{ text }}