余尚辉 4 місяців тому
батько
коміт
a06940727c
2 змінених файлів з 25 додано та 16 видалено
  1. 12 1
      src/core/callcenter/data_handler.py
  2. 13 15
      src/core/callcenter/esl/client.py

+ 12 - 1
src/core/callcenter/data_handler.py

@@ -55,4 +55,15 @@ class DataHandleServer:
     def update_agent_monitor_service_state(self, agent_num,service_state):
         agent_monitor = AgentMonitor.query.filter(agent_num == agent_num).first()
         agent_monitor.service_state = service_state
-        db.session.commit()
+        db.session.commit()
+
+    @with_app_context
+    def update_whitelist(self):      # 获取所有白名单
+        phones = Whitelist.query.filter_by(del_flag=0).all()
+        return [phone.phone for phone in phones]
+
+    @with_app_context
+    def load_agent_monitor(self):      # 获取所有空闲的坐席
+        agents = AgentMonitor.query.filter_by(check_state=0, service_state=2).all()
+        agent_nums = [agent.agent_num for agent in agents]
+        return agent_nums

+ 13 - 15
src/core/callcenter/esl/client.py

@@ -471,38 +471,36 @@ class OutboundClient:
     def __init__(self, agent, app):
         self.app = app
         self.logger = app.logger
-        self.whitelist = []
-        self.update_whitelist()  # 初始化加载白名单
+        self.dataHandleServer = DataHandleServer(app)
+        self.whitelist = self.dataHandleServer.update_whitelist()  # 初始化加载白名单
 
         # 定时更新白名单
         threading.Thread(target=self.refresh_whitelist, daemon=True).start()
 
-
-        self.dataHandleServer = DataHandleServer(app)
         #threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent, logger)).start()
         server_thread = threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent))
         server_thread.daemon = True  # 设置守护线程
         server_thread.start()
 
-    def update_whitelist(self):
-        with self.app.app_context():
-            phones = Whitelist.query.filter_by(del_flag=0).all()
-            self.whitelist = [phone.phone for phone in phones]
-            self.logger.info("Whitelist updated: %s", self.whitelist)
+    # def update_whitelist(self):
+    #     with self.app.app_context():
+    #         phones = Whitelist.query.filter_by(del_flag=0).all()
+    #         self.whitelist = [phone.phone for phone in phones]
+    #         self.logger.info("Whitelist updated: %s", self.whitelist)
 
     def refresh_whitelist(self):
         while True:
             time.sleep(3600) # 每 1小时 更新一次
-            self.update_whitelist()
+            self.dataHandleServer.update_whitelist()
 
     def load_whitelist(self):
         return self.whitelist
 
-    def load_agent_monitor(self):
-        with self.app.app_context():
-            agents = AgentMonitor.query.filter_by(check_state=0,service_state=2).all()
-            agent_nums = [agent.agent_num for agent in agents]
-            return agent_nums
+    # def load_agent_monitor(self):
+    #     with self.app.app_context():
+    #         agents = AgentMonitor.query.filter_by(check_state=0,service_state=2).all()
+    #         agent_nums = [agent.agent_num for agent in agents]
+    #         return agent_nums
 
 
     class ESLRequestHandler(socketserver.BaseRequestHandler):