|
|
@@ -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(®, pattern, REG_EXTENDED | REG_NOSUB);
|
|
|
- if (ret) {
|
|
|
- char ebuff[256];
|
|
|
- regerror(ret, ®, 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(®, pattern, REG_EXTENDED | REG_NOSUB);
|
|
|
+ if (ret) {
|
|
|
+ char ebuff[256];
|
|
|
+ regerror(ret, ®, 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(®, 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(®, 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;
|