zhoufan il y a 1 an
Parent
commit
d3734f1be9

+ 1 - 4
midware-api/src/main/java/midware/ApiApplication.java

@@ -8,13 +8,10 @@ import org.springframework.context.ConfigurableApplicationContext;
8 8
 import org.springframework.core.env.Environment;
9 9
 import org.springframework.scheduling.annotation.EnableAsync;
10 10
 
11
-import java.net.InetAddress;
12
-import java.net.UnknownHostException;
13
-
14 11
 @SpringBootApplication
15 12
 @EnableAsync
16 13
 public class ApiApplication {
17
-    public static void main(String[] args) throws UnknownHostException {
14
+    public static void main(String[] args) {
18 15
         //SpringApplication.run(WebApiApplication.class, args);
19 16
         SpringApplication springApplication = new SpringApplication(ApiApplication.class);
20 17
         springApplication.setBannerMode(Banner.Mode.OFF);

+ 14 - 4
midware-api/src/main/java/midware/controller/HomeController.java

@@ -12,16 +12,14 @@ import midware.service.eslclient.entity.Channel;
12 12
 import midware.service.eslclient.entity.Session;
13 13
 import midware.service.init.EslClientService;
14 14
 import midware.service.rep.IIvrService;
15
-import midware.util.helper.CodeHelper;
16
-import midware.util.helper.RedisHelper;
17
-import midware.util.helper.StringHelper;
18
-import midware.util.helper.TtsHelper;
15
+import midware.util.helper.*;
19 16
 import org.springframework.beans.factory.annotation.Autowired;
20 17
 import org.springframework.web.bind.annotation.*;
21 18
 
22 19
 import javax.servlet.http.HttpServletResponse;
23 20
 import java.io.IOException;
24 21
 import java.io.PrintWriter;
22
+import java.text.SimpleDateFormat;
25 23
 import java.util.*;
26 24
 import java.util.concurrent.TimeUnit;
27 25
 import java.util.stream.Collectors;
@@ -56,6 +54,18 @@ public class HomeController extends BaseController {
56 54
         return Success("", new Date());
57 55
     }
58 56
 
57
+    @GetMapping("/mac")
58
+    public AjaxResult Mac() {
59
+        return Success("", IpHelper.getMac());
60
+    }
61
+
62
+    @GetMapping("/authcode/{date}/{num}")
63
+    public AjaxResult AuthCode(@PathVariable String date,@PathVariable int num) {
64
+        String str = SecretHelper.MD5(IpHelper.getMac()) + "|" + date + "|" + num;
65
+        String result = Base64.getEncoder().encodeToString(SecretHelper.AesEncrypt(str).getBytes());
66
+        return Success("", result);
67
+    }
68
+
59 69
     @GetMapping("/esl")
60 70
     public AjaxResult Esl() {
61 71
         Map<String, Object> map = new HashMap<>();

+ 66 - 4
midware-service/src/main/java/midware/service/eslclient/EslCommon.java

@@ -1,22 +1,38 @@
1 1
 package midware.service.eslclient;
2 2
 
3
+import lombok.extern.slf4j.Slf4j;
3 4
 import midware.entity.database.rep.AgentAction;
4 5
 import midware.entity.database.rep.AgentState;
5 6
 import midware.entity.database.rep.ChanEvent;
6 7
 import midware.service.eslclient.entity.Agent;
8
+import midware.service.eslclient.entity.Auth;
7 9
 import midware.service.eslclient.entity.Channel;
8 10
 import midware.service.eslclient.entity.Session;
11
+import midware.service.init.EslClientService;
12
+import midware.util.enums.EslAgentEnum;
13
+import midware.util.helper.IpHelper;
14
+import midware.util.helper.SecretHelper;
15
+import midware.util.helper.SpringHelper;
16
+import midware.util.helper.StringHelper;
9 17
 
10
-import java.util.ArrayList;
11
-import java.util.HashMap;
12
-import java.util.List;
13
-import java.util.Map;
18
+import java.io.BufferedReader;
19
+import java.io.File;
20
+import java.io.IOException;
21
+import java.io.InputStreamReader;
22
+import java.nio.charset.StandardCharsets;
23
+import java.nio.file.Files;
24
+import java.text.ParseException;
25
+import java.text.SimpleDateFormat;
26
+import java.util.*;
14 27
 import java.util.concurrent.locks.Lock;
15 28
 import java.util.concurrent.locks.ReentrantLock;
16 29
 import java.util.stream.Collectors;
17 30
 
31
+@Slf4j
18 32
 public class EslCommon {
19 33
     static Lock eslLock=new ReentrantLock();
34
+    //授权信息
35
+    public static Auth auth=new Auth();
20 36
     //坐席列表
21 37
     public static List<Agent> agents=new ArrayList<>();
22 38
     //通道列表
@@ -100,4 +116,50 @@ public class EslCommon {
100 116
     public static boolean isInSession(String number) {
101 117
         return channels.stream().anyMatch(p -> p.getNumber().equals(number) && !p.getSessionId().equals(""));
102 118
     }
119
+
120
+    public static void checkAuth(){
121
+        boolean isAuth = false;
122
+        Date time = null;
123
+        int agentNum = 0;
124
+        try {
125
+            File file = new File("jyxx");
126
+            if (file.exists()) {
127
+                String s = "";
128
+                InputStreamReader in = new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8);
129
+                BufferedReader br = new BufferedReader(in);
130
+                StringBuilder sb = new StringBuilder();
131
+                while ((s = br.readLine()) != null) {
132
+                    sb.append(s);
133
+                }
134
+                String content = sb.toString();
135
+                String result = SecretHelper.AesDecrypt(new String(Base64.getDecoder().decode(content)));
136
+                if (StringHelper.isNotEmpty(result)) {
137
+                    String[] results = result.split("\\|");
138
+                    if (SecretHelper.MD5(IpHelper.getMac()).equals(results[0])) {
139
+                        time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(results[1] + " 23:59:59");
140
+                        agentNum = Integer.parseInt(results[2]);
141
+                        isAuth = true;
142
+                    }
143
+                }
144
+            }
145
+
146
+        } catch (IOException | ParseException e) {
147
+            log.error("授权解析失败", e);
148
+        }
149
+        if (isAuth && time.compareTo(new Date()) > 0) {
150
+            EslCommon.auth.setExpire(false);
151
+            EslCommon.auth.setExpireTime(time);
152
+            EslCommon.auth.setAgentNum(agentNum);
153
+        } else {
154
+            EslCommon.auth = new Auth();
155
+            if (EslCommon.agents.size() > 0) {
156
+                EslClientService eslClientService = SpringHelper.getBean(EslClientService.class);
157
+                for (Agent a : EslCommon.agents) {
158
+                    eslClientService.logout(a.getAgent(), a.getGroup());
159
+                    a.setAgentState(EslAgentEnum.logout.ordinal());
160
+                }
161
+                EslCommon.agents=new ArrayList<>();
162
+            }
163
+        }
164
+    }
103 165
 }

+ 27 - 18
midware-service/src/main/java/midware/service/eslclient/EslEventListener.java

@@ -13,7 +13,7 @@ import midware.service.eslclient.entity.Session;
13 13
 import midware.service.init.EslClientService;
14 14
 import midware.service.init.WebSocketService;
15 15
 import midware.service.rep.IRecordService;
16
-import midware.util.enums.EslAgentNum;
16
+import midware.util.enums.EslAgentEnum;
17 17
 import midware.util.enums.EslCommandEnum;
18 18
 import midware.util.enums.EslEventEnum;
19 19
 import midware.util.helper.SpringHelper;
@@ -55,11 +55,20 @@ public class EslEventListener implements IEslEventListener {
55 55
                     if(StringHelper.isEmpty(exten))exten=header.get("from-user");
56 56
                     Channel chan1 = EslCommon.getChanByExten(exten);
57 57
                     if(chan1!=null) {
58
+                        //通话中或者振铃中,断开
59
+                        if (StringHelper.isNotEmpty(chan1.getSessionId())) {
60
+                            try {
61
+                                eslClientService.kill(chan1.getSessionId());
62
+                                Thread.sleep(300);
63
+                            } catch (InterruptedException e) {
64
+                                throw new RuntimeException(e);
65
+                            }
66
+                        }
58 67
                         EslCommon.channels.remove(chan1);
59 68
                         Agent at = EslCommon.getAgentByExten(exten);
60
-                        if (at != null){
61
-                            if (at.getAgentState() != EslAgentNum.logout.ordinal()) {
62
-                                at.setAgentState(EslAgentNum.logout.ordinal());
69
+                        if (at != null) {
70
+                            if (at.getAgentState() != EslAgentEnum.logout.ordinal()) {
71
+                                at.setAgentState(EslAgentEnum.logout.ordinal());
63 72
                             }
64 73
                             eslClientService.logout(at.getAgent(), at.getGroup());
65 74
                             EslCommon.agents.remove(at);
@@ -191,7 +200,7 @@ public class EslEventListener implements IEslEventListener {
191 200
                         if (callType==2) {
192 201
                             eslClientService.setWork(agent.getAgent(), false);
193 202
                         }
194
-                        agent.setAgentState(EslAgentNum.requested.ordinal());
203
+                        agent.setAgentState(EslAgentEnum.requested.ordinal());
195 204
                         if (agent.getOpType() == 4) return;
196 205
                     }
197 206
 
@@ -310,13 +319,13 @@ public class EslEventListener implements IEslEventListener {
310 319
                         //被叫应答
311 320
                         if (chan.getSessionSort() > 1) {
312 321
                             if (agent != null) {
313
-                                agent.setAgentState(EslAgentNum.talking.ordinal());
322
+                                agent.setAgentState(EslAgentEnum.talking.ordinal());
314 323
                                 if (agent.getOpType() == 4) return;
315 324
                             }
316 325
                             //分机打分机时更新主叫坐席状态
317 326
                             if (callType==2 && !session.isAnswer()) {
318 327
                                 Agent callerAgent = EslCommon.getAgentByExten(callerNum);
319
-                                if (callerAgent != null) callerAgent.setAgentState(EslAgentNum.talking.ordinal());
328
+                                if (callerAgent != null) callerAgent.setAgentState(EslAgentEnum.talking.ordinal());
320 329
                             }
321 330
 
322 331
                             String ext = callerNum;
@@ -367,7 +376,7 @@ public class EslEventListener implements IEslEventListener {
367 376
                     //代接
368 377
                     if(agent!=null&&agent.getOpType()==5) {
369 378
                         Agent agent1 = EslCommon.getAgentByExten(header.get("Caller-Callee-ID-Number"));
370
-                        if (agent1 != null) agent1.setAgentState(EslAgentNum.talking.ordinal());
379
+                        if (agent1 != null) agent1.setAgentState(EslAgentEnum.talking.ordinal());
371 380
                     }
372 381
                     break;
373 382
                 case CHANNEL_HANGUP_COMPLETE:
@@ -396,16 +405,16 @@ public class EslEventListener implements IEslEventListener {
396 405
                         if (agent != null) {
397 406
                             String agentNo = agent.getAgent();
398 407
                             if (callType==1 && chan.isAnswer()) {//呼入接通后挂断-话后处理
399
-                                agent.setAgentState(EslAgentNum.aftertalk.ordinal());
408
+                                agent.setAgentState(EslAgentEnum.aftertalk.ordinal());
400 409
                                 new ScheduledThreadPoolExecutor(1).schedule(() -> {
401 410
                                     Agent agent2 = EslCommon.getAgent(agentNo);
402
-                                    if (agent2 != null && agent2.getAgentState() == EslAgentNum.aftertalk.ordinal()) {
403
-                                        agent2.setAgentState(EslAgentNum.free.ordinal());
411
+                                    if (agent2 != null && agent2.getAgentState() == EslAgentEnum.aftertalk.ordinal()) {
412
+                                        agent2.setAgentState(EslAgentEnum.free.ordinal());
404 413
                                     }
405 414
                                 }, 20, TimeUnit.SECONDS);
406 415
                             } else {//呼出挂断-空闲
407 416
                                 chan.setSessionId("");
408
-                                agent.setAgentState(EslAgentNum.free.ordinal());
417
+                                agent.setAgentState(EslAgentEnum.free.ordinal());
409 418
                             }
410 419
                             if (callType==2) {
411 420
                                 eslClientService.setWork(agentNo, true);
@@ -519,23 +528,23 @@ public class EslEventListener implements IEslEventListener {
519 528
             if (bodys.startsWith("+OK")) {
520 529
                 switch (type) {
521 530
                     case "Login"://签入
522
-                        agent.setAgentState(EslAgentNum.free.ordinal());
531
+                        agent.setAgentState(EslAgentEnum.free.ordinal());
523 532
                         break;
524 533
                     case "Logout"://签出
525
-                        agent.setAgentState(EslAgentNum.logout.ordinal());
534
+                        agent.setAgentState(EslAgentEnum.logout.ordinal());
526 535
                         EslCommon.agents.remove(agent);
527 536
                         break;
528 537
                     case "WorkOn"://置闲
529
-                        agent.setAgentState(EslAgentNum.free.ordinal());
538
+                        agent.setAgentState(EslAgentEnum.free.ordinal());
530 539
                         break;
531 540
                     case "WorkOff"://置忙
532
-                        agent.setAgentState(EslAgentNum.busy.ordinal());
541
+                        agent.setAgentState(EslAgentEnum.busy.ordinal());
533 542
                         break;
534 543
                     case "ForceWorkOn"://强制置闲
535 544
                     case "ForceWorkOff"://强制置忙
536 545
                         Agent tagent = EslCommon.getAgent(values[2]);
537
-                        if (type.equals("ForceWorkOn")) tagent.setAgentState(EslAgentNum.free.ordinal());
538
-                        else tagent.setAgentState(EslAgentNum.busy.ordinal());
546
+                        if (type.equals("ForceWorkOn")) tagent.setAgentState(EslAgentEnum.free.ordinal());
547
+                        else tagent.setAgentState(EslAgentEnum.busy.ordinal());
539 548
                         break;
540 549
                     case "HoldOn"://开启保持
541 550
                         break;

+ 0 - 3
midware-service/src/main/java/midware/service/eslclient/entity/Agent.java

@@ -6,14 +6,11 @@ import lombok.Setter;
6 6
 import midware.entity.database.rep.AgentState;
7 7
 import midware.service.eslclient.EslCommon;
8 8
 import midware.service.init.WebSocketService;
9
-import midware.service.rep.IAgentStateService;
10
-import midware.util.helper.AsyncHelper;
11 9
 import midware.util.helper.SpringHelper;
12 10
 
13 11
 import java.util.Date;
14 12
 import java.util.HashMap;
15 13
 import java.util.Map;
16
-import java.util.TimerTask;
17 14
 
18 15
 @Data
19 16
 public class Agent {

+ 17 - 0
midware-service/src/main/java/midware/service/eslclient/entity/Auth.java

@@ -0,0 +1,17 @@
1
+package midware.service.eslclient.entity;
2
+
3
+import lombok.Data;
4
+
5
+import java.util.Date;
6
+
7
+@Data
8
+public class Auth {
9
+    //过期时间
10
+    private Date ExpireTime = null;
11
+    //是否过期
12
+    private boolean isExpire = true;
13
+    // 通道数量
14
+    //private long channelNum = 0;
15
+    // 坐席数量
16
+    private long agentNum = 0;
17
+}

+ 14 - 0
midware-service/src/main/java/midware/service/init/EslClientService.java

@@ -8,6 +8,7 @@ import midware.service.eslclient.EslCommon;
8 8
 import midware.service.eslclient.EslEventListener;
9 9
 import midware.service.eslclient.entity.Session;
10 10
 import midware.util.config.EslClientConfig;
11
+import midware.util.enums.EslAgentEnum;
11 12
 import midware.util.enums.EslCommandEnum;
12 13
 import midware.util.enums.EslEventEnum;
13 14
 import midware.util.helper.StringHelper;
@@ -22,6 +23,7 @@ import javax.annotation.PostConstruct;
22 23
 import javax.annotation.PreDestroy;
23 24
 import java.io.File;
24 25
 import java.text.SimpleDateFormat;
26
+import java.util.ArrayList;
25 27
 import java.util.Date;
26 28
 import java.util.concurrent.ScheduledThreadPoolExecutor;
27 29
 import java.util.concurrent.TimeUnit;
@@ -68,6 +70,14 @@ public class EslClientService {
68 70
                     } catch (Exception e1) {
69 71
                     }
70 72
                 }
73
+            }else {
74
+                if (EslCommon.agents.size() > 0) {
75
+                    for (Agent a : EslCommon.agents) {
76
+                        logout(a.getAgent(), a.getGroup());
77
+                        a.setAgentState(EslAgentEnum.logout.ordinal());
78
+                    }
79
+                    EslCommon.agents=new ArrayList<>();
80
+                }
71 81
             }
72 82
         }, 1, 5000, TimeUnit.MILLISECONDS);
73 83
 
@@ -81,6 +91,8 @@ public class EslClientService {
81 91
             String path=new File("").getAbsolutePath();
82 92
             client.sendAsyncApiCommand(EslCommandEnum.global_setvar.name(), "md_base_dir=" +path );
83 93
         }
94
+
95
+        EslCommon.checkAuth();
84 96
     }
85 97
 
86 98
     @PreDestroy
@@ -88,7 +100,9 @@ public class EslClientService {
88 100
         if (EslCommon.agents.size() > 0) {
89 101
             for (Agent a : EslCommon.agents) {
90 102
                 logout(a.getAgent(), a.getGroup());
103
+                a.setAgentState(EslAgentEnum.logout.ordinal());
91 104
             }
105
+            EslCommon.agents=new ArrayList<>();
92 106
         }
93 107
     }
94 108
 

+ 2 - 0
midware-service/src/main/java/midware/service/init/QuartzService.java

@@ -1,6 +1,7 @@
1 1
 package midware.service.init;
2 2
 
3 3
 import lombok.extern.slf4j.Slf4j;
4
+import midware.service.quartz.job.AuthJob;
4 5
 import midware.service.quartz.job.BatchInsertJob;
5 6
 import midware.service.quartz.util.QuartzHelper;
6 7
 import org.quartz.Scheduler;
@@ -27,5 +28,6 @@ public class QuartzService {
27 28
         }
28 29
 
29 30
         QuartzHelper.createScheduleJob(scheduler, new BatchInsertJob());
31
+        QuartzHelper.createScheduleJob(scheduler, new AuthJob());
30 32
     }
31 33
 }

+ 43 - 33
midware-service/src/main/java/midware/service/init/WebSocketService.java

@@ -6,7 +6,7 @@ import midware.entity.database.rep.AgentAction;
6 6
 import midware.service.eslclient.EslCommon;
7 7
 import midware.service.eslclient.entity.Agent;
8 8
 import midware.service.eslclient.entity.Channel;
9
-import midware.util.enums.EslAgentNum;
9
+import midware.util.enums.EslAgentEnum;
10 10
 import midware.util.helper.SpringHelper;
11 11
 import midware.util.helper.StringHelper;
12 12
 import org.springframework.stereotype.Component;
@@ -48,8 +48,8 @@ public class WebSocketService {
48 48
         try {
49 49
             Agent a = EslCommon.getAgent(agentId);
50 50
             if (a != null) {
51
-                if (a.getAgentState() != EslAgentNum.logout.ordinal()) {
52
-                    a.setAgentState(EslAgentNum.logout.ordinal());
51
+                if (a.getAgentState() != EslAgentEnum.logout.ordinal()) {
52
+                    a.setAgentState(EslAgentEnum.logout.ordinal());
53 53
                 }
54 54
                 eslClientService.logout(a.getAgent(), a.getGroup());
55 55
                 EslCommon.agents.remove(a);
@@ -74,12 +74,20 @@ public class WebSocketService {
74 74
 
75 75
             Map<String, Object> result = new HashMap<>();
76 76
             result.put("Type", type);
77
+
78
+            if(EslCommon.auth.isExpire()){
79
+                result.put("Result", "授权过期");
80
+                session.getBasicRemote().sendText(JSON.toJSONString(result));
81
+                return;
82
+            }
83
+
77 84
             result.put("Result", "操作失败1");
78 85
             Agent agent = EslCommon.getAgent(agentId);
79
-            Channel chan = null;EslAgentNum state =null;
86
+            Channel chan = null;
87
+            EslAgentEnum state =null;
80 88
             if (agent != null) {
81 89
                 chan = EslCommon.getChanByExten(agent.getExten());
82
-                state = EslAgentNum.values()[agent.getAgentState()];
90
+                state = EslAgentEnum.values()[agent.getAgentState()];
83 91
                 if (chan == null) {
84 92
                     result.put("Result", "分机未注册");
85 93
                     state = null;
@@ -106,6 +114,8 @@ public class WebSocketService {
106 114
                             result.put("Result", "分机未注册");
107 115
                         } else if (EslCommon.getAgentByExten(AgentExten) != null) {
108 116
                             result.put("Result", "分机已存在");
117
+                        } else if (EslCommon.auth.getAgentNum()>0&& EslCommon.agents.size()>=EslCommon.auth.getAgentNum()) {
118
+                            result.put("Result", "坐席数量已达上限");
109 119
                         } else {
110 120
                             this.agentId = AgentId;
111 121
                             sessionPool.put(AgentId, session);
@@ -114,7 +124,7 @@ public class WebSocketService {
114 124
                             agent.setAgent(AgentId);
115 125
                             agent.setExten(AgentExten);
116 126
                             agent.setGroup(AgentGroup);
117
-                            agent.setAgentState(EslAgentNum.loging.ordinal());
127
+                            agent.setAgentState(EslAgentEnum.loging.ordinal());
118 128
 
119 129
                             chan = EslCommon.getChanByExten(AgentExten);
120 130
                             String rt = eslClientService.login(AgentId, AgentExten, AgentGroup);
@@ -129,7 +139,7 @@ public class WebSocketService {
129 139
                     break;
130 140
                 case "Logout"://签出
131 141
                     //空闲/置忙/话后处理  可以签出
132
-                    if (Arrays.asList(EslAgentNum.free, EslAgentNum.busy, EslAgentNum.aftertalk).contains(state)) {
142
+                    if (Arrays.asList(EslAgentEnum.free, EslAgentEnum.busy, EslAgentEnum.aftertalk).contains(state)) {
133 143
                         String rt = eslClientService.logout(agentId, agent.getGroup());
134 144
                         if (StringHelper.isNotEmpty(rt)) {
135 145
                             EslCommon.sessionOpera.put(rt, type + "|" + agentId);
@@ -141,7 +151,7 @@ public class WebSocketService {
141 151
                     break;
142 152
                 case "WorkOn"://置闲
143 153
                     //置忙/话后处理  可以置闲
144
-                    if (Arrays.asList(EslAgentNum.busy, EslAgentNum.aftertalk).contains(state)) {
154
+                    if (Arrays.asList(EslAgentEnum.busy, EslAgentEnum.aftertalk).contains(state)) {
145 155
                         String rt = eslClientService.setWork(agentId, true);
146 156
                         if (StringHelper.isNotEmpty(rt)) {
147 157
                             EslCommon.sessionOpera.put(rt, type + "|" + agentId);
@@ -151,7 +161,7 @@ public class WebSocketService {
151 161
                     break;
152 162
                 case "WorkOff"://置忙
153 163
                     //空闲/话后处理  可以置忙
154
-                    if (Arrays.asList(EslAgentNum.free, EslAgentNum.aftertalk).contains(state)) {
164
+                    if (Arrays.asList(EslAgentEnum.free, EslAgentEnum.aftertalk).contains(state)) {
155 165
                         String rt = eslClientService.setWork(agentId, false);
156 166
                         if (StringHelper.isNotEmpty(rt)) {
157 167
                             EslCommon.sessionOpera.put(rt, type + "|" + agentId);
@@ -161,12 +171,12 @@ public class WebSocketService {
161 171
                     break;
162 172
                 case "MakeCall"://外呼
163 173
                     //空闲/置忙/话后处理  可以外呼
164
-                    if (map.get("DestinationNumber") != null && Arrays.asList(EslAgentNum.free, EslAgentNum.busy, EslAgentNum.aftertalk).contains(state)) {
174
+                    if (map.get("DestinationNumber") != null && Arrays.asList(EslAgentEnum.free, EslAgentEnum.busy, EslAgentEnum.aftertalk).contains(state)) {
165 175
                         String DestinationNumber = map.get("DestinationNumber").toString();
166 176
                         param = DestinationNumber;
167 177
                         if (StringHelper.isNotEmpty(DestinationNumber)) {
168 178
                             Agent tAgent = EslCommon.getAgentByExten(DestinationNumber);
169
-                            if (tAgent != null && tAgent.getAgentState() != EslAgentNum.free.ordinal()) {
179
+                            if (tAgent != null && tAgent.getAgentState() != EslAgentEnum.free.ordinal()) {
170 180
                                 result.put("Result", "目标坐席忙碌中");
171 181
                             } else {
172 182
                                 String rt = eslClientService.extenCall(agent.getExten(), DestinationNumber);
@@ -180,7 +190,7 @@ public class WebSocketService {
180 190
                     break;
181 191
                 case "HoldOn"://开启保持
182 192
                     //通话中  可以开启保持
183
-                    if (Objects.equals(state, EslAgentNum.talking)) {
193
+                    if (Objects.equals(state, EslAgentEnum.talking)) {
184 194
                         String rt = eslClientService.setHold(chan.getSessionId(), true);
185 195
                         if (StringHelper.isNotEmpty(rt)) {
186 196
                             EslCommon.sessionOpera.put(rt, type + "|" + agentId);
@@ -190,7 +200,7 @@ public class WebSocketService {
190 200
                     break;
191 201
                 case "HoldOff"://关闭保持
192 202
                     //通话中  可以关闭保持
193
-                    if (Objects.equals(state, EslAgentNum.talking)) {
203
+                    if (Objects.equals(state, EslAgentEnum.talking)) {
194 204
                         String rt = eslClientService.setHold(chan.getSessionId(), false);
195 205
                         if (StringHelper.isNotEmpty(rt)) {
196 206
                             EslCommon.sessionOpera.put(rt, type + "|" + agentId);
@@ -200,7 +210,7 @@ public class WebSocketService {
200 210
                     break;
201 211
                 case "MuteOn"://开启静音
202 212
                     //通话中  可以开启静音
203
-                    if (Objects.equals(state, EslAgentNum.talking)) {
213
+                    if (Objects.equals(state, EslAgentEnum.talking)) {
204 214
                         String rt = eslClientService.setMute(chan.getChanId(), true);
205 215
                         if (StringHelper.isNotEmpty(rt)) {
206 216
                             EslCommon.sessionOpera.put(rt, type + "|" + agentId);
@@ -210,7 +220,7 @@ public class WebSocketService {
210 220
                     break;
211 221
                 case "MuteOff"://关闭静音
212 222
                     //通话中  可以关闭静音
213
-                    if (Objects.equals(state, EslAgentNum.talking)) {
223
+                    if (Objects.equals(state, EslAgentEnum.talking)) {
214 224
                         String rt = eslClientService.setMute(chan.getChanId(), false);
215 225
                         if (StringHelper.isNotEmpty(rt)) {
216 226
                             EslCommon.sessionOpera.put(rt, type + "|" + agentId);
@@ -220,7 +230,7 @@ public class WebSocketService {
220 230
                     break;
221 231
                 case "Transfer"://转移
222 232
                     //通话中  可以转移
223
-                    if (map.get("DestinationNumber") != null && Objects.equals(state, EslAgentNum.talking)) {
233
+                    if (map.get("DestinationNumber") != null && Objects.equals(state, EslAgentEnum.talking)) {
224 234
                         String DestinationNumber = map.get("DestinationNumber").toString();
225 235
                         param = DestinationNumber;
226 236
                         if (StringHelper.isNotEmpty(DestinationNumber)) {
@@ -228,7 +238,7 @@ public class WebSocketService {
228 238
                                 result.put("Result", "目标不能是自己");
229 239
                             } else {
230 240
                                 Agent tAgent = EslCommon.getAgentByExten(DestinationNumber);
231
-                                if (tAgent != null && tAgent.getAgentState() != EslAgentNum.free.ordinal()) {
241
+                                if (tAgent != null && tAgent.getAgentState() != EslAgentEnum.free.ordinal()) {
232 242
                                     result.put("Result", "目标坐席忙碌中");
233 243
                                 } else if (EslCommon.isInSession(DestinationNumber)) {
234 244
                                     result.put("Result", "目标号码忙碌中");
@@ -248,7 +258,7 @@ public class WebSocketService {
248 258
                     break;
249 259
                 case "ConsultOn"://开启协商
250 260
                     //通话中  可以协商
251
-                    if (map.get("DestinationNumber") != null && Objects.equals(state, EslAgentNum.talking)) {
261
+                    if (map.get("DestinationNumber") != null && Objects.equals(state, EslAgentEnum.talking)) {
252 262
                         String DestinationNumber = map.get("DestinationNumber").toString();
253 263
                         param = DestinationNumber;
254 264
                         if (StringHelper.isNotEmpty(DestinationNumber)) {
@@ -256,7 +266,7 @@ public class WebSocketService {
256 266
                                 result.put("Result", "目标不能是自己");
257 267
                             } else {
258 268
                                 Agent tAgent = EslCommon.getAgentByExten(DestinationNumber);
259
-                                if (tAgent != null && tAgent.getAgentState() != EslAgentNum.free.ordinal()) {
269
+                                if (tAgent != null && tAgent.getAgentState() != EslAgentEnum.free.ordinal()) {
260 270
                                     result.put("Result", "目标坐席忙碌中");
261 271
                                 } else if (EslCommon.isInSession(DestinationNumber)) {
262 272
                                     result.put("Result", "目标号码忙碌中");
@@ -276,7 +286,7 @@ public class WebSocketService {
276 286
                     break;
277 287
                 case "ConsultOff"://关闭协商
278 288
                     //通话中  可以协商取消
279
-                    if (Objects.equals(state, EslAgentNum.talking)) {
289
+                    if (Objects.equals(state, EslAgentEnum.talking)) {
280 290
                         String sid = chan.getSessionId();
281 291
                         Channel channel = EslCommon.channels.stream().filter(p -> p.getSessionId().equals(sid)
282 292
                                 && p.getSessionSort() == 3).findFirst().get();
@@ -289,7 +299,7 @@ public class WebSocketService {
289 299
                     break;
290 300
                 case "Meeting"://会议
291 301
                     //通话中  可以会议
292
-                    if (map.get("DestinationNumber") != null && Objects.equals(state, EslAgentNum.talking)) {
302
+                    if (map.get("DestinationNumber") != null && Objects.equals(state, EslAgentEnum.talking)) {
293 303
                         String DestinationNumber = map.get("DestinationNumber").toString();
294 304
                         param = DestinationNumber;
295 305
                         if (StringHelper.isNotEmpty(DestinationNumber)) {
@@ -297,7 +307,7 @@ public class WebSocketService {
297 307
                                 result.put("Result", "目标不能是自己");
298 308
                             } else {
299 309
                                 Agent tAgent = EslCommon.getAgentByExten(DestinationNumber);
300
-                                if (tAgent != null && tAgent.getAgentState() != EslAgentNum.free.ordinal()) {
310
+                                if (tAgent != null && tAgent.getAgentState() != EslAgentEnum.free.ordinal()) {
301 311
                                     result.put("Result", "目标坐席忙碌中");
302 312
                                 } else if (EslCommon.isInSession(DestinationNumber)) {
303 313
                                     result.put("Result", "目标号码忙碌中");
@@ -315,7 +325,7 @@ public class WebSocketService {
315 325
                     break;
316 326
                 case "TurnMyd"://转满意度
317 327
                     //通话中  可以转满意度
318
-                    if (Objects.equals(state, EslAgentNum.talking)) {
328
+                    if (Objects.equals(state, EslAgentEnum.talking)) {
319 329
                         String rt = eslClientService.turnMyd(chan.getSessionId());
320 330
                         if (StringHelper.isNotEmpty(rt)) {
321 331
                             EslCommon.sessionOpera.put(rt, type + "|" + agentId);
@@ -325,7 +335,7 @@ public class WebSocketService {
325 335
                     break;
326 336
                 case "DropCall"://挂机
327 337
                     //通话中/请求中  可以挂机
328
-                    if (Arrays.asList(EslAgentNum.talking, EslAgentNum.requested).contains(state)) {
338
+                    if (Arrays.asList(EslAgentEnum.talking, EslAgentEnum.requested).contains(state)) {
329 339
                         String rt = eslClientService.kill(chan.getChanId());
330 340
                         if (StringHelper.isNotEmpty(rt)) {
331 341
                             EslCommon.sessionOpera.put(rt, type + "|" + agentId);
@@ -345,7 +355,7 @@ public class WebSocketService {
345 355
                     break;
346 356
                 case "Listen"://监听
347 357
                     //空闲/置忙  可以监听
348
-                    if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
358
+                    if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentEnum.free, EslAgentEnum.busy).contains(state)) {
349 359
                         String TargetAgentID = map.get("TargetAgentID").toString();
350 360
                         param = TargetAgentID;
351 361
                         if (StringHelper.isNotEmpty(TargetAgentID)) {
@@ -373,7 +383,7 @@ public class WebSocketService {
373 383
                     break;
374 384
                 case "Insert"://强插
375 385
                     //空闲/置忙  可以强插
376
-                    if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
386
+                    if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentEnum.free, EslAgentEnum.busy).contains(state)) {
377 387
                         String TargetAgentID = map.get("TargetAgentID").toString();
378 388
                         param = TargetAgentID;
379 389
                         if (StringHelper.isNotEmpty(TargetAgentID)) {
@@ -402,7 +412,7 @@ public class WebSocketService {
402 412
                     break;
403 413
                 case "Intercept"://强截
404 414
                     //空闲/置忙  可以强截
405
-                    if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
415
+                    if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentEnum.free, EslAgentEnum.busy).contains(state)) {
406 416
                         String TargetAgentID = map.get("TargetAgentID").toString();
407 417
                         param = TargetAgentID;
408 418
                         if (StringHelper.isNotEmpty(TargetAgentID)) {
@@ -459,7 +469,7 @@ public class WebSocketService {
459 469
                     break;
460 470
                 case "Instead"://代接
461 471
                     //空闲/置忙  可以代接
462
-                    if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentNum.free, EslAgentNum.busy).contains(state)) {
472
+                    if (map.get("TargetAgentID") != null && Arrays.asList(EslAgentEnum.free, EslAgentEnum.busy).contains(state)) {
463 473
                         String TargetAgentID = map.get("TargetAgentID").toString();
464 474
                         param = TargetAgentID;
465 475
                         if (StringHelper.isNotEmpty(TargetAgentID)) {
@@ -469,7 +479,7 @@ public class WebSocketService {
469 479
                                 Agent tAgent = EslCommon.getAgent(TargetAgentID);
470 480
                                 if (tAgent == null) {
471 481
                                     result.put("Result", "目标坐席未签入");
472
-                                } else if (tAgent.getAgentState() != EslAgentNum.requested.ordinal()) {
482
+                                } else if (tAgent.getAgentState() != EslAgentEnum.requested.ordinal()) {
473 483
                                     result.put("Result", "目标坐席未振铃");
474 484
                                 } else {
475 485
                                     Channel tchan = EslCommon.getChanByExten(tAgent.getExten());
@@ -502,7 +512,7 @@ public class WebSocketService {
502 512
                             Agent tAgent = EslCommon.getAgent(TargetAgentID);
503 513
                             if (tAgent == null) {
504 514
                                 result.put("Result", "目标坐席未签入");
505
-                            } else if (tAgent.getAgentState() != EslAgentNum.free.ordinal()) {
515
+                            } else if (tAgent.getAgentState() != EslAgentEnum.free.ordinal()) {
506 516
                                 result.put("Result", "目标坐席不能置忙");
507 517
                             } else {
508 518
                                 String rt = eslClientService.setWork(TargetAgentID, type.equals("ForceWorkOn"));
@@ -559,7 +569,7 @@ public class WebSocketService {
559 569
         String result = "";
560 570
         if (agent == null) {
561 571
             result = "目标坐席未签入";
562
-        } else if (agent.getAgentState() != EslAgentNum.talking.ordinal()) {
572
+        } else if (agent.getAgentState() != EslAgentEnum.talking.ordinal()) {
563 573
             result = "目标坐席未通话";
564 574
         }
565 575
         return result;
@@ -574,8 +584,8 @@ public class WebSocketService {
574 584
     public void onError(Throwable error) {
575 585
         Agent a = EslCommon.getAgent(agentId);
576 586
         if (a != null) {
577
-            if (a.getAgentState() != EslAgentNum.logout.ordinal()) {
578
-                a.setAgentState(EslAgentNum.logout.ordinal());
587
+            if (a.getAgentState() != EslAgentEnum.logout.ordinal()) {
588
+                a.setAgentState(EslAgentEnum.logout.ordinal());
579 589
             }
580 590
             eslClientService.logout(a.getAgent(), a.getGroup());
581 591
             EslCommon.agents.remove(a);

+ 19 - 0
midware-service/src/main/java/midware/service/quartz/job/AuthJob.java

@@ -0,0 +1,19 @@
1
+package midware.service.quartz.job;
2
+
3
+import lombok.extern.slf4j.Slf4j;
4
+import midware.service.eslclient.EslCommon;
5
+import midware.service.quartz.util.QuartzJob;
6
+import org.quartz.JobExecutionContext;
7
+
8
+//批量插入数据库
9
+@Slf4j
10
+public class AuthJob extends QuartzJob {
11
+    public AuthJob() {
12
+        cron = "0 0/1 * * * ?";
13
+    }
14
+
15
+    @Override
16
+    protected void doExecute(JobExecutionContext context) {
17
+        EslCommon.checkAuth();
18
+    }
19
+}

+ 2 - 2
midware-util/src/main/java/midware/util/enums/EslAgentNum.java

@@ -1,6 +1,6 @@
1 1
 package midware.util.enums;
2 2
 
3
-public enum EslAgentNum {
3
+public enum EslAgentEnum {
4 4
     unkown("未知"),
5 5
     loging("登录中"),
6 6
     free("空闲"),
@@ -12,7 +12,7 @@ public enum EslAgentNum {
12 12
     ;
13 13
 
14 14
     private String description;
15
-    EslAgentNum(String description) {
15
+    EslAgentEnum(String description) {
16 16
         this.description = description;
17 17
     }
18 18
 }

+ 29 - 0
midware-util/src/main/java/midware/util/helper/IpHelper.java

@@ -26,4 +26,33 @@ public class IpHelper {
26 26
         }
27 27
         return hostIP;
28 28
     }
29
+
30
+    public static String getMac(){
31
+        String mac="";
32
+        try {
33
+            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
34
+            while (networkInterfaces.hasMoreElements()) {
35
+                NetworkInterface ni = networkInterfaces.nextElement();
36
+                if (ni.isLoopback() || ni.isVirtual() || !ni.isUp()) {
37
+                    continue;
38
+                }
39
+                byte[] macByte = ni.getHardwareAddress();
40
+                if (macByte == null) {
41
+                    continue;
42
+                }
43
+                StringBuilder buf = new StringBuilder();
44
+                for (byte aMac : macByte) {
45
+                    buf.append(String.format("%02X-", aMac));
46
+                }
47
+                if (buf.length() > 0) {
48
+                    buf.deleteCharAt(buf.length() - 1);
49
+                    mac=buf.toString();
50
+                    break;
51
+                }
52
+            }
53
+        } catch (SocketException e) {
54
+            e.printStackTrace();
55
+        }
56
+        return mac;
57
+    }
29 58
 }