Java Code Examples for com.alibaba.dubbo.common.utils.CollectionUtils#isNotEmpty()

The following examples show how to use com.alibaba.dubbo.common.utils.CollectionUtils#isNotEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserServiceImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
/**
 * 根据userState将userId分组
 * @param userStateReqs 修改用户状态的请求
 * @return 分组后结果(key:用户状态、value:该状态下对应的userid列表)
 */
private Map<Integer, List<String>> groupUserIdByUserState(BatchReq<UserStateReq> userStateReqs) {
    // 创建结果集
    Map<Integer, List<String>> userStateMap = Maps.newHashMap();

    // 遍历UserStateEnum
    if (UserStateEnum.values().length > 0) {
        for (UserStateEnum userStateEnum : UserStateEnum.values()) {
            // 获取当前用户状态下的所有userid
            List<String> userIdList = Lists.newArrayList();
            if (CollectionUtils.isNotEmpty(userStateReqs.getReqList())) {
                for (UserStateReq userStateReq : userStateReqs.getReqList()) {
                    if (userStateReq.getUserState() == userStateEnum.getCode()) {
                        userIdList.add(userStateReq.getUserId());
                    }
                }
                userStateMap.put(userStateEnum.getCode(), userIdList);
            }
        }
    }

    return userStateMap;
}
 
Example 2
Source File: AccessAuthHandle.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
/**
 * 检查当前用户是否拥有访问该接口的权限
 * @param userEntity 用户信息
 * @param accessAuthEntity 接口权限信息
 */
private void checkPermission(UserEntity userEntity, AccessAuthEntity accessAuthEntity) {
    // 获取接口权限
    String accessPermission = accessAuthEntity.getPermission();

    // 获取用户权限
    List<PermissionEntity> userPermissionList = userEntity.getRoleEntity().getPermissionList();

    // 判断用户是否包含接口权限
    if (CollectionUtils.isNotEmpty(userPermissionList)) {
        for (PermissionEntity permissionEntity : userPermissionList) {
            if (permissionEntity.getPermission().equals(accessPermission)) {
                return;
            }
        }
    }

    // 没有权限
    throw new CommonBizException(ExpCodeEnum.NO_PERMISSION);
}
 
Example 3
Source File: UserRepository.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
public List<UserDO> findIn(List<Long> ids) {
    try{
        ids = ids.stream().distinct().collect(Collectors.toList());
        ListUtil.sort(ids);
        RBuckets rBuckets = redissonClient.getBuckets(JsonJacksonCodec.INSTANCE);
        Map<String, UserDO> vpMaps = rBuckets.get(ModelUtil.formatStrings(UserKeys.USER_DO_ID, ids));

        List<UserDO> list = Lists.newArrayListWithCapacity(ids.size());
        List<Long> redisIds = Lists.newArrayListWithCapacity(ids.size());
        ids.stream().forEach( id -> {
            String key = String.format(UserKeys.USER_DO_ID, id);
            if (vpMaps.containsKey(key)) {
                UserDO topicDO = vpMaps.get(key);
                if (Objects.nonNull(topicDO)) {
                    list.add(topicDO);
                    redisIds.add(id);

                    //延迟过期
                    redissonClient.getBucket(key,JsonJacksonCodec.INSTANCE)
                            .expire(AppConfig.COMMON_CACHE_DAYS, TimeUnit.MINUTES);
                }
            }
        });

        List<Long> lastIds = ListUtils.removeAll(ids, redisIds);
        if (CollectionUtils.isNotEmpty(lastIds)) {
            List<UserDO> dbList =  list(lastIds);
            if (CollectionUtils.isNotEmpty(dbList)) {
                list.addAll(dbList);

                dbList.stream().forEach(topicDO -> {
                    redissonClient.getBucket(String.format(UserKeys.USER_DO_ID, topicDO.getUid()),JsonJacksonCodec.INSTANCE)
                            .setAsync(topicDO, AppConfig.COMMON_CACHE_DAYS, TimeUnit.MINUTES);
                });
            }
        }

        return list;
    }catch(Throwable th){
        throw new RepositoryException(ErrorCode.DB_ERROR.getErrorCode(),ErrorCode.DB_ERROR.getErrorMsg(),th);
    }
}