From 061f63d25644fe1d3113fc70c2701f4097773402 Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Mon, 19 Sep 2022 13:09:52 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=907.2.5=E3=80=91=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E6=95=B0=E6=8D=AE=EF=BC=8C=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E9=BB=98=E8=AE=A4100=E6=9D=A1=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kernel/rule/constants/RuleConstants.java | 5 +++++ .../scanner/ResourceReportListener.java | 15 ++++++++----- .../service/impl/SysResourceServiceImpl.java | 22 ++++++++++++++----- .../impl/SysRoleResourceServiceImpl.java | 8 ++++++- .../listener/SuperAdminInitListener.java | 2 ++ 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/constants/RuleConstants.java b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/constants/RuleConstants.java index 05e1e81de..2828182b7 100644 --- a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/constants/RuleConstants.java +++ b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/constants/RuleConstants.java @@ -97,4 +97,9 @@ public interface RuleConstants { */ String SYSTEM_CONFIG_INIT_FLAG_NAME = "SYS_CONFIG_INIT_FLAG"; + /** + * 默认分批插入mysql数据的大小 + */ + int DEFAULT_BATCH_INSERT_SIZE = 100; + } diff --git a/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/ResourceReportListener.java b/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/ResourceReportListener.java index c5dfca9c5..1a741a5b9 100644 --- a/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/ResourceReportListener.java +++ b/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/ResourceReportListener.java @@ -69,25 +69,30 @@ public class ResourceReportListener extends ApplicationReadyListener implements // 如果项目还没进行资源扫描 if (!InitScanFlagHolder.getFlag()) { + long beginSaveLocal = System.currentTimeMillis(); + // 获取当前系统的所有资源 ResourceCollectorApi resourceCollectorApi = applicationContext.getBean(ResourceCollectorApi.class); Map> modularResources = resourceCollectorApi.getModularResources(); // 持久化资源,发送资源到资源服务或本项目 ResourceReportApi resourceService = applicationContext.getBean(ResourceReportApi.class); - List persistencePojos = resourceService.reportResourcesAndGetResult(new ReportResourceParam(scannerProperties.getAppCode(), modularResources)); + List persistencePojos = + resourceService.reportResourcesAndGetResult(new ReportResourceParam(scannerProperties.getAppCode(), modularResources)); + + long saveLocalFinish = System.currentTimeMillis(); + log.info("存储本地接口资源完成,耗时:{}ms", (saveLocalFinish - beginSaveLocal)); // 向DevOps一体化平台汇报资源 DevOpsReportProperties devOpsReportProperties = applicationContext.getBean(DevOpsReportProperties.class); // 如果配置了相关属性则进行DevOps资源汇报 - if (ObjectUtil.isAllNotEmpty(devOpsReportProperties, - devOpsReportProperties.getServerHost(), - devOpsReportProperties.getProjectInteractionSecretKey(), - devOpsReportProperties.getProjectUniqueCode(), + if (ObjectUtil.isAllNotEmpty(devOpsReportProperties, devOpsReportProperties.getServerHost(), + devOpsReportProperties.getProjectInteractionSecretKey(), devOpsReportProperties.getProjectUniqueCode(), devOpsReportProperties.getServerHost())) { DevOpsReportApi devOpsReportApi = applicationContext.getBean(DevOpsReportApi.class); try { devOpsReportApi.reportResources(devOpsReportProperties, persistencePojos); + log.info("向DevOps平台汇报资源信息完成,耗时:{}ms", (System.currentTimeMillis() - saveLocalFinish)); } catch (Exception e) { log.error("向DevOps平台汇报异常出现网络错误,如无法联通DevOps平台可关闭相关配置。", e); } diff --git a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/service/impl/SysResourceServiceImpl.java b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/service/impl/SysResourceServiceImpl.java index eac954c6e..4ad29a61b 100644 --- a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/service/impl/SysResourceServiceImpl.java +++ b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/system/modular/resource/service/impl/SysResourceServiceImpl.java @@ -25,6 +25,7 @@ package cn.stylefeng.roses.kernel.system.modular.resource.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ObjectUtil; import cn.stylefeng.roses.kernel.auth.api.LoginUserApi; @@ -136,7 +137,8 @@ public class SysResourceServiceImpl extends ServiceImpl sysResourceLambdaQueryWrapper = new LambdaQueryWrapper<>(); - sysResourceLambdaQueryWrapper.select(SysResource::getAppCode, SysResource::getModularCode, SysResource::getModularName, SysResource::getResourceCode, SysResource::getUrl, SysResource::getResourceName); + sysResourceLambdaQueryWrapper.select(SysResource::getAppCode, SysResource::getModularCode, SysResource::getModularName, SysResource::getResourceCode, + SysResource::getUrl, SysResource::getResourceName); // 只查询需要授权的接口 sysResourceLambdaQueryWrapper.eq(SysResource::getRequiredPermissionFlag, YesOrNotEnum.Y.getCode()); @@ -144,7 +146,8 @@ public class SysResourceServiceImpl extends ServiceImpl roleIds = loginUserApi.getLoginUser().getSimpleRoleInfoList().parallelStream().map(SimpleRoleInfo::getRoleId).collect(Collectors.toList()); + List roleIds = loginUserApi.getLoginUser().getSimpleRoleInfoList().parallelStream().map(SimpleRoleInfo::getRoleId) + .collect(Collectors.toList()); Set resourceCodeList = roleServiceApi.getRoleResourceCodeList(roleIds); if (!resourceCodeList.isEmpty()) { sysResourceLambdaQueryWrapper.in(SysResource::getResourceCode, resourceCodeList); @@ -228,11 +231,13 @@ public class SysResourceServiceImpl extends ServiceImpl sysResourceLambdaQueryWrapper = new LambdaQueryWrapper<>(); sysResourceLambdaQueryWrapper.eq(SysResource::getViewFlag, YesOrNotEnum.N.getCode()); - sysResourceLambdaQueryWrapper.select(SysResource::getAppCode, SysResource::getModularCode, SysResource::getModularName, SysResource::getResourceCode, SysResource::getUrl, SysResource::getResourceName); + sysResourceLambdaQueryWrapper.select(SysResource::getAppCode, SysResource::getModularCode, SysResource::getModularName, SysResource::getResourceCode, + SysResource::getUrl, SysResource::getResourceName); // 查询条件 if (ObjectUtil.isNotEmpty(resourceRequest.getResourceName())) { - sysResourceLambdaQueryWrapper.like(SysResource::getUrl, resourceRequest.getResourceName()).or().like(SysResource::getResourceName, resourceRequest.getResourceName()); + sysResourceLambdaQueryWrapper.like(SysResource::getUrl, resourceRequest.getResourceName()).or() + .like(SysResource::getResourceName, resourceRequest.getResourceName()); } List allResource = this.list(sysResourceLambdaQueryWrapper); @@ -304,7 +309,11 @@ public class SysResourceServiceImpl extends ServiceImpl> split = ListUtil.split(allResources, RuleConstants.DEFAULT_BATCH_INSERT_SIZE); + for (List sysResources : split) { + this.getBaseMapper().insertBatchSomeColumn(sysResources); + } } else { this.saveBatch(allResources, allResources.size()); } @@ -476,7 +485,8 @@ public class SysResourceServiceImpl extends ServiceImpl createResourceTree(Map>> appModularResources, Map modularCodeName) { + private List createResourceTree(Map>> appModularResources, Map modularCodeName) { List finalTree = new ArrayList<>(); diff --git a/kernel-s-system/system-business-role/src/main/java/cn/stylefeng/roses/kernel/system/modular/role/service/impl/SysRoleResourceServiceImpl.java b/kernel-s-system/system-business-role/src/main/java/cn/stylefeng/roses/kernel/system/modular/role/service/impl/SysRoleResourceServiceImpl.java index c0b10bec9..2d1be1f9e 100644 --- a/kernel-s-system/system-business-role/src/main/java/cn/stylefeng/roses/kernel/system/modular/role/service/impl/SysRoleResourceServiceImpl.java +++ b/kernel-s-system/system-business-role/src/main/java/cn/stylefeng/roses/kernel/system/modular/role/service/impl/SysRoleResourceServiceImpl.java @@ -24,9 +24,11 @@ */ package cn.stylefeng.roses.kernel.system.modular.role.service.impl; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi; import cn.stylefeng.roses.kernel.db.api.context.DbOperatorContext; +import cn.stylefeng.roses.kernel.rule.constants.RuleConstants; import cn.stylefeng.roses.kernel.rule.enums.DbTypeEnum; import cn.stylefeng.roses.kernel.system.api.pojo.role.request.SysRoleRequest; import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRoleResource; @@ -149,7 +151,11 @@ public class SysRoleResourceServiceImpl extends ServiceImpl sysRoleResourceList) { DbTypeEnum currentDbType = DbOperatorContext.me().getCurrentDbType(); if (DbTypeEnum.MYSQL.equals(currentDbType)) { - this.getBaseMapper().insertBatchSomeColumn(sysRoleResourceList); + // 分批插入数据 + List> split = ListUtil.split(sysRoleResourceList, RuleConstants.DEFAULT_BATCH_INSERT_SIZE); + for (List sysRoleResources : split) { + this.getBaseMapper().insertBatchSomeColumn(sysRoleResources); + } } else { this.saveBatch(sysRoleResourceList, sysRoleResourceList.size()); } diff --git a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/system/starter/listener/SuperAdminInitListener.java b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/system/starter/listener/SuperAdminInitListener.java index 2b28200ae..af39d3ac2 100644 --- a/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/system/starter/listener/SuperAdminInitListener.java +++ b/kernel-s-system/system-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/system/starter/listener/SuperAdminInitListener.java @@ -49,7 +49,9 @@ public class SuperAdminInitListener extends ApplicationReadyListener implements @Override public void eventCallback(ApplicationReadyEvent event) { + long startTime = System.currentTimeMillis(); initAdminService.initSuperAdmin(); + log.info("初始化超级管理员权限完成,耗时:{}ms", (System.currentTimeMillis() - startTime)); } @Override