774056846 4 months ago
parent
commit
e39de4102a
2 changed files with 8 additions and 7 deletions
  1. 4 7
      src/core/callcenter/cache.py
  2. 4 0
      src/core/callcenter/data_handler.py

+ 4 - 7
src/core/callcenter/cache.py

@@ -9,6 +9,7 @@ from datetime import datetime
 from src.core.callcenter.constant import *
 from src.core.callcenter.api import AgentInfo, CallInfo, RouteGateway
 from src.core.callcenter.dao import Agent, Phone
+from src.core.callcenter.data_handler import DataHandleServer
 from src.core.datasource import RedisHandler
 
 
@@ -18,14 +19,14 @@ class Cache:
         self.deviceCall = {}
         self.deviceUserPart = {}
         self.redis_handler = RedisHandler()
+        self.dataHandleServer = DataHandleServer(app)
 
     def get_agent_info(self, saas_id, agent_number):
         text = self.redis_handler.get(AGENT_INFO + saas_id + ":" + agent_number)
-        print('get_agent_info', saas_id, agent_number, text)
-        sys.stdout.flush()  # 强制刷新输出缓冲区
+        print('get_agent_info', saas_id, agent_number, text, flush=True)
         if text:
             return AgentInfo.from_json(text)
-        phone = self.get_agent_phone(saas_id, agent_number)
+        phone = self.dataHandleServer.get_agent_phone(saas_id, agent_number)
         agent_info = AgentInfo(saas_id=saas_id, sip_server=phone.sip_server, agent_number=agent_number)
         print('get_agent_info', saas_id, agent_number, agent_info, flush=True)
         self.add_agent_info(agent=agent_info)
@@ -119,10 +120,6 @@ class Cache:
                             called_prefix='',
                             status=0)
 
-
-    def get_agent_phone(self, saas_id, agent_num):
-        return Phone.query.filter(Phone.saas_id == saas_id, Phone.phone_num == agent_num).first()
-
     def add_delay_message(self, action, delay_action, timeouts):
         delay_action.uuid = uuid.uuid4()
         key = CTI_ENGINE_DELAY_ACTION % action

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

@@ -47,6 +47,10 @@ class DataHandleServer:
         agent = Agent.query.filter(agent_num == agent_num).first()
         return agent
 
+    @with_app_context
+    def get_agent_phone(self, saas_id, agent_num):
+        return Phone.query.filter(Phone.saas_id == saas_id, Phone.phone_num == agent_num).first()
+
     @with_app_context
     def update_agent_monitor_service_state(self, agent_num,service_state):
         agent_monitor = AgentMonitor.query.filter(agent_num == agent_num).first()