| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- #include "RcfEcho.h"
- #include <iostream>
- #include <sstream>
- #include <fstream>
- #include <boost\date_time\posix_time\posix_time.hpp>
- #include <boost\filesystem.hpp>
- #include <boost/algorithm/string.hpp>
- #include "CRedis.h"
- #include "GlobalVar.h"
- std::string GetCurTime()
- {
- std::string curTime = boost::posix_time::to_iso_extended_string(boost::posix_time::microsec_clock::local_time());
- int pos = curTime.find('T');
- curTime.replace(pos, 1, std::string(" "));
- curTime += " ";
- return curTime;
- }
- static std::string GetCurDate()
- {
- std::string curTime = boost::posix_time::to_iso_extended_string(boost::posix_time::microsec_clock::local_time());
- int pos = curTime.find('T');
- curTime = curTime.substr(0, pos);
- return curTime;
- }
- static std::string logPath = "./data/rcf/";
- void Log(const RCF::ByteBuffer & byte)
- {
- std::cout << byte.string() << std::endl;
- if (!boost::filesystem::exists(logPath))
- boost::filesystem::create_directories(logPath);
- static std::string lastFile = logPath + GetCurDate() + "_rcf.txt";
- std::string curFile = logPath + GetCurDate() + "_rcf.txt";
- static std::ofstream file(lastFile, std::ios::app);
- if (curFile != lastFile) // 第二天重新写文件
- {
- if (file.is_open())
- {
- file.close();
- }
- lastFile = curFile;
- file.open(lastFile, std::ios::app);
- }
- if (file.is_open())
- {
- file << byte.string() << std::endl;
- file.flush();
- }
- }
- void print(std::string str)
- {
- RCF::ByteBuffer byte_buff(str);
- auto log = RCF::LogToFunc(std::bind(Log, std::placeholders::_1));
- log.write(byte_buff);
- }
- CRcfEcho::CRcfEcho():m_ctiRunState(false)
- {
- RCF::enableLogging();
- }
- bool CRcfEcho::pushAgentList(const int agentId, const std::string & agentList)
- {
- std::unique_lock<std::mutex>lock(m_agentListLock);
- m_agentList[agentId] = agentList;
- lock.unlock();
- //std::cout << GetCurTime() << "保存:" << __FUNCTION__ << " " << agentId << ": " << agentList << std::endl;
-
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << agentId << ": \n" << agentList << std::endl;
- print(ss.str());
- return true;
- }
- bool CRcfEcho::getAgentList(const int agentId, std::string & agentList)
- {
- std::unique_lock<std::mutex>lock(m_agentListLock);
- auto it = m_agentList.find(agentId);
- if (it == m_agentList.end())
- return false;
- agentList = it->second;
- m_agentList.erase(it);
- lock.unlock();
- //std::cout << GetCurTime() << "获取:" << __FUNCTION__ << " " << agentId << ": " << agentList << std::endl;
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << agentId << ": \n" << agentList << std::endl;
- print(ss.str());
- return true;
- }
- bool CRcfEcho::pushRedis(std::vector<std::string>& v)
- {
- for (auto val : v)
- {
- std::vector<std::string> vecs;
- boost::split(vecs, val, boost::algorithm::is_any_of("|"));
- if (vecs.size()>=2)
- {
- GlobalVar::GetInstance()->updateGroupTalkingNum(vecs.at(0), vecs.at(1)); // 2022-03-16 保存到全局变量中,供http接口访问
- bool ret = CRedis::GetInstance()->set(vecs.at(0).c_str(),vecs.at(1).c_str());
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << ret << " \n" << vecs.at(0)<< " :"<<vecs.at(1) << std::endl;
- print(ss.str());
- }
- }
- return true;
- }
- bool CRcfEcho::pushCallIndex(const std::string& callIndex)
- {
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << " \n" << callIndex << std::endl;
- print(ss.str());
- std::vector<std::string> vecs;
- boost::split(vecs, callIndex, boost::algorithm::is_any_of("#"));
- for (auto val : vecs)
- {
- std::vector<std::string> ivr;
- boost::split(ivr, val, boost::algorithm::is_any_of("|"));
- if (vecs.size() >= 2)
- {
- m_callIndexs[ivr.at(0)] = ivr.at(1);
- }
- }
- return true;
- }
- bool CRcfEcho::getCallIndex(const int index, std::string & callIndex)
- {
- std::string strIndex = std::to_string(index);
- auto it = m_callIndexs.find(strIndex);
- if (it == m_callIndexs.end())
- {
- std::stringstream ss1;
- ss1 << GetCurTime() << " " << __FUNCTION__ << "\n"<<" ivr索引" << index << " 失败" << std::endl;
- print(ss1.str());
- return false;
- }
- callIndex = it->second;
- std::stringstream ss1;
- ss1 << GetCurTime() << " " << __FUNCTION__ << " " << " \n" << index << " :" << callIndex << std::endl;
- print(ss1.str());
- return true;
- }
- bool CRcfEcho::pushSubmitData(const int nEventType, const std::string& state)
- {
- std::unique_lock<std::mutex>lock(m_submitDataLock);
- m_submitDatas[nEventType] = state;
- m_submitData = state;
- lock.unlock();
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << nEventType << ": \n" << state << std::endl;
- print(ss.str());
- return true;
- }
- bool CRcfEcho::getSubmitData(const int nEventType, std::string & state)
- {
- std::unique_lock<std::mutex>lock(m_submitDataLock);
- auto it = m_submitDatas.find(nEventType);
- if (it == m_submitDatas.end())
- {
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << nEventType << ": \n" << "失败" << std::endl;
- print(ss.str());
- return false;
- }
- state = it->second;
- //m_submitDatas.erase(it);
- //state = m_submitData;
- lock.unlock();
-
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << nEventType << ": \n" << state << std::endl;
- print(ss.str());
- return true;
- }
- bool CRcfEcho::pushZmdExtenStateList(const std::string & extList)
- {
- m_extZmdList = extList;
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << m_extZmdList << std::endl;
- print(ss.str());
- return true;
- }
- bool CRcfEcho::getZmdExtenStateList(std::string & extList)
- {
- extList = m_extZmdList;
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << m_extZmdList << std::endl;
- print(ss.str());
- return true;
- }
- bool CRcfEcho::pushOnlineAgentGroupDetail(const std::string & groupNo, const std::string & agentList)
- {
- m_agentGroup[groupNo] = agentList;
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << groupNo << ": " << agentList << std::endl;
- print(ss.str());
- return true;
- }
- bool CRcfEcho::getOnlineAgentGroupDetail(std::vector<std::string>& agentList)
- {
- agentList.clear();
- auto it = m_agentGroup.begin();
- while (it != m_agentGroup.end())
- {
- agentList.emplace_back(it->second);
-
- // 日志打印
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << it->first << ": " << it->second << std::endl;
- print(ss.str());
- //
- ++it;
- }
- return true;
- }
- bool CRcfEcho::delOnlineAgentGroupDetail(const int agentID, const int extenNo)
- {
- std::vector<std::string> vecs; // 坐席集合
- std::vector<std::string> detailVec; // 坐席信息 下标0坐席号,1分机号
- std::string str; // 重新拼接每个组对应的坐席
- auto it = m_agentGroup.begin();
- while (it != m_agentGroup.end()) {
- vecs.clear();
- str = "";
- boost::split(vecs, it->second, boost::algorithm::is_any_of("#"));
- // 遍历每个坐席信息,用于判断是否是要删除的
- auto vecIt = vecs.begin();
- while (vecIt != vecs.end()) {
- detailVec.clear();
- boost::split(detailVec, *vecIt, boost::algorithm::is_any_of("|"));
- if (detailVec.size() > 2) {
- if (detailVec[0] == std::to_string(agentID) && detailVec[1] == std::to_string(extenNo)) {
- // 该坐席删除
- }
- else {
- str += *vecIt;
- str += "#";
- }
- }
- ++vecIt;
- }
- // 重新赋值
- it->second = str;
- // 日志打印
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << " " << it->first << ": "<< it->second << std::endl;
- print(ss.str());
- //
- ++it;
- }
- return true;
- }
- bool CRcfEcho::clearOnlineAgentGroupDetail()
- {
- m_agentGroup.clear();
- // 日志打印
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << std::endl;
- print(ss.str());
- return false;
- }
- bool CRcfEcho::pushCtiState(const bool isRun)
- {
- m_ctiRunState.store(isRun);
- // 日志打印
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << ":" << isRun << std::endl;
- print(ss.str());
- return m_ctiRunState.load();
- }
- bool CRcfEcho::getCtiState()
- {
- std::stringstream ss;
- ss << GetCurTime() << " " << __FUNCTION__ << ":" << m_ctiRunState.load() << std::endl;
- print(ss.str());
- return m_ctiRunState.load();
- }
|