|
|
@@ -5,13 +5,13 @@ import lombok.Data;
|
|
5
|
5
|
import lombok.Setter;
|
|
6
|
6
|
import lombok.extern.slf4j.Slf4j;
|
|
7
|
7
|
import midware.entity.database.rep.AgentState;
|
|
|
8
|
+import midware.entity.database.rep.Busy;
|
|
8
|
9
|
import midware.service.eslclient.EslCommon;
|
|
9
|
10
|
import midware.service.init.WebSocketService;
|
|
10
|
11
|
import midware.util.helper.SpringHelper;
|
|
11
|
12
|
|
|
12
|
|
-import java.util.Date;
|
|
13
|
|
-import java.util.HashMap;
|
|
14
|
|
-import java.util.Map;
|
|
|
13
|
+import java.util.*;
|
|
|
14
|
+import java.util.stream.Collectors;
|
|
15
|
15
|
|
|
16
|
16
|
@Slf4j
|
|
17
|
17
|
@Data
|
|
|
@@ -61,5 +61,53 @@ public class Agent {
|
|
61
|
61
|
synchronized (EslCommon.states) {
|
|
62
|
62
|
EslCommon.states.add(as);
|
|
63
|
63
|
}
|
|
|
64
|
+ synchronized (EslCommon.busys) {
|
|
|
65
|
+ if (s==5)
|
|
|
66
|
+ {
|
|
|
67
|
+ handleBusyStateStart(as);
|
|
|
68
|
+ }
|
|
|
69
|
+ else {
|
|
|
70
|
+ handleBusyStateEnd(as);
|
|
|
71
|
+ }
|
|
|
72
|
+ }
|
|
|
73
|
+ }
|
|
|
74
|
+ private void handleBusyStateStart(AgentState state) {
|
|
|
75
|
+ String agent = state.getAgent();
|
|
|
76
|
+ Date currentTime = new Date(); // 当前时间
|
|
|
77
|
+ // 检查该坐席是否已经有未结束的忙碌记录
|
|
|
78
|
+ boolean hasUnfinishedBusy = EslCommon.busys.stream()
|
|
|
79
|
+ .anyMatch(busy -> agent.equals(busy.getAgent()) && busy.getEndTime() == null);
|
|
|
80
|
+ if (hasUnfinishedBusy) {
|
|
|
81
|
+ // 如果有未结束的记录,先结束它
|
|
|
82
|
+ endExistingBusyRecord(agent, currentTime);
|
|
|
83
|
+ }
|
|
|
84
|
+ // 创建新的忙碌记录
|
|
|
85
|
+ Busy newBusy = new Busy();
|
|
|
86
|
+ newBusy.setAgent(agent);
|
|
|
87
|
+ newBusy.setExten(state.getExten());
|
|
|
88
|
+ newBusy.setCreateTime(currentTime);
|
|
|
89
|
+ newBusy.setEndTime(null); // 结束时间为空
|
|
|
90
|
+ newBusy.setBusyDuration(0L); // 刚开始,时长为0
|
|
|
91
|
+ newBusy.setIsPush(0L); // 未推送
|
|
|
92
|
+ EslCommon.busys.add(newBusy);
|
|
|
93
|
+ }
|
|
|
94
|
+ private void handleBusyStateEnd(AgentState state) {
|
|
|
95
|
+ String agent = state.getAgent();
|
|
|
96
|
+ Date currentTime = new Date();
|
|
|
97
|
+ // 结束该坐席所有未结束的忙碌记录
|
|
|
98
|
+ endExistingBusyRecord(agent, currentTime);
|
|
64
|
99
|
}
|
|
|
100
|
+ private void endExistingBusyRecord(String agent, Date endTime) {
|
|
|
101
|
+ List<Busy> unfinishedRecords = EslCommon.busys.stream()
|
|
|
102
|
+ .filter(busy -> agent.equals(busy.getAgent()) && busy.getEndTime() == null)
|
|
|
103
|
+ .collect(Collectors.toList());
|
|
|
104
|
+ for (Busy busy : unfinishedRecords) {
|
|
|
105
|
+ // 计算忙碌时长(秒)
|
|
|
106
|
+ long duration = (endTime.getTime() - busy.getCreateTime().getTime()) / 1000;
|
|
|
107
|
+ // 更新记录
|
|
|
108
|
+ busy.setEndTime(endTime);
|
|
|
109
|
+ busy.setBusyDuration(duration);
|
|
|
110
|
+ }
|
|
|
111
|
+ }
|
|
|
112
|
+
|
|
65
|
113
|
}
|