private void fillAccessObject(List<DataSourceAccess> list, DataSourceAccessSelector selector) {
        if (BooleanUtils.isNotTrue(selector.getAccessObject())) {
            return;
        }
        List<Long> userIdList = Lists.newArrayList();
        List<Long> teamIdList = Lists.newArrayList();
        for (DataSourceAccess data : list) {
            if (AccessObjectTypeEnum.TEAM.getCode().equals(data.getAccessObjectType())) {
                teamIdList.add(data.getAccessObjectId());
            } else if (AccessObjectTypeEnum.USER.getCode().equals(data.getAccessObjectType())) {
                userIdList.add(data.getAccessObjectId());
            }
        }
        List<User> userList = userService.listQuery(userIdList).getData();
        Map<Long, User> userMap = EasyCollectionUtils.toIdentityMap(userList, User::getId);
        List<Team> teamList = teamService.listQuery(teamIdList).getData();
        Map<Long, Team> teamMap = EasyCollectionUtils.toIdentityMap(teamList, Team::getId);
        for (DataSourceAccess data : list) {
            DataSourceAccessObject dataSourceAccessObject = data.getAccessObject();
            if (dataSourceAccessObject == null) {
                continue;
            }
            if (AccessObjectTypeEnum.TEAM.getCode().equals(data.getAccessObjectType())) {
                Team team = teamMap.get(data.getAccessObjectId());
                if (team == null) {
                    continue;
                }
                dataSourceAccessObject.setCode(team.getCode());
                dataSourceAccessObject.setName(team.getName());
            } else if (AccessObjectTypeEnum.USER.getCode().equals(data.getAccessObjectType())) {
                User user = userMap.get(data.getAccessObjectId());
                if (user == null) {
                    continue;
                }
                dataSourceAccessObject.setCode(user.getUserName());
                dataSourceAccessObject.setName(user.getNickName());
            }
        }
    }
Data Source Access

@author Jiaju Zhuang
chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DataSourceAccessServiceImpl.java