作者 crossoverJie

:recycle: 重构代码---->策略模式优化 if else

@@ -26,6 +26,8 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -26,6 +26,8 @@ import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.beans.factory.annotation.Value; 26 import org.springframework.beans.factory.annotation.Value;
27 import org.springframework.stereotype.Component; 27 import org.springframework.stereotype.Component;
28 28
  29 +import javax.annotation.PostConstruct;
  30 +
29 /** 31 /**
30 * Function: 32 * Function:
31 * 33 *
@@ -65,7 +67,7 @@ public class CIMClient { @@ -65,7 +67,7 @@ public class CIMClient {
65 */ 67 */
66 private int errorCount; 68 private int errorCount;
67 69
68 - //@PostConstruct 70 + @PostConstruct
69 public void start() throws Exception { 71 public void start() throws Exception {
70 72
71 //登录 + 获取可以使用的服务器 ip+port 73 //登录 + 获取可以使用的服务器 ip+port
@@ -207,6 +209,8 @@ public class CIMClient { @@ -207,6 +209,8 @@ public class CIMClient {
207 * @throws InterruptedException 209 * @throws InterruptedException
208 */ 210 */
209 public void close() throws InterruptedException { 211 public void close() throws InterruptedException {
210 - channel.close(); 212 + if (channel != null){
  213 + channel.close();
  214 + }
211 } 215 }
212 } 216 }
1 package com.crossoverjie.cim.client.service; 1 package com.crossoverjie.cim.client.service;
2 2
  3 +import com.crossoverjie.cim.client.service.impl.command.PrintAllCommand;
3 import com.crossoverjie.cim.client.util.SpringBeanFactory; 4 import com.crossoverjie.cim.client.util.SpringBeanFactory;
4 -import com.crossoverjie.cim.common.enums.SystemCommandEnumType; 5 +import com.crossoverjie.cim.common.enums.SystemCommandEnum;
  6 +import com.crossoverjie.cim.common.util.StringUtil;
5 import org.slf4j.Logger; 7 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
7 import org.springframework.stereotype.Component; 9 import org.springframework.stereotype.Component;
@@ -20,16 +22,22 @@ public class InnerCommandContext { @@ -20,16 +22,22 @@ public class InnerCommandContext {
20 private final static Logger LOGGER = LoggerFactory.getLogger(InnerCommandContext.class); 22 private final static Logger LOGGER = LoggerFactory.getLogger(InnerCommandContext.class);
21 23
22 /** 24 /**
23 - * 获取执行器  
24 - * @param command 执行器 25 + * 获取执行器实例
  26 + * @param command 执行器实例
25 * @return 27 * @return
26 */ 28 */
27 - public InnerCommand execute(String command) { 29 + public InnerCommand getInstance(String command) {
28 30
29 - Map<String, String> allClazz = SystemCommandEnumType.getAllClazz();  
30 - String clazz = allClazz.get(command); 31 + Map<String, String> allClazz = SystemCommandEnum.getAllClazz();
  32 +
  33 + //兼容需要命令后接参数的数据 :q cross
  34 + String[] trim = command.trim().split(" ");
  35 + String clazz = allClazz.get(trim[0]);
31 InnerCommand innerCommand = null; 36 InnerCommand innerCommand = null;
32 try { 37 try {
  38 + if (StringUtil.isEmpty(clazz)){
  39 + clazz = PrintAllCommand.class.getName() ;
  40 + }
33 innerCommand = (InnerCommand) SpringBeanFactory.getBean(Class.forName(clazz)); 41 innerCommand = (InnerCommand) SpringBeanFactory.getBean(Class.forName(clazz));
34 } catch (Exception e) { 42 } catch (Exception e) {
35 LOGGER.error("Exception", e); 43 LOGGER.error("Exception", e);
@@ -54,4 +54,14 @@ public interface MsgHandle { @@ -54,4 +54,14 @@ public interface MsgHandle {
54 * 关闭系统 54 * 关闭系统
55 */ 55 */
56 void shutdown() ; 56 void shutdown() ;
  57 +
  58 + /**
  59 + * 开启 AI 模式
  60 + */
  61 + void openAIModel() ;
  62 +
  63 + /**
  64 + * 关闭 AI 模式
  65 + */
  66 + void closeAIModel() ;
57 } 67 }
1 package com.crossoverjie.cim.client.service.impl; 1 package com.crossoverjie.cim.client.service.impl;
2 2
3 -import com.alibaba.fastjson.JSON;  
4 import com.crossoverjie.cim.client.client.CIMClient; 3 import com.crossoverjie.cim.client.client.CIMClient;
5 import com.crossoverjie.cim.client.config.AppConfiguration; 4 import com.crossoverjie.cim.client.config.AppConfiguration;
6 -import com.crossoverjie.cim.client.service.InnerCommandContext;  
7 -import com.crossoverjie.cim.client.service.MsgHandle;  
8 -import com.crossoverjie.cim.client.service.MsgLogger;  
9 -import com.crossoverjie.cim.client.service.RouteRequest; 5 +import com.crossoverjie.cim.client.service.*;
10 import com.crossoverjie.cim.client.vo.req.GroupReqVO; 6 import com.crossoverjie.cim.client.vo.req.GroupReqVO;
11 import com.crossoverjie.cim.client.vo.req.P2PReqVO; 7 import com.crossoverjie.cim.client.vo.req.P2PReqVO;
12 import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO; 8 import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO;
13 import com.crossoverjie.cim.common.data.construct.TrieTree; 9 import com.crossoverjie.cim.common.data.construct.TrieTree;
14 -import com.crossoverjie.cim.common.enums.SystemCommandEnumType; 10 +import com.crossoverjie.cim.common.enums.SystemCommandEnum;
15 import com.crossoverjie.cim.common.util.StringUtil; 11 import com.crossoverjie.cim.common.util.StringUtil;
16 import org.slf4j.Logger; 12 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
@@ -134,44 +130,10 @@ public class MsgHandler implements MsgHandle { @@ -134,44 +130,10 @@ public class MsgHandler implements MsgHandle {
134 @Override 130 @Override
135 public boolean innerCommand(String msg) { 131 public boolean innerCommand(String msg) {
136 132
137 - // TODO: 2019-01-22 判断逻辑过多,需要重构。  
138 if (msg.startsWith(":")) { 133 if (msg.startsWith(":")) {
139 - Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode();  
140 -  
141 - innerCommandContext.execute(msg);  
142 -  
143 - if (SystemCommandEnumType.QUIT.getCommandType().trim().equals(msg)) {  
144 - //关闭系统  
145 - shutdown();  
146 - } else if (SystemCommandEnumType.ALL.getCommandType().trim().equals(msg)) {  
147 - printAllCommand(allStatusCode);  
148 -  
149 - } else if (SystemCommandEnumType.ONLINE_USER.getCommandType().toLowerCase().trim().equals(msg.toLowerCase())) {  
150 - //打印在线用户  
151 - printOnlineUsers();  
152 -  
153 - } else if (msg.startsWith(SystemCommandEnumType.QUERY.getCommandType().trim() + " ")) {  
154 - //查询聊天记录  
155 - queryChatHistory(msg);  
156 - } else if (SystemCommandEnumType.AI.getCommandType().trim().equals(msg.toLowerCase())) {  
157 - //开启 AI 模式  
158 - aiModel = true;  
159 - System.out.println("\033[31;4m" + "Hello,我是估值两亿的 AI 机器人!" + "\033[0m");  
160 - } else if (SystemCommandEnumType.QAI.getCommandType().trim().equals(msg.toLowerCase())) {  
161 - //关闭 AI 模式  
162 - aiModel = false;  
163 - System.out.println("\033[31;4m" + "。゚(゚´ω`゚)゚。 AI 下线了!" + "\033[0m");  
164 - } else if (msg.startsWith(SystemCommandEnumType.PREFIX.getCommandType().trim() + " ")) {  
165 - //模糊匹配  
166 - prefixSearch(msg);  
167 - } else if (SystemCommandEnumType.INFO.getCommandType().trim().equals(msg.toLowerCase())) {  
168 - LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");  
169 - LOGGER.info("client info=[{}]", JSON.toJSONString(clientInfo.get()));  
170 - LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");  
171 -  
172 - } else {  
173 - printAllCommand(allStatusCode);  
174 - } 134 +
  135 + InnerCommand instance = innerCommandContext.getInstance(msg);
  136 + instance.process(msg) ;
175 137
176 return true; 138 return true;
177 139
@@ -259,6 +221,16 @@ public class MsgHandler implements MsgHandle { @@ -259,6 +221,16 @@ public class MsgHandler implements MsgHandle {
259 System.exit(0); 221 System.exit(0);
260 } 222 }
261 223
  224 + @Override
  225 + public void openAIModel() {
  226 + aiModel = true;
  227 + }
  228 +
  229 + @Override
  230 + public void closeAIModel() {
  231 + aiModel = false ;
  232 + }
  233 +
262 private void printAllCommand(Map<String, String> allStatusCode) { 234 private void printAllCommand(Map<String, String> allStatusCode) {
263 LOGGER.warn("===================================="); 235 LOGGER.warn("====================================");
264 for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) { 236 for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) {
  1 +package com.crossoverjie.cim.client.service.impl.command;
  2 +
  3 +import com.crossoverjie.cim.client.service.InnerCommand;
  4 +import com.crossoverjie.cim.client.service.MsgHandle;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Service;
  9 +
  10 +/**
  11 + * Function:
  12 + *
  13 + * @author crossoverJie
  14 + * Date: 2019-01-27 19:37
  15 + * @since JDK 1.8
  16 + */
  17 +@Service
  18 +public class CloseAIModelCommand implements InnerCommand {
  19 + private final static Logger LOGGER = LoggerFactory.getLogger(CloseAIModelCommand.class);
  20 +
  21 +
  22 + @Autowired
  23 + private MsgHandle msgHandle ;
  24 +
  25 + @Override
  26 + public void process(String msg) {
  27 + msgHandle.closeAIModel();
  28 + System.out.println("\033[31;4m" + "。゚(゚´ω`゚)゚。 AI 下线了!" + "\033[0m");
  29 + }
  30 +}
  1 +package com.crossoverjie.cim.client.service.impl.command;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.crossoverjie.cim.client.service.InnerCommand;
  5 +import com.crossoverjie.cim.client.service.impl.ClientInfo;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +/**
  12 + * Function:
  13 + *
  14 + * @author crossoverJie
  15 + * Date: 2019-01-27 19:37
  16 + * @since JDK 1.8
  17 + */
  18 +@Service
  19 +public class EchoInfoCommand implements InnerCommand {
  20 + private final static Logger LOGGER = LoggerFactory.getLogger(EchoInfoCommand.class);
  21 +
  22 +
  23 + @Autowired
  24 + private ClientInfo clientInfo;
  25 +
  26 + @Override
  27 + public void process(String msg) {
  28 + LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  29 + LOGGER.info("client info=[{}]", JSON.toJSONString(clientInfo.get()));
  30 + LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  31 + }
  32 +}
  1 +package com.crossoverjie.cim.client.service.impl.command;
  2 +
  3 +import com.crossoverjie.cim.client.service.InnerCommand;
  4 +import com.crossoverjie.cim.client.service.MsgHandle;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Service;
  9 +
  10 +/**
  11 + * Function:
  12 + *
  13 + * @author crossoverJie
  14 + * Date: 2019-01-27 19:37
  15 + * @since JDK 1.8
  16 + */
  17 +@Service
  18 +public class OpenAIModelCommand implements InnerCommand {
  19 + private final static Logger LOGGER = LoggerFactory.getLogger(OpenAIModelCommand.class);
  20 +
  21 +
  22 + @Autowired
  23 + private MsgHandle msgHandle ;
  24 +
  25 + @Override
  26 + public void process(String msg) {
  27 + msgHandle.openAIModel();
  28 + System.out.println("\033[31;4m" + "Hello,我是估值两亿的 AI 机器人!" + "\033[0m");
  29 + }
  30 +}
  1 +package com.crossoverjie.cim.client.service.impl.command;
  2 +
  3 +import com.crossoverjie.cim.client.service.InnerCommand;
  4 +import com.crossoverjie.cim.client.service.RouteRequest;
  5 +import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO;
  6 +import com.crossoverjie.cim.common.data.construct.TrieTree;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Service;
  11 +
  12 +import java.util.List;
  13 +
  14 +/**
  15 + * Function:
  16 + *
  17 + * @author crossoverJie
  18 + * Date: 2019-01-27 19:37
  19 + * @since JDK 1.8
  20 + */
  21 +@Service
  22 +public class PrefixSearchCommand implements InnerCommand {
  23 + private final static Logger LOGGER = LoggerFactory.getLogger(PrefixSearchCommand.class);
  24 +
  25 +
  26 + @Autowired
  27 + private RouteRequest routeRequest ;
  28 +
  29 + @Override
  30 + public void process(String msg) {
  31 + try {
  32 + List<OnlineUsersResVO.DataBodyBean> onlineUsers = routeRequest.onlineUsers();
  33 + TrieTree trieTree = new TrieTree();
  34 + for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) {
  35 + trieTree.insert(onlineUser.getUserName());
  36 + }
  37 +
  38 + String[] split = msg.split(" ");
  39 + String key = split[1];
  40 + List<String> list = trieTree.prefixSearch(key);
  41 +
  42 + for (String res : list) {
  43 + res = res.replace(key, "\033[31;4m" + key + "\033[0m");
  44 + System.out.println(res);
  45 + }
  46 +
  47 + } catch (Exception e) {
  48 + LOGGER.error("Exception", e);
  49 + }
  50 + }
  51 +}
1 package com.crossoverjie.cim.client.service.impl.command; 1 package com.crossoverjie.cim.client.service.impl.command;
2 2
3 import com.crossoverjie.cim.client.service.InnerCommand; 3 import com.crossoverjie.cim.client.service.InnerCommand;
4 -import com.crossoverjie.cim.common.enums.SystemCommandEnumType; 4 +import com.crossoverjie.cim.common.enums.SystemCommandEnum;
5 import org.slf4j.Logger; 5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 6 import org.slf4j.LoggerFactory;
7 import org.springframework.stereotype.Service; 7 import org.springframework.stereotype.Service;
@@ -21,7 +21,7 @@ public class PrintAllCommand implements InnerCommand { @@ -21,7 +21,7 @@ public class PrintAllCommand implements InnerCommand {
21 21
22 @Override 22 @Override
23 public void process(String msg) { 23 public void process(String msg) {
24 - Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode(); 24 + Map<String, String> allStatusCode = SystemCommandEnum.getAllStatusCode();
25 LOGGER.warn("===================================="); 25 LOGGER.warn("====================================");
26 for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) { 26 for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) {
27 String key = stringStringEntry.getKey(); 27 String key = stringStringEntry.getKey();
  1 +package com.crossoverjie.cim.client.service.impl.command;
  2 +
  3 +import com.crossoverjie.cim.client.service.InnerCommand;
  4 +import com.crossoverjie.cim.client.service.RouteRequest;
  5 +import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * Function:
  15 + *
  16 + * @author crossoverJie
  17 + * Date: 2019-01-27 19:37
  18 + * @since JDK 1.8
  19 + */
  20 +@Service
  21 +public class PrintOnlineUsersCommand implements InnerCommand {
  22 + private final static Logger LOGGER = LoggerFactory.getLogger(PrintOnlineUsersCommand.class);
  23 +
  24 +
  25 + @Autowired
  26 + private RouteRequest routeRequest ;
  27 +
  28 + @Override
  29 + public void process(String msg) {
  30 + try {
  31 + List<OnlineUsersResVO.DataBodyBean> onlineUsers = routeRequest.onlineUsers();
  32 +
  33 + LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  34 + for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) {
  35 + LOGGER.info("userId={}=====userName={}", onlineUser.getUserId(), onlineUser.getUserName());
  36 + }
  37 + LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  38 +
  39 + } catch (Exception e) {
  40 + LOGGER.error("Exception", e);
  41 + }
  42 + }
  43 +}
  1 +package com.crossoverjie.cim.client.service.impl.command;
  2 +
  3 +import com.crossoverjie.cim.client.service.InnerCommand;
  4 +import com.crossoverjie.cim.client.service.MsgLogger;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Service;
  9 +
  10 +/**
  11 + * Function:
  12 + *
  13 + * @author crossoverJie
  14 + * Date: 2019-01-27 19:37
  15 + * @since JDK 1.8
  16 + */
  17 +@Service
  18 +public class QueryHistoryCommand implements InnerCommand {
  19 + private final static Logger LOGGER = LoggerFactory.getLogger(QueryHistoryCommand.class);
  20 +
  21 +
  22 + @Autowired
  23 + private MsgLogger msgLogger ;
  24 +
  25 + @Override
  26 + public void process(String msg) {
  27 + String[] split = msg.split(" ");
  28 + String res = msgLogger.query(split[1]);
  29 + System.out.println(res);
  30 + }
  31 +}
1 package com.crossoverjie.cim.client.service; 1 package com.crossoverjie.cim.client.service;
2 2
3 import com.crossoverjie.cim.client.CIMClientApplication; 3 import com.crossoverjie.cim.client.CIMClientApplication;
  4 +import com.crossoverjie.cim.common.enums.SystemCommandEnum;
4 import org.junit.Test; 5 import org.junit.Test;
5 import org.junit.runner.RunWith; 6 import org.junit.runner.RunWith;
6 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
@@ -17,7 +18,72 @@ public class InnerCommandContextTest { @@ -17,7 +18,72 @@ public class InnerCommandContextTest {
17 @Test 18 @Test
18 public void execute() { 19 public void execute() {
19 String msg = ":all"; 20 String msg = ":all";
20 - InnerCommand execute = context.execute(msg); 21 + InnerCommand execute = context.getInstance(msg);
  22 + execute.process(msg) ;
  23 + }
  24 +
  25 + @Test
  26 + public void execute3() {
  27 + String msg = SystemCommandEnum.ONLINE_USER.getCommandType();
  28 + InnerCommand execute = context.getInstance(msg);
  29 + execute.process(msg) ;
  30 + }
  31 +
  32 + @Test
  33 + public void execute4() {
  34 + String msg = ":q 天气";
  35 + InnerCommand execute = context.getInstance(msg);
  36 + execute.process(msg) ;
  37 + }
  38 +
  39 + @Test
  40 + public void execute5() {
  41 + String msg = ":q crossoverJie";
  42 + InnerCommand execute = context.getInstance(msg);
  43 + execute.process(msg) ;
  44 + }
  45 +
  46 + @Test
  47 + public void execute6() {
  48 + String msg = SystemCommandEnum.AI.getCommandType();
  49 + InnerCommand execute = context.getInstance(msg);
  50 + execute.process(msg) ;
  51 + }
  52 +
  53 + @Test
  54 + public void execute7() {
  55 + String msg = SystemCommandEnum.QAI.getCommandType();
  56 + InnerCommand execute = context.getInstance(msg);
  57 + execute.process(msg) ;
  58 + }
  59 +
  60 + @Test
  61 + public void execute8() {
  62 + String msg = ":pu cross";
  63 + InnerCommand execute = context.getInstance(msg);
  64 + execute.process(msg) ;
  65 + }
  66 +
  67 + @Test
  68 + public void execute9() {
  69 + String msg = SystemCommandEnum.INFO.getCommandType();
  70 + InnerCommand execute = context.getInstance(msg);
  71 + execute.process(msg) ;
  72 + }
  73 +
  74 + @Test
  75 + public void execute10() {
  76 + String msg = "dsds";
  77 + InnerCommand execute = context.getInstance(msg);
  78 + execute.process(msg) ;
  79 + }
  80 +
  81 +
  82 +
  83 + // @Test
  84 + public void quit() {
  85 + String msg = ":q!";
  86 + InnerCommand execute = context.getInstance(msg);
21 execute.process(msg) ; 87 execute.process(msg) ;
22 } 88 }
23 } 89 }
@@ -10,16 +10,16 @@ import java.util.Map; @@ -10,16 +10,16 @@ import java.util.Map;
10 * Date: 2018/12/26 18:38 10 * Date: 2018/12/26 18:38
11 * @since JDK 1.8 11 * @since JDK 1.8
12 */ 12 */
13 -public enum SystemCommandEnumType { 13 +public enum SystemCommandEnum {
14 14
15 ALL(":all ","获取所有命令","PrintAllCommand"), 15 ALL(":all ","获取所有命令","PrintAllCommand"),
16 - ONLINE_USER(":olu ","获取所有在线用户",""), 16 + ONLINE_USER(":olu ","获取所有在线用户","PrintOnlineUsersCommand"),
17 QUIT(":q! ","退出程序","ShutDownCommand"), 17 QUIT(":q! ","退出程序","ShutDownCommand"),
18 - QUERY(":q ","【:q 关键字】查询聊天记录",""),  
19 - AI(":ai ","开启 AI 模式",""),  
20 - QAI(":qai ","关闭 AI 模式",""),  
21 - PREFIX(":pu ","模糊匹配用户",""),  
22 - INFO(":info ","获取客户端信息","") 18 + QUERY(":q ","【:q 关键字】查询聊天记录","QueryHistoryCommand"),
  19 + AI(":ai ","开启 AI 模式","OpenAIModelCommand"),
  20 + QAI(":qai ","关闭 AI 模式","CloseAIModelCommand"),
  21 + PREFIX(":pu ","模糊匹配用户","PrefixSearchCommand"),
  22 + INFO(":info ","获取客户端信息","EchoInfoCommand")
23 23
24 ; 24 ;
25 25
@@ -29,6 +29,9 @@ public enum SystemCommandEnumType { @@ -29,6 +29,9 @@ public enum SystemCommandEnumType {
29 /** 枚举描述 */ 29 /** 枚举描述 */
30 private final String desc; 30 private final String desc;
31 31
  32 + /**
  33 + * 实现类
  34 + */
32 private final String clazz ; 35 private final String clazz ;
33 36
34 37
@@ -37,7 +40,7 @@ public enum SystemCommandEnumType { @@ -37,7 +40,7 @@ public enum SystemCommandEnumType {
37 * @param commandType 枚举值码。 40 * @param commandType 枚举值码。
38 * @param desc 枚举描述。 41 * @param desc 枚举描述。
39 */ 42 */
40 - private SystemCommandEnumType(String commandType, String desc,String clazz) { 43 + private SystemCommandEnum(String commandType, String desc, String clazz) {
41 this.commandType = commandType; 44 this.commandType = commandType;
42 this.desc = desc; 45 this.desc = desc;
43 this.clazz = clazz ; 46 this.clazz = clazz ;
@@ -89,7 +92,7 @@ public enum SystemCommandEnumType { @@ -89,7 +92,7 @@ public enum SystemCommandEnumType {
89 */ 92 */
90 public static Map<String,String> getAllStatusCode() { 93 public static Map<String,String> getAllStatusCode() {
91 Map<String,String> map = new HashMap<String, String>(16) ; 94 Map<String,String> map = new HashMap<String, String>(16) ;
92 - for (SystemCommandEnumType status : values()) { 95 + for (SystemCommandEnum status : values()) {
93 map.put(status.getCommandType(),status.getDesc()) ; 96 map.put(status.getCommandType(),status.getDesc()) ;
94 } 97 }
95 return map; 98 return map;
@@ -97,7 +100,7 @@ public enum SystemCommandEnumType { @@ -97,7 +100,7 @@ public enum SystemCommandEnumType {
97 100
98 public static Map<String,String> getAllClazz() { 101 public static Map<String,String> getAllClazz() {
99 Map<String,String> map = new HashMap<String, String>(16) ; 102 Map<String,String> map = new HashMap<String, String>(16) ;
100 - for (SystemCommandEnumType status : values()) { 103 + for (SystemCommandEnum status : values()) {
101 map.put(status.getCommandType().trim(),"com.crossoverjie.cim.client.service.impl.command." + status.getClazz()) ; 104 map.put(status.getCommandType().trim(),"com.crossoverjie.cim.client.service.impl.command." + status.getClazz()) ;
102 } 105 }
103 return map; 106 return map;
@@ -9,7 +9,7 @@ public class SystemCommandEnumTypeTest { @@ -9,7 +9,7 @@ public class SystemCommandEnumTypeTest {
9 9
10 @Test 10 @Test
11 public void getAllStatusCode() throws Exception { 11 public void getAllStatusCode() throws Exception {
12 - Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode(); 12 + Map<String, String> allStatusCode = SystemCommandEnum.getAllStatusCode();
13 for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) { 13 for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) {
14 String key = stringStringEntry.getKey(); 14 String key = stringStringEntry.getKey();
15 String value = stringStringEntry.getValue(); 15 String value = stringStringEntry.getValue();