添加批量获取用户信息的接口
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <[email protected]>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.xiaoleilu.loServer.action.admin;
|
||||||
|
|
||||||
|
import cn.wildfirechat.common.APIPath;
|
||||||
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
|
import cn.wildfirechat.pojos.*;
|
||||||
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
|
import com.xiaoleilu.loServer.RestResult;
|
||||||
|
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||||
|
import com.xiaoleilu.loServer.annotation.Route;
|
||||||
|
import com.xiaoleilu.loServer.handler.Request;
|
||||||
|
import com.xiaoleilu.loServer.handler.Response;
|
||||||
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Route(APIPath.User_Batch_Get_Infos)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class GetBatchUserAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
InputStringList inputUserId = getRequestBody(request.getNettyRequest(), InputStringList.class);
|
||||||
|
if (inputUserId != null && inputUserId.getList() != null && !inputUserId.getList().isEmpty()) {
|
||||||
|
|
||||||
|
OutputUserInfoList res = new OutputUserInfoList();
|
||||||
|
res.userInfos = new ArrayList<>();
|
||||||
|
for (String userId : inputUserId.getList()) {
|
||||||
|
WFCMessage.User user = messagesStore.getUserInfo(userId);
|
||||||
|
if(user == null || StringUtil.isNullOrEmpty(user.getName())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
InputOutputUserInfo inputOutputUserInfo = InputOutputUserInfo.fromPbUser(user);
|
||||||
|
res.userInfos.add(inputOutputUserInfo);
|
||||||
|
}
|
||||||
|
RestResult result = RestResult.ok(res);
|
||||||
|
setResponseContent(result, response);
|
||||||
|
} else {
|
||||||
|
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package cn.wildfirechat.pojos;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class InputStringList {
|
||||||
|
private List<String> list;
|
||||||
|
|
||||||
|
public InputStringList() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStringList(List<String> list) {
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getList() {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setList(List<String> list) {
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -193,6 +193,14 @@ public class Main {
|
|||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMResult<OutputUserInfoList> batchGetUsers = UserAdmin.getBatchUsers(Arrays.asList("userId1", "admin", "FireRobot", "TestUser"));
|
||||||
|
if (batchGetUsers.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
System.out.println("get batch user success");
|
||||||
|
} else {
|
||||||
|
System.out.println("get batch user failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
InputOutputUserInfo updateUserInfo = new InputOutputUserInfo();
|
InputOutputUserInfo updateUserInfo = new InputOutputUserInfo();
|
||||||
updateUserInfo.setUserId(System.currentTimeMillis()+"");
|
updateUserInfo.setUserId(System.currentTimeMillis()+"");
|
||||||
updateUserInfo.setDisplayName("updatedUserName");
|
updateUserInfo.setDisplayName("updatedUserName");
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import cn.wildfirechat.pojos.*;
|
|||||||
import cn.wildfirechat.sdk.model.IMResult;
|
import cn.wildfirechat.sdk.model.IMResult;
|
||||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class UserAdmin {
|
public class UserAdmin {
|
||||||
public static IMResult<InputOutputUserInfo> getUserByName(String name) throws Exception {
|
public static IMResult<InputOutputUserInfo> getUserByName(String name) throws Exception {
|
||||||
String path = APIPath.User_Get_Info;
|
String path = APIPath.User_Get_Info;
|
||||||
@@ -37,6 +39,13 @@ public class UserAdmin {
|
|||||||
return AdminHttpUtils.httpJsonPost(path, input, OutputGetUserList.class);
|
return AdminHttpUtils.httpJsonPost(path, input, OutputGetUserList.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IMResult<OutputUserInfoList> getBatchUsers(List<String> userIds) throws Exception {
|
||||||
|
String path = APIPath.User_Batch_Get_Infos;
|
||||||
|
InputStringList input = new InputStringList();
|
||||||
|
input.setList(userIds);
|
||||||
|
return AdminHttpUtils.httpJsonPost(path, input, OutputUserInfoList.class);
|
||||||
|
}
|
||||||
|
|
||||||
public static IMResult<OutputCreateUser> createUser(InputOutputUserInfo user) throws Exception {
|
public static IMResult<OutputCreateUser> createUser(InputOutputUserInfo user) throws Exception {
|
||||||
String path = APIPath.Create_User;
|
String path = APIPath.Create_User;
|
||||||
return AdminHttpUtils.httpJsonPost(path, user, OutputCreateUser.class);
|
return AdminHttpUtils.httpJsonPost(path, user, OutputCreateUser.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user