|
|
@@ -94,7 +94,7 @@ public class WebSocket {
|
|
94
|
94
|
mv.setStatus("success");
|
|
95
|
95
|
mv.setType("text");
|
|
96
|
96
|
mv.setContent(first);
|
|
97
|
|
- session.getAsyncRemote().sendText(JSON.toJSONString(mv));
|
|
|
97
|
+ sendText(session,JSON.toJSONString(mv));
|
|
98
|
98
|
|
|
99
|
99
|
Message msg1 = new Message();
|
|
100
|
100
|
msg1.setCreateTime(new Date());
|
|
|
@@ -118,7 +118,7 @@ public class WebSocket {
|
|
118
|
118
|
MessageView mv1 = new MessageView();
|
|
119
|
119
|
mv1.setStatus("error");
|
|
120
|
120
|
mv1.setContent("签入失败,重复签入");
|
|
121
|
|
- session.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
121
|
+ sendText(session,JSON.toJSONString(mv1));
|
|
122
|
122
|
session.close();
|
|
123
|
123
|
}
|
|
124
|
124
|
} catch (Exception e) {
|
|
|
@@ -149,7 +149,7 @@ public class WebSocket {
|
|
149
|
149
|
mv1.setStatus("error");
|
|
150
|
150
|
mv1.setContent("客户已下线");
|
|
151
|
151
|
mv1.setUser(userCode);
|
|
152
|
|
- session1.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
152
|
+ sendText(session1,JSON.toJSONString(mv1));
|
|
153
|
153
|
}
|
|
154
|
154
|
khsessionPool.remove(userCode);
|
|
155
|
155
|
khkfs.remove(userCode);
|
|
|
@@ -175,7 +175,7 @@ public class WebSocket {
|
|
175
|
175
|
mvh.setStatus("success");
|
|
176
|
176
|
mvh.setType(type);
|
|
177
|
177
|
mvh.setContent(mv.getContent());
|
|
178
|
|
- session.getAsyncRemote().sendText(JSON.toJSONString(mvh));
|
|
|
178
|
+ sendText(session,JSON.toJSONString(mvh));
|
|
179
|
179
|
return;
|
|
180
|
180
|
}
|
|
181
|
181
|
|
|
|
@@ -215,10 +215,10 @@ public class WebSocket {
|
|
215
|
215
|
WxMpKefuMessage wechatMessage = WxMpKefuMessage.TEXT().toUser(kh).content(content).build();
|
|
216
|
216
|
webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMessage);
|
|
217
|
217
|
} catch (WxErrorException e) {
|
|
218
|
|
- log.error("发送微信消息失败",e);
|
|
|
218
|
+ log.error("发送微信消息失败", e);
|
|
219
|
219
|
mv1.setStatus("error");
|
|
220
|
220
|
mv1.setContent("发送微信消息失败");
|
|
221
|
|
- session.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
221
|
+ sendText(session,JSON.toJSONString(mv1));
|
|
222
|
222
|
return;
|
|
223
|
223
|
}
|
|
224
|
224
|
} else {
|
|
|
@@ -227,7 +227,7 @@ public class WebSocket {
|
|
227
|
227
|
mv1.setStatus("success");
|
|
228
|
228
|
mv1.setType(type);
|
|
229
|
229
|
mv1.setContent(content);
|
|
230
|
|
- session1.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
230
|
+ sendText(session1,JSON.toJSONString(mv1));
|
|
231
|
231
|
}
|
|
232
|
232
|
} else {
|
|
233
|
233
|
mv1.setStatus("error");
|
|
|
@@ -235,7 +235,7 @@ public class WebSocket {
|
|
235
|
235
|
}
|
|
236
|
236
|
|
|
237
|
237
|
if (!exist) {
|
|
238
|
|
- session.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
238
|
+ sendText(session,JSON.toJSONString(mv1));
|
|
239
|
239
|
return;
|
|
240
|
240
|
}
|
|
241
|
241
|
} else {
|
|
|
@@ -249,7 +249,9 @@ public class WebSocket {
|
|
249
|
249
|
String first = webSocket.configService.getConfigValue("AutoReply");
|
|
250
|
250
|
if (StringHelper.isNotEmpty(first)) {//自动回复
|
|
251
|
251
|
if ("text".equals(type)) {
|
|
252
|
|
- if (!content.contains("人工")) {
|
|
|
252
|
+ String[] keys = new String[]{"人工", "客服"};
|
|
|
253
|
+ if (!StringHelper.containList(content, keys)) {
|
|
|
254
|
+ //if (!content.contains("人工")) {
|
|
253
|
255
|
//获取匹配的记录
|
|
254
|
256
|
AutoReply[] list = webSocket.autoReplyService.selectMatchList(1, content);
|
|
255
|
257
|
if (list != null && list.length > 0) {
|
|
|
@@ -265,7 +267,7 @@ public class WebSocket {
|
|
265
|
267
|
throw new RuntimeException(e);
|
|
266
|
268
|
}
|
|
267
|
269
|
long n = webSocket.messageService.getCount(qw);//当天回复次数
|
|
268
|
|
- if (ar.getReplyCount()==0||(ar.getReplyCount() > 0 && n < ar.getReplyCount())) {
|
|
|
270
|
+ if (ar.getReplyCount() == 0 || (ar.getReplyCount() > 0 && n < ar.getReplyCount())) {
|
|
269
|
271
|
//回复内容条数
|
|
270
|
272
|
List<Map<String, Object>> cs = ar.getContent();
|
|
271
|
273
|
if (cs != null && cs.size() > 0) {
|
|
|
@@ -295,11 +297,7 @@ public class WebSocket {
|
|
295
|
297
|
mv1.setStatus("success");
|
|
296
|
298
|
mv1.setType(hftype);
|
|
297
|
299
|
mv1.setContent(hfcontent);
|
|
298
|
|
- try {
|
|
299
|
|
- session.getBasicRemote().sendText(JSON.toJSONString(mv1));
|
|
300
|
|
- } catch (IOException e) {
|
|
301
|
|
- throw new RuntimeException(e);
|
|
302
|
|
- }
|
|
|
300
|
+ sendText(session,JSON.toJSONString(mv1));
|
|
303
|
301
|
}
|
|
304
|
302
|
} else {
|
|
305
|
303
|
int rn = cs.size();
|
|
|
@@ -329,7 +327,7 @@ public class WebSocket {
|
|
329
|
327
|
mv1.setStatus("success");
|
|
330
|
328
|
mv1.setType(hftype);
|
|
331
|
329
|
mv1.setContent(hfcontent);
|
|
332
|
|
- session.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
330
|
+ sendText(session,JSON.toJSONString(mv1));
|
|
333
|
331
|
}
|
|
334
|
332
|
}
|
|
335
|
333
|
}
|
|
|
@@ -341,6 +339,17 @@ public class WebSocket {
|
|
341
|
339
|
} else {
|
|
342
|
340
|
zrg = true;
|
|
343
|
341
|
}
|
|
|
342
|
+ if (zrg) {
|
|
|
343
|
+ MessageView mv1 = new MessageView();
|
|
|
344
|
+ mv1.setStatus("success");
|
|
|
345
|
+ mv1.setType("text");
|
|
|
346
|
+ mv1.setContent("人工客服正火速赶来,请稍等...");
|
|
|
347
|
+ sendText(session,JSON.toJSONString(mv1));
|
|
|
348
|
+ mv1.setContent("【人工客服工作时间为每天(含节假日)8:30-20:00,如现在非工作时间,建议您使用自助服务或者在工作时间联系我们。】");
|
|
|
349
|
+ sendText(session,JSON.toJSONString(mv1));
|
|
|
350
|
+ mv1.setContent("正在接入客服,请稍后...");
|
|
|
351
|
+ sendText(session,JSON.toJSONString(mv1));
|
|
|
352
|
+ }
|
|
344
|
353
|
} else if (servicers.get(kf) == 2) {//客服置忙
|
|
345
|
354
|
zrg = true;
|
|
346
|
355
|
}
|
|
|
@@ -360,7 +369,7 @@ public class WebSocket {
|
|
360
|
369
|
mv1.setType(type);
|
|
361
|
370
|
mv1.setContent(content);
|
|
362
|
371
|
mv1.setUser(userCode);
|
|
363
|
|
- session1.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
372
|
+ sendText(session1,JSON.toJSONString(mv1));
|
|
364
|
373
|
}
|
|
365
|
374
|
}
|
|
366
|
375
|
}
|
|
|
@@ -399,7 +408,7 @@ public class WebSocket {
|
|
399
|
408
|
mv1.setStatus("error");
|
|
400
|
409
|
mv1.setContent("客户已下线");
|
|
401
|
410
|
mv1.setUser(userCode);
|
|
402
|
|
- session1.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
411
|
+ sendText(session1,JSON.toJSONString(mv1));
|
|
403
|
412
|
}
|
|
404
|
413
|
khsessionPool.remove(userCode);
|
|
405
|
414
|
khkfs.remove(userCode);
|
|
|
@@ -408,6 +417,26 @@ public class WebSocket {
|
|
408
|
417
|
error.printStackTrace();
|
|
409
|
418
|
}
|
|
410
|
419
|
|
|
|
420
|
+ //发送消息处理
|
|
|
421
|
+ private void sendText(Session s,String msg){
|
|
|
422
|
+ if (s != null && s.isOpen()) {
|
|
|
423
|
+ synchronized (s) {
|
|
|
424
|
+ try {
|
|
|
425
|
+ s.getBasicRemote().sendText(msg);
|
|
|
426
|
+ } catch (IOException e) {
|
|
|
427
|
+ log.error(msg+" 发送失败",e);
|
|
|
428
|
+ if(e.getMessage().contains("close")) {
|
|
|
429
|
+ try {
|
|
|
430
|
+ s.close();
|
|
|
431
|
+ } catch (IOException ex) {
|
|
|
432
|
+ log.error(msg + " 关闭失败", ex);
|
|
|
433
|
+ }
|
|
|
434
|
+ }
|
|
|
435
|
+ }
|
|
|
436
|
+ }
|
|
|
437
|
+ }
|
|
|
438
|
+ }
|
|
|
439
|
+
|
|
411
|
440
|
//客户转移
|
|
412
|
441
|
public String khTransfer(String kf,String kh) {
|
|
413
|
442
|
String msg = "客户已下线";
|
|
|
@@ -454,7 +483,7 @@ public class WebSocket {
|
|
454
|
483
|
mv1.setType("transfer");
|
|
455
|
484
|
mv1.setContent("转移客户");
|
|
456
|
485
|
mv1.setUser(kh);
|
|
457
|
|
- session1.getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
486
|
+ sendText(session1,JSON.toJSONString(mv1));
|
|
458
|
487
|
}
|
|
459
|
488
|
|
|
460
|
489
|
return msg;
|
|
|
@@ -545,7 +574,7 @@ public class WebSocket {
|
|
545
|
574
|
mv1.setStatus("success");
|
|
546
|
575
|
mv1.setType(type);
|
|
547
|
576
|
mv1.setContent(content);
|
|
548
|
|
- khsessionPool.get(kh).getAsyncRemote().sendText(JSON.toJSONString(mv1));
|
|
|
577
|
+ sendText(khsessionPool.get(kh),JSON.toJSONString(mv1));
|
|
549
|
578
|
}
|
|
550
|
579
|
|
|
551
|
580
|
webSocket.messageService.insert(message);
|
|
|
@@ -628,7 +657,9 @@ public class WebSocket {
|
|
628
|
657
|
String first = webSocket.configService.getConfigValue("AutoReply");
|
|
629
|
658
|
if (StringHelper.isNotEmpty(first)) {//自动回复
|
|
630
|
659
|
if ("text".equals(msgType)) {
|
|
631
|
|
- if (!content.contains("人工")) {
|
|
|
660
|
+ String[] keys = new String[]{"人工", "客服"};
|
|
|
661
|
+ if (!StringHelper.containList(content, keys)) {
|
|
|
662
|
+ //if (!content.contains("人工")) {
|
|
632
|
663
|
//获取匹配的记录
|
|
633
|
664
|
AutoReply[] list = webSocket.autoReplyService.selectMatchList(2, content);
|
|
634
|
665
|
if (list != null && list.length > 0) {
|
|
|
@@ -746,6 +777,21 @@ public class WebSocket {
|
|
746
|
777
|
} else {
|
|
747
|
778
|
zrg = true;
|
|
748
|
779
|
}
|
|
|
780
|
+ if (zrg) {
|
|
|
781
|
+ try {
|
|
|
782
|
+ String ct1="人工客服正火速赶来,请稍等……";
|
|
|
783
|
+ WxMpKefuMessage wechatMessage1 = WxMpKefuMessage.TEXT().toUser(sendUser).content(ct1).build();
|
|
|
784
|
+ webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMessage1);
|
|
|
785
|
+ String ct2="【人工客服工作时间为每天(含节假日)8:30-20:00,如现在非工作时间,建议您使用自助服务或者在工作时间联系我们。】";
|
|
|
786
|
+ WxMpKefuMessage wechatMessage2 = WxMpKefuMessage.TEXT().toUser(sendUser).content(ct2).build();
|
|
|
787
|
+ webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMessage2);
|
|
|
788
|
+ String ct3="正在接入客服,请稍后...";
|
|
|
789
|
+ WxMpKefuMessage wechatMessage3 = WxMpKefuMessage.TEXT().toUser(sendUser).content(ct3).build();
|
|
|
790
|
+ webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMessage3);
|
|
|
791
|
+ } catch (WxErrorException e) {
|
|
|
792
|
+ throw new RuntimeException(e);
|
|
|
793
|
+ }
|
|
|
794
|
+ }
|
|
749
|
795
|
} else if (servicers.get(kf) == 2) {//客服置忙
|
|
750
|
796
|
zrg = true;
|
|
751
|
797
|
}
|
|
|
@@ -765,7 +811,7 @@ public class WebSocket {
|
|
765
|
811
|
mv.setType(msgType);
|
|
766
|
812
|
mv.setContent(content);
|
|
767
|
813
|
mv.setUser(sendUser);
|
|
768
|
|
- session1.getAsyncRemote().sendText(JSON.toJSONString(mv));
|
|
|
814
|
+ sendText(session1,JSON.toJSONString(mv));
|
|
769
|
815
|
}
|
|
770
|
816
|
}
|
|
771
|
817
|
|