Przeglądaj źródła

ITSM录音和对接

CX 1 rok temu
rodzic
commit
049db6f25e

+ 10 - 0
src/main/java/com/dashitech/businessdata/dao/ICallRecordDAO.java

@@ -0,0 +1,10 @@
1
+package com.dashitech.businessdata.dao;
2
+
3
+import com.dashitech.businessdata.entity.CallRecordEntity;
4
+import org.springframework.data.jpa.repository.JpaRepository;
5
+
6
+/**
7
+ */
8
+public interface ICallRecordDAO extends JpaRepository<CallRecordEntity, String> {
9
+    CallRecordEntity save(CallRecordEntity callLogEntity);
10
+}

+ 245 - 0
src/main/java/com/dashitech/businessdata/entity/CallRecordEntity.java

@@ -0,0 +1,245 @@
1
+package com.dashitech.businessdata.entity;
2
+
3
+import com.dashitech.utils.I18n;
4
+
5
+import javax.persistence.*;
6
+import java.io.Serializable;
7
+import java.util.Date;
8
+
9
+/**
10
+ * ITSM通话记录表
11
+ */
12
+@Entity
13
+@Table(name = "itsm_call_record")
14
+public class CallRecordEntity implements Serializable {
15
+
16
+    @Id
17
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
18
+    @Column(name = "id", length = 20)
19
+    private Long id;
20
+
21
+    @Version
22
+    @Column(name = "VERSION")
23
+    private Integer version;
24
+
25
+    @I18n("通话流水")
26
+    @Column(name = "call_accept")
27
+    private String callAccept;
28
+
29
+    @I18n("主叫名称")
30
+    @Column(name = "caller_id_number")
31
+    private String callerIdNumber;
32
+
33
+    @I18n("被叫号码")
34
+    @Column(name = "destination_number")
35
+    private String destinationNumber;
36
+
37
+    @I18n("话务发起时间")
38
+    @Column(name = "created_time")
39
+    private Date createdTime;
40
+
41
+    @I18n("话务接听时间,如果电话未接,则为空")
42
+    @Column(name = "answered_time")
43
+    private Date answeredTime;
44
+
45
+    @I18n("话务结束时间")
46
+    @Column(name = "over_time")
47
+    private Date overTime;
48
+
49
+    @I18n("话务使用的线路")
50
+    @Column(name = "gate_way")
51
+    private String gateWay;
52
+
53
+    @I18n("通话录音的绝对地址,如果未接通,则为空")
54
+    @Column(name = "recording_file_name")
55
+    private String recordingFileName;
56
+
57
+    @I18n("自动外呼的任务id号,如果是点击拨号则为空")
58
+    @Column(name = "batch_accept")
59
+    private String batchAccept;
60
+
61
+    @I18n("点击拨号客户自定义的标识,不传为空")
62
+    @Column(name = "other_str")
63
+    private String otherStr;
64
+
65
+    @I18n("1,传入的phone作为主叫(呼出),2,传入的phone作为被叫(呼入),3批量外呼流水号,不传查全部")
66
+    @Column(name = "call_type")
67
+    private String callType;
68
+
69
+    @I18n("通话时长")
70
+    @Column(name = "calltime")
71
+    private String callTime;
72
+
73
+    @I18n("线路或者系统返回的状态,无实际意义")
74
+    @Column(name = "status")
75
+    private String status;
76
+
77
+    @I18n("挂断方")
78
+    @Column(name = "hangup_side")
79
+    private String hangupSide;
80
+
81
+
82
+    @I18n("是否被接听,0未接、1已接")
83
+    @Column(name = "is_answered")
84
+    private Integer isAnswered;
85
+
86
+    @I18n("用户id")
87
+    @Column(name = "user_id")
88
+    private Long userId;
89
+
90
+    @I18n("院区id")
91
+    @Column(name = "branch_id")
92
+    private Long branch;
93
+
94
+    public Long getId() {
95
+        return id;
96
+    }
97
+
98
+    public void setId(Long id) {
99
+        this.id = id;
100
+    }
101
+
102
+    public Integer getVersion() {
103
+        return version;
104
+    }
105
+
106
+    public void setVersion(Integer version) {
107
+        this.version = version;
108
+    }
109
+
110
+    public Long getBranch() {
111
+        return branch;
112
+    }
113
+
114
+    public void setBranch(Long branch) {
115
+        this.branch = branch;
116
+    }
117
+
118
+    public Long getUserId() {
119
+        return userId;
120
+    }
121
+
122
+    public void setUserId(Long userId) {
123
+        this.userId = userId;
124
+    }
125
+
126
+    public String getCallAccept() {
127
+        return callAccept;
128
+    }
129
+
130
+    public void setCallAccept(String callAccept) {
131
+        this.callAccept = callAccept;
132
+    }
133
+
134
+    public String getCallerIdNumber() {
135
+        return callerIdNumber;
136
+    }
137
+
138
+    public void setCallerIdNumber(String callerIdNumber) {
139
+        this.callerIdNumber = callerIdNumber;
140
+    }
141
+
142
+    public String getDestinationNumber() {
143
+        return destinationNumber;
144
+    }
145
+
146
+    public void setDestinationNumber(String destinationNumber) {
147
+        this.destinationNumber = destinationNumber;
148
+    }
149
+
150
+    public Date getCreatedTime() {
151
+        return createdTime;
152
+    }
153
+
154
+    public void setCreatedTime(Date createdTime) {
155
+        this.createdTime = createdTime;
156
+    }
157
+
158
+    public Date getAnsweredTime() {
159
+        return answeredTime;
160
+    }
161
+
162
+    public void setAnsweredTime(Date answeredTime) {
163
+        this.answeredTime = answeredTime;
164
+    }
165
+
166
+    public Date getOverTime() {
167
+        return overTime;
168
+    }
169
+
170
+    public void setOverTime(Date overTime) {
171
+        this.overTime = overTime;
172
+    }
173
+
174
+    public String getGateWay() {
175
+        return gateWay;
176
+    }
177
+
178
+    public void setGateWay(String gateWay) {
179
+        this.gateWay = gateWay;
180
+    }
181
+
182
+    public String getRecordingFileName() {
183
+        return recordingFileName;
184
+    }
185
+
186
+    public void setRecordingFileName(String recordingFileName) {
187
+        this.recordingFileName = recordingFileName;
188
+    }
189
+
190
+    public String getBatchAccept() {
191
+        return batchAccept;
192
+    }
193
+
194
+    public void setBatchAccept(String batchAccept) {
195
+        this.batchAccept = batchAccept;
196
+    }
197
+
198
+    public String getOtherStr() {
199
+        return otherStr;
200
+    }
201
+
202
+    public void setOtherStr(String otherStr) {
203
+        this.otherStr = otherStr;
204
+    }
205
+
206
+    public String getCallType() {
207
+        return callType;
208
+    }
209
+
210
+    public void setCallType(String callType) {
211
+        this.callType = callType;
212
+    }
213
+
214
+    public String getCallTime() {
215
+        return callTime;
216
+    }
217
+
218
+    public void setCallTime(String callTime) {
219
+        this.callTime = callTime;
220
+    }
221
+
222
+    public String getStatus() {
223
+        return status;
224
+    }
225
+
226
+    public void setStatus(String status) {
227
+        this.status = status;
228
+    }
229
+
230
+    public String getHangupSide() {
231
+        return hangupSide;
232
+    }
233
+
234
+    public void setHangupSide(String hangupSide) {
235
+        this.hangupSide = hangupSide;
236
+    }
237
+
238
+    public Integer getIsAnswered() {
239
+        return isAnswered;
240
+    }
241
+
242
+    public void setIsAnswered(Integer isAnswered) {
243
+        this.isAnswered = isAnswered;
244
+    }
245
+}

+ 79 - 10
src/main/java/com/dashitech/callcenter/socket/HandlerThread.java

@@ -1,19 +1,17 @@
1 1
 package com.dashitech.callcenter.socket;
2 2
 
3
-import com.dashitech.businessdata.dao.ICallLogDAO;
4
-import com.dashitech.businessdata.dao.IDepartmentDAO;
5
-import com.dashitech.businessdata.dao.IDictionaryDAO;
6
-import com.dashitech.businessdata.dao.IHospitalConfigDAO;
3
+import com.dashitech.businessdata.dao.*;
7 4
 import com.dashitech.businessdata.entity.CallLogEntity;
8
-import com.dashitech.businessdata.entity.DictionaryEntity;
5
+import com.dashitech.businessdata.entity.CallRecordEntity;
9 6
 import com.dashitech.businessdata.entity.HospitalConfig;
10 7
 import com.dashitech.callcenter.webSocket.service.PhoneWebSocket;
8
+import com.dashitech.utils.DateUtil2;
11 9
 import com.dashitech.utils.JsonUtil;
10
+import com.dashitech.utils.PropertiesUtil;
12 11
 import com.fasterxml.jackson.databind.ObjectMapper;
13 12
 import net.sf.json.JSONObject;
14 13
 import org.apache.commons.lang.StringUtils;
15 14
 import org.springframework.beans.factory.annotation.Autowired;
16
-import org.springframework.context.annotation.Configuration;
17 15
 import org.springframework.stereotype.Service;
18 16
 
19 17
 import java.io.DataInputStream;
@@ -21,10 +19,7 @@ import java.io.DataOutputStream;
21 19
 import java.net.Socket;
22 20
 import java.text.ParseException;
23 21
 import java.text.SimpleDateFormat;
24
-import java.util.Date;
25
-import java.util.HashMap;
26
-import java.util.List;
27
-import java.util.Map;
22
+import java.util.*;
28 23
 
29 24
 /**
30 25
  * Created by chi on 2020/8/6.
@@ -34,6 +29,14 @@ public class HandlerThread  {
34 29
 
35 30
     //  这里使用静态,让 service 属于类
36 31
     private static ICallLogDAO callLogDAO;
32
+
33
+    private static ICallRecordDAO callRecordDAO;
34
+
35
+    @Autowired
36
+    public void setCallRecordDAO(ICallRecordDAO callRecordDAO) {
37
+        HandlerThread.callRecordDAO = callRecordDAO;
38
+    }
39
+
37 40
     @Autowired
38 41
     public void setCallLogDAO(ICallLogDAO callLogDAO) {
39 42
         HandlerThread.callLogDAO = callLogDAO;
@@ -57,6 +60,10 @@ public class HandlerThread  {
57 60
         HandlerThread.hospitalConfigDAO = hospitalConfigDAO;
58 61
     }
59 62
 
63
+    private static String project;
64
+    private static String recordNginxPath;
65
+    private static String recordRegex;
66
+
60 67
     private Socket sc;
61 68
 
62 69
     private static Map<String,String> phoneMap = new HashMap<>();
@@ -95,6 +102,13 @@ public class HandlerThread  {
95 102
                 //将信息流转换为String
96 103
                 String data = new String(b1);
97 104
                 System.out.println("data:"+data+"his"+his);
105
+
106
+                if(project == null) {
107
+                    project = PropertiesUtil.getProperty("project");
108
+                    recordNginxPath = PropertiesUtil.getProperty("db.hjzx.record.nginx");
109
+                    recordRegex = PropertiesUtil.getProperty("db.hjzx.record.path.regex");
110
+                }
111
+
98 112
                 if (data != null || !data.equals("")&&data.substring(0,1).equals("{")) {
99 113
                     if (JsonUtil.toJSONObject(data).containsKey("channelStatusList")){
100 114
                         List llist = JsonUtil.toJSONObject(data).optJSONArray("channelStatusList");
@@ -372,6 +386,8 @@ public class HandlerThread  {
372 386
                 }
373 387
                 callLog.setHosId(Integer.parseInt(his));
374 388
                 callLogDAO.save(callLog);
389
+                //TODO 根据配置文件开关,是否保存到ITSM的通话记录数据
390
+                saveItsmCallRecord(callLog);
375 391
             }
376 392
         }
377 393
     }
@@ -403,6 +419,59 @@ public class HandlerThread  {
403 419
         return "暂无";
404 420
     }
405 421
 
422
+    /**
423
+     * 根据配置文件开关,是否保存到ITSM的通话记录数据
424
+     */
425
+    private void saveItsmCallRecord(CallLogEntity callLog) {
426
+        try {
427
+            if("ITSM".equals(project)) {
428
+                CallRecordEntity recordEntity = new CallRecordEntity();
429
+                String uuid = UUID.randomUUID().toString();
430
+                recordEntity.setCallAccept(uuid);
431
+                recordEntity.setVersion(0);
432
+                recordEntity.setCallerIdNumber(callLog.getdTMFA());
433
+                recordEntity.setDestinationNumber(callLog.getdTMFB());
434
+                recordEntity.setCreatedTime(callLog.getResponseTime());
435
+                recordEntity.setCallTime(callLog.getLongTime());
436
+                recordEntity.setRecordingFileName(callLog.getPath());
437
+                recordEntity.setIsAnswered(callLog.getCallState());
438
+
439
+                //处理结束时间
440
+                if(callLog.getResponseTime() != null && callLog.getLongTime() != null) {
441
+                    Date overTime = DateUtil2.addSeconds(callLog.getResponseTime(), Integer.valueOf(callLog.getLongTime()));
442
+                    recordEntity.setOverTime(overTime);
443
+                }
444
+                //院区
445
+                if(callLog.getHosId() != null) {
446
+                    recordEntity.setBranch(callLog.getHosId().longValue());
447
+                }
448
+                //呼入呼出,其它
449
+                if(callLog.getCallType() != null) {
450
+                    if("1".equals(callLog.getCallType().toString())) {
451
+                        recordEntity.setCallType("2");
452
+                    }else if("2".equals(callLog.getCallType().toString())) {
453
+                        recordEntity.setCallType("1");
454
+                    }else {
455
+                        recordEntity.setCallType("3");
456
+                    }
457
+                }
458
+                //处理录音地址
459
+                if(callLog.getPath() != null) {
460
+                    String newPath = callLog.getPath();
461
+                    String[] arr = callLog.getPath().split(recordRegex);
462
+                    if (arr.length > 1) {
463
+                        newPath = recordNginxPath + arr[1];
464
+                    }
465
+                    recordEntity.setRecordingFileName(newPath);
466
+                }
467
+                callRecordDAO.save(recordEntity);
468
+                System.out.println("ITSM保存通话记录完成:"+recordEntity.getCallAccept());
469
+            }
470
+        } catch (Exception ex) {
471
+            ex.printStackTrace();
472
+        }
473
+    }
474
+
406 475
     public static void main(String[] args) {
407 476
         System.out.println(System.currentTimeMillis() / 1000);
408 477
     }

+ 10 - 6
src/main/resources/application.properties

@@ -1,11 +1,11 @@
1 1
 mysql2.spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
2 2
 #\u8F6C\u8FD0\u4E1A\u52A1\u5E93\u6570\u636E\u6E90
3 3
 mysql2.spring.datasource.driver-class-name=com.mysql.jdbc.Driver
4
-mysql2.spring.datasource.url=jdbc:mysql://localhost:3306/hsms2_1129?autoReconnect=true&useUnicode=true&characterEncoding=utf8
5
-#mysql2.spring.datasource.url=jdbc:mysql://192.168.3.108:3306/hsms2_tjzy_0622?autoReconnect=true&useUnicode=true&characterEncoding=utf8
4
+#mysql2.spring.datasource.url=jdbc:mysql://localhost:3306/hsms2_1129?autoReconnect=true&useUnicode=true&characterEncoding=utf8
5
+mysql2.spring.datasource.url=jdbc:mysql://192.168.3.111:3306/md2?autoReconnect=true&useUnicode=true&characterEncoding=utf8
6 6
 mysql2.spring.datasource.username=root
7
-mysql2.spring.datasource.password=DStech@123
8
-#mysql2.spring.datasource.password=100100
7
+#mysql2.spring.datasource.password=DStech@123
8
+mysql2.spring.datasource.password=100100
9 9
 
10 10
 
11 11
 # \u4E0B\u9762\u4E3A\u8FDE\u63A5\u6C60\u7684\u8865\u5145\u8BBE\u7F6E\uFF0C\u5E94\u7528\u5230\u4E0A\u9762\u6240\u6709\u6570\u636E\u6E90\u4E2D
@@ -25,9 +25,13 @@ mysql2.spring.datasource.testWhileIdle=true
25 25
 mysql2.spring.datasource.testOnBorrow=true
26 26
 mysql2.spring.datasource.testOnReturn=true
27 27
 
28
+#project=HSMS
29
+project=ITSM
30
+db.hjzx.record.nginx=/hjzxRecord
31
+db.hjzx.record.path.regex=voice
28 32
 
29
-spring.redis.host=192.168.245.108
30
-#spring.redis.host=localhost
33
+#spring.redis.host=192.168.245.108
34
+spring.redis.host=localhost
31 35
 spring.redis.port=6379
32 36
 spring.redis.password=Redis@#6379pwD
33 37
 spring.redis.pool.max-total=100