From 3a16f9d9aba6bef43b922c1cf753d7dcabaecf70 Mon Sep 17 00:00:00 2001 From: lijiahang Date: Mon, 2 Sep 2024 12:37:11 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=80=BB=E8=BE=91.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../orion-server-module-service-impl.java.vm | 36 +++++++++---------- .../orion-server-module-service.java.vm | 9 +++++ .../module/asset/service/ExecLogService.java | 10 ++++++ .../asset/service/HostConnectLogService.java | 9 +++++ .../module/asset/service/HostService.java | 10 ++++++ .../asset/service/UploadTaskService.java | 10 ++++++ .../service/impl/ExecLogServiceImpl.java | 21 ++++++----- .../impl/HostConnectLogServiceImpl.java | 24 ++++++------- .../asset/service/impl/HostServiceImpl.java | 21 ++++++----- .../service/impl/UploadTaskServiceImpl.java | 21 ++++++----- .../infra/api/impl/OperatorLogApiImpl.java | 5 ++- .../infra/service/OperatorLogService.java | 10 ++++++ .../infra/service/SystemUserService.java | 18 ++++++++++ .../service/impl/OperatorLogServiceImpl.java | 35 +++++++++--------- .../service/impl/SystemUserServiceImpl.java | 34 +++++++++++++----- 15 files changed, 182 insertions(+), 91 deletions(-) diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-service-impl.java.vm b/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-service-impl.java.vm index 43db4c0e..53506008 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-service-impl.java.vm +++ b/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-service-impl.java.vm @@ -122,7 +122,8 @@ public class ${table.serviceImplName} implements ${table.serviceName} { @Override public List<${type}VO> get${type}List(${type}QueryRequest request) { // 条件 - LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(request); + LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(request) + .orderByDesc(${type}DO::getId); // 查询 return ${typeLower}DAO.of(wrapper).list(${type}Convert.MAPPER::to); } @@ -148,23 +149,28 @@ public class ${table.serviceImplName} implements ${table.serviceName} { .sorted(Comparator.comparing(${type}VO::getId).reversed()) .collect(Collectors.toList()); } - #end + @Override - public Long get${type}Count(${type}QueryRequest request) { + public DataGrid<${type}VO> get${type}Page(${type}QueryRequest request) { + // 条件 + LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(request) + .orderByDesc(${type}DO::getId); + // 查询 return ${typeLower}DAO.of() - .wrapper(this.buildQueryWrapper(request)) - .countMax(request.getLimit()); + .page(request) + .wrapper(wrapper) + .dataGrid(${type}Convert.MAPPER::to); } @Override - public DataGrid<${type}VO> get${type}Page(${type}QueryRequest request) { + public Long get${type}Count(${type}QueryRequest request) { // 条件 LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(request); // 查询 - return ${typeLower}DAO.of(wrapper) - .page(request) - .dataGrid(${type}Convert.MAPPER::to); + return ${typeLower}DAO.of() + .wrapper(wrapper) + .countMax(request.getLimit()); } @Override @@ -234,13 +240,8 @@ public class ${table.serviceImplName} implements ${table.serviceName} { Valid.isFalse(present, ErrorMessage.DATA_PRESENT); } - /** - * 构建查询 wrapper - * - * @param request request - * @return wrapper - */ - private LambdaQueryWrapper<${type}DO> buildQueryWrapper(${type}QueryRequest request) { + @Override + public LambdaQueryWrapper<${type}DO> buildQueryWrapper(${type}QueryRequest request) { String searchValue = request.getSearchValue(); return ${typeLower}DAO.wrapper() #foreach($field in ${table.fields}) @@ -250,8 +251,7 @@ public class ${table.serviceImplName} implements ${table.serviceName} { #foreach($field in ${table.fields}) .eq(${type}DO::get${field.capitalName}, searchValue)#if($foreach.hasNext).or()#end #end - ) - .orderByDesc(${type}DO::getId); + ); } } diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-service.java.vm b/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-service.java.vm index d5293f74..48c1cca5 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-service.java.vm +++ b/orion-visor-framework/orion-visor-spring-boot-starter-mybatis/src/main/resources/templates/orion-server-module-service.java.vm @@ -1,5 +1,6 @@ package ${package.Service}; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; #foreach($pkg in ${customModuleFilePackages}) import ${pkg}.*; @@ -116,4 +117,12 @@ public interface ${table.serviceName} { */ Integer delete${type}(${type}QueryRequest request); + /** + * 构建查询 wrapper + * + * @param request request + * @return wrapper + */ + private LambdaQueryWrapper<${type}DO> buildQueryWrapper(${type}QueryRequest request); + } diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/ExecLogService.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/ExecLogService.java index 8eb01929..cf2cde80 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/ExecLogService.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/ExecLogService.java @@ -1,6 +1,8 @@ package com.orion.visor.module.asset.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; +import com.orion.visor.module.asset.entity.domain.ExecLogDO; import com.orion.visor.module.asset.entity.dto.ExecLogTailDTO; import com.orion.visor.module.asset.entity.request.exec.ExecLogClearRequest; import com.orion.visor.module.asset.entity.request.exec.ExecLogQueryRequest; @@ -144,4 +146,12 @@ public interface ExecLogService { */ void asyncDeleteLogFiles(List idList); + /** + * 构建查询 wrapper + * + * @param request request + * @return wrapper + */ + LambdaQueryWrapper buildQueryWrapper(ExecLogQueryRequest request); + } diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/HostConnectLogService.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/HostConnectLogService.java index 9099ff78..a771acab 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/HostConnectLogService.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/HostConnectLogService.java @@ -1,5 +1,6 @@ package com.orion.visor.module.asset.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; import com.orion.visor.module.asset.entity.domain.HostConnectLogDO; import com.orion.visor.module.asset.entity.request.host.HostConnectLogClearRequest; @@ -106,4 +107,12 @@ public interface HostConnectLogService { */ Integer forceOffline(HostConnectLogQueryRequest request); + /** + * 构建查询 wrapper + * + * @param request request + * @return wrapper + */ + LambdaQueryWrapper buildQueryWrapper(HostConnectLogQueryRequest request); + } diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/HostService.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/HostService.java index d21949df..3a7ddeb1 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/HostService.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/HostService.java @@ -1,6 +1,8 @@ package com.orion.visor.module.asset.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; +import com.orion.visor.module.asset.entity.domain.HostDO; import com.orion.visor.module.asset.entity.request.host.*; import com.orion.visor.module.asset.entity.vo.HostConfigVO; import com.orion.visor.module.asset.entity.vo.HostVO; @@ -123,4 +125,12 @@ public interface HostService { */ void clearCache(); + /** + * 构建查询 wrapper + * + * @param request request + * @return wrapper + */ + LambdaQueryWrapper buildQueryWrapper(HostQueryRequest request); + } diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/UploadTaskService.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/UploadTaskService.java index 9d1d0a4e..e6ef63ac 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/UploadTaskService.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/UploadTaskService.java @@ -1,6 +1,8 @@ package com.orion.visor.module.asset.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; +import com.orion.visor.module.asset.entity.domain.UploadTaskDO; import com.orion.visor.module.asset.entity.request.upload.UploadTaskClearRequest; import com.orion.visor.module.asset.entity.request.upload.UploadTaskCreateRequest; import com.orion.visor.module.asset.entity.request.upload.UploadTaskQueryRequest; @@ -113,4 +115,12 @@ public interface UploadTaskService { */ void clearUploadSwapFiles(List idList); + /** + * 构建查询 wrapper + * + * @param request request + * @return wrapper + */ + LambdaQueryWrapper buildQueryWrapper(UploadTaskQueryRequest request); + } diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/ExecLogServiceImpl.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/ExecLogServiceImpl.java index 703cfe04..018a0283 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/ExecLogServiceImpl.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/ExecLogServiceImpl.java @@ -93,7 +93,8 @@ public class ExecLogServiceImpl implements ExecLogService { @Override public DataGrid getExecLogPage(ExecLogQueryRequest request) { // 条件 - LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request) + .orderByDesc(ExecLogDO::getId); // 查询 return execLogDAO.of(wrapper) .page(request) @@ -220,8 +221,11 @@ public Integer deleteExecLogByIdList(List idList) { @Override public Long queryExecLogCount(ExecLogQueryRequest request) { + // 条件 + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + // 查询 return execLogDAO.of() - .wrapper(this.buildQueryWrapper(request)) + .wrapper(wrapper) .countMax(request.getLimit()); } @@ -232,6 +236,7 @@ public Integer clearExecLog(ExecLogClearRequest request) { // 查询 LambdaQueryWrapper wrapper = this.buildQueryWrapper(request) .select(ExecLogDO::getId) + .orderByAsc(ExecLogDO::getId) .last(SqlUtils.limit(request.getLimit())); List idList = execLogDAO.selectList(wrapper) .stream() @@ -452,13 +457,8 @@ public void asyncDeleteLogFiles(List idList) { .forEach(Files1::delete); } - /** - * 构建查询 wrapper - * - * @param request request - * @return wrapper - */ - private LambdaQueryWrapper buildQueryWrapper(ExecLogQueryRequest request) { + @Override + public LambdaQueryWrapper buildQueryWrapper(ExecLogQueryRequest request) { return execLogDAO.wrapper() .eq(ExecLogDO::getId, request.getId()) .eq(ExecLogDO::getUserId, request.getUserId()) @@ -471,8 +471,7 @@ private LambdaQueryWrapper buildQueryWrapper(ExecLogQueryRequest requ .in(ExecLogDO::getStatus, request.getStatusList()) .ge(ExecLogDO::getStartTime, Arrays1.getIfPresent(request.getStartTimeRange(), 0)) .le(ExecLogDO::getStartTime, Arrays1.getIfPresent(request.getStartTimeRange(), 1)) - .le(ExecLogDO::getCreateTime, request.getCreateTimeLe()) - .orderByDesc(ExecLogDO::getId); + .le(ExecLogDO::getCreateTime, request.getCreateTimeLe()); } /** diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/HostConnectLogServiceImpl.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/HostConnectLogServiceImpl.java index 03ddb9fe..87eb02f0 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/HostConnectLogServiceImpl.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/HostConnectLogServiceImpl.java @@ -73,7 +73,8 @@ public HostConnectLogDO create(HostConnectTypeEnum type, HostConnectLogCreateReq @Override public DataGrid getHostConnectLogPage(HostConnectLogQueryRequest request) { // 条件 - LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request) + .orderByDesc(HostConnectLogDO::getId); // 查询 return hostConnectLogDAO.of(wrapper) .page(request) @@ -104,7 +105,8 @@ public List getHostConnectSessions(HostConnectLogQueryRequest // 条件 request.setIdList(idList); request.setStatus(HostConnectStatusEnum.CONNECTING.name()); - LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request) + .orderByDesc(HostConnectLogDO::getId); // 查询 return hostConnectLogDAO.of(wrapper) .list(s -> { @@ -187,8 +189,11 @@ public Integer deleteHostConnectLog(List idList) { @Override public Long getHostConnectLogCount(HostConnectLogQueryRequest request) { + // 条件 + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + // 查询 return hostConnectLogDAO.of() - .wrapper(this.buildQueryWrapper(request)) + .wrapper(wrapper) .countMax(request.getLimit()); } @@ -199,6 +204,7 @@ public Integer clearHostConnectLog(HostConnectLogClearRequest request) { // 查询 LambdaQueryWrapper wrapper = this.buildQueryWrapper(request) .select(HostConnectLogDO::getId) + .orderByAsc(HostConnectLogDO::getId) .last(SqlUtils.limit(request.getLimit())); List list = hostConnectLogDAO.selectList(wrapper); if (list.isEmpty()) { @@ -234,13 +240,8 @@ public Integer forceOffline(HostConnectLogQueryRequest request) { return this.updateStatus(record, HostConnectStatusEnum.FORCE_OFFLINE, null); } - /** - * 构建查询 wrapper - * - * @param request request - * @return wrapper - */ - private LambdaQueryWrapper buildQueryWrapper(HostConnectLogQueryRequest request) { + @Override + public LambdaQueryWrapper buildQueryWrapper(HostConnectLogQueryRequest request) { return hostConnectLogDAO.wrapper() .eq(HostConnectLogDO::getId, request.getId()) .in(HostConnectLogDO::getId, request.getIdList()) @@ -253,8 +254,7 @@ private LambdaQueryWrapper buildQueryWrapper(HostConnectLogQue .in(HostConnectLogDO::getStatus, request.getStatusList()) .ge(HostConnectLogDO::getStartTime, Arrays1.getIfPresent(request.getStartTimeRange(), 0)) .le(HostConnectLogDO::getStartTime, Arrays1.getIfPresent(request.getStartTimeRange(), 1)) - .le(HostConnectLogDO::getCreateTime, request.getCreateTimeLe()) - .orderByDesc(HostConnectLogDO::getId); + .le(HostConnectLogDO::getCreateTime, request.getCreateTimeLe()); } } diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/HostServiceImpl.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/HostServiceImpl.java index 0e8cb47d..f0649554 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/HostServiceImpl.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/HostServiceImpl.java @@ -259,9 +259,10 @@ public DataGrid getHostPage(HostQueryRequest request) { if (wrapper == null) { return DataGrid.of(Lists.empty()); } - // 数量条件 - LambdaQueryWrapper countWrapper = wrapper.clone(); - wrapper.select(HostDAO.BASE_COLUMN); + // 基础条件 + LambdaQueryWrapper countWrapper = wrapper.clone() + .select(HostDAO.BASE_COLUMN) + .orderByAsc(HostDO::getId); // 查询 DataGrid hosts = hostDAO.of(wrapper) .page(request) @@ -273,8 +274,11 @@ public DataGrid getHostPage(HostQueryRequest request) { @Override public Long getHostCount(HostQueryRequest request) { + // 条件 + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + // 查询 return hostDAO.of() - .wrapper(this.buildQueryWrapper(request)) + .wrapper(wrapper) .countMax(request.getLimit()); } @@ -359,13 +363,8 @@ private void checkHostCodePresent(HostDO domain) { Valid.isFalse(present, ErrorMessage.CODE_PRESENT); } - /** - * 构建查询 wrapper - * - * @param request request - * @return wrapper - */ - private LambdaQueryWrapper buildQueryWrapper(HostQueryRequest request) { + @Override + public LambdaQueryWrapper buildQueryWrapper(HostQueryRequest request) { String searchValue = request.getSearchValue(); LambdaQueryWrapper wrapper = hostDAO.wrapper(); // tag 条件 diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/UploadTaskServiceImpl.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/UploadTaskServiceImpl.java index 8093cfed..1515b279 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/UploadTaskServiceImpl.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/UploadTaskServiceImpl.java @@ -169,7 +169,8 @@ public UploadTaskVO getUploadTask(Long id) { @Override public DataGrid getUploadTaskPage(UploadTaskQueryRequest request) { // 条件 - LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request) + .orderByDesc(UploadTaskDO::getId); // 查询 return uploadTaskDAO.of(wrapper) .page(request) @@ -216,8 +217,11 @@ public List getUploadTaskStatus(List idList, Boolean q @Override public Long getUploadTaskCount(UploadTaskQueryRequest request) { + // 条件 + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + // 查询 return uploadTaskDAO.of() - .wrapper(this.buildQueryWrapper(request)) + .wrapper(wrapper) .countMax(request.getLimit()); } @@ -227,6 +231,7 @@ public Integer clearUploadTask(UploadTaskClearRequest request) { // 查询id LambdaQueryWrapper wrapper = this.buildQueryWrapper(request) .select(UploadTaskDO::getId) + .orderByAsc(UploadTaskDO::getId) .last(SqlUtils.limit(request.getLimit())); List idList = uploadTaskDAO.of(wrapper) .list(UploadTaskDO::getId); @@ -306,13 +311,8 @@ public void clearUploadSwapFiles(List idList) { paths.forEach(Files1::delete); } - /** - * 构建查询 wrapper - * - * @param request request - * @return wrapper - */ - private LambdaQueryWrapper buildQueryWrapper(UploadTaskQueryRequest request) { + @Override + public LambdaQueryWrapper buildQueryWrapper(UploadTaskQueryRequest request) { return uploadTaskDAO.wrapper() .eq(UploadTaskDO::getId, request.getId()) .eq(UploadTaskDO::getUserId, request.getUserId()) @@ -320,8 +320,7 @@ private LambdaQueryWrapper buildQueryWrapper(UploadTaskQueryReques .like(UploadTaskDO::getRemotePath, request.getRemotePath()) .eq(UploadTaskDO::getStatus, request.getStatus()) .ge(UploadTaskDO::getCreateTime, Arrays1.getIfPresent(request.getCreateTimeRange(), 0)) - .le(UploadTaskDO::getCreateTime, Arrays1.getIfPresent(request.getCreateTimeRange(), 1)) - .orderByDesc(UploadTaskDO::getId); + .le(UploadTaskDO::getCreateTime, Arrays1.getIfPresent(request.getCreateTimeRange(), 1)); } /** diff --git a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/api/impl/OperatorLogApiImpl.java b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/api/impl/OperatorLogApiImpl.java index 72fd69c2..40491cf0 100644 --- a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/api/impl/OperatorLogApiImpl.java +++ b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/api/impl/OperatorLogApiImpl.java @@ -32,9 +32,12 @@ public class OperatorLogApiImpl implements OperatorLogApi { @Override public DataGrid getOperatorLogPage(OperatorLogQueryDTO request) { Valid.valid(request); + // 条件 + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + // 查询 return operatorLogDAO.of() .page(request) - .wrapper(this.buildQueryWrapper(request)) + .wrapper(wrapper) .dataGrid(OperatorLogProviderConvert.MAPPER::to); } diff --git a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/OperatorLogService.java b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/OperatorLogService.java index 9918bb6e..ccc79cc1 100644 --- a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/OperatorLogService.java +++ b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/OperatorLogService.java @@ -1,7 +1,9 @@ package com.orion.visor.module.infra.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; import com.orion.visor.framework.biz.operator.log.core.model.OperatorLogModel; +import com.orion.visor.module.infra.entity.domain.OperatorLogDO; import com.orion.visor.module.infra.entity.request.operator.OperatorLogClearRequest; import com.orion.visor.module.infra.entity.request.operator.OperatorLogQueryRequest; import com.orion.visor.module.infra.entity.vo.LoginHistoryVO; @@ -66,4 +68,12 @@ public interface OperatorLogService { */ List getLoginHistory(String username, Integer count); + /** + * 构建查询 wrapper + * + * @param request request + * @return wrapper + */ + LambdaQueryWrapper buildQueryWrapper(OperatorLogQueryRequest request); + } diff --git a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/SystemUserService.java b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/SystemUserService.java index bee42ec2..fa9201f9 100644 --- a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/SystemUserService.java +++ b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/SystemUserService.java @@ -1,6 +1,8 @@ package com.orion.visor.module.infra.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; +import com.orion.visor.module.infra.entity.domain.SystemUserDO; import com.orion.visor.module.infra.entity.request.user.*; import com.orion.visor.module.infra.entity.vo.SystemUserVO; @@ -62,6 +64,14 @@ public interface SystemUserService { */ DataGrid getSystemUserPage(SystemUserQueryRequest request); + /** + * 查询系统用户数量 + * + * @param request request + * @return count + */ + Long getSystemUserCount(SystemUserQueryRequest request); + /** * 通过 id 删除用户 * @@ -92,4 +102,12 @@ public interface SystemUserService { */ void resetPassword(UserResetPasswordRequest request); + /** + * 获取查询 wrapper + * + * @param request request + * @return wrapper + */ + LambdaQueryWrapper buildQueryWrapper(SystemUserQueryRequest request); + } diff --git a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/OperatorLogServiceImpl.java b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/OperatorLogServiceImpl.java index 8e08c81f..e715bb99 100644 --- a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/OperatorLogServiceImpl.java +++ b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/OperatorLogServiceImpl.java @@ -49,7 +49,8 @@ public void addOperatorLog(OperatorLogModel model) { @Override public DataGrid getOperatorLogPage(OperatorLogQueryRequest request) { // 条件 - LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request) + .orderByDesc(OperatorLogDO::getId); // 查询 return operatorLogDAO.of(wrapper) .page(request) @@ -68,8 +69,11 @@ public Integer deleteOperatorLog(List idList) { @Override public Long getOperatorLogCount(OperatorLogQueryRequest request) { + // 条件 + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + // 查询 return operatorLogDAO.of() - .wrapper(this.buildQueryWrapper(request)) + .wrapper(wrapper) .countMax(request.getLimit()); } @@ -78,6 +82,7 @@ public Integer clearOperatorLog(OperatorLogClearRequest request) { log.info("OperatorLogService.clearOperatorLog start {}", JSON.toJSONString(request)); // 删除参数 LambdaQueryWrapper wrapper = this.buildQueryWrapper(request) + .orderByAsc(OperatorLogDO::getId) .last(SqlUtils.limit(request.getLimit())); // 删除 int effect = operatorLogDAO.delete(wrapper); @@ -89,25 +94,20 @@ public Integer clearOperatorLog(OperatorLogClearRequest request) { @Override public List getLoginHistory(String username, Integer count) { - Valid.gt(count, 0, ErrorMessage.PARAM_ERROR); - // 条件 - OperatorLogQueryRequest request = new OperatorLogQueryRequest(); - request.setUsername(username); - request.setType(AuthenticationOperatorType.LOGIN); - LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + Valid.inRange(count, 0, 100, ErrorMessage.PARAM_ERROR); // 查询 - return operatorLogDAO.of(wrapper) + return operatorLogDAO.of() + .createWrapper() + .eq(OperatorLogDO::getUsername, username) + .eq(OperatorLogDO::getType, AuthenticationOperatorType.LOGIN) + .orderByDesc(OperatorLogDO::getId) + .then() .limit(count) .list(OperatorLogConvert.MAPPER::toLoginHistory); } - /** - * 构建查询 wrapper - * - * @param request request - * @return wrapper - */ - private LambdaQueryWrapper buildQueryWrapper(OperatorLogQueryRequest request) { + @Override + public LambdaQueryWrapper buildQueryWrapper(OperatorLogQueryRequest request) { return operatorLogDAO.wrapper() .eq(OperatorLogDO::getUserId, request.getUserId()) .eq(OperatorLogDO::getUsername, request.getUsername()) @@ -116,8 +116,7 @@ private LambdaQueryWrapper buildQueryWrapper(OperatorLogQueryRequ .eq(OperatorLogDO::getType, request.getType()) .eq(OperatorLogDO::getResult, request.getResult()) .ge(OperatorLogDO::getStartTime, Arrays1.getIfPresent(request.getStartTimeRange(), 0)) - .le(OperatorLogDO::getStartTime, Arrays1.getIfPresent(request.getStartTimeRange(), 1)) - .orderByDesc(OperatorLogDO::getId); + .le(OperatorLogDO::getStartTime, Arrays1.getIfPresent(request.getStartTimeRange(), 1)); } } diff --git a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/SystemUserServiceImpl.java b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/SystemUserServiceImpl.java index c86c213b..ebd74d54 100644 --- a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/SystemUserServiceImpl.java +++ b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/SystemUserServiceImpl.java @@ -207,20 +207,25 @@ public List getSystemUserList() { @Override public DataGrid getSystemUserPage(SystemUserQueryRequest request) { - // 构造条件 - LambdaQueryWrapper wrapper = systemUserDAO.wrapper() - .eq(SystemUserDO::getId, request.getId()) - .like(SystemUserDO::getUsername, request.getUsername()) - .like(SystemUserDO::getNickname, request.getNickname()) - .like(SystemUserDO::getMobile, request.getMobile()) - .like(SystemUserDO::getEmail, request.getEmail()) - .eq(SystemUserDO::getStatus, request.getStatus()); + // 条件 + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); // 查询 - return systemUserDAO.of(wrapper) + return systemUserDAO.of() .page(request) + .wrapper(wrapper) .dataGrid(SystemUserConvert.MAPPER::to); } + @Override + public Long getSystemUserCount(SystemUserQueryRequest request) { + // 条件 + LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); + // 查询 + return systemUserDAO.of() + .wrapper(wrapper) + .countMax(request.getLimit()); + } + @Override public Integer deleteSystemUserById(Long id) { return this.deleteSystemUserByIdList(Lists.singleton(id)); @@ -358,4 +363,15 @@ private void deleteUserCacheKey(List userList) { RedisUtils.delete(deleteKeys); } + @Override + public LambdaQueryWrapper buildQueryWrapper(SystemUserQueryRequest request) { + return systemUserDAO.wrapper() + .eq(SystemUserDO::getId, request.getId()) + .like(SystemUserDO::getUsername, request.getUsername()) + .like(SystemUserDO::getNickname, request.getNickname()) + .like(SystemUserDO::getMobile, request.getMobile()) + .like(SystemUserDO::getEmail, request.getEmail()) + .eq(SystemUserDO::getStatus, request.getStatus()); + } + }