server api添加通过邮箱获取用户列表的接口
This commit is contained in:
+66
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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.InputGetUserInfo;
|
||||||
|
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
||||||
|
import cn.wildfirechat.pojos.OutputUserInfoList;
|
||||||
|
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.util.internal.StringUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Route(APIPath.User_Get_Email_Info)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class GetUsersByEmailAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
String email = getRequestBody(request.getNettyRequest(), String.class);
|
||||||
|
if (!StringUtil.isNullOrEmpty(email)) {
|
||||||
|
|
||||||
|
List<WFCMessage.User> users = messagesStore.getUserInfosByEmail(email);
|
||||||
|
List<InputOutputUserInfo> list = new ArrayList<>();
|
||||||
|
for (WFCMessage.User user : users) {
|
||||||
|
list.add(InputOutputUserInfo.fromPbUser(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
RestResult result;
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_EXIST);
|
||||||
|
} else {
|
||||||
|
OutputUserInfoList outputUserInfoList = new OutputUserInfoList();
|
||||||
|
outputUserInfoList.userInfos = list;
|
||||||
|
result = RestResult.ok(outputUserInfoList);
|
||||||
|
}
|
||||||
|
|
||||||
|
setResponseContent(result, response);
|
||||||
|
} else {
|
||||||
|
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2917,6 +2917,99 @@ public class DatabaseStore {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<WFCMessage.User> getUserInfosByEmail(String email) {
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<WFCMessage.User> outList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
connection = DBUtil.getConnection();
|
||||||
|
String sql = "select `_uid`, `_name`" +
|
||||||
|
", `_display_name`" +
|
||||||
|
", `_portrait`" +
|
||||||
|
", `_mobile`" +
|
||||||
|
", `_gender`" +
|
||||||
|
", `_email`" +
|
||||||
|
", `_address`" +
|
||||||
|
", `_company`" +
|
||||||
|
", `_social`" +
|
||||||
|
", `_extra`" +
|
||||||
|
", `_type`" +
|
||||||
|
", `_deleted`" +
|
||||||
|
", `_dt` from t_user where `_deleted` = 0 and `_email` = ?";
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
statement.setString(1, email);
|
||||||
|
|
||||||
|
rs = statement.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
WFCMessage.User.Builder builder = WFCMessage.User.newBuilder();
|
||||||
|
int index = 1;
|
||||||
|
String value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setUid(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setName(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setDisplayName(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setPortrait(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setMobile(value);
|
||||||
|
|
||||||
|
int gender = rs.getInt(index++);
|
||||||
|
builder.setGender(gender);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setEmail(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setAddress(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setCompany(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setSocial(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setExtra(value);
|
||||||
|
|
||||||
|
int type = rs.getInt(index++);
|
||||||
|
builder.setType(type);
|
||||||
|
|
||||||
|
int deleted = rs.getInt(index++);
|
||||||
|
builder.setDeleted(deleted);
|
||||||
|
|
||||||
|
long longValue = rs.getLong(index++);
|
||||||
|
if(longValue <= 0)
|
||||||
|
longValue = 1;
|
||||||
|
builder.setUpdateDt(longValue);
|
||||||
|
|
||||||
|
outList.add(builder.build());
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
Utility.printExecption(LOG, e, RDBS_Exception);
|
||||||
|
} finally {
|
||||||
|
DBUtil.closeDB(connection, statement, rs);
|
||||||
|
}
|
||||||
|
return outList;
|
||||||
|
}
|
||||||
|
|
||||||
List<WFCMessage.User> getAllUsers(int count, int offset) {
|
List<WFCMessage.User> getAllUsers(int count, int offset) {
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
|
|||||||
@@ -2986,6 +2986,11 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
return getUserInfo(userId);
|
return getUserInfo(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<WFCMessage.User> getUserInfosByEmail(String email) {
|
||||||
|
return databaseStore.getUserInfosByEmail(email);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WFCMessage.User> getUserInfoList(int count, int offset) {
|
public List<WFCMessage.User> getUserInfoList(int count, int offset) {
|
||||||
return databaseStore.getAllUsers(count, offset);
|
return databaseStore.getAllUsers(count, offset);
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ public interface IMessagesStore {
|
|||||||
WFCMessage.User getUserInfo(String userId);
|
WFCMessage.User getUserInfo(String userId);
|
||||||
WFCMessage.User getUserInfoByName(String name);
|
WFCMessage.User getUserInfoByName(String name);
|
||||||
WFCMessage.User getUserInfoByMobile(String mobile);
|
WFCMessage.User getUserInfoByMobile(String mobile);
|
||||||
|
List<WFCMessage.User> getUserInfosByEmail(String email);
|
||||||
List<WFCMessage.User> searchUser(String keyword, int searchType, int page);
|
List<WFCMessage.User> searchUser(String keyword, int searchType, int page);
|
||||||
|
|
||||||
List<WFCMessage.User> getUserInfoList(int count, int offset);
|
List<WFCMessage.User> getUserInfoList(int count, int offset);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public interface APIPath {
|
|||||||
String User_Get_Token = "/admin/user/get_token";
|
String User_Get_Token = "/admin/user/get_token";
|
||||||
String User_Update_Block_Status = "/admin/user/update_block_status";
|
String User_Update_Block_Status = "/admin/user/update_block_status";
|
||||||
String User_Get_Info = "/admin/user/get_info";
|
String User_Get_Info = "/admin/user/get_info";
|
||||||
|
String User_Get_Email_Info = "/admin/user/get_info_by_email";
|
||||||
String User_Get_All = "/admin/user/all";
|
String User_Get_All = "/admin/user/all";
|
||||||
String User_Get_Robot_Info = "/admin/user/get_robot_info";
|
String User_Get_Robot_Info = "/admin/user/get_robot_info";
|
||||||
String User_Get_Blocked_List = "/admin/user/get_blocked_list";
|
String User_Get_Blocked_List = "/admin/user/get_blocked_list";
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cn.wildfirechat.pojos;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class OutputUserInfoList {
|
||||||
|
public List<InputOutputUserInfo> userInfos;
|
||||||
|
}
|
||||||
@@ -178,6 +178,15 @@ public class Main {
|
|||||||
System.out.println("get user info by userId failure");
|
System.out.println("get user info by userId failure");
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMResult<OutputUserInfoList> userInfoListIMResult = UserAdmin.getUserByEmail("[email protected]");
|
||||||
|
if(userInfoListIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS || userInfoListIMResult.getErrorCode() == ErrorCode.ERROR_CODE_NOT_EXIST) {
|
||||||
|
System.out.println("getUserByEmail success");
|
||||||
|
} else {
|
||||||
|
System.out.println("getUserByEmail 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");
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ public class UserAdmin {
|
|||||||
return AdminHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
return AdminHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IMResult<OutputUserInfoList> getUserByEmail(String email) throws Exception {
|
||||||
|
String path = APIPath.User_Get_Email_Info;
|
||||||
|
return AdminHttpUtils.httpJsonPost(path, email, OutputUserInfoList.class);
|
||||||
|
}
|
||||||
|
|
||||||
public static IMResult<OutputGetUserList> getAllUsers(int count, int offset) throws Exception {
|
public static IMResult<OutputGetUserList> getAllUsers(int count, int offset) throws Exception {
|
||||||
String path = APIPath.User_Get_All;
|
String path = APIPath.User_Get_All;
|
||||||
InputGetUserList input = new InputGetUserList();
|
InputGetUserList input = new InputGetUserList();
|
||||||
|
|||||||
Reference in New Issue
Block a user