774056846 4 months ago
parent
commit
990cec71c3
1 changed files with 74 additions and 70 deletions
  1. 74 70
      src/core/callcenter/esl/handler/channel_hangup_handler.py

+ 74 - 70
src/core/callcenter/esl/handler/channel_hangup_handler.py

@@ -3,6 +3,7 @@
 
 import json
 import sys
+import traceback
 
 import src.core.callcenter.cache as Cache
 from src.core.callcenter.acd import AcdService
@@ -26,79 +27,82 @@ class ChannelHangupHandler(EslEventHandler):
 
     def handle(self, address, event, coreUUID):
         print(json.loads(event.serialize('json')))
-        call_id = EslEventUtil.getCallId(event)
-        if not call_id:
-            self.release(event)
-            self.logger.info("call_id is null")
-            return
-        call = Cache.get_call_info(call_id)
-        if not call:
-            self.logger.info("call:%s is null", call_id)
-            return
-        device_id = EslEventUtil.getDeviceId(event)
-        device = call.device_info_map.get(device_id)
-        if not device:
-            self.logger.info("device:%s is null", device_id)
-            return
-
-        count = len(call.device_list)
-        print('ChannelHangupHandler, call_id=%s, device_id=%s, count=%s', call_id, device_id, count)
         try:
-            call.device_list.remove(device_id)
-        except:
-            pass
-        cause = EslEventUtil.getCallHangupCause(event)
-        caller = EslEventUtil.getCallerCallerIdNumber(event)
-        called = EslEventUtil.getCallerDestinationNumber(event)
-        sip_status = EslEventUtil.getSipStatus(event)
-        sip_protocol = EslEventUtil.getSipProtocol(event)
-        rtp_use_codec = EslEventUtil.getRtpUseCodec(event)
-        channel_name = EslEventUtil.getCallerChannelName(event)
-        timestamp = EslEventUtil.getEventDateTimestamp(event)
-        hangup_cause = EslEventUtil.getVariableSipHPLIBRAHangupCause(event)
-        hangup_reason = EslEventUtil.getLIBRAHangupReason(event)
-
-        device.hangup_cause = cause
-        device.sip_protocol = sip_protocol
-        device.sip_status = sip_status
-        device.channel_name = channel_name
-        device.end_time = timestamp
-
-        # 计算通话时长
-        if device.answer_time:
-            device.talk_time = int(device.end_time) - int(device.answer_time)
-        else:
-            device.ring_start_time = device.end_time
-        # 计算录音时长
-        if device.record_start_time:
-            device.record_time = int(device.end_time) - int(device.record_start_time)
-        call.device_info_map[device.device_id] = device
-
-        # 如果是转人工
-        if 'transferToAgent' == hangup_reason and DeviceType.ROBOT.code == device.device_type:
-            call.answer_flag = AnswerFlag.TRANSFER_TO_AGENT.code
-            service_id = EslEventUtil.getLIBRAServiceId(event)
+            call_id = EslEventUtil.getCallId(event)
+            if not call_id:
+                self.release(event)
+                print("call_id is null")
+                return
+            call = Cache.get_call_info(call_id)
+            if not call:
+                print("call:%s is null", call_id)
+                return
+            device_id = EslEventUtil.getDeviceId(event)
+            device = call.device_info_map.get(device_id)
+            if not device:
+                print("device:%s is null", device_id)
+                return
+
+            count = len(call.device_list)
+            print('ChannelHangupHandler, call_id=%s, device_id=%s, count=%s'% (call_id, device_id, count))
+            try:
+                call.device_list.remove(device_id)
+            except:
+                pass
+            cause = EslEventUtil.getCallHangupCause(event)
+            caller = EslEventUtil.getCallerCallerIdNumber(event)
+            called = EslEventUtil.getCallerDestinationNumber(event)
+            sip_status = EslEventUtil.getSipStatus(event)
+            sip_protocol = EslEventUtil.getSipProtocol(event)
+            rtp_use_codec = EslEventUtil.getRtpUseCodec(event)
+            channel_name = EslEventUtil.getCallerChannelName(event)
+            timestamp = EslEventUtil.getEventDateTimestamp(event)
+            hangup_cause = EslEventUtil.getVariableSipHPLIBRAHangupCause(event)
+            hangup_reason = EslEventUtil.getLIBRAHangupReason(event)
+
+            device.hangup_cause = cause
+            device.sip_protocol = sip_protocol
+            device.sip_status = sip_status
+            device.channel_name = channel_name
+            device.end_time = timestamp
+
+            # 计算通话时长
+            if device.answer_time:
+                device.talk_time = int(device.end_time) - int(device.answer_time)
+            else:
+                device.ring_start_time = device.end_time
+            # 计算录音时长
+            if device.record_start_time:
+                device.record_time = int(device.end_time) - int(device.record_start_time)
+            call.device_info_map[device.device_id] = device
+
+            # 如果是转人工
+            if 'transferToAgent' == hangup_reason and DeviceType.ROBOT.code == device.device_type:
+                call.answer_flag = AnswerFlag.TRANSFER_TO_AGENT.code
+                service_id = EslEventUtil.getLIBRAServiceId(event)
+                Cache.add_call_info(call)
+                self.acd_service.transfer_to_agent(call, device, service_id)
+                sys.stdout.flush()  # 强制刷新输出缓冲区
+                return
+
+            # 如果有下一步
+            next_command = call.next_commands[0] if len(call.next_commands) > 0 else None
+            if next_command:
+                self.next_cmd(call, device, next_command, cause)
+                sys.stdout.flush()  # 强制刷新输出缓冲区
+                return
+
+            # 一般情况下,挂断其他所有设备
+            if device.cdr_type <= 4 and not call.end_time:
+                call.end_time = device.end_time
+                self.call_service.hangup_all(call, CallCause.HANGUP_EVENT)
+
+            # 判断挂机方向 && 更新缓存
+            self.hangup_dir(call, device, cause)
             Cache.add_call_info(call)
-            self.acd_service.transfer_to_agent(call, device, service_id)
-            sys.stdout.flush()  # 强制刷新输出缓冲区
-            return
-
-        # 如果有下一步
-        next_command = call.next_commands[0] if len(call.next_commands) > 0 else None
-        if next_command:
-            self.next_cmd(call, device, next_command, cause)
             sys.stdout.flush()  # 强制刷新输出缓冲区
-            return
-
-        # 一般情况下,挂断其他所有设备
-        if device.cdr_type <= 4 and not call.end_time:
-            call.end_time = device.end_time
-            self.call_service.hangup_all(call, CallCause.HANGUP_EVENT)
-
-        # 判断挂机方向 && 更新缓存
-        self.hangup_dir(call, device, cause)
-        Cache.add_call_info(call)
-        sys.stdout.flush()  # 强制刷新输出缓冲区
+        except:
+            traceback.print_exc()
 
     def release(self, event):
         device_id = event.getHeader("Unique-ID")