-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from crossoverJie/cim-1.0.3
cim 1.0.3
- Loading branch information
Showing
17 changed files
with
527 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
cim-client/src/main/java/com/crossoverjie/cim/client/service/InnerCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.crossoverjie.cim.client.service; | ||
|
||
/** | ||
* Function: | ||
* | ||
* @author crossoverJie | ||
* Date: 2019-01-27 19:26 | ||
* @since JDK 1.8 | ||
*/ | ||
public interface InnerCommand { | ||
|
||
/** | ||
* 执行 | ||
* @param msg | ||
*/ | ||
void process(String msg) ; | ||
} |
49 changes: 49 additions & 0 deletions
49
cim-client/src/main/java/com/crossoverjie/cim/client/service/InnerCommandContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.crossoverjie.cim.client.service; | ||
|
||
import com.crossoverjie.cim.client.service.impl.command.PrintAllCommand; | ||
import com.crossoverjie.cim.client.util.SpringBeanFactory; | ||
import com.crossoverjie.cim.common.enums.SystemCommandEnum; | ||
import com.crossoverjie.cim.common.util.StringUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Function: | ||
* | ||
* @author crossoverJie | ||
* Date: 2019-01-27 19:39 | ||
* @since JDK 1.8 | ||
*/ | ||
@Component | ||
public class InnerCommandContext { | ||
private final static Logger LOGGER = LoggerFactory.getLogger(InnerCommandContext.class); | ||
|
||
/** | ||
* 获取执行器实例 | ||
* @param command 执行器实例 | ||
* @return | ||
*/ | ||
public InnerCommand getInstance(String command) { | ||
|
||
Map<String, String> allClazz = SystemCommandEnum.getAllClazz(); | ||
|
||
//兼容需要命令后接参数的数据 :q cross | ||
String[] trim = command.trim().split(" "); | ||
String clazz = allClazz.get(trim[0]); | ||
InnerCommand innerCommand = null; | ||
try { | ||
if (StringUtil.isEmpty(clazz)){ | ||
clazz = PrintAllCommand.class.getName() ; | ||
} | ||
innerCommand = (InnerCommand) SpringBeanFactory.getBean(Class.forName(clazz)); | ||
} catch (Exception e) { | ||
LOGGER.error("Exception", e); | ||
} | ||
|
||
return innerCommand; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...t/src/main/java/com/crossoverjie/cim/client/service/impl/command/CloseAIModelCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.crossoverjie.cim.client.service.impl.command; | ||
|
||
import com.crossoverjie.cim.client.service.InnerCommand; | ||
import com.crossoverjie.cim.client.service.MsgHandle; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Function: | ||
* | ||
* @author crossoverJie | ||
* Date: 2019-01-27 19:37 | ||
* @since JDK 1.8 | ||
*/ | ||
@Service | ||
public class CloseAIModelCommand implements InnerCommand { | ||
private final static Logger LOGGER = LoggerFactory.getLogger(CloseAIModelCommand.class); | ||
|
||
|
||
@Autowired | ||
private MsgHandle msgHandle ; | ||
|
||
@Override | ||
public void process(String msg) { | ||
msgHandle.closeAIModel(); | ||
System.out.println("\033[31;4m" + "。゚(゚´ω`゚)゚。 AI 下线了!" + "\033[0m"); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...lient/src/main/java/com/crossoverjie/cim/client/service/impl/command/EchoInfoCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.crossoverjie.cim.client.service.impl.command; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.crossoverjie.cim.client.service.InnerCommand; | ||
import com.crossoverjie.cim.client.service.impl.ClientInfo; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Function: | ||
* | ||
* @author crossoverJie | ||
* Date: 2019-01-27 19:37 | ||
* @since JDK 1.8 | ||
*/ | ||
@Service | ||
public class EchoInfoCommand implements InnerCommand { | ||
private final static Logger LOGGER = LoggerFactory.getLogger(EchoInfoCommand.class); | ||
|
||
|
||
@Autowired | ||
private ClientInfo clientInfo; | ||
|
||
@Override | ||
public void process(String msg) { | ||
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | ||
LOGGER.info("client info=[{}]", JSON.toJSONString(clientInfo.get())); | ||
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...nt/src/main/java/com/crossoverjie/cim/client/service/impl/command/OpenAIModelCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.crossoverjie.cim.client.service.impl.command; | ||
|
||
import com.crossoverjie.cim.client.service.InnerCommand; | ||
import com.crossoverjie.cim.client.service.MsgHandle; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Function: | ||
* | ||
* @author crossoverJie | ||
* Date: 2019-01-27 19:37 | ||
* @since JDK 1.8 | ||
*/ | ||
@Service | ||
public class OpenAIModelCommand implements InnerCommand { | ||
private final static Logger LOGGER = LoggerFactory.getLogger(OpenAIModelCommand.class); | ||
|
||
|
||
@Autowired | ||
private MsgHandle msgHandle ; | ||
|
||
@Override | ||
public void process(String msg) { | ||
msgHandle.openAIModel(); | ||
System.out.println("\033[31;4m" + "Hello,我是估值两亿的 AI 机器人!" + "\033[0m"); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...t/src/main/java/com/crossoverjie/cim/client/service/impl/command/PrefixSearchCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.crossoverjie.cim.client.service.impl.command; | ||
|
||
import com.crossoverjie.cim.client.service.InnerCommand; | ||
import com.crossoverjie.cim.client.service.RouteRequest; | ||
import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO; | ||
import com.crossoverjie.cim.common.data.construct.TrieTree; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Function: | ||
* | ||
* @author crossoverJie | ||
* Date: 2019-01-27 19:37 | ||
* @since JDK 1.8 | ||
*/ | ||
@Service | ||
public class PrefixSearchCommand implements InnerCommand { | ||
private final static Logger LOGGER = LoggerFactory.getLogger(PrefixSearchCommand.class); | ||
|
||
|
||
@Autowired | ||
private RouteRequest routeRequest ; | ||
|
||
@Override | ||
public void process(String msg) { | ||
try { | ||
List<OnlineUsersResVO.DataBodyBean> onlineUsers = routeRequest.onlineUsers(); | ||
TrieTree trieTree = new TrieTree(); | ||
for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) { | ||
trieTree.insert(onlineUser.getUserName()); | ||
} | ||
|
||
String[] split = msg.split(" "); | ||
String key = split[1]; | ||
List<String> list = trieTree.prefixSearch(key); | ||
|
||
for (String res : list) { | ||
res = res.replace(key, "\033[31;4m" + key + "\033[0m"); | ||
System.out.println(res); | ||
} | ||
|
||
} catch (Exception e) { | ||
LOGGER.error("Exception", e); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...lient/src/main/java/com/crossoverjie/cim/client/service/impl/command/PrintAllCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.crossoverjie.cim.client.service.impl.command; | ||
|
||
import com.crossoverjie.cim.client.service.InnerCommand; | ||
import com.crossoverjie.cim.common.enums.SystemCommandEnum; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Function: | ||
* | ||
* @author crossoverJie | ||
* Date: 2019-01-27 19:37 | ||
* @since JDK 1.8 | ||
*/ | ||
@Service | ||
public class PrintAllCommand implements InnerCommand { | ||
private final static Logger LOGGER = LoggerFactory.getLogger(PrintAllCommand.class); | ||
|
||
@Override | ||
public void process(String msg) { | ||
Map<String, String> allStatusCode = SystemCommandEnum.getAllStatusCode(); | ||
LOGGER.warn("===================================="); | ||
for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) { | ||
String key = stringStringEntry.getKey(); | ||
String value = stringStringEntry.getValue(); | ||
LOGGER.warn(key + "----->" + value); | ||
} | ||
LOGGER.warn("===================================="); | ||
} | ||
} |
Oops, something went wrong.