|
|
|
package com.crossoverjie.cim.client.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.crossoverjie.cim.client.client.CIMClient;
|
|
|
|
import com.crossoverjie.cim.client.config.AppConfiguration;
|
|
|
|
import com.crossoverjie.cim.client.service.MsgHandle;
|
|
...
|
...
|
@@ -33,33 +34,37 @@ import java.util.concurrent.TimeUnit; |
|
|
|
public class MsgHandler implements MsgHandle {
|
|
|
|
private final static Logger LOGGER = LoggerFactory.getLogger(MsgHandler.class);
|
|
|
|
@Autowired
|
|
|
|
private RouteRequest routeRequest ;
|
|
|
|
private RouteRequest routeRequest;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private AppConfiguration configuration;
|
|
|
|
|
|
|
|
@Resource(name = "callBackThreadPool")
|
|
|
|
private ThreadPoolExecutor executor ;
|
|
|
|
private ThreadPoolExecutor executor;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private CIMClient cimClient ;
|
|
|
|
private CIMClient cimClient;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private MsgLogger msgLogger ;
|
|
|
|
private MsgLogger msgLogger;
|
|
|
|
|
|
|
|
private boolean aiModel = false ;
|
|
|
|
@Autowired
|
|
|
|
private ClientInfo clientInfo ;
|
|
|
|
|
|
|
|
private boolean aiModel = false;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendMsg(String msg) {
|
|
|
|
if (aiModel){
|
|
|
|
if (aiModel) {
|
|
|
|
aiChat(msg);
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
normalChat(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 正常聊天
|
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
*/
|
|
|
|
private void normalChat(String msg) {
|
|
...
|
...
|
@@ -73,7 +78,7 @@ public class MsgHandler implements MsgHandle { |
|
|
|
try {
|
|
|
|
p2pChat(p2PReqVO);
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOGGER.error("Exception",e);
|
|
|
|
LOGGER.error("Exception", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
...
|
...
|
@@ -82,21 +87,22 @@ public class MsgHandler implements MsgHandle { |
|
|
|
try {
|
|
|
|
groupChat(groupReqVO);
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOGGER.error("Exception",e);
|
|
|
|
LOGGER.error("Exception", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AI model
|
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
*/
|
|
|
|
private void aiChat(String msg) {
|
|
|
|
msg = msg.replace("吗","") ;
|
|
|
|
msg = msg.replace("嘛","") ;
|
|
|
|
msg = msg.replace("?","!");
|
|
|
|
msg = msg.replace("?","!");
|
|
|
|
msg = msg.replace("你","我");
|
|
|
|
msg = msg.replace("吗", "");
|
|
|
|
msg = msg.replace("嘛", "");
|
|
|
|
msg = msg.replace("?", "!");
|
|
|
|
msg = msg.replace("?", "!");
|
|
|
|
msg = msg.replace("你", "我");
|
|
|
|
System.out.println("AI:\033[31;4m" + msg + "\033[0m");
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -114,7 +120,7 @@ public class MsgHandler implements MsgHandle { |
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean checkMsg(String msg) {
|
|
|
|
if (StringUtil.isEmpty(msg)){
|
|
|
|
if (StringUtil.isEmpty(msg)) {
|
|
|
|
LOGGER.warn("不能发送空消息!");
|
|
|
|
return true;
|
|
|
|
}
|
|
...
|
...
|
@@ -124,41 +130,46 @@ public class MsgHandler implements MsgHandle { |
|
|
|
@Override
|
|
|
|
public boolean innerCommand(String msg) {
|
|
|
|
|
|
|
|
if (msg.startsWith(":")){
|
|
|
|
if (msg.startsWith(":")) {
|
|
|
|
Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode();
|
|
|
|
|
|
|
|
if (SystemCommandEnumType.QUIT.getCommandType().trim().equals(msg)){
|
|
|
|
if (SystemCommandEnumType.QUIT.getCommandType().trim().equals(msg)) {
|
|
|
|
//关闭系统
|
|
|
|
shutdown();
|
|
|
|
} else if (SystemCommandEnumType.ALL.getCommandType().trim().equals(msg)){
|
|
|
|
} else if (SystemCommandEnumType.ALL.getCommandType().trim().equals(msg)) {
|
|
|
|
printAllCommand(allStatusCode);
|
|
|
|
|
|
|
|
} else if (SystemCommandEnumType.ONLINE_USER.getCommandType().toLowerCase().trim().equals(msg.toLowerCase())){
|
|
|
|
} else if (SystemCommandEnumType.ONLINE_USER.getCommandType().toLowerCase().trim().equals(msg.toLowerCase())) {
|
|
|
|
//打印在线用户
|
|
|
|
printOnlineUsers();
|
|
|
|
|
|
|
|
} else if (msg.startsWith(SystemCommandEnumType.QUERY.getCommandType().trim() + " ")){
|
|
|
|
} else if (msg.startsWith(SystemCommandEnumType.QUERY.getCommandType().trim() + " ")) {
|
|
|
|
//查询聊天记录
|
|
|
|
queryChatHistory(msg);
|
|
|
|
}else if (SystemCommandEnumType.AI.getCommandType().trim().equals(msg.toLowerCase())){
|
|
|
|
} else if (SystemCommandEnumType.AI.getCommandType().trim().equals(msg.toLowerCase())) {
|
|
|
|
//开启 AI 模式
|
|
|
|
aiModel = true ;
|
|
|
|
aiModel = true;
|
|
|
|
System.out.println("\033[31;4m" + "Hello,我是估值两亿的 AI 机器人!" + "\033[0m");
|
|
|
|
}else if (SystemCommandEnumType.QAI.getCommandType().trim().equals(msg.toLowerCase())){
|
|
|
|
} else if (SystemCommandEnumType.QAI.getCommandType().trim().equals(msg.toLowerCase())) {
|
|
|
|
//关闭 AI 模式
|
|
|
|
aiModel = false ;
|
|
|
|
aiModel = false;
|
|
|
|
System.out.println("\033[31;4m" + "。゚(゚´ω`゚)゚。 AI 下线了!" + "\033[0m");
|
|
|
|
}else if (msg.startsWith(SystemCommandEnumType.PREFIX.getCommandType().trim() + " ")){
|
|
|
|
} else if (msg.startsWith(SystemCommandEnumType.PREFIX.getCommandType().trim() + " ")) {
|
|
|
|
//模糊匹配
|
|
|
|
prefixSearch(msg);
|
|
|
|
}else {
|
|
|
|
} else if (SystemCommandEnumType.INFO.getCommandType().trim().equals(msg.toLowerCase())) {
|
|
|
|
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
|
|
LOGGER.info("client info=[{}]", JSON.toJSONString(clientInfo.get()));
|
|
|
|
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
printAllCommand(allStatusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}else {
|
|
|
|
return false ;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
...
|
...
|
@@ -167,12 +178,13 @@ public class MsgHandler implements MsgHandle { |
|
|
|
|
|
|
|
/**
|
|
|
|
* 模糊匹配
|
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
*/
|
|
|
|
private void prefixSearch(String msg) {
|
|
|
|
try {
|
|
|
|
List<OnlineUsersResVO.DataBodyBean> onlineUsers = routeRequest.onlineUsers();
|
|
|
|
TrieTree trieTree = new TrieTree() ;
|
|
|
|
TrieTree trieTree = new TrieTree();
|
|
|
|
for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) {
|
|
|
|
trieTree.insert(onlineUser.getUserName());
|
|
|
|
}
|
|
...
|
...
|
@@ -187,16 +199,17 @@ public class MsgHandler implements MsgHandle { |
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOGGER.error("Exception" ,e);
|
|
|
|
LOGGER.error("Exception", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询聊天记录
|
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
*/
|
|
|
|
private void queryChatHistory(String msg) {
|
|
|
|
String[] split = msg.split(" ") ;
|
|
|
|
String[] split = msg.split(" ");
|
|
|
|
String res = msgLogger.query(split[1]);
|
|
|
|
System.out.println(res);
|
|
|
|
}
|
|
...
|
...
|
@@ -210,12 +223,12 @@ public class MsgHandler implements MsgHandle { |
|
|
|
|
|
|
|
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
|
|
for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) {
|
|
|
|
LOGGER.info("userId={}=====userName={}",onlineUser.getUserId(),onlineUser.getUserName());
|
|
|
|
LOGGER.info("userId={}=====userName={}", onlineUser.getUserId(), onlineUser.getUserName());
|
|
|
|
}
|
|
|
|
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOGGER.error("Exception" ,e);
|
|
|
|
LOGGER.error("Exception", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -234,7 +247,7 @@ public class MsgHandler implements MsgHandle { |
|
|
|
}
|
|
|
|
cimClient.close();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
LOGGER.error("InterruptedException",e);
|
|
|
|
LOGGER.error("InterruptedException", e);
|
|
|
|
}
|
|
|
|
System.exit(0);
|
|
|
|
}
|
...
|
...
|
|