作者 crossoverJie

:sparkles: Introducing new features.onlineusers

... ... @@ -3,6 +3,9 @@ package com.crossoverjie.cim.client.service;
import com.crossoverjie.cim.client.vo.req.GroupReqVO;
import com.crossoverjie.cim.client.vo.req.LoginReqVO;
import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO;
import java.util.List;
/**
* Function:
... ... @@ -26,4 +29,10 @@ public interface RouteRequest {
* @throws Exception
*/
CIMServerResVO.ServerInfo getCIMServer(LoginReqVO loginReqVO) throws Exception;
/**
*
* @return 获取所有在线用户
*/
List<OnlineUsersResVO.DataBodyBean> onlineUsers()throws Exception ;
}
... ...
... ... @@ -6,6 +6,7 @@ import com.crossoverjie.cim.client.service.MsgHandle;
import com.crossoverjie.cim.client.service.RouteRequest;
import com.crossoverjie.cim.client.vo.req.GroupReqVO;
import com.crossoverjie.cim.client.vo.req.P2PReqVO;
import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO;
import com.crossoverjie.cim.common.enums.SystemCommandEnumType;
import com.crossoverjie.cim.common.util.StringUtil;
import org.slf4j.Logger;
... ... @@ -13,6 +14,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
... ... @@ -91,6 +93,11 @@ public class MsgHandler implements MsgHandle {
shutdown();
} else if (SystemCommandEnumType.ALL.getCommandType().trim().equals(msg)){
printAllCommand(allStatusCode);
} else if (SystemCommandEnumType.ONLINE_USER.getCommandType().trim().equals(msg)){
//打印在线用户
printOnlineUsers();
}else {
printAllCommand(allStatusCode);
}
... ... @@ -105,6 +112,24 @@ public class MsgHandler implements MsgHandle {
}
/**
* 打印在线用户
*/
private void printOnlineUsers() {
try {
List<OnlineUsersResVO.DataBodyBean> onlineUsers = routeRequest.onlineUsers();
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) {
LOGGER.info("userId={}=====userName={}",onlineUser.getUserId(),onlineUser.getUserName());
}
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
} catch (Exception e) {
LOGGER.error("Exception" ,e);
}
}
/**
* 关闭系统
*/
private void shutdown() {
... ...
... ... @@ -7,6 +7,7 @@ import com.crossoverjie.cim.client.service.RouteRequest;
import com.crossoverjie.cim.client.vo.req.GroupReqVO;
import com.crossoverjie.cim.client.vo.req.LoginReqVO;
import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO;
import com.crossoverjie.cim.common.enums.StatusEnum;
import okhttp3.*;
import org.slf4j.Logger;
... ... @@ -16,6 +17,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.List;
/**
* Function:
... ... @@ -40,6 +42,11 @@ public class RouteRequestImpl implements RouteRequest {
@Value("${cim.server.route.request.url}")
private String serverRouteRequestUrl;
@Value("${cim.server.online.user.url}")
private String onlineUserUrl;
@Autowired
private AppConfiguration appConfiguration ;
... ... @@ -95,4 +102,29 @@ public class RouteRequestImpl implements RouteRequest {
return cimServerResVO.getDataBody();
}
@Override
public List<OnlineUsersResVO.DataBodyBean> onlineUsers() throws Exception{
JSONObject jsonObject = new JSONObject();
RequestBody requestBody = RequestBody.create(mediaType,jsonObject.toString());
Request request = new Request.Builder()
.url(onlineUserUrl)
.post(requestBody)
.build();
Response response = okHttpClient.newCall(request).execute() ;
if (!response.isSuccessful()){
throw new IOException("Unexpected code " + response);
}
if (!response.isSuccessful()){
throw new IOException("Unexpected code " + response);
}
String json = response.body().string() ;
OnlineUsersResVO onlineUsersResVO = JSON.parseObject(json, OnlineUsersResVO.class);
return onlineUsersResVO.getDataBody();
}
}
... ...
package com.crossoverjie.cim.client.vo.res;
import java.util.List;
/**
* Function:
*
* @author crossoverJie
* Date: 2018/12/26 23:17
* @since JDK 1.8
*/
public class OnlineUsersResVO {
/**
* code : 9000
* message : 成功
* reqNo : null
* dataBody : [{"userId":1545574841528,"userName":"zhangsan"},{"userId":1545574871143,"userName":"crossoverJie"}]
*/
private String code;
private String message;
private Object reqNo;
private List<DataBodyBean> dataBody;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getReqNo() {
return reqNo;
}
public void setReqNo(Object reqNo) {
this.reqNo = reqNo;
}
public List<DataBodyBean> getDataBody() {
return dataBody;
}
public void setDataBody(List<DataBodyBean> dataBody) {
this.dataBody = dataBody;
}
public static class DataBodyBean {
/**
* userId : 1545574841528
* userName : zhangsan
*/
private long userId;
private String userName;
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
}
... ...
... ... @@ -16,6 +16,9 @@ cim.group.route.request.url=http://45.78.28.220:8083/groupRoute
# 登录并获取服务器ip+port
cim.server.route.request.url=http://45.78.28.220:8083/login
# 在线用户
cim.server.online.user.url=http://45.78.28.220:8083/onlineUser
###=======本地模拟======###
## 群发消息
... ... @@ -24,6 +27,9 @@ cim.server.route.request.url=http://45.78.28.220:8083/login
## 登录并获取服务器ip+port
#cim.server.route.request.url=http://localhost:8083/login
# 在线用户
#cim.server.online.user=http://localhost:8083/onlineUser
# 客户端唯一ID
cim.user.id=1545574841528
cim.user.userName=zhangsan
... ...
... ... @@ -3,7 +3,13 @@ package com.crossoverjie.cim.server.test;
import com.alibaba.fastjson.JSON;
import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* Function:
... ... @@ -14,6 +20,7 @@ import org.junit.Test;
*/
public class CommonTest {
private final static Logger LOGGER = LoggerFactory.getLogger(CommonTest.class);
@Test
public void test() {
... ... @@ -27,4 +34,30 @@ public class CommonTest {
String[] split = text.split(" ");
System.out.println(split.length);
}
@Test
public void onlineUser(){
List<OnlineUsersResVO.DataBodyBean> onlineUsers = new ArrayList<>(64) ;
OnlineUsersResVO.DataBodyBean bodyBean = new OnlineUsersResVO.DataBodyBean() ;
bodyBean.setUserId(100L);
bodyBean.setUserName("zhangsan");
onlineUsers.add(bodyBean) ;
bodyBean = new OnlineUsersResVO.DataBodyBean();
bodyBean.setUserId(200L);
bodyBean.setUserName("crossoverJie");
onlineUsers.add(bodyBean) ;
LOGGER.info("list={}",JSON.toJSONString(onlineUsers));
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) {
LOGGER.info("userId={}=====userName={}",onlineUser.getUserId(),onlineUser.getUserName());
}
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
}
... ...