This commit is contained in:
bwcx_jzy 2023-06-20 18:03:04 +08:00
parent f039b7f99e
commit 0f066f9a41
No known key found for this signature in database
GPG Key ID: E187D6E9DDDE8C53
10 changed files with 106 additions and 107 deletions

View File

@ -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;
}

View File

@ -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("操作成功");
}

View File

@ -90,9 +90,10 @@ public class BuildInfoService extends BaseGroupService<BuildInfoModel> 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

View File

@ -113,28 +113,29 @@ public class DbBuildHistoryLogService extends BaseWorkspaceService<BuildHistoryL
}
@Override
public void insert(BuildHistoryLog buildHistoryLog) {
super.insert(buildHistoryLog);
public int insert(BuildHistoryLog buildHistoryLog) {
int count = super.insert(buildHistoryLog);
// 清理单个
int buildItemMaxHistoryCount = buildExtConfig.getItemMaxHistoryCount();
super.autoLoopClear("startTime", buildItemMaxHistoryCount,
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<String> 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<String> 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<BuildHistoryL
return;
}
super.autoLoopClear("startTime", saveCount,
null,
buildHistoryLog1 -> {
JsonMessage<String> jsonMessage = this.deleteLogAndFile(buildHistoryLog1);
if (!jsonMessage.success()) {
log.warn("{} {} {}", buildHistoryLog1.getBuildName(), buildHistoryLog1.getBuildNumberId(), jsonMessage);
return false;
}
return true;
});
null,
buildHistoryLog1 -> {
JsonMessage<String> jsonMessage = this.deleteLogAndFile(buildHistoryLog1);
if (!jsonMessage.success()) {
log.warn("{} {} {}", buildHistoryLog1.getBuildName(), buildHistoryLog1.getBuildNumberId(), jsonMessage);
return false;
}
return true;
});
}
@Override

View File

@ -39,11 +39,11 @@ public class DbMonitorNotifyLogService extends BaseWorkspaceService<MonitorNotif
@Override
public void insert(MonitorNotifyLog monitorNotifyLog) {
public int insert(MonitorNotifyLog monitorNotifyLog) {
try {
BaseServerController.resetInfo(UserModel.EMPTY);
//
super.insert(monitorNotifyLog);
return super.insert(monitorNotifyLog);
//
} finally {
BaseServerController.removeEmpty();

View File

@ -78,10 +78,11 @@ public abstract class BaseDbService<T extends BaseDbModel> 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;
}
/**

View File

@ -44,9 +44,10 @@ import java.util.List;
public class MonitorService extends BaseWorkspaceService<MonitorModel> implements ICron<MonitorModel> {
@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<MonitorModel> implement
}
/*public boolean checkProject(String nodeId, String projectId) {
List<MonitorModel> list = list();
if (list == null || list.isEmpty()) {
return false;
}
for (MonitorModel monitorModel : list) {
List<MonitorModel.NodeProject> projects = monitorModel.projects();
if (projects != null) {
for (MonitorModel.NodeProject project : projects) {
if (project.getNode().equals(nodeId)) {
List<String> projects1 = project.getProjects();
if (projects1 != null && projects1.contains(projectId)) {
return true;
}
}
}
}
}
return false;
}*/
/*public boolean checkProject(String nodeId, String projectId) {
List<MonitorModel> list = list();
if (list == null || list.isEmpty()) {
return false;
}
for (MonitorModel monitorModel : list) {
List<MonitorModel.NodeProject> projects = monitorModel.projects();
if (projects != null) {
for (MonitorModel.NodeProject project : projects) {
if (project.getNode().equals(nodeId)) {
List<String> projects1 = project.getProjects();
if (projects1 != null && projects1.contains(projectId)) {
return true;
}
}
}
}
}
return false;
}*/
}

View File

@ -82,9 +82,10 @@ public class CommandService extends BaseWorkspaceService<CommandModel> 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<CommandModel> 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);
}
});
}
}

View File

@ -57,9 +57,10 @@ public class ScriptServer extends BaseGlobalOrWorkspaceService<ScriptModel> 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

View File

@ -95,11 +95,11 @@ public abstract class BaseDbCommonService<T> {
*
* @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);
}