shanghui 2 months ago
parent
commit
07982f2de2

+ 0 - 2
src/core/callcenter/agent.py

@@ -104,8 +104,6 @@ class AgentEventService:
             # 信道发起事件,触发完成发起(或桥)&& 坐席侧
             if CHANNEL_ORIGINATE == event_name and is_agent:
                 self.push_handler.push_on_agent_work_report(saas_id, flow_id, agent_num, call_id, AgentScene.MANUAL, WorkStatus.AGENT_RINGING,phone=call_info.caller)
-                self.logger.info('信道发起事件:%s', agent)
-                self.data_handle_server.update_record(call_id, user_id=agent.user_id, user_name=agent.agent_name)
 
             # 进度事件,外呼时对方提醒。或者入呼时提醒 && 坐席侧
             if CHANNEL_PROGRESS == event_name and is_agent:

+ 4 - 5
src/core/callcenter/data_handler.py

@@ -50,11 +50,10 @@ class DataHandleServer:
             call_record.bussiness_type = bot_record.intent if bot_record else ''
         # 如果记录是转人工并且有客服接通把客服更新到转接字段
         self.app.logger.debug(f"Received kwargs: {kwargs} user_id:{user_id},user_name:{user_name}, call_record:{call_record}")
-        # if call_record.service_category==2 and user_id:
-        #    call_record.transfer_user_id = user_id
-        #    call_record.transfer_user_name =user_name
-        #    kwargs.pop('user_id', None)
-        #    kwargs.pop('user_name', None)
+        #如果记录已经有user_id不再更新 删除参数里面的user_id
+        if call_record.user_id and user_id:
+           kwargs.pop('user_id', None)
+           kwargs.pop('user_name', None)
         # 动态更新字段
         for key, value in kwargs.items():
             if hasattr(call_record, key):

+ 16 - 6
src/core/callcenter/esl/handler/channel_hangup_handler.py

@@ -152,20 +152,30 @@ class ChannelHangupHandler(EslEventHandler):
         records = []
         sip_status = []
         hangup_cause = []
+        agent_name = ''
         for value in call_info.device_info_map.values():
             records.append(value.record) if value.record else None
             sip_status.append(value.sip_status)
             hangup_cause.append(value.hangup_cause)
-        self.logger.info("get_call_info_record: %s", records)
-        threading.Thread(target=self._update_record_in_thread, args=(call_info.call_id, list(set(records)), ",".join(sip_status), ",".join(hangup_cause),call_info.answer_count)).start()
+            if value.device_type == DeviceType.AGENT.code :
+                agent_name = value.agent_key
+        self.logger.info("get_call_info_record: %s,agent_name:%s", records, agent_name)
+        threading.Thread(target=self._update_record_in_thread, args=(call_info.call_id, list(set(records)), ",".join(sip_status), ",".join(hangup_cause), agent_name)).start()
 
-    def _update_record_in_thread(self, call_id, records, sip_status, hangup_cause, answer_count):
+    def update_name(self,call_id, agent_name):
+        try:
+            agent = self.dataHandleServer.get_user_name(agent_name)
+            return agent
+        except Exception as e:
+            self.logger.error("update_name error: %s", str(e))
+    def _update_record_in_thread(self, call_id, records, sip_status, hangup_cause, agent_name):
         """用于在独立线程中执行 update_record"""
         try:
+            agent = self.update_name(call_id, agent_name)
             # status = 0 if answer_count <= 0 else 1
             if len(records) == 0:
-                self.logger.warning("没有录音文件,直接更新记录: call_id=%s, sip_status=%s, hangup_cause=%s", call_id, sip_status, hangup_cause)
-                self.dataHandleServer.update_record(call_id, time_end=datetime.now(), sip_status=sip_status, sip_hangup_cause=hangup_cause)
+                self.logger.warning("没有录音文件,直接更新记录: call_id=%s, sip_status=%s, hangup_cause=%s, agent_name=%s", call_id, sip_status, hangup_cause,agent_name)
+                self.dataHandleServer.update_record(call_id, time_end=datetime.now(), sip_status=sip_status, sip_hangup_cause=hangup_cause,user_id=agent.user_id, user_name=agent.agent_name)
                 return
             merge_record = self.merge_audio_files(records) if len(records) > 1 else records[0]
             # try:
@@ -175,7 +185,7 @@ class ChannelHangupHandler(EslEventHandler):
             # except Exception as chmod_error:
             #     self.logger.error("设置文件权限失败: %s, error: %s", merge_record, str(chmod_error))
 
-            self.dataHandleServer.update_record(call_id, time_end=datetime.now(), url=merge_record, sip_status=sip_status, sip_hangup_cause=hangup_cause)
+            self.dataHandleServer.update_record(call_id, time_end=datetime.now(), url=merge_record, sip_status=sip_status, sip_hangup_cause=hangup_cause,user_id=agent.user_id, user_name=agent.agent_name)
             self.logger.info("更新录音记录完成: call_id=%s", call_id)
         except Exception as e:
             self.logger.error("更新录音记录失败: call_id=%s, error=%s", call_id, str(e))