Forráskód Böngészése

!10838 终端本地文件列表上送
Merge pull request !10838 from 80310970/ResFileListUpload_CJL

刘文涛80174520 2 hónapja
szülő
commit
6cb8816ea4

+ 1 - 1
Module/mod_CardIssuerStand/CardIssuerStandFSM.cpp

@@ -2218,7 +2218,7 @@ int CCardIssuerFSM::CaptureCard(SpReqAnsContext<CardIssuerStandService_Capture_R
 	eErr = MachineMoveCardBackNotHold();
 	if (eErr == Error_Succeed)
 	{
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040220305")();
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040220304")();
 		bool bCaptured = ToRegistCaptureCardInfo();
 		m_currCardNo = m_addCardNo = "";
 	}

+ 151 - 1
Module/mod_ResourceWatcher/ResourceWatcherFSM.cpp

@@ -330,6 +330,21 @@ void ResourceWatcherFSM::TriggerProccessUpload()
     }
 }
 
+void ResourceWatcherFSM::TriggerFileListUpload()
+{
+    CSmartPointer<IConfigInfo> spCtSettingConfig;
+    GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
+    //集中配置读取需要上送的路径
+    CSimpleStringA fileListPath("");
+    spCtSettingConfig->ReadConfigValue(m_pEntity->GetEntityName(), "DirPathToUploadFileList", fileListPath);
+    if (!fileListPath.IsNullOrEmpty())
+    {
+        m_fileListPath = fileListPath.Split('|');
+        UploadDirPathFileListTask* uploadFileListTask = new UploadDirPathFileListTask(this);
+        GetEntityBase()->GetFunction()->PostThreadPoolTask(uploadFileListTask);
+    }
+}
+
 ErrorCodeEnum ResourceWatcherFSM::OnInit()
 {
     neverMainPage = true;		//是否未进入过首页
@@ -4890,7 +4905,7 @@ void ResourceWatcherFSM::ConfirmWindowEffectHasBeenOpen()
 }
 #endif // RVC_OS_LINUX
 
-void ResourceWatcherFSM::GetSystemProccess()
+void ResourceWatcherFSM::UploadSystemProccess()
 {
     if(processName.empty())
     {
@@ -4933,4 +4948,139 @@ void ResourceWatcherFSM::GetSystemProccess()
         }
         
     }
+}
+
+void ResourceWatcherFSM::UploadDirPathFileList(CSimpleStringA dirFilePath)
+{
+    CSimpleStringA realPath(true);
+    int res = ExpandDir(dirFilePath, realPath);
+    switch (res)
+    {
+    case -1: //映射无效,使用原数据
+    {
+        realPath = dirFilePath;
+        break;
+    }
+    case -2: //GetPath映射错误,ExpandDir有报错,这里就不报了
+    {
+        return;
+    }
+    default:
+        break;
+    }
+
+    DWORD attrs = GetFileAttributesA(realPath);
+    if (attrs == INVALID_FILE_ATTRIBUTES)
+    {
+        const DWORD lastError = GetLastError();
+        DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5A15")("Acess to path error:[%s], GLE = %u.", realPath.GetData(), lastError);
+        return;
+    }
+    else  if (!(attrs & FILE_ATTRIBUTE_DIRECTORY))
+    { //非文件夹类型
+        DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5A15")("Path [%s]  is not Directory!", realPath.GetData());
+        return;
+    }
+
+    int len = 0;
+    vector<CSimpleStringA> fileList = GetFileListFromDirectory(realPath);
+    if (!fileList.empty())
+    {
+
+        string tPath = realPath.GetData();
+        string jsonPath;
+        for (char c : tPath) { //替换反斜杠
+            if (c == '\\') {
+                jsonPath += '\\';
+                jsonPath += '\\';
+            }
+            else {
+                jsonPath += c;
+            }
+        }
+        CSimpleStringA curListStr = "";
+        CSimpleStringA endStr = ",";
+        CSimpleStringA totalListStr = CSimpleStringA::Format("{\"path\":\"%s\", \"fileList\":[", jsonPath.c_str());
+
+        if (totalListStr.GetLength() > 1000)
+        {
+            DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Dir Path length over 1000!");
+            DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("%s", totalListStr.SubString(0, 1000));
+            return;
+        }
+
+        for (int i = 0; i < fileList.size(); i++)
+        {
+            curListStr = CSimpleStringA("\"") + fileList[i] + "\"";
+            len = totalListStr.GetLength() + curListStr.GetLength();
+            if (len > 1000 || i == (fileList.size() - 1))
+            {
+                endStr = "]}";
+                if (i == (fileList.size() - 1)) //最后一个
+                {
+                    totalListStr = totalListStr + curListStr + endStr;
+                    DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetFileListFromDirectory")(totalListStr.GetData());
+                    break;
+                }
+                else //长度超限
+                {
+                    totalListStr[totalListStr.GetLength() - 1] = ']';
+                    totalListStr = totalListStr + "}";
+                    DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetFileListFromDirectory")(totalListStr.GetData());
+                    totalListStr = CSimpleStringA::Format("{\"path\":\"%s\", \"fileList\":[", jsonPath.c_str()) + curListStr + ","; //超过长度则从当前进程开始重新搭建日志
+                }
+            }
+            else
+            {
+                endStr = ",";
+                totalListStr = totalListStr + curListStr + endStr;
+            }
+        }
+    }
+}
+
+vector<CSimpleStringA> ResourceWatcherFSM::GetFileListFromDirectory(CSimpleStringA path)
+{
+    vector<CSimpleStringA> files;
+#ifdef _WIN32
+    WIN32_FIND_DATAA data;
+    HANDLE hFind;
+
+    CSimpleStringA searchPath = path + "\\*";
+    hFind = FindFirstFileA(searchPath.GetData(), &data);
+    if (hFind != INVALID_HANDLE_VALUE) {
+        do {
+            if (strcmp(data.cFileName, ".") == 0 || strcmp(data.cFileName, "..") == 0)
+                continue;
+            
+            files.push_back(data.cFileName);
+
+            if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { //文件夹类型,只传文件夹名
+                CSimpleStringA fullPath = path + "\\" + data.cFileName;
+                UploadDirPathFileList(fullPath); //上送子文件夹下的文件列表
+            }
+        } while (FindNextFileA(hFind, &data) != 0);
+        FindClose(hFind);
+    }
+#else
+    DIR* dir = opendir(path.GetData());
+    if (!dir) return files;
+
+    struct dirent* entry;
+    while ((entry = readdir(dir)) != nullptr) {
+        if (CSimpleStringA(entry->d_name) == "." || CSimpleStringA(entry->d_name) == "..")
+            continue;
+        
+        files.push_back(entry->d_name);
+
+        CSimpleStringA fullPath = path + "/" + entry->d_name;
+        DWORD attrs = GetFileAttributesA(fullPath);
+        if (attrs & FILE_ATTRIBUTE_DIRECTORY) { //文件夹类型,只传文件夹名
+            UploadDirPathFileList(fullPath); //上送子文件夹下的文件列表
+        }
+    }
+    closedir(dir);
+#endif
+
+    return files;
 }

+ 27 - 4
Module/mod_ResourceWatcher/ResourceWatcherFSM.h

@@ -24,7 +24,6 @@
 #include <sys/types.h>
 #include <dirent.h>
 #include <sys/stat.h>
-#include "CommEntityUtil.hpp"
 #else
 #include <ws2tcpip.h>
 #include <tchar.h>
@@ -238,6 +237,7 @@ public:
 	//进入首页时触发的功能在此
 	void TriggerAtStatusChanged(bool bMStatus);
 	void TriggerProccessUpload();
+	void TriggerFileListUpload();
 
 	void AfterInit();
 
@@ -272,6 +272,7 @@ private:
 
 	int m_diskLastWarnHour;
 	BOOL m_skipDesktopDetect;
+	CAutoArray<CSimpleStringA> m_fileListPath;
 
 #ifdef RVC_OS_WIN
 	vector<CSimpleStringA>m_nonSignedFiles;
@@ -319,11 +320,16 @@ public:
 		ResourceWatcherService_GetBizLinks_Ans>::Pointer ctx);
 
 	bool GetNeverMainPageFlag() { return neverMainPage; } //是否未进过首页
-	void GetSystemProccess();
 	void GetSystemCPUStatus();
 	void GetSystemMemoryStatus();
 	void GetSystemDiskStatus();
 	void GetDiskStatusFrom(LPCTSTR path);
+
+	vector<CSimpleStringA> GetFileListFromDirectory(CSimpleStringA path);
+	void UploadDirPathFileList(CSimpleStringA dirFilePath);
+	CAutoArray<CSimpleStringA> GetUploadPathList() { return m_fileListPath; }
+	void UploadSystemProccess();
+
 	void HardwareInfoTimer(void* pData);
 	void DiskCheckTimer(void* pData);
 
@@ -519,6 +525,9 @@ struct DiskAndFilesTask : public ITaskSp
 			m_pFSM->GetEntityBase()->GetFunction()->SetTimer(TIMER_DISK_CHECK, pListener, checkTime);
 			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Set DISK CHECK Timer!");
 		}
+
+		//清理结束后触发
+		m_pFSM->TriggerFileListUpload();
 	}
 };
 
@@ -539,7 +548,6 @@ struct UploadSysProcInfoTask : public ITaskSp
 	UploadSysProcInfoTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
 	void Process()
 	{
-		CSimpleStringA t_terminalState;
 		DWORD elapsed = 0;
 		DWORD dwStart = SP::Module::Comm::RVCGetTickCount();
 		DWORD dwEnd = SP::Module::Comm::RVCGetTickCount();
@@ -551,6 +559,21 @@ struct UploadSysProcInfoTask : public ITaskSp
 			elapsed = dwEnd - dwStart;
 		}
 		m_pFSM->GetSystemCPUStatus();
-		m_pFSM->GetSystemProccess();
+		m_pFSM->UploadSystemProccess();
+	}
+};
+
+//获取指定路径并将文件列表上送
+struct UploadDirPathFileListTask : public ITaskSp
+{
+	ResourceWatcherFSM* m_pFSM;
+	UploadDirPathFileListTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
+	void Process()
+	{
+		CAutoArray<CSimpleStringA> list = m_pFSM->GetUploadPathList();
+		for (int i = 0; i < list.GetCount(); i++)
+		{
+			m_pFSM->UploadDirPathFileList(list[i]);
+		}
 	}
 };

+ 9 - 1
Module/mod_ResourceWatcher/mod_ResourceWatcher.h

@@ -98,11 +98,15 @@ public:
 		{
 			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Terminal has been lastStage(%s) before ResourceWatcher start.", terminalStage);
 			m_fsm.TriggerProccessUpload();
+			if (!(0 == CSimpleStringA("A").Compare(terminalStage, true))) //非首页,已达终态
+			{
+				m_fsm.TriggerFileListUpload();
+			}
 		}
 		else
 		{
 			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Terminal is starting, regist the teminalStage Event.");
-			spEntityFunction->RegistSysVarEvent("terminalStage", this);
+			spEntityFunction->RegistSysVarEvent("TerminalStage", this);
 		}
 		
 
@@ -247,6 +251,10 @@ public:
 			{
 				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Status changed, teminalStage = %s.", pszValue);
 				m_fsm.TriggerProccessUpload();
+				if (!(0 == CSimpleStringA("A").Compare(pszValue, true))) //非通过准入的情况下,直接开始文件列表获取
+				{
+					m_fsm.TriggerFileListUpload();
+				}
 			}
 		}
 	}

+ 5 - 5
Module/mod_accessauth/AccessAuthFSM.cpp

@@ -1045,7 +1045,7 @@ CSimpleStringA CAccessAuthFSM::GetOsVersion()
 	ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
 	if (eErr != Error_Succeed) {
 		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("GetPath runinfo error=%s.", SpStrError(eErr));
-		errInfo["getLastErr"] = GetLastError();
+		errInfo["getLastErr"] = to_string(GetLastError());
 		errMsg = generateJsonStr(errInfo).second.c_str();
 		return errMsg;
 	}
@@ -1056,7 +1056,7 @@ CSimpleStringA CAccessAuthFSM::GetOsVersion()
 	{
 		DWORD dwErr = GetLastError();
 		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("open runcfg\\osverion file failed. [%d]", dwErr);
-		errInfo["getLastErr"] = dwErr;
+		errInfo["getLastErr"] = to_string(dwErr);
 		errMsg = generateJsonStr(errInfo).second.c_str();
 		return errMsg;
 	}
@@ -1071,7 +1071,7 @@ CSimpleStringA CAccessAuthFSM::GetOsVersion()
 			continue;
 	}
 
-	errInfo["getLastErr"] = GetLastError();
+	errInfo["getLastErr"] = to_string(GetLastError());
 	errMsg = generateJsonStr(errInfo).second.c_str();
 	return errMsg;
 #else
@@ -1107,12 +1107,12 @@ void CAccessAuthFSM::GetIPandMac(CSimpleStringA& ip, CSimpleStringA& mac)
 		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Get sys netinfo failed!. rc=%d.", rc);
 		errInfo["errcode"] = "RTA5216";
 		errInfo["msg"] = "调用系统api获取ip失败";
-		errInfo["getLastErr"] = GetLastError();
+		errInfo["getLastErr"] = to_string(GetLastError());
 		ip = generateJsonStr(errInfo).second.c_str();
 
 		errInfo["errcode"] = "RTA5217";
 		errInfo["msg"] = "调用系统api获取mac地址失败";
-		errInfo["getLastErr"] = GetLastError();
+		errInfo["getLastErr"] = to_string(GetLastError());
 		mac = generateJsonStr(errInfo).second.c_str();
 
 		auto pEntity = (CAccessAuthEntity*)m_pEntity;

+ 9 - 9
Module/mod_accessauth/mod_AccessAuth.cpp

@@ -782,7 +782,7 @@ ErrorCodeEnum CAccessAuthEntity::GetPinPadModel(CSimpleStringA& pinpadModel, boo
 
 		errInfo["errcode"] = "RTA5204";
 		errInfo["msg"] = "PinPad超时未打开";
-		errInfo["getLastErr"] = GetLastError();
+		errInfo["getLastErr"] = to_string(GetLastError());
 		pinpadModel = generateJsonStr(errInfo).second.c_str();
 
 	}
@@ -797,7 +797,7 @@ ErrorCodeEnum CAccessAuthEntity::GetPinPadModel(CSimpleStringA& pinpadModel, boo
 
 		errInfo["errcode"] = "RTA5218";
 		errInfo["msg"] = "PinPad打开失败";
-		errInfo["getLastErr"] = GetLastError();
+		errInfo["getLastErr"] = to_string(GetLastError());
 		pinpadModel = generateJsonStr(errInfo).second.c_str();
 	}
 	else if(rc != Error_Succeed)
@@ -811,7 +811,7 @@ ErrorCodeEnum CAccessAuthEntity::GetPinPadModel(CSimpleStringA& pinpadModel, boo
 
 		errInfo["errcode"] = "RTA5205";
 		errInfo["msg"] = "连接PinPad取数据异常";
-		errInfo["getLastErr"] = GetLastError();
+		errInfo["getLastErr"] = to_string(GetLastError());
 		pinpadModel = generateJsonStr(errInfo).second.c_str();
 	}
 
@@ -1347,7 +1347,7 @@ void CAccessAuthEntity::GetHardWareInfo()
 		{
 			errInfo["errcode"] = "RTA5213";
 			errInfo["msg"] = "调用系统api获取CPU序号失败";
-			errInfo["getLastErr"] = GetLastError();
+			errInfo["getLastErr"] = to_string(GetLastError());
 			m_cpuId = generateJsonStr(errInfo).second.c_str();
 
 			m_iGetTermSysInfo = -1;
@@ -1373,7 +1373,7 @@ void CAccessAuthEntity::GetHardWareInfo()
 		{
 			errInfo["errcode"] = "RTA5214";
 			errInfo["msg"] = "调用系统api获取主板ID号失败";
-			errInfo["getLastErr"] = GetLastError();
+			errInfo["getLastErr"] = to_string(GetLastError());
 			m_mainBoardId = generateJsonStr(errInfo).second.c_str();
 
 			m_iGetTermSysInfo = -1;
@@ -1400,7 +1400,7 @@ void CAccessAuthEntity::GetHardWareInfo()
 		{
 			errInfo["errcode"] = "RTA5215";
 			errInfo["msg"] = "调用系统api获取硬盘ID号失败";
-			errInfo["getLastErr"] = GetLastError();
+			errInfo["getLastErr"] = to_string(GetLastError());
 			m_hardDiskId = generateJsonStr(errInfo).second.c_str();
 
 			m_iGetTermSysInfo = -1;
@@ -1434,7 +1434,7 @@ void CAccessAuthEntity::GetHardWareInfo()
 		{
 			errInfo["errcode"] = "RTA5213";
 			errInfo["msg"] = "调用系统api获取CPU序号失败";
-			errInfo["getLastErr"] = GetLastError();
+			errInfo["getLastErr"] = to_string(GetLastError());
 			m_cpuId = generateJsonStr(errInfo).second.c_str();
 
 			m_iGetTermSysInfo = -1;
@@ -1461,7 +1461,7 @@ void CAccessAuthEntity::GetHardWareInfo()
 		{
 			errInfo["errcode"] = "RTA5214";
 			errInfo["msg"] = "调用系统api获取主板ID号失败";
-			errInfo["getLastErr"] = GetLastError();
+			errInfo["getLastErr"] = to_string(GetLastError());
 			m_mainBoardId = generateJsonStr(errInfo).second.c_str();
 
 			m_iGetTermSysInfo = -1;
@@ -1489,7 +1489,7 @@ void CAccessAuthEntity::GetHardWareInfo()
 		{
 			errInfo["errcode"] = "RTA5215";
 			errInfo["msg"] = "调用系统api获取硬盘ID号失败";
-			errInfo["getLastErr"] = GetLastError();
+			errInfo["getLastErr"] = to_string(GetLastError());
 			m_hardDiskId = generateJsonStr(errInfo).second.c_str();
 
 			m_iGetTermSysInfo = -1;