Search in sources :

Example 1 with GroupMemberBean

use of com.akaxin.site.storage.bean.GroupMemberBean in project openzaly by akaxincom.

the class ApiGroupService method profile.

/**
 * 获取群资料信息,一般由以下几部分组成 <br>
 * 1.群资料GroupProfile <br>
 * 2.群主基本资料GroupMaster,群主通过GroupProfile获取 <br>
 * 3.群成员人数以及排在最前列的四位用户 <br>
 * 4.无权限限制
 *
 * @param command
 * @return
 */
public CommandResponse profile(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupProfileProto.ApiGroupProfileRequest request = ApiGroupProfileProto.ApiGroupProfileRequest.parseFrom(command.getParams());
        String groupId = request.getGroupId();
        int pageNum = 1;
        int pageSize = GroupConfig.GROUP_MIN_MEMBER_COUNT;
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(groupId)) {
            GroupProfileBean groupBean = UserGroupDao.getInstance().getGroupProfile(groupId);
            if (groupBean != null && StringUtils.isNotBlank(groupBean.getGroupId())) {
                SimpleUserBean ownerProfileBean = UserProfileDao.getInstance().getSimpleProfileById(groupBean.getCreateUserId());
                logger.debug("get groupId={},groupOwner={}", groupId, ownerProfileBean.toString());
                int groupMembersCount = UserGroupDao.getInstance().getGroupMemberCount(groupId);
                logger.debug("get groupId={},groupMembers={}", groupId, groupMembersCount);
                List<GroupMemberBean> groupMemberList = UserGroupDao.getInstance().getGroupMemberList(groupId, pageNum, pageSize);
                UserProto.UserProfile ownerProfile = UserProto.UserProfile.newBuilder().setSiteUserId(String.valueOf(ownerProfileBean.getUserId())).setUserPhoto(String.valueOf(ownerProfileBean.getUserPhoto())).setUserName(String.valueOf(ownerProfileBean.getUserName())).build();
                GroupProto.GroupProfile groupProfile = GroupProto.GroupProfile.newBuilder().setId(groupBean.getGroupId()).setName(String.valueOf(groupBean.getGroupName())).setIcon(String.valueOf(groupBean.getGroupPhoto())).build();
                ApiGroupProfileProto.ApiGroupProfileResponse.Builder responseBuilder = ApiGroupProfileProto.ApiGroupProfileResponse.newBuilder();
                responseBuilder.setOwner(ownerProfile);
                responseBuilder.setProfile(groupProfile);
                responseBuilder.setGroupMemberCount(groupMembersCount);
                for (GroupMemberBean memberBean : groupMemberList) {
                    UserProto.UserProfile memberProfile = UserProto.UserProfile.newBuilder().setSiteUserId(String.valueOf(memberBean.getUserId())).setUserPhoto(String.valueOf(memberBean.getUserPhoto())).setUserName(String.valueOf(memberBean.getUserName())).build();
                    GroupProto.GroupMemberProfile groupMemberProfile = GroupProto.GroupMemberProfile.newBuilder().setProfile(memberProfile).build();
                    responseBuilder.addGroupLastestMember(groupMemberProfile);
                }
                // 是否可以邀请群聊(除了群主以外)
                responseBuilder.setCloseInviteGroupChat(groupBean.isCloseInviteGroupChat());
                ApiGroupProfileProto.ApiGroupProfileResponse response = responseBuilder.build();
                commandResponse.setParams(response.toByteArray());
                errCode = ErrorCode2.SUCCESS;
            }
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiGroupProfileProto(com.akaxin.proto.site.ApiGroupProfileProto) UserProto(com.akaxin.proto.core.UserProto) GroupProto(com.akaxin.proto.core.GroupProto) CommandResponse(com.akaxin.common.command.CommandResponse) GroupMemberBean(com.akaxin.site.storage.bean.GroupMemberBean) SimpleUserBean(com.akaxin.site.storage.bean.SimpleUserBean) ErrorCode2(com.akaxin.common.constant.ErrorCode2) GroupProfileBean(com.akaxin.site.storage.bean.GroupProfileBean)

Example 2 with GroupMemberBean

use of com.akaxin.site.storage.bean.GroupMemberBean in project openzaly by akaxincom.

the class SQLiteUserGroupDao method getGroupMember.

public GroupMemberBean getGroupMember(String siteUserId, String groupId) throws SQLException {
    long startTime = System.currentTimeMillis();
    String sql = "SELECT site_user_id,user_role FROM " + USER_GROUP_TABLE + " WHERE site_user_id=? AND site_group_id=?;";
    PreparedStatement preStatement = SQLiteJDBCManager.getConnection().prepareStatement(sql);
    preStatement.setString(1, siteUserId);
    preStatement.setString(2, groupId);
    ResultSet rs = preStatement.executeQuery();
    GroupMemberBean member = new GroupMemberBean();
    if (rs.next()) {
        member.setUserId(rs.getString(1));
        member.setUserRole(rs.getInt(2));
    }
    long endTime = System.currentTimeMillis();
    LogUtils.dbDebugLog(logger, startTime, member.toString(), sql + siteUserId + "," + groupId);
    return member;
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) GroupMemberBean(com.akaxin.site.storage.bean.GroupMemberBean)

Example 3 with GroupMemberBean

use of com.akaxin.site.storage.bean.GroupMemberBean in project openzaly by akaxincom.

the class ApiGroupService method members.

/**
 * 获取群成员 <br>
 * 无权限控制
 *
 * @param command
 * @return
 */
public CommandResponse members(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupMembersProto.ApiGroupMembersRequest request = ApiGroupMembersProto.ApiGroupMembersRequest.parseFrom(command.getParams());
        String groupId = request.getGroupId();
        int pageNum = 1;
        int pageSize = GroupConfig.GROUP_MAX_MEMBER_COUNT;
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(groupId)) {
            List<GroupMemberBean> memberList = UserGroupDao.getInstance().getGroupMemberList(groupId, pageNum, pageSize);
            ApiGroupMembersProto.ApiGroupMembersResponse.Builder responseBuilder = ApiGroupMembersProto.ApiGroupMembersResponse.newBuilder();
            for (GroupMemberBean member : memberList) {
                GroupProto.GroupMemberRole memberRole = GroupProto.GroupMemberRole.forNumber(member.getUserRole());
                UserProto.UserProfile memberProfile = UserProto.UserProfile.newBuilder().setSiteUserId(member.getUserId()).setUserName(String.valueOf(member.getUserName())).setUserPhoto(String.valueOf(member.getUserPhoto())).build();
                GroupProto.GroupMemberProfile groupMember = GroupProto.GroupMemberProfile.newBuilder().setRole(memberRole).setProfile(memberProfile).build();
                responseBuilder.addList(groupMember);
            }
            commandResponse.setParams(responseBuilder.build().toByteArray());
            errCode = ErrorCode2.SUCCESS;
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiGroupMembersProto(com.akaxin.proto.site.ApiGroupMembersProto) GroupProto(com.akaxin.proto.core.GroupProto) UserProto(com.akaxin.proto.core.UserProto) CommandResponse(com.akaxin.common.command.CommandResponse) GroupMemberBean(com.akaxin.site.storage.bean.GroupMemberBean) ErrorCode2(com.akaxin.common.constant.ErrorCode2)

Example 4 with GroupMemberBean

use of com.akaxin.site.storage.bean.GroupMemberBean in project openzaly by akaxincom.

the class HttpGroupService method nonmembers.

public CommandResponse nonmembers(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        HaiGroupNonmembersProto.HaiGroupNonmembersRequest request = HaiGroupNonmembersProto.HaiGroupNonmembersRequest.parseFrom(command.getParams());
        String groupId = request.getGroupId();
        int pageNum = request.getPageNumber();
        int pageSize = request.getPageSize();
        LogUtils.requestDebugLog(logger, command, request.toString());
        List<GroupMemberBean> memberList = UserGroupDao.getInstance().getNonGroupMemberList(groupId, pageNum, pageSize);
        HaiGroupNonmembersProto.HaiGroupNonmembersResponse.Builder responseBuilder = HaiGroupNonmembersProto.HaiGroupNonmembersResponse.newBuilder();
        for (GroupMemberBean member : memberList) {
            GroupProto.GroupMemberRole memberRole = GroupProto.GroupMemberRole.NONMEMBER;
            UserProto.UserProfile memberProfile = UserProto.UserProfile.newBuilder().setSiteUserId(member.getUserId()).setUserName(String.valueOf(member.getUserName())).setUserPhoto(String.valueOf(member.getUserPhoto())).build();
            GroupProto.GroupMemberProfile groupMember = GroupProto.GroupMemberProfile.newBuilder().setRole(memberRole).setProfile(memberProfile).build();
            responseBuilder.addGroupMember(groupMember);
        }
        commandResponse.setParams(responseBuilder.build().toByteArray());
        errCode = ErrorCode2.SUCCESS;
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : GroupProto(com.akaxin.proto.core.GroupProto) UserProto(com.akaxin.proto.core.UserProto) CommandResponse(com.akaxin.common.command.CommandResponse) GroupMemberBean(com.akaxin.site.storage.bean.GroupMemberBean) ErrorCode2(com.akaxin.common.constant.ErrorCode2) HaiGroupNonmembersProto(com.akaxin.proto.plugin.HaiGroupNonmembersProto)

Example 5 with GroupMemberBean

use of com.akaxin.site.storage.bean.GroupMemberBean in project openzaly by akaxincom.

the class HttpGroupService method members.

/**
 * 获取群成员列表
 *
 * @param command
 * @return
 */
public CommandResponse members(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        HaiGroupMembersProto.HaiGroupMembersRequest request = HaiGroupMembersProto.HaiGroupMembersRequest.parseFrom(command.getParams());
        String groupId = request.getGroupId();
        int pageNum = request.getPageNumber();
        int pageSize = request.getPageSize();
        if (pageNum == 0 && pageSize == 0) {
            pageNum = 1;
            pageSize = GroupConfig.GROUP_MAX_MEMBER_COUNT;
        }
        LogUtils.requestDebugLog(logger, command, request.toString());
        List<GroupMemberBean> memberList = UserGroupDao.getInstance().getGroupMemberList(groupId, pageNum, pageSize);
        HaiGroupMembersProto.HaiGroupMembersResponse.Builder responseBuilder = HaiGroupMembersProto.HaiGroupMembersResponse.newBuilder();
        for (GroupMemberBean member : memberList) {
            GroupProto.GroupMemberRole memberRole = GroupProto.GroupMemberRole.forNumber(member.getUserRole());
            UserProto.UserProfile memberProfile = UserProto.UserProfile.newBuilder().setSiteUserId(member.getUserId()).setUserName(String.valueOf(member.getUserName())).setUserPhoto(String.valueOf(member.getUserPhoto())).build();
            GroupProto.GroupMemberProfile groupMember = GroupProto.GroupMemberProfile.newBuilder().setRole(memberRole).setProfile(memberProfile).build();
            responseBuilder.addGroupMember(groupMember);
        }
        commandResponse.setParams(responseBuilder.build().toByteArray());
        errCode = ErrorCode2.SUCCESS;
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : GroupProto(com.akaxin.proto.core.GroupProto) UserProto(com.akaxin.proto.core.UserProto) CommandResponse(com.akaxin.common.command.CommandResponse) GroupMemberBean(com.akaxin.site.storage.bean.GroupMemberBean) ErrorCode2(com.akaxin.common.constant.ErrorCode2) HaiGroupMembersProto(com.akaxin.proto.plugin.HaiGroupMembersProto)

Aggregations

GroupMemberBean (com.akaxin.site.storage.bean.GroupMemberBean)7 CommandResponse (com.akaxin.common.command.CommandResponse)4 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)4 GroupProto (com.akaxin.proto.core.GroupProto)4 UserProto (com.akaxin.proto.core.UserProto)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 ArrayList (java.util.ArrayList)2 HaiGroupMembersProto (com.akaxin.proto.plugin.HaiGroupMembersProto)1 HaiGroupNonmembersProto (com.akaxin.proto.plugin.HaiGroupNonmembersProto)1 ApiGroupMembersProto (com.akaxin.proto.site.ApiGroupMembersProto)1 ApiGroupProfileProto (com.akaxin.proto.site.ApiGroupProfileProto)1 GroupProfileBean (com.akaxin.site.storage.bean.GroupProfileBean)1 SimpleUserBean (com.akaxin.site.storage.bean.SimpleUserBean)1