Browse Source

置忙数据

duhongyu 4 months ago
parent
commit
77846bf302

+ 1 - 0
jyxx

@@ -0,0 +1 @@
1
+OS9NTEFlcDdtcDlsVWdUM2V3anVIeDhpRURRdXdiUjloeHVQbDk3cUt6RitmTThzajZqWksvU0o4dWFhM3MyRg==

+ 1 - 1
midware-api/src/main/resources/application-dev.yml

@@ -5,7 +5,7 @@ spring:
5 5
   datasource:
6 6
     type: com.alibaba.druid.pool.DruidDataSource
7 7
     driver-class-name: com.mysql.cj.jdbc.Driver
8
-    url: jdbc:mysql://192.168.1.200:3306/hjzx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
8
+    url: jdbc:mysql://192.168.1.8:3306/hjzx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
9 9
     username: root
10 10
     password: 800100
11 11
 

+ 29 - 0
midware-entity/src/main/java/midware/entity/database/rep/Busy.java

@@ -0,0 +1,29 @@
1
+package midware.entity.database.rep;
2
+
3
+
4
+import com.baomidou.mybatisplus.annotation.IdType;
5
+import com.baomidou.mybatisplus.annotation.TableId;
6
+import com.baomidou.mybatisplus.annotation.TableName;
7
+import lombok.Data;
8
+
9
+import java.util.Date;
10
+
11
+@Data
12
+@TableName("rep_busy")
13
+public class Busy {
14
+    /** 主键id */
15
+    @TableId(type = IdType.AUTO)
16
+    private Long id;
17
+    /** 坐席工号 */
18
+    private String agent;
19
+    /** exten */
20
+    private String exten;
21
+    /** 开始时间 */
22
+    private Date createTime;
23
+    /** 结束时间 */
24
+    private Date endTime;
25
+    /** 置忙时长(秒) */
26
+    private Long busyDuration;
27
+    /** 是否推送 */
28
+    private Long isPush;
29
+}

+ 9 - 0
midware-mapper/src/main/java/midware/mapper/rep/BusyMapper.java

@@ -0,0 +1,9 @@
1
+package midware.mapper.rep;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import midware.entity.database.rep.Busy;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+@Mapper
8
+public interface BusyMapper extends BaseMapper<Busy> {
9
+}

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

@@ -47,6 +47,9 @@ public class EslCommon {
47 47
 
48 48
     public static List<AgentAction> actions=new ArrayList<>();
49 49
     public static List<AgentState> states=new ArrayList<>();
50
+
51
+    public static List<Busy> busys=new ArrayList<>();
52
+
50 53
     public static List<ChanEvent> events=new ArrayList<>();
51 54
     public static List<Asr> asrs=new ArrayList<>();
52 55
 

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

@@ -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
 }

+ 11 - 0
midware-service/src/main/java/midware/service/quartz/job/BatchInsertJob.java

@@ -10,6 +10,7 @@ import org.quartz.JobExecutionContext;
10 10
 
11 11
 import java.util.ArrayList;
12 12
 import java.util.List;
13
+import java.util.stream.Collectors;
13 14
 
14 15
 //批量插入数据库
15 16
 public class BatchInsertJob extends QuartzJob {
@@ -55,5 +56,15 @@ public class BatchInsertJob extends QuartzJob {
55 56
             }
56 57
             SpringHelper.getBean(IAsrService.class).insert(asrs);
57 58
         }
59
+        if(EslCommon.busys.size()>0) {
60
+            List<Busy> busyList = new ArrayList<>();
61
+            synchronized (EslCommon.busys) {
62
+                busyList = EslCommon.busys.stream()
63
+                        .filter(busy -> busy.getCreateTime() != null && busy.getEndTime() != null)
64
+                        .collect(Collectors.toList());
65
+                EslCommon.busys.removeAll(busyList);
66
+            }
67
+            SpringHelper.getBean(IBusyService.class).insert(busyList);
68
+        }
58 69
     }
59 70
 }

+ 7 - 0
midware-service/src/main/java/midware/service/rep/IBusyService.java

@@ -0,0 +1,7 @@
1
+package midware.service.rep;
2
+
3
+import midware.entity.database.rep.Busy;
4
+import midware.service.IBaseService;
5
+
6
+public interface IBusyService extends IBaseService<Busy> {
7
+}

+ 14 - 0
midware-service/src/main/java/midware/service/rep/impl/BusyServiceImpl.java

@@ -0,0 +1,14 @@
1
+package midware.service.rep.impl;
2
+
3
+import midware.entity.database.rep.Busy;
4
+import midware.mapper.rep.BusyMapper;
5
+import midware.service.BaseServiceImpl;
6
+import midware.service.rep.IBusyService;
7
+import org.springframework.stereotype.Service;
8
+import org.springframework.transaction.annotation.Transactional;
9
+
10
+@Transactional
11
+@Service
12
+public class BusyServiceImpl extends BaseServiceImpl<BusyMapper, Busy> implements IBusyService {
13
+    public BusyServiceImpl(){ super(false); }
14
+}