Class WorkgroupRoutingService
java.lang.Object
com.bytedesk.service.workgroup_routing.WorkgroupRoutingService
工作组路由服务
根据工作组路由模式选择客服
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BytedeskEventPublisherprivate final PresenceFacadeServiceprivate final QueueRestServiceprivate final ThreadRestServiceprivate final UidUtilsprivate final WorkgroupRepositoryprivate final WorkgroupRoutingRepository -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadvanceAfterAssignment(String workgroupUid, String assignedAgentUid) 异步预计算:在一次分配后推进 cursor 并刷新 nextAgent。private voidadvanceStateAfterAssignment(String routingMode, WorkgroupEntity workgroup, ThreadEntity thread, List<AgentEntity> availableAgents, WorkgroupRoutingEntity state, AgentEntity assignedAgent) intcalculatePriority(ThreadEntity thread) 计算会话优先级private doublecalculateWeight(AgentEntity agent) 计算客服权重private AgentEntitycomputeNextAgentForDisplay(String routingMode, WorkgroupEntity workgroup, ThreadEntity thread, List<AgentEntity> availableAgents, WorkgroupRoutingEntity state) private AgentEntitycomputeNextAgentForState(String routingMode, WorkgroupEntity workgroup, ThreadEntity thread, List<AgentEntity> availableAgents, WorkgroupRoutingEntity state) private AgentEntityfindAgentByUid(List<AgentEntity> agents, String agentUid) private doubleTODO: 获取平均响应时间(秒)private WorkgroupRoutingEntitygetOrCreateRoutingState(WorkgroupEntity workgroup) getRoutingState(WorkgroupEntity workgroup) 获取工作组路由状态(用于前端可视化,不推进 cursor)。private booleanisEntityBackedMode(String routingMode) voidrefreshRoutingState(WorkgroupEntity workgroup) voidrefreshRoutingStateByWorkgroupUid(String workgroupUid) 异步预计算:刷新 workgroup 的 nextAgent(不推进 cursor)。private voidresetStateForMode(WorkgroupRoutingEntity state, WorkgroupEntity workgroup, String routingMode) selectAgent(WorkgroupEntity workgroup, ThreadEntity thread) 根据工作组路由模式选择客服private AgentEntityselectAgentRealtimeFallback(WorkgroupEntity workgroup, ThreadEntity thread, List<AgentEntity> availableAgents, String routingMode) private AgentEntityselectByConsistentHash(String visitorUid, List<AgentEntity> agents) 一致性哈希算法 相同访客尽量分配给同一个客服private AgentEntityselectByFastestResponse(List<AgentEntity> agents) 最快响应算法 选择平均响应时间最短的客服private AgentEntityselectByLeastActive(List<AgentEntity> agents) 最小活动数算法 选择当前会话数最少的客服private AgentEntityselectByRandom(List<AgentEntity> agents) 随机算法 随机选择一个可用客服private AgentEntityselectByRecent(WorkgroupEntity workgroup, ThreadEntity thread) 选择最近一次会话ThreadEntity接待的客服。private AgentEntityselectByRoundRobinInMemory(Long cursor, List<AgentEntity> agents) 轮询算法 按顺序将请求分配给每个客服private AgentEntityselectByWeightedRandom(List<AgentEntity> agents) 加权随机算法 根据客服评分和性能给予不同权重private List<AgentEntity>sortAgentsByUid(List<AgentEntity> agents)
-
Field Details
-
workgroupRoutingRepository
-
workgroupRepository
-
bytedeskEventPublisher
-
uidUtils
-
queueRestService
-
threadRestService
-
presenceFacadeService
-
-
Constructor Details
-
WorkgroupRoutingService
public WorkgroupRoutingService()
-
-
Method Details
-
selectAgent
根据工作组路由模式选择客服 -
getRoutingState
获取工作组路由状态(用于前端可视化,不推进 cursor)。 -
refreshRoutingStateByWorkgroupUid
异步预计算:刷新 workgroup 的 nextAgent(不推进 cursor)。 典型触发:presence/接待状态变化、定时任务兜底。 -
refreshRoutingState
-
advanceAfterAssignment
异步预计算:在一次分配后推进 cursor 并刷新 nextAgent。 -
isEntityBackedMode
-
selectAgentRealtimeFallback
private AgentEntity selectAgentRealtimeFallback(WorkgroupEntity workgroup, ThreadEntity thread, List<AgentEntity> availableAgents, String routingMode) -
getOrCreateRoutingState
-
resetStateForMode
private void resetStateForMode(WorkgroupRoutingEntity state, WorkgroupEntity workgroup, String routingMode) -
findAgentByUid
-
computeNextAgentForState
private AgentEntity computeNextAgentForState(String routingMode, WorkgroupEntity workgroup, ThreadEntity thread, List<AgentEntity> availableAgents, WorkgroupRoutingEntity state) -
computeNextAgentForDisplay
private AgentEntity computeNextAgentForDisplay(String routingMode, WorkgroupEntity workgroup, ThreadEntity thread, List<AgentEntity> availableAgents, WorkgroupRoutingEntity state) -
advanceStateAfterAssignment
private void advanceStateAfterAssignment(String routingMode, WorkgroupEntity workgroup, ThreadEntity thread, List<AgentEntity> availableAgents, WorkgroupRoutingEntity state, AgentEntity assignedAgent) -
selectByRoundRobinInMemory
轮询算法 按顺序将请求分配给每个客服 -
sortAgentsByUid
-
selectByLeastActive
最小活动数算法 选择当前会话数最少的客服 -
selectByRandom
随机算法 随机选择一个可用客服 -
selectByWeightedRandom
加权随机算法 根据客服评分和性能给予不同权重 -
selectByConsistentHash
一致性哈希算法 相同访客尽量分配给同一个客服 -
selectByFastestResponse
最快响应算法 选择平均响应时间最短的客服 -
calculateWeight
计算客服权重 -
getAverageResponseTime
TODO: 获取平均响应时间(秒) -
calculatePriority
计算会话优先级 -
selectByRecent
选择最近一次会话ThreadEntity接待的客服。首先选择最近一次接待的客服 thread.agent
-