Search in sources :

Example 1 with UserProfileBean

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

the class ApiFriendService method profile.

/**
 * 查询好友的个人资料
 *
 * @param command
 * @return
 */
public CommandResponse profile(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiFriendProfileProto.ApiFriendProfileRequest request = ApiFriendProfileProto.ApiFriendProfileRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        // 等待查询的站点用户ID || globalUserId
        String globalOrSiteFriendId = request.getSiteUserId();
        // 等待查询的用户公钥,优先级高
        String userIdPubk = request.getUserIdPubk();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isAllEmpty(userIdPubk, globalOrSiteFriendId)) {
            errCode = ErrorCode2.ERROR_PARAMETER;
            return commandResponse.setErrCode2(errCode);
        }
        UserProfileBean userBean = UserProfileDao.getInstance().getUserProfileById(globalOrSiteFriendId);
        if (null == userBean || StringUtils.isBlank(userBean.getSiteUserId())) {
            // 直接复用之前的接口了。
            userBean = UserProfileDao.getInstance().getUserProfileByGlobalUserId(globalOrSiteFriendId);
        }
        if (userBean != null && StringUtils.isNotBlank(userBean.getSiteUserId())) {
            UserProto.UserProfile userProfileProto = UserProto.UserProfile.newBuilder().setSiteUserId(String.valueOf(userBean.getSiteUserId())).setUserName(String.valueOf(userBean.getUserName())).setUserPhoto(String.valueOf(userBean.getUserPhoto())).setUserStatusValue(userBean.getUserStatus()).build();
            UserProto.UserRelation userRelation = UserFriendDao.getInstance().getUserRelation(siteUserId, userBean.getSiteUserId());
            ApiFriendProfileProto.ApiFriendProfileResponse response = ApiFriendProfileProto.ApiFriendProfileResponse.newBuilder().setProfile(userProfileProto).setRelation(userRelation).setUserIdPubk(userBean.getUserIdPubk()).build();
            commandResponse.setParams(response.toByteArray());
            errCode = ErrorCode2.SUCCESS;
        }
    } 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) ApiFriendProfileProto(com.akaxin.proto.site.ApiFriendProfileProto) UserProfileBean(com.akaxin.site.storage.bean.UserProfileBean)

Example 2 with UserProfileBean

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

the class ApiUserService method profile.

/**
 * 获取用户个人资料信息
 *
 * 支持使用globalUserid与siteUserId
 *
 * @param command
 * @return
 */
public CommandResponse profile(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errorCode = ErrorCode2.ERROR;
    try {
        ApiUserProfileProto.ApiUserProfileRequest request = ApiUserProfileProto.ApiUserProfileRequest.parseFrom(command.getParams());
        String currentUserId = command.getSiteUserId();
        String siteUserId = request.getSiteUserId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId) && siteUserId.equals(currentUserId)) {
            UserProfileBean userBean = UserProfileDao.getInstance().getUserProfileById(siteUserId);
            if (null == userBean) {
                // 直接复用之前的接口了。
                userBean = UserProfileDao.getInstance().getUserProfileByGlobalUserId(siteUserId);
            }
            if (userBean != null && StringUtils.isNotBlank(userBean.getSiteUserId())) {
                UserProto.UserProfile.Builder userProfileBuilder = UserProto.UserProfile.newBuilder();
                userProfileBuilder.setSiteUserId(userBean.getSiteUserId());
                if (userBean.getUserName() != null) {
                    userProfileBuilder.setUserName(userBean.getUserName());
                }
                if (userBean.getUserPhoto() != null) {
                    userProfileBuilder.setUserPhoto(userBean.getUserPhoto());
                }
                if (userBean.getSelfIntroduce() != null) {
                    userProfileBuilder.setSelfIntroduce(userBean.getSelfIntroduce());
                }
                userProfileBuilder.setUserStatusValue(userBean.getUserStatus());
                ApiUserProfileProto.ApiUserProfileResponse response = ApiUserProfileProto.ApiUserProfileResponse.newBuilder().setUserProfile(userProfileBuilder.build()).build();
                commandResponse.setParams(response.toByteArray());
                errorCode = ErrorCode2.SUCCESS;
            }
        } else {
            errorCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errorCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errorCode);
}
Also used : ApiUserProfileProto(com.akaxin.proto.site.ApiUserProfileProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) UserProfileBean(com.akaxin.site.storage.bean.UserProfileBean)

Example 3 with UserProfileBean

use of com.akaxin.site.storage.bean.UserProfileBean 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 4 with UserProfileBean

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

the class UserProfileDao method getUserProfileByGlobalUserId.

public UserProfileBean getUserProfileByGlobalUserId(String id) {
    UserProfileBean userBean = null;
    try {
        userBean = userProfileDao.getUserProfileByGlobalUserId(id);
        userBean.setGlobalUserId(id);
    } catch (SQLException e) {
        logger.error("get user profile by userId error.", e);
    }
    return userBean;
}
Also used : SQLException(java.sql.SQLException) UserProfileBean(com.akaxin.site.storage.bean.UserProfileBean)

Example 5 with UserProfileBean

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

the class SQLiteUserProfileDao method queryUserProfileByPubk.

public UserProfileBean queryUserProfileByPubk(String userIdPubk) throws SQLException {
    long startTime = System.currentTimeMillis();
    String sql = "SELECT site_user_id,user_id_pubk,user_name,user_photo,user_status,self_introduce,register_time FROM " + USER_PROFILE_TABLE + " WHERE user_id_pubk=?;";
    PreparedStatement preStatement = SQLiteJDBCManager.getConnection().prepareStatement(sql);
    preStatement.setString(1, userIdPubk);
    ResultSet rs = preStatement.executeQuery();
    UserProfileBean userBean = null;
    if (rs.next()) {
        userBean = new UserProfileBean();
        userBean.setSiteUserId(rs.getString(1));
        userBean.setUserIdPubk(rs.getString(2));
        userBean.setUserName(rs.getString(3));
        userBean.setUserPhoto(rs.getString(4));
        userBean.setUserStatus(rs.getInt(5));
        userBean.setSelfIntroduce(rs.getString(6));
        userBean.setRegisterTime(rs.getLong(7));
    }
    LogUtils.dbDebugLog(logger, startTime, userBean, sql, userIdPubk);
    return userBean;
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) UserProfileBean(com.akaxin.site.storage.bean.UserProfileBean)

Aggregations

UserProfileBean (com.akaxin.site.storage.bean.UserProfileBean)10 CommandResponse (com.akaxin.common.command.CommandResponse)6 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)6 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 UserProto (com.akaxin.proto.core.UserProto)2 ConfigProto (com.akaxin.proto.core.ConfigProto)1 HaiUserProfileProto (com.akaxin.proto.plugin.HaiUserProfileProto)1 HaiUserUpdateProto (com.akaxin.proto.plugin.HaiUserUpdateProto)1 ApiFriendProfileProto (com.akaxin.proto.site.ApiFriendProfileProto)1 ApiSiteConfigProto (com.akaxin.proto.site.ApiSiteConfigProto)1 ApiSiteRegisterProto (com.akaxin.proto.site.ApiSiteRegisterProto)1 ApiUserProfileProto (com.akaxin.proto.site.ApiUserProfileProto)1 ApiUserUpdateProfileProto (com.akaxin.proto.site.ApiUserUpdateProfileProto)1 SQLException (java.sql.SQLException)1