Search in sources :

Example 1 with SimpleUserRelationBean

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

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

the class SQLiteUserProfileDao method queryUserRelationPageList.

/**
 * 分页获取用户列表,这个列表包含用户与查询的用户之前的关系
 *
 * @param siteUserId
 * @param pageNum
 * @param pageSize
 * @return
 * @throws SQLException
 */
public List<SimpleUserRelationBean> queryUserRelationPageList(String siteUserId, int pageNum, int pageSize) throws SQLException {
    long startTime = System.currentTimeMillis();
    List<SimpleUserRelationBean> userPageList = new ArrayList<SimpleUserRelationBean>();
    String sql = "SELECT a.site_user_id,a.user_name,a.user_photo,a.user_status,b.site_friend_id from " + USER_PROFILE_TABLE + " AS a LEFT JOIN (SELECT site_user_id,site_friend_id FROM " + SQLConst.SITE_USER_FRIEND + " WHERE site_user_id=?) AS b ON a.site_user_id=b.site_friend_id ORDER BY a.id DESC LIMIT ?,?;";
    int startNum = (pageNum - 1) * pageSize;
    PreparedStatement preStatement = SQLiteJDBCManager.getConnection().prepareStatement(sql);
    preStatement.setString(1, siteUserId);
    preStatement.setInt(2, startNum);
    preStatement.setInt(3, pageSize);
    ResultSet rs = preStatement.executeQuery();
    while (rs.next()) {
        SimpleUserRelationBean bean = new SimpleUserRelationBean();
        bean.setUserId(rs.getString(1));
        bean.setUserName(rs.getString(2));
        bean.setUserPhoto(rs.getString(3));
        bean.setUserStatus(rs.getInt(4));
        if (StringUtils.isNotBlank(rs.getString(5))) {
            bean.setRelation(UserProto.UserRelation.RELATION_FRIEND_VALUE);
        } else {
            bean.setRelation(UserProto.UserRelation.RELATION_NONE_VALUE);
        }
        userPageList.add(bean);
    }
    LogUtils.dbDebugLog(logger, startTime, userPageList.size(), sql, startNum, pageSize);
    return userPageList;
}
Also used : SimpleUserRelationBean(com.akaxin.site.storage.bean.SimpleUserRelationBean) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

SimpleUserRelationBean (com.akaxin.site.storage.bean.SimpleUserRelationBean)2 CommandResponse (com.akaxin.common.command.CommandResponse)1 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)1 HaiUserRelationListProto (com.akaxin.proto.plugin.HaiUserRelationListProto)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1