Explorar o código

#IQRV #comment [Healthmanager] 从新微服务接口获取终端信息并将不准确信息进行告警提示

gifur %!s(int64=3) %!d(string=hai) anos
pai
achega
fe6bfefad9

+ 3 - 0
Module/include/microservices/api_comm.h

@@ -15,6 +15,9 @@
 #define URLPATH_GRAY_CHECK "/api/gray/way/"
 #define URLPATH_CENTERSETTING_UPDATE_CONFIG "/api/terminal/center/config"
 #define URLPATH_DEVICECONTROL_LOGIN "/api/login/sign/"
+#define URLPATH_REGISTER_FULL_LIST "/terminal/api/manage/regist/full/list"
+
+#define URLPATH_MANUFACTURE_GET_ALL "/terminal/api/v1/manufacture/getAll"
 
 namespace MicroServices
 {

+ 121 - 0
Module/include/microservices/api_manage_list.h

@@ -0,0 +1,121 @@
+#ifndef MICROSERVICES_API_MANAGE_LIST_HEADER_
+#define MICROSERVICES_API_MANAGE_LIST_HEADER_
+
+#include "api_comm.h"
+#include <string>
+
+
+namespace MicroServices
+{
+
+namespace API
+{
+namespace Manage
+{
+/*
+{
+    "request": "http://rvcterminal.paasst.cmbchina.cn/api/manage/regist/full/list?terminalNo=7555980103",
+    "success": true,
+    "errorCode": "10000",
+    "message": "请求成功",
+    "returnCode": "SUC0000",
+    "errorMsg": "请求成功",
+    "total": 1,
+    "page": 1,
+    "pageSize": 20,
+    "data": [
+        {
+            "terminalNo": "7555980103",
+            "branchNo": "755",
+            "machineNo": "2021092215115721",
+            "deviceNo": "D06255",
+            "businessStructID": "1BFEB05100000000",
+            "businessStructInfo": {
+                "commonName": "ShenZhenFenHangYingYeBu",
+                "editor": null,
+                "globalName": "CMB.ShenZhenFenHang.ShenZhenFenHangYingYeBu",
+                "expTime": null,
+                "description": null,
+                "nodeType": "B",
+                "parentId": "17A2113A0000000A",
+                "bDisplay": true,
+                "structId": "1BFEB05100000000",
+                "nLayer": 3,
+                "topStruct": false,
+                "structName": "深圳分行营业部",
+                "structType": "201",
+                "structFullName": "招商银行/深圳分行/深圳分行营业部",
+                "bActive": true,
+                "branchNo": "755598"
+            },
+            "structID": "1BFEB05100000000",
+            "structInfo": null,
+            "initIP": "99.12.22.197",
+            "machineType": "RVC.Stand2S",
+            "machineVersion": "5.0",
+            "sites": "CMB.LIB",
+            "outletNo": "755598",
+            "grooveCount": 1,
+            "line": "RVC_Branch_MarketingDeviceManage",
+            "lineDes": "市场条线",
+            "state": "1",
+            "stateName": "正常",
+            "workFlowState": null,
+            "remark": "1",
+            "pinPadId": "cw_1902BB2104258467",
+            "padDeviceId": "cw_00000000",
+            "oldMachineNo": null,
+            "enrolGPS": "0000000000000000",
+            "enrolAddr": null,
+            "createTime": "2021-09-22 15:11:26.967",
+            "editor": "SP07550003",
+            "editTime": "2021-12-14 17:17:26.203",
+            "initializer": "SP80278003",
+            "terminalStage": "A",
+            "runState": " ",
+            "installChanged": "2022-02-24 10:19:00.0",
+            "lastShakeTime": "2022-02-24 14:51:49.0",
+            "currentIP": "0.0.0.0",
+            "installVersion": "0000000200000000",
+            "deviceID": "26B12F0B00004A5A",
+            "manufactureID": "26B0EA9300004A5A",
+            "manufacturerName": null,
+            "batchNo": "20210415",
+            "enterID": "SP01250002",
+            "enterTime": "2021-09-22 15:11:00.0",
+            "machineManager": null,
+            "result": null,
+            "checkTable": null,
+            "checkTableName": null,
+            "infoState": "1",
+            "infoStateName": "已注册",
+            "deviceTye": "有效型号大机"
+        }
+    ]
+}
+*/
+
+struct RegistDetailInfo
+{
+    std::string branchNo;
+    std::string deviceNo;
+    std::string initIP;
+    std::string machineNo;
+    std::string machineType;
+    std::string machineVersion;
+    std::string sites;
+    std::string terminalNo;
+    std::string manufactureID;
+    std::string manufacturerName;
+    std::string deviceTye;
+};
+
+}
+
+}
+
+}
+
+
+
+#endif //MICROSERVICES_API_MANAGE_LIST_HEADER_

+ 28 - 0
Module/include/microservices/api_manufacture_controller.h

@@ -0,0 +1,28 @@
+#ifndef MICROSERVICES_API_MANUFACTURE_CONTROLLER_HEADER_
+#define MICROSERVICES_API_MANUFACTURE_CONTROLLER_HEADER_
+
+#include "api_comm.h"
+#include <string>
+
+
+namespace MicroServices
+{
+
+namespace API
+{
+namespace Manufacture
+{
+
+struct ManufactureInfo
+{
+    std::string manufacturerId;
+    std::string manufacturerName;
+};
+
+}
+
+}
+
+}
+
+#endif //MICROSERVICES_API_MANUFACTURE_CONTROLLER_HEADER_

+ 9 - 3
Module/mod_healthmanager/HealthManagerFSM.cpp

@@ -2408,7 +2408,8 @@ void CHealthManagerFSM::ToLogWarnTermAboutInfo(BOOL bSuccessFlag)
     CSmartPointer<IConfigInfo> pConfig;
 	GetEntityBase()->GetFunction()->OpenConfig(Config_Cache, pConfig);
     int stepStatus(0), curStep(0), lastRecordTime(0);
-	CSimpleStringA strInstallVersion;
+	CSimpleStringA strInstallVersion(true);
+    CSimpleStringA strAdditonalMsg(true);
     pConfig->ReadConfigValueInt("TerminalDeploy", "CurrStep", curStep);
 
 
@@ -2417,14 +2418,19 @@ void CHealthManagerFSM::ToLogWarnTermAboutInfo(BOOL bSuccessFlag)
         pConfig->ReadConfigValueInt("TerminalDeploy", "CurrState", stepStatus);
         pConfig->ReadConfigValueInt("TerminalDeploy", "TimeStamp", lastRecordTime);
 		pConfig->ReadConfigValue("TerminalDeploy", "InstallVersion", strInstallVersion);
+        pConfig->ReadConfigValue("TerminalDeploy", "LastInfo", strAdditonalMsg);
 
         LogWarn(Severity_High, Error_Debug, LOG_WARN_HEALTH_INSTALL_TIMESTAMP, 
-				CSimpleString::Format("[{\"timeStamp\":\"%s\",\"step\":%d,\"state\":%d, \"version\":\"%s\"}]", 
-									  CSmallDateTime(lastRecordTime).ToTimeString().GetData(), curStep, stepStatus, strInstallVersion.GetData()));
+				CSimpleString::Format("[{\"timeStamp\":\"%s\",\"step\":%d,\"state\":%d, \"version\":\"%s\", \"msg\":\"%s\"}]", 
+									  CSmallDateTime(lastRecordTime).ToTimeString().GetData(), curStep, stepStatus
+									  , strInstallVersion.GetData(), strAdditonalMsg.GetData()));
 
         pConfig->WriteConfigValueInt("TerminalDeploy", "CurrStep", DeployStep_Begin);
         pConfig->WriteConfigValueInt("TerminalDeploy", "CurrState", DEPLOYSTATE_NOTINIT);
         pConfig->WriteConfigValue("TerminalDeploy", "TimeStamp", CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
+		if (!strAdditonalMsg.IsNullOrEmpty()) {
+            pConfig->WriteConfigValue("TerminalDeploy", "LastInfo", NULL);
+		}
     }
 }
 

+ 109 - 20
Module/mod_healthmanager/mod_healthmanager.cpp

@@ -32,7 +32,8 @@
 #include "EntityBootStruct.h"
 #include "RestfulFunc.h"
 
-#include "api_manage_regist.h"
+#include "api_manage_list.h"
+#include "api_manufacture_controller.h"
 #include "JsonConvertHelper.hpp"
 
 using namespace std;
@@ -2655,6 +2656,7 @@ void CHealthManagerEntity::DeployTerminal(SpReqAnsContext<HealthManagerService_D
 					pConfig->WriteConfigValue("TerminalDeploy", "ServerIP", NULL);
 					pConfig->WriteConfigValue("TerminalDeploy", "HeadOfficeMode", NULL);
 					pConfig->WriteConfigValue("TerminalDeploy", "InstallVersion", NULL);
+					pConfig->WriteConfigValue("TerminalDeploy", "LastInfo", NULL);
 				}
 					break;
                 case DeployStep_FetchCenterSettings:
@@ -2761,6 +2763,7 @@ void CHealthManagerEntity::DeployTerminal(SpReqAnsContext<HealthManagerService_D
 
 			bool toRecord(false);
 			bool fHeadOfficeMode(false);
+			CSimpleStringA matchInfo(true);
 
 			if (ctx->Req.param1 == 0) { //走分行服务
 				CTerminalInfoQuery* pCnn = new CTerminalInfoQuery(this);
@@ -2794,25 +2797,47 @@ void CHealthManagerEntity::DeployTerminal(SpReqAnsContext<HealthManagerService_D
 				fHeadOfficeMode = true;
 				HttpClientRequestConfig config(serverIP.GetData());
 				HttpClientResponseResult result;
-				config.SetChildUri(CSimpleStringA(URLPATH_TERMINAL_REGISTER_INFO).Append(terminalNo).GetData());
+				config.SetChildUri(URLPATH_REGISTER_FULL_LIST);
+				config.AppendQuery("terminalNo", terminalNo.GetData());
 				RestfulClient client = RestfulClient::getInstance();
 				client.Do(config, result);
-				if (result.statusCode == HttpStatusCode::OK) {
-
+				if (result.ConsiderAsSucc()) {
 					struct CommResponseJson : public MicroServices::API::CommResponse {
                         JSONCONVERT2OBJECT_MEMEBER_REGISTER(success, errorCode, returnCode, errorMsg, message)
 					};
 					CommResponseJson reponseStatus;
 
-                    struct RegistInfoJson : public MicroServices::API::Manage::RegistInfo {
-                        JSONCONVERT2OBJECT_MEMEBER_REGISTER(branchNo, deviceNo, initIP, machineNo, machineType, machineVersion, sites, terminalNo)
+                    struct RegistInfoJson : public MicroServices::API::Manage::RegistDetailInfo {
+                        JSONCONVERT2OBJECT_MEMEBER_REGISTER(branchNo, deviceNo, initIP, machineNo, machineType, machineVersion, sites, terminalNo, manufactureID, manufacturerName, deviceTye)
                     } terminalRegistInfo;
 
 					Json::Value rawRoot;
-                    if (GetJsonRootObject(rawRoot, result.content) 
-						&& Json2Object(reponseStatus, rawRoot) && reponseStatus.IsReqBusinessSucc()
-						&&  Json2Object(terminalRegistInfo, rawRoot["data"])) {
-
+					bool testSucc(false);
+					do 
+					{
+						if (!GetJsonRootObject(rawRoot, result.content)) {
+							Dbg("%d", __LINE__);
+							break;
+						}
+                        if (!Json2Object(reponseStatus, rawRoot)) {
+                            Dbg("%d", __LINE__);
+                            break;
+                        }
+                        if (!reponseStatus.IsReqBusinessSucc()) {
+                            Dbg("%d", __LINE__);
+                            break;
+                        }
+                        if (!(rawRoot["data"].size() > 0)) {
+                            Dbg("%d", __LINE__);
+                            break;
+                        }
+                        if (!Json2Object(terminalRegistInfo, rawRoot["data"][0])) {
+                            Dbg("%d", __LINE__);
+                            break;
+                        }
+						testSucc = true;
+					} while (false);
+                    if (testSucc) {
 						auto printFunc = [&terminalRegistInfo]() {
                             Dbg("TerminalNo: %s", terminalRegistInfo.terminalNo.c_str());
                             Dbg("BranchNo: %s", terminalRegistInfo.branchNo.c_str());
@@ -2822,7 +2847,52 @@ void CHealthManagerEntity::DeployTerminal(SpReqAnsContext<HealthManagerService_D
                             Dbg("MachineType: %s", terminalRegistInfo.machineType.c_str());
                             Dbg("MachineVersion: %s", terminalRegistInfo.machineVersion.c_str());
                             Dbg("Sites: %s", terminalRegistInfo.sites.c_str());
+							Dbg("manufactureID: %s", terminalRegistInfo.manufactureID.c_str());
+							Dbg("manufacturerName: %s", terminalRegistInfo.manufacturerName.c_str());
+							/** Agent: 终端设备型号*/
+							Dbg("deviceTye: %s", terminalRegistInfo.deviceTye.c_str());
 						};
+						
+						printFunc();
+
+						if (!terminalRegistInfo.manufactureID.empty() && terminalRegistInfo.manufacturerName.empty()) {
+                            CommResponseJson reponseStatus2;
+                            HttpClientResponseResult result2;
+                            Json::Value rawRoot2;
+                            config.SetChildUri(URLPATH_MANUFACTURE_GET_ALL);
+                            config.ResetQuery();
+                            client.Do(config, result2);
+							bool fetchManufactureDone(false);
+                            if (result2.ConsiderAsSucc() && GetJsonRootObject(rawRoot2, result2.content)
+                                && Json2Object(reponseStatus2, rawRoot2) && reponseStatus2.IsReqBusinessSucc()) {
+                                struct ManufactureInfoJson : public MicroServices::API::Manufacture::ManufactureInfo {
+                                    JSONCONVERT2OBJECT_MEMEBER_REGISTER(manufacturerId, manufacturerName)
+                                };
+                                struct ManufactureList {
+                                    std::vector<ManufactureInfoJson> data;
+                                    JSONCONVERT2OBJECT_MEMEBER_REGISTER(data)
+                                } manufactureList;
+                                if (Json2Object(manufactureList, rawRoot2)) {
+                                    for (auto it = manufactureList.data.begin(); it != manufactureList.data.end(); ++it) {
+                                        if (it->manufacturerId.compare(terminalRegistInfo.manufactureID) == 0) {
+                                            terminalRegistInfo.manufacturerName = it->manufacturerName;
+                                            Dbg("get manufacturer name: %s", terminalRegistInfo.manufacturerName.c_str());
+											fetchManufactureDone = true;
+                                            break;
+                                        }
+                                    }
+                                }
+                            }
+
+                            if (!fetchManufactureDone) {
+                                if (reponseStatus2.IsPadded() && !reponseStatus2.IsReqBusinessSucc()) {
+                                    Dbg("请求失败:%s", reponseStatus2.WhatError().c_str());
+                                } else {
+                                    Dbg("解析返回内容失败:%s", result2.content.c_str());
+                                }
+                            }
+						}
+
 						printFunc();
 
                         if (terminalRegistInfo.terminalNo.empty()) {
@@ -2834,24 +2904,46 @@ void CHealthManagerEntity::DeployTerminal(SpReqAnsContext<HealthManagerService_D
 															, terminalNo.GetData(), terminalRegistInfo.terminalNo.c_str());
                         } else {
 							bool bMatched(true);
+							
                             if (strTerminalType.Compare(terminalRegistInfo.machineType.c_str()) != 0) {
-                                Dbg("终端类型不匹配!输入为:%s,查询为:%s", strTerminalType.GetData(), terminalRegistInfo.machineType.c_str());
+								if (!matchInfo.IsNullOrEmpty()) { matchInfo += "|"; }
+								matchInfo += CSimpleStringA::Format("终端类型不匹配:[%s]vs[%s]", strTerminalType.GetData(), terminalRegistInfo.machineType.c_str());
                                 bMatched = false;
                             }
+                            if (strVendorName.Compare(terminalRegistInfo.manufacturerName.c_str()) != 0) {
+								if (!matchInfo.IsNullOrEmpty()) { matchInfo += "|"; }
+								matchInfo += CSimpleStringA::Format("设备厂商不匹配:[%s]vs[%s];", strVendorName.GetData(), terminalRegistInfo.manufacturerName.c_str());
+                                bMatched = false;
+                            }
+                            if (strDeviceModel.Compare(terminalRegistInfo.deviceTye.c_str()) != 0) {
+								if (!matchInfo.IsNullOrEmpty()) { matchInfo += "|"; }
+								matchInfo += CSimpleStringA::Format("设备型号不匹配:[%s]vs[%s];", strDeviceModel.GetData(), terminalRegistInfo.deviceTye.c_str());
+                                bMatched = false;
+                            }
+							/** Agent: 设备编号*/
 							if (strDeviceSN.Compare(terminalRegistInfo.machineNo.c_str()) != 0) {
-								Dbg("设备序列号不匹配!输入为:%s,查询为:%s", strDeviceSN.GetData(), terminalRegistInfo.machineNo.c_str());
+								matchInfo += CSimpleStringA::Format("设备序列号不匹配:[%s]vs[%s];", strDeviceSN.GetData(), terminalRegistInfo.machineNo.c_str());
 								bMatched = false;
 							}
 							/** 其他信息的校验和应用 [Gifur@2022123]*/
-                            toRecord = true;
+							if (!bMatched) {
+								//tmpResult = Error_DataCheck;
+								tmpMsg = matchInfo;
+							} else {
+								//toRecord = true;
+							}
+							toRecord = true;
                         }
 					} else {
 						if (reponseStatus.IsPadded() && !reponseStatus.IsReqBusinessSucc()) {
                             tmpResult = Error_DataCheck;
                             tmpMsg = CSimpleStringA::Format("请求失败:%s", reponseStatus.WhatError().c_str());
+                            Dbg(tmpMsg);
 						} else {
                             tmpResult = Error_DataCheck;
                             tmpMsg = CSimpleStringA::Format("解析返回内容失败:%s", result.content.c_str());
+							Dbg(tmpMsg);
+							Dbg("rawRoot[data].size(): %d", rawRoot["data"].size());
 						}
 					}
 				} else {
@@ -2875,7 +2967,9 @@ void CHealthManagerEntity::DeployTerminal(SpReqAnsContext<HealthManagerService_D
                     const ErrorCodeEnum ec1 = pConfig->WriteConfigValue("TerminalDeploy", "Manufacturer", strVendorName);
                     const ErrorCodeEnum ec2 = pConfig->WriteConfigValue("TerminalDeploy", "ServerIP", serverIP);
                     const ErrorCodeEnum ec3 = pConfig->WriteConfigValueInt("TerminalDeploy", "HeadOfficeMode", fHeadOfficeMode ? 1 : 0);
-
+					if (!matchInfo.IsNullOrEmpty()) {
+						pConfig->WriteConfigValue("TerminalDeploy", "LastInfo", matchInfo);
+					}
                     Dbg("record step: %s, %s, %s", SpStrError(ec0), SpStrError(ec1), SpStrError(ec2), SpStrError(ec3));
                 } while (false);
 
@@ -2936,7 +3030,7 @@ void CHealthManagerEntity::DeployTerminal(SpReqAnsContext<HealthManagerService_D
                             inifile_write_str(strRootTmpFile, "Terminal", "SN", strDeviceSN);
                         }
                     } else {
-                        tmpMsg = "找不到对应的备选配置,请确认选择的机型和设备厂商是否正确";
+                        tmpMsg = "harewarecfg下找不到对应的备选配置,请确认选择的机型和设备厂商是否正确";
                         tmpResult = Error_InvalidState;
                     }
 
@@ -3337,11 +3431,6 @@ void CHealthManagerEntity::DeployTerminal(SpReqAnsContext<HealthManagerService_D
         CSmartPointer<IConfigInfo> pConfig;
         GetFunction()->OpenConfig(Config_Cache, pConfig);
 		pConfig->WriteConfigValue("TerminalDeploy", "InstallVersion", info.InstallVersion.ToString());
-        //int nTemp(0);
-        //CSmartPointer<IConfigInfo> pConfig;
-        //GetFunction()->OpenConfig(Config_Cache, pConfig);
-        //pConfig->ReadConfigValueInt("TerminalDeploy", "HeadOfficeMode", nTemp);
-        //SP::Module::Comm::Settings::StoreHeadBranchServicesMode(this, (nTemp > 0));
 
 		Dbg("received finish install cmd!");
 		LogWarn(Severity_High, Error_Debug, LOG_WARN_HEALTH_INSTALL_FINISHED, "install finished");

+ 2 - 1
Other/libRestfulFunc/RestfulFunc.h

@@ -107,6 +107,7 @@ struct HttpClientRequestConfig
     void AppendQuery(const std::string& name, const std::string& value) {
         mQueryPairs[name] = value;
     }
+    void ResetQuery() { mQueryPairs.clear(); }
 
     std::string GetBaseUri() const { return mUri; }
     std::string GetSubUri() const { return mSubUri; }
@@ -134,7 +135,7 @@ struct HttpClientResponseResult
     std::string content;
     /**  子类继承实现 */
     virtual bool ConsiderAsSucc() const {
-        return (statusCode == 200);
+        return (statusCode == HttpStatusCode::OK);
     }
 };