【7.2.5】【role】更新批量插入roleResource的方法

pull/37/head
fengshuonan 2022-09-17 15:12:04 +08:00
parent 7b573b530a
commit e477aa2427
4 changed files with 27 additions and 3 deletions

View File

@ -24,8 +24,8 @@
*/ */
package cn.stylefeng.roses.kernel.system.modular.role.mapper; package cn.stylefeng.roses.kernel.system.modular.role.mapper;
import cn.stylefeng.roses.kernel.db.mp.injector.CustomBaseMapper;
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRoleResource; import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRoleResource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/** /**
* mapper * mapper
@ -33,5 +33,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @author majianguo * @author majianguo
* @date 2020/11/5 4:15 * @date 2020/11/5 4:15
*/ */
public interface SysRoleResourceMapper extends BaseMapper<SysRoleResource> { public interface SysRoleResourceMapper extends CustomBaseMapper<SysRoleResource> {
} }

View File

@ -73,4 +73,12 @@ public interface SysRoleResourceService extends IService<SysRoleResource> {
*/ */
void deleteRoleResourceListByRoleId(Long roleId); void deleteRoleResourceListByRoleId(Long roleId);
/**
*
*
* @author fengshuonan
* @date 2022/9/17 14:33
*/
void quickSaveAll(List<SysRoleResource> sysRoleResourceList);
} }

View File

@ -26,6 +26,9 @@ package cn.stylefeng.roses.kernel.system.modular.role.service.impl;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi; import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.db.api.pojo.druid.DruidProperties;
import cn.stylefeng.roses.kernel.rule.enums.DbTypeEnum;
import cn.stylefeng.roses.kernel.rule.util.DatabaseTypeUtil;
import cn.stylefeng.roses.kernel.system.api.pojo.role.request.SysRoleRequest; import cn.stylefeng.roses.kernel.system.api.pojo.role.request.SysRoleRequest;
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRoleResource; import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRoleResource;
import cn.stylefeng.roses.kernel.system.modular.role.mapper.SysRoleResourceMapper; import cn.stylefeng.roses.kernel.system.modular.role.mapper.SysRoleResourceMapper;
@ -53,6 +56,9 @@ public class SysRoleResourceServiceImpl extends ServiceImpl<SysRoleResourceMappe
@Resource(name = "roleResourceCacheApi") @Resource(name = "roleResourceCacheApi")
private CacheOperatorApi<List<String>> roleResourceCacheApi; private CacheOperatorApi<List<String>> roleResourceCacheApi;
@Resource
private DruidProperties druidProperties;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void grantResource(SysRoleRequest sysRoleRequest) { public void grantResource(SysRoleRequest sysRoleRequest) {
@ -143,4 +149,14 @@ public class SysRoleResourceServiceImpl extends ServiceImpl<SysRoleResourceMappe
} }
@Override
public void quickSaveAll(List<SysRoleResource> sysRoleResourceList) {
DbTypeEnum currentDbType = DatabaseTypeUtil.getDbType(druidProperties.getUrl());
if (DbTypeEnum.MYSQL.equals(currentDbType)) {
this.getBaseMapper().insertBatchSomeColumn(sysRoleResourceList);
} else {
this.saveBatch(sysRoleResourceList, sysRoleResourceList.size());
}
}
} }

View File

@ -89,7 +89,7 @@ public class InitAdminService {
sysRoleResource.setRoleId(superAdminRole.getRoleId()); sysRoleResource.setRoleId(superAdminRole.getRoleId());
sysRoleResources.add(sysRoleResource); sysRoleResources.add(sysRoleResource);
} }
sysRoleResourceService.saveBatch(sysRoleResources, sysRoleResources.size()); sysRoleResourceService.quickSaveAll(sysRoleResources);
} }
} }