Search in sources :

Example 6 with IamResourcePermission

use of com.diboot.iam.entity.IamResourcePermission in project diboot by dibo-software.

the class IamResourcePermissionServiceImpl method hasDirtyData.

/**
 * 检测是否又脏数据存在
 * @return
 */
private boolean hasDirtyData() {
    List<IamResourcePermission> list = this.getEntityList(null);
    if (V.isEmpty(list)) {
        return false;
    }
    Map<String, IamResourcePermission> idObjectMap = BeanUtils.convertToStringKeyObjectMap(list, BeanUtils.convertToFieldName(IamResourcePermission::getId));
    List<Long> deleteIdList = new ArrayList<>();
    for (IamResourcePermission item : list) {
        if (!hasTopRootNode(idObjectMap, item, null)) {
            deleteIdList.add(item.getId());
        }
    }
    return V.notEmpty(deleteIdList);
}
Also used : IamResourcePermission(com.diboot.iam.entity.IamResourcePermission)

Example 7 with IamResourcePermission

use of com.diboot.iam.entity.IamResourcePermission in project diboot by dibo-software.

the class IamResourcePermissionServiceImpl method clearDirtyData.

/**
 * 清理没有关联关系的
 */
private void clearDirtyData() {
    List<IamResourcePermission> list = this.getEntityList(null);
    if (V.isEmpty(list)) {
        return;
    }
    Map<String, IamResourcePermission> idObjectMap = BeanUtils.convertToStringKeyObjectMap(list, BeanUtils.convertToFieldName(IamResourcePermission::getId));
    List<Long> deleteIdList = new ArrayList<>();
    for (IamResourcePermission item : list) {
        if (!hasTopRootNode(idObjectMap, item, null)) {
            deleteIdList.add(item.getId());
        }
    }
    if (V.notEmpty(deleteIdList)) {
        LambdaQueryWrapper deleteWrapper = Wrappers.<IamResourcePermission>lambdaQuery().in(IamResourcePermission::getId, deleteIdList);
        long count = this.getEntityListCount(deleteWrapper);
        if (count > 0) {
            this.deleteEntities(deleteWrapper);
            log.info("共清理掉{}条无用数据", count);
        }
    }
}
Also used : IamResourcePermission(com.diboot.iam.entity.IamResourcePermission) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 8 with IamResourcePermission

use of com.diboot.iam.entity.IamResourcePermission in project diboot by dibo-software.

the class IamHelper method buildRoleVo4FrontEnd.

/**
 * 构建role-permission角色权限数据格式(合并role等),用于前端适配
 * @param roleVOList
 * @return
 */
public static IamRoleVO buildRoleVo4FrontEnd(List<IamRoleVO> roleVOList) {
    if (V.isEmpty(roleVOList)) {
        return null;
    }
    // 对RoleList做聚合处理,以适配前端
    List<String> nameList = new ArrayList<>(roleVOList.size());
    List<String> codeList = new ArrayList<>(roleVOList.size());
    List<IamResourcePermission> allPermissionList = new ArrayList<>();
    roleVOList.forEach(vo -> {
        nameList.add(vo.getName());
        codeList.add(vo.getCode());
        if (V.notEmpty(vo.getPermissionList())) {
            allPermissionList.addAll(vo.getPermissionList());
        }
    });
    // 对permissionList进行去重
    List permissionList = BeanUtils.distinctByKey(allPermissionList, IamResourcePermission::getId);
    IamRoleVO roleVO = new IamRoleVO();
    roleVO.setName(S.join(nameList));
    roleVO.setCode(S.join(codeList));
    roleVO.setPermissionList(permissionList);
    return roleVO;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IamResourcePermission(com.diboot.iam.entity.IamResourcePermission) IamRoleVO(com.diboot.iam.vo.IamRoleVO)

Aggregations

IamResourcePermission (com.diboot.iam.entity.IamResourcePermission)8 BusinessException (com.diboot.core.exception.BusinessException)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 IamResourcePermissionListVO (com.diboot.iam.vo.IamResourcePermissionListVO)2 InvalidResourcePermissionVO (com.diboot.iam.vo.InvalidResourcePermissionVO)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)1 RelationsBinder (com.diboot.core.binding.RelationsBinder)1 BeanUtils (com.diboot.core.util.BeanUtils)1 S (com.diboot.core.util.S)1 V (com.diboot.core.util.V)1 Status (com.diboot.core.vo.Status)1 IamCacheManager (com.diboot.iam.cache.IamCacheManager)1 Cons (com.diboot.iam.config.Cons)1 IamResourcePermissionDTO (com.diboot.iam.dto.IamResourcePermissionDTO)1 IamResourcePermissionMapper (com.diboot.iam.mapper.IamResourcePermissionMapper)1 IamResourcePermissionService (com.diboot.iam.service.IamResourcePermissionService)1 IamRoleVO (com.diboot.iam.vo.IamRoleVO)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1