123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- #include "stdafx2.h"
- #include "mod_GuiConsole.h"
- #include "guitask.h"
- #include "EventCode.h"
- #include "MaterialMgrCnn.h"
- #include "GUIConsoleUserCodeDef.h"
- #include "CardIssuer_client_g.h"
- using namespace CardIssuer;
- #include "MaintainWatcher_client_g.h"
- using namespace MaintainWatcher;
- #include "fileutil.h"
- void CGUIConsoleEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_FSM.Init(this);
- auto rc = SubscribeEntitysEvents();
- if (rc != Error_Succeed)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("subscribe MaintainWatcher event fail, %s", SpStrError(rc));
- else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("subscribe MaintainWatcher event succeed");
-
- bool toInitializeSysLog(true);
- CSmartPointer<IConfigInfo> pConfig;
- if (GetFunction()->OpenConfig(Config_Software, pConfig) == Error_Succeed) {
- CSimpleStringA strValue(true);
- pConfig->ReadConfigValue("Common", "SwitchLogService", strValue);
- if (strValue.Compare("OFF") == 0) {
- toInitializeSysLog = false;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Do not initialize SysLog!!!!");
- }
- }
- if (toInitializeSysLog) {
- InitializeBeidou();
- } else {
- LogWarn(Severity_Low, Error_Debug, EVENT_MOD_GUICONSOLE_DISABLE_UNIONNETLOG_BCZ_CFG, "do not enable union log!");
- }
- pTransactionContext->SendAnswer(Error_Succeed) ;
- }
- void CGUIConsoleEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_FSM.PostExitEvent();
- UnsubscribeEntitysEvents();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- CServerSessionBase *CGUIConsoleEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszParam*/)
- {
- return new CGUIConsoleSession(this);
- }
- void CGUIConsoleEntity::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, const linkContext& pLinkInfo)
- {
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnLog(entity = %s, syscode = 0x%X, usercode = 0x%X", pszEntityName, dwSysError, dwUserCode);
- if (dwUserCode == EVENT_MACHINE_COVER_OPEN) // 机盖打开
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the machine cover open!!");
- m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_CoverOpen));
- }
- else if (dwUserCode == EVENT_MACHINE_COVER_CLOSE) // 机盖关闭
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the machine cover close.");
- m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_CoverClose));
- }
- else if (dwUserCode == EVENT_UKEY_INSERTED) // 证书插入
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the key inserted");
- m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_UKeyInserted));
- }
- else if ((dwUserCode == EVENT_UKEY_LOW_LEVEL) // 具有维护权
- || (dwUserCode == EVENT_UKEY_HIGH_LEVEL)) // 具有高级权限)
- {
- bool bLowLevel = dwUserCode == EVENT_UKEY_LOW_LEVEL;
-
- if (bLowLevel)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("lower priviledge");
- else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("higher priviledge");
- // 调用UKey接口取维护人员信息
- m_strUserID = "";
- m_strUserName = "";
- m_strAuthorizer = "";
- m_strAuthTime = "";
- MaintainCertificate_ClientBase *pClient = new MaintainCertificate_ClientBase(this);
- auto rc = pClient->Connect();
- if (rc != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("connect to MaintainWatcher entity fail: %d", rc);
- pClient->SafeDelete();
- }
- else
- {
- MaintainCertificate_GetUserInfo_Req req = {};
- MaintainCertificate_GetUserInfo_Ans ans = {};
- rc = pClient->GetUserInfo(req, ans, 10000);
- if (rc != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get userinfo fail from MaintainWatcher: %s", SpStrError(rc));
- }
- else
- {
- // UserID=SP00000004;UserName=RVC0001;AuthorierID=SP00000001;AuthorizeTime=2014/8/13 18:46:29;RecommenderSAP=80274390;RecommenderOfficeID=274390;
- CSimpleStringA &str = ans.UserInfo;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get maintainer info: %s", (const char*)str);
- auto arr = str.Split(';');
- for (int i = 0; i < arr.GetCount(); i++)
- {
- auto arr2 = arr[i].Split('=');
- if (arr2.GetCount() != 2)
- continue;
- if (arr2[0] == "UserID")
- m_strUserID = arr2[1];
- else if (arr2[0] == "UserName")
- m_strUserName = arr2[1];
- else if (arr2[0] == "AuthorierID")
- m_strAuthorizer = arr2[1];
- else if (arr2[0] == "AuthorizeTime")
- m_strAuthTime = arr2[1];
- }
- }
-
- pClient->GetFunction()->CloseSession();
- }
- pClient = NULL;
- m_strCurRight = bLowLevel ? "Low" : "High";
- m_dwBeginTime = CSmallDateTime::GetNow();
- auto pEvent = new FSMEvent(CGUIConsoleFSM::Event_CertVerified);
- pEvent->param1 = bLowLevel ? 1 : 2;
- m_FSM.PostEventFIFO(pEvent);
- }
- else if (dwUserCode == EVENT_UKEY_PULLOUT) // 证书拔出
- {
- m_strUserID = "";
- m_strUserName = "";
- m_strAuthorizer = "";
- m_strAuthTime = "";
- m_strCurRight = "";
- m_dwBeginTime = 0;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("certificate key pull out");
- m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_UKeyPulled));
- }
- else if (dwUserCode == LOG_EVT_HEALTH_FIRST_ENTER_MAINPADE)
- {
- // IE首页打开, 关闭运行输出
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("IE main page has been loaded successfully, close console terminal!");
- GetFunction()->GetPrivilegeFunction()->CloseOuputConsole();
- }
- }
- ErrorCodeEnum CGUIConsoleEntity::SubscribeEntitysEvents()
- {
- auto pFunc = GetFunction();
- auto rc = pFunc->SubscribeLog(m_SubLogID1, this, Log_Event, Severity_None, Error_IgnoreAll, -1, "MaintainWatcher");
- rc = pFunc->SubscribeLog(m_SubLogID2, this, Log_Event, Severity_None, Error_IgnoreAll, -1, "Gpio");
- // 业务首页加载事件
- rc = pFunc->SubscribeLog(m_SubLogID3, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HEALTH_FIRST_ENTER_MAINPADE, "HealthManager");
- return rc;
- }
- ErrorCodeEnum CGUIConsoleEntity::UnsubscribeEntitysEvents()
- {
- auto pFunc = GetFunction();
- if ((__int64)m_SubLogID1 != 0)
- pFunc->UnsubscribeLog(m_SubLogID1);
-
- if ((__int64)m_SubLogID2 != 0)
- pFunc->UnsubscribeLog(m_SubLogID2);
- if ((__int64)m_SubLogID3 != 0)
- pFunc->UnsubscribeLog(m_SubLogID3);
- return Error_Succeed;
- }
- ErrorCodeEnum CGUIConsoleEntity::GetCurrentMaintainer(CSimpleStringA &strUserID, CSimpleStringA &strUserName, CSimpleStringA &strCurRight,
- CSimpleStringA &strAuthorizer, unsigned int &dwBeginTime)
- {
- strUserID = m_strUserID;
- strUserName = m_strUserName;
- strCurRight = m_strCurRight;
- strAuthorizer = m_strAuthorizer;
- dwBeginTime = m_dwBeginTime;
- return Error_Succeed;
- }
- ErrorCodeEnum CGUIConsoleEntity::Empower(const char *pszUserID)
- {
- if (m_strUserID.IsNullOrEmpty() || m_strUserID.Compare(pszUserID) != 0)
- return Error_NoPrivilege;
- m_strCurRight = "High";
- m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_HighLevel));
- return Error_Succeed;
- }
- ErrorCodeEnum CGUIConsoleEntity::Takeover(const char *pszUserID)
- {
- if (m_strUserID.IsNullOrEmpty() || m_strUserID.Compare(pszUserID) != 0)
- return Error_NoPrivilege;
- m_strCurRight = "Low";
- m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_Takeover));
- return Error_Succeed;
- }
- ErrorCodeEnum CGUIConsoleEntity::ForceQuit()
- {
- m_strUserID = "";
- m_strUserName = "";
- m_strAuthorizer = "";
- m_strAuthTime = "";
- m_strCurRight = "";
- m_dwBeginTime = 0;
- m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_ForceQuit));
- return Error_Succeed;
- }
- ErrorCodeEnum CGUIConsoleEntity::PostUserLoginEvent(const char *pszUserID)
- {
- m_strUserID = pszUserID;
- m_strUserName = pszUserID;
- m_strAuthorizer = "";
- m_strAuthTime = "";
- m_strCurRight = "Low";
- m_dwBeginTime = CSmallDateTime::GetNow();
- m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_CoverOpen));
- auto pEvent = new FSMEvent(CGUIConsoleFSM::Event_CertVerified);
- pEvent->param1 = 1;
- m_FSM.PostEventFIFO(pEvent);
- return Error_Succeed;
- }
- ErrorCodeEnum CGUIConsoleEntity::AddTradeManage(const char *pszTerminalNo, const char *pszAgentID, const char *pszTime)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AddTradeManage: %s, %s, %s", pszTerminalNo, pszAgentID, pszTime);
- ErrorCodeEnum rc = Error_Succeed;
- CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
- if (pCnn->ConnectFromCentralSetting() && pCnn->IsConnectionOK())
- {
- rc = pCnn->AddTradeManage(pszTerminalNo, pszAgentID, pszTime);
- pCnn->Close();
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("连接物料服务失败");
- rc = Error_NetBroken;
- }
- pCnn->DecRefCount();
- pCnn = NULL;
- if (Error_Succeed != rc)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("mod AddTradeManage return : %s", SpStrError(rc));
- return rc;
- }
- ErrorCodeEnum CGUIConsoleEntity::AddMaterialCounter(const char *pszMaterialCode)
- {
- // 递增后台计数
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AddMaterialCounter: %s", pszMaterialCode);
- CSystemStaticInfo sysInfo;
- auto rc = GetFunction()->GetSystemStaticInfo(sysInfo);
- assert(rc == Error_Succeed);
- CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
- if (pCnn->ConnectFromCentralSetting() && pCnn->IsConnectionOK())
- {
- rc = pCnn->AddMaterialCounter(sysInfo.strTerminalID, pszMaterialCode);
- pCnn->Close();
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Connect to MaterialMgrEntity failed!");
- rc = Error_NetBroken;
- }
- pCnn->DecRefCount();
- pCnn = NULL;
- if (rc == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Add material counter for %s succ.", pszMaterialCode);
- }
- else
- {
- LogError(Severity_Middle, rc, 0, CSimpleStringA::Format("add material counter failed: %s", SpStrError(rc)));
- }
- return rc;
- }
- //查询物料信息
- ErrorCodeEnum CGUIConsoleEntity::QueryMaterialInfo(const char *pszDeviceNo, unsigned int &count, CAutoArray<CSimpleStringA> &arrDeviceNo, CAutoArray<CSimpleStringA> &arrMateriel,
- CAutoArray<CSimpleStringA> &CardGroove, CAutoArray<CSimpleStringA> &CardBoxNo, CAutoArray<CSimpleStringA> &PsbCode, CAutoArray<CSimpleStringA> &PsbName,
- CAutoArray<unsigned int> &CardInit, CAutoArray<unsigned int> &CardRemains, CAutoArray<unsigned int> &CardIssued, CAutoArray<unsigned int> &CardMixed,
- CAutoArray<unsigned int> &CardPercent, CAutoArray<CSimpleStringA> &TerminalNo, CAutoArray<CSimpleStringA> &Maintainer, CAutoArray<CSimpleStringA> &MaintainTime,
- CAutoArray<CSimpleStringA> &UpdateTime)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("QueryMaterialInfo DeviceNo = %s", pszDeviceNo);
- ErrorCodeEnum rc = Error_Succeed;
- CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
-
- CSystemStaticInfo sysInfo;
- rc = GetFunction()->GetSystemStaticInfo(sysInfo);
- assert(rc == Error_Succeed);
- rc = pCnn->QueryMaterialInfo(pszDeviceNo, count, arrDeviceNo, arrMateriel, CardGroove, CardBoxNo, PsbCode, PsbName, CardInit, CardRemains, CardIssued, CardMixed,
- CardPercent, TerminalNo, Maintainer, MaintainTime, UpdateTime);
- if(pCnn->IsConnectionOK())
- pCnn->Close();
- pCnn->DecRefCount();
- pCnn = NULL;
- return rc;
- }
- ErrorCodeEnum CGUIConsoleEntity::GetMaterialCounter(const char *pszMaterial, unsigned int &dwLastCapacity, unsigned int &dwUsedCounter)
- {
- ErrorCodeEnum rc = Error_Succeed;
- CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
- if (pCnn->ConnectFromCentralSetting() && pCnn->IsConnectionOK())
- {
- CSystemStaticInfo sysInfo;
- auto rc = GetFunction()->GetSystemStaticInfo(sysInfo);
- assert(rc == Error_Succeed);
- GetMaterialCounterRet ret = {};
- rc = pCnn->GetMaterialCounter(pszMaterial, (const char*)sysInfo.strTerminalID, (const char*)GetCurMaintainer(),
- dwLastCapacity, dwUsedCounter);
- pCnn->Close();
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Connect to MaterialMgrEntity failed!");
- rc = Error_NetBroken;
- }
- pCnn->DecRefCount();
- pCnn = NULL;
- return rc;
- }
- ErrorCodeEnum CGUIConsoleEntity::ResetMaterialCounter(const char *pszMaterial, unsigned int dwResetCapacity,
- unsigned int dwUsedCounter, unsigned int dwRemainCounter, const char *pszComment)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ResetMaterialCounter: %s, reset: %d", pszMaterial, dwResetCapacity);
- // 重置硬件计数
- ErrorCodeEnum rc = Error_Succeed;
- CSimpleStringA strMaterialCode = pszMaterial;
- if (strMaterialCode == "DebitCard" || strMaterialCode == "RetainCard")
- {
- CardIssuerService_ClientBase *pClient = new CardIssuerService_ClientBase(this);
- rc = pClient->Connect();
- if (rc == Error_Succeed)
- {
- CardIssuerService_SetMaterialCount_Req req = {};
- if (strMaterialCode == "DebitCard")
- {
- req.bRemains = true;
- req.remains = dwResetCapacity;
- req.bIssued = true;
- req.issued = 0;
- req.bMixed = true;
- req.mixed = 0;
- req.bCaptured = false;
- }
- else if (strMaterialCode == "RetainCard")
- {
- req.bCaptured = true;
- req.captured = 0;
- req.bRemains = false;
- req.bIssued = false;
- req.bMixed = false;
- }
- CardIssuerService_SetMaterialCount_Ans ret = {};
- rc = pClient->SetMaterialCount(req, ret, 10000);
- pClient->GetFunction()->CloseSession();
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("连接CardIssuer失败");
- pClient->SafeDelete();
- }
- }
- else
- {
- rc = Error_NoTarget;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Unknow material code: {%s}", (const char*)strMaterialCode);
- }
- if (rc != Error_Succeed)
- {
- LogError(Severity_Middle, rc, 0, CSimpleStringA::Format("Reset teminal material counter failed: %s", SpStrError(rc)));
- return rc;
- }
- // 重置后台计数
- CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
- if (pCnn->ConnectFromCentralSetting() && pCnn->IsConnectionOK())
- {
- CSystemStaticInfo sysInfo;
- rc = GetFunction()->GetSystemStaticInfo(sysInfo);
- assert(rc == Error_Succeed);
- rc = pCnn->ResetMaterialCounter(strMaterialCode, sysInfo.strTerminalID, GetCurMaintainer(),
- dwResetCapacity, dwUsedCounter, dwRemainCounter, pszComment);
- pCnn->Close();
- }
- else {
- rc = Error_NetBroken;
- }
- pCnn->DecRefCount();
- pCnn = NULL;
- if (rc == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Reset teminal material counter succ: %s", (const char*)strMaterialCode);
- }
- else
- {
- LogError(Severity_Middle, rc, 0, CSimpleStringA::Format("Reset teminal material counter from server failed:%s", SpStrError(rc)));
- }
- return rc;
- }
- ErrorCodeEnum CGUIConsoleEntity::RegistSwallowedCard(const char *pszCardNo, const char *pszReasonCode,
- const char *pszDate, const char *pszTime, const char *pszDeviceSciNo)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RegistSwallowedCard card = %s, reson = %s", pszCardNo, pszReasonCode);
- // 20170210: 空卡或无卡号吞卡也要登记
- //if (pszCardNo == NULL || strlen(pszCardNo) == 0)
- // return Error_Param;
- // invoke material branch service
- ErrorCodeEnum rc = Error_Break;
- CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
- if (pCnn->ConnectFromCentralSetting() && pCnn->IsConnectionOK())
- {
- CSystemStaticInfo sysInfo;
- rc = GetFunction()->GetSystemStaticInfo(sysInfo);
- assert(rc == Error_Succeed);
- rc = pCnn->RegistSwallowedCard(sysInfo.strMachineType, sysInfo.strTerminalID, pszCardNo, pszReasonCode, pszDate, pszTime, pszDeviceSciNo);
- pCnn->Close();
- }
- else {
- rc = Error_NetBroken;
- }
- pCnn->DecRefCount();
- pCnn = NULL;
- char tempCardNo[MAX_PATH] = "";
- int cardNoLen = strlen(pszCardNo);
- if (cardNoLen > 8)
- {
- for (int i = 0; i < 4; i++)
- *(tempCardNo + i) = *(pszCardNo + i);
- for (int i = 4; i < cardNoLen - 4; i++)
- *(tempCardNo + i) = '*';
- for (int i = cardNoLen - 4; i < cardNoLen; i++)
- *(tempCardNo + i) = *(pszCardNo + i);
- *(tempCardNo + cardNoLen) = '\0';
- }
- else
- strcpy(tempCardNo, pszCardNo);
- if (rc == Error_Succeed)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Register swallow card succ,cardno: %s, reason: %s", tempCardNo, pszReasonCode);
- else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Register swallow card failed(%s),cardno: %s, reason: %s", SpStrError(rc), tempCardNo, pszReasonCode);
-
- return rc;
- }
- ErrorCodeEnum CGUIConsoleEntity::SyncMaterialCount(const char *pszDeviceNo, DWORD dwCardBoxNum,
- CAutoArray<bool> &arrMaintainFlag, CAutoArray<CSimpleStringA> &arrMaintainer, CAutoArray<unsigned int> &arrMaintainTime,
- CAutoArray<CSimpleStringA> &arrCardBoxNo, CAutoArray<CSimpleStringA> &arrPsbCode,
- CAutoArray<CSimpleStringA> &arrPsbName, CAutoArray<unsigned int> &arrCardInit, CAutoArray<unsigned int> &arrCardRemains,
- CAutoArray<unsigned int> &arrCardIssued, CAutoArray<unsigned int> &arrCardMixed, CAutoArray<unsigned int> &arrCardPercent)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SyncMaterialCount DeviceNo = %s, CardBoxNum = %d", pszDeviceNo, dwCardBoxNum);
- if (pszDeviceNo == NULL || strlen(pszDeviceNo) == 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("param [pszDeviceNo] invalid");
- return Error_Param;
- }
- if (dwCardBoxNum <= 0)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("param [dwCardBoxNum] invalid");
- return Error_Param;
- }
- if (arrCardBoxNo.GetCount() != (dwCardBoxNum+1)
- || arrCardBoxNo.GetCount() != (dwCardBoxNum + 1)
- || arrPsbCode.GetCount() != (dwCardBoxNum + 1)
- || arrPsbName.GetCount() != (dwCardBoxNum + 1)
- || arrCardInit.GetCount() != (dwCardBoxNum + 1)
- || arrCardRemains.GetCount() != (dwCardBoxNum + 1)
- || arrCardIssued.GetCount() != (dwCardBoxNum + 1)
- || arrCardMixed.GetCount() != (dwCardBoxNum + 1)
- || arrCardPercent.GetCount() != (dwCardBoxNum + 1)
- || arrMaintainFlag.GetCount() != (dwCardBoxNum + 1)
- || arrMaintainer.GetCount() != (dwCardBoxNum + 1)
- || arrMaintainTime.GetCount() != (dwCardBoxNum + 1))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("element count of array param invalid");
- return Error_Param;
- }
- // invoke material branch service
- ErrorCodeEnum rc = Error_Succeed;
- CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
- rc = pCnn->SyncMaterialCount(pszDeviceNo, dwCardBoxNum, arrMaintainFlag, arrMaintainer, arrMaintainTime,
- arrCardBoxNo, arrPsbCode, arrPsbName, arrCardInit, arrCardRemains, arrCardIssued, arrCardMixed, arrCardPercent);
- if(pCnn->IsConnectionOK())
- pCnn->Close();
- pCnn->DecRefCount();
- pCnn = NULL;
- if (rc == Error_Succeed)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("计数同步成功");
- else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("计数同步失败:%s", SpStrError(rc));
- return rc;
- }
- void CGUIConsoleEntity::InitializeBeidou()
- {
- CSmartPointer<IConfigInfo> pConfig;
- CSimpleString t_endpoint, t_topicSys, t_topicUser, t_topicBeidou, t_bussSys, t_bussUser;
- bool readSender = false;
- if (GetFunction()->OpenConfig(Config_CenterSetting, pConfig) == Error_Succeed
- && Error_Succeed == pConfig->ReadConfigValue("Common", "SendEndpoint", t_endpoint)
- && Error_Succeed == pConfig->ReadConfigValue("Common", "SendSys", t_topicSys)
- && Error_Succeed == pConfig->ReadConfigValue("Common", "SendUser", t_topicUser)
- && Error_Succeed == pConfig->ReadConfigValue("Common", "SendBeidou", t_topicBeidou)
- && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessSys", t_bussSys)
- && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessUser", t_bussUser)
- && 0 != t_topicSys.GetLength()
- && 0 != t_topicUser.GetLength()
- && 0 != t_topicBeidou.GetLength()
- && 0 != t_bussSys.GetLength()
- && 0 != t_bussUser.GetLength()) {
- CSimpleStringA dbgInfo = CSimpleStringA::Format("\"endpoint\":\"%s\", \"topicSys\":\"%s\", \"topicUser\":\"%s\", \"topicBeidou\":\"%s\", \"bussSys\":\"%s\", \"bussUser\":\"%s\"",
- t_endpoint.GetData(), t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData());
- if (0 != t_endpoint.GetLength()) {
- GetFunction()->GetPrivilegeFunction()->BeginLogSend(t_endpoint.GetData(), t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData());
- LogWarn(Severity_Low, Error_Debug, EVENT_MOD_GUICONSOLE_ENABLE_UNIONNETLOG_WITH_VALICONFIG,
- dbgInfo);
- } else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint is empty, do not begin send log");
- LogWarn(Severity_Low, Error_Debug, EVENT_MOD_GUICONSOLE_DISABLE_UNIONNETLOG_BCZ_LACK, dbgInfo);
- }
- } else {
- const char* default_endpoint = "https://kafkaproxy.paas.cmbchina.cn/api/kafka/log/send";
- const char* topicSys = "LR18_23_VTMTerminalLogService_L_sys_VTMTerminalSysLog_SRC_SZ";
- const char* topicUser = "LR18_23_VTMTerminalLogService_L_biz_VTMTerminalUserLog_SRC_SZ";
- const char* topicBeidou = "LR18_23_VTMTerminalLogService_L_trace_VTMTerminalTraceLog_SRC_SZ";
- const char* topicBussSys = "LR18_23_VTMTerminalLogService_L_sys_VTMBusiness_SRC_SZ";
- const char* topicBussUser = "LR18_23_VTMTerminalLogService_L_biz_VTMBusiness_SRC_SZ";
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read endpoint and topic err, need check centersetting, use default %s-%s-%s-%s-%s-%s",
- default_endpoint, topicSys, topicUser, topicBeidou, topicBussSys, topicBussUser);
- GetFunction()->GetPrivilegeFunction()->BeginLogSend(default_endpoint, topicSys, topicUser, topicBeidou, topicBussSys, topicBussUser);
- CSimpleStringA dbgInfo = CSimpleStringA::Format("\"endpoint\":\"%s\", \"topicSys\":\"%s\", \"topicUser\":\"%s\", \"topicBeidou\":\"%s\", \"bussSys\":\"%s\", \"bussUser\":\"%s\"",
- default_endpoint, topicSys, topicUser, topicBeidou, topicBussSys, topicBussUser);
- LogWarn(Severity_Low, Error_Debug, EVENT_MOD_GUICONSOLE_ENABLE_UNIONNETLOG_WITH_DEFAULTCONFIG, dbgInfo);
- }
- }
- void CGUIConsoleEntity::OnTimeout(DWORD dwTimerID)
- {
- static long oldFileSize = -1;
- const long maxFileSize = 10000000; //10MB
- const char* defaultDBStoragePath = "/opt/rvc/terminaldbstorage/RVC.LogSdk/RvcLogSdk.db";
- if (dwTimerID == ENT_TIMERID_CHECK_LOGDB_SIZE) {
- if (ExistsFileA(defaultDBStoragePath)) {
- struct stat statbuf;
- if (stat(defaultDBStoragePath, &statbuf) < 0) {
- int err = errno;
- LogWarn(Severity_Low, Error_Resource, EVENT_MOD_GUICONSOLE_UNIONNETLOG_LOCAL_STORAGE_SIZE,
- CSimpleStringA::Format("failed to stat %s: %s", defaultDBStoragePath, strerror(err)));
- } else {
- if (oldFileSize != statbuf.st_size) {
- if (statbuf.st_size >= maxFileSize) {
- LogWarn(Severity_Low, Error_Resource, EVENT_MOD_GUICONSOLE_UNIONNETLOG_LOCAL_STORAGE_SIZE,
- CSimpleStringA::Format("db file changed from: %d to %ld", oldFileSize, statbuf.st_size));
- }
- oldFileSize = statbuf.st_size;
- }
- }
- } else {
- LogWarn(Severity_Low, Error_Resource, EVENT_MOD_GUICONSOLE_UNIONNETLOG_LOCAL_STORAGE_SIZE,
- CSimpleStringA::Format("%s does not exist!", defaultDBStoragePath));
- }
- }
- }
- void CGUIConsoleSession::Handle_GetCurrentMaintainer(SpReqAnsContext<GUIConsoleService_GetCurrentMaintainer_Req, GUIConsoleService_GetCurrentMaintainer_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->GetCurrentMaintainer(ctx->Ans.strUserID, ctx->Ans.strUserName, ctx->Ans.strCurRight, ctx->Ans.strAuthorizer, ctx->Ans.dwBeginTime);
- ctx->Answer(rc);
- }
- void CGUIConsoleSession::Handle_Empower(SpReqAnsContext<GUIConsoleService_Empower_Req, GUIConsoleService_Empower_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->Empower(ctx->Req.strUserID);
- ctx->Answer(rc);
- }
- void CGUIConsoleSession::Handle_Takeover(SpReqAnsContext<GUIConsoleService_Takeover_Req, GUIConsoleService_Takeover_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->Takeover(ctx->Req.strUserID);
- ctx->Answer(rc);
- }
- void CGUIConsoleSession::Handle_ForceQuit(SpReqAnsContext<GUIConsoleService_ForceQuit_Req, GUIConsoleService_ForceQuit_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->ForceQuit();
- ctx->Answer(rc);
- }
- void CGUIConsoleSession::Handle_AddMaterialCounter(SpReqAnsContext<GUIConsoleService_AddMaterialCounter_Req, GUIConsoleService_AddMaterialCounter_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->AddMaterialCounter(ctx->Req.strMaterialCode);
- ctx->Answer(rc);
- }
- void CGUIConsoleSession::Handle_AddTradeManage(SpReqAnsContext<GUIConsoleService_AddTradeManage_Req, GUIConsoleService_AddTradeManage_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->AddTradeManage(ctx->Req.terminalNo, ctx->Req.AgentID, ctx->Req.time);
- ctx->Answer(rc);
- }
- //查询物料信息
- void CGUIConsoleSession::Handle_QueryMaterialInfo(SpReqAnsContext<GUIConsoleService_QueryMaterialInfo_Req, GUIConsoleService_QueryMaterialInfo_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->QueryMaterialInfo(ctx->Req.strDeviceNo, ctx->Ans.count, ctx->Ans.arrDeviceNo, ctx->Ans.arrMateriel, ctx->Ans.CardGroove, ctx->Ans.CardBoxNo, ctx->Ans.PsbCode,
- ctx->Ans.PsbName, ctx->Ans.CardInit, ctx->Ans.CardRemains, ctx->Ans.CardIssued, ctx->Ans.CardMixed, ctx->Ans.CardPercent, ctx->Ans.TerminalNo, ctx->Ans.Maintainer,
- ctx->Ans.MaintainTime, ctx->Ans.UpdateTime);
- ctx->Answer(rc);
- }
- void CGUIConsoleSession::Handle_GetMaterialCounter(SpReqAnsContext<GUIConsoleService_GetMaterialCounter_Req, GUIConsoleService_GetMaterialCounter_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->GetMaterialCounter(ctx->Req.strMaterialCode, ctx->Ans.dwLastCapacity, ctx->Ans.dwUsedCounter);
- ctx->Answer(rc);
- }
- void CGUIConsoleSession::Handle_ResetMaterialCounter(SpReqAnsContext<GUIConsoleService_ResetMaterialCounter_Req, GUIConsoleService_ResetMaterialCounter_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->ResetMaterialCounter(ctx->Req.strMaterialCode, ctx->Req.dwResetCapacity, ctx->Req.dwUsedCounter, ctx->Req.dwRemainCounter, ctx->Req.strComment);
- ctx->Answer(rc);
- }
- void CGUIConsoleSession::Handle_RegistSwallowedCard(SpReqAnsContext<GUIConsoleService_RegistSwallowedCard_Req, GUIConsoleService_RegistSwallowedCard_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->RegistSwallowedCard(ctx->Req.strCardNo, ctx->Req.strReasonCode, ctx->Req.strSwallowDate, ctx->Req.strSwallowTime, ctx->Req.strDeviceSciNo);
- ctx->Answer(rc);
- }
- void CGUIConsoleSession::Handle_SyncMaterialCount(SpOnewayCallContext<GUIConsoleService_SyncMaterialCount_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->SyncMaterialCount(ctx->Info.strDeviceNo, ctx->Info.dwCardBoxNum, ctx->Info.arrMaintainFlag,
- ctx->Info.arrMaintainer, ctx->Info.arrMaintainTime, ctx->Info.arrCardBoxNo, ctx->Info.arrPsbCode,
- ctx->Info.arrPsbName, ctx->Info.arrCardInit, ctx->Info.arrCardRemains, ctx->Info.arrCardIssued,
- ctx->Info.arrCardMixed, ctx->Info.arrCardPercent);
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CGUIConsoleEntity)
- SP_END_ENTITY_MAP()
|