Search in sources :

Example 16 with CommandResponse

use of com.akaxin.common.command.CommandResponse 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 17 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiGroupService method delete.

/**
 * 用户删除群,此时需要验证用户是否具有权限 <br>
 * 目前:具有权限的仅为群的创建者 <br>
 * 群主/管理员权限限制
 *
 * @param command
 * @return
 */
public CommandResponse delete(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupDeleteProto.ApiGroupDeleteRequest request = ApiGroupDeleteProto.ApiGroupDeleteRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String groupId = request.getGroupId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId) && StringUtils.isNotBlank(groupId)) {
            String groupMasterId = UserGroupDao.getInstance().getGroupMaster(groupId);
            if (siteUserId.equals(groupMasterId)) {
                if (UserGroupDao.getInstance().deleteGroup(groupId)) {
                    errCode = ErrorCode2.SUCCESS;
                }
            } else {
                errCode = ErrorCode2.ERROR_NOPERMISSION;
            }
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiGroupDeleteProto(com.akaxin.proto.site.ApiGroupDeleteProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse)

Example 18 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiGroupService method updateSetting.

/**
 * 个人更新群设置信息
 *
 * @param command
 * @return
 */
public CommandResponse updateSetting(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupUpdateSettingProto.ApiGroupUpdateSettingRequest request = ApiGroupUpdateSettingProto.ApiGroupUpdateSettingRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String groupId = request.getGroupId();
        boolean isMute = request.getMessageMute();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNoneEmpty(siteUserId, groupId)) {
            UserGroupBean bean = new UserGroupBean();
            bean.setSiteGroupId(groupId);
            bean.setMute(isMute);
            if (UserGroupDao.getInstance().updateUserGroupSetting(siteUserId, bean)) {
                errCode = ErrorCode2.SUCCESS;
            } else {
                errCode = ErrorCode2.ERROR_DATABASE_EXECUTE;
            }
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) UserGroupBean(com.akaxin.site.storage.bean.UserGroupBean) CommandResponse(com.akaxin.common.command.CommandResponse) ApiGroupUpdateSettingProto(com.akaxin.proto.site.ApiGroupUpdateSettingProto)

Example 19 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiGroupService method deleteMember.

/**
 * 群主以及管理员删除群成员<br>
 * 群主/管理员权限限制
 *
 * @param command
 * @return
 */
public CommandResponse deleteMember(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupRemoveMemberProto.ApiGroupRemoveMemberRequest request = ApiGroupRemoveMemberProto.ApiGroupRemoveMemberRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String groupId = request.getGroupId();
        ProtocolStringList deleteMemberIds = request.getSiteUserIdList();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId) && StringUtils.isNoneBlank(groupId) && deleteMemberIds != null) {
            String groupMasterId = UserGroupDao.getInstance().getGroupMaster(groupId);
            if (siteUserId.equals(groupMasterId)) {
                if (UserGroupDao.getInstance().deleteGroupMember(groupId, deleteMemberIds)) {
                    errCode = ErrorCode2.SUCCESS;
                }
            } else {
                errCode = ErrorCode2.ERROR_NOPERMISSION;
            }
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiGroupRemoveMemberProto(com.akaxin.proto.site.ApiGroupRemoveMemberProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) ProtocolStringList(com.google.protobuf.ProtocolStringList)

Example 20 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiPluginService method page.

/**
 * <pre>
 * 获取插件扩展的展示页面,支持两种方式
 * 	1.非加密方式,此时扩展authkey不存在
 *  2.加密方式,此时扩展authkey存在
 * </pre>
 *
 * @param command
 * @return
 */
public CommandResponse page(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiPluginPageProto.ApiPluginPageRequest request = ApiPluginPageProto.ApiPluginPageRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String pluginId = request.getPluginId();
        // /index || index.php || index.html
        String requestPage = request.getPage();
        String requestParams = request.getParams();
        LogUtils.requestDebugLog(logger, command, request.toString());
        Map<Integer, String> header = command.getHeader();
        String siteSessionId = header.get(CoreProto.HeaderKey.CLIENT_SOCKET_SITE_SESSION_ID_VALUE);
        String pluginRefere = header.get(CoreProto.HeaderKey.PLUGIN_CLIENT_REFERER_VALUE);
        if (StringUtils.isNoneEmpty(siteUserId, pluginId)) {
            PluginBean bean = SitePluginDao.getInstance().getPluginProfile(Integer.valueOf(pluginId));
            if (bean != null && bean.getApiUrl() != null) {
                String pageUrl = buildUrl(bean.getApiUrl(), requestPage, bean.getUrlPage());
                logger.debug("http request uri={}", pageUrl);
                PluginProto.ProxyPluginPackage.Builder packageBuilder = PluginProto.ProxyPluginPackage.newBuilder();
                packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE, siteUserId);
                packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_SESSION_ID_VALUE, siteSessionId);
                packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_ID_VALUE, pluginId);
                packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_TIMESTAMP_VALUE, String.valueOf(System.currentTimeMillis()));
                if (StringUtils.isNotEmpty(pluginRefere)) {
                    packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_REFERER_VALUE, pluginRefere);
                }
                if (StringUtils.isNotEmpty(requestParams)) {
                    packageBuilder.setData(requestParams);
                }
                byte[] httpContent = packageBuilder.build().toByteArray();
                String authKey = bean.getAuthKey();
                if (StringUtils.isNotEmpty(authKey)) {
                    // AES 加密整个proto,通过http传输给plugin
                    byte[] tsk = bean.getAuthKey().getBytes(CharsetCoding.ISO_8859_1);
                    byte[] enPostContent = AESCrypto.encrypt(tsk, httpContent);
                    httpContent = enPostContent;
                }
                byte[] httpResponse = ZalyHttpClient.getInstance().postBytes(pageUrl, httpContent);
                ApiPluginProxyProto.ApiPluginProxyResponse response = ApiPluginProxyProto.ApiPluginProxyResponse.newBuilder().setData(ByteString.copyFrom(httpResponse)).build();
                // byte[] httpResponse = ZalyHttpClient.getInstance().get(pageUrl);
                // ApiPluginPageProto.ApiPluginPageResponse response =
                // ApiPluginPageProto.ApiPluginPageResponse
                // .newBuilder().setData(ByteString.copyFrom(httpResponse)).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 : CommandResponse(com.akaxin.common.command.CommandResponse) ByteString(com.google.protobuf.ByteString) ErrorCode2(com.akaxin.common.constant.ErrorCode2) ApiPluginProxyProto(com.akaxin.proto.site.ApiPluginProxyProto) ApiPluginPageProto(com.akaxin.proto.site.ApiPluginPageProto) PluginBean(com.akaxin.site.storage.bean.PluginBean)

Aggregations

CommandResponse (com.akaxin.common.command.CommandResponse)82 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)68 UserProto (com.akaxin.proto.core.UserProto)12 PluginBean (com.akaxin.site.storage.bean.PluginBean)7 ByteString (com.google.protobuf.ByteString)7 GroupProto (com.akaxin.proto.core.GroupProto)6 GroupProfileBean (com.akaxin.site.storage.bean.GroupProfileBean)6 SimpleUserBean (com.akaxin.site.storage.bean.SimpleUserBean)6 UserProfileBean (com.akaxin.site.storage.bean.UserProfileBean)6 UserDeviceBean (com.akaxin.site.storage.bean.UserDeviceBean)5 Command (com.akaxin.common.command.Command)4 DeviceProto (com.akaxin.proto.core.DeviceProto)4 ProtocolStringList (com.google.protobuf.ProtocolStringList)4 ConfigProto (com.akaxin.proto.core.ConfigProto)3 GroupMemberBean (com.akaxin.site.storage.bean.GroupMemberBean)3 UserGroupBean (com.akaxin.site.storage.bean.UserGroupBean)3 RedisCommand (com.akaxin.common.command.RedisCommand)2 ImStcPsnProto (com.akaxin.proto.client.ImStcPsnProto)2 CoreProto (com.akaxin.proto.core.CoreProto)2 FileProto (com.akaxin.proto.core.FileProto)2