فهرست منبع

#IQBX #comment 调通健康实体通过微服务获取终端信息

gifur 3 سال پیش
والد
کامیت
77351cf4ad

+ 88 - 0
Module/include/microservices/api_manage_regist.h

@@ -0,0 +1,88 @@
+#ifndef MICROSERVICES_API_MANAGE_REGIST_HEADER_
+#define MICROSERVICES_API_MANAGE_REGIST_HEADER_
+
+#include <string>
+
+namespace MicroServices
+{
+
+namespace API
+{
+
+struct CommResponse
+{
+    bool success;
+    std::string errorCode;
+    std::string returnCode;
+    std::string errorMsg;
+    std::string message;
+};
+
+namespace Manage
+{
+//http://rvcterminal.paasst.cmbchina.cn/api/manage/regist/7555980103
+/*
+    "data": {
+        "branchNo": "755",
+        "businessStructID": "1BFEB05100000000",
+        "businessStructInfo": {
+            "bActive": true,
+            "bDisplay": true,
+            "branchNo": "755598",
+            "commonName": "ShenZhenFenHangYingYeBu",
+            "description": null,
+            "editor": null,
+            "expTime": null,
+            "globalName": "CMB.ShenZhenFenHang.ShenZhenFenHangYingYeBu",
+            "nLayer": 3,
+            "nodeType": "B",
+            "parentId": "17A2113A0000000A",
+            "structFullName": "招商银行/深圳分行/深圳分行营业部",
+            "structId": "1BFEB05100000000",
+            "structName": "深圳分行营业部",
+            "structType": "102",
+            "topStruct": false
+        },
+        "deviceNo": "D06255",
+        "grooveCount": 1,
+        "initIP": "99.12.22.197",
+        "line": "RVC_Branch_MarketingDeviceManage",
+        "lineDes": "市场条线",
+        "machineNo": "2021092215115721",
+        "machineType": "RVC.Stand2S",
+        "machineVersion": "5.0",
+        "outletNo": "755598",
+        "padDeviceId": "cw_00000000",
+        "pinPadId": "cw_1902BB2104258467",
+        "remark": "1",
+        "sites": "CMB.LIB",
+        "state": "1",
+        "stateName": "正常",
+        "structID": "1BFEB05100000000",
+        "structInfo": null,
+        "terminalNo": "7555980103",
+        "workFlowState": null
+    }
+*/
+
+
+struct RegistInfo
+{
+    std::string branchNo;
+    std::string deviceNo;
+    std::string initIP;
+    std::string machineNo;
+    std::string machineType;
+    std::string machineVersion;
+    std::string sites;
+    std::string terminalNo;
+};
+}
+
+}
+
+}
+
+
+
+#endif //MICROSERVICES_API_MANAGE_REGIST_HEADER_

+ 8 - 1
Module/mod_healthmanager/CMakeLists.txt

@@ -34,6 +34,13 @@ target_include_directories(${MODULE_NAME} PRIVATE
 	${MODULE_BASE_DIR}/mod_CameraConfigManage #for header file
 	${MODULE_BASE_DIR}/mod_chromium
 	${MODULE_BASE_DIR}/mod_ResourceWatcher
+	${RVC_OTHER_DEPENDENIES_DIR}/libRestfulFunc
+	${MODULE_MICRO_SERVICES_INCLUDE_DIR}
+	${CONAN_INCLUDE_DIRS_JSONCPP}
+)
+
+target_link_directories(${MODULE_NAME} PRIVATE
+	${CONAN_LIB_DIRS_JSONCPP}
 )
 
 # 添加实体需要依赖的其他共享库(包括系统库)
@@ -41,7 +48,7 @@ set(${MODULE_PREFIX}_SYSLIBS libpublicFun)
 if(MSVC)
 	list(APPEND ${MODULE_PREFIX}_SYSLIBS Ws2_32)
 endif(MSVC)
-set(${MODULE_PREFIX}_LIBS)
+set(${MODULE_PREFIX}_LIBS RestfulFunc ${CONAN_PKG_LIBS_JSONCPP})
 target_link_libraries(${MODULE_NAME} ${MODULE_BASE_LIBS} ${${MODULE_PREFIX}_LIBS} ${${MODULE_PREFIX}_SYSLIBS})
 
 

+ 151 - 87
Module/mod_healthmanager/mod_healthmanager.cpp

@@ -30,6 +30,10 @@
 #include "osutil.h"
 
 #include "EntityBootStruct.h"
+#include "RestfulFunc.h"
+
+#include "api_manage_regist.h"
+#include "JsonConvertHelper.hpp"
 
 using namespace std;
 
@@ -2745,104 +2749,164 @@ void CHealthManagerEntity::DeployTerminal(SpReqAnsContext<HealthManagerService_D
 				Dbg("vendor: %s, model:%s, sn: %s", strVendorName.GetData(), strDeviceModel.GetData(), strDeviceSN.GetData());
 			}
 
-            /** 1050 是固定的服务端实体端口 [Gifur@20211013]*/
-            const bool ret = pCnn->ConnectServer(serverIP.GetData(), 1050);
-            Dbg("Connect finished: %d", ret);
-            if (pCnn->IsConnectionOK()) {
-                Dbg("Connect OK!");
-                TerminalRegistRet info;
-                result = pCnn->GetTerminalInfo(terminalNo.GetData(), &info);
-                pCnn->Close();
-                PrintTerminalRegistInfo(&info);
-                if (strlen(info.TerminalNo) == 0) {
-                    tmpResult = Error_NotExist;
-                    tmpMsg = "查询终端信息不存在,请检测输入的终端号是否正确";
-                } else if (terminalNo.Compare(info.TerminalNo) != 0) {
-                    tmpResult = Error_MisMatched;
-                    tmpMsg = CSimpleStringA::Format("查询返回的终端信息不匹配,输入:%s,返回:%s", terminalNo.GetData(), info.TerminalNo);
+			bool toRecord = false;
+			if (ctx->Req.param1 == 0) { //走分行服务
+                            /** 1050 是固定的服务端实体端口 [Gifur@20211013]*/
+                const bool ret = pCnn->ConnectServer(serverIP.GetData(), 1050);
+                Dbg("Connect finished: %d", ret);
+                if (pCnn->IsConnectionOK()) {
+                    Dbg("Connect OK!");
+                    TerminalRegistRet info;
+                    result = pCnn->GetTerminalInfo(terminalNo.GetData(), &info);
+                    pCnn->Close();
+                    PrintTerminalRegistInfo(&info);
+                    if (strlen(info.TerminalNo) == 0) {
+                        tmpResult = Error_NotExist;
+                        tmpMsg = "查询终端信息不存在,请检测输入的终端号是否正确";
+                    } else if (terminalNo.Compare(info.TerminalNo) != 0) {
+                        tmpResult = Error_MisMatched;
+                        tmpMsg = CSimpleStringA::Format("查询返回的终端信息不匹配,输入:%s,返回:%s", terminalNo.GetData(), info.TerminalNo);
+                    } else {
+						toRecord = true;
+                    }
+
                 } else {
-                    ErrorCodeEnum ec(Error_Succeed);
-                    do {
-                        Dbg("record to cache...");
-                        CSmartPointer<IConfigInfo> pConfig;
-						GetFunction()->OpenConfig(Config_Cache, pConfig);
-                        const ErrorCodeEnum ec0 = pConfig->WriteConfigValue("TerminalDeploy", "TerminalNo", terminalNo);
-                        const ErrorCodeEnum ec1 = pConfig->WriteConfigValue("TerminalDeploy", "Manufacturer", vendorType);
-                        const ErrorCodeEnum ec2 = pConfig->WriteConfigValue("TerminalDeploy", "ServerIP", serverIP);
-                        Dbg("record step: %s, %s, %s", SpStrError(ec0), SpStrError(ec1), SpStrError(ec2));
-                    } while (false);
-
-                    do {
-                        CSimpleStringA strRootCfgPath;
-                        CSimpleStringA strRootTmpFile;
-                        CSimpleStringA strRootIniFullPath;
-                        CSimpleStringA strRootChosenFile(true);
-						CSimpleStringA strNousedPath;
-
-                        ec = GetTmpRootFilePath(strRootIniFullPath, strRootTmpFile, strNousedPath);
-						///**TODO(Gifur@10/16/2021): ASSERT 在这个步骤root.ini 文件不应该出现的,可能是字段的缺失才识别为未配置模式 */
-                        if (ExistsFileA(strRootIniFullPath)) {
-                            fileutil_copy_file(strNousedPath, strRootIniFullPath);
-                            fileutil_delete_file(strRootIniFullPath);
-                            Dbg("root.ini exists!"); 
+                    Dbg("Connect Failed!");
+                    result = Error_ConnectFailed;
+                }
+                pCnn->DecRefCount();
+                pCnn = NULL;
+
+			} else if (ctx->Req.param1 == 1) { //走总行服务
+
+				HttpClientRequestConfig config(serverIP.GetData());
+				HttpClientResponseResult result;
+				config.SetChildUri(CSimpleStringA("/terminal/api/manage/regist/").Append(terminalNo).GetData());
+				RestfulClient client = RestfulClient::getInstance();
+				client.Do(config, result);
+				if (result.statusCode == HttpStatusCode::OK) {
+
+                    struct RegistInfoJson : public MicroServices::API::Manage::RegistInfo {
+                        JSONCONVERT2OBJECT_MEMEBER_REGISTER(branchNo, deviceNo, initIP, machineNo, machineType, machineVersion, sites, terminalNo)
+                    } terminalRegistInfo;
+
+					Json::Value rawRoot;
+                    if (GetJsonRootObject(rawRoot, result.content) && Json2Object(terminalRegistInfo, rawRoot["data"])) {
+
+						auto printFunc = [&terminalRegistInfo]() {
+                            Dbg("TerminalNo: %s", terminalRegistInfo.terminalNo.c_str());
+                            Dbg("BranchNo: %s", terminalRegistInfo.branchNo.c_str());
+                            Dbg("DeviceNo: %s", terminalRegistInfo.deviceNo.c_str());
+                            Dbg("IP: %s", terminalRegistInfo.initIP.c_str());
+                            Dbg("MachineNo: %s", terminalRegistInfo.machineNo.c_str());
+                            Dbg("MachineType: %s", terminalRegistInfo.machineType.c_str());
+                            Dbg("MachineVersion: %s", terminalRegistInfo.machineVersion.c_str());
+                            Dbg("Sites: %s", terminalRegistInfo.sites.c_str());
+						};
+						printFunc();
+                        if (terminalRegistInfo.terminalNo.empty()) {
+                            tmpResult = Error_NotExist;
+                            tmpMsg = "查询终端信息不存在,请检测输入的终端号是否正确";
+                        } else if (terminalRegistInfo.terminalNo != terminalNo.GetData()) {
+                            tmpResult = Error_MisMatched;
+                            tmpMsg = CSimpleStringA::Format("查询返回的终端信息不匹配,输入:%s,返回:%s", terminalNo.GetData(), terminalRegistInfo.terminalNo);
+                        } else {
+                            toRecord = true;
                         }
+					} else {
+                        tmpResult = Error_DataCheck;
+                        tmpMsg = CSimpleStringA::Format("解析返回内容失败:%s", result.content.c_str());
+					}
+					
+				} else {
+					tmpResult = Error_ServerNotAvailable;
+					if (result.content.size() > 0) {
+                        tmpMsg = CSimpleStringA::Format("访问 %s 失败:%d %s", config.GetRequestUri().c_str(), result.statusCode, result.content.c_str());
+					} else {
+                        tmpMsg = CSimpleStringA::Format("访问 %s 失败:%d", config.GetRequestUri().c_str(), result.statusCode);
+					}
+				}
+			}
+
+			if (toRecord) {
+
+                ErrorCodeEnum ec(Error_Succeed);
+                do {
+                    Dbg("record to cache...");
+                    CSmartPointer<IConfigInfo> pConfig;
+                    GetFunction()->OpenConfig(Config_Cache, pConfig);
+                    const ErrorCodeEnum ec0 = pConfig->WriteConfigValue("TerminalDeploy", "TerminalNo", terminalNo);
+                    const ErrorCodeEnum ec1 = pConfig->WriteConfigValue("TerminalDeploy", "Manufacturer", vendorType);
+                    const ErrorCodeEnum ec2 = pConfig->WriteConfigValue("TerminalDeploy", "ServerIP", serverIP);
+                    Dbg("record step: %s, %s, %s", SpStrError(ec0), SpStrError(ec1), SpStrError(ec2));
+                } while (false);
+
+                do {
+                    CSimpleStringA strRootCfgPath;
+                    CSimpleStringA strRootTmpFile;
+                    CSimpleStringA strRootIniFullPath;
+                    CSimpleStringA strRootChosenFile(true);
+                    CSimpleStringA strNousedPath;
+
+                    ec = GetTmpRootFilePath(strRootIniFullPath, strRootTmpFile, strNousedPath);
+                    ///**TODO(Gifur@10/16/2021): ASSERT 在这个步骤root.ini 文件不应该出现的,可能是字段的缺失才识别为未配置模式 */
+                    if (ExistsFileA(strRootIniFullPath)) {
+                        fileutil_copy_file(strNousedPath, strRootIniFullPath);
+                        fileutil_delete_file(strRootIniFullPath);
+                        Dbg("root.ini exists!");
+                    }
 
-                        ec = GetFunction()->GetPath("HardwareCfg", strRootCfgPath);
-                        array_header_t* subs = fileutil_get_sub_files_a(strRootCfgPath);
-                        if (subs) {
-                            regex_t reg;
-                            CSimpleStringA machineType("Stand2S");
-                            CSimpleStringA rootPattern("root");
-                            CSimpleStringA pattern = rootPattern + "\\-" + machineType + "\\-" + vendorType + "\\-[a-zA-Z0-9_\\(\\)\\-]*" + ".ini";
-                            int ret = regcomp(&reg, pattern, REG_EXTENDED | REG_NOSUB);
-                            if (ret) {
-                                char ebuff[256];
-                                regerror(ret, &reg, ebuff, 256);
-                                Dbg("regex failed: %s", ebuff);
-                                tmpResult = Error_Unexpect;
-                                tmpMsg = CSimpleStringA::Format("内部错误:REGEX %s", ebuff);
-                                toolkit_array_free2(subs);
+                    ec = GetFunction()->GetPath("HardwareCfg", strRootCfgPath);
+                    array_header_t* subs = fileutil_get_sub_files_a(strRootCfgPath);
+                    if (subs) {
+                        regex_t reg;
+                        CSimpleStringA machineType("Stand2S");
+                        CSimpleStringA rootPattern("root");
+                        CSimpleStringA pattern = rootPattern + "\\-" + machineType + "\\-" + vendorType + "\\-[a-zA-Z0-9_\\(\\)\\-]*" + ".ini";
+                        int ret = regcomp(&reg, pattern, REG_EXTENDED | REG_NOSUB);
+                        if (ret) {
+                            char ebuff[256];
+                            regerror(ret, &reg, ebuff, 256);
+                            Dbg("regex failed: %s", ebuff);
+                            tmpResult = Error_Unexpect;
+                            tmpMsg = CSimpleStringA::Format("内部错误:REGEX %s", ebuff);
+                            toolkit_array_free2(subs);
+                            break;
+                        }
+                        Dbg("pattern: %s", pattern.GetData());
+                        for (int i = 0; i < subs->nelts; ++i) {
+                            char* filenamePath = ARRAY_IDX(subs, i, char*);
+                            char* filename = &filenamePath[strRootCfgPath.GetLength() + 1];
+                            Dbg("filename: %s", filename);
+                            ret = regexec(&reg, filename, 0, NULL, 0);
+                            if (0 == ret) {
+                                Dbg("matched!");
+                                strRootChosenFile = filenamePath;
                                 break;
                             }
-                            Dbg("pattern: %s", pattern.GetData());
-                            for (int i = 0; i < subs->nelts; ++i) {
-                                char* filenamePath = ARRAY_IDX(subs, i, char*);
-                                char* filename = &filenamePath[strRootCfgPath.GetLength() + 1];
-                                Dbg("filename: %s", filename);
-                                ret = regexec(&reg, filename, 0, NULL, 0);
-                                if (0 == ret) {
-                                    Dbg("matched!");
-                                    strRootChosenFile = filenamePath;
-                                    break;
-                                }
-                                Dbg("not matched.");
-                            }
-                            toolkit_array_free2(subs);
+                            Dbg("not matched.");
                         }
+                        toolkit_array_free2(subs);
+                    }
 
-                        if (!strRootChosenFile.IsNullOrEmpty()) {
-                            fileutil_copy_file(strRootTmpFile, strRootChosenFile);
-                            inifile_write_str(strRootTmpFile, "Terminal", "TerminalNo", terminalNo);
-                            //inifile_write_str(strRootTmpFile, "Terminal", "Manufacturer", vendorType);
-							if (!strDeviceSN.IsNullOrEmpty()) {
-								inifile_write_str(strRootTmpFile, "Terminal", "SN", strDeviceSN);
-							}
-                        } else {
-                            tmpMsg = "找不到对应的备选配置,请确认选择的机型和设备厂商是否正确";
-                            tmpResult = Error_InvalidState;
+                    if (!strRootChosenFile.IsNullOrEmpty()) {
+                        fileutil_copy_file(strRootTmpFile, strRootChosenFile);
+                        inifile_write_str(strRootTmpFile, "Terminal", "TerminalNo", terminalNo);
+                        //inifile_write_str(strRootTmpFile, "Terminal", "Manufacturer", vendorType);
+                        if (!strDeviceSN.IsNullOrEmpty()) {
+                            inifile_write_str(strRootTmpFile, "Terminal", "SN", strDeviceSN);
                         }
+                    } else {
+                        tmpMsg = "找不到对应的备选配置,请确认选择的机型和设备厂商是否正确";
+                        tmpResult = Error_InvalidState;
+                    }
 
-                    } while (false);
+                } while (false);
 
-                    ctx->Ans.param2 = serverIP;
-                }
+                ctx->Ans.param2 = serverIP;
+			
+			}
 
-            } else {
-                Dbg("Connect Failed!");
-                result = Error_ConnectFailed;
-            }
-            pCnn->DecRefCount();
-            pCnn = NULL;
 		} else if(ctx->Req.options == 1){
 			//从缓存文件中获取,避免出现依赖
             CSimpleStringA terminalNo;

+ 10 - 0
Other/libRestfulFunc/JsonConvertHelper.hpp

@@ -264,6 +264,16 @@ bool Json2Object(TClass& aimObj, const std::string& jsonTypeStr)
     }
     return Json2Object(aimObj, root);
 }
+
+static bool GetJsonRootObject(Json::Value& root, const std::string& jsonTypeStr)
+{
+    Json::Reader reader;
+    if (!reader.parse(jsonTypeStr, root)) {
+        return false;
+    }
+    return true;
+}
+
 ////////////////////////////////////////////////////////////////////////
 
 template <typename TClass, typename enable_if<HasConverFunction<TClass>::has, int>::type = 0>

+ 2 - 0
Other/libRestfulFunc/RestfulFunc.h

@@ -93,6 +93,8 @@ struct HttpClientRequestConfig
     std::string GetBaseUri() const { return mUri; }
     std::string GetSubUri() const { return mSubUri; }
 
+    std::string GetRequestUri() const { return mUri + mSubUri; }
+
     HttpRequestMethod GetType() const { return mMethod; }
 
 private:

+ 3 - 1
Other/libpublicFun/test/CMakeLists.txt

@@ -7,7 +7,9 @@ file(GLOB ${MODULE_PREFIX}_TESTS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
 foreach(test ${${MODULE_PREFIX}_TESTS})
 	get_filename_component(test_name ${test} NAME_WE)
 	add_executable(${test_name} ${test})
-	target_include_directories(${test_name} PRIVATE ${CONAN_INCLUDE_DIRS_CATCH} ${OTHER_LIB_BASE_DIR}/libpublicFun)
+	target_include_directories(${test_name} PRIVATE 
+		${CONAN_INCLUDE_DIRS_CATCH} ${OTHER_LIB_BASE_DIR}/libpublicFun
+		${ThirdPartyHeadRoot}/CJson)
 	target_link_libraries(${test_name} PRIVATE libpublicFun)
 	set_property(TARGET ${test_name} PROPERTY FOLDER "test/other")
 	set_target_properties(${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")

+ 2 - 0
addin/cmake/ModMakeSettings.cmake

@@ -4,6 +4,8 @@ set(MODULE_BASE_DIR "${PROJECT_SOURCE_DIR}/Module")
 
 SET(ModuleCommonHeadPath "${MODULE_BASE_DIR}/include")
 
+SET(MODULE_MICRO_SERVICES_INCLUDE_DIR "${ModuleCommonHeadPath}/microservices")
+
 set(OTHER_LIB_BASE_DIR "${PROJECT_SOURCE_DIR}/Other")
 
 set(Tool_BASE_DIR "${PROJECT_SOURCE_DIR}/Tool")