Search in sources :

Example 31 with CommandResponse

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

the class HttpUserService method relationList.

/**
 * 分页获取用户列表,同时附带与当前用户之间关系
 *
 * @param command
 * @return
 */
public CommandResponse relationList(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errorCode = ErrorCode2.ERROR;
    try {
        HaiUserRelationListProto.HaiUserRelationListRequest request = HaiUserRelationListProto.HaiUserRelationListRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        int pageNum = request.getPageNumber();
        int pageSize = request.getPageSize();
        LogUtils.requestDebugLog(logger, command, request.toString());
        List<SimpleUserRelationBean> pageList = UserProfileDao.getInstance().getUserRelationPageList(siteUserId, pageNum, pageSize);
        if (pageList != null) {
            HaiUserRelationListProto.HaiUserRelationListResponse.Builder responseBuilder = HaiUserRelationListProto.HaiUserRelationListResponse.newBuilder();
            for (SimpleUserRelationBean bean : pageList) {
                UserProto.UserRelationProfile.Builder userProfileBuilder = UserProto.UserRelationProfile.newBuilder();
                UserProto.SimpleUserProfile.Builder supBuilder = UserProto.SimpleUserProfile.newBuilder();
                supBuilder.setSiteUserId(bean.getUserId());
                if (StringUtils.isNotBlank(bean.getUserId())) {
                    supBuilder.setUserName(String.valueOf(bean.getUserName()));
                }
                if (StringUtils.isNotBlank(bean.getUserPhoto())) {
                    supBuilder.setUserPhoto(bean.getUserPhoto());
                }
                supBuilder.setUserStatusValue(bean.getUserStatus());
                userProfileBuilder.setProfile(supBuilder);
                userProfileBuilder.setRelationValue(bean.getRelation());
                responseBuilder.addUserProfile(userProfileBuilder.build());
            }
            commandResponse.setParams(responseBuilder.build().toByteArray());
            errorCode = ErrorCode2.SUCCESS;
        }
    } catch (Exception e) {
        errorCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errorCode);
}
Also used : SimpleUserRelationBean(com.akaxin.site.storage.bean.SimpleUserRelationBean) CommandResponse(com.akaxin.common.command.CommandResponse) ErrorCode2(com.akaxin.common.constant.ErrorCode2) HaiUserRelationListProto(com.akaxin.proto.plugin.HaiUserRelationListProto)

Example 32 with CommandResponse

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

the class HttpUserService method update.

/**
 * 更新用户信息
 *
 * @param command
 * @return
 */
public CommandResponse update(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        HaiUserUpdateProto.HaiUserUpdateRequest request = HaiUserUpdateProto.HaiUserUpdateRequest.parseFrom(command.getParams());
        String siteUserId = request.getUserProfile().getSiteUserId();
        String userName = request.getUserProfile().getUserName();
        String userPhoto = request.getUserProfile().getUserPhoto();
        String userIntro = request.getUserProfile().getSelfIntroduce();
        LogUtils.requestDebugLog(logger, command, request.toString());
        // 过滤参数
        if (StringUtils.isNoneBlank(siteUserId)) {
            UserProfileBean bean = new UserProfileBean();
            bean.setSiteUserId(siteUserId);
            bean.setUserName(userName);
            bean.setUserPhoto(userPhoto);
            bean.setSelfIntroduce(userIntro);
            if (UserProfileDao.getInstance().updateUserProfile(bean)) {
                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 : ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) HaiUserUpdateProto(com.akaxin.proto.plugin.HaiUserUpdateProto) UserProfileBean(com.akaxin.site.storage.bean.UserProfileBean)

Example 33 with CommandResponse

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

the class HttpUserService method sealUp.

/**
 * <pre>
 * 		禁封/解禁 用户身份
 * </pre>
 *
 * @param command
 * @return
 */
public CommandResponse sealUp(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        HaiUserSealUpProto.HaiUserSealUpRequest request = HaiUserSealUpProto.HaiUserSealUpRequest.parseFrom(command.getParams());
        String siteUserId = request.getSiteUserId();
        UserProto.UserStatus userStatus = request.getStatus();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId)) {
            if (UserProfileDao.getInstance().updateUserStatus(siteUserId, userStatus.getNumber())) {
                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 : ErrorCode2(com.akaxin.common.constant.ErrorCode2) UserProto(com.akaxin.proto.core.UserProto) CommandResponse(com.akaxin.common.command.CommandResponse) HaiUserSealUpProto(com.akaxin.proto.plugin.HaiUserSealUpProto)

Example 34 with CommandResponse

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

the class User2Notice method applyFriendNotice.

/**
 * A用户添加用户B为好友,发送B有好友添加的申请 <br>
 *
 * 客户端接收到此通知,会在通讯录的好友申请提示
 *
 * @param siteUserId
 *            用户B的用户ID
 */
public void applyFriendNotice(String siteUserId) {
    List<String> deviceList = UserSessionDao.getInstance().getSessionDevices(siteUserId);
    for (String deviceId : deviceList) {
        CommandResponse commandResponse = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION).setAction(CommandConst.IM_NOTICE);
        ImStcNoticeProto.ImStcNoticeRequest noticeRequest = ImStcNoticeProto.ImStcNoticeRequest.newBuilder().setType(ImStcNoticeProto.NoticeType.APPLY_FRIEND).build();
        commandResponse.setParams(noticeRequest.toByteArray());
        commandResponse.setErrCode(ErrorCode.SUCCESS);
        ChannelWriter.writeByDeviceId(deviceId, commandResponse);
        logger.debug("apply friend notice. to siteUserId={} deviceId={}", siteUserId, deviceId);
    }
}
Also used : ImStcNoticeProto(com.akaxin.proto.client.ImStcNoticeProto) ByteString(com.google.protobuf.ByteString) CommandResponse(com.akaxin.common.command.CommandResponse)

Example 35 with CommandResponse

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

the class AbstractRequest method executeMethodByReflect.

private CommandResponse executeMethodByReflect(Command command) {
    CommandResponse response = null;
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        String methodName = command.getMethod();
        Method m = this.getClass().getDeclaredMethod(methodName, command.getClass());
        response = (CommandResponse) m.invoke(this, command);
    } catch (Exception e) {
        LogUtils.requestErrorLog(logger, command, e);
    }
    if (response == null) {
        response = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION).setAction(CommandConst.ACTION_RES).setErrCode2(errCode);
    }
    return response;
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) Method(java.lang.reflect.Method)

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