com.akaxin.proto.core.UserProto Java Examples

The following examples show how to use com.akaxin.proto.core.UserProto. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserFriendDao.java    From wind-im with Apache License 2.0 6 votes vote down vote up
public UserProto.UserRelation getUserRelation(String siteUserId, String siteFriendId) {
	int relation = 0;
	try {
		relation = userFriendDao.queryRelation(siteUserId, siteFriendId);
		if (relation == RELATION_NUMBERo) {
			relation = userFriendDao.queryRelation(siteFriendId, siteUserId);
			if (relation == RELATION_NUMBERo) {
				return UserProto.UserRelation.RELATION_FRIEND;
			}
			return UserProto.UserRelation.RELATION_CARE;
		} else {
			relation = userFriendDao.queryRelation(siteFriendId, siteUserId);
			if (relation == RELATION_NUMBERo) {
				return UserProto.UserRelation.RELATION_FANS;
			}
		}
	} catch (SQLException e) {
		logger.error("get user relation error.siteUserId={} siteFriendId={}", e);
	}
	return UserProto.UserRelation.RELATION_NONE;
}
 
Example #2
Source File: UserFriendDao.java    From openzaly with Apache License 2.0 6 votes vote down vote up
public UserProto.UserRelation getUserRelation(String siteUserId, String siteFriendId) {
	int relation = 0;
	try {
		relation = userFriendDao.queryRelation(siteUserId, siteFriendId);
		if (relation == RELATION_NUMBERo) {
			relation = userFriendDao.queryRelation(siteFriendId, siteUserId);
			if (relation == RELATION_NUMBERo) {
				return UserProto.UserRelation.RELATION_FRIEND;
			}
			return UserProto.UserRelation.RELATION_CARE;
		} else {
			relation = userFriendDao.queryRelation(siteFriendId, siteUserId);
			if (relation == RELATION_NUMBERo) {
				return UserProto.UserRelation.RELATION_FANS;
			}
		}
	} catch (SQLException e) {
		logger.error("get user relation error.siteUserId={} siteFriendId={}", e);
	}
	return UserProto.UserRelation.RELATION_NONE;
}
 
Example #3
Source File: UserFriendDao.java    From openzaly with Apache License 2.0 6 votes vote down vote up
public UserProto.UserRelation getUserRelation(String siteUserId, String siteFriendId) {
	int relation = 0;
	try {
		relation = userFriendDao.queryRelation(siteUserId, siteFriendId);
		if (relation == RELATION_NUMBERo) {
			relation = userFriendDao.queryRelation(siteFriendId, siteUserId);
			if (relation == RELATION_NUMBERo) {
				return UserProto.UserRelation.RELATION_FRIEND;
			}
			return UserProto.UserRelation.RELATION_CARE;
		} else {
			relation = userFriendDao.queryRelation(siteFriendId, siteUserId);
			if (relation == RELATION_NUMBERo) {
				return UserProto.UserRelation.RELATION_FANS;
			}
		}
	} catch (SQLException e) {
		logger.error("get user relation error.siteUserId={} siteFriendId={}", e);
	}
	return UserProto.UserRelation.RELATION_NONE;
}
 
Example #4
Source File: UserDetectionHandler.java    From wind-im with Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * 检测消息是否可以发送:
 * 		1.消息发送者是否为正常用户
 * 		2.消息接受者是否为正常用户
 * 		3.二者是否为好友关系
 * </pre>
 * 
 * @param siteUserId
 * @param siteFriendId
 * @return
 */
private boolean checkUser(String siteUserId, String siteFriendId, boolean isMaster) {
	try {
		// 检测发送者的状态
		SimpleUserBean userBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteUserId, isMaster);
		if (userBean != null) {
			if (userBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测接受者的状态
		SimpleUserBean friendBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteFriendId, isMaster);
		if (friendBean != null) {
			if (friendBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测是否为好友关系
		if (!ImUserFriendDao.getInstance().isFriend(siteUserId, siteFriendId, isMaster)) {
			return false;
		}
		return true;
	} catch (Exception e) {
		logger.error(StringHelper.format("check siteUserid={} siteFriendId={} error.", siteUserId, siteFriendId),
				e);
	}
	return false;
}
 
Example #5
Source File: GroupDetectionHandler.java    From openzaly with Apache License 2.0 5 votes vote down vote up
private boolean checkUser(String siteUserId) {
	// 检测发送者的状态
	SimpleUserBean userBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteUserId);
	if (userBean != null) {
		if (userBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
			return false;
		}
	} else {
		return false;
	}

	return true;
}
 
Example #6
Source File: UserDetectionHandler.java    From openzaly with Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * 检测消息是否可以发送:
 * 		1.消息发送者是否为正常用户
 * 		2.消息接受者是否为正常用户
 * 		3.二者是否为好友关系
 * </pre>
 * 
 * @param siteUserId
 * @param siteFriendId
 * @return
 */
private boolean checkUser(String siteUserId, String siteFriendId, boolean isMaster) {
	try {
		// 检测发送者的状态
		SimpleUserBean userBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteUserId, isMaster);
		if (userBean != null) {
			if (userBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测接受者的状态
		SimpleUserBean friendBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteFriendId, isMaster);
		if (friendBean != null) {
			if (friendBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测是否为好友关系
		if (!ImUserFriendDao.getInstance().isFriend(siteUserId, siteFriendId, isMaster)) {
			return false;
		}
		return true;
	} catch (Exception e) {
		logger.error(StringHelper.format("check siteUserid={} siteFriendId={} error.", siteUserId, siteFriendId),
				e);
	}
	return false;
}
 
Example #7
Source File: WebChatSendMessageHandler.java    From openzaly with Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * 检测消息是否可以发送:
 * 		1.消息发送者是否为正常用户
 * 		2.消息接受者是否为正常用户
 * 		3.二者是否为好友关系
 * </pre>
 * 
 * @param siteUserId
 * @param siteFriendId
 * @return
 */
private boolean checkUser(String siteUserId, String siteFriendId) {
	try {
		// 检测发送者的状态
		SimpleUserBean userBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteUserId);
		if (userBean != null) {
			if (userBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测接受者的状态
		SimpleUserBean friendBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteFriendId);
		if (friendBean != null) {
			if (friendBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测是否为好友关系
		if (!ImUserFriendDao.getInstance().isFriend(siteUserId, siteFriendId)) {
			return false;
		}
		return true;
	} catch (Exception e) {
		logger.error(StringHelper.format("check siteUserid={} siteFriendId={} error.", siteUserId, siteFriendId),
				e);
	}
	return false;
}
 
Example #8
Source File: ApiFriendService.java    From openzaly with Apache License 2.0 5 votes vote down vote up
/**
 * 获取用户的好友申请列表
 * 
 * @param command
 * @return
 */
public CommandResponse applyList(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		String siteUserId = command.getSiteUserId();
		LogUtils.requestDebugLog(logger, command, "");

		if (StringUtils.isNotBlank(siteUserId)) {
			List<ApplyUserBean> applyUserList = UserFriendDao.getInstance().getApplyUserList(siteUserId);
			ApiFriendApplyListProto.ApiFriendApplyListResponse.Builder responseBuilder = ApiFriendApplyListProto.ApiFriendApplyListResponse
					.newBuilder();
			for (ApplyUserBean applyUser : applyUserList) {
				if (StringUtils.isNotEmpty(applyUser.getUserId())) {
					UserProto.UserProfile.Builder userProfileBuilder = UserProto.UserProfile.newBuilder();
					userProfileBuilder.setSiteUserId(applyUser.getUserId());
					userProfileBuilder.setUserName(String.valueOf(applyUser.getUserName()));
					userProfileBuilder.setUserPhoto(String.valueOf(applyUser.getUserPhoto()));
					UserProto.ApplyUserProfile applyUserProfile = UserProto.ApplyUserProfile.newBuilder()
							.setApplyUser(userProfileBuilder.build())
							.setApplyReason(String.valueOf(applyUser.getApplyReason())).build();
					responseBuilder.addList(applyUserProfile);
				}
			}
			commandResponse.setParams(responseBuilder.build().toByteArray());
			errCode = ErrorCode2.SUCCESS;
		}
	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example #9
Source File: UserSquareController.java    From openzaly with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST, value = "/pullMemberList")
@ResponseBody
public Map<String, Object> getMemberList(HttpServletRequest request, @RequestBody byte[] bodyParam) {
	Map<String, Object> results = new HashMap<String, Object>();
	boolean nodata = true;
	try {
		PluginProto.ProxyPluginPackage pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);

		Map<String, String> ReqMap = GsonUtils.fromJson(pluginPackage.getData(), Map.class);

		int pageNum = Integer.valueOf(ReqMap.get("page"));
		List<SimpleUserBean> userList = userService.getUserList(pageNum, 20);
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		if (userList != null && userList.size() > 0) {
			if (20 == userList.size()) {
				nodata = false;
			}
			for (SimpleUserBean bean : userList) {
				Map<String, String> memberMap = new HashMap<String, String>();
				if (siteUserId != bean.getUserId()) {
					memberMap.put("site_user_id", bean.getUserId());
					memberMap.put("site_user_name", bean.getUserName());
					UserProto.UserRelation userRelation = UserFriendDao.getInstance().getUserRelation(siteUserId,
							bean.getUserId());
					memberMap.put("site_user_relation", String.valueOf(userRelation.getNumber()));
				}
				data.add(memberMap);
			}
		}
		results.put("Data", data);

	} catch (Exception e) {
		logger.error("get Member list error", e);
	}
	results.put("loading", nodata);
	return results;
}
 
Example #10
Source File: GroupDetectionHandler.java    From openzaly with Apache License 2.0 5 votes vote down vote up
private boolean checkUser(String siteUserId) {
	// 检测发送者的状态
	SimpleUserBean userBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteUserId);
	if (userBean != null) {
		if (userBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
			return false;
		}
	} else {
		return false;
	}

	return true;
}
 
Example #11
Source File: UserDetectionHandler.java    From openzaly with Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * 检测消息是否可以发送:
 * 		1.消息发送者是否为正常用户
 * 		2.消息接受者是否为正常用户
 * 		3.二者是否为好友关系
 * </pre>
 * 
 * @param siteUserId
 * @param siteFriendId
 * @return
 */
private boolean checkUser(String siteUserId, String siteFriendId, boolean isMaster) {
	try {
		// 检测发送者的状态
		SimpleUserBean userBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteUserId, isMaster);
		if (userBean != null) {
			if (userBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测接受者的状态
		SimpleUserBean friendBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteFriendId, isMaster);
		if (friendBean != null) {
			if (friendBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测是否为好友关系
		if (!ImUserFriendDao.getInstance().isFriend(siteUserId, siteFriendId, isMaster)) {
			return false;
		}
		return true;
	} catch (Exception e) {
		logger.error(StringHelper.format("check siteUserid={} siteFriendId={} error.", siteUserId, siteFriendId),
				e);
	}
	return false;
}
 
Example #12
Source File: WebChatSendMessageHandler.java    From openzaly with Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * 检测消息是否可以发送:
 * 		1.消息发送者是否为正常用户
 * 		2.消息接受者是否为正常用户
 * 		3.二者是否为好友关系
 * </pre>
 * 
 * @param siteUserId
 * @param siteFriendId
 * @return
 */
private boolean checkUser(String siteUserId, String siteFriendId) {
	try {
		// 检测发送者的状态
		SimpleUserBean userBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteUserId);
		if (userBean != null) {
			if (userBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测接受者的状态
		SimpleUserBean friendBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteFriendId);
		if (friendBean != null) {
			if (friendBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测是否为好友关系
		if (!ImUserFriendDao.getInstance().isFriend(siteUserId, siteFriendId)) {
			return false;
		}
		return true;
	} catch (Exception e) {
		logger.error(StringHelper.format("check siteUserid={} siteFriendId={} error.", siteUserId, siteFriendId),
				e);
	}
	return false;
}
 
Example #13
Source File: ApiFriendService.java    From openzaly with Apache License 2.0 5 votes vote down vote up
/**
 * 获取用户的好友申请列表
 * 
 * @param command
 * @return
 */
public CommandResponse applyList(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		String siteUserId = command.getSiteUserId();
		LogUtils.requestDebugLog(logger, command, "");

		if (StringUtils.isNotBlank(siteUserId)) {
			List<ApplyUserBean> applyUserList = UserFriendDao.getInstance().getApplyUserList(siteUserId);
			ApiFriendApplyListProto.ApiFriendApplyListResponse.Builder responseBuilder = ApiFriendApplyListProto.ApiFriendApplyListResponse
					.newBuilder();
			for (ApplyUserBean applyUser : applyUserList) {
				if (StringUtils.isNotEmpty(applyUser.getUserId())) {
					UserProto.UserProfile.Builder userProfileBuilder = UserProto.UserProfile.newBuilder();
					userProfileBuilder.setSiteUserId(applyUser.getUserId());
					userProfileBuilder.setUserName(String.valueOf(applyUser.getUserName()));
					userProfileBuilder.setUserPhoto(String.valueOf(applyUser.getUserPhoto()));
					UserProto.ApplyUserProfile applyUserProfile = UserProto.ApplyUserProfile.newBuilder()
							.setApplyUser(userProfileBuilder.build())
							.setApplyReason(String.valueOf(applyUser.getApplyReason())).build();
					responseBuilder.addList(applyUserProfile);
				}
			}
			commandResponse.setParams(responseBuilder.build().toByteArray());
			errCode = ErrorCode2.SUCCESS;
		}
	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example #14
Source File: UserSquareController.java    From openzaly with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST, value = "/pullMemberList")
@ResponseBody
public Map<String, Object> getMemberList(HttpServletRequest request, @RequestBody byte[] bodyParam) {
	Map<String, Object> results = new HashMap<String, Object>();
	boolean nodata = true;
	int pageSize = 20;
	try {
		PluginProto.ProxyPluginPackage pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);

		Map<String, String> ReqMap = GsonUtils.fromJson(pluginPackage.getData(), Map.class);

		int pageNum = Integer.valueOf(ReqMap.get("pageNum"));
		List<SimpleUserBean> userList = userService.getUserList(pageNum, pageSize);
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		if (userList != null && userList.size() > 0) {
			nodata = false;
			for (SimpleUserBean bean : userList) {
				Map<String, String> memberMap = new HashMap<String, String>();
				if (siteUserId != bean.getUserId()) {
					memberMap.put("site_user_id", bean.getUserId());
					memberMap.put("site_user_name", bean.getUserName());
					memberMap.put("site_user_photo", bean.getUserPhoto());
					UserProto.UserRelation userRelation = UserFriendDao.getInstance().getUserRelation(siteUserId,
							bean.getUserId());
					memberMap.put("site_user_relation", String.valueOf(userRelation.getNumber()));
				}
				data.add(memberMap);
			}
		} 
		results.put("Data", data);

	} catch (Exception e) {
		logger.error("get Member list error", e);
	}
	results.put("loading", nodata);
	return results;
}
 
Example #15
Source File: WebChatSendMessageHandler.java    From wind-im with Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * 检测消息是否可以发送:
 * 		1.消息发送者是否为正常用户
 * 		2.消息接受者是否为正常用户
 * 		3.二者是否为好友关系
 * </pre>
 * 
 * @param siteUserId
 * @param siteFriendId
 * @return
 */
private boolean checkUser(String siteUserId, String siteFriendId) {
	try {
		// 检测发送者的状态
		SimpleUserBean userBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteUserId);
		if (userBean != null) {
			if (userBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测接受者的状态
		SimpleUserBean friendBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteFriendId);
		if (friendBean != null) {
			if (friendBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
				return false;
			}
		} else {
			return false;
		}

		// 检测是否为好友关系
		if (!ImUserFriendDao.getInstance().isFriend(siteUserId, siteFriendId)) {
			return false;
		}
		return true;
	} catch (Exception e) {
		logger.error(StringHelper.format("check siteUserid={} siteFriendId={} error.", siteUserId, siteFriendId),
				e);
	}
	return false;
}
 
Example #16
Source File: GroupDetectionHandler.java    From wind-im with Apache License 2.0 5 votes vote down vote up
private boolean checkUser(String siteUserId) {
	// 检测发送者的状态
	SimpleUserBean userBean = ImUserProfileDao.getInstance().getSimpleUserProfile(siteUserId);
	if (userBean != null) {
		if (userBean.getUserStatus() != UserProto.UserStatus.NORMAL_VALUE) {
			return false;
		}
	} else {
		return false;
	}

	return true;
}
 
Example #17
Source File: UserSquareController.java    From wind-im with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST, value = "/pullMemberList")
@ResponseBody
public Map<String, Object> getMemberList(HttpServletRequest request, @RequestBody byte[] bodyParam) {
	Map<String, Object> results = new HashMap<String, Object>();
	boolean nodata = true;
	int pageSize = 20;
	try {
		PluginProto.ProxyPluginPackage pluginPackage = PluginProto.ProxyPluginPackage.parseFrom(bodyParam);
		Map<Integer, String> headerMap = pluginPackage.getPluginHeaderMap();
		String siteUserId = headerMap.get(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE);

		Map<String, String> ReqMap = GsonUtils.fromJson(pluginPackage.getData(), Map.class);

		int pageNum = Integer.valueOf(ReqMap.get("pageNum"));
		List<SimpleUserBean> userList = userService.getUserList(pageNum, pageSize);
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		if (userList != null && userList.size() > 0) {
			nodata = false;
			for (SimpleUserBean bean : userList) {
				Map<String, String> memberMap = new HashMap<String, String>();
				if (siteUserId != bean.getUserId()) {
					memberMap.put("site_user_id", bean.getUserId());
					memberMap.put("site_user_name", bean.getUserName());
					memberMap.put("site_user_photo", bean.getUserPhoto());
					UserProto.UserRelation userRelation = UserFriendDao.getInstance().getUserRelation(siteUserId,
							bean.getUserId());
					memberMap.put("site_user_relation", String.valueOf(userRelation.getNumber()));
				}
				data.add(memberMap);
			}
		} 
		results.put("Data", data);

	} catch (Exception e) {
		logger.error("get Member list error", e);
	}
	results.put("loading", nodata);
	return results;
}
 
Example #18
Source File: ApiFriendService.java    From wind-im with Apache License 2.0 5 votes vote down vote up
/**
 * 获取用户的好友申请列表
 * 
 * @param command
 * @return
 */
public CommandResponse applyList(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		String siteUserId = command.getSiteUserId();
		LogUtils.requestDebugLog(logger, command, "");

		if (StringUtils.isNotBlank(siteUserId)) {
			List<ApplyUserBean> applyUserList = UserFriendDao.getInstance().getApplyUserList(siteUserId);
			ApiFriendApplyListProto.ApiFriendApplyListResponse.Builder responseBuilder = ApiFriendApplyListProto.ApiFriendApplyListResponse
					.newBuilder();
			for (ApplyUserBean applyUser : applyUserList) {
				if (StringUtils.isNotEmpty(applyUser.getUserId())) {
					UserProto.UserProfile.Builder userProfileBuilder = UserProto.UserProfile.newBuilder();
					userProfileBuilder.setSiteUserId(applyUser.getUserId());
					userProfileBuilder.setUserName(String.valueOf(applyUser.getUserName()));
					userProfileBuilder.setUserPhoto(String.valueOf(applyUser.getUserPhoto()));
					UserProto.ApplyUserProfile applyUserProfile = UserProto.ApplyUserProfile.newBuilder()
							.setApplyUser(userProfileBuilder.build())
							.setApplyReason(String.valueOf(applyUser.getApplyReason())).build();
					responseBuilder.addList(applyUserProfile);
				}
			}
			commandResponse.setParams(responseBuilder.build().toByteArray());
			errCode = ErrorCode2.SUCCESS;
		}
	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example #19
Source File: ApiFriendService.java    From wind-im with Apache License 2.0 4 votes vote down vote up
/**
 * 查询好友的资料信息,点击好友头像查看使用
 * 
 * @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();
		String globalOrSiteFriendId = request.getSiteUserId();// 等待查询的站点用户ID || globalUserId
		String userIdPubk = request.getUserIdPubk(); // 等待查询的用户公钥,优先级高
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isAllEmpty(userIdPubk, globalOrSiteFriendId)) {
			errCode = ErrorCode2.ERROR_PARAMETER;
			return commandResponse.setErrCode2(errCode);
		}

		// 1.如果是siteUserId
		UserFriendBean userBean = UserProfileDao.getInstance().getFriendProfileById(siteUserId,
				globalOrSiteFriendId);
		// 2.如果不是则认为是globalUserId
		if (null == userBean || StringUtils.isNotEmpty(userBean.getSiteUserId())) {
			String siteFriendId = UserProfileDao.getInstance().getSiteUserIdByGlobalUserId(globalOrSiteFriendId);
			if (StringUtils.isNotEmpty(siteFriendId)) {
				userBean = UserProfileDao.getInstance().getFriendProfileById(siteUserId, siteFriendId);
			}
		}

		if (userBean != null && StringUtils.isNotBlank(userBean.getSiteUserId())) {
			UserProto.UserProfile.Builder friendProfileBuilder = UserProto.UserProfile.newBuilder();
			friendProfileBuilder.setSiteUserId(userBean.getSiteUserId());
			friendProfileBuilder.setUserIdPubk(userBean.getUserIdPubk());
			if (StringUtils.isNotEmpty(userBean.getAliasName())) {
				friendProfileBuilder.setUserName(userBean.getAliasName());
				if (StringUtils.isNotEmpty(userBean.getUserName())) {
					friendProfileBuilder.setNickName(userBean.getUserName());
				}
			} else {
				if (StringUtils.isNotEmpty(userBean.getUserName())) {
					friendProfileBuilder.setUserName(userBean.getUserName());
					friendProfileBuilder.setNickName(userBean.getUserName());
				}
			}

			if (StringUtils.isNotEmpty(userBean.getSiteLoginId())) {
				friendProfileBuilder.setSiteLoginId(userBean.getSiteLoginId());
			}
			if (StringUtils.isNotEmpty(userBean.getUserPhoto())) {
				friendProfileBuilder.setUserPhoto(userBean.getUserPhoto());
			}
			friendProfileBuilder.setUserStatusValue(userBean.getUserStatus());
			UserProto.UserProfile friendProfile = friendProfileBuilder.build();

			// 查关系
			UserProto.UserRelation userRelation = UserFriendDao.getInstance().getUserRelation(siteUserId,
					userBean.getSiteUserId());
			ApiFriendProfileProto.ApiFriendProfileResponse response = ApiFriendProfileProto.ApiFriendProfileResponse
					.newBuilder().setProfile(friendProfile).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);
}
 
Example #20
Source File: SiteUserProfileDao.java    From wind-im with Apache License 2.0 4 votes vote down vote up
/**
 * 分页获取用户列表,这个列表包含用户与查询的用户之间的关系,扩展中使用
 *
 * @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_name_in_latin,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;

	Connection conn = null;
	PreparedStatement pst = null;
	ResultSet rs = null;
	try {
		conn = DatabaseConnection.getSlaveConnection();
		pst = conn.prepareStatement(sql);
		pst.setString(1, siteUserId);
		pst.setInt(2, startNum);
		pst.setInt(3, pageSize);

		rs = pst.executeQuery();
		while (rs.next()) {
			SimpleUserRelationBean bean = new SimpleUserRelationBean();
			bean.setUserId(rs.getString(1));
			bean.setUserName(rs.getString(2));
			bean.setUserNameInLatin(rs.getString(3));
			bean.setUserPhoto(rs.getString(4));
			bean.setUserStatus(rs.getInt(5));
			if (StringUtils.isNotBlank(rs.getString(6))) {
				bean.setRelation(UserProto.UserRelation.RELATION_FRIEND_VALUE);
			} else {
				bean.setRelation(UserProto.UserRelation.RELATION_NONE_VALUE);
			}
			userPageList.add(bean);
		}
	} catch (Exception e) {
		throw e;
	} finally {
		DatabaseConnection.returnConnection(conn, pst, rs);
	}

	LogUtils.dbDebugLog(logger, startTime, userPageList.size(), sql, startNum, pageSize);
	return userPageList;
}
 
Example #21
Source File: HttpUserService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * 获取站点上的所有用户列表
 * 
 * @param command
 * @return
 */
public CommandResponse list(Command command) {
	CommandResponse commandResponse = new CommandResponse();
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		HaiUserListProto.HaiUserListRequest request = HaiUserListProto.HaiUserListRequest
				.parseFrom(command.getParams());
		int pageNum = request.getPageNumber();
		int pageSize = request.getPageSize();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (pageNum == 0 && pageSize == 0) {
			pageNum = 1;
			pageSize = 100;
		}

		int totalUserNum = UserProfileDao.getInstance().getTotalUserNum();
		List<SimpleUserBean> userPageList = UserProfileDao.getInstance().getUserPageList(pageNum, pageSize);

		HaiUserListProto.HaiUserListResponse.Builder responseBuilder = HaiUserListProto.HaiUserListResponse
				.newBuilder();
		responseBuilder.setPageTotalNum(totalUserNum);
		if (userPageList != null) {
			for (SimpleUserBean bean : userPageList) {
				UserProto.SimpleUserProfile.Builder userProfileBuilder = UserProto.SimpleUserProfile.newBuilder();
				userProfileBuilder.setSiteUserId(bean.getUserId());
				if (StringUtils.isNotBlank(bean.getUserName())) {
					userProfileBuilder.setUserName(bean.getUserName());
				}
				if (StringUtils.isNotBlank(bean.getUserPhoto())) {
					userProfileBuilder.setUserPhoto(bean.getUserPhoto());
				}
				userProfileBuilder.setUserStatusValue(bean.getUserStatus());
				responseBuilder.addUserProfile(userProfileBuilder.build());
			}
		}
		responseBuilder.setPageTotalNum(totalUserNum);
		commandResponse.setParams(responseBuilder.build().toByteArray());
		errCode = ErrorCode2.SUCCESS;

	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}

	return commandResponse.setErrCode(errCode);
}
 
Example #22
Source File: ApiGroupService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * 获取用户群组中,不存在的好友用户
 *
 * @param command
 * @return
 */
public CommandResponse nonMembers(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		ApiGroupNonMembersProto.ApiGroupNonMembersRequest request = ApiGroupNonMembersProto.ApiGroupNonMembersRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String groupId = request.getGroupId();
		int pageNum = request.getPageNumber();
		int pageSize = request.getPageSize();
		if (pageNum == 0 && pageSize == 0) {
			pageSize = 100;
		}
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isAnyEmpty(siteUserId, groupId)) {
			throw new ZalyException(ErrorCode2.ERROR_PARAMETER);
		}

		if (!checkGroupStatus(groupId)) {
			throw new ZalyException(ErrorCode2.ERROR_GROUP_DELETED);
		}

		List<SimpleUserBean> userFriendList = UserGroupDao.getInstance().getUserFriendNonGroupMemberList(siteUserId,
				groupId, pageNum, pageSize);
		ApiGroupNonMembersProto.ApiGroupNonMembersResponse.Builder responseBuilder = ApiGroupNonMembersProto.ApiGroupNonMembersResponse
				.newBuilder();
		for (SimpleUserBean friendBean : userFriendList) {
			UserProto.SimpleUserProfile friendProfile = UserProto.SimpleUserProfile.newBuilder()
					.setSiteUserId(friendBean.getUserId()).setUserName(String.valueOf(friendBean.getUserName()))
					.setUserPhoto(String.valueOf(friendBean.getUserPhoto())).build();
			responseBuilder.addProfile(friendProfile);
		}
		commandResponse.setParams(responseBuilder.build().toByteArray());
		errCode = ErrorCode2.SUCCESS;

	} catch (Exception e) {
		if (e instanceof ZalyException) {
			errCode = ((ZalyException) e).getErrCode();
		} else {
			errCode = ErrorCode2.ERROR_SYSTEMERROR;
		}
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode(errCode);
}
 
Example #23
Source File: ApiGroupService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * 获取群成员 <br>
 * 无权限控制
 *
 * @param command
 * @return
 */
public CommandResponse members(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		ApiGroupMembersProto.ApiGroupMembersRequest request = ApiGroupMembersProto.ApiGroupMembersRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String siteGroupId = request.getGroupId();
		int pageNum = 1;
		int pageSize = GroupConfig.GROUP_MAX_MEMBER_COUNT;
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isAnyEmpty(siteUserId, siteGroupId)) {
			throw new ZalyException(ErrorCode2.ERROR_PARAMETER);
		}

		if (!checkGroupStatus(siteGroupId)) {
			throw new ZalyException(ErrorCode2.ERROR_GROUP_DELETED);
		}

		List<GroupMemberBean> memberList = UserGroupDao.getInstance().getGroupMemberList(siteGroupId, pageNum,
				pageSize);
		ApiGroupMembersProto.ApiGroupMembersResponse.Builder responseBuilder = ApiGroupMembersProto.ApiGroupMembersResponse
				.newBuilder();
		for (GroupMemberBean member : memberList) {
			GroupProto.GroupMemberRole memberRole = GroupProto.GroupMemberRole.forNumber(member.getUserRole());
			UserProto.UserProfile memberProfile = UserProto.UserProfile.newBuilder()
					.setSiteUserId(member.getUserId()).setUserName(String.valueOf(member.getUserName()))
					.setUserPhoto(String.valueOf(member.getUserPhoto())).build();
			GroupProto.GroupMemberProfile groupMember = GroupProto.GroupMemberProfile.newBuilder()
					.setRole(memberRole).setProfile(memberProfile).build();
			responseBuilder.addList(groupMember);
		}
		commandResponse.setParams(responseBuilder.build().toByteArray());
		errCode = ErrorCode2.SUCCESS;

	} catch (Exception e) {
		if (e instanceof ZalyException) {
			errCode = ((ZalyException) e).getErrCode();
		} else {
			errCode = ErrorCode2.ERROR_SYSTEMERROR;
		}
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode(errCode);
}
 
Example #24
Source File: ApiGroupService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * 获取群资料信息,一般由以下几部分组成 <br>
 * 1.群资料GroupProfile <br>
 * 2.群主基本资料GroupMaster,群主通过GroupProfile获取 <br>
 * 3.群成员人数以及排在最前列的四位用户 <br>
 * 4.无权限限制
 *
 * @param command
 * @return
 */
public CommandResponse profile(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		ApiGroupProfileProto.ApiGroupProfileRequest request = ApiGroupProfileProto.ApiGroupProfileRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String groupId = request.getGroupId();
		int pageNum = 1;
		int pageSize = GroupConfig.GROUP_MIN_MEMBER_COUNT;
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isAnyEmpty(siteUserId, groupId)) {
			throw new ZalyException(ErrorCode2.ERROR_PARAMETER);
		}

		if (!checkGroupStatus(groupId)) {
			throw new ZalyException(ErrorCode2.ERROR_GROUP_DELETED);
		}

		GroupProfileBean groupBean = UserGroupDao.getInstance().getGroupProfile(groupId);
		if (groupBean == null || StringUtils.isEmpty(groupBean.getGroupId())) {
			throw new ZalyException(ErrorCode2.ERROR_GROUP_QUERY_PROFILE);
		}

		SimpleUserBean ownerProfileBean = UserProfileDao.getInstance()
				.getSimpleProfileById(groupBean.getCreateUserId());
		logger.debug("get groupId={},groupOwner={}", groupId, ownerProfileBean.toString());

		int groupMembersCount = UserGroupDao.getInstance().getGroupMemberCount(groupId);
		logger.debug("get groupId={},groupMembers={}", groupId, groupMembersCount);

		List<GroupMemberBean> groupMemberList = UserGroupDao.getInstance().getGroupMemberList(groupId, pageNum,
				pageSize);

		UserProto.UserProfile ownerProfile = UserProto.UserProfile.newBuilder()
				.setSiteUserId(String.valueOf(ownerProfileBean.getUserId()))
				.setUserPhoto(String.valueOf(ownerProfileBean.getUserPhoto()))
				.setUserName(String.valueOf(ownerProfileBean.getUserName())).build();
		GroupProto.GroupProfile groupProfile = GroupProto.GroupProfile.newBuilder().setId(groupBean.getGroupId())
				.setName(String.valueOf(groupBean.getGroupName()))
				.setIcon(String.valueOf(groupBean.getGroupPhoto())).build();

		ApiGroupProfileProto.ApiGroupProfileResponse.Builder responseBuilder = ApiGroupProfileProto.ApiGroupProfileResponse
				.newBuilder();
		responseBuilder.setOwner(ownerProfile);
		responseBuilder.setProfile(groupProfile);
		responseBuilder.setGroupMemberCount(groupMembersCount);

		for (GroupMemberBean memberBean : groupMemberList) {
			UserProto.UserProfile memberProfile = UserProto.UserProfile.newBuilder()
					.setSiteUserId(String.valueOf(memberBean.getUserId()))
					.setUserPhoto(String.valueOf(memberBean.getUserPhoto()))
					.setUserName(String.valueOf(memberBean.getUserName())).build();
			GroupProto.GroupMemberProfile groupMemberProfile = GroupProto.GroupMemberProfile.newBuilder()
					.setProfile(memberProfile).build();
			responseBuilder.addGroupLastestMember(groupMemberProfile);
		}
		// 是否可以邀请群聊(除了群主以外)
		responseBuilder.setCloseInviteGroupChat(groupBean.isCloseInviteGroupChat());
		ApiGroupProfileProto.ApiGroupProfileResponse response = responseBuilder.build();

		commandResponse.setParams(response.toByteArray());
		errCode = ErrorCode2.SUCCESS;
	} catch (Exception e) {
		if (e instanceof ZalyException) {
			errCode = ((ZalyException) e).getErrCode();
		} else {
			errCode = ErrorCode2.ERROR_SYSTEMERROR;
		}
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode(errCode);
}
 
Example #25
Source File: ApiFriendService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * 获取个人的好友列表,通讯录中使用
 * 
 * @param command
 * @return
 */
public CommandResponse list(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		ApiFriendListProto.ApiFriendListRequest request = ApiFriendListProto.ApiFriendListRequest
				.parseFrom(command.getParams());
		String currentUserId = command.getSiteUserId();
		String siteUserId = request.getSiteUserId();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isNotBlank(siteUserId) && siteUserId.equals(currentUserId)) {
			List<SimpleUserBean> friendBeanList = UserFriendDao.getInstance().getUserFriends(siteUserId);

			ApiFriendListProto.ApiFriendListResponse.Builder responseBuilder = ApiFriendListProto.ApiFriendListResponse
					.newBuilder();
			for (SimpleUserBean friendBean : friendBeanList) {
				UserProto.SimpleUserProfile.Builder friendBuilder = UserProto.SimpleUserProfile.newBuilder();
				friendBuilder.setSiteUserId(friendBean.getUserId());
				if (StringUtils.isNotEmpty(friendBean.getAliasName())) {
					friendBuilder.setUserName(friendBean.getAliasName());
					if (StringUtils.isNotEmpty(friendBean.getAliasNameInLatin())) {
						friendBuilder.setUsernameInLatin(friendBean.getAliasNameInLatin());
					}
				} else {
					if (StringUtils.isNotEmpty(friendBean.getUserName())) {
						friendBuilder.setUserName(friendBean.getUserName());
					}
					if (StringUtils.isNotEmpty(friendBean.getUserNameInLatin())) {
						friendBuilder.setUsernameInLatin(friendBean.getUserNameInLatin());
					}
				}
				if (StringUtils.isNotEmpty(friendBean.getUserPhoto())) {
					friendBuilder.setUserPhoto(friendBean.getUserPhoto());
				}
				responseBuilder.addList(friendBuilder.build());
			}
			commandResponse.setParams(responseBuilder.build().toByteArray());
			errCode = ErrorCode2.SUCCESS;
		} else {
			errCode = ErrorCode2.ERROR_PARAMETER;
		}
	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example #26
Source File: ApiFriendService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * 查询好友的资料信息,点击好友头像查看使用
 * 
 * @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();
		String globalOrSiteFriendId = request.getSiteUserId();// 等待查询的站点用户ID || globalUserId
		String userIdPubk = request.getUserIdPubk(); // 等待查询的用户公钥,优先级高
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isAllEmpty(userIdPubk, globalOrSiteFriendId)) {
			errCode = ErrorCode2.ERROR_PARAMETER;
			return commandResponse.setErrCode2(errCode);
		}

		// 1.如果是siteUserId
		UserFriendBean userBean = UserProfileDao.getInstance().getFriendProfileById(siteUserId,
				globalOrSiteFriendId);
		// 2.如果不是则认为是globalUserId
		if (null == userBean || StringUtils.isNotEmpty(userBean.getSiteUserId())) {
			String siteFriendId = UserProfileDao.getInstance().getSiteUserIdByGlobalUserId(globalOrSiteFriendId);
			if (StringUtils.isNotEmpty(siteFriendId)) {
				userBean = UserProfileDao.getInstance().getFriendProfileById(siteUserId, siteFriendId);
			}
		}

		if (userBean != null && StringUtils.isNotBlank(userBean.getSiteUserId())) {
			UserProto.UserProfile.Builder friendProfileBuilder = UserProto.UserProfile.newBuilder();
			friendProfileBuilder.setSiteUserId(userBean.getSiteUserId());
			friendProfileBuilder.setUserIdPubk(userBean.getUserIdPubk());
			if (StringUtils.isNotEmpty(userBean.getAliasName())) {
				friendProfileBuilder.setUserName(userBean.getAliasName());
				if (StringUtils.isNotEmpty(userBean.getUserName())) {
					friendProfileBuilder.setNickName(userBean.getUserName());
				}
			} else {
				if (StringUtils.isNotEmpty(userBean.getUserName())) {
					friendProfileBuilder.setUserName(userBean.getUserName());
					friendProfileBuilder.setNickName(userBean.getUserName());
				}
			}

			if (StringUtils.isNotEmpty(userBean.getSiteLoginId())) {
				friendProfileBuilder.setSiteLoginId(userBean.getSiteLoginId());
			}
			if (StringUtils.isNotEmpty(userBean.getUserPhoto())) {
				friendProfileBuilder.setUserPhoto(userBean.getUserPhoto());
			}
			friendProfileBuilder.setUserStatusValue(userBean.getUserStatus());
			UserProto.UserProfile friendProfile = friendProfileBuilder.build();

			// 查关系
			UserProto.UserRelation userRelation = UserFriendDao.getInstance().getUserRelation(siteUserId,
					userBean.getSiteUserId());
			ApiFriendProfileProto.ApiFriendProfileResponse response = ApiFriendProfileProto.ApiFriendProfileResponse
					.newBuilder().setProfile(friendProfile).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);
}
 
Example #27
Source File: ApiUserService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * 获取用户个人资料信息,支持使用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 (StringUtils.isNotEmpty(userBean.getUserName())) {
					userProfileBuilder.setUserName(userBean.getUserName());
				}
				if (StringUtils.isNotEmpty(userBean.getSiteLoginId())) {
					userProfileBuilder.setSiteLoginId(userBean.getSiteLoginId());
				}
				if (StringUtils.isNotEmpty(userBean.getUserPhoto())) {
					userProfileBuilder.setUserPhoto(userBean.getUserPhoto());
				}
				if (StringUtils.isNotEmpty(userBean.getSelfIntroduce())) {
					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);
}
 
Example #28
Source File: ApiUserService.java    From wind-im with Apache License 2.0 4 votes vote down vote up
/**
 * 获取用户个人资料信息,支持使用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 (StringUtils.isNotEmpty(userBean.getUserName())) {
					userProfileBuilder.setUserName(userBean.getUserName());
				}
				if (StringUtils.isNotEmpty(userBean.getSiteLoginId())) {
					userProfileBuilder.setSiteLoginId(userBean.getSiteLoginId());
				}
				if (StringUtils.isNotEmpty(userBean.getUserPhoto())) {
					userProfileBuilder.setUserPhoto(userBean.getUserPhoto());
				}
				if (StringUtils.isNotEmpty(userBean.getSelfIntroduce())) {
					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);
}
 
Example #29
Source File: SiteUserProfileDao.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * 分页获取用户列表,这个列表包含用户与查询的用户之间的关系,扩展中使用
 *
 * @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_name_in_latin,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;

	Connection conn = null;
	PreparedStatement pst = null;
	ResultSet rs = null;
	try {
		conn = DatabaseConnection.getSlaveConnection();
		pst = conn.prepareStatement(sql);
		pst.setString(1, siteUserId);
		pst.setInt(2, startNum);
		pst.setInt(3, pageSize);

		rs = pst.executeQuery();
		while (rs.next()) {
			SimpleUserRelationBean bean = new SimpleUserRelationBean();
			bean.setUserId(rs.getString(1));
			bean.setUserName(rs.getString(2));
			bean.setUserNameInLatin(rs.getString(3));
			bean.setUserPhoto(rs.getString(4));
			bean.setUserStatus(rs.getInt(5));
			if (StringUtils.isNotBlank(rs.getString(6))) {
				bean.setRelation(UserProto.UserRelation.RELATION_FRIEND_VALUE);
			} else {
				bean.setRelation(UserProto.UserRelation.RELATION_NONE_VALUE);
			}
			userPageList.add(bean);
		}
	} catch (Exception e) {
		throw e;
	} finally {
		DatabaseConnection.returnConnection(conn, pst, rs);
	}

	LogUtils.dbDebugLog(logger, startTime, userPageList.size(), sql, startNum, pageSize);
	return userPageList;
}
 
Example #30
Source File: HttpUserService.java    From wind-im with Apache License 2.0 4 votes vote down vote up
/**
 * 获取站点上的所有用户列表
 * 
 * @param command
 * @return
 */
public CommandResponse list(Command command) {
	CommandResponse commandResponse = new CommandResponse();
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		HaiUserListProto.HaiUserListRequest request = HaiUserListProto.HaiUserListRequest
				.parseFrom(command.getParams());
		int pageNum = request.getPageNumber();
		int pageSize = request.getPageSize();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (pageNum == 0 && pageSize == 0) {
			pageNum = 1;
			pageSize = 100;
		}

		int totalUserNum = UserProfileDao.getInstance().getTotalUserNum();
		List<SimpleUserBean> userPageList = UserProfileDao.getInstance().getUserPageList(pageNum, pageSize);

		HaiUserListProto.HaiUserListResponse.Builder responseBuilder = HaiUserListProto.HaiUserListResponse
				.newBuilder();
		responseBuilder.setPageTotalNum(totalUserNum);
		if (userPageList != null) {
			for (SimpleUserBean bean : userPageList) {
				UserProto.SimpleUserProfile.Builder userProfileBuilder = UserProto.SimpleUserProfile.newBuilder();
				userProfileBuilder.setSiteUserId(bean.getUserId());
				if (StringUtils.isNotBlank(bean.getUserName())) {
					userProfileBuilder.setUserName(bean.getUserName());
				}
				if (StringUtils.isNotBlank(bean.getUserPhoto())) {
					userProfileBuilder.setUserPhoto(bean.getUserPhoto());
				}
				userProfileBuilder.setUserStatusValue(bean.getUserStatus());
				responseBuilder.addUserProfile(userProfileBuilder.build());
			}
		}
		responseBuilder.setPageTotalNum(totalUserNum);
		commandResponse.setParams(responseBuilder.build().toByteArray());
		errCode = ErrorCode2.SUCCESS;

	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}

	return commandResponse.setErrCode(errCode);
}