|
|
@@ -12,7 +12,6 @@ import midware.util.helper.StringHelper;
|
|
12
|
12
|
import org.springframework.stereotype.Component;
|
|
13
|
13
|
|
|
14
|
14
|
import javax.websocket.*;
|
|
15
|
|
-import javax.websocket.server.PathParam;
|
|
16
|
15
|
import javax.websocket.server.ServerEndpoint;
|
|
17
|
16
|
import java.io.IOException;
|
|
18
|
17
|
import java.util.*;
|
|
|
@@ -56,7 +55,7 @@ public class WebSocketService {
|
|
56
|
55
|
EslCommon.agents.remove(a);
|
|
57
|
56
|
sessionPool.remove(agentId);
|
|
58
|
57
|
}
|
|
59
|
|
- if(subScribeSessionPool.contains(session))subScribeSessionPool.remove(session);
|
|
|
58
|
+ subScribeSessionPool.remove(session);
|
|
60
|
59
|
} catch (Exception e) {
|
|
61
|
60
|
log.error("close错误", e);
|
|
62
|
61
|
}
|
|
|
@@ -70,15 +69,24 @@ public class WebSocketService {
|
|
70
|
69
|
@OnMessage
|
|
71
|
70
|
public void onMessage(String message) {
|
|
72
|
71
|
try {
|
|
73
|
|
- Map<String, Object> result = new HashMap<>();
|
|
74
|
72
|
Map map = JSON.parseObject(message, Map.class);
|
|
75
|
73
|
String type = map.get("Type").toString();
|
|
76
|
|
- Agent agent = EslCommon.getAgent(agentId);
|
|
77
|
|
- Channel chan = null;
|
|
78
|
|
- if (agent != null) chan = EslCommon.getChanByExten(agent.getExten());
|
|
79
|
|
- EslAgentNum state = agent == null ? null : EslAgentNum.values()[agent.getAgentState()];
|
|
|
74
|
+
|
|
|
75
|
+ Map<String, Object> result = new HashMap<>();
|
|
80
|
76
|
result.put("Type", type);
|
|
81
|
77
|
result.put("Result", "操作失败");
|
|
|
78
|
+ Agent agent = EslCommon.getAgent(agentId);
|
|
|
79
|
+ Channel chan = null;EslAgentNum state =null;
|
|
|
80
|
+ if (agent != null) {
|
|
|
81
|
+ chan = EslCommon.getChanByExten(agent.getExten());
|
|
|
82
|
+ state = EslAgentNum.values()[agent.getAgentState()];
|
|
|
83
|
+ if (chan == null) {
|
|
|
84
|
+ result.put("Result", "分机未注册");
|
|
|
85
|
+ state = null;
|
|
|
86
|
+ }
|
|
|
87
|
+ }
|
|
|
88
|
+
|
|
|
89
|
+
|
|
82
|
90
|
String param = "";
|
|
83
|
91
|
boolean isSend = true;
|
|
84
|
92
|
switch (type) {
|
|
|
@@ -92,40 +100,37 @@ public class WebSocketService {
|
|
92
|
100
|
param = AgentExten + "|" + AgentGroup;
|
|
93
|
101
|
//String AgentType = map.get("AgentType").toString();
|
|
94
|
102
|
|
|
95
|
|
- if (StringHelper.isNotEmpty(agentId)) {
|
|
96
|
|
- result.put("Result", "重复签入");
|
|
97
|
|
- } else {
|
|
98
|
|
- if (StringHelper.isNotEmpty(AgentId) && StringHelper.isNotEmpty(AgentExten) && StringHelper.isNotEmpty(AgentGroup)) {
|
|
99
|
|
- if (EslCommon.existAgent(AgentId)) {
|
|
100
|
|
- result.put("Result", "坐席已存在");
|
|
101
|
|
- } else if (!EslCommon.existExten(AgentExten)) {
|
|
102
|
|
- result.put("Result", "分机未注册");
|
|
103
|
|
- } else if (EslCommon.getAgentByExten(AgentExten) != null) {
|
|
104
|
|
- result.put("Result", "分机已存在");
|
|
105
|
|
- } else {
|
|
106
|
|
- this.agentId = AgentId;
|
|
107
|
|
- sessionPool.put(AgentId,session);
|
|
|
103
|
+ if (StringHelper.isNotEmpty(AgentId) && StringHelper.isNotEmpty(AgentExten) && StringHelper.isNotEmpty(AgentGroup)) {
|
|
|
104
|
+ if (EslCommon.existAgent(AgentId)) {
|
|
|
105
|
+ result.put("Result", "坐席已存在");
|
|
|
106
|
+ } else if (!EslCommon.existExten(AgentExten)) {
|
|
|
107
|
+ result.put("Result", "分机未注册");
|
|
|
108
|
+ } else if (EslCommon.getAgentByExten(AgentExten) != null) {
|
|
|
109
|
+ result.put("Result", "分机已存在");
|
|
|
110
|
+ } else {
|
|
|
111
|
+ this.agentId = AgentId;
|
|
|
112
|
+ sessionPool.put(AgentId, session);
|
|
108
|
113
|
|
|
109
|
|
- agent = new Agent();
|
|
110
|
|
- agent.setAgent(AgentId);
|
|
111
|
|
- agent.setExten(AgentExten);
|
|
112
|
|
- agent.setGroup(AgentGroup);
|
|
113
|
|
- //agent.setAgentState(EslAgentNum.loging.ordinal());
|
|
|
114
|
+ agent = new Agent();
|
|
|
115
|
+ agent.setAgent(AgentId);
|
|
|
116
|
+ agent.setExten(AgentExten);
|
|
|
117
|
+ agent.setGroup(AgentGroup);
|
|
|
118
|
+ agent.setAgentState(EslAgentNum.loging.ordinal());
|
|
114
|
119
|
|
|
115
|
|
- chan = EslCommon.getChanByExten(AgentExten);
|
|
116
|
|
- String rt = eslClientService.login(AgentId, AgentExten, AgentGroup);
|
|
117
|
|
- if (StringHelper.isNotEmpty(rt)) {
|
|
118
|
|
- EslCommon.agents.add(agent);
|
|
119
|
|
- EslCommon.sessionOpera.put(rt, type + "|" + AgentId);
|
|
120
|
|
- isSend = false;
|
|
121
|
|
- }
|
|
|
120
|
+ chan = EslCommon.getChanByExten(AgentExten);
|
|
|
121
|
+ String rt = eslClientService.login(AgentId, AgentExten, AgentGroup);
|
|
|
122
|
+ if (StringHelper.isNotEmpty(rt)) {
|
|
|
123
|
+ EslCommon.agents.add(agent);
|
|
|
124
|
+ EslCommon.sessionOpera.put(rt, type + "|" + AgentId);
|
|
|
125
|
+ isSend = false;
|
|
122
|
126
|
}
|
|
123
|
127
|
}
|
|
124
|
128
|
}
|
|
|
129
|
+
|
|
125
|
130
|
break;
|
|
126
|
131
|
case "Logout"://签出
|
|
127
|
132
|
//空闲/置忙/话后处理 可以签出
|
|
128
|
|
- if (StringHelper.isNotEmpty(agentId) && Arrays.asList(EslAgentNum.free, EslAgentNum.busy, EslAgentNum.aftertalk).contains(state)) {
|
|
|
133
|
+ if (Arrays.asList(EslAgentNum.free, EslAgentNum.busy, EslAgentNum.aftertalk).contains(state)) {
|
|
129
|
134
|
String rt = eslClientService.logout(agentId, agent.getGroup());
|
|
130
|
135
|
if (StringHelper.isNotEmpty(rt)) {
|
|
131
|
136
|
EslCommon.sessionOpera.put(rt, type + "|" + agentId);
|
|
|
@@ -137,7 +142,7 @@ public class WebSocketService {
|
|
137
|
142
|
break;
|
|
138
|
143
|
case "WorkOn"://置闲
|
|
139
|
144
|
//置忙/话后处理 可以置闲
|
|
140
|
|
- if (StringHelper.isNotEmpty(agentId) && Arrays.asList(EslAgentNum.busy, EslAgentNum.aftertalk).contains(state)) {
|
|
|
145
|
+ if (Arrays.asList(EslAgentNum.busy, EslAgentNum.aftertalk).contains(state)) {
|
|
141
|
146
|
String rt = eslClientService.setWork(agentId, true);
|
|
142
|
147
|
if (StringHelper.isNotEmpty(rt)) {
|
|
143
|
148
|
EslCommon.sessionOpera.put(rt, type + "|" + agentId);
|
|
|
@@ -147,7 +152,7 @@ public class WebSocketService {
|
|
147
|
152
|
break;
|
|
148
|
153
|
case "WorkOff"://置忙
|
|
149
|
154
|
//空闲/话后处理 可以置忙
|
|
150
|
|
- if (StringHelper.isNotEmpty(agentId) && Arrays.asList(EslAgentNum.free, EslAgentNum.aftertalk).contains(state)) {
|
|
|
155
|
+ if (Arrays.asList(EslAgentNum.free, EslAgentNum.aftertalk).contains(state)) {
|
|
151
|
156
|
String rt = eslClientService.setWork(agentId, false);
|
|
152
|
157
|
if (StringHelper.isNotEmpty(rt)) {
|
|
153
|
158
|
EslCommon.sessionOpera.put(rt, type + "|" + agentId);
|
|
|
@@ -157,7 +162,7 @@ public class WebSocketService {
|
|
157
|
162
|
break;
|
|
158
|
163
|
case "MakeCall"://外呼
|
|
159
|
164
|
//空闲/置忙/话后处理 可以外呼
|
|
160
|
|
- if (StringHelper.isNotEmpty(agentId) && Arrays.asList(EslAgentNum.free, EslAgentNum.busy, EslAgentNum.aftertalk).contains(state)) {
|
|
|
165
|
+ if (map.get("DestinationNumber") != null && Arrays.asList(EslAgentNum.free, EslAgentNum.busy, EslAgentNum.aftertalk).contains(state)) {
|
|
161
|
166
|
String DestinationNumber = map.get("DestinationNumber").toString();
|
|
162
|
167
|
param = DestinationNumber;
|
|
163
|
168
|
if (StringHelper.isNotEmpty(DestinationNumber)) {
|
|
|
@@ -176,7 +181,7 @@ public class WebSocketService {
|
|
176
|
181
|
break;
|
|
177
|
182
|
case "HoldOn"://开启保持
|
|
178
|
183
|
//通话中 可以开启保持
|
|
179
|
|
- if (StringHelper.isNotEmpty(agentId) && Objects.equals(state, EslAgentNum.talking)) {
|
|
|
184
|
+ if (Objects.equals(state, EslAgentNum.talking)) {
|
|
180
|
185
|
String rt = eslClientService.setHold(chan.getSessionId(), true);
|
|
181
|
186
|
if (StringHelper.isNotEmpty(rt)) {
|
|
182
|
187
|
EslCommon.sessionOpera.put(rt, type + "|" + agentId);
|
|
|
@@ -186,7 +191,7 @@ public class WebSocketService {
|
|
186
|
191
|
break;
|
|
187
|
192
|
case "HoldOff"://关闭保持
|
|
188
|
193
|
//通话中 可以关闭保持
|
|
189
|
|
- if (StringHelper.isNotEmpty(agentId) && Objects.equals(state, EslAgentNum.talking)) {
|
|
|
194
|
+ if (Objects.equals(state, EslAgentNum.talking)) {
|
|
190
|
195
|
String rt = eslClientService.setHold(chan.getSessionId(), false);
|
|
191
|
196
|
if (StringHelper.isNotEmpty(rt)) {
|
|
192
|
197
|
EslCommon.sessionOpera.put(rt, type + "|" + agentId);
|
|
|
@@ -196,7 +201,7 @@ public class WebSocketService {
|
|
196
|
201
|
break;
|
|
197
|
202
|
case "MuteOn"://开启静音
|
|
198
|
203
|
//通话中 可以开启静音
|
|
199
|
|
- if (StringHelper.isNotEmpty(agentId) && Objects.equals(state, EslAgentNum.talking)) {
|
|
|
204
|
+ if (Objects.equals(state, EslAgentNum.talking)) {
|
|
200
|
205
|
String rt = eslClientService.setMute(chan.getChanId(), true);
|
|
201
|
206
|
if (StringHelper.isNotEmpty(rt)) {
|
|
202
|
207
|
EslCommon.sessionOpera.put(rt, type + "|" + agentId);
|
|
|
@@ -206,7 +211,7 @@ public class WebSocketService {
|
|
206
|
211
|
break;
|
|
207
|
212
|
case "MuteOff"://关闭静音
|
|
208
|
213
|
//通话中 可以关闭静音
|
|
209
|
|
- if (StringHelper.isNotEmpty(agentId) && Objects.equals(state, EslAgentNum.talking)) {
|
|
|
214
|
+ if (Objects.equals(state, EslAgentNum.talking)) {
|
|
210
|
215
|
String rt = eslClientService.setMute(chan.getChanId(), false);
|
|
211
|
216
|
if (StringHelper.isNotEmpty(rt)) {
|
|
212
|
217
|
EslCommon.sessionOpera.put(rt, type + "|" + agentId);
|
|
|
@@ -216,7 +221,7 @@ public class WebSocketService {
|
|
216
|
221
|
break;
|
|
217
|
222
|
case "Transfer"://转移
|
|
218
|
223
|
//通话中 可以转移
|
|
219
|
|
- if (StringHelper.isNotEmpty(agentId) && Objects.equals(state, EslAgentNum.talking)) {
|
|
|
224
|
+ if (map.get("DestinationNumber") != null && Objects.equals(state, EslAgentNum.talking)) {
|
|
220
|
225
|
String DestinationNumber = map.get("DestinationNumber").toString();
|
|
221
|
226
|
param = DestinationNumber;
|
|
222
|
227
|
if (StringHelper.isNotEmpty(DestinationNumber)) {
|
|
|
@@ -244,7 +249,7 @@ public class WebSocketService {
|
|
244
|
249
|
break;
|
|
245
|
250
|
case "ConsultOn"://开启协商
|
|
246
|
251
|
//通话中 可以协商
|
|
247
|
|
- if (StringHelper.isNotEmpty(agentId) && Objects.equals(state, EslAgentNum.talking)) {
|
|
|
252
|
+ if (map.get("DestinationNumber") != null && Objects.equals(state, EslAgentNum.talking)) {
|
|
248
|
253
|
String DestinationNumber = map.get("DestinationNumber").toString();
|
|
249
|
254
|
param = DestinationNumber;
|
|
250
|
255
|
if (StringHelper.isNotEmpty(DestinationNumber)) {
|
|
|
@@ -272,7 +277,7 @@ public class WebSocketService {
|
|
272
|
277
|
break;
|
|
273
|
278
|
case "ConsultOff"://关闭协商
|
|
274
|
279
|
//通话中 可以协商取消
|
|
275
|
|
- if (StringHelper.isNotEmpty(agentId) && Objects.equals(state, EslAgentNum.talking)) {
|
|
|
280
|
+ if (Objects.equals(state, EslAgentNum.talking)) {
|
|
276
|
281
|
String sid = chan.getSessionId();
|
|
277
|
282
|
Channel channel = EslCommon.channels.stream().filter(p -> p.getSessionId().equals(sid)
|
|
278
|
283
|
&& p.getSessionSort() == 3).findFirst().get();
|
|
|
@@ -285,7 +290,7 @@ public class WebSocketService {
|
|
285
|
290
|
break;
|
|
286
|
291
|
case "Meeting"://会议
|
|
287
|
292
|
//通话中 可以会议
|
|
288
|
|
- if (StringHelper.isNotEmpty(agentId) && Objects.equals(state, EslAgentNum.talking)) {
|
|
|
293
|
+ if (map.get("DestinationNumber") != null && Objects.equals(state, EslAgentNum.talking)) {
|
|
289
|
294
|
String DestinationNumber = map.get("DestinationNumber").toString();
|
|
290
|
295
|
param = DestinationNumber;
|
|
291
|
296
|
if (StringHelper.isNotEmpty(DestinationNumber)) {
|
|
|
@@ -311,7 +316,7 @@ public class WebSocketService {
|
|
311
|
316
|
break;
|
|
312
|
317
|
case "TurnMyd"://转满意度
|
|
313
|
318
|
//通话中 可以转满意度
|
|
314
|
|
- if (StringHelper.isNotEmpty(agentId) && Objects.equals(state, EslAgentNum.talking)) {
|
|
|
319
|
+ if (Objects.equals(state, EslAgentNum.talking)) {
|
|
315
|
320
|
String rt = eslClientService.turnMyd(chan.getSessionId());
|
|
316
|
321
|
if (StringHelper.isNotEmpty(rt)) {
|
|
317
|
322
|
EslCommon.sessionOpera.put(rt, type + "|" + agentId);
|
|
|
@@ -321,7 +326,7 @@ public class WebSocketService {
|
|
321
|
326
|
break;
|
|
322
|
327
|
case "DropCall"://挂机
|
|
323
|
328
|
//通话中/请求中 可以挂机
|
|
324
|
|
- if (StringHelper.isNotEmpty(agentId) && Arrays.asList(EslAgentNum.talking, EslAgentNum.requested).contains(state)) {
|
|
|
329
|
+ if (Arrays.asList(EslAgentNum.talking, EslAgentNum.requested).contains(state)) {
|
|
325
|
330
|
String rt = eslClientService.kill(chan.getChanId());
|
|
326
|
331
|
if (StringHelper.isNotEmpty(rt)) {
|
|
327
|
332
|
EslCommon.sessionOpera.put(rt, type + "|" + agentId);
|
|
|
@@ -330,18 +335,18 @@ public class WebSocketService {
|
|
330
|
335
|
}
|
|
331
|
336
|
break;
|
|
332
|
337
|
case "SubScribeOn":
|
|
333
|
|
- agent.setIsMonitor(1);
|
|
|
338
|
+ if (agent != null) agent.setIsMonitor(1);
|
|
334
|
339
|
subScribeSessionPool.add(this.session);
|
|
335
|
340
|
result.put("Result", true);
|
|
336
|
341
|
break;
|
|
337
|
342
|
case "SubScribeOff":
|
|
338
|
|
- agent.setIsMonitor(0);
|
|
|
343
|
+ if (agent != null) agent.setIsMonitor(0);
|
|
339
|
344
|
subScribeSessionPool.remove(this.session);
|
|
340
|
345
|
result.put("Result", true);
|
|
341
|
346
|
break;
|
|
342
|
347
|
case "Listen"://监听
|
|
343
|
348
|
//空闲/置忙 可以监听
|
|
344
|
|
- if (StringHelper.isNotEmpty(agentId) && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
|
|
|
349
|
+ if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
|
|
345
|
350
|
String TargetAgentID = map.get("TargetAgentID").toString();
|
|
346
|
351
|
param = TargetAgentID;
|
|
347
|
352
|
if (StringHelper.isNotEmpty(TargetAgentID)) {
|
|
|
@@ -369,7 +374,7 @@ public class WebSocketService {
|
|
369
|
374
|
break;
|
|
370
|
375
|
case "Insert"://强插
|
|
371
|
376
|
//空闲/置忙 可以强插
|
|
372
|
|
- if (StringHelper.isNotEmpty(agentId) && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
|
|
|
377
|
+ if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
|
|
373
|
378
|
String TargetAgentID = map.get("TargetAgentID").toString();
|
|
374
|
379
|
param = TargetAgentID;
|
|
375
|
380
|
if (StringHelper.isNotEmpty(TargetAgentID)) {
|
|
|
@@ -398,7 +403,7 @@ public class WebSocketService {
|
|
398
|
403
|
break;
|
|
399
|
404
|
case "Intercept"://强截
|
|
400
|
405
|
//空闲/置忙 可以强截
|
|
401
|
|
- if (StringHelper.isNotEmpty(agentId) && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
|
|
|
406
|
+ if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
|
|
402
|
407
|
String TargetAgentID = map.get("TargetAgentID").toString();
|
|
403
|
408
|
param = TargetAgentID;
|
|
404
|
409
|
if (StringHelper.isNotEmpty(TargetAgentID)) {
|
|
|
@@ -428,7 +433,7 @@ public class WebSocketService {
|
|
428
|
433
|
}
|
|
429
|
434
|
break;
|
|
430
|
435
|
case "Break"://强拆
|
|
431
|
|
- if (state.ordinal() > 0) {
|
|
|
436
|
+ if (map.get("TargetAgentID") != null) {
|
|
432
|
437
|
String TargetAgentID = map.get("TargetAgentID").toString();
|
|
433
|
438
|
param = TargetAgentID;
|
|
434
|
439
|
if (StringHelper.isNotEmpty(TargetAgentID)) {
|
|
|
@@ -455,7 +460,7 @@ public class WebSocketService {
|
|
455
|
460
|
break;
|
|
456
|
461
|
case "Instead"://代接
|
|
457
|
462
|
//空闲/置忙 可以代接
|
|
458
|
|
- if (StringHelper.isNotEmpty(agentId) && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
|
|
|
463
|
+ if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
|
|
459
|
464
|
String TargetAgentID = map.get("TargetAgentID").toString();
|
|
460
|
465
|
param = TargetAgentID;
|
|
461
|
466
|
if (StringHelper.isNotEmpty(TargetAgentID)) {
|
|
|
@@ -491,7 +496,7 @@ public class WebSocketService {
|
|
491
|
496
|
break;
|
|
492
|
497
|
case "ForceWorkOn"://强制置闲
|
|
493
|
498
|
case "ForceWorkOff"://强制置忙
|
|
494
|
|
- if (state.ordinal() > 0) {
|
|
|
499
|
+ if (map.get("TargetAgentID") != null) {
|
|
495
|
500
|
String TargetAgentID = map.get("TargetAgentID").toString();
|
|
496
|
501
|
param = TargetAgentID;
|
|
497
|
502
|
if (StringHelper.isNotEmpty(TargetAgentID)) {
|
|
|
@@ -511,11 +516,14 @@ public class WebSocketService {
|
|
511
|
516
|
}
|
|
512
|
517
|
break;
|
|
513
|
518
|
}
|
|
|
519
|
+
|
|
514
|
520
|
AgentAction aa = new AgentAction();
|
|
515
|
521
|
aa.setAction(type);
|
|
516
|
|
- aa.setGroupNo(agent.getGroup());
|
|
517
|
|
- aa.setAgent(agent.getAgent());
|
|
518
|
|
- aa.setExten(agent.getExten());
|
|
|
522
|
+ if(agent!=null) {
|
|
|
523
|
+ aa.setGroupNo(agent.getGroup());
|
|
|
524
|
+ aa.setAgent(agent.getAgent());
|
|
|
525
|
+ aa.setExten(agent.getExten());
|
|
|
526
|
+ }
|
|
519
|
527
|
aa.setParam(param);
|
|
520
|
528
|
if (chan != null) aa.setUuid(chan.getSessionId());
|
|
521
|
529
|
aa.setIsSuccess(0);
|
|
|
@@ -574,7 +582,7 @@ public class WebSocketService {
|
|
574
|
582
|
EslCommon.agents.remove(a);
|
|
575
|
583
|
sessionPool.remove(agentId);
|
|
576
|
584
|
}
|
|
577
|
|
- if(subScribeSessionPool.contains(session))subScribeSessionPool.remove(session);
|
|
|
585
|
+ subScribeSessionPool.remove(session);
|
|
578
|
586
|
error.printStackTrace();
|
|
579
|
587
|
}
|
|
580
|
588
|
|