完成 服务启动之后权限自动入库

This commit is contained in:
wuy 2019-06-23 01:13:45 +08:00
parent ade3e1fe5f
commit 457f6cb66c
2 changed files with 16 additions and 12 deletions

View File

@ -31,8 +31,8 @@ public class Permission extends BaseEntity {
@TableField @TableField
private String permissionName; private String permissionName;
/**此处覆盖了父类的属性,初始化权限的时候需要设置该值,父类默认不设置*/ /**此处覆盖了父类的属性,初始化权限的时候需要设置该值,直接使用父类,无法设置*/
// @TableField @TableField
// private boolean deleted = false; private boolean deleted = false;
} }

View File

@ -191,7 +191,7 @@ public abstract class AbstractStorageApplicationListener implements ApplicationL
*/ */
private void saveOrUpdateOrDeletePermission(PermissionServiceImpl permissionService) { private void saveOrUpdateOrDeletePermission(PermissionServiceImpl permissionService) {
//记录修改和删除的权限数量 //记录修改和删除的权限数量
int modifyCount = 0, removeCount = 0, totalCount = 0; int modifyCount = 0, removeCount = 0, totalCount = loadCodePermissionMap.values().size();;
List<Permission> saveOrUpdateOrDeletePermissionList = new ArrayList<>(); List<Permission> saveOrUpdateOrDeletePermissionList = new ArrayList<>();
//设置删除 or 修改 //设置删除 or 修改
for (Map.Entry<String, Permission> entry : dbPermissionMap.entrySet()) { for (Map.Entry<String, Permission> entry : dbPermissionMap.entrySet()) {
@ -219,19 +219,23 @@ public abstract class AbstractStorageApplicationListener implements ApplicationL
//需要操作的数据=转化为List<Permission> //需要操作的数据=转化为List<Permission>
List<Permission> saveOrUpdatePermissionList; List<Permission> saveOrUpdatePermissionList;
if (V.notEmpty(loadCodePermissionMap)) { if (V.notEmpty(loadCodePermissionMap)) {
totalCount = loadCodePermissionMap.values().size();
List<PermissionStorage> permissionStorageList = loadCodePermissionMap.values().stream().collect(Collectors.toList()); List<PermissionStorage> permissionStorageList = loadCodePermissionMap.values().stream().collect(Collectors.toList());
saveOrUpdatePermissionList = BeanUtils.convertList(permissionStorageList, Permission.class); saveOrUpdatePermissionList = BeanUtils.convertList(permissionStorageList, Permission.class);
saveOrUpdateOrDeletePermissionList.addAll(saveOrUpdatePermissionList); saveOrUpdateOrDeletePermissionList.addAll(saveOrUpdatePermissionList);
} }
//保存更新删除 权限 if (V.notEmpty(saveOrUpdateOrDeletePermissionList)) {
boolean success = permissionService.saveOrUpdateBatch(saveOrUpdateOrDeletePermissionList); //保存更新删除 权限
if (success) { boolean success = permissionService.saveOrUpdateBatch(saveOrUpdateOrDeletePermissionList);
log.debug("【初始化权限】<== 成功!共计权限{}个 新增【{}】个, 修改【{}】个,删除【{}】个!", if (success) {
totalCount, (saveOrUpdateOrDeletePermissionList.size() - modifyCount - removeCount), modifyCount, removeCount); log.debug("【初始化权限】<== 成功!");
} else { } else {
log.debug("【初始化权限】<== 失败!"); log.debug("【初始化权限】<== 失败!");
}
} }
log.debug("当前系统权限共计【{}】个 新增【{}】个, 修改【{}】个,删除【{}】个!",
totalCount, (saveOrUpdateOrDeletePermissionList.size() - modifyCount - removeCount), modifyCount, removeCount);
} }
/** /**