From d01266d44b501a12fa4cdb2686d5e98c26b8b19a Mon Sep 17 00:00:00 2001 From: bwcx_jzy Date: Fri, 3 Dec 2021 14:06:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=94=A8=E5=88=86=E9=A1=B5=EF=BC=8C?= =?UTF-8?q?=E9=80=9A=E7=94=A8=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/io/jpom/common/Const.java | 2 - .../java/io/jpom/controller/LoginControl.java | 2 +- .../controller/build/BuildInfoController.java | 33 +- .../build/BuildInfoHistoryController.java | 48 +- .../build/RepositoryController.java | 14 +- .../monitor/MonitorLogController.java | 87 +-- .../node/NodeWelcomeController.java | 13 +- .../controller/node/ssh/SshController.java | 9 +- .../outgiving/OutGivingLogController.java | 67 +- .../system/BackupInfoController.java | 9 +- .../user/log/UserOptLogController.java | 9 +- .../java/io/jpom/model/PageResultDto.java | 109 +++ .../java/io/jpom/model/data/UserModel.java | 24 +- .../main/java/io/jpom/monitor/Monitor.java | 4 +- .../dblog/DbSystemMonitorLogService.java | 4 +- .../jpom/service/dblog/RepositoryService.java | 9 + .../service/h2db/BaseDbCommonService.java | 23 +- .../io/jpom/service/h2db/BaseDbService.java | 43 ++ .../io/jpom/service/user/UserService.java | 3 + .../src/main/java/io/jpom/util/GitUtil.java | 2 - web-vue/src/pages/build/history.vue | 2 +- web-vue/src/pages/build/list-info.vue | 15 +- web-vue/src/pages/build/list.vue | 687 ------------------ web-vue/src/pages/repository/list.vue | 3 +- web-vue/src/router/index.js | 5 - 25 files changed, 332 insertions(+), 894 deletions(-) create mode 100644 modules/server/src/main/java/io/jpom/model/PageResultDto.java delete mode 100644 web-vue/src/pages/build/list.vue diff --git a/modules/common/src/main/java/io/jpom/common/Const.java b/modules/common/src/main/java/io/jpom/common/Const.java index a6c548930..a97fc9ec1 100644 --- a/modules/common/src/main/java/io/jpom/common/Const.java +++ b/modules/common/src/main/java/io/jpom/common/Const.java @@ -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 diff --git a/modules/server/src/main/java/io/jpom/controller/LoginControl.java b/modules/server/src/main/java/io/jpom/controller/LoginControl.java index 76b59bd9a..105fd7310 100644 --- a/modules/server/src/main/java/io/jpom/controller/LoginControl.java +++ b/modules/server/src/main/java/io/jpom/controller/LoginControl.java @@ -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); diff --git a/modules/server/src/main/java/io/jpom/controller/build/BuildInfoController.java b/modules/server/src/main/java/io/jpom/controller/build/BuildInfoController.java index 4f9e819b5..f84b89375 100644 --- a/modules/server/src/main/java/io/jpom/controller/build/BuildInfoController.java +++ b/modules/server/src/main/java/io/jpom/controller/build/BuildInfoController.java @@ -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 list = buildInfoService.listPage(where, pageReq); - JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", list); - jsonObject.put("total", list.getTotal()); - return jsonObject.toString(); + PageResultDto 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 仓库才有分支信息"); 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 1c6719de6..825c346b9 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 @@ -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 pageResult = dbBuildHistoryLogService.listPage(entity, pageObj); - 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()); + PageResultDto pageResultTemp = dbBuildHistoryLogService.listPage(entity, pageObj); + // + PageResultDto pageResult = new PageResultDto<>(pageResultTemp); + List result = pageResult.getResult(); + if (result != null) { + List 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 getDataIds() { Entity where = Entity.create(); Page pageReq = new Page(); - List list = buildInfoService.listPage(where, pageReq); + List list = buildInfoService.listPageOnlyResult(where, pageReq); if (CollUtil.isEmpty(list)) { return new HashSet<>(); } else { diff --git a/modules/server/src/main/java/io/jpom/controller/build/RepositoryController.java b/modules/server/src/main/java/io/jpom/controller/build/RepositoryController.java index fffd09dc4..437d7063f 100644 --- a/modules/server/src/main/java/io/jpom/controller/build/RepositoryController.java +++ b/modules/server/src/main/java/io/jpom/controller/build/RepositoryController.java @@ -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 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 pageResult = repositoryService.listPage(entity, pageObj); + return JsonMessage.getString(200, "获取成功", pageResult); } /** diff --git a/modules/server/src/main/java/io/jpom/controller/monitor/MonitorLogController.java b/modules/server/src/main/java/io/jpom/controller/monitor/MonitorLogController.java index 6cb12d009..f2debff65 100644 --- a/modules/server/src/main/java/io/jpom/controller/monitor/MonitorLogController.java +++ b/modules/server/src/main/java/io/jpom/controller/monitor/MonitorLogController.java @@ -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 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 pageResult = dbMonitorNotifyLogService.listPage(entity, pageObj); - JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", pageResult); - jsonObject.put("total", pageResult.getTotal()); - return jsonObject.toString(); - } + PageResultDto pageResult = dbMonitorNotifyLogService.listPage(entity, pageObj); + return JsonMessage.getString(200, "获取成功", pageResult); + } } diff --git a/modules/server/src/main/java/io/jpom/controller/node/NodeWelcomeController.java b/modules/server/src/main/java/io/jpom/controller/node/NodeWelcomeController.java index 01c74e231..e212c99cc 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/NodeWelcomeController.java +++ b/modules/server/src/main/java/io/jpom/controller/node/NodeWelcomeController.java @@ -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 getList(String time, long millis) { + private PageResultDto 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 pageResult = getList(selTime, millis); + PageResultDto pageResult = getList(selTime, millis); List series = new ArrayList<>(); List 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 monitorData = getList(time, getCycleMillis()); + PageResultDto 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 result = monitorData.getResult(); + for (SystemMonitorLog log : result) { long monitorTime = log.getMonitorTime(); buf.append(DateUtil.date(monitorTime).toString()).append(",") .append(log.getOccupyCpu()).append("%").append(",") diff --git a/modules/server/src/main/java/io/jpom/controller/node/ssh/SshController.java b/modules/server/src/main/java/io/jpom/controller/node/ssh/SshController.java index acf214cc5..674477c26 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/ssh/SshController.java +++ b/modules/server/src/main/java/io/jpom/controller/node/ssh/SshController.java @@ -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 pageResult = sshTerminalExecuteLogService.listPage(entity, pageObj); - JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", pageResult); - jsonObject.put("total", pageResult.getTotal()); - return jsonObject.toString(); + PageResultDto pageResult = sshTerminalExecuteLogService.listPage(entity, pageObj); + return JsonMessage.getString(200, "获取成功", pageResult); } } diff --git a/modules/server/src/main/java/io/jpom/controller/outgiving/OutGivingLogController.java b/modules/server/src/main/java/io/jpom/controller/outgiving/OutGivingLogController.java index c79b8b65a..86474f988 100644 --- a/modules/server/src/main/java/io/jpom/controller/outgiving/OutGivingLogController.java +++ b/modules/server/src/main/java/io/jpom/controller/outgiving/OutGivingLogController.java @@ -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 pageResult = dbOutGivingLogService.listPage(entity, pageObj); - JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", pageResult); - jsonObject.put("total", pageResult.getTotal()); - return jsonObject.toString(); - } + PageResultDto pageResult = dbOutGivingLogService.listPage(entity, pageObj); + return JsonMessage.getString(200, "获取成功", pageResult); + } } diff --git a/modules/server/src/main/java/io/jpom/controller/system/BackupInfoController.java b/modules/server/src/main/java/io/jpom/controller/system/BackupInfoController.java index c1e2f3980..98f9501fd 100644 --- a/modules/server/src/main/java/io/jpom/controller/system/BackupInfoController.java +++ b/modules/server/src/main/java/io/jpom/controller/system/BackupInfoController.java @@ -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 pageResult = backupInfoService.listPage(entity, pageObj); + PageResultDto pageResult = backupInfoService.listPage(entity, pageObj); - JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", pageResult); - jsonObject.put("total", pageResult.getTotal()); - return jsonObject; + return JsonMessage.getString(200, "获取成功", pageResult); } /** diff --git a/modules/server/src/main/java/io/jpom/controller/user/log/UserOptLogController.java b/modules/server/src/main/java/io/jpom/controller/user/log/UserOptLogController.java index e2bdbc2ea..0f6a57640 100644 --- a/modules/server/src/main/java/io/jpom/controller/user/log/UserOptLogController.java +++ b/modules/server/src/main/java/io/jpom/controller/user/log/UserOptLogController.java @@ -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 pageResult = dbUserOperateLogService.listPage(entity, pageObj); - JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", pageResult); - jsonObject.put("total", pageResult.getTotal()); - return jsonObject.toString(); + PageResultDto pageResult = dbUserOperateLogService.listPage(entity, pageObj); + return JsonMessage.getString(200, "获取成功", pageResult); } } diff --git a/modules/server/src/main/java/io/jpom/model/PageResultDto.java b/modules/server/src/main/java/io/jpom/model/PageResultDto.java new file mode 100644 index 000000000..e03b2632e --- /dev/null +++ b/modules/server/src/main/java/io/jpom/model/PageResultDto.java @@ -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 implements Serializable { + + public static final PageResultDto EMPTY = new PageResultDto<>(1, 10, 0); + + /** + * 结果 + */ + private List result; + /** + * 页码 + */ + private Integer page; + /** + * 每页结果数 + */ + private Integer pageSize; + /** + * 总页数 + */ + private Integer totalPage; + /** + * 总数 + */ + private Integer total; + + public PageResultDto(PageResult 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 getResult() { + return result; + } + + public void setResult(List 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); + } +} diff --git a/modules/server/src/main/java/io/jpom/model/data/UserModel.java b/modules/server/src/main/java/io/jpom/model/data/UserModel.java index 48a8e1287..80a8c7800 100644 --- a/modules/server/src/main/java/io/jpom/model/data/UserModel.java +++ b/modules/server/src/main/java/io/jpom/model/data/UserModel.java @@ -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; } // 解锁时间 diff --git a/modules/server/src/main/java/io/jpom/monitor/Monitor.java b/modules/server/src/main/java/io/jpom/monitor/Monitor.java index e8e721c00..edf24432a 100644 --- a/modules/server/src/main/java/io/jpom/monitor/Monitor.java +++ b/modules/server/src/main/java/io/jpom/monitor/Monitor.java @@ -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 pageResult = dbMonitorNotifyLogService.listPage(entity, page); + PageResultDto pageResult = dbMonitorNotifyLogService.listPage(entity, page); if (pageResult.isEmpty()) { return true; } diff --git a/modules/server/src/main/java/io/jpom/service/dblog/DbSystemMonitorLogService.java b/modules/server/src/main/java/io/jpom/service/dblog/DbSystemMonitorLogService.java index eb9eb9d11..30e725a3e 100644 --- a/modules/server/src/main/java/io/jpom/service/dblog/DbSystemMonitorLogService.java +++ b/modules/server/src/main/java/io/jpom/service/dblog/DbSystemMonitorLogService.java @@ -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 getMonitorData(long startTime, long endTime) { + public PageResultDto getMonitorData(long startTime, long endTime) { Entity entity = new Entity(SystemMonitorLog.TABLE_NAME); entity.set(" MONITORTIME", ">= " + startTime); entity.set("MONITORTIME", "<= " + endTime); diff --git a/modules/server/src/main/java/io/jpom/service/dblog/RepositoryService.java b/modules/server/src/main/java/io/jpom/service/dblog/RepositoryService.java index 163524bc5..4c1226adb 100644 --- a/modules/server/src/main/java/io/jpom/service/dblog/RepositoryService.java +++ b/modules/server/src/main/java/io/jpom/service/dblog/RepositoryService.java @@ -33,4 +33,13 @@ import org.springframework.stereotype.Service; @Service public class RepositoryService extends BaseDbService { + @Override + protected void fillSelectResult(RepositoryModel repositoryModel) { + if (repositoryModel == null) { + return; + } + // 隐藏密码字段 + repositoryModel.setPassword(null); + repositoryModel.setRsaPrv(null); + } } diff --git a/modules/server/src/main/java/io/jpom/service/h2db/BaseDbCommonService.java b/modules/server/src/main/java/io/jpom/service/h2db/BaseDbCommonService.java index ff07bd413..617a07827 100644 --- a/modules/server/src/main/java/io/jpom/service/h2db/BaseDbCommonService.java +++ b/modules/server/src/main/java/io/jpom/service/h2db/BaseDbCommonService.java @@ -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 { * @param page 分页 * @return 结果 */ - public PageResult listPage(Entity where, Page page) { + @SuppressWarnings({"unchecked", "rawtypes"}) + public PageResultDto 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 pageResult; @@ -423,9 +425,20 @@ public abstract class BaseDbCommonService { this.fillSelectResult(entityToBean); return entityToBean; }).collect(Collectors.toList()); - PageResult pageResult1 = new PageResult<>(pageResult.getPage(), pageResult.getPageSize(), pageResult.getTotal()); - pageResult1.addAll(list); - return pageResult1; + PageResultDto pageResultDto = new PageResultDto(pageResult); + pageResultDto.setResult(list); + return pageResultDto; + } + /** + * 分页查询 + * + * @param where 条件 + * @param page 分页 + * @return 结果 + */ + public List listPageOnlyResult(Entity where, Page page) { + PageResultDto pageResultDto = this.listPage(where, page); + return pageResultDto.getResult(); } /** diff --git a/modules/server/src/main/java/io/jpom/service/h2db/BaseDbService.java b/modules/server/src/main/java/io/jpom/service/h2db/BaseDbService.java index 39aa89333..20f184be2 100644 --- a/modules/server/src/main/java/io/jpom/service/h2db/BaseDbService.java +++ b/modules/server/src/main/java/io/jpom/service/h2db/BaseDbService.java @@ -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 extends BaseDbCommonS public long count() { return super.count(Entity.create()); } + + + /** + * 通用的分页查询 + *

+ * page=1&limit=10&order=ascend&order_field=name + * + * @param request 请求对象 + * @return page + */ + public PageResultDto listPage(ServletRequest request) { + Map 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 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); + } } diff --git a/modules/server/src/main/java/io/jpom/service/user/UserService.java b/modules/server/src/main/java/io/jpom/service/user/UserService.java index df3d21fda..463cc3054 100644 --- a/modules/server/src/main/java/io/jpom/service/user/UserService.java +++ b/modules/server/src/main/java/io/jpom/service/user/UserService.java @@ -28,6 +28,9 @@ public class UserService extends BaseDbService { @Override protected void fillSelectResult(UserModel data) { + if (data == null) { + return; + } data.setSalt(null); } diff --git a/modules/server/src/main/java/io/jpom/util/GitUtil.java b/modules/server/src/main/java/io/jpom/util/GitUtil.java index 3049fa1d6..8d90bb181 100644 --- a/modules/server/src/main/java/io/jpom/util/GitUtil.java +++ b/modules/server/src/main/java/io/jpom/util/GitUtil.java @@ -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; diff --git a/web-vue/src/pages/build/history.vue b/web-vue/src/pages/build/history.vue index 9f1e09c2e..d9a18d6c0 100644 --- a/web-vue/src/pages/build/history.vue +++ b/web-vue/src/pages/build/history.vue @@ -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; diff --git a/web-vue/src/pages/build/list-info.vue b/web-vue/src/pages/build/list-info.vue index eaf3d0851..ff215412e 100644 --- a/web-vue/src/pages/build/list-info.vue +++ b/web-vue/src/pages/build/list-info.vue @@ -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(); }, }, diff --git a/web-vue/src/pages/build/list.vue b/web-vue/src/pages/build/list.vue deleted file mode 100644 index 2071ddd48..000000000 --- a/web-vue/src/pages/build/list.vue +++ /dev/null @@ -1,687 +0,0 @@ -/** * 该页面是老版本的构建信息页面,之后可能会删除,新版本的页面请参考 ./list-info.vue */ - - - diff --git a/web-vue/src/pages/repository/list.vue b/web-vue/src/pages/repository/list.vue index bd3b5b205..94eb37c2b 100644 --- a/web-vue/src/pages/repository/list.vue +++ b/web-vue/src/pages/repository/list.vue @@ -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; }); diff --git a/web-vue/src/router/index.js b/web-vue/src/router/index.js index c5a33e656..dcbaaab4b 100644 --- a/web-vue/src/router/index.js +++ b/web-vue/src/router/index.js @@ -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",