通用分页,通用列表查询方法

This commit is contained in:
bwcx_jzy 2021-12-03 14:06:55 +08:00
parent bf40266965
commit d01266d44b
25 changed files with 332 additions and 894 deletions

View File

@ -32,8 +32,6 @@ public class Const {
*/
public static final String ID_STR = "id";
public static final String GROUP_STR = "group";
public static final String GROUP_COLUMN_STR = "`group`";
/**
* 应用程序类型的配置 key

View File

@ -181,7 +181,7 @@ public class LoginControl extends BaseServerController {
return JsonMessage.getString(400, "该账户登录失败次数过多,已被锁定" + msg + ",请不要再次尝试");
}
// 验证
if (userPwd.equals(userModel.getPassword())) {
if (userService.simpleLogin(userName, userPwd) != null) {
userModel.unLock();
setSessionAttribute(LoginInterceptor.SESSION_NAME, userModel);
removeSessionAttribute(SHOW_CODE);

View File

@ -27,9 +27,6 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Tuple;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.common.validator.ValidatorConfig;
import cn.jiangzeyin.common.validator.ValidatorItem;
@ -38,11 +35,14 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.jpom.build.BuildUtil;
import io.jpom.common.BaseServerController;
import io.jpom.common.Const;
import io.jpom.common.interceptor.OptLog;
import io.jpom.model.AfterOpt;
import io.jpom.model.BaseEnum;
import io.jpom.model.data.*;
import io.jpom.model.PageResultDto;
import io.jpom.model.data.BuildInfoModel;
import io.jpom.model.data.RepositoryModel;
import io.jpom.model.data.SshModel;
import io.jpom.model.data.UserModel;
import io.jpom.model.enums.BuildReleaseMethod;
import io.jpom.model.log.UserOperateLogV1;
import io.jpom.plugin.ClassFeature;
@ -104,27 +104,14 @@ public class BuildInfoController extends BaseServerController {
/**
* load build list with params
*
* @param group
* @return
* @return json
*/
@RequestMapping(value = "/build/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String getBuildList(String group,
@ValidatorConfig(value = {
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "limit error")
}, defaultVal = "10") int limit,
@ValidatorConfig(value = {
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "page error")
}, defaultVal = "1") int page) {
// if group is empty string, dont set into entity property
Entity where = Entity.create()
.setIgnoreNull(Const.GROUP_COLUMN_STR, StrUtil.isEmpty(group) ? null : group);
Page pageReq = new Page(page, limit);
public String getBuildList() {
// load list with page
PageResult<BuildInfoModel> list = buildInfoService.listPage(where, pageReq);
JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", list);
jsonObject.put("total", list.getTotal());
return jsonObject.toString();
PageResultDto<BuildInfoModel> list = buildInfoService.listPage(getRequest());
return JsonMessage.getString(200, "获取成功", list);
}
/**
@ -317,7 +304,7 @@ public class BuildInfoController extends BaseServerController {
public String branchList(
@ValidatorConfig(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "仓库ID不能为空")) String repositoryId) throws Exception {
// 根据 repositoryId 查询仓库信息
RepositoryModel repositoryModel = repositoryService.getByKey(repositoryId);
RepositoryModel repositoryModel = repositoryService.getByKey(repositoryId, false);
Assert.notNull(repositoryModel, "无效的仓库信息");
//
Assert.state(repositoryModel.getRepoType() == 0, "只有 GIT 仓库才有分支信息");

View File

@ -29,17 +29,16 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.hutool.extra.servlet.ServletUtil;
import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.common.validator.ValidatorConfig;
import cn.jiangzeyin.common.validator.ValidatorItem;
import cn.jiangzeyin.common.validator.ValidatorRule;
import com.alibaba.fastjson.JSONObject;
import io.jpom.build.BuildUtil;
import io.jpom.common.BaseServerController;
import io.jpom.common.interceptor.OptLog;
import io.jpom.model.BaseEnum;
import io.jpom.model.PageResultDto;
import io.jpom.model.data.BuildInfoModel;
import io.jpom.model.data.UserModel;
import io.jpom.model.enums.BuildStatus;
@ -60,9 +59,10 @@ import org.springframework.web.bind.annotation.RestController;
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.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
@ -170,29 +170,33 @@ public class BuildInfoHistoryController extends BaseServerController {
entity.set("buildDataId", dataIds);
}
}
PageResult<BuildHistoryLog> pageResult = dbBuildHistoryLogService.listPage(entity, pageObj);
List<BuildHistoryLogVo> 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());
PageResultDto<BuildHistoryLog> pageResultTemp = dbBuildHistoryLogService.listPage(entity, pageObj);
//
PageResultDto<BuildHistoryLogVo> pageResult = new PageResultDto<>(pageResultTemp);
List<BuildHistoryLogVo> result = pageResult.getResult();
if (result != null) {
List<BuildHistoryLogVo> collect = result.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());
}
}
}
return buildHistoryLogVo;
}).collect(Collectors.toList());
JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", collect);
jsonObject.put("total", pageResult.getTotal());
return jsonObject.toString();
return buildHistoryLogVo;
}).collect(Collectors.toList());
pageResult.setResult(collect);
}
return JsonMessage.getString(200, "获取成功", pageResult);
}
private Set<String> getDataIds() {
Entity where = Entity.create();
Page pageReq = new Page();
List<BuildInfoModel> list = buildInfoService.listPage(where, pageReq);
List<BuildInfoModel> list = buildInfoService.listPageOnlyResult(where, pageReq);
if (CollUtil.isEmpty(list)) {
return new HashSet<>();
} else {

View File

@ -30,7 +30,6 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.hutool.db.sql.Direction;
import cn.hutool.db.sql.Order;
import cn.jiangzeyin.common.DefaultSystemLog;
@ -38,10 +37,10 @@ import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.common.validator.ValidatorConfig;
import cn.jiangzeyin.common.validator.ValidatorItem;
import cn.jiangzeyin.common.validator.ValidatorRule;
import com.alibaba.fastjson.JSONObject;
import io.jpom.build.BuildUtil;
import io.jpom.common.BaseServerController;
import io.jpom.common.Const;
import io.jpom.model.PageResultDto;
import io.jpom.model.data.RepositoryModel;
import io.jpom.model.data.UserModel;
import io.jpom.model.enums.GitProtocolEnum;
@ -95,15 +94,8 @@ public class RepositoryController extends BaseServerController {
entity.setIgnoreNull("repoType", repoType);
//管理员可以获取删除或者没删除的
entity.setIgnoreNull("strike", userModel.isSystemUser() ? strike : 0);
PageResult<RepositoryModel> pageResult = repositoryService.listPage(entity, pageObj);
pageResult.forEach(repositoryModel -> {
// 隐藏密码字段
repositoryModel.setPassword(null);
repositoryModel.setRsaPrv(null);
});
JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", pageResult);
jsonObject.put("total", pageResult.getTotal());
return jsonObject;
PageResultDto<RepositoryModel> pageResult = repositoryService.listPage(entity, pageObj);
return JsonMessage.getString(200, "获取成功", pageResult);
}
/**

View File

@ -26,13 +26,12 @@ import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.common.validator.ValidatorConfig;
import cn.jiangzeyin.common.validator.ValidatorItem;
import cn.jiangzeyin.common.validator.ValidatorRule;
import com.alibaba.fastjson.JSONObject;
import io.jpom.common.BaseServerController;
import io.jpom.model.PageResultDto;
import io.jpom.model.log.MonitorNotifyLog;
import io.jpom.plugin.ClassFeature;
import io.jpom.plugin.Feature;
@ -57,60 +56,40 @@ import javax.annotation.Resource;
@Feature(cls = ClassFeature.MONITOR)
public class MonitorLogController extends BaseServerController {
@Resource
private DbMonitorNotifyLogService dbMonitorNotifyLogService;
@Resource
private DbMonitorNotifyLogService dbMonitorNotifyLogService;
// /**
// * 展示监控页面
// *
// * @return page
// */
// @RequestMapping(value = "log.html", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
// @Feature(method = MethodFeature.LOG)
// public String list() {
// // 所有节点
// List<NodeModel> nodeModels = nodeService.list();
// setAttribute("nodeArray", nodeModels);
//
// //通知方式
// JSONArray notifyTypeArray = BaseEnum.toJSONArray(MonitorModel.NotifyType.class);
// setAttribute("notifyTypeArray", notifyTypeArray);
// return "monitor/loglist";
// }
/**
* 展示用户列表
*
* @param selectNode 节点
* @param limit 限制
* @param notifyStatus 状态
* @return json
*/
@RequestMapping(value = "list_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@Feature(method = MethodFeature.LOG)
public String listData(String selectNode, String notifyStatus,
@ValidatorConfig(value = {
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "limit error")
}, defaultVal = "10") int limit,
@ValidatorConfig(value = {
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "page error")
}, defaultVal = "1") int page) {
Page pageObj = new Page(page, limit);
Entity entity = Entity.create();
this.doPage(pageObj, entity, "createTime");
/**
* 展示用户列表
*
* @param selectNode 节点
* @param limit 限制
* @param notifyStatus 状态
* @return json
*/
@RequestMapping(value = "list_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@Feature(method = MethodFeature.LOG)
public String listData(String selectNode, String notifyStatus,
@ValidatorConfig(value = {
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "limit error")
}, defaultVal = "10") int limit,
@ValidatorConfig(value = {
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "page error")
}, defaultVal = "1") int page) {
Page pageObj = new Page(page, limit);
Entity entity = Entity.create();
this.doPage(pageObj, entity, "createTime");
if (StrUtil.isNotEmpty(selectNode)) {
entity.set("nodeId", selectNode);
}
if (StrUtil.isNotEmpty(selectNode)) {
entity.set("nodeId", selectNode);
}
if (StrUtil.isNotEmpty(notifyStatus)) {
entity.set("notifyStatus", Convert.toBool(notifyStatus, true));
}
if (StrUtil.isNotEmpty(notifyStatus)) {
entity.set("notifyStatus", Convert.toBool(notifyStatus, true));
}
PageResult<MonitorNotifyLog> pageResult = dbMonitorNotifyLogService.listPage(entity, pageObj);
JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", pageResult);
jsonObject.put("total", pageResult.getTotal());
return jsonObject.toString();
}
PageResultDto<MonitorNotifyLog> pageResult = dbMonitorNotifyLogService.listPage(entity, pageObj);
return JsonMessage.getString(200, "获取成功", pageResult);
}
}

View File

@ -8,7 +8,6 @@ import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.hutool.db.sql.Direction;
import cn.hutool.db.sql.Order;
import cn.hutool.extra.servlet.ServletUtil;
@ -19,6 +18,7 @@ import io.jpom.common.forward.NodeForward;
import io.jpom.common.forward.NodeUrl;
import io.jpom.model.BaseEnum;
import io.jpom.model.Cycle;
import io.jpom.model.PageResultDto;
import io.jpom.model.data.NodeModel;
import io.jpom.model.data.UserModel;
import io.jpom.model.log.SystemMonitorLog;
@ -90,7 +90,7 @@ public class NodeWelcomeController extends BaseServerController {
return JsonMessage.getString(200, "ok", object);
}
private PageResult<SystemMonitorLog> getList(String time, long millis) {
private PageResultDto<SystemMonitorLog> getList(String time, long millis) {
long endTime = System.currentTimeMillis();
long startTime = endTime - TimeUnit.MINUTES.toMillis(30);
if (StrUtil.isNotEmpty(time)) {
@ -119,10 +119,10 @@ public class NodeWelcomeController extends BaseServerController {
private JSONObject getData(String selTime) {
long millis = getCycleMillis();
PageResult<SystemMonitorLog> pageResult = getList(selTime, millis);
PageResultDto<SystemMonitorLog> pageResult = getList(selTime, millis);
List<JSONObject> series = new ArrayList<>();
List<String> scale = new ArrayList<>();
for (int i = pageResult.size() - 1; i >= 0; i--) {
for (int i = pageResult.getTotal() - 1; i >= 0; i--) {
SystemMonitorLog systemMonitorLog = pageResult.get(i);
if (StrUtil.isEmpty(selTime)) {
scale.add(DateUtil.formatTime(new Date(systemMonitorLog.getMonitorTime())));
@ -168,14 +168,15 @@ public class NodeWelcomeController extends BaseServerController {
@RequestMapping(value = "exportTop")
public void exportTop(String time) throws UnsupportedEncodingException {
PageResult<SystemMonitorLog> monitorData = getList(time, getCycleMillis());
PageResultDto<SystemMonitorLog> monitorData = getList(time, getCycleMillis());
if (monitorData.getTotal() <= 0) {
// NodeForward.requestDownload(node, getRequest(), getResponse(), NodeUrl.exportTop);
} else {
NodeModel node = getNode();
StringBuilder buf = new StringBuilder();
buf.append("监控时间").append(",占用cpu").append(",占用内存").append(",占用磁盘").append("\r\n");
for (SystemMonitorLog log : monitorData) {
List<SystemMonitorLog> result = monitorData.getResult();
for (SystemMonitorLog log : result) {
long monitorTime = log.getMonitorTime();
buf.append(DateUtil.date(monitorTime).toString()).append(",")
.append(log.getOccupyCpu()).append("%").append(",")

View File

@ -4,18 +4,17 @@ import cn.hutool.core.text.StrSplitter;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.hutool.extra.ssh.JschUtil;
import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.common.validator.ValidatorConfig;
import cn.jiangzeyin.common.validator.ValidatorItem;
import cn.jiangzeyin.common.validator.ValidatorRule;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jcraft.jsch.Session;
import io.jpom.common.BaseServerController;
import io.jpom.common.interceptor.OptLog;
import io.jpom.model.BaseModel;
import io.jpom.model.PageResultDto;
import io.jpom.model.data.AgentWhitelist;
import io.jpom.model.data.NodeModel;
import io.jpom.model.data.SshModel;
@ -254,10 +253,8 @@ public class SshController extends BaseServerController {
entity.set("userId".toUpperCase(), userId);
}
PageResult<SshTerminalExecuteLog> pageResult = sshTerminalExecuteLogService.listPage(entity, pageObj);
JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", pageResult);
jsonObject.put("total", pageResult.getTotal());
return jsonObject.toString();
PageResultDto<SshTerminalExecuteLog> pageResult = sshTerminalExecuteLogService.listPage(entity, pageObj);
return JsonMessage.getString(200, "获取成功", pageResult);
}
}

View File

@ -25,13 +25,12 @@ package io.jpom.controller.outgiving;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.common.validator.ValidatorConfig;
import cn.jiangzeyin.common.validator.ValidatorItem;
import cn.jiangzeyin.common.validator.ValidatorRule;
import com.alibaba.fastjson.JSONObject;
import io.jpom.common.BaseServerController;
import io.jpom.model.PageResultDto;
import io.jpom.model.log.OutGivingLog;
import io.jpom.plugin.ClassFeature;
import io.jpom.plugin.Feature;
@ -56,10 +55,10 @@ import javax.annotation.Resource;
@RequestMapping(value = "/outgiving")
@Feature(cls = ClassFeature.OUTGIVING)
public class OutGivingLogController extends BaseServerController {
@Resource
private OutGivingServer outGivingServer;
@Resource
private DbOutGivingLogService dbOutGivingLogService;
@Resource
private OutGivingServer outGivingServer;
@Resource
private DbOutGivingLogService dbOutGivingLogService;
// @RequestMapping(value = "log.html", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
// @Feature(method = MethodFeature.LOG)
@ -76,37 +75,35 @@ public class OutGivingLogController extends BaseServerController {
// return "outgiving/loglist";
// }
@RequestMapping(value = "log_list_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@Feature(method = MethodFeature.LOG)
public String listData(String nodeId,
String outGivingId,
String status,
@ValidatorConfig(value = {
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "limit error")
}, defaultVal = "10") int limit,
@ValidatorConfig(value = {
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "page error")
}, defaultVal = "1") int page) {
@RequestMapping(value = "log_list_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@Feature(method = MethodFeature.LOG)
public String listData(String nodeId,
String outGivingId,
String status,
@ValidatorConfig(value = {
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "limit error")
}, defaultVal = "10") int limit,
@ValidatorConfig(value = {
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "page error")
}, defaultVal = "1") int page) {
Page pageObj = new Page(page, limit);
Entity entity = Entity.create();
this.doPage(pageObj, entity, "startTime");
if (StrUtil.isNotEmpty(nodeId)) {
entity.set("nodeId", nodeId);
}
Page pageObj = new Page(page, limit);
Entity entity = Entity.create();
this.doPage(pageObj, entity, "startTime");
if (StrUtil.isNotEmpty(nodeId)) {
entity.set("nodeId", nodeId);
}
if (StrUtil.isNotEmpty(outGivingId)) {
entity.set("outGivingId", outGivingId);
}
if (StrUtil.isNotEmpty(outGivingId)) {
entity.set("outGivingId", outGivingId);
}
if (StrUtil.isNotEmpty(status)) {
entity.set("outGivingId", status);
}
if (StrUtil.isNotEmpty(status)) {
entity.set("outGivingId", status);
}
PageResult<OutGivingLog> pageResult = dbOutGivingLogService.listPage(entity, pageObj);
JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", pageResult);
jsonObject.put("total", pageResult.getTotal());
return jsonObject.toString();
}
PageResultDto<OutGivingLog> pageResult = dbOutGivingLogService.listPage(entity, pageObj);
return JsonMessage.getString(200, "获取成功", pageResult);
}
}

View File

@ -28,7 +28,6 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.hutool.db.sql.Direction;
import cn.hutool.db.sql.Order;
import cn.hutool.extra.servlet.ServletUtil;
@ -39,10 +38,10 @@ import cn.jiangzeyin.common.validator.ValidatorItem;
import cn.jiangzeyin.common.validator.ValidatorRule;
import cn.jiangzeyin.controller.multipart.MultipartFileBuilder;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.jpom.common.BaseServerController;
import io.jpom.common.Const;
import io.jpom.common.interceptor.OptLog;
import io.jpom.model.PageResultDto;
import io.jpom.model.data.BackupInfoModel;
import io.jpom.model.enums.BackupStatusEnum;
import io.jpom.model.log.UserOperateLogV1;
@ -100,11 +99,9 @@ public class BackupInfoController extends BaseServerController {
entity.setIgnoreNull("backupType", backupType);
// 查询数据库
PageResult<BackupInfoModel> pageResult = backupInfoService.listPage(entity, pageObj);
PageResultDto<BackupInfoModel> pageResult = backupInfoService.listPage(entity, pageObj);
JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", pageResult);
jsonObject.put("total", pageResult.getTotal());
return jsonObject;
return JsonMessage.getString(200, "获取成功", pageResult);
}
/**

View File

@ -25,13 +25,12 @@ package io.jpom.controller.user.log;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.common.validator.ValidatorConfig;
import cn.jiangzeyin.common.validator.ValidatorItem;
import cn.jiangzeyin.common.validator.ValidatorRule;
import com.alibaba.fastjson.JSONObject;
import io.jpom.common.BaseServerController;
import io.jpom.model.PageResultDto;
import io.jpom.model.log.UserOperateLogV1;
import io.jpom.plugin.ClassFeature;
import io.jpom.plugin.Feature;
@ -91,9 +90,7 @@ public class UserOptLogController extends BaseServerController {
entity.set("userId".toUpperCase(), selectUser);
}
PageResult<UserOperateLogV1> pageResult = dbUserOperateLogService.listPage(entity, pageObj);
JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", pageResult);
jsonObject.put("total", pageResult.getTotal());
return jsonObject.toString();
PageResultDto<UserOperateLogV1> pageResult = dbUserOperateLogService.listPage(entity, pageObj);
return JsonMessage.getString(200, "获取成功", pageResult);
}
}

View File

@ -0,0 +1,109 @@
package io.jpom.model;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.PageUtil;
import cn.hutool.db.PageResult;
import java.io.Serializable;
import java.util.List;
/**
* 分页查询结果对象
*
* @author bwcx_jzy
* @since 2021/12/3
*/
public class PageResultDto<T> implements Serializable {
public static final PageResultDto EMPTY = new PageResultDto<>(1, 10, 0);
/**
* 结果
*/
private List<T> result;
/**
* 页码
*/
private Integer page;
/**
* 每页结果数
*/
private Integer pageSize;
/**
* 总页数
*/
private Integer totalPage;
/**
* 总数
*/
private Integer total;
public PageResultDto(PageResult<T> pageResult) {
this.setPage(pageResult.getPage());
this.setPageSize(pageResult.getPageSize());
this.setTotalPage(pageResult.getTotalPage());
this.setTotal(pageResult.getTotal());
}
public PageResultDto(PageResultDto<?> pageResult) {
this.setPage(pageResult.getPage());
this.setPageSize(pageResult.getPageSize());
this.setTotalPage(pageResult.getTotalPage());
this.setTotal(pageResult.getTotal());
}
public PageResultDto(int page, int pageSize, int total) {
this.setPage(page);
this.setPageSize(pageSize);
this.setTotalPage(PageUtil.totalPage(total, pageSize));
this.setTotal(total);
}
public List<T> getResult() {
return result;
}
public void setResult(List<T> result) {
this.result = result;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public Integer getTotalPage() {
return totalPage;
}
public void setTotalPage(Integer totalPage) {
this.totalPage = totalPage;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public boolean isEmpty() {
return CollUtil.isEmpty(getResult());
}
public T get(int index) {
return CollUtil.get(getResult(), index);
}
}

View File

@ -76,15 +76,15 @@ public class UserModel extends BaseStrikeDbModel {
/**
* 连续登录失败次数
*/
private int pwdErrorCount;
private Integer pwdErrorCount;
/**
* 最后失败时间
*/
private long lastPwdErrorTime;
private Long lastPwdErrorTime;
/**
* 账号被锁定的时长
*/
private long lockTime;
private Long lockTime;
// /**
// * 记录最后修改时间
// */
@ -131,15 +131,15 @@ public class UserModel extends BaseStrikeDbModel {
this.systemUser = systemUser;
}
public long getLockTime() {
public Long getLockTime() {
return lockTime;
}
public long getLastPwdErrorTime() {
public Long getLastPwdErrorTime() {
return lastPwdErrorTime;
}
public void setLastPwdErrorTime(long lastPwdErrorTime) {
public void setLastPwdErrorTime(Long lastPwdErrorTime) {
this.lastPwdErrorTime = lastPwdErrorTime;
}
@ -147,7 +147,7 @@ public class UserModel extends BaseStrikeDbModel {
this.lockTime = lockTime;
}
public int getPwdErrorCount() {
public Integer getPwdErrorCount() {
return pwdErrorCount;
}
@ -185,7 +185,7 @@ public class UserModel extends BaseStrikeDbModel {
public void unLock() {
setPwdErrorCount(0);
setLockTime(0);
setLastPwdErrorTime(0);
setLastPwdErrorTime(0L);
}
/**
@ -202,13 +202,13 @@ public class UserModel extends BaseStrikeDbModel {
return 0;
}
// 最后一次失败时间
long lastTime = getLastPwdErrorTime();
if (lastTime <= 0) {
Long lastTime = getLastPwdErrorTime();
if (lastTime == null || lastTime <= 0) {
return 0;
}
// 当前锁定时间
long lockTime = getLockTime();
if (lockTime <= 0) {
Long lockTime = getLockTime();
if (lockTime == null || lockTime <= 0) {
return 0;
}
// 解锁时间

View File

@ -31,7 +31,6 @@ import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.Task;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.hutool.db.sql.Direction;
import cn.hutool.db.sql.Order;
import cn.hutool.http.HttpStatus;
@ -43,6 +42,7 @@ import com.alibaba.fastjson.JSONObject;
import io.jpom.common.forward.NodeForward;
import io.jpom.common.forward.NodeUrl;
import io.jpom.model.Cycle;
import io.jpom.model.PageResultDto;
import io.jpom.model.data.MonitorModel;
import io.jpom.model.data.NodeModel;
import io.jpom.model.data.UserModel;
@ -280,7 +280,7 @@ public class Monitor implements Task {
page.addOrder(new Order("createTime", Direction.DESC));
PageResult<MonitorNotifyLog> pageResult = dbMonitorNotifyLogService.listPage(entity, page);
PageResultDto<MonitorNotifyLog> pageResult = dbMonitorNotifyLogService.listPage(entity, page);
if (pageResult.isEmpty()) {
return true;
}

View File

@ -23,7 +23,7 @@
package io.jpom.service.dblog;
import cn.hutool.db.Entity;
import cn.hutool.db.PageResult;
import io.jpom.model.PageResultDto;
import io.jpom.model.log.SystemMonitorLog;
import io.jpom.service.h2db.BaseDbCommonService;
import org.springframework.stereotype.Service;
@ -39,7 +39,7 @@ public class DbSystemMonitorLogService extends BaseDbCommonService<SystemMonitor
super(SystemMonitorLog.TABLE_NAME, "id", SystemMonitorLog.class);
}
public PageResult<SystemMonitorLog> getMonitorData(long startTime, long endTime) {
public PageResultDto<SystemMonitorLog> getMonitorData(long startTime, long endTime) {
Entity entity = new Entity(SystemMonitorLog.TABLE_NAME);
entity.set(" MONITORTIME", ">= " + startTime);
entity.set("MONITORTIME", "<= " + endTime);

View File

@ -33,4 +33,13 @@ import org.springframework.stereotype.Service;
@Service
public class RepositoryService extends BaseDbService<RepositoryModel> {
@Override
protected void fillSelectResult(RepositoryModel repositoryModel) {
if (repositoryModel == null) {
return;
}
// 隐藏密码字段
repositoryModel.setPassword(null);
repositoryModel.setRsaPrv(null);
}
}

View File

@ -33,6 +33,7 @@ import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.jiangzeyin.common.DefaultSystemLog;
import io.jpom.model.PageResultDto;
import io.jpom.system.JpomRuntimeException;
import io.jpom.system.db.DbConfig;
@ -402,11 +403,12 @@ public abstract class BaseDbCommonService<T> {
* @param page 分页
* @return 结果
*/
public PageResult<T> listPage(Entity where, Page page) {
@SuppressWarnings({"unchecked", "rawtypes"})
public PageResultDto<T> listPage(Entity where, Page page) {
if (!DbConfig.getInstance().isInit()) {
// ignore
DefaultSystemLog.getLog().error("The database is not initialized, this execution will be ignored");
return new PageResult<>(page.getPageNumber(), page.getPageSize(), 0);
return PageResultDto.EMPTY;
}
where.setTableName(getTableName());
PageResult<Entity> pageResult;
@ -423,9 +425,20 @@ public abstract class BaseDbCommonService<T> {
this.fillSelectResult(entityToBean);
return entityToBean;
}).collect(Collectors.toList());
PageResult<T> pageResult1 = new PageResult<>(pageResult.getPage(), pageResult.getPageSize(), pageResult.getTotal());
pageResult1.addAll(list);
return pageResult1;
PageResultDto<T> pageResultDto = new PageResultDto(pageResult);
pageResultDto.setResult(list);
return pageResultDto;
}
/**
* 分页查询
*
* @param where 条件
* @param page 分页
* @return 结果
*/
public List<T> listPageOnlyResult(Entity where, Page page) {
PageResultDto<T> pageResultDto = this.listPage(where, page);
return pageResultDto.getResult();
}
/**

View File

@ -22,21 +22,30 @@
*/
package io.jpom.service.h2db;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.SystemClock;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.sql.Direction;
import cn.hutool.db.sql.Order;
import cn.hutool.extra.servlet.ServletUtil;
import io.jpom.common.BaseServerController;
import io.jpom.common.Const;
import io.jpom.model.BaseDbModel;
import io.jpom.model.BaseUserModifyDbModel;
import io.jpom.model.PageResultDto;
import io.jpom.model.data.UserModel;
import org.springframework.util.Assert;
import javax.servlet.ServletRequest;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* 数据库操作 通用 serve
@ -129,4 +138,38 @@ public abstract class BaseDbService<T extends BaseDbModel> extends BaseDbCommonS
public long count() {
return super.count(Entity.create());
}
/**
* 通用的分页查询
* <p>
* page=1&limit=10&order=ascend&order_field=name
*
* @param request 请求对象
* @return page
*/
public PageResultDto<T> listPage(ServletRequest request) {
Map<String, String> paramMap = ServletUtil.getParamMap(request);
int page = Convert.toInt(paramMap.get("page"), 1);
int limit = Convert.toInt(paramMap.get("limit"), 10);
Assert.state(page > 0, "page value error");
Assert.state(limit > 0 && limit < 200, "limit value error");
String orderField = paramMap.get("order_field");
String order = paramMap.get("order");
// 移除 默认字段
MapUtil.removeAny(paramMap, "page", "limit", "order_field", "order");
//
Page pageReq = new Page(page, limit);
Entity where = Entity.create();
//
for (Map.Entry<String, String> stringStringEntry : paramMap.entrySet()) {
String key = stringStringEntry.getKey();
String value = stringStringEntry.getValue();
where.setIgnoreNull(StrUtil.format("`{}`", key), value);
}
if (StrUtil.isNotEmpty(orderField)) {
pageReq.addOrder(new Order(orderField, StrUtil.equalsIgnoreCase(order, "ascend") ? Direction.ASC : Direction.DESC));
}
return super.listPage(where, pageReq);
}
}

View File

@ -28,6 +28,9 @@ public class UserService extends BaseDbService<UserModel> {
@Override
protected void fillSelectResult(UserModel data) {
if (data == null) {
return;
}
data.setSalt(null);
}

View File

@ -30,12 +30,10 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Tuple;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import io.jpom.build.BuildUtil;
import io.jpom.common.Const;
import io.jpom.model.data.RepositoryModel;
import io.jpom.model.enums.GitProtocolEnum;
import io.jpom.system.JpomRuntimeException;

View File

@ -158,7 +158,7 @@ export default {
this.listQuery.time = this.timeRange;
geteBuildHistory(this.listQuery).then(res => {
if (res.code === 200) {
this.list = res.data;
this.list = res.data.result;
this.total = res.total;
}
this.loading = false;

View File

@ -267,7 +267,7 @@ export default {
{ title: "顺序重启(有重启失败将继续)", value: 3 },
],
columns: [
{ title: "名称", dataIndex: "name", width: 150, ellipsis: true, scopedSlots: { customRender: "name" } },
{ title: "名称", dataIndex: "name", width: 150, sorter: true, ellipsis: true, scopedSlots: { customRender: "name" } },
{ title: "分组", dataIndex: "group", width: 100, ellipsis: true, scopedSlots: { customRender: "group" } },
{
title: "分支",
@ -402,8 +402,8 @@ export default {
this.loading = true;
getBuildList(this.listQuery).then((res) => {
if (res.code === 200) {
this.list = res.data;
this.total = res.total;
this.list = res.data.result;
this.total = res.data.total;
}
this.loading = false;
});
@ -417,7 +417,7 @@ export default {
};
getRepositoryList(query).then((res) => {
if (res.code === 200) {
this.repositoryList = res.data;
this.repositoryList = res.data.result;
}
});
},
@ -698,9 +698,14 @@ export default {
this.handleFilter();
},
//
changePage(pagination) {
changePage(pagination, filters, sorter) {
console.log(pagination, filters, sorter);
this.listQuery.page = pagination.current;
this.listQuery.limit = pagination.pageSize;
if (sorter) {
this.listQuery.order = sorter.order;
this.listQuery.order_field = sorter.field;
}
this.loadData();
},
},

View File

@ -1,687 +0,0 @@
/** * 该页面是老版本的构建信息页面,之后可能会删除,新版本的页面请参考 ./list-info.vue */
<template>
<div>
<div ref="filter" class="filter">
<a-select v-model="listQuery.group" allowClear placeholder="请选择分组" class="filter-item" @change="handleFilter">
<a-select-option v-for="group in groupList" :key="group">{{ group }}</a-select-option>
</a-select>
<a-button type="primary" @click="handleFilter">搜索</a-button>
<a-button type="primary" @click="handleAdd">新增</a-button>
<a-button type="primary" @click="loadData">刷新</a-button>
</div>
<!-- 表格 -->
<a-table
:loading="loading"
:columns="columns"
:data-source="list"
:style="{ 'max-height': tableHeight + 'px' }"
:scroll="{ x: 1210, y: tableHeight - 60 }"
bordered
rowKey="id"
:pagination="false"
>
<a-tooltip slot="name" slot-scope="text" placement="topLeft" :title="text">
<span>{{ text }}</span>
</a-tooltip>
<a-tooltip slot="branchName" slot-scope="text" placement="topLeft" :title="text">
<span>{{ text }}</span>
</a-tooltip>
<template slot="releaseMethod" slot-scope="text" placement="topleft" :title="text">
<span>{{ releaseMethodMap[text] }}</span>
</template>
<template slot="status" slot-scope="text">
<span v-if="text === 0">未构建</span>
<span v-else-if="text === 1">构建中</span>
<span v-else-if="text === 2">构建成功</span>
<span v-else-if="text === 3">构建失败</span>
<span v-else-if="text === 4">发布中</span>
<span v-else-if="text === 5">发布成功</span>
<span v-else-if="text === 6">发布失败</span>
<span v-else-if="text === 7">取消构建</span>
<span v-else>未知状态</span>
</template>
<a-tooltip slot="buildIdStr" slot-scope="text, record" placement="topLeft" :title="text + ' ( 点击查看日志 ) '">
<span v-if="record.buildId <= 0"></span>
<a-tag v-else color="#108ee9" @click="handleBuildLog(record)">{{ text }}</a-tag>
</a-tooltip>
<a-tooltip slot="modifyUser" slot-scope="text" placement="topLeft" :title="text">
<span>{{ text }}</span>
</a-tooltip>
<template slot="operation" slot-scope="text, record">
<a-button type="primary" @click="handleEdit(record)">编辑</a-button>
<a-button type="danger" v-if="record.status === 1 || record.status === 4" @click="handleStopBuild(record)">停止 </a-button>
<a-button type="primary" v-else @click="handleStartBuild(record)">构建</a-button>
<a-dropdown>
<a class="ant-dropdown-link" @click="(e) => e.preventDefault()">
更多
<a-icon type="down" />
</a>
<a-menu slot="overlay">
<a-menu-item>
<a-button type="primary" @click="handleTrigger(record)">触发器</a-button>
</a-menu-item>
<a-menu-item>
<a-button type="danger" @click="handleDelete(record)">删除</a-button>
</a-menu-item>
<a-menu-item>
<a-button type="danger" :disabled="!record.sourceExist" @click="handleClear(record)">清除构建 </a-button>
</a-menu-item>
</a-menu>
</a-dropdown>
</template>
</a-table>
<!-- 编辑区 -->
<a-modal v-model="editBuildVisible" title="编辑构建" @ok="handleEditBuildOk" width="40%" :maskClosable="false">
<a-form-model ref="editBuildForm" :rules="rules" :model="temp" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
<a-form-model-item label="名称" prop="name">
<a-input v-model="temp.name" placeholder="名称" />
</a-form-model-item>
<a-form-model-item label="分组名称" prop="group">
<a-row>
<a-col :span="18">
<a-select v-model="temp.group" placeholder="可手动输入">
<a-select-option v-for="group in groupList" :key="group">{{ group }}</a-select-option>
</a-select>
</a-col>
<a-col :span="6">
<a-popover v-model="addGroupvisible" title="添加分组" trigger="click">
<template slot="content">
<a-row>
<a-col :span="18">
<a-input v-model="temp.tempGroup" placeholder="分组名称" />
</a-col>
<a-col :span="6">
<a-button type="primary" @click="handleAddGroup">确认</a-button>
</a-col>
</a-row>
</template>
<a-button type="primary" class="btn-add">添加分组</a-button>
</a-popover>
</a-col>
</a-row>
</a-form-model-item>
<a-form-model-item label="仓库地址" prop="gitUrl">
<a-input-group compact>
<a-select style="width: 20%" v-model="temp.repoType" name="repoType" placeholder="仓库类型">
<a-select-option :value="0">GIT</a-select-option>
<a-select-option :value="1">SVN</a-select-option>
</a-select>
<a-input style="width: 80%" v-model="temp.gitUrl" placeholder="仓库地址" />
</a-input-group>
</a-form-model-item>
<!-- <a-form-model-item label="仓库类型" prop="repoType">-->
<!-- </a-form-model-item>-->
<a-form-model-item label="账号信息" prop="userName">
<a-input-group size="large">
<a-row :gutter="12">
<a-col :span="12">
<a-input v-model="temp.userName" placeholder="登录用户">
<a-icon slot="prefix" type="user" />
</a-input>
</a-col>
<a-col :span="12">
<a-input-password v-model="temp.password" placeholder="登录密码">
<a-icon slot="prefix" type="lock" />
</a-input-password>
</a-col>
</a-row>
</a-input-group>
</a-form-model-item>
<!-- <a-form-model-item label="登录密码" prop="password">-->
<!-- </a-form-model-item>-->
<a-form-model-item v-show="temp.repoType === 0" label="分支" prop="branchName">
<a-row>
<a-col :span="18">
<a-select v-model="temp.branchName" placeholder="请先填写仓库地址和账号信息">
<a-select-option v-for="branch in branchList" :key="branch">{{ branch }} </a-select-option>
</a-select>
</a-col>
<a-col :span="6">
<a-button type="primary" class="btn-add" @click="loadBranchList">获取分支</a-button>
</a-col>
</a-row>
</a-form-model-item>
<a-form-model-item label="构建命令" prop="script">
<a-input v-model="temp.script" type="textarea" :auto-size="{ minRows: 2, maxRows: 6 }" allow-clear placeholder="构建执行的命令(非阻塞命令)mvn clean package" />
</a-form-model-item>
<a-form-model-item label="产物目录" prop="resultDirFile" class="jpom-target-dir">
<a-input v-model="temp.resultDirFile" placeholder="构建产物目录,相对路径">
<a-tooltip slot="suffix">
<template slot="title">
<div>可以理解为项目打包的目录 Jpom 项目执行构建命令 <b>mvn clean package</b> 构建命令构建产物相对路径为<b>modules/server/target/server-2.4.2-release</b></div>
<div><br /></div>
<div>
支持通配符(AntPathMatcher)
<ul>
<li>? 匹配一个字符</li>
<li>* 匹配零个或多个字符</li>
<li>** 匹配路径中的零个或多个目录</li>
</ul>
</div>
</template>
<a-icon type="question-circle" theme="filled" />
</a-tooltip>
</a-input>
</a-form-model-item>
<a-form-model-item label="发布操作" prop="releaseMethod">
<a-radio-group v-model="temp.releaseMethod" name="releaseMethod">
<a-radio :value="0">不发布</a-radio>
<a-radio :value="1">节点分发</a-radio>
<a-radio :value="2">项目</a-radio>
<a-radio :value="3">SSH</a-radio>
</a-radio-group>
</a-form-model-item>
<!-- 节点分发 -->
<a-form-model-item v-if="temp.releaseMethod === 1" label="分发项目" prop="releaseMethodDataId">
<a-select v-model="temp.releaseMethodDataId_1" placeholder="请选择分发项目">
<a-select-option v-for="dispatch in dispatchList" :key="dispatch.id">{{ dispatch.name }} </a-select-option>
</a-select>
</a-form-model-item>
<!-- 项目 -->
<a-form-model-item v-if="temp.releaseMethod === 2" label="发布项目" prop="releaseMethodDataId">
<a-cascader v-model="temp.releaseMethodDataIdList" :options="cascaderList" placeholder="Please select" />
</a-form-model-item>
<a-form-model-item v-if="temp.releaseMethod === 2" label="发布后操作" prop="afterOpt">
<a-select v-model="temp.afterOpt" placeholder="请选择发布后操作">
<a-select-option v-for="opt in afterOptList" :key="opt.value">{{ opt.title }}</a-select-option>
</a-select>
</a-form-model-item>
<!-- SSH -->
<a-form-model-item v-if="temp.releaseMethod === 3" label="SSH/目录:" prop="releaseMethodDataId">
<a-input-group compact>
<a-select style="width: 30%" v-model="temp.releaseMethodDataId_3" placeholder="请先填写仓库地址和账号信息">
<a-select-option v-for="ssh in sshList" :key="ssh.id">{{ ssh.name }}</a-select-option>
</a-select>
<a-input style="width: 70%" v-model="temp.releasePath" placeholder="发布目录,构建产物上传到对应目录" />
</a-input-group>
</a-form-model-item>
<!-- <a-form-model-item v-if="temp.releaseMethod === 3" label="发布目录" prop="releasePath">-->
<!-- </a-form-model-item>-->
<a-form-model-item v-if="temp.releaseMethod === 3" label="发布命令" prop="releaseCommand">
<a-input
v-model="temp.releaseCommand"
allow-clear
:auto-size="{ minRows: 2, maxRows: 10 }"
type="textarea"
:rows="3"
placeholder="发布执行的命令(非阻塞命令),一般是启动项目命令 如ps -aux | grep java"
/>
</a-form-model-item>
<a-form-model-item v-if="temp.releaseMethod === 2 || temp.releaseMethod === 3" label="清空发布" prop="clearOld">
<a-switch v-model="temp.clearOld" checked-children="" un-checked-children="" />
</a-form-model-item>
</a-form-model>
</a-modal>
<!-- 触发器 -->
<a-modal v-model="triggerVisible" title="触发器" :footer="null" :maskClosable="false">
<a-form-model ref="editTriggerForm" :rules="rules" :model="temp" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
<a-form-model-item label="触发器地址" prop="triggerBuildUrl">
<a-input v-model="temp.triggerBuildUrl" type="textarea" readOnly :rows="3" style="resize: none" placeholder="触发器地址" />
</a-form-model-item>
<a-row>
<a-col :span="6"></a-col>
<a-col :span="16">
<a-button type="primary" class="btn-add" @click="resetTrigger">重置</a-button>
</a-col>
</a-row>
</a-form-model>
</a-modal>
<!-- 构建日志 -->
<a-modal width="80vw" v-model="buildLogVisible" title="构建日志" :footer="null" :maskClosable="false" @cancel="closeBuildLogModel">
<build-log v-if="buildLogVisible" :temp="temp" />
</a-modal>
</div>
</template>
<script>
import { mapGetters } from "vuex";
import BuildLog from "./log";
import { clearBuid, deleteBuild, editBuild, getBranchList, getBuildGroupList, getBuildList, getTriggerUrl, releaseMethodMap, resetTrigger, startBuild, stopBuild } from "../../api/build";
import { getDishPatchList } from "../../api/dispatch";
import { getNodeProjectList } from "../../api/node";
import { getSshList } from "../../api/ssh";
import { parseTime } from "../../utils/time";
export default {
components: {
BuildLog,
},
data() {
return {
releaseMethodMap: releaseMethodMap,
loading: false,
listQuery: {},
tableHeight: "70vh",
groupList: [],
list: [],
branchList: [],
dispatchList: [],
cascaderList: [],
sshList: [],
temp: {},
editBuildVisible: false,
addGroupvisible: false,
triggerVisible: false,
buildLogVisible: false,
afterOptList: [
{ title: "不做任何操作", value: 0 },
{ title: "并发重启", value: 1 },
{ title: "完整顺序重启(有重启失败将结束本次)", value: 2 },
{ title: "顺序重启(有重启失败将继续)", value: 3 },
],
columns: [
{ title: "名称", dataIndex: "name", width: 150, ellipsis: true, scopedSlots: { customRender: "name" } },
{ title: "分组", dataIndex: "group", width: 150, ellipsis: true, scopedSlots: { customRender: "group" } },
{
title: "分支",
dataIndex: "branchName",
width: 100,
ellipsis: true,
scopedSlots: { customRender: "branchName" },
},
{ title: "状态", dataIndex: "status", width: 100, ellipsis: true, scopedSlots: { customRender: "status" } },
{
title: "构建 ID",
dataIndex: "buildIdStr",
width: 80,
ellipsis: true,
scopedSlots: { customRender: "buildIdStr" },
},
{
title: "修改人",
dataIndex: "modifyUser",
width: 150,
ellipsis: true,
scopedSlots: { customRender: "modifyUser" },
},
{
title: "修改时间",
dataIndex: "modifyTime",
customRender: (text) => {
if (!text) {
return "";
}
return parseTime(text);
},
width: 180,
},
{
title: "发布方式",
dataIndex: "releaseMethod",
width: 100,
ellipsis: true,
scopedSlots: { customRender: "releaseMethod" },
},
{
title: "产物目录",
dataIndex: "resultDirFile",
ellipsis: true,
scopedSlots: { customRender: "resultDirFile" },
},
{ title: "构建命令", dataIndex: "script", ellipsis: true, scopedSlots: { customRender: "script" } },
{
title: "操作",
dataIndex: "operation",
width: 240,
scopedSlots: { customRender: "operation" },
align: "left",
fixed: "right",
},
],
rules: {
name: [{ required: true, message: "Please input build name", trigger: "blur" }],
script: [{ required: true, message: "Please input build script", trigger: "blur" }],
resultDirFile: [{ required: true, message: "Please input build target path", trigger: "blur" }],
releasePath: [{ required: true, message: "Please input release path", trigger: "blur" }],
},
};
},
computed: {
...mapGetters(["getGuideFlag"]),
},
watch: {
getGuideFlag() {
this.introGuide();
},
},
created() {
this.calcTableHeight();
this.loadGroupList();
this.handleFilter();
},
methods: {
//
introGuide() {
if (this.getGuideFlag) {
this.$introJs()
.setOptions({
hidePrev: true,
steps: [
{
title: "Jpom 导航助手",
element: document.querySelector(".jpom-target-dir"),
intro: "可以理解为项目打包的目录。如 Jpom 项目执行 <b>mvn clean package</b> 构建命令,构建产物相对路径为:<b>modules/server/target/server-2.4.2-release</b>",
},
],
})
.start();
return false;
}
this.$introJs().exit();
},
//
calcTableHeight() {
this.$nextTick(() => {
this.tableHeight = window.innerHeight - this.$refs["filter"].clientHeight - 135;
});
},
//
loadGroupList() {
getBuildGroupList().then((res) => {
if (res.code === 200) {
this.groupList = res.data;
}
});
},
//
loadData() {
this.list = [];
this.loading = true;
getBuildList(this.listQuery).then((res) => {
if (res.code === 200) {
this.list = res.data;
}
this.loading = false;
});
},
//
loadDispatchList() {
this.dispatchList = [];
getDishPatchList().then((res) => {
if (res.code === 200) {
this.dispatchList = res.data;
}
});
},
//
loadNodeProjectList() {
this.cascaderList = [];
getNodeProjectList().then((res) => {
if (res.code === 200) {
res.data.forEach((node) => {
const nodeItem = {
label: node.name,
value: node.id,
children: [],
};
node.projects.forEach((project) => {
const projectItem = {
label: project.name,
value: project.id,
};
nodeItem.children.push(projectItem);
});
this.cascaderList.push(nodeItem);
});
}
});
},
// SSH
loadSshList() {
this.sshList = [];
getSshList().then((res) => {
if (res.code === 200) {
this.sshList = res.data;
}
});
},
//
handleFilter() {
this.loadData();
},
//
handleAdd() {
this.temp = {
repoType: 0,
};
this.branchList = [];
this.loadDispatchList();
this.loadNodeProjectList();
this.loadSshList();
this.editBuildVisible = true;
this.$nextTick(() => {
setTimeout(() => {
this.introGuide();
}, 500);
});
},
//
handleEdit(record) {
this.temp = Object.assign(record);
this.temp.tempGroup = "";
//
if (record.releaseMethodDataId) {
if (record.releaseMethod === 1) {
this.temp.releaseMethodDataId_1 = record.releaseMethodDataId;
}
if (record.releaseMethod === 2) {
this.temp.releaseMethodDataIdList = record.releaseMethodDataId.split(":");
}
if (record.releaseMethod === 3) {
this.temp.releaseMethodDataId_3 = record.releaseMethodDataId;
}
}
this.loadBranchList();
this.loadDispatchList();
this.loadNodeProjectList();
this.loadSshList();
this.editBuildVisible = true;
},
//
handleAddGroup() {
if (!this.temp.tempGroup || this.temp.tempGroup.length === 0) {
this.$notification.warning({
message: "分组名称不能为空",
duration: 2,
});
return false;
}
//
if (this.groupList.indexOf(this.temp.tempGroup) === -1) {
this.groupList.push(this.temp.tempGroup);
}
this.temp.tempGroup = "";
this.$notification.success({
message: "添加成功",
duration: 2,
});
this.addGroupvisible = false;
},
//
loadBranchList() {
const loading = this.$loading.service({
lock: true,
text: "正在加载项目分支",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)",
});
this.branchList = [];
const params = {
url: this.temp.gitUrl,
userName: this.temp.userName,
userPwd: this.temp.password,
};
getBranchList(params).then((res) => {
if (res.code === 200) {
this.branchList = res.data;
}
loading.close();
});
},
//
handleEditBuildOk() {
//
this.$refs["editBuildForm"].validate((valid) => {
if (!valid) {
return false;
}
//
if (this.temp.releaseMethod === 2) {
if (this.temp.releaseMethodDataIdList.length < 2) {
this.$notification.warn({
message: "请选择节点项目",
duration: 2,
});
return false;
}
this.temp.releaseMethodDataId_2_node = this.temp.releaseMethodDataIdList[0];
this.temp.releaseMethodDataId_2_project = this.temp.releaseMethodDataIdList[1];
}
//
editBuild(this.temp).then((res) => {
if (res.code === 200) {
//
this.$notification.success({
message: res.msg,
duration: 2,
});
this.$refs["editBuildForm"].resetFields();
this.editBuildVisible = false;
this.handleFilter();
this.loadGroupList();
}
});
});
},
//
handleDelete(record) {
this.$confirm({
title: "系统提示",
content: "真的要删除构建信息么?",
okText: "确认",
cancelText: "取消",
onOk: () => {
//
deleteBuild(record.id).then((res) => {
if (res.code === 200) {
this.$notification.success({
message: res.msg,
duration: 2,
});
this.loadData();
}
});
},
});
},
//
handleTrigger(record) {
this.temp = Object.assign(record);
getTriggerUrl(record.id).then((res) => {
if (res.code === 200) {
this.temp.triggerBuildUrl = `${location.protocol}${location.host}${res.data.triggerBuildUrl}`;
this.triggerVisible = true;
}
});
},
//
resetTrigger() {
resetTrigger(this.temp.id).then((res) => {
if (res.code === 200) {
this.$notification.success({
message: res.msg,
duration: 2,
});
this.triggerVisible = false;
this.handleTrigger(this.temp);
}
});
},
//
handleClear(record) {
this.$confirm({
title: "系统提示",
content: "真的要清除构建信息么?",
okText: "确认",
cancelText: "取消",
onOk: () => {
clearBuid(record.id).then((res) => {
if (res.code === 200) {
this.$notification.success({
message: res.msg,
duration: 2,
});
this.loadData();
}
});
},
});
},
//
handleStartBuild(record) {
this.temp = Object.assign(record);
startBuild(this.temp.id).then((res) => {
if (res.code === 200) {
this.$notification.success({
message: res.msg,
duration: 2,
});
this.handleFilter();
//
this.handleBuildLog({
id: this.temp.id,
buildId: res.data,
});
}
});
},
//
handleStopBuild(record) {
this.temp = Object.assign(record);
stopBuild(this.temp.id).then((res) => {
if (res.code === 200) {
this.$notification.success({
message: res.msg,
duration: 2,
});
this.handleFilter();
}
});
},
//
handleBuildLog(record) {
this.temp = {
id: record.id,
buildId: record.buildId,
};
this.buildLogVisible = true;
},
//
closeBuildLogModel() {
this.handleFilter();
},
},
};
</script>
<style scoped>
.filter {
margin-bottom: 10px;
}
.ant-btn {
margin-right: 10px;
}
.filter-item {
width: 150px;
margin-right: 10px;
}
.btn-add {
margin-left: 10px;
margin-right: 0;
}
</style>

View File

@ -232,7 +232,8 @@ export default {
this.loading = true;
getRepositoryList(this.listQuery).then((res) => {
if (res.code === 200) {
this.list = res.data;
this.list = res.data.result;
this.total = res.data.total;
}
this.loading = false;
});

View File

@ -64,11 +64,6 @@ const children = [
name: "repository-list",
component: () => import("../pages/repository/list"),
},
{
path: "/build/list",
name: "build-list",
component: () => import("../pages/build/list"),
},
{
path: "/build/list-info",
name: "build-list-info",