【7.2.5】批量插入数据,改为默认100条记录

pull/37/head
fengshuonan 2022-09-19 13:09:52 +08:00
parent 237c9b4b53
commit 061f63d256
5 changed files with 40 additions and 12 deletions

View File

@ -97,4 +97,9 @@ public interface RuleConstants {
*/
String SYSTEM_CONFIG_INIT_FLAG_NAME = "SYS_CONFIG_INIT_FLAG";
/**
* mysql
*/
int DEFAULT_BATCH_INSERT_SIZE = 100;
}

View File

@ -69,25 +69,30 @@ public class ResourceReportListener extends ApplicationReadyListener implements
// 如果项目还没进行资源扫描
if (!InitScanFlagHolder.getFlag()) {
long beginSaveLocal = System.currentTimeMillis();
// 获取当前系统的所有资源
ResourceCollectorApi resourceCollectorApi = applicationContext.getBean(ResourceCollectorApi.class);
Map<String, Map<String, ResourceDefinition>> modularResources = resourceCollectorApi.getModularResources();
// 持久化资源,发送资源到资源服务或本项目
ResourceReportApi resourceService = applicationContext.getBean(ResourceReportApi.class);
List<SysResourcePersistencePojo> persistencePojos = resourceService.reportResourcesAndGetResult(new ReportResourceParam(scannerProperties.getAppCode(), modularResources));
List<SysResourcePersistencePojo> 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);
}

View File

@ -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<SysResourceMapper, SysRe
// 获取所有的资源
LambdaQueryWrapper<SysResource> 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<SysResourceMapper, SysRe
LoginUserApi loginUserApi = LoginContext.me();
if (!loginUserApi.getSuperAdminFlag()) {
// 获取权限列表
List<Long> roleIds = loginUserApi.getLoginUser().getSimpleRoleInfoList().parallelStream().map(SimpleRoleInfo::getRoleId).collect(Collectors.toList());
List<Long> roleIds = loginUserApi.getLoginUser().getSimpleRoleInfoList().parallelStream().map(SimpleRoleInfo::getRoleId)
.collect(Collectors.toList());
Set<String> resourceCodeList = roleServiceApi.getRoleResourceCodeList(roleIds);
if (!resourceCodeList.isEmpty()) {
sysResourceLambdaQueryWrapper.in(SysResource::getResourceCode, resourceCodeList);
@ -228,11 +231,13 @@ public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysRe
// 1. 获取所有的资源
LambdaQueryWrapper<SysResource> 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<SysResource> allResource = this.list(sysResourceLambdaQueryWrapper);
@ -304,7 +309,11 @@ public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysRe
// 将资源存入库中
DbTypeEnum currentDbType = DbOperatorContext.me().getCurrentDbType();
if (DbTypeEnum.MYSQL.equals(currentDbType)) {
this.getBaseMapper().insertBatchSomeColumn(allResources);
// 分批插入记录
List<List<SysResource>> split = ListUtil.split(allResources, RuleConstants.DEFAULT_BATCH_INSERT_SIZE);
for (List<SysResource> sysResources : split) {
this.getBaseMapper().insertBatchSomeColumn(sysResources);
}
} else {
this.saveBatch(allResources, allResources.size());
}
@ -476,7 +485,8 @@ public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysRe
* @author fengshuonan
* @date 2020/12/18 15:45
*/
private List<LayuiApiResourceTreeNode> createResourceTree(Map<String, Map<String, List<LayuiApiResourceTreeNode>>> appModularResources, Map<String, String> modularCodeName) {
private List<LayuiApiResourceTreeNode> createResourceTree(Map<String, Map<String, List<LayuiApiResourceTreeNode>>> appModularResources, Map<String,
String> modularCodeName) {
List<LayuiApiResourceTreeNode> finalTree = new ArrayList<>();

View File

@ -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<SysRoleResourceMappe
public void quickSaveAll(List<SysRoleResource> sysRoleResourceList) {
DbTypeEnum currentDbType = DbOperatorContext.me().getCurrentDbType();
if (DbTypeEnum.MYSQL.equals(currentDbType)) {
this.getBaseMapper().insertBatchSomeColumn(sysRoleResourceList);
// 分批插入数据
List<List<SysRoleResource>> split = ListUtil.split(sysRoleResourceList, RuleConstants.DEFAULT_BATCH_INSERT_SIZE);
for (List<SysRoleResource> sysRoleResources : split) {
this.getBaseMapper().insertBatchSomeColumn(sysRoleResources);
}
} else {
this.saveBatch(sysRoleResourceList, sysRoleResourceList.size());
}

View File

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