mod_guiconsole.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. #include "stdafx2.h"
  2. #include "mod_GuiConsole.h"
  3. #include "guitask.h"
  4. #include "EventCode.h"
  5. #include "MaterialMgrCnn.h"
  6. #include "GUIConsoleUserCodeDef.h"
  7. #include "CardIssuer_client_g.h"
  8. using namespace CardIssuer;
  9. #include "MaintainWatcher_client_g.h"
  10. using namespace MaintainWatcher;
  11. #include "fileutil.h"
  12. void CGUIConsoleEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  13. {
  14. m_FSM.Init(this);
  15. auto rc = SubscribeEntitysEvents();
  16. if (rc != Error_Succeed)
  17. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("subscribe MaintainWatcher event fail, %s", SpStrError(rc));
  18. else
  19. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("subscribe MaintainWatcher event succeed");
  20. bool toInitializeSysLog(true);
  21. CSmartPointer<IConfigInfo> pConfig;
  22. if (GetFunction()->OpenConfig(Config_Software, pConfig) == Error_Succeed) {
  23. CSimpleStringA strValue(true);
  24. pConfig->ReadConfigValue("Common", "SwitchLogService", strValue);
  25. if (strValue.Compare("OFF") == 0) {
  26. toInitializeSysLog = false;
  27. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Do not initialize SysLog!!!!");
  28. }
  29. }
  30. if (toInitializeSysLog) {
  31. InitializeBeidou();
  32. } else {
  33. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_GUICONSOLE_DISABLE_UNIONNETLOG_BCZ_CFG, "do not enable union log!");
  34. }
  35. pTransactionContext->SendAnswer(Error_Succeed) ;
  36. }
  37. void CGUIConsoleEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  38. {
  39. m_FSM.PostExitEvent();
  40. UnsubscribeEntitysEvents();
  41. pTransactionContext->SendAnswer(Error_Succeed);
  42. }
  43. CServerSessionBase *CGUIConsoleEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszParam*/)
  44. {
  45. return new CGUIConsoleSession(this);
  46. }
  47. void CGUIConsoleEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  48. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  49. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo)
  50. {
  51. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnLog(entity = %s, syscode = 0x%X, usercode = 0x%X", pszEntityName, dwSysError, dwUserCode);
  52. if (dwUserCode == EVENT_MACHINE_COVER_OPEN) // 机盖打开
  53. {
  54. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the machine cover open!!");
  55. m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_CoverOpen));
  56. }
  57. else if (dwUserCode == EVENT_MACHINE_COVER_CLOSE) // 机盖关闭
  58. {
  59. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the machine cover close.");
  60. m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_CoverClose));
  61. }
  62. else if (dwUserCode == EVENT_UKEY_INSERTED) // 证书插入
  63. {
  64. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the key inserted");
  65. m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_UKeyInserted));
  66. }
  67. else if ((dwUserCode == EVENT_UKEY_LOW_LEVEL) // 具有维护权
  68. || (dwUserCode == EVENT_UKEY_HIGH_LEVEL)) // 具有高级权限)
  69. {
  70. bool bLowLevel = dwUserCode == EVENT_UKEY_LOW_LEVEL;
  71. if (bLowLevel)
  72. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("lower priviledge");
  73. else
  74. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("higher priviledge");
  75. // 调用UKey接口取维护人员信息
  76. m_strUserID = "";
  77. m_strUserName = "";
  78. m_strAuthorizer = "";
  79. m_strAuthTime = "";
  80. MaintainCertificate_ClientBase *pClient = new MaintainCertificate_ClientBase(this);
  81. auto rc = pClient->Connect();
  82. if (rc != Error_Succeed)
  83. {
  84. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("connect to MaintainWatcher entity fail: %d", rc);
  85. pClient->SafeDelete();
  86. }
  87. else
  88. {
  89. MaintainCertificate_GetUserInfo_Req req = {};
  90. MaintainCertificate_GetUserInfo_Ans ans = {};
  91. rc = pClient->GetUserInfo(req, ans, 10000);
  92. if (rc != Error_Succeed)
  93. {
  94. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get userinfo fail from MaintainWatcher: %s", SpStrError(rc));
  95. }
  96. else
  97. {
  98. // UserID=SP00000004;UserName=RVC0001;AuthorierID=SP00000001;AuthorizeTime=2014/8/13 18:46:29;RecommenderSAP=80274390;RecommenderOfficeID=274390;
  99. CSimpleStringA &str = ans.UserInfo;
  100. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get maintainer info: %s", (const char*)str);
  101. auto arr = str.Split(';');
  102. for (int i = 0; i < arr.GetCount(); i++)
  103. {
  104. auto arr2 = arr[i].Split('=');
  105. if (arr2.GetCount() != 2)
  106. continue;
  107. if (arr2[0] == "UserID")
  108. m_strUserID = arr2[1];
  109. else if (arr2[0] == "UserName")
  110. m_strUserName = arr2[1];
  111. else if (arr2[0] == "AuthorierID")
  112. m_strAuthorizer = arr2[1];
  113. else if (arr2[0] == "AuthorizeTime")
  114. m_strAuthTime = arr2[1];
  115. }
  116. }
  117. pClient->GetFunction()->CloseSession();
  118. }
  119. pClient = NULL;
  120. m_strCurRight = bLowLevel ? "Low" : "High";
  121. m_dwBeginTime = CSmallDateTime::GetNow();
  122. auto pEvent = new FSMEvent(CGUIConsoleFSM::Event_CertVerified);
  123. pEvent->param1 = bLowLevel ? 1 : 2;
  124. m_FSM.PostEventFIFO(pEvent);
  125. }
  126. else if (dwUserCode == EVENT_UKEY_PULLOUT) // 证书拔出
  127. {
  128. m_strUserID = "";
  129. m_strUserName = "";
  130. m_strAuthorizer = "";
  131. m_strAuthTime = "";
  132. m_strCurRight = "";
  133. m_dwBeginTime = 0;
  134. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("certificate key pull out");
  135. m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_UKeyPulled));
  136. }
  137. else if (dwUserCode == LOG_EVT_HEALTH_FIRST_ENTER_MAINPADE)
  138. {
  139. // IE首页打开, 关闭运行输出
  140. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("IE main page has been loaded successfully, close console terminal!");
  141. GetFunction()->GetPrivilegeFunction()->CloseOuputConsole();
  142. }
  143. }
  144. ErrorCodeEnum CGUIConsoleEntity::SubscribeEntitysEvents()
  145. {
  146. auto pFunc = GetFunction();
  147. auto rc = pFunc->SubscribeLog(m_SubLogID1, this, Log_Event, Severity_None, Error_IgnoreAll, -1, "MaintainWatcher");
  148. rc = pFunc->SubscribeLog(m_SubLogID2, this, Log_Event, Severity_None, Error_IgnoreAll, -1, "Gpio");
  149. // 业务首页加载事件
  150. rc = pFunc->SubscribeLog(m_SubLogID3, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HEALTH_FIRST_ENTER_MAINPADE, "HealthManager");
  151. return rc;
  152. }
  153. ErrorCodeEnum CGUIConsoleEntity::UnsubscribeEntitysEvents()
  154. {
  155. auto pFunc = GetFunction();
  156. if ((__int64)m_SubLogID1 != 0)
  157. pFunc->UnsubscribeLog(m_SubLogID1);
  158. if ((__int64)m_SubLogID2 != 0)
  159. pFunc->UnsubscribeLog(m_SubLogID2);
  160. if ((__int64)m_SubLogID3 != 0)
  161. pFunc->UnsubscribeLog(m_SubLogID3);
  162. return Error_Succeed;
  163. }
  164. ErrorCodeEnum CGUIConsoleEntity::GetCurrentMaintainer(CSimpleStringA &strUserID, CSimpleStringA &strUserName, CSimpleStringA &strCurRight,
  165. CSimpleStringA &strAuthorizer, unsigned int &dwBeginTime)
  166. {
  167. strUserID = m_strUserID;
  168. strUserName = m_strUserName;
  169. strCurRight = m_strCurRight;
  170. strAuthorizer = m_strAuthorizer;
  171. dwBeginTime = m_dwBeginTime;
  172. return Error_Succeed;
  173. }
  174. ErrorCodeEnum CGUIConsoleEntity::Empower(const char *pszUserID)
  175. {
  176. if (m_strUserID.IsNullOrEmpty() || m_strUserID.Compare(pszUserID) != 0)
  177. return Error_NoPrivilege;
  178. m_strCurRight = "High";
  179. m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_HighLevel));
  180. return Error_Succeed;
  181. }
  182. ErrorCodeEnum CGUIConsoleEntity::Takeover(const char *pszUserID)
  183. {
  184. if (m_strUserID.IsNullOrEmpty() || m_strUserID.Compare(pszUserID) != 0)
  185. return Error_NoPrivilege;
  186. m_strCurRight = "Low";
  187. m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_Takeover));
  188. return Error_Succeed;
  189. }
  190. ErrorCodeEnum CGUIConsoleEntity::ForceQuit()
  191. {
  192. m_strUserID = "";
  193. m_strUserName = "";
  194. m_strAuthorizer = "";
  195. m_strAuthTime = "";
  196. m_strCurRight = "";
  197. m_dwBeginTime = 0;
  198. m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_ForceQuit));
  199. return Error_Succeed;
  200. }
  201. ErrorCodeEnum CGUIConsoleEntity::PostUserLoginEvent(const char *pszUserID)
  202. {
  203. m_strUserID = pszUserID;
  204. m_strUserName = pszUserID;
  205. m_strAuthorizer = "";
  206. m_strAuthTime = "";
  207. m_strCurRight = "Low";
  208. m_dwBeginTime = CSmallDateTime::GetNow();
  209. m_FSM.PostEventFIFO(new FSMEvent(CGUIConsoleFSM::Event_CoverOpen));
  210. auto pEvent = new FSMEvent(CGUIConsoleFSM::Event_CertVerified);
  211. pEvent->param1 = 1;
  212. m_FSM.PostEventFIFO(pEvent);
  213. return Error_Succeed;
  214. }
  215. ErrorCodeEnum CGUIConsoleEntity::AddTradeManage(const char *pszTerminalNo, const char *pszAgentID, const char *pszTime)
  216. {
  217. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AddTradeManage: %s, %s, %s", pszTerminalNo, pszAgentID, pszTime);
  218. ErrorCodeEnum rc = Error_Succeed;
  219. CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
  220. if (pCnn->ConnectFromCentralSetting() && pCnn->IsConnectionOK())
  221. {
  222. rc = pCnn->AddTradeManage(pszTerminalNo, pszAgentID, pszTime);
  223. pCnn->Close();
  224. }
  225. else
  226. {
  227. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("连接物料服务失败");
  228. rc = Error_NetBroken;
  229. }
  230. pCnn->DecRefCount();
  231. pCnn = NULL;
  232. if (Error_Succeed != rc)
  233. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("mod AddTradeManage return : %s", SpStrError(rc));
  234. return rc;
  235. }
  236. ErrorCodeEnum CGUIConsoleEntity::AddMaterialCounter(const char *pszMaterialCode)
  237. {
  238. // 递增后台计数
  239. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AddMaterialCounter: %s", pszMaterialCode);
  240. CSystemStaticInfo sysInfo;
  241. auto rc = GetFunction()->GetSystemStaticInfo(sysInfo);
  242. assert(rc == Error_Succeed);
  243. CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
  244. if (pCnn->ConnectFromCentralSetting() && pCnn->IsConnectionOK())
  245. {
  246. rc = pCnn->AddMaterialCounter(sysInfo.strTerminalID, pszMaterialCode);
  247. pCnn->Close();
  248. }
  249. else
  250. {
  251. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Connect to MaterialMgrEntity failed!");
  252. rc = Error_NetBroken;
  253. }
  254. pCnn->DecRefCount();
  255. pCnn = NULL;
  256. if (rc == Error_Succeed)
  257. {
  258. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Add material counter for %s succ.", pszMaterialCode);
  259. }
  260. else
  261. {
  262. LogError(Severity_Middle, rc, 0, CSimpleStringA::Format("add material counter failed: %s", SpStrError(rc)));
  263. }
  264. return rc;
  265. }
  266. //查询物料信息
  267. ErrorCodeEnum CGUIConsoleEntity::QueryMaterialInfo(const char *pszDeviceNo, unsigned int &count, CAutoArray<CSimpleStringA> &arrDeviceNo, CAutoArray<CSimpleStringA> &arrMateriel,
  268. CAutoArray<CSimpleStringA> &CardGroove, CAutoArray<CSimpleStringA> &CardBoxNo, CAutoArray<CSimpleStringA> &PsbCode, CAutoArray<CSimpleStringA> &PsbName,
  269. CAutoArray<unsigned int> &CardInit, CAutoArray<unsigned int> &CardRemains, CAutoArray<unsigned int> &CardIssued, CAutoArray<unsigned int> &CardMixed,
  270. CAutoArray<unsigned int> &CardPercent, CAutoArray<CSimpleStringA> &TerminalNo, CAutoArray<CSimpleStringA> &Maintainer, CAutoArray<CSimpleStringA> &MaintainTime,
  271. CAutoArray<CSimpleStringA> &UpdateTime)
  272. {
  273. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("QueryMaterialInfo DeviceNo = %s", pszDeviceNo);
  274. ErrorCodeEnum rc = Error_Succeed;
  275. CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
  276. CSystemStaticInfo sysInfo;
  277. rc = GetFunction()->GetSystemStaticInfo(sysInfo);
  278. assert(rc == Error_Succeed);
  279. rc = pCnn->QueryMaterialInfo(pszDeviceNo, count, arrDeviceNo, arrMateriel, CardGroove, CardBoxNo, PsbCode, PsbName, CardInit, CardRemains, CardIssued, CardMixed,
  280. CardPercent, TerminalNo, Maintainer, MaintainTime, UpdateTime);
  281. if(pCnn->IsConnectionOK())
  282. pCnn->Close();
  283. pCnn->DecRefCount();
  284. pCnn = NULL;
  285. return rc;
  286. }
  287. ErrorCodeEnum CGUIConsoleEntity::GetMaterialCounter(const char *pszMaterial, unsigned int &dwLastCapacity, unsigned int &dwUsedCounter)
  288. {
  289. ErrorCodeEnum rc = Error_Succeed;
  290. CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
  291. if (pCnn->ConnectFromCentralSetting() && pCnn->IsConnectionOK())
  292. {
  293. CSystemStaticInfo sysInfo;
  294. auto rc = GetFunction()->GetSystemStaticInfo(sysInfo);
  295. assert(rc == Error_Succeed);
  296. GetMaterialCounterRet ret = {};
  297. rc = pCnn->GetMaterialCounter(pszMaterial, (const char*)sysInfo.strTerminalID, (const char*)GetCurMaintainer(),
  298. dwLastCapacity, dwUsedCounter);
  299. pCnn->Close();
  300. }
  301. else
  302. {
  303. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Connect to MaterialMgrEntity failed!");
  304. rc = Error_NetBroken;
  305. }
  306. pCnn->DecRefCount();
  307. pCnn = NULL;
  308. return rc;
  309. }
  310. ErrorCodeEnum CGUIConsoleEntity::ResetMaterialCounter(const char *pszMaterial, unsigned int dwResetCapacity,
  311. unsigned int dwUsedCounter, unsigned int dwRemainCounter, const char *pszComment)
  312. {
  313. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ResetMaterialCounter: %s, reset: %d", pszMaterial, dwResetCapacity);
  314. // 重置硬件计数
  315. ErrorCodeEnum rc = Error_Succeed;
  316. CSimpleStringA strMaterialCode = pszMaterial;
  317. if (strMaterialCode == "DebitCard" || strMaterialCode == "RetainCard")
  318. {
  319. CardIssuerService_ClientBase *pClient = new CardIssuerService_ClientBase(this);
  320. rc = pClient->Connect();
  321. if (rc == Error_Succeed)
  322. {
  323. CardIssuerService_SetMaterialCount_Req req = {};
  324. if (strMaterialCode == "DebitCard")
  325. {
  326. req.bRemains = true;
  327. req.remains = dwResetCapacity;
  328. req.bIssued = true;
  329. req.issued = 0;
  330. req.bMixed = true;
  331. req.mixed = 0;
  332. req.bCaptured = false;
  333. }
  334. else if (strMaterialCode == "RetainCard")
  335. {
  336. req.bCaptured = true;
  337. req.captured = 0;
  338. req.bRemains = false;
  339. req.bIssued = false;
  340. req.bMixed = false;
  341. }
  342. CardIssuerService_SetMaterialCount_Ans ret = {};
  343. rc = pClient->SetMaterialCount(req, ret, 10000);
  344. pClient->GetFunction()->CloseSession();
  345. }
  346. else
  347. {
  348. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("连接CardIssuer失败");
  349. pClient->SafeDelete();
  350. }
  351. }
  352. else
  353. {
  354. rc = Error_NoTarget;
  355. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Unknow material code: {%s}", (const char*)strMaterialCode);
  356. }
  357. if (rc != Error_Succeed)
  358. {
  359. LogError(Severity_Middle, rc, 0, CSimpleStringA::Format("Reset teminal material counter failed: %s", SpStrError(rc)));
  360. return rc;
  361. }
  362. // 重置后台计数
  363. CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
  364. if (pCnn->ConnectFromCentralSetting() && pCnn->IsConnectionOK())
  365. {
  366. CSystemStaticInfo sysInfo;
  367. rc = GetFunction()->GetSystemStaticInfo(sysInfo);
  368. assert(rc == Error_Succeed);
  369. rc = pCnn->ResetMaterialCounter(strMaterialCode, sysInfo.strTerminalID, GetCurMaintainer(),
  370. dwResetCapacity, dwUsedCounter, dwRemainCounter, pszComment);
  371. pCnn->Close();
  372. }
  373. else {
  374. rc = Error_NetBroken;
  375. }
  376. pCnn->DecRefCount();
  377. pCnn = NULL;
  378. if (rc == Error_Succeed)
  379. {
  380. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Reset teminal material counter succ: %s", (const char*)strMaterialCode);
  381. }
  382. else
  383. {
  384. LogError(Severity_Middle, rc, 0, CSimpleStringA::Format("Reset teminal material counter from server failed:%s", SpStrError(rc)));
  385. }
  386. return rc;
  387. }
  388. ErrorCodeEnum CGUIConsoleEntity::RegistSwallowedCard(const char *pszCardNo, const char *pszReasonCode,
  389. const char *pszDate, const char *pszTime, const char *pszDeviceSciNo)
  390. {
  391. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RegistSwallowedCard card = %s, reson = %s", pszCardNo, pszReasonCode);
  392. // 20170210: 空卡或无卡号吞卡也要登记
  393. //if (pszCardNo == NULL || strlen(pszCardNo) == 0)
  394. // return Error_Param;
  395. // invoke material branch service
  396. ErrorCodeEnum rc = Error_Break;
  397. CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
  398. if (pCnn->ConnectFromCentralSetting() && pCnn->IsConnectionOK())
  399. {
  400. CSystemStaticInfo sysInfo;
  401. rc = GetFunction()->GetSystemStaticInfo(sysInfo);
  402. assert(rc == Error_Succeed);
  403. rc = pCnn->RegistSwallowedCard(sysInfo.strMachineType, sysInfo.strTerminalID, pszCardNo, pszReasonCode, pszDate, pszTime, pszDeviceSciNo);
  404. pCnn->Close();
  405. }
  406. else {
  407. rc = Error_NetBroken;
  408. }
  409. pCnn->DecRefCount();
  410. pCnn = NULL;
  411. char tempCardNo[MAX_PATH] = "";
  412. int cardNoLen = strlen(pszCardNo);
  413. if (cardNoLen > 8)
  414. {
  415. for (int i = 0; i < 4; i++)
  416. *(tempCardNo + i) = *(pszCardNo + i);
  417. for (int i = 4; i < cardNoLen - 4; i++)
  418. *(tempCardNo + i) = '*';
  419. for (int i = cardNoLen - 4; i < cardNoLen; i++)
  420. *(tempCardNo + i) = *(pszCardNo + i);
  421. *(tempCardNo + cardNoLen) = '\0';
  422. }
  423. else
  424. strcpy(tempCardNo, pszCardNo);
  425. if (rc == Error_Succeed)
  426. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Register swallow card succ,cardno: %s, reason: %s", tempCardNo, pszReasonCode);
  427. else
  428. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Register swallow card failed(%s),cardno: %s, reason: %s", SpStrError(rc), tempCardNo, pszReasonCode);
  429. return rc;
  430. }
  431. ErrorCodeEnum CGUIConsoleEntity::SyncMaterialCount(const char *pszDeviceNo, DWORD dwCardBoxNum,
  432. CAutoArray<bool> &arrMaintainFlag, CAutoArray<CSimpleStringA> &arrMaintainer, CAutoArray<unsigned int> &arrMaintainTime,
  433. CAutoArray<CSimpleStringA> &arrCardBoxNo, CAutoArray<CSimpleStringA> &arrPsbCode,
  434. CAutoArray<CSimpleStringA> &arrPsbName, CAutoArray<unsigned int> &arrCardInit, CAutoArray<unsigned int> &arrCardRemains,
  435. CAutoArray<unsigned int> &arrCardIssued, CAutoArray<unsigned int> &arrCardMixed, CAutoArray<unsigned int> &arrCardPercent)
  436. {
  437. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SyncMaterialCount DeviceNo = %s, CardBoxNum = %d", pszDeviceNo, dwCardBoxNum);
  438. if (pszDeviceNo == NULL || strlen(pszDeviceNo) == 0)
  439. {
  440. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("param [pszDeviceNo] invalid");
  441. return Error_Param;
  442. }
  443. if (dwCardBoxNum <= 0)
  444. {
  445. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("param [dwCardBoxNum] invalid");
  446. return Error_Param;
  447. }
  448. if (arrCardBoxNo.GetCount() != (dwCardBoxNum+1)
  449. || arrCardBoxNo.GetCount() != (dwCardBoxNum + 1)
  450. || arrPsbCode.GetCount() != (dwCardBoxNum + 1)
  451. || arrPsbName.GetCount() != (dwCardBoxNum + 1)
  452. || arrCardInit.GetCount() != (dwCardBoxNum + 1)
  453. || arrCardRemains.GetCount() != (dwCardBoxNum + 1)
  454. || arrCardIssued.GetCount() != (dwCardBoxNum + 1)
  455. || arrCardMixed.GetCount() != (dwCardBoxNum + 1)
  456. || arrCardPercent.GetCount() != (dwCardBoxNum + 1)
  457. || arrMaintainFlag.GetCount() != (dwCardBoxNum + 1)
  458. || arrMaintainer.GetCount() != (dwCardBoxNum + 1)
  459. || arrMaintainTime.GetCount() != (dwCardBoxNum + 1))
  460. {
  461. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("element count of array param invalid");
  462. return Error_Param;
  463. }
  464. // invoke material branch service
  465. ErrorCodeEnum rc = Error_Succeed;
  466. CMaterialMgrCnn *pCnn = new CMaterialMgrCnn(this);
  467. rc = pCnn->SyncMaterialCount(pszDeviceNo, dwCardBoxNum, arrMaintainFlag, arrMaintainer, arrMaintainTime,
  468. arrCardBoxNo, arrPsbCode, arrPsbName, arrCardInit, arrCardRemains, arrCardIssued, arrCardMixed, arrCardPercent);
  469. if(pCnn->IsConnectionOK())
  470. pCnn->Close();
  471. pCnn->DecRefCount();
  472. pCnn = NULL;
  473. if (rc == Error_Succeed)
  474. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("计数同步成功");
  475. else
  476. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("计数同步失败:%s", SpStrError(rc));
  477. return rc;
  478. }
  479. void CGUIConsoleEntity::InitializeBeidou()
  480. {
  481. CSmartPointer<IConfigInfo> pConfig;
  482. CSimpleString t_endpoint, t_topicSys, t_topicUser, t_topicBeidou, t_bussSys, t_bussUser;
  483. bool readSender = false;
  484. if (GetFunction()->OpenConfig(Config_CenterSetting, pConfig) == Error_Succeed
  485. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendEndpoint", t_endpoint)
  486. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendSys", t_topicSys)
  487. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendUser", t_topicUser)
  488. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendBeidou", t_topicBeidou)
  489. && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessSys", t_bussSys)
  490. && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessUser", t_bussUser)
  491. && 0 != t_topicSys.GetLength()
  492. && 0 != t_topicUser.GetLength()
  493. && 0 != t_topicBeidou.GetLength()
  494. && 0 != t_bussSys.GetLength()
  495. && 0 != t_bussUser.GetLength()) {
  496. CSimpleStringA dbgInfo = CSimpleStringA::Format("\"endpoint\":\"%s\", \"topicSys\":\"%s\", \"topicUser\":\"%s\", \"topicBeidou\":\"%s\", \"bussSys\":\"%s\", \"bussUser\":\"%s\"",
  497. t_endpoint.GetData(), t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData());
  498. if (0 != t_endpoint.GetLength()) {
  499. GetFunction()->GetPrivilegeFunction()->BeginLogSend(t_endpoint.GetData(), t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData());
  500. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_GUICONSOLE_ENABLE_UNIONNETLOG_WITH_VALICONFIG,
  501. dbgInfo);
  502. } else {
  503. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint is empty, do not begin send log");
  504. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_GUICONSOLE_DISABLE_UNIONNETLOG_BCZ_LACK, dbgInfo);
  505. }
  506. } else {
  507. const char* default_endpoint = "https://kafkaproxy.paas.cmbchina.cn/api/kafka/log/send";
  508. const char* topicSys = "LR18_23_VTMTerminalLogService_L_sys_VTMTerminalSysLog_SRC_SZ";
  509. const char* topicUser = "LR18_23_VTMTerminalLogService_L_biz_VTMTerminalUserLog_SRC_SZ";
  510. const char* topicBeidou = "LR18_23_VTMTerminalLogService_L_trace_VTMTerminalTraceLog_SRC_SZ";
  511. const char* topicBussSys = "LR18_23_VTMTerminalLogService_L_sys_VTMBusiness_SRC_SZ";
  512. const char* topicBussUser = "LR18_23_VTMTerminalLogService_L_biz_VTMBusiness_SRC_SZ";
  513. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read endpoint and topic err, need check centersetting, use default %s-%s-%s-%s-%s-%s",
  514. default_endpoint, topicSys, topicUser, topicBeidou, topicBussSys, topicBussUser);
  515. GetFunction()->GetPrivilegeFunction()->BeginLogSend(default_endpoint, topicSys, topicUser, topicBeidou, topicBussSys, topicBussUser);
  516. CSimpleStringA dbgInfo = CSimpleStringA::Format("\"endpoint\":\"%s\", \"topicSys\":\"%s\", \"topicUser\":\"%s\", \"topicBeidou\":\"%s\", \"bussSys\":\"%s\", \"bussUser\":\"%s\"",
  517. default_endpoint, topicSys, topicUser, topicBeidou, topicBussSys, topicBussUser);
  518. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_GUICONSOLE_ENABLE_UNIONNETLOG_WITH_DEFAULTCONFIG, dbgInfo);
  519. }
  520. }
  521. void CGUIConsoleEntity::OnTimeout(DWORD dwTimerID)
  522. {
  523. static long oldFileSize = -1;
  524. const long maxFileSize = 10000000; //10MB
  525. const char* defaultDBStoragePath = "/opt/rvc/terminaldbstorage/RVC.LogSdk/RvcLogSdk.db";
  526. if (dwTimerID == ENT_TIMERID_CHECK_LOGDB_SIZE) {
  527. if (ExistsFileA(defaultDBStoragePath)) {
  528. struct stat statbuf;
  529. if (stat(defaultDBStoragePath, &statbuf) < 0) {
  530. int err = errno;
  531. LogWarn(Severity_Low, Error_Resource, EVENT_MOD_GUICONSOLE_UNIONNETLOG_LOCAL_STORAGE_SIZE,
  532. CSimpleStringA::Format("failed to stat %s: %s", defaultDBStoragePath, strerror(err)));
  533. } else {
  534. if (oldFileSize != statbuf.st_size) {
  535. if (statbuf.st_size >= maxFileSize) {
  536. LogWarn(Severity_Low, Error_Resource, EVENT_MOD_GUICONSOLE_UNIONNETLOG_LOCAL_STORAGE_SIZE,
  537. CSimpleStringA::Format("db file changed from: %d to %ld", oldFileSize, statbuf.st_size));
  538. }
  539. oldFileSize = statbuf.st_size;
  540. }
  541. }
  542. } else {
  543. LogWarn(Severity_Low, Error_Resource, EVENT_MOD_GUICONSOLE_UNIONNETLOG_LOCAL_STORAGE_SIZE,
  544. CSimpleStringA::Format("%s does not exist!", defaultDBStoragePath));
  545. }
  546. }
  547. }
  548. void CGUIConsoleSession::Handle_GetCurrentMaintainer(SpReqAnsContext<GUIConsoleService_GetCurrentMaintainer_Req, GUIConsoleService_GetCurrentMaintainer_Ans>::Pointer ctx)
  549. {
  550. auto rc = m_pEntity->GetCurrentMaintainer(ctx->Ans.strUserID, ctx->Ans.strUserName, ctx->Ans.strCurRight, ctx->Ans.strAuthorizer, ctx->Ans.dwBeginTime);
  551. ctx->Answer(rc);
  552. }
  553. void CGUIConsoleSession::Handle_Empower(SpReqAnsContext<GUIConsoleService_Empower_Req, GUIConsoleService_Empower_Ans>::Pointer ctx)
  554. {
  555. auto rc = m_pEntity->Empower(ctx->Req.strUserID);
  556. ctx->Answer(rc);
  557. }
  558. void CGUIConsoleSession::Handle_Takeover(SpReqAnsContext<GUIConsoleService_Takeover_Req, GUIConsoleService_Takeover_Ans>::Pointer ctx)
  559. {
  560. auto rc = m_pEntity->Takeover(ctx->Req.strUserID);
  561. ctx->Answer(rc);
  562. }
  563. void CGUIConsoleSession::Handle_ForceQuit(SpReqAnsContext<GUIConsoleService_ForceQuit_Req, GUIConsoleService_ForceQuit_Ans>::Pointer ctx)
  564. {
  565. auto rc = m_pEntity->ForceQuit();
  566. ctx->Answer(rc);
  567. }
  568. void CGUIConsoleSession::Handle_AddMaterialCounter(SpReqAnsContext<GUIConsoleService_AddMaterialCounter_Req, GUIConsoleService_AddMaterialCounter_Ans>::Pointer ctx)
  569. {
  570. auto rc = m_pEntity->AddMaterialCounter(ctx->Req.strMaterialCode);
  571. ctx->Answer(rc);
  572. }
  573. void CGUIConsoleSession::Handle_AddTradeManage(SpReqAnsContext<GUIConsoleService_AddTradeManage_Req, GUIConsoleService_AddTradeManage_Ans>::Pointer ctx)
  574. {
  575. auto rc = m_pEntity->AddTradeManage(ctx->Req.terminalNo, ctx->Req.AgentID, ctx->Req.time);
  576. ctx->Answer(rc);
  577. }
  578. //查询物料信息
  579. void CGUIConsoleSession::Handle_QueryMaterialInfo(SpReqAnsContext<GUIConsoleService_QueryMaterialInfo_Req, GUIConsoleService_QueryMaterialInfo_Ans>::Pointer ctx)
  580. {
  581. 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,
  582. ctx->Ans.PsbName, ctx->Ans.CardInit, ctx->Ans.CardRemains, ctx->Ans.CardIssued, ctx->Ans.CardMixed, ctx->Ans.CardPercent, ctx->Ans.TerminalNo, ctx->Ans.Maintainer,
  583. ctx->Ans.MaintainTime, ctx->Ans.UpdateTime);
  584. ctx->Answer(rc);
  585. }
  586. void CGUIConsoleSession::Handle_GetMaterialCounter(SpReqAnsContext<GUIConsoleService_GetMaterialCounter_Req, GUIConsoleService_GetMaterialCounter_Ans>::Pointer ctx)
  587. {
  588. auto rc = m_pEntity->GetMaterialCounter(ctx->Req.strMaterialCode, ctx->Ans.dwLastCapacity, ctx->Ans.dwUsedCounter);
  589. ctx->Answer(rc);
  590. }
  591. void CGUIConsoleSession::Handle_ResetMaterialCounter(SpReqAnsContext<GUIConsoleService_ResetMaterialCounter_Req, GUIConsoleService_ResetMaterialCounter_Ans>::Pointer ctx)
  592. {
  593. auto rc = m_pEntity->ResetMaterialCounter(ctx->Req.strMaterialCode, ctx->Req.dwResetCapacity, ctx->Req.dwUsedCounter, ctx->Req.dwRemainCounter, ctx->Req.strComment);
  594. ctx->Answer(rc);
  595. }
  596. void CGUIConsoleSession::Handle_RegistSwallowedCard(SpReqAnsContext<GUIConsoleService_RegistSwallowedCard_Req, GUIConsoleService_RegistSwallowedCard_Ans>::Pointer ctx)
  597. {
  598. auto rc = m_pEntity->RegistSwallowedCard(ctx->Req.strCardNo, ctx->Req.strReasonCode, ctx->Req.strSwallowDate, ctx->Req.strSwallowTime, ctx->Req.strDeviceSciNo);
  599. ctx->Answer(rc);
  600. }
  601. void CGUIConsoleSession::Handle_SyncMaterialCount(SpOnewayCallContext<GUIConsoleService_SyncMaterialCount_Info>::Pointer ctx)
  602. {
  603. LOG_FUNCTION();
  604. m_pEntity->SyncMaterialCount(ctx->Info.strDeviceNo, ctx->Info.dwCardBoxNum, ctx->Info.arrMaintainFlag,
  605. ctx->Info.arrMaintainer, ctx->Info.arrMaintainTime, ctx->Info.arrCardBoxNo, ctx->Info.arrPsbCode,
  606. ctx->Info.arrPsbName, ctx->Info.arrCardInit, ctx->Info.arrCardRemains, ctx->Info.arrCardIssued,
  607. ctx->Info.arrCardMixed, ctx->Info.arrCardPercent);
  608. }
  609. SP_BEGIN_ENTITY_MAP()
  610. SP_ENTITY(CGUIConsoleEntity)
  611. SP_END_ENTITY_MAP()