作者 crossoverJie

:sparkles: Introducing new features.内置命令

@@ -7,10 +7,12 @@ import com.crossoverjie.cim.client.service.RouteRequest; @@ -7,10 +7,12 @@ import com.crossoverjie.cim.client.service.RouteRequest;
7 import com.crossoverjie.cim.client.util.SpringBeanFactory; 7 import com.crossoverjie.cim.client.util.SpringBeanFactory;
8 import com.crossoverjie.cim.client.vo.req.GroupReqVO; 8 import com.crossoverjie.cim.client.vo.req.GroupReqVO;
9 import com.crossoverjie.cim.client.vo.req.P2PReqVO; 9 import com.crossoverjie.cim.client.vo.req.P2PReqVO;
  10 +import com.crossoverjie.cim.common.enums.SystemCommandEnumType;
10 import com.crossoverjie.cim.common.util.StringUtil; 11 import com.crossoverjie.cim.common.util.StringUtil;
11 import org.slf4j.Logger; 12 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
13 14
  15 +import java.util.Map;
14 import java.util.Scanner; 16 import java.util.Scanner;
15 17
16 /** 18 /**
@@ -49,6 +51,12 @@ public class Scan implements Runnable { @@ -49,6 +51,12 @@ public class Scan implements Runnable {
49 continue; 51 continue;
50 } 52 }
51 53
  54 + //系统内置命令
  55 + if (msg.startsWith(":")){
  56 + innerCommand(msg);
  57 + continue ;
  58 + }
  59 +
52 //单聊 60 //单聊
53 totalMsg = msg.split("><"); 61 totalMsg = msg.split("><");
54 if (totalMsg.length > 1) { 62 if (totalMsg.length > 1) {
@@ -64,6 +72,28 @@ public class Scan implements Runnable { @@ -64,6 +72,28 @@ public class Scan implements Runnable {
64 } 72 }
65 } 73 }
66 74
  75 + /**
  76 + * 处理内置函数
  77 + */
  78 + private void innerCommand(String msg) {
  79 + Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode();
  80 +
  81 + if (SystemCommandEnumType.QUIT.getCommandType().equals(msg)){
  82 + LOGGER.info("系统关闭中。。。。");
  83 + System.exit(0);
  84 + }else {
  85 + LOGGER.warn("====================================");
  86 + for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) {
  87 + String key = stringStringEntry.getKey();
  88 + String value = stringStringEntry.getValue();
  89 + LOGGER.warn(key + "----->" + value);
  90 + }
  91 + LOGGER.warn("====================================");
  92 + }
  93 +
  94 + return;
  95 + }
  96 +
67 private void p2pChat(String[] totalMsg) { 97 private void p2pChat(String[] totalMsg) {
68 P2PReqVO p2PReqVO = new P2PReqVO(); 98 P2PReqVO p2PReqVO = new P2PReqVO();
69 p2PReqVO.setUserId(configuration.getUserId()); 99 p2PReqVO.setUserId(configuration.getUserId());
@@ -22,8 +22,9 @@ public class Constants { @@ -22,8 +22,9 @@ public class Constants {
22 public static final String COUNTER_CLIENT_PUSH_COUNT = "counter.client.push.count" ; 22 public static final String COUNTER_CLIENT_PUSH_COUNT = "counter.client.push.count" ;
23 23
24 24
25 -  
26 - 25 + /**
  26 + * 自定义报文类型
  27 + */
27 public static class CommandType{ 28 public static class CommandType{
28 /** 29 /**
29 * 登录 30 * 登录
@@ -35,7 +36,7 @@ public class Constants { @@ -35,7 +36,7 @@ public class Constants {
35 public static final int MSG = 2 ; 36 public static final int MSG = 2 ;
36 37
37 /** 38 /**
38 - * 业务消息 39 + * ping
39 */ 40 */
40 public static final int PING = 3 ; 41 public static final int PING = 3 ;
41 } 42 }
  1 +package com.crossoverjie.cim.common.enums;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.HashMap;
  5 +import java.util.List;
  6 +import java.util.Map;
  7 +
  8 +/**
  9 + * Function:
  10 + *
  11 + * @author crossoverJie
  12 + * Date: 2018/12/26 18:38
  13 + * @since JDK 1.8
  14 + */
  15 +public enum SystemCommandEnumType {
  16 +
  17 + ALL(":all ","获取所有命令"),
  18 + ONLINE_USER(":onlineUser","获取所有在线用户"),
  19 + QUIT(":q ","退出程序")
  20 +
  21 + ;
  22 +
  23 + /** 枚举值码 */
  24 + private final String commandType;
  25 +
  26 + /** 枚举描述 */
  27 + private final String desc;
  28 +
  29 +
  30 + /**
  31 + * 构建一个 。
  32 + * @param commandType 枚举值码。
  33 + * @param desc 枚举描述。
  34 + */
  35 + private SystemCommandEnumType(String commandType, String desc) {
  36 + this.commandType = commandType;
  37 + this.desc = desc;
  38 + }
  39 +
  40 + /**
  41 + * 得到枚举值码。
  42 + * @return 枚举值码。
  43 + */
  44 + public String getCommandType() {
  45 + return commandType.trim();
  46 + }
  47 +
  48 + /**
  49 + * 得到枚举描述。
  50 + * @return 枚举描述。
  51 + */
  52 + public String getDesc() {
  53 + return desc;
  54 + }
  55 +
  56 + /**
  57 + * 得到枚举值码。
  58 + * @return 枚举值码。
  59 + */
  60 + public String code() {
  61 + return commandType;
  62 + }
  63 +
  64 + /**
  65 + * 得到枚举描述。
  66 + * @return 枚举描述。
  67 + */
  68 + public String message() {
  69 + return desc;
  70 + }
  71 +
  72 + /**
  73 + * 获取全部枚举值码。
  74 + *
  75 + * @return 全部枚举值码。
  76 + */
  77 + public static Map<String,String> getAllStatusCode() {
  78 + List<String> list = new ArrayList<String>();
  79 + Map<String,String> map = new HashMap<String, String>(16) ;
  80 + for (SystemCommandEnumType status : values()) {
  81 + list.add(status.code());
  82 + map.put(status.getCommandType(),status.getDesc()) ;
  83 + }
  84 + return map;
  85 + }
  86 +
  87 +}
  1 +package com.crossoverjie.cim.common.enums;
  2 +
  3 +import org.junit.Test;
  4 +
  5 +import java.util.Map;
  6 +
  7 +public class SystemCommandEnumTypeTest {
  8 +
  9 +
  10 + @Test
  11 + public void getAllStatusCode() throws Exception {
  12 + Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode();
  13 + for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) {
  14 + String key = stringStringEntry.getKey();
  15 + String value = stringStringEntry.getValue();
  16 + System.out.println(key + "----->" + value);
  17 + }
  18 +
  19 + }
  20 +
  21 +}