| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- #include "stdafx.h"
- #include "SpBase.h"
- #include "Event.h"
- #ifndef _WIN32
- #include <time.h>
- #endif // !_WIN32
- #include "InteractiveLog_server_g.h"
- #include "../mod_customeraware/Event.h"
- using namespace InteractiveLog;
- #include "bizlog.h"
- class CInterativeLogEntity;
- class ServerSession : public LogService_ServerSessionBase
- {
- public:
- ServerSession(CInterativeLogEntity *pEntity) : m_pEntity(pEntity) {}
- virtual void Handle_LogFunction(SpOnewayCallContext<LogService_LogFunction_Info>::Pointer ctx);
- virtual void Handle_LogCustomerID(SpOnewayCallContext<LogService_LogCustomerID_Info>::Pointer ctx);
- virtual void Handle_LogAgreement(SpOnewayCallContext<LogService_LogAgreement_Info>::Pointer ctx);
- virtual void Handle_LogReceipt(SpOnewayCallContext<LogService_LogReceipt_Info>::Pointer ctx);
- virtual void Handle_LogOperation(SpOnewayCallContext<LogService_LogOperation_Info>::Pointer ctx);
- virtual void Handle_LogResponse(SpOnewayCallContext<LogService_LogResponse_Info>::Pointer ctx);
- virtual void Handle_LogAgent(SpOnewayCallContext<LogService_LogAgent_Info>::Pointer ctx);
- virtual void Handle_LogBegin(SpOnewayCallContext<LogService_LogBegin_Info>::Pointer ctx);
- virtual void Handle_LogEnd(SpOnewayCallContext<LogService_LogEnd_Info>::Pointer ctx);
- virtual void Handle_LogCallID(SpOnewayCallContext<LogService_LogCallID_Info>::Pointer ctx);
- private:
- CInterativeLogEntity *m_pEntity;
- };
- // 0x
- class CInterativeLogEntity : public CEntityBase, public ILogListener, public ISysVarListener
- {
- public:
- CInterativeLogEntity() : m_log(NULL) {}
- virtual ~CInterativeLogEntity() {}
- virtual const char *GetEntityName() const { return "InteractiveLog"; }
- virtual bool IsService()const{return true;}
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error;
- CSimpleStringA strPath;
- m_nDesktopType = 0;
- m_strSessionCount = "0";
- Error = GetFunction()->GetPath("InterLog", strPath);
- if (Error != Error_Succeed) {
- LOG_TRACE("getpath InterLog failed!");
- }
- m_log = bizlog_create((LPCSTR)strPath);
- if (!m_log)
- {
- Error = Error_Param;
- LOG_TRACE("create bizlog object failed!");
- }
- {
- CSmartPointer<IEntityFunction> Func = GetFunction();
- CSimpleStringA strValue;
- if (Func->RegistSysVarEvent(SYSVAR_DESKTOPTYPE, this) != Error_Succeed)
- {
- LOG_TRACE("register sysvar %s failed!", SYSVAR_DESKTOPTYPE);
- }
- else
- {
- Func->GetSysVar(SYSVAR_DESKTOPTYPE, strValue);
- if (strValue[0] ==DESKTOPTYPE_BUS) //切换到业务屏,打开LOG
- {
- m_nDesktopType = 0;
- }
- else if (strValue[0] == DESKTOPTYPE_INFO) //切换到信息屏,屏蔽LOG
- {
- m_nDesktopType = 1;
- }
- else if (strValue[0] == DESKTOPTYPE_USER) //切换到用户桌面,屏蔽LOG
- {
- m_nDesktopType = 2;
- }
- else
- {
- Dbg("unknown desktop type!");
- }
- }
- }
- /*{
- CSmartPointer<IEntityFunction> Func = GetFunction();
- CSimpleStringA strValue;
- if (Func->RegistSysVarEvent("SessionCount", this) != Error_Succeed)
- {
- LOG_TRACE("register sysvar %SessionCount failed!");
- }
- else
- {
- Func->GetSysVar("SessionCount", m_strSessionCount);
- Dbg("SessionCount = %s",m_strSessionCount);
- }
- }
- */
- GetFunction()->SubscribeLog(m_SubIDStopRecord, this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_CUSTOMERAWARE_END, NULL, false);
- pTransactionContext->SendAnswer(Error);
- }
- virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
- const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
- const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage)
- {
- if (dwUserCode == EVENT_MOD_CUSTOMERAWARE_END)
- {
- ErrorCodeEnum errCode;
- errCode = GetFunction()->SetSysVar("CustomerID","N");
- if (errCode != Error_Succeed)
- {
- Dbg("set CustomerID failed (%d).",errCode);
- }
- else
- {
- Dbg("set customerid to N");
- }
- }
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- if (m_log)
- {
- bizlog_destroy(m_log);
- m_log = NULL;
- }
- GetFunction()->UnsubscribeLog(m_SubIDStopRecord);
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
- {
- if (_stricmp(pszKey, SYSVAR_DESKTOPTYPE) == 0)
- {
- Dbg("desktop type from : %c to %c", pszOldValue[0], pszValue[0]);
- if ((pszOldValue[0]==DESKTOPTYPE_BUS)) //如果从业务屏切换到其他屏,自动关闭当前interlog
- {
- LogEnd();
- }
- if (pszValue[0] == DESKTOPTYPE_BUS) //切换到业务屏,打开LOG
- {
- m_nDesktopType = 0;
- }
- else if (pszValue[0] == DESKTOPTYPE_INFO) //切换到信息屏,屏蔽LOG
- {
- m_nDesktopType = 1;
- }
- else if (pszValue[0] == DESKTOPTYPE_USER) //切换到用户桌面,屏蔽LOG
- {
- m_nDesktopType = 2;
- }
- else
- {
- Dbg("unknown desktop type!");
- }
- }
- //else if (_stricmp(pszKey, "SessionCount") == 0)
- //{
- // GetFunction()->GetSysVar("SessionCount", m_strSessionCount);
- // Dbg("SessionCount = %s",m_strSessionCount);
- //}
- }
- virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszParam*/)
- {
- LOG_FUNCTION();
- return new ServerSession(this);
- }
- void LogFunction(SpOnewayCallContext<LogService_LogFunction_Info>::Pointer ctx)
- {
- //Prepare();
- if (m_nDesktopType != 0) //如果不是业务状态
- {
- Dbg("LogFunction,desktop type is not B,ignore");
- return;
- }
- CSimpleStringA name = CSimpleStringW2A(ctx->Info.nam);
- CSimpleStringA display = CSimpleStringW2A(ctx->Info.display);
- CSimpleStringA product = CSimpleStringW2A(ctx->Info.product);
- CSimpleStringA service_code = CSimpleStringW2A(ctx->Info.service_code);
- bizlog_function(m_log, name, display, product, service_code, ctx->Info.action_id);
- }
- void LogCustomerID(SpOnewayCallContext<LogService_LogCustomerID_Info>::Pointer ctx)
- {
- if (m_nDesktopType != 0) //如果不是业务状态
- {
- Dbg("LogCustomerID,desktop type is not B,ignore");
- return;
- }
- //Prepare();
- CSimpleStringA customer_id = CSimpleStringW2A(ctx->Info.customer_id);
- ErrorCodeEnum errCode;
- errCode = GetFunction()->SetSysVar("CustomerID",customer_id);
- Dbg("set CustomerID to %s",customer_id);
- if (errCode != Error_Succeed)
- {
- Dbg("set CustomerID failed (%d).",errCode);
- }
- CSimpleStringA verify_method = CSimpleStringW2A(ctx->Info.verify_method);
- bizlog_customer_id(m_log, customer_id, verify_method, ctx->Info.level, ctx->Info.action_id);
- }
- void LogAgreement(SpOnewayCallContext<LogService_LogAgreement_Info>::Pointer ctx)
- {
- if (m_nDesktopType != 0) //如果不是业务状态
- {
- Dbg("LogAgreement,desktop type is not B,ignore");
- return;
- }
- //Prepare();
- CSimpleStringA content = CSimpleStringW2A(ctx->Info.content);
- bizlog_agreement(m_log, content, ctx->Info.action_id);
- }
- void LogReceipt(SpOnewayCallContext<LogService_LogReceipt_Info>::Pointer ctx)
- {
- if (m_nDesktopType != 0) //如果不是业务状态
- {
- Dbg("LogReceipt,desktop type is not B,ignore");
- return;
- }
- //Prepare();
- CSimpleStringA content = CSimpleStringW2A(ctx->Info.content);
- bizlog_receipt(m_log, content, ctx->Info.action_id);
- }
- void LogOperation(SpOnewayCallContext<LogService_LogOperation_Info>::Pointer ctx)
- {
- if (m_nDesktopType != 0) //如果不是业务状态
- {
- Dbg("LogOperation,desktop type is not B,ignore");
- return;
- }
- //Prepare();
- CSimpleStringA code = CSimpleStringW2A(ctx->Info.code);
- CSimpleStringA content = CSimpleStringW2A(ctx->Info.content);
- bizlog_operation(m_log, code, content, ctx->Info.action_id);
- }
- void LogResponse(SpOnewayCallContext<LogService_LogResponse_Info>::Pointer ctx)
- {
- if (m_nDesktopType != 0) //如果不是业务状态
- {
- Dbg("LogResponse,desktop type is not B,ignore");
- return;
- }
- //Prepare();
- CSimpleStringA code = CSimpleStringW2A(ctx->Info.code);
- CSimpleStringA content = CSimpleStringW2A(ctx->Info.content);
- bizlog_response(m_log, code, content, ctx->Info.action_id);
- }
- void LogAgent(SpOnewayCallContext<LogService_LogAgent_Info>::Pointer ctx)
- {
- if (m_nDesktopType != 0) //如果不是业务状态
- {
- Dbg("LogAgent,desktop type is not B,ignore");
- return;
- }
- //Prepare();
- CSimpleStringA code = CSimpleStringW2A(ctx->Info.code);
- CSimpleStringA content = CSimpleStringW2A(ctx->Info.content);
- bizlog_agent(m_log, code, content, ctx->Info.action_id);
- }
- void LogBegin(SpOnewayCallContext<LogService_LogBegin_Info>::Pointer ctx)
- {
- if (m_nDesktopType != 0) //如果不是业务状态
- {
- Dbg("LogBegin,desktop type is not B,ignore");
- return;
- }
- //Prepare();
- Dbg("log Begin get sessionid and sessioncnt");
- CSimpleStringA session_id = CSimpleStringW2A(ctx->Info.session_id);
- //文件名定为YYYYMMDD_XXX_SessionID。xxx为业务浏览器记录的运行时SessionID变化次数
-
- char strtimebuffer[256] = {0};
- #ifdef RVC_OS_WIN
- SYSTEMTIME nowTime; // 系统时间结构体
- GetLocalTime(&nowTime);
- sprintf_s(strtimebuffer, "%4d%02d%02d", nowTime.wYear, nowTime.wMonth, nowTime.wDay);
- #else
- struct tm* t;
- time_t tt;
- time(&tt);
- t = localtime(&tt);
- snprintf(strtimebuffer, 256, "%4d%02d%02d", t->tm_year+1900, t->tm_mon+1, t->tm_mday);
- #endif
- CSimpleStringA strTime = strtimebuffer;
- m_strSessionCount = CSimpleStringA::Format("%d",ctx->Info.session_count);
- Dbg("SessionCount = %s",m_strSessionCount);
- CSimpleStringA filename = strTime+"_"+m_strSessionCount+"_"+session_id;
- bizlog_session_begin(m_log, session_id,filename);
- Dbg("Begin new log -- %s",filename);
- }
- void LogEnd(SpOnewayCallContext<LogService_LogEnd_Info>::Pointer ctx)
- {
- if (m_nDesktopType != 0) //如果不是业务状态
- {
- Dbg("LogEnd,desktop type is not B,ignore");
- return;
- }
- //Prepare();
- bizlog_session_end(m_log);
- Dbg("End log");
- }
- void LogEnd()
- {
- bizlog_session_end(m_log);
- Dbg("Desktop type change to !B,Auto End log");
- }
- void LogCallID(SpOnewayCallContext<LogService_LogCallID_Info>::Pointer ctx)
- {
- if (m_nDesktopType != 0) //如果不是业务状态
- {
- Dbg("LogCallID,desktop type is not B,ignore");
- return;
- }
- CSimpleStringA callid = CSimpleStringW2A(ctx->Info.call_id);
- CSimpleStringA agentid = CSimpleStringW2A(ctx->Info.workNumber);
- CSimpleStringA skillCode = CSimpleStringW2A(ctx->Info.skillCode);
- bizlog_call_id(m_log, callid, skillCode, agentid, ctx->Info.action_id);
- }
- void Prepare()
- {
- //if (m_log)
- //{
- // if (!bizlog_has_session(m_log))
- // {
- // m_uid = CUUID::Create(m_uid);
- // bizlog_session_begin(m_log, m_uid.ToString());
- // }
- //}
- }
- private:
- CUUID m_SubIDStopRecord;
- bizlog_t *m_log;
- int m_nDesktopType; //0:业务屏,1:信息屏,2:用户桌面
- CSimpleStringA m_strSessionCount;
- };
- void ServerSession::Handle_LogFunction(SpOnewayCallContext<LogService_LogFunction_Info>::Pointer ctx)
- {
- m_pEntity->LogFunction(ctx);
- }
- void ServerSession::Handle_LogCustomerID(SpOnewayCallContext<LogService_LogCustomerID_Info>::Pointer ctx)
- {
- m_pEntity->LogCustomerID(ctx);
- }
- void ServerSession::Handle_LogAgreement(SpOnewayCallContext<LogService_LogAgreement_Info>::Pointer ctx)
- {
- m_pEntity->LogAgreement(ctx);
- }
- void ServerSession::Handle_LogReceipt(SpOnewayCallContext<LogService_LogReceipt_Info>::Pointer ctx)
- {
- m_pEntity->LogReceipt(ctx);
- }
- void ServerSession::Handle_LogOperation(SpOnewayCallContext<LogService_LogOperation_Info>::Pointer ctx)
- {
- m_pEntity->LogOperation(ctx);
- }
- void ServerSession::Handle_LogResponse(SpOnewayCallContext<LogService_LogResponse_Info>::Pointer ctx)
- {
- m_pEntity->LogResponse(ctx);
- }
- void ServerSession::Handle_LogAgent(SpOnewayCallContext<LogService_LogAgent_Info>::Pointer ctx)
- {
- m_pEntity->LogAgent(ctx);
- }
- void ServerSession::Handle_LogBegin(SpOnewayCallContext<LogService_LogBegin_Info>::Pointer ctx)
- {
- m_pEntity->LogBegin(ctx);
- }
- void ServerSession::Handle_LogEnd(SpOnewayCallContext<LogService_LogEnd_Info>::Pointer ctx)
- {
- m_pEntity->LogEnd(ctx);
- }
- void ServerSession::Handle_LogCallID(SpOnewayCallContext<LogService_LogCallID_Info>::Pointer ctx)
- {
- m_pEntity->LogCallID(ctx);
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CInterativeLogEntity)
- SP_END_ENTITY_MAP()
|