|
|
@@ -9,6 +9,7 @@ import api.entity.view.online.MessageView;
|
|
9
|
9
|
import api.service.dify.IDifyAssistantService;
|
|
10
|
10
|
import api.service.online.IMessageService;
|
|
11
|
11
|
import api.service.patient.IPatientService;
|
|
|
12
|
+import api.service.sf.ISfPlanService;
|
|
12
|
13
|
import api.service.system.IConfigService;
|
|
13
|
14
|
import api.util.enums.PatientSource;
|
|
14
|
15
|
import api.util.helper.*;
|
|
|
@@ -40,12 +41,9 @@ public class WebSocket {
|
|
40
|
41
|
private IMessageService messageService;
|
|
41
|
42
|
@Autowired
|
|
42
|
43
|
private IPatientService patientService;
|
|
43
|
|
- @Autowired
|
|
44
|
|
- private IDifyAssistantService difyAssistantService;
|
|
|
44
|
+
|
|
45
|
45
|
@Autowired
|
|
46
|
46
|
private WxMpService wxMpService;
|
|
47
|
|
- @Autowired
|
|
48
|
|
- private IConfigService configService;
|
|
49
|
47
|
|
|
50
|
48
|
private static WebSocket webSocket;
|
|
51
|
49
|
|
|
|
@@ -91,11 +89,11 @@ public class WebSocket {
|
|
91
|
89
|
customers.put(userCode, source);
|
|
92
|
90
|
khsessionPool.put(userCode, session);
|
|
93
|
91
|
Long pid = null;
|
|
94
|
|
- List<String> ps = session.getRequestParameterMap().get("project");
|
|
95
|
|
- if(ps!=null&&ps.size()>0)
|
|
96
|
|
- {
|
|
97
|
|
- pid = Long.valueOf(ps.get(0));
|
|
98
|
|
- }
|
|
|
92
|
+ // List<String> ps = session.getRequestParameterMap().get("project");
|
|
|
93
|
+// if(ps!=null&&ps.size()>0)
|
|
|
94
|
+// {
|
|
|
95
|
+// pid = Long.valueOf(ps.get(0));
|
|
|
96
|
+// }
|
|
99
|
97
|
addCustomer(userCode, source, pid);
|
|
100
|
98
|
}
|
|
101
|
99
|
}
|
|
|
@@ -214,25 +212,59 @@ public class WebSocket {
|
|
214
|
212
|
|
|
215
|
213
|
if (!exist) {
|
|
216
|
214
|
session.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
217
|
|
- return;
|
|
218
|
215
|
}
|
|
|
216
|
+ webSocket.messageService.insert(msg);
|
|
219
|
217
|
} else {
|
|
220
|
218
|
//客户发送消息
|
|
221
|
219
|
msg.setSend(1);
|
|
222
|
220
|
msg.setKhUser(userCode);
|
|
223
|
221
|
msg.setKhSource(source);
|
|
224
|
222
|
String kf = khkfs.get(userCode);
|
|
|
223
|
+ if(content.contains("人工"))
|
|
|
224
|
+ {
|
|
|
225
|
+
|
|
225
|
226
|
if (StringHelper.isEmpty(kf)||servicers.get(kf)==2) {
|
|
226
|
227
|
kf = servicerQueue.poll();
|
|
227
|
228
|
if (!StringHelper.isEmpty(kf)) {
|
|
228
|
229
|
servicerQueue.add(kf);
|
|
229
|
|
- khkfs.put(userCode, kf);
|
|
|
230
|
+ Session session1 = khsessionPool.get(userCode);
|
|
|
231
|
+ if (session1 != null) {
|
|
|
232
|
+ msg.setKfUser(kf);
|
|
|
233
|
+ webSocket.messageService.insert(msg);
|
|
|
234
|
+ MessageView mv1 = new MessageView();
|
|
|
235
|
+ mv1.setUser("admin");
|
|
|
236
|
+ mv1.setStatus("success");
|
|
|
237
|
+ mv1.setType(type);
|
|
|
238
|
+ mv1.setContent("正在为您转接人工,请稍后");
|
|
|
239
|
+ session1.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
240
|
+ addMsg(userCode,"正在为您转接人工,请稍后");
|
|
|
241
|
+ }
|
|
230
|
242
|
}
|
|
231
|
|
- }
|
|
|
243
|
+ else
|
|
|
244
|
+ {
|
|
|
245
|
+ IConfigService configService = SpringHelper.getBean(IConfigService.class);
|
|
|
246
|
+ String answer= configService.getConfigValue("prompt");
|
|
|
247
|
+ Session session1 = khsessionPool.get(userCode);
|
|
|
248
|
+ if (session1 != null) {
|
|
|
249
|
+ MessageView mv1 = new MessageView();
|
|
|
250
|
+ mv1.setStatus("success");
|
|
|
251
|
+ mv1.setType(type);
|
|
|
252
|
+ mv1.setContent(answer);
|
|
|
253
|
+ mv1.setUser(userCode);
|
|
|
254
|
+ session1.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
255
|
+ }
|
|
|
256
|
+ addMsg(userCode,answer);
|
|
|
257
|
+ }
|
|
|
258
|
+ }
|
|
|
259
|
+ }
|
|
|
260
|
+ else
|
|
|
261
|
+ {
|
|
|
262
|
+ webSocket.messageService.insert(msg);
|
|
|
263
|
+ }
|
|
232
|
264
|
if (!StringHelper.isEmpty(kf)) {
|
|
|
265
|
+ msg.setKfUser(kf);
|
|
233
|
266
|
Session session1 = kfsessionPool.get(kf);
|
|
234
|
267
|
if (session1 != null) {
|
|
235
|
|
- msg.setKfUser(kf);
|
|
236
|
268
|
MessageView mv1 = new MessageView();
|
|
237
|
269
|
mv1.setStatus("success");
|
|
238
|
270
|
mv1.setType(type);
|
|
|
@@ -241,14 +273,74 @@ public class WebSocket {
|
|
241
|
273
|
session1.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
242
|
274
|
}
|
|
243
|
275
|
}
|
|
244
|
|
- }
|
|
245
|
|
- //webSocket.messageService.insert(msg);
|
|
246
|
|
- AsyncHelper.instance().execute(new TimerTask() {
|
|
247
|
|
- @Override
|
|
248
|
|
- public void run() {
|
|
249
|
|
- webSocket.messageService.insert(msg);
|
|
|
276
|
+ else
|
|
|
277
|
+ {
|
|
|
278
|
+ if(!content.contains("人工")) {
|
|
|
279
|
+ IDifyAssistantService difyAssistantService = SpringHelper.getBean(IDifyAssistantService.class);
|
|
|
280
|
+ DifyChatMessagesInput input = new DifyChatMessagesInput();
|
|
|
281
|
+ LambdaQueryWrapper<DifyAssistant> qw = new LambdaQueryWrapper<>();
|
|
|
282
|
+ qw.eq(DifyAssistant::getCode, "mxyh");
|
|
|
283
|
+ DifyAssistant dify = difyAssistantService.getEntity(qw);
|
|
|
284
|
+ if (dify != null) {
|
|
|
285
|
+ input.setId(dify.getAssistantId());
|
|
|
286
|
+ input.setQuery(content);
|
|
|
287
|
+ Map<String, Object> conversationMap = conversations.get(userCode);
|
|
|
288
|
+ String Conversation_id = "";
|
|
|
289
|
+ if (conversationMap != null) {
|
|
|
290
|
+ Object Aime = conversationMap.get("conversationAime");
|
|
|
291
|
+ Object Id = conversationMap.get("conversationId");
|
|
|
292
|
+ if (Aime != null) {
|
|
|
293
|
+ Date time = (Date) conversationMap.get("conversationAime");
|
|
|
294
|
+ // 获取当前时间
|
|
|
295
|
+ Date now = new Date();
|
|
|
296
|
+ // 计算时间差的绝对值(毫秒)
|
|
|
297
|
+ long diffInMilliseconds = Math.abs(now.getTime() - time.getTime());
|
|
|
298
|
+ if (diffInMilliseconds <= (30 * 60 * 1000) && Id != null) {
|
|
|
299
|
+ Conversation_id = Id.toString();
|
|
|
300
|
+ }
|
|
|
301
|
+ }
|
|
|
302
|
+ }
|
|
|
303
|
+ input.setConversation_id(Conversation_id);
|
|
|
304
|
+ input.setAuto_generate_name(false);
|
|
|
305
|
+ try {
|
|
|
306
|
+ String json = difyAssistantService.sendMessages(input, dify, userCode);
|
|
|
307
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
308
|
+ JsonNode rootNode = mapper.readTree(json);
|
|
|
309
|
+ String answer = rootNode.get("answer").asText();
|
|
|
310
|
+ String conversationId = rootNode.get("conversation_id").asText();
|
|
|
311
|
+ if (!conversations.containsKey(userCode)) {
|
|
|
312
|
+ conversations.remove(userCode);
|
|
|
313
|
+ Map<String, Object> conversationsMap = new HashMap<>();
|
|
|
314
|
+ conversationsMap.put("conversationId", conversationId);
|
|
|
315
|
+ conversationsMap.put("conversationAime", new Date());
|
|
|
316
|
+ conversations.put(userCode, conversationsMap);
|
|
|
317
|
+ }
|
|
|
318
|
+ Session session1 = khsessionPool.get(userCode);
|
|
|
319
|
+ if (session1 != null) {
|
|
|
320
|
+ MessageView mv1 = new MessageView();
|
|
|
321
|
+ mv1.setStatus("success");
|
|
|
322
|
+ mv1.setType(type);
|
|
|
323
|
+ mv1.setContent(answer);
|
|
|
324
|
+ mv1.setUser(userCode);
|
|
|
325
|
+ session1.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
326
|
+ }
|
|
|
327
|
+ addMsg(userCode, answer);
|
|
|
328
|
+
|
|
|
329
|
+ } catch (Exception E) {
|
|
|
330
|
+ }
|
|
|
331
|
+
|
|
|
332
|
+ }
|
|
|
333
|
+ }
|
|
250
|
334
|
}
|
|
251
|
|
- });
|
|
|
335
|
+
|
|
|
336
|
+ }
|
|
|
337
|
+ // webSocket.messageService.insert(msg);
|
|
|
338
|
+// AsyncHelper.instance().execute(new TimerTask() {
|
|
|
339
|
+// @Override
|
|
|
340
|
+// public void run() {
|
|
|
341
|
+// webSocket.messageService.insert(msg);
|
|
|
342
|
+// }
|
|
|
343
|
+// });
|
|
252
|
344
|
}
|
|
253
|
345
|
}
|
|
254
|
346
|
|
|
|
@@ -583,8 +675,6 @@ public class WebSocket {
|
|
583
|
675
|
String kf = khkfs.get(sendUser);
|
|
584
|
676
|
// if(content.contains("人工"))
|
|
585
|
677
|
// {
|
|
586
|
|
-//
|
|
587
|
|
-//
|
|
588
|
678
|
// if (StringHelper.isEmpty(kf)||servicers.get(kf)==2) {
|
|
589
|
679
|
// kf = servicerQueue.poll();
|
|
590
|
680
|
// if (!StringHelper.isEmpty(kf)) {
|
|
|
@@ -631,6 +721,7 @@ public class WebSocket {
|
|
631
|
721
|
{
|
|
632
|
722
|
if ("text".equals(msgType))
|
|
633
|
723
|
{
|
|
|
724
|
+ IDifyAssistantService difyAssistantService= SpringHelper.getBean(IDifyAssistantService.class);
|
|
634
|
725
|
webSocket.messageService.insert(message);
|
|
635
|
726
|
DifyChatMessagesInput input=new DifyChatMessagesInput();
|
|
636
|
727
|
LambdaQueryWrapper<DifyAssistant> qw = new LambdaQueryWrapper<>();
|