Переглянути джерело

Merge branch 'develop' of ssh://gitlab.fuxicarbon.com:1111/client_service/voice-gateway-service into develop

余尚辉 4 місяців тому
батько
коміт
ddbd1195ed

+ 2 - 2
src/core/callcenter/api.py

@@ -416,8 +416,8 @@ class AgentInfo:
         """
         try:
             if self.sip_server:
-                parsed_uri = urlparse(self.sip_server)
-                return parsed_uri.hostname if parsed_uri.hostname else self.realm
+                sip_uri = SipURI(self.sip_server)
+                return sip_uri.get_host() if sip_uri.get_host() else self.realm
         except Exception as ex:
             print(f"Error parsing SIP server URI: {ex}")
         return self.realm

+ 13 - 5
src/core/callcenter/cache.py

@@ -5,6 +5,7 @@ import json
 
 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.datasource import RedisHandler
 
 cacheDay = 7
@@ -14,10 +15,13 @@ redis_handler = RedisHandler()
 print(redis_handler.redis.info())
 
 
-def get_agent_info(agent_number):
-    text = redis_handler.get(AGENT_INFO + agent_number)
+def get_agent_info(saas_id, agent_number):
+    text = redis_handler.get(AGENT_INFO + saas_id + ":" + agent_number)
     if not text:
-        return None
+        phone = get_agent_phone(saas_id, agent_number)
+        agent_info = AgentInfo(saas_id=saas_id, sip_server=phone.sip_server, agent_number=agent_number)
+        add_agent_info(agent=agent_info)
+        return agent_info
     return AgentInfo.from_json(text)
 
 
@@ -36,14 +40,14 @@ def get_agent_number(token):
 # 缓存坐席
 def add_agent_info(call_info: CallInfo = None, agent: AgentInfo = None, call_id=None, device_id=None):
     if call_info and not agent:
-        agent = get_agent_info(call_info.agent_key)
+        agent = get_agent_info(call_info.saas_id, call_info.agent_key)
     if not agent:
         return
     if call_id:
         agent.call_id = call_id
     if device_id:
         agent.device_id = device_id
-    redis_handler.set(AGENT_INFO + agent.agent_number, json.dumps(agent), cacheDay * 24 * 60 * 60)
+    redis_handler.set(AGENT_INFO + agent.saas_id + agent.agent_number, agent.to_json_string(), cacheDay * 24 * 60 * 60)
 
 
 # 缓存CALL_INFO
@@ -103,3 +107,7 @@ def get_route_gateway(saas_id):
                         caller_prefix='',
                         called_prefix='',
                         status=0)
+
+
+def get_agent_phone(saas_id, agent_num):
+    return Phone.query.filter(Phone.saas_id == saas_id, Phone.phone_num == agent_num).first()

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

@@ -6,7 +6,7 @@ import time
 import src.core.callcenter.cache as Cache
 from src.core.callcenter.constant import saasId, HOLD_MUSIC_PATH
 from src.core.callcenter.enumeration import CallCause, Direction, NextType, DeviceType, CdrType
-from src.core.callcenter.api import AgentCallRequest, AgentInfo, CallInfo, HangupCallRequest, CheckInCallRequest, \
+from src.core.callcenter.api import AgentCallRequest, CallInfo, HangupCallRequest, CheckInCallRequest, \
     DeviceInfo, NextCommand, MakeCallContext
 from src.core.callcenter.esl.constant.sip_header_constant import sipHeaderServiceId
 from src.core.callcenter.snowflake import Snowflake
@@ -24,7 +24,8 @@ class CallService:
         device_id = 'D' + self.snowflake.next_id()
         now = lambda: int(round(time.time() * 1000))
 
-        agent = Cache.get_agent_info(request.agent_id)
+        agent = Cache.get_agent_info(request.saas_id, request.agent_id)
+        route_gateway = Cache.get_route_gateway(request.saas_id)
         call_info = CallInfo(call_id=call_id, agent_key=agent.agent_number, cti_host=agent.sip_server,
                              caller=agent.agent_number, called=request.called, direction=Direction.INBOUND,
                              caller_display=request.caller_display, called_display=request.called_display,
@@ -56,7 +57,7 @@ class CallService:
     def transfer(self, call_info: CallInfo, agent_number, service_id):
         caller = call_info.called
         call_id = call_info.call_id
-        agent = Cache.get_agent_info(call_info.agent_key)
+        agent = Cache.get_agent_info(call_info.saas_id, call_info.agent_key)
         device_id = 'D' + self.snowflake.next_id()
         now = lambda: int(round(time.time() * 1000))
 
@@ -110,5 +111,5 @@ class CallService:
             self.client.hangup_call(call_info.call_id, device, CallCause.RESTART)
 
     def checkin_call(self, request: CheckInCallRequest):
-        agent = Cache.get_agent_info(request.agent_number)
+        agent = Cache.get_agent_info(request.saas_id, request.agent_number)
         return self.client.show_channel(agent.device_id)

+ 1 - 2
src/core/callcenter/constant.py

@@ -2,7 +2,6 @@
 # encoding:utf-8
 
 import json
-from src.core.callcenter.api import CallInfo
 
 saasId = "mdj"
 
@@ -95,5 +94,5 @@ def format_time_millis(time_millis, pattern='%Y%m%d'):
     return dt.strftime(pattern)
 
 
-def get_record_prefix(call: CallInfo):
+def get_record_prefix(call):
     return BASE_RECORD_PATH + call.call_type + '/' + call.saas_id + '/' + call.caller + '/' + format_time_millis(call.call_time)

+ 4 - 3
src/core/callcenter/views.py

@@ -143,7 +143,8 @@ def manual_call():
     # ext?: object
     # callId: string
     data = request.json()
-    req = AgentCallRequest(saas_id=data.get('saas_id'), call_type=CallType.OUTBOUND_CALL, called=data.get('called'), follow_data=data.get('ext'))
+    req = AgentCallRequest(saas_id=data.get('saas_id'), call_type=CallType.OUTBOUND_CALL, caller=data.get('caller'),
+                           agent_id=data.get('caller'), called=data.get('called'), follow_data=data.get('ext'))
     res = call_service.call(req)
     return success_response(res)
 
@@ -152,8 +153,8 @@ def manual_call():
 def manual_hang():
     """挂断"""
     data = request.json()
-    agent = Cache.get_agent_info(data.get('agentId'))
-    req = HangupCallRequest(saas_id=data.get('vccId'), call_id=data.get('callId'), agent_number=agent.agent_number)
+    agent = Cache.get_agent_info(data.get('saasId'), data.get('agentId'))
+    req = HangupCallRequest(saas_id=data.get('saasId'), call_id=data.get('callId'), agent_number=agent.agent_number)
     call_service.hangup(req)
     return success_response()