diff --git a/modules/server/src/main/java/org/dromara/jpom/controller/outgiving/OutGivingProjectEditController.java b/modules/server/src/main/java/org/dromara/jpom/controller/outgiving/OutGivingProjectEditController.java index fb1136da7..b0e88cac7 100644 --- a/modules/server/src/main/java/org/dromara/jpom/controller/outgiving/OutGivingProjectEditController.java +++ b/modules/server/src/main/java/org/dromara/jpom/controller/outgiving/OutGivingProjectEditController.java @@ -144,6 +144,7 @@ public class OutGivingProjectEditController extends BaseServerController { } outGivingServer.delByKey(id, request); + // return JsonMessage.success("删除成功"); } @@ -406,11 +407,11 @@ public class OutGivingProjectEditController extends BaseServerController { // String webhook = getParameter("webhook"); webhook = Opt.ofBlankAble(webhook) - .map(s -> { - Validator.validateMatchRegex(RegexPool.URL_HTTP, s, "WebHooks 地址不合法"); - return s; - }) - .orElse(StrUtil.EMPTY); + .map(s -> { + Validator.validateMatchRegex(RegexPool.URL_HTTP, s, "WebHooks 地址不合法"); + return s; + }) + .orElse(StrUtil.EMPTY); outGivingModel.setWebhook(webhook); return tuples; } diff --git a/modules/server/src/main/java/org/dromara/jpom/func/assets/controller/MachineSshController.java b/modules/server/src/main/java/org/dromara/jpom/func/assets/controller/MachineSshController.java index 8432b90f1..ea2f81fe1 100644 --- a/modules/server/src/main/java/org/dromara/jpom/func/assets/controller/MachineSshController.java +++ b/modules/server/src/main/java/org/dromara/jpom/func/assets/controller/MachineSshController.java @@ -160,9 +160,7 @@ public class MachineSshController extends BaseGroupNameController { sshModel.setGroupName(groupName); sshModel.setHost(host); // 如果密码传递不为空就设置值 因为上面已经判断了只有修改的情况下 password 才可能为空 - if (StrUtil.isNotEmpty(password)) { - sshModel.setPassword(password); - } + Opt.ofBlankAble(password).ifPresent(sshModel::setPassword); if (StrUtil.startWith(privateKey, URLUtil.FILE_URL_PREFIX)) { String rsaPath = StrUtil.removePrefix(privateKey, URLUtil.FILE_URL_PREFIX); Assert.state(FileUtil.isFile(rsaPath), "配置的私钥文件不存在"); @@ -181,7 +179,7 @@ public class MachineSshController extends BaseGroupNameController { Charset.forName(charset); sshModel.setCharset(charset); } catch (Exception e) { - return new JsonMessage<>(405, "请填写正确的编码格式"); + return new JsonMessage<>(405, "请填写正确的编码格式," + e.getMessage()); } // 判断重复 Entity entity = Entity.create(); @@ -189,9 +187,7 @@ public class MachineSshController extends BaseGroupNameController { entity.set("port", sshModel.getPort()); entity.set("`user`", sshModel.getUser()); entity.set("connectType", sshModel.getConnectType()); - if (StrUtil.isNotEmpty(id)) { - entity.set("id", StrUtil.format(" <> {}", id)); - } + Opt.ofBlankAble(id).ifPresent(s -> entity.set("id", StrUtil.format(" <> {}", s))); boolean exists = machineSshServer.exists(entity); Assert.state(!exists, "对应的SSH已经存在啦"); try { @@ -201,11 +197,7 @@ public class MachineSshController extends BaseGroupNameController { log.warn("ssh连接失败", e); return new JsonMessage<>(505, "ssh连接失败:" + e.getMessage()); } - if (add) { - machineSshServer.insert(sshModel); - } else { - machineSshServer.updateById(sshModel); - } + int i = add ? machineSshServer.insert(sshModel) : machineSshServer.updateById(sshModel); return JsonMessage.success("操作成功"); } diff --git a/modules/server/src/main/java/org/dromara/jpom/service/dblog/BuildInfoService.java b/modules/server/src/main/java/org/dromara/jpom/service/dblog/BuildInfoService.java index 80e87c942..2f418c1e5 100644 --- a/modules/server/src/main/java/org/dromara/jpom/service/dblog/BuildInfoService.java +++ b/modules/server/src/main/java/org/dromara/jpom/service/dblog/BuildInfoService.java @@ -90,9 +90,10 @@ public class BuildInfoService extends BaseGroupService implement } @Override - public void insert(BuildInfoModel buildInfoModel) { - super.insert(buildInfoModel); + public int insert(BuildInfoModel buildInfoModel) { + int count = super.insert(buildInfoModel); this.checkCron(buildInfoModel); + return count; } @Override diff --git a/modules/server/src/main/java/org/dromara/jpom/service/dblog/DbBuildHistoryLogService.java b/modules/server/src/main/java/org/dromara/jpom/service/dblog/DbBuildHistoryLogService.java index 5e322d3b9..5d7a4ce1a 100644 --- a/modules/server/src/main/java/org/dromara/jpom/service/dblog/DbBuildHistoryLogService.java +++ b/modules/server/src/main/java/org/dromara/jpom/service/dblog/DbBuildHistoryLogService.java @@ -113,28 +113,29 @@ public class DbBuildHistoryLogService extends BaseWorkspaceService { - entity.set("buildDataId", buildHistoryLog.getBuildDataId()); - // 清理单项构建历史保留个数只判断(构建结束、发布中、发布失败、发布失败)有效构建状态,避免无法保留有效构建历史 - entity.set("status", CollUtil.newArrayList( - BuildStatus.Success.getCode(), - BuildStatus.PubIng.getCode(), - BuildStatus.PubSuccess.getCode(), - BuildStatus.PubError.getCode())); - }, - buildHistoryLog1 -> { - JsonMessage jsonMessage = this.deleteLogAndFile(buildHistoryLog1); - if (!jsonMessage.success()) { - log.warn("{} {} {}", buildHistoryLog1.getBuildName(), buildHistoryLog1.getBuildNumberId(), jsonMessage); - return false; - } - return true; - }); + entity -> { + entity.set("buildDataId", buildHistoryLog.getBuildDataId()); + // 清理单项构建历史保留个数只判断(构建结束、发布中、发布失败、发布失败)有效构建状态,避免无法保留有效构建历史 + entity.set("status", CollUtil.newArrayList( + BuildStatus.Success.getCode(), + BuildStatus.PubIng.getCode(), + BuildStatus.PubSuccess.getCode(), + BuildStatus.PubError.getCode())); + }, + buildHistoryLog1 -> { + JsonMessage jsonMessage = this.deleteLogAndFile(buildHistoryLog1); + if (!jsonMessage.success()) { + log.warn("{} {} {}", buildHistoryLog1.getBuildName(), buildHistoryLog1.getBuildNumberId(), jsonMessage); + return false; + } + return true; + }); + return count; } @Override @@ -147,15 +148,15 @@ public class DbBuildHistoryLogService extends BaseWorkspaceService { - JsonMessage jsonMessage = this.deleteLogAndFile(buildHistoryLog1); - if (!jsonMessage.success()) { - log.warn("{} {} {}", buildHistoryLog1.getBuildName(), buildHistoryLog1.getBuildNumberId(), jsonMessage); - return false; - } - return true; - }); + null, + buildHistoryLog1 -> { + JsonMessage jsonMessage = this.deleteLogAndFile(buildHistoryLog1); + if (!jsonMessage.success()) { + log.warn("{} {} {}", buildHistoryLog1.getBuildName(), buildHistoryLog1.getBuildNumberId(), jsonMessage); + return false; + } + return true; + }); } @Override diff --git a/modules/server/src/main/java/org/dromara/jpom/service/dblog/DbMonitorNotifyLogService.java b/modules/server/src/main/java/org/dromara/jpom/service/dblog/DbMonitorNotifyLogService.java index 73ce5a838..da0099588 100644 --- a/modules/server/src/main/java/org/dromara/jpom/service/dblog/DbMonitorNotifyLogService.java +++ b/modules/server/src/main/java/org/dromara/jpom/service/dblog/DbMonitorNotifyLogService.java @@ -39,11 +39,11 @@ public class DbMonitorNotifyLogService extends BaseWorkspaceService extends BaseDbCommonS new Order("modifyTimeMillis", Direction.DESC) }; - public void insert(T t) { + public int insert(T t) { this.fillInsert(t); - super.insertDb(t); + int count = super.insertDb(t); this.executeClear(); + return count; } /** diff --git a/modules/server/src/main/java/org/dromara/jpom/service/monitor/MonitorService.java b/modules/server/src/main/java/org/dromara/jpom/service/monitor/MonitorService.java index 371175a55..4d33ccf0d 100644 --- a/modules/server/src/main/java/org/dromara/jpom/service/monitor/MonitorService.java +++ b/modules/server/src/main/java/org/dromara/jpom/service/monitor/MonitorService.java @@ -44,9 +44,10 @@ import java.util.List; public class MonitorService extends BaseWorkspaceService implements ICron { @Override - public void insert(MonitorModel monitorModel) { - super.insert(monitorModel); + public int insert(MonitorModel monitorModel) { + int count = super.insert(monitorModel); this.checkCron(monitorModel); + return count; } @Override @@ -134,24 +135,24 @@ public class MonitorService extends BaseWorkspaceService implement } - /*public boolean checkProject(String nodeId, String projectId) { - List list = list(); - if (list == null || list.isEmpty()) { - return false; - } - for (MonitorModel monitorModel : list) { - List projects = monitorModel.projects(); - if (projects != null) { - for (MonitorModel.NodeProject project : projects) { - if (project.getNode().equals(nodeId)) { - List projects1 = project.getProjects(); - if (projects1 != null && projects1.contains(projectId)) { - return true; - } - } - } - } - } - return false; - }*/ + /*public boolean checkProject(String nodeId, String projectId) { + List list = list(); + if (list == null || list.isEmpty()) { + return false; + } + for (MonitorModel monitorModel : list) { + List projects = monitorModel.projects(); + if (projects != null) { + for (MonitorModel.NodeProject project : projects) { + if (project.getNode().equals(nodeId)) { + List projects1 = project.getProjects(); + if (projects1 != null && projects1.contains(projectId)) { + return true; + } + } + } + } + } + return false; + }*/ } diff --git a/modules/server/src/main/java/org/dromara/jpom/service/node/ssh/CommandService.java b/modules/server/src/main/java/org/dromara/jpom/service/node/ssh/CommandService.java index eb13ca0a1..416b6663a 100644 --- a/modules/server/src/main/java/org/dromara/jpom/service/node/ssh/CommandService.java +++ b/modules/server/src/main/java/org/dromara/jpom/service/node/ssh/CommandService.java @@ -82,9 +82,10 @@ public class CommandService extends BaseWorkspaceService implement } @Override - public void insert(CommandModel commandModel) { - super.insert(commandModel); + public int insert(CommandModel commandModel) { + int count = super.insert(commandModel); this.checkCron(commandModel); + return count; } @Override @@ -311,34 +312,34 @@ public class CommandService extends BaseWorkspaceService implement */ public void syncToWorkspace(String ids, String nowWorkspaceId, String workspaceId) { StrUtil.splitTrim(ids, StrUtil.COMMA) - .forEach(id -> { - CommandModel data = super.getByKey(id, false, entity -> entity.set("workspaceId", nowWorkspaceId)); - Assert.notNull(data, "没有对应的ssh脚本信息"); - // - CommandModel where = new CommandModel(); - where.setWorkspaceId(workspaceId); - where.setName(data.getName()); - CommandModel exits = super.queryByBean(where); - if (exits == null) { - // 不存在则添加 信息 - data.setId(null); - data.setWorkspaceId(workspaceId); - data.setCreateTimeMillis(null); - data.setModifyTimeMillis(null); - data.setSshIds(null); - data.setModifyUser(null); - super.insert(data); - } else { - // 修改信息 - CommandModel update = new CommandModel(); - update.setId(exits.getId()); - update.setCommand(data.getCommand()); - update.setDesc(data.getDesc()); - update.setDefParams(data.getDefParams()); - update.setAutoExecCron(data.getAutoExecCron()); - super.updateById(update); - } - }); + .forEach(id -> { + CommandModel data = super.getByKey(id, false, entity -> entity.set("workspaceId", nowWorkspaceId)); + Assert.notNull(data, "没有对应的ssh脚本信息"); + // + CommandModel where = new CommandModel(); + where.setWorkspaceId(workspaceId); + where.setName(data.getName()); + CommandModel exits = super.queryByBean(where); + if (exits == null) { + // 不存在则添加 信息 + data.setId(null); + data.setWorkspaceId(workspaceId); + data.setCreateTimeMillis(null); + data.setModifyTimeMillis(null); + data.setSshIds(null); + data.setModifyUser(null); + super.insert(data); + } else { + // 修改信息 + CommandModel update = new CommandModel(); + update.setId(exits.getId()); + update.setCommand(data.getCommand()); + update.setDesc(data.getDesc()); + update.setDefParams(data.getDefParams()); + update.setAutoExecCron(data.getAutoExecCron()); + super.updateById(update); + } + }); } } diff --git a/modules/server/src/main/java/org/dromara/jpom/service/script/ScriptServer.java b/modules/server/src/main/java/org/dromara/jpom/service/script/ScriptServer.java index 55880339a..42e28aeb8 100644 --- a/modules/server/src/main/java/org/dromara/jpom/service/script/ScriptServer.java +++ b/modules/server/src/main/java/org/dromara/jpom/service/script/ScriptServer.java @@ -57,9 +57,10 @@ public class ScriptServer extends BaseGlobalOrWorkspaceService impl } @Override - public void insert(ScriptModel scriptModel) { - super.insert(scriptModel); + public int insert(ScriptModel scriptModel) { + int count = super.insert(scriptModel); this.checkCron(scriptModel); + return count; } @Override diff --git a/modules/storage-module/storage-module-common/src/main/java/org/dromara/jpom/db/BaseDbCommonService.java b/modules/storage-module/storage-module-common/src/main/java/org/dromara/jpom/db/BaseDbCommonService.java index 9cb2fc138..a77ae1893 100644 --- a/modules/storage-module/storage-module-common/src/main/java/org/dromara/jpom/db/BaseDbCommonService.java +++ b/modules/storage-module/storage-module-common/src/main/java/org/dromara/jpom/db/BaseDbCommonService.java @@ -95,11 +95,11 @@ public abstract class BaseDbCommonService { * * @param t 数据 */ - protected final void insertDb(T t) { + protected final int insertDb(T t) { Db db = Db.use(this.getDataSource()); try { Entity entity = this.dataBeanToEntity(t); - db.insert(entity); + return db.insert(entity); } catch (Exception e) { throw warpException(e); }