|
@@ -11,6 +11,8 @@ import com.dashitech.utils.PropertiesUtil;
|
11
|
11
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
12
|
12
|
import net.sf.json.JSONObject;
|
13
|
13
|
import org.apache.commons.lang.StringUtils;
|
|
14
|
+import org.apache.commons.logging.Log;
|
|
15
|
+import org.apache.commons.logging.LogFactory;
|
14
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
17
|
import org.springframework.stereotype.Service;
|
16
|
18
|
|
|
@@ -27,6 +29,8 @@ import java.util.*;
|
27
|
29
|
@Service
|
28
|
30
|
public class HandlerThread {
|
29
|
31
|
|
|
32
|
+ private static Log log = LogFactory.getLog(HandlerThread.class);
|
|
33
|
+
|
30
|
34
|
// 这里使用静态,让 service 属于类
|
31
|
35
|
private static ICallLogDAO callLogDAO;
|
32
|
36
|
|
|
@@ -78,7 +82,6 @@ public class HandlerThread {
|
78
|
82
|
}
|
79
|
83
|
|
80
|
84
|
public void run() {
|
81
|
|
- // TODO Auto-generated method stub
|
82
|
85
|
DataInputStream input = null;
|
83
|
86
|
DataOutputStream output = null;
|
84
|
87
|
try {
|
|
@@ -247,8 +250,19 @@ public class HandlerThread {
|
247
|
250
|
//TODO 增加返回 uuid 并且保存通话记录数据
|
248
|
251
|
if (jsonObject.containsKey("dtmfa") && jsonObject.get("dtmfa").toString() != null && !jsonObject.optString("dtmfa").toString().equals("")){
|
249
|
252
|
rMap.put("phone", jsonObject.opt("dtmfa"));
|
250
|
|
- // rMap.put("callid",);
|
251
|
253
|
rMap.put("status", 201);
|
|
254
|
+
|
|
255
|
+ //TODO 先保存通话记录
|
|
256
|
+ CallLogEntity callLogEntity = new CallLogEntity();
|
|
257
|
+ callLogEntity.setdTMFA(jsonObject.optString("dtmfa"));
|
|
258
|
+ callLogEntity.setdTMFB(jsonObject.optString("dtmfb"));
|
|
259
|
+ if(StringUtils.isNotEmpty(jsonObject.optString("rstime"))) {
|
|
260
|
+ callLogEntity.setResponseTime(DateUtil2.parseDateTime(jsonObject.optString("rstime")));
|
|
261
|
+ }
|
|
262
|
+
|
|
263
|
+ saveItsmCallRecord(callLogEntity,jsonObject.optString("uuid"));
|
|
264
|
+ rMap.put("callId",jsonObject.optString("uuid"));
|
|
265
|
+
|
252
|
266
|
}else {
|
253
|
267
|
rMap.put("phone","");
|
254
|
268
|
rMap.put("status", 201);
|
|
@@ -390,7 +404,7 @@ public class HandlerThread {
|
390
|
404
|
callLog.setHosId(Integer.parseInt(his));
|
391
|
405
|
callLogDAO.save(callLog);
|
392
|
406
|
//TODO 根据配置文件开关,是否保存到ITSM的通话记录数据
|
393
|
|
- saveItsmCallRecord(callLog);
|
|
407
|
+ saveItsmCallRecord(callLog,null);
|
394
|
408
|
}
|
395
|
409
|
}
|
396
|
410
|
}
|
|
@@ -425,49 +439,84 @@ public class HandlerThread {
|
425
|
439
|
/**
|
426
|
440
|
* 根据配置文件开关,是否保存到ITSM的通话记录数据
|
427
|
441
|
*/
|
428
|
|
- private void saveItsmCallRecord(CallLogEntity callLog) {
|
|
442
|
+ private void saveItsmCallRecord(CallLogEntity callLog,String uuid) {
|
429
|
443
|
try {
|
430
|
444
|
if("ITSM".equals(project)) {
|
431
|
|
- CallRecordEntity recordEntity = new CallRecordEntity();
|
432
|
|
- String uuid = UUID.randomUUID().toString();
|
433
|
|
- recordEntity.setCallAccept(uuid);
|
434
|
|
- recordEntity.setVersion(0);
|
435
|
|
- recordEntity.setCallerIdNumber(callLog.getdTMFA());
|
436
|
|
- recordEntity.setDestinationNumber(callLog.getdTMFB());
|
437
|
|
- recordEntity.setCreatedTime(callLog.getResponseTime());
|
438
|
|
- recordEntity.setCallTime(callLog.getLongTime());
|
439
|
|
- recordEntity.setRecordingFileName(callLog.getPath());
|
440
|
|
- recordEntity.setIsAnswered(callLog.getCallState());
|
441
|
|
-
|
442
|
|
- //处理结束时间
|
443
|
|
- if(callLog.getResponseTime() != null && callLog.getLongTime() != null) {
|
444
|
|
- Date overTime = DateUtil2.addSeconds(callLog.getResponseTime(), Integer.valueOf(callLog.getLongTime()));
|
445
|
|
- recordEntity.setOverTime(overTime);
|
446
|
|
- }
|
447
|
|
- //院区
|
448
|
|
- if(callLog.getHosId() != null) {
|
449
|
|
- recordEntity.setBranch(callLog.getHosId().longValue());
|
450
|
|
- }
|
451
|
|
- //呼入呼出,其它
|
452
|
|
- if(callLog.getCallType() != null) {
|
453
|
|
- if("1".equals(callLog.getCallType().toString())) {
|
454
|
|
- recordEntity.setCallType("2");
|
455
|
|
- }else if("2".equals(callLog.getCallType().toString())) {
|
456
|
|
- recordEntity.setCallType("1");
|
|
445
|
+ CallRecordEntity recordEntity = null;
|
|
446
|
+ log.info("开始保存通话记录");
|
|
447
|
+ //TODO 根据uuid区分是:新增通话记录,还是修改附件的通话记录
|
|
448
|
+ if(StringUtils.isNotEmpty(uuid)) { //新增
|
|
449
|
+ Long id = callRecordDAO.selectIdByUuid(uuid);
|
|
450
|
+ if(id == null) {
|
|
451
|
+ recordEntity = new CallRecordEntity();
|
|
452
|
+ recordEntity.setVersion(0);
|
|
453
|
+ recordEntity.setCallAccept(uuid);
|
|
454
|
+ recordEntity.setCallerIdNumber(callLog.getdTMFA());
|
|
455
|
+ recordEntity.setDestinationNumber(callLog.getdTMFB());
|
|
456
|
+ recordEntity.setCreatedTime(callLog.getResponseTime());
|
|
457
|
+ callRecordDAO.save(recordEntity);
|
|
458
|
+ log.info("新增临时通话记录完成");
|
457
|
459
|
}else {
|
458
|
|
- recordEntity.setCallType("3");
|
|
460
|
+ log.info("已有临时通话记录,忽略此条uuid:"+uuid);
|
459
|
461
|
}
|
460
|
|
- }
|
461
|
|
- //处理录音地址
|
462
|
|
- if(callLog.getPath() != null) {
|
463
|
|
- String newPath = callLog.getPath();
|
464
|
|
- String[] arr = callLog.getPath().split(recordRegex);
|
465
|
|
- if (arr.length > 1) {
|
466
|
|
- newPath = recordNginxPath + arr[1];
|
|
462
|
+ }else { //修改
|
|
463
|
+ log.info("开始匹配临时通话记录");
|
|
464
|
+ recordEntity = callRecordDAO.selectByParams(callLog.getdTMFA(), callLog.getdTMFB(), callLog.getResponseTime());
|
|
465
|
+
|
|
466
|
+ //TODO 根据【主叫、被叫、起始时间】判断是否查询到对应数据,来绑定附件,如果未匹配到,直接新增
|
|
467
|
+ String newUUID = null;
|
|
468
|
+ if(recordEntity != null) {
|
|
469
|
+ log.info("匹配到临时通话记录!开始修改");
|
|
470
|
+ newUUID = recordEntity.getCallAccept();
|
|
471
|
+ }else {
|
|
472
|
+ log.info("未匹配到临时通话记录!开始新增");
|
|
473
|
+ recordEntity = new CallRecordEntity();
|
|
474
|
+ newUUID = UUID.randomUUID().toString();
|
467
|
475
|
}
|
468
|
|
- recordEntity.setRecordingFileName(newPath);
|
|
476
|
+
|
|
477
|
+ recordEntity.setCallAccept(newUUID);
|
|
478
|
+ recordEntity.setVersion(0);
|
|
479
|
+ recordEntity.setCallerIdNumber(callLog.getdTMFA());
|
|
480
|
+ recordEntity.setDestinationNumber(callLog.getdTMFB());
|
|
481
|
+ recordEntity.setCreatedTime(callLog.getResponseTime());
|
|
482
|
+ recordEntity.setCallTime(callLog.getLongTime());
|
|
483
|
+ recordEntity.setRecordingFileName(callLog.getPath());
|
|
484
|
+ recordEntity.setIsAnswered(callLog.getCallState());
|
|
485
|
+
|
|
486
|
+ //处理结束时间
|
|
487
|
+ if(callLog.getResponseTime() != null && callLog.getLongTime() != null) {
|
|
488
|
+ Date overTime = DateUtil2.addSeconds(callLog.getResponseTime(), Integer.valueOf(callLog.getLongTime()));
|
|
489
|
+ recordEntity.setOverTime(overTime);
|
|
490
|
+ }
|
|
491
|
+ //院区
|
|
492
|
+ if(callLog.getHosId() != null) {
|
|
493
|
+ recordEntity.setBranch(callLog.getHosId().longValue());
|
|
494
|
+ }
|
|
495
|
+ //呼入呼出,其它
|
|
496
|
+ if(callLog.getCallType() != null) {
|
|
497
|
+ if("1".equals(callLog.getCallType().toString())) {
|
|
498
|
+ recordEntity.setCallType("2");
|
|
499
|
+ }else if("2".equals(callLog.getCallType().toString())) {
|
|
500
|
+ recordEntity.setCallType("1");
|
|
501
|
+ }else {
|
|
502
|
+ recordEntity.setCallType("3");
|
|
503
|
+ }
|
|
504
|
+ }
|
|
505
|
+ //处理录音地址
|
|
506
|
+ if(callLog.getPath() != null) {
|
|
507
|
+ String newPath = callLog.getPath();
|
|
508
|
+ String[] arr = callLog.getPath().split(recordRegex);
|
|
509
|
+ if (arr.length > 1) {
|
|
510
|
+ newPath = recordNginxPath + arr[1];
|
|
511
|
+ }
|
|
512
|
+ recordEntity.setRecordingFileName(newPath);
|
|
513
|
+ }
|
|
514
|
+
|
|
515
|
+ callRecordDAO.save(recordEntity);
|
|
516
|
+ log.info("附件通话记录保存完成");
|
469
|
517
|
}
|
470
|
|
- callRecordDAO.save(recordEntity);
|
|
518
|
+
|
|
519
|
+ log.info("ITSM保存通话记录完成:"+recordEntity.getCallAccept());
|
471
|
520
|
System.out.println("ITSM保存通话记录完成:"+recordEntity.getCallAccept());
|
472
|
521
|
}
|
473
|
522
|
} catch (Exception ex) {
|