#include "OpTransfer.h" #include "VirtualChan.h" #include "OperationReactor.h" #include "FsProxy.h" COpTransfer::COpTransfer(COperationReactor * pParent, long Instance) : COperation(pParent, Instance), m_pHostExtChan(nullptr) { } COpTransfer::~COpTransfer(void) { } /***************************************************************** **【函数名称】 _end **【函数功能】 操作完成 **【参数】 IsSucceed 操作是否成功 lpData 随路数据 **【返回值】 ****************************************************************/ void COpTransfer::_end(bool IsSucceed) { std::string sql; if (IsSucceed) { LOG_INFO(("{OpTransfer}: 分机[%lu]转移成功, DestNum = %s"), m_pHostExtChan->no(), m_DestNumber.c_str()); Format fmt("update transfer set answer_time = '%s',is_success = %d where uuid = '%s'"); fmt % Util::CurTime() %1 % m_SessionId; sql = fmt.str(); } else { LOG_WARN(("{OpTransfer}: 分机[%lu]转移失败, DestNum = %s"), m_pHostExtChan->no(), m_DestNumber.c_str()); Format fmt("update transfer set end_time = '%s',is_success = %d where uuid = '%s'"); fmt % Util::CurTime() %0 % m_SessionId; sql = fmt.str(); } SqlWrite::GetInstance()->addSql(sql); SqlWrite::GetInstance()->addSql(toSql(IsSucceed, "转移")); // 返回执行结果 if (m_InstanceCancel != FS_LINK_INSTANCE_INVALID) m_pParent->onOpResult(m_InstanceCancel, !IsSucceed); m_pParent->onOpResult(m_Instance, this, IsSucceed, std::to_string(m_pHostExtChan->no())); } /***************************************************************** **【函数名称】 start **【函数功能】 执行操作 **【参数】 **【返回值】 *****************************************************************/ bool COpTransfer::start(LineOpParam* pParam) { // 校验状态 if (m_pHostChan->state() != CHAN_LOGIC_STATE_TALKING) return false; // 获取待转移的通道 VirtualChan* pDestChan = CFsProxy::GetInstance().getAssoChanInSession(m_pHostChan); if (pDestChan == nullptr || pDestChan->currOp() != nullptr) { if (pDestChan != nullptr && pDestChan->currOp() != nullptr) LOG_WARN("当前通道[%lu]已绑定操作,OpType = [%s]",pDestChan->no(),pDestChan->opNumber().c_str()); return false; } // 保存被叫信息 std::string CallerNum = pParam->szParam1; m_DestNumber = pParam->szParam2; m_pHostExtChan = m_pHostChan; detachHostChan(); attachHostChan(pDestChan); // 通知启动日志 LOG_INFO(("{OpConsult}: 分机[%lu]执行转移, DestNum = %s"), m_pHostExtChan->no(), m_DestNumber.c_str()); m_SessionId = pDestChan->sessionId(); std::string caller_agent = CFsProxy::GetInstance().getAgentByExten(CallerNum); std::string callee_agent = CFsProxy::GetInstance().getAgentByExten(m_DestNumber); m_CallerAgent = caller_agent; m_Caller = CallerNum; m_CalleeAgent = callee_agent; m_Callee = m_DestNumber; m_OpTime = Util::CurTime(); { Format fmt("update cdr set op_type = %d where uuid = '%s'"); fmt % type() % pDestChan->sessionId(); SqlWrite::GetInstance()->addSql(fmt.str()); } { Format fmt("insert into transfer(uuid,caller_agent,caller,callee_agent,callee,create_time) values('%s','%s','%s','%s','%s','%s')"); fmt %pDestChan->sessionId() % caller_agent %CallerNum %callee_agent %m_DestNumber %m_OpTime; SqlWrite::GetInstance()->addSql(fmt.str()); } return CFsProxy::GetInstance().transfer(uniqueId(), pDestChan, m_DestNumber); } /***************************************************************** **【函数名称】 onBackgroudJobDone **【函数功能】 后台命令执行结束事件处理 **【参数】 **【返回值】 *****************************************************************/ void COpTransfer::onBackgroudJobDone(PBG_JOB_NOTIFY pNotify) { if (pNotify->JobBody.find( ESL_JOB_DONE_RES_FAILED) != std::string::npos) _end(false); } void COpTransfer::onSessionChanStateUpdated(VirtualChan * pChan) { if (pChan == m_pHostExtChan) return; switch ((int)pChan->state()) { case CHAN_LOGIC_STATE_RING_BACK: case CHAN_LOGIC_STATE_ALERTING: m_pParent->onOpProcess(m_Instance, m_pHostChan->no(), pChan->no(), pChan->type(), pChan->callerNum(), pChan->calleeNum()); break; case CHAN_LOGIC_STATE_TALKING: _end(true); break; case CHAN_LOGIC_STATE_FREE: _end(false); } }