zhoufan hace 1 año
padre
commit
c5e5de42d9

+ 5 - 0
midware-api/src/main/java/midware/controller/HomeController.java

@@ -67,6 +67,11 @@ public class HomeController extends BaseController {
67 67
         return Success("", result);
68 68
     }
69 69
 
70
+    @GetMapping("/agentfree")
71
+    public String AgentFree() {
72
+        return EslCommon.agents.stream().anyMatch(p -> p.getAgentState() == 2) ? "1" : "0";
73
+    }
74
+
70 75
     @GetMapping("/esl")
71 76
     public AjaxResult Esl() {
72 77
         Map<String, Object> map = new HashMap<>();

+ 30 - 42
midware-service/src/main/java/midware/service/eslclient/EslEventListener.java

@@ -108,7 +108,8 @@ public class EslEventListener implements IEslEventListener {
108 108
                             String uuid = header.get("Channel-Call-UUID");
109 109
                             new ScheduledThreadPoolExecutor(1).schedule(() -> {
110 110
                                 if (EslCommon.groupTempList.get(queue).remove(caller)) {
111
-                                    if (!EslCommon.groupWaitList.containsKey(queue)) {
111
+                                    long wn = EslCommon.channels.stream().filter(p -> p.getSessionId().equals(uuid)).count();
112
+                                    if (wn == 1 && !EslCommon.groupWaitList.containsKey(queue)) {
112 113
                                         EslCommon.groupWaitList.put(queue, new ArrayList<>());
113 114
                                     }
114 115
                                     List<String> listWait = EslCommon.groupWaitList.get(queue);
@@ -118,7 +119,7 @@ public class EslEventListener implements IEslEventListener {
118 119
                                     result.put("Type", "Wait");
119 120
                                     result.put("Result", true);
120 121
                                     result.put("Count", listWait.size());
121
-                                    webSocketService.sendMessageGroupAll(queue,JSON.toJSONString(result));
122
+                                    webSocketService.sendMessageGroupAll(queue, JSON.toJSONString(result));
122 123
 
123 124
                                     //播报位置
124 125
                                     eslClientService.playPosition(listWait.indexOf(caller) + 1, uuid);
@@ -131,9 +132,15 @@ public class EslEventListener implements IEslEventListener {
131 132
                                     //每隔20s播报位置
132 133
                                     ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
133 134
                                     executor.scheduleAtFixedRate(() -> {
135
+                                        long wc = EslCommon.channels.stream().filter(p -> p.getSessionId().equals(uuid)).count();
134 136
                                         int postion = EslCommon.groupWaitList.get(queue).indexOf(caller);
135 137
                                         if (postion >= 0) {
136
-                                            eslClientService.playPosition(postion + 1, uuid);
138
+                                            if (wc == 1) {
139
+                                                eslClientService.playPosition(postion + 1, uuid);
140
+                                            } else {
141
+                                                delWait(queue,caller);
142
+                                                executor.shutdown();
143
+                                            }
137 144
                                         } else {
138 145
                                             executor.shutdown();
139 146
                                         }
@@ -143,35 +150,11 @@ public class EslEventListener implements IEslEventListener {
143 150
                             break;
144 151
                         case "agent-offering":
145 152
                             String phone = header.get("CC-Member-CID-Name");
146
-                            if (EslCommon.groupTempList.containsKey(queue)) {
147
-                                EslCommon.groupTempList.get(queue).remove(phone);
148
-                            }
149
-                            if (EslCommon.groupWaitList.containsKey(queue)) {
150
-                                if (EslCommon.groupWaitList.get(queue).remove(phone)) {
151
-                                    //排队数量
152
-                                    Map<String, Object> result = new HashMap<>();
153
-                                    result.put("Type", "Wait");
154
-                                    result.put("Result", true);
155
-                                    result.put("Count", EslCommon.groupWaitList.get(queue).size());
156
-                                    webSocketService.sendMessageGroupAll(queue,JSON.toJSONString(result));
157
-                                }
158
-                            }
153
+                            delWait(queue,phone);
159 154
                             //eslClientService.playAgent(header.get("CC-Agent"), header.get("CC-Member-Session-UUID"));
160 155
                             break;
161 156
                         case "member-queue-end":
162
-                            if (EslCommon.groupTempList.containsKey(queue)) {
163
-                                EslCommon.groupTempList.get(queue).remove(caller);
164
-                            }
165
-                            if (EslCommon.groupWaitList.containsKey(queue)) {
166
-                                if (EslCommon.groupWaitList.get(queue).remove(caller)) {
167
-                                    //排队数量
168
-                                    Map<String, Object> result = new HashMap<>();
169
-                                    result.put("Type", "Wait");
170
-                                    result.put("Result", true);
171
-                                    result.put("Count", EslCommon.groupWaitList.get(queue).size());
172
-                                    webSocketService.sendMessageGroupAll(queue,JSON.toJSONString(result));
173
-                                }
174
-                            }
157
+                            delWait(queue,caller);
175 158
                             break;
176 159
                     }
177 160
                     break;
@@ -259,19 +242,7 @@ public class EslEventListener implements IEslEventListener {
259 242
                             if (calleeAgent != null) {
260 243
 
261 244
                                 String queue = calleeAgent.getGroup();
262
-                                if (EslCommon.groupTempList.containsKey(queue)) {
263
-                                    EslCommon.groupTempList.get(queue).remove(callerNum);
264
-                                }
265
-                                if (EslCommon.groupWaitList.containsKey(queue)) {
266
-                                    if (EslCommon.groupWaitList.get(queue).remove(callerNum)) {
267
-                                        //排队数量
268
-                                        Map<String, Object> result = new HashMap<>();
269
-                                        result.put("Type", "Wait");
270
-                                        result.put("Result", true);
271
-                                        result.put("Count", EslCommon.groupWaitList.get(queue).size());
272
-                                        webSocketService.sendMessageGroupAll(queue,JSON.toJSONString(result));
273
-                                    }
274
-                                }
245
+                                delWait(queue,callerNum);
275 246
 
276 247
                                 calleeAgent.setCallType(1);
277 248
                                 uw = new LambdaUpdateWrapper<>();
@@ -810,6 +781,23 @@ public class EslEventListener implements IEslEventListener {
810 781
         }
811 782
     }
812 783
 
784
+    //删除排队
785
+    private void delWait(String queue,String phone){
786
+        if (EslCommon.groupTempList.containsKey(queue)) {
787
+            EslCommon.groupTempList.get(queue).remove(phone);
788
+        }
789
+        if (EslCommon.groupWaitList.containsKey(queue)) {
790
+            if (EslCommon.groupWaitList.get(queue).remove(phone)) {
791
+                //排队数量
792
+                Map<String, Object> result = new HashMap<>();
793
+                result.put("Type", "Wait");
794
+                result.put("Result", true);
795
+                result.put("Count", EslCommon.groupWaitList.get(queue).size());
796
+                SpringHelper.getBean(WebSocketService.class).sendMessageGroupAll(queue,JSON.toJSONString(result));
797
+            }
798
+        }
799
+    }
800
+
813 801
     //获取识别结果
814 802
     private String getXmlResult(String xml, boolean islm) {
815 803
         String result = "";

+ 1 - 1
midware-service/src/main/java/midware/service/init/EslClientService.java

@@ -505,7 +505,6 @@ public class EslClientService {
505 505
                     + "conference:" + sessionId + "@" + at + "' inline";
506 506
             result = client.sendAsyncApiCommand(command, arg);
507 507
             if (!result.equals("") && session != null) session.setMeeting(true);
508
-            setConferenceExitSound(sessionId, true);
509 508
         } catch (Exception e) {
510 509
             log.error(sessionId + " 会话加入会议失败", e);
511 510
         }
@@ -536,6 +535,7 @@ public class EslClientService {
536 535
                     + " &conference(" + meetingId + "@" + at + ")"
537 536
                     + "\r\nJob-UUID: " + action + "|" + System.currentTimeMillis();
538 537
             result = client.sendAsyncApiCommand(command, arg);
538
+            setConferenceExitSound(meetingId, true);
539 539
         } catch (Exception e) {
540 540
             log.error(callerNum + "|" + calleeNum + "|" + meetingId + " 呼叫加入会议失败", e);
541 541
         }