|
1
|
package com.crossoverjie.cim.client.service.impl;
|
1
|
package com.crossoverjie.cim.client.service.impl;
|
|
2
|
|
2
|
|
|
|
|
3
|
+import com.alibaba.fastjson.JSON;
|
|
3
|
import com.crossoverjie.cim.client.client.CIMClient;
|
4
|
import com.crossoverjie.cim.client.client.CIMClient;
|
|
4
|
import com.crossoverjie.cim.client.config.AppConfiguration;
|
5
|
import com.crossoverjie.cim.client.config.AppConfiguration;
|
|
5
|
import com.crossoverjie.cim.client.service.MsgHandle;
|
6
|
import com.crossoverjie.cim.client.service.MsgHandle;
|
|
@@ -33,33 +34,37 @@ import java.util.concurrent.TimeUnit; |
|
@@ -33,33 +34,37 @@ import java.util.concurrent.TimeUnit; |
|
33
|
public class MsgHandler implements MsgHandle {
|
34
|
public class MsgHandler implements MsgHandle {
|
|
34
|
private final static Logger LOGGER = LoggerFactory.getLogger(MsgHandler.class);
|
35
|
private final static Logger LOGGER = LoggerFactory.getLogger(MsgHandler.class);
|
|
35
|
@Autowired
|
36
|
@Autowired
|
|
36
|
- private RouteRequest routeRequest ;
|
37
|
+ private RouteRequest routeRequest;
|
|
37
|
|
38
|
|
|
38
|
@Autowired
|
39
|
@Autowired
|
|
39
|
private AppConfiguration configuration;
|
40
|
private AppConfiguration configuration;
|
|
40
|
|
41
|
|
|
41
|
@Resource(name = "callBackThreadPool")
|
42
|
@Resource(name = "callBackThreadPool")
|
|
42
|
- private ThreadPoolExecutor executor ;
|
43
|
+ private ThreadPoolExecutor executor;
|
|
43
|
|
44
|
|
|
44
|
@Autowired
|
45
|
@Autowired
|
|
45
|
- private CIMClient cimClient ;
|
46
|
+ private CIMClient cimClient;
|
|
46
|
|
47
|
|
|
47
|
@Autowired
|
48
|
@Autowired
|
|
48
|
- private MsgLogger msgLogger ;
|
49
|
+ private MsgLogger msgLogger;
|
|
49
|
|
50
|
|
|
50
|
- private boolean aiModel = false ;
|
51
|
+ @Autowired
|
|
|
|
52
|
+ private ClientInfo clientInfo ;
|
|
|
|
53
|
+
|
|
|
|
54
|
+ private boolean aiModel = false;
|
|
51
|
|
55
|
|
|
52
|
@Override
|
56
|
@Override
|
|
53
|
public void sendMsg(String msg) {
|
57
|
public void sendMsg(String msg) {
|
|
54
|
- if (aiModel){
|
58
|
+ if (aiModel) {
|
|
55
|
aiChat(msg);
|
59
|
aiChat(msg);
|
|
56
|
- }else {
|
60
|
+ } else {
|
|
57
|
normalChat(msg);
|
61
|
normalChat(msg);
|
|
58
|
}
|
62
|
}
|
|
59
|
}
|
63
|
}
|
|
60
|
|
64
|
|
|
61
|
/**
|
65
|
/**
|
|
62
|
* 正常聊天
|
66
|
* 正常聊天
|
|
|
|
67
|
+ *
|
|
63
|
* @param msg
|
68
|
* @param msg
|
|
64
|
*/
|
69
|
*/
|
|
65
|
private void normalChat(String msg) {
|
70
|
private void normalChat(String msg) {
|
|
@@ -73,7 +78,7 @@ public class MsgHandler implements MsgHandle { |
|
@@ -73,7 +78,7 @@ public class MsgHandler implements MsgHandle { |
|
73
|
try {
|
78
|
try {
|
|
74
|
p2pChat(p2PReqVO);
|
79
|
p2pChat(p2PReqVO);
|
|
75
|
} catch (Exception e) {
|
80
|
} catch (Exception e) {
|
|
76
|
- LOGGER.error("Exception",e);
|
81
|
+ LOGGER.error("Exception", e);
|
|
77
|
}
|
82
|
}
|
|
78
|
|
83
|
|
|
79
|
} else {
|
84
|
} else {
|
|
@@ -82,21 +87,22 @@ public class MsgHandler implements MsgHandle { |
|
@@ -82,21 +87,22 @@ public class MsgHandler implements MsgHandle { |
|
82
|
try {
|
87
|
try {
|
|
83
|
groupChat(groupReqVO);
|
88
|
groupChat(groupReqVO);
|
|
84
|
} catch (Exception e) {
|
89
|
} catch (Exception e) {
|
|
85
|
- LOGGER.error("Exception",e);
|
90
|
+ LOGGER.error("Exception", e);
|
|
86
|
}
|
91
|
}
|
|
87
|
}
|
92
|
}
|
|
88
|
}
|
93
|
}
|
|
89
|
|
94
|
|
|
90
|
/**
|
95
|
/**
|
|
91
|
* AI model
|
96
|
* AI model
|
|
|
|
97
|
+ *
|
|
92
|
* @param msg
|
98
|
* @param msg
|
|
93
|
*/
|
99
|
*/
|
|
94
|
private void aiChat(String msg) {
|
100
|
private void aiChat(String msg) {
|
|
95
|
- msg = msg.replace("吗","") ;
|
|
|
|
96
|
- msg = msg.replace("嘛","") ;
|
|
|
|
97
|
- msg = msg.replace("?","!");
|
|
|
|
98
|
- msg = msg.replace("?","!");
|
|
|
|
99
|
- msg = msg.replace("你","我");
|
101
|
+ msg = msg.replace("吗", "");
|
|
|
|
102
|
+ msg = msg.replace("嘛", "");
|
|
|
|
103
|
+ msg = msg.replace("?", "!");
|
|
|
|
104
|
+ msg = msg.replace("?", "!");
|
|
|
|
105
|
+ msg = msg.replace("你", "我");
|
|
100
|
System.out.println("AI:\033[31;4m" + msg + "\033[0m");
|
106
|
System.out.println("AI:\033[31;4m" + msg + "\033[0m");
|
|
101
|
}
|
107
|
}
|
|
102
|
|
108
|
|
|
@@ -114,7 +120,7 @@ public class MsgHandler implements MsgHandle { |
|
@@ -114,7 +120,7 @@ public class MsgHandler implements MsgHandle { |
|
114
|
|
120
|
|
|
115
|
@Override
|
121
|
@Override
|
|
116
|
public boolean checkMsg(String msg) {
|
122
|
public boolean checkMsg(String msg) {
|
|
117
|
- if (StringUtil.isEmpty(msg)){
|
123
|
+ if (StringUtil.isEmpty(msg)) {
|
|
118
|
LOGGER.warn("不能发送空消息!");
|
124
|
LOGGER.warn("不能发送空消息!");
|
|
119
|
return true;
|
125
|
return true;
|
|
120
|
}
|
126
|
}
|
|
@@ -124,41 +130,46 @@ public class MsgHandler implements MsgHandle { |
|
@@ -124,41 +130,46 @@ public class MsgHandler implements MsgHandle { |
|
124
|
@Override
|
130
|
@Override
|
|
125
|
public boolean innerCommand(String msg) {
|
131
|
public boolean innerCommand(String msg) {
|
|
126
|
|
132
|
|
|
127
|
- if (msg.startsWith(":")){
|
133
|
+ if (msg.startsWith(":")) {
|
|
128
|
Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode();
|
134
|
Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode();
|
|
129
|
|
135
|
|
|
130
|
- if (SystemCommandEnumType.QUIT.getCommandType().trim().equals(msg)){
|
136
|
+ if (SystemCommandEnumType.QUIT.getCommandType().trim().equals(msg)) {
|
|
131
|
//关闭系统
|
137
|
//关闭系统
|
|
132
|
shutdown();
|
138
|
shutdown();
|
|
133
|
- } else if (SystemCommandEnumType.ALL.getCommandType().trim().equals(msg)){
|
139
|
+ } else if (SystemCommandEnumType.ALL.getCommandType().trim().equals(msg)) {
|
|
134
|
printAllCommand(allStatusCode);
|
140
|
printAllCommand(allStatusCode);
|
|
135
|
|
141
|
|
|
136
|
- } else if (SystemCommandEnumType.ONLINE_USER.getCommandType().toLowerCase().trim().equals(msg.toLowerCase())){
|
142
|
+ } else if (SystemCommandEnumType.ONLINE_USER.getCommandType().toLowerCase().trim().equals(msg.toLowerCase())) {
|
|
137
|
//打印在线用户
|
143
|
//打印在线用户
|
|
138
|
printOnlineUsers();
|
144
|
printOnlineUsers();
|
|
139
|
|
145
|
|
|
140
|
- } else if (msg.startsWith(SystemCommandEnumType.QUERY.getCommandType().trim() + " ")){
|
146
|
+ } else if (msg.startsWith(SystemCommandEnumType.QUERY.getCommandType().trim() + " ")) {
|
|
141
|
//查询聊天记录
|
147
|
//查询聊天记录
|
|
142
|
queryChatHistory(msg);
|
148
|
queryChatHistory(msg);
|
|
143
|
- }else if (SystemCommandEnumType.AI.getCommandType().trim().equals(msg.toLowerCase())){
|
149
|
+ } else if (SystemCommandEnumType.AI.getCommandType().trim().equals(msg.toLowerCase())) {
|
|
144
|
//开启 AI 模式
|
150
|
//开启 AI 模式
|
|
145
|
- aiModel = true ;
|
151
|
+ aiModel = true;
|
|
146
|
System.out.println("\033[31;4m" + "Hello,我是估值两亿的 AI 机器人!" + "\033[0m");
|
152
|
System.out.println("\033[31;4m" + "Hello,我是估值两亿的 AI 机器人!" + "\033[0m");
|
|
147
|
- }else if (SystemCommandEnumType.QAI.getCommandType().trim().equals(msg.toLowerCase())){
|
153
|
+ } else if (SystemCommandEnumType.QAI.getCommandType().trim().equals(msg.toLowerCase())) {
|
|
148
|
//关闭 AI 模式
|
154
|
//关闭 AI 模式
|
|
149
|
- aiModel = false ;
|
155
|
+ aiModel = false;
|
|
150
|
System.out.println("\033[31;4m" + "。゚(゚´ω`゚)゚。 AI 下线了!" + "\033[0m");
|
156
|
System.out.println("\033[31;4m" + "。゚(゚´ω`゚)゚。 AI 下线了!" + "\033[0m");
|
|
151
|
- }else if (msg.startsWith(SystemCommandEnumType.PREFIX.getCommandType().trim() + " ")){
|
157
|
+ } else if (msg.startsWith(SystemCommandEnumType.PREFIX.getCommandType().trim() + " ")) {
|
|
152
|
//模糊匹配
|
158
|
//模糊匹配
|
|
153
|
prefixSearch(msg);
|
159
|
prefixSearch(msg);
|
|
154
|
- }else {
|
160
|
+ } else if (SystemCommandEnumType.INFO.getCommandType().trim().equals(msg.toLowerCase())) {
|
|
|
|
161
|
+ LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
|
|
162
|
+ LOGGER.info("client info=[{}]", JSON.toJSONString(clientInfo.get()));
|
|
|
|
163
|
+ LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
|
|
164
|
+
|
|
|
|
165
|
+ } else {
|
|
155
|
printAllCommand(allStatusCode);
|
166
|
printAllCommand(allStatusCode);
|
|
156
|
}
|
167
|
}
|
|
157
|
|
168
|
|
|
158
|
- return true ;
|
169
|
+ return true;
|
|
159
|
|
170
|
|
|
160
|
- }else {
|
|
|
|
161
|
- return false ;
|
171
|
+ } else {
|
|
|
|
172
|
+ return false;
|
|
162
|
}
|
173
|
}
|
|
163
|
|
174
|
|
|
164
|
|
175
|
|
|
@@ -167,12 +178,13 @@ public class MsgHandler implements MsgHandle { |
|
@@ -167,12 +178,13 @@ public class MsgHandler implements MsgHandle { |
|
167
|
|
178
|
|
|
168
|
/**
|
179
|
/**
|
|
169
|
* 模糊匹配
|
180
|
* 模糊匹配
|
|
|
|
181
|
+ *
|
|
170
|
* @param msg
|
182
|
* @param msg
|
|
171
|
*/
|
183
|
*/
|
|
172
|
private void prefixSearch(String msg) {
|
184
|
private void prefixSearch(String msg) {
|
|
173
|
try {
|
185
|
try {
|
|
174
|
List<OnlineUsersResVO.DataBodyBean> onlineUsers = routeRequest.onlineUsers();
|
186
|
List<OnlineUsersResVO.DataBodyBean> onlineUsers = routeRequest.onlineUsers();
|
|
175
|
- TrieTree trieTree = new TrieTree() ;
|
187
|
+ TrieTree trieTree = new TrieTree();
|
|
176
|
for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) {
|
188
|
for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) {
|
|
177
|
trieTree.insert(onlineUser.getUserName());
|
189
|
trieTree.insert(onlineUser.getUserName());
|
|
178
|
}
|
190
|
}
|
|
@@ -187,16 +199,17 @@ public class MsgHandler implements MsgHandle { |
|
@@ -187,16 +199,17 @@ public class MsgHandler implements MsgHandle { |
|
187
|
}
|
199
|
}
|
|
188
|
|
200
|
|
|
189
|
} catch (Exception e) {
|
201
|
} catch (Exception e) {
|
|
190
|
- LOGGER.error("Exception" ,e);
|
202
|
+ LOGGER.error("Exception", e);
|
|
191
|
}
|
203
|
}
|
|
192
|
}
|
204
|
}
|
|
193
|
|
205
|
|
|
194
|
/**
|
206
|
/**
|
|
195
|
* 查询聊天记录
|
207
|
* 查询聊天记录
|
|
|
|
208
|
+ *
|
|
196
|
* @param msg
|
209
|
* @param msg
|
|
197
|
*/
|
210
|
*/
|
|
198
|
private void queryChatHistory(String msg) {
|
211
|
private void queryChatHistory(String msg) {
|
|
199
|
- String[] split = msg.split(" ") ;
|
212
|
+ String[] split = msg.split(" ");
|
|
200
|
String res = msgLogger.query(split[1]);
|
213
|
String res = msgLogger.query(split[1]);
|
|
201
|
System.out.println(res);
|
214
|
System.out.println(res);
|
|
202
|
}
|
215
|
}
|
|
@@ -210,12 +223,12 @@ public class MsgHandler implements MsgHandle { |
|
@@ -210,12 +223,12 @@ public class MsgHandler implements MsgHandle { |
|
210
|
|
223
|
|
|
211
|
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
224
|
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
212
|
for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) {
|
225
|
for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) {
|
|
213
|
- LOGGER.info("userId={}=====userName={}",onlineUser.getUserId(),onlineUser.getUserName());
|
226
|
+ LOGGER.info("userId={}=====userName={}", onlineUser.getUserId(), onlineUser.getUserName());
|
|
214
|
}
|
227
|
}
|
|
215
|
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
228
|
LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
216
|
|
229
|
|
|
217
|
} catch (Exception e) {
|
230
|
} catch (Exception e) {
|
|
218
|
- LOGGER.error("Exception" ,e);
|
231
|
+ LOGGER.error("Exception", e);
|
|
219
|
}
|
232
|
}
|
|
220
|
}
|
233
|
}
|
|
221
|
|
234
|
|
|
@@ -234,7 +247,7 @@ public class MsgHandler implements MsgHandle { |
|
@@ -234,7 +247,7 @@ public class MsgHandler implements MsgHandle { |
|
234
|
}
|
247
|
}
|
|
235
|
cimClient.close();
|
248
|
cimClient.close();
|
|
236
|
} catch (InterruptedException e) {
|
249
|
} catch (InterruptedException e) {
|
|
237
|
- LOGGER.error("InterruptedException",e);
|
250
|
+ LOGGER.error("InterruptedException", e);
|
|
238
|
}
|
251
|
}
|
|
239
|
System.exit(0);
|
252
|
System.exit(0);
|
|
240
|
}
|
253
|
}
|