作者 crossoverJie

:sparkles: Introducing new features.内置命令

... ... @@ -7,10 +7,12 @@ import com.crossoverjie.cim.client.service.RouteRequest;
import com.crossoverjie.cim.client.util.SpringBeanFactory;
import com.crossoverjie.cim.client.vo.req.GroupReqVO;
import com.crossoverjie.cim.client.vo.req.P2PReqVO;
import com.crossoverjie.cim.common.enums.SystemCommandEnumType;
import com.crossoverjie.cim.common.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.Scanner;
/**
... ... @@ -49,6 +51,12 @@ public class Scan implements Runnable {
continue;
}
//系统内置命令
if (msg.startsWith(":")){
innerCommand(msg);
continue ;
}
//单聊
totalMsg = msg.split("><");
if (totalMsg.length > 1) {
... ... @@ -64,6 +72,28 @@ public class Scan implements Runnable {
}
}
/**
* 处理内置函数
*/
private void innerCommand(String msg) {
Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode();
if (SystemCommandEnumType.QUIT.getCommandType().equals(msg)){
LOGGER.info("系统关闭中。。。。");
System.exit(0);
}else {
LOGGER.warn("====================================");
for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) {
String key = stringStringEntry.getKey();
String value = stringStringEntry.getValue();
LOGGER.warn(key + "----->" + value);
}
LOGGER.warn("====================================");
}
return;
}
private void p2pChat(String[] totalMsg) {
P2PReqVO p2PReqVO = new P2PReqVO();
p2PReqVO.setUserId(configuration.getUserId());
... ...
... ... @@ -22,8 +22,9 @@ public class Constants {
public static final String COUNTER_CLIENT_PUSH_COUNT = "counter.client.push.count" ;
/**
* 自定义报文类型
*/
public static class CommandType{
/**
* 登录
... ... @@ -35,7 +36,7 @@ public class Constants {
public static final int MSG = 2 ;
/**
* 业务消息
* ping
*/
public static final int PING = 3 ;
}
... ...
package com.crossoverjie.cim.common.enums;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Function:
*
* @author crossoverJie
* Date: 2018/12/26 18:38
* @since JDK 1.8
*/
public enum SystemCommandEnumType {
ALL(":all ","获取所有命令"),
ONLINE_USER(":onlineUser","获取所有在线用户"),
QUIT(":q ","退出程序")
;
/** 枚举值码 */
private final String commandType;
/** 枚举描述 */
private final String desc;
/**
* 构建一个 。
* @param commandType 枚举值码。
* @param desc 枚举描述。
*/
private SystemCommandEnumType(String commandType, String desc) {
this.commandType = commandType;
this.desc = desc;
}
/**
* 得到枚举值码。
* @return 枚举值码。
*/
public String getCommandType() {
return commandType.trim();
}
/**
* 得到枚举描述。
* @return 枚举描述。
*/
public String getDesc() {
return desc;
}
/**
* 得到枚举值码。
* @return 枚举值码。
*/
public String code() {
return commandType;
}
/**
* 得到枚举描述。
* @return 枚举描述。
*/
public String message() {
return desc;
}
/**
* 获取全部枚举值码。
*
* @return 全部枚举值码。
*/
public static Map<String,String> getAllStatusCode() {
List<String> list = new ArrayList<String>();
Map<String,String> map = new HashMap<String, String>(16) ;
for (SystemCommandEnumType status : values()) {
list.add(status.code());
map.put(status.getCommandType(),status.getDesc()) ;
}
return map;
}
}
\ No newline at end of file
... ...
package com.crossoverjie.cim.common.enums;
import org.junit.Test;
import java.util.Map;
public class SystemCommandEnumTypeTest {
@Test
public void getAllStatusCode() throws Exception {
Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode();
for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) {
String key = stringStringEntry.getKey();
String value = stringStringEntry.getValue();
System.out.println(key + "----->" + value);
}
}
}
\ No newline at end of file
... ...