瀏覽代碼

事件剥离逻辑,fix

DavidLiu 4 月之前
父節點
當前提交
4acb2b963d
共有 2 個文件被更改,包括 55 次插入6 次删除
  1. 48 6
      src/core/callcenter/agent.py
  2. 7 0
      src/core/callcenter/api.py

+ 48 - 6
src/core/callcenter/agent.py

@@ -11,7 +11,7 @@ from sqlalchemy import or_
 import src.core.callcenter.esl.utils.esl_event_util as EslEventUtil
 from src.core import with_app_context
 from src.core.callcenter.api import AgentActionRequest, AgentQueryRequest, AgentRequest, AgentEventData, \
-    AgentStateData, HumanServiceQueryRequest, AgentMonitorData, CallInfo, DeviceInfo
+    AgentStateData, HumanServiceQueryRequest, AgentMonitorData, CallInfo, DeviceInfo, AgentDelayStateData
 from src.core.callcenter.cache import Cache
 from src.core.callcenter.dao import *
 from src.core.callcenter.data_handler import DataHandleServer
@@ -34,6 +34,44 @@ class AgentEventService:
         self.agent_state_service = AgentStateService(app)
         self.agent_actionlog_service = AgentActionLogService(app)
 
+    def delay_state(self, state_data: AgentDelayStateData):
+        agent = self.data_handle_server.get_agent(state_data.saas_id, state_data.agent_num)
+        if not agent:
+            return
+        agent_monitor = self.data_handle_server.get_agent_monitor(state_data.saas_id, state_data.agent_num)
+        if not agent_monitor:
+            return
+
+        #TODO 非最新通话的延迟事件,忽略.
+        agent_scene = AgentScene.get_by_code(state_data.scene)
+        self.logger.info("agent event delay state %s %s %s %s", state_data.saas_id, state_data.agent_num, state_data.service_state, agent_monitor.service_state)
+        if AgentServiceState.REPROCESSING.code == state_data.service_state and AgentServiceState.REPROCESSING.code == agent_monitor.service_state:
+            self.reprocessing_idle(state_data)
+
+        if AgentServiceState.DIALING.code == state_data.service_state and AgentServiceState.DIALING.code == agent_monitor.service_state:
+            if self.cache.get_call_is_answer(state_data.saas_id, state_data.agent_num):
+                return
+            self.agent_monitor_service.update_idle(agent_monitor)
+
+            self.push_handler.push_on_call_end(state_data.saas_id, state_data.flow_id, agent_scene, ServiceDirect.MANUAL_CALL.service_direct, '0')
+            self.push_handler.push_on_agent_work_report(state_data.saas_id, state_data.flow_id, state_data.agent_num, '', agent_scene, WorkStatus.AGENT_HANG_REPROCESSING)
+            self.push_handler.push_on_agent_work_report(state_data.saas_id, state_data.flow_id, state_data.agent_num, '', agent_scene, WorkStatus.AGENT_HANG_IDLE)
+
+            self.agent_actionlog_service.insert_service_state(agent_monitor, AgentServiceState.IDLE, AgentLogState.BIZ_DIALING_IDLE)
+
+        if AgentServiceState.HANGING.code == state_data.service_state \
+                and (AgentServiceState.DIALING.code == agent_monitor.service_state
+                     or AgentServiceState.CALLING.code == agent_monitor.service_state):
+            self.agent_monitor_service.update_idle(agent_monitor)
+
+            if AgentServiceState.DIALING.code == agent_monitor.service_state:
+                self.push_handler.push_on_call_end(state_data.saas_id, state_data.flow_id, agent_scene, ServiceDirect.MANUAL_CALL.service_direct, '0')
+                self.push_handler.push_on_agent_work_report(state_data.saas_id, state_data.flow_id, state_data.agent_num, '', agent_scene, WorkStatus.AGENT_HANG_REPROCESSING)
+
+            self.push_handler.push_on_agent_work_report(state_data.saas_id, state_data.flow_id, state_data.agent_num, '', agent_scene, WorkStatus.AGENT_HANG_IDLE)
+            self.agent_actionlog_service.insert_service_state(agent_monitor, AgentServiceState.IDLE, AgentLogState.MANUAL_HANG_UP)
+
+
     def agent_event_channel(self, event, call_info: CallInfo, device_info: DeviceInfo):
         event_name = EslEventUtil.getEventName(event)
         saas_id = call_info.saas_id
@@ -94,7 +132,7 @@ class AgentEventService:
                     self.cache.set_call_is_end(call_id)
 
             self.agent_monitor_service.update_processing(agent_monitor)
-            self.reprocessing_idle(saas_id, flow_id, agent_num, AgentServiceState.REPROCESSING, AgentScene.MANUAL)
+            self.reprocessing_idle(AgentDelayStateData(saas_id, flow_id, agent_num, AgentServiceState.REPROCESSING, AgentScene.MANUAL))
             self.push_handler.push_on_call_end(saas_id, flow_id, AgentScene.MANUAL, ServiceDirect.MANUAL_CALL.service_direct, '0')
             self.push_handler.push_on_agent_work_report(saas_id, flow_id, agent_num, call_id, AgentScene.MANUAL, WorkStatus.AGENT_HANG_REPROCESSING)
             self.push_handler.push_on_agent_report(saas_id, agent_num, AgentScene.MANUAL, AgentServiceState.REPROCESSING)
@@ -166,15 +204,15 @@ class AgentEventService:
                                                   AgentLogState.CHANNEL_HANG_UP, service_id=human_service_id)
 
 
-    def reprocessing_idle(self, saas_id, flow_id, agent_num, service_state:AgentServiceState, scene: AgentScene):
-        agent = self.data_handle_server.get_agent(saas_id, agent_num)
+    def reprocessing_idle(self, state_data: AgentDelayStateData):
+        agent = self.data_handle_server.get_agent(state_data.saas_id, state_data.agent_num)
         if not agent:
             return
-        agent_monitor = self.data_handle_server.get_agent_monitor(saas_id, agent_num)
+        agent_monitor = self.data_handle_server.get_agent_monitor(state_data.saas_id, state_data.agent_num)
         if not agent_monitor:
             return
         self.agent_monitor_service.update_idle(agent_monitor)
-        self.push_handler.push_on_agent_work_report(saas_id, flow_id, agent_num, "", scene, WorkStatus.AGENT_HANG_IDLE)
+        self.push_handler.push_on_agent_work_report(state_data.saas_id, state_data.flow_id, state_data.agent_num, "", state_data.scene, WorkStatus.AGENT_HANG_IDLE)
         self.agent_actionlog_service.insert_service_state(agent_monitor, AgentServiceState.IDLE, AgentLogState.REPROCESSING_IDLE)
 
 
@@ -182,6 +220,7 @@ class AgentOperService:
 
     def __init__(self, app):
         self.app = app
+        self.logger = app.logger
         self.push_handler = PushHandler(app.logger)
         self.data_handle_server = DataHandleServer(app)
         self.agent_monitor_service = AgentMonitorService(app)
@@ -374,6 +413,7 @@ class AgentService:
 
     def __init__(self, app):
         self.app = app
+        self.logger = app.logger
         self.data_handle_server = DataHandleServer(app)
         self.agent_monitor_service = AgentMonitorService(app)
 
@@ -491,6 +531,7 @@ class AgentMonitorService:
 
     def __init__(self, app):
         self.app = app
+        self.logger = app.logger
         self.data_handle_server = DataHandleServer(app)
 
     @with_app_context
@@ -602,6 +643,7 @@ class AgentActionLogService:
 
     def __init__(self, app):
         self.app = app
+        self.logger = app.logger
         self.data_handle_server = DataHandleServer(app)
 
     @with_app_context

+ 7 - 0
src/core/callcenter/api.py

@@ -176,6 +176,13 @@ class AgentStateData(BaseApi):
         self.assign_time = assign_time
         self.phone_num = phone_num
 
+class AgentDelayStateData(BaseApi):
+    def __init__(self, saas_id=None, flow_id=None, agent_num=None, service_state=None, scene=None):
+        self.saas_id = saas_id
+        self.flow_id = flow_id
+        self.agent_num = agent_num
+        self.service_state = service_state
+        self.scene = scene
 
 class HangupCallRequest(BaseApi):
     def __init__(self, saas_id, call_id, agent_number):