소스 검색

#IQRV #comment [JS] 安装流程支持厂商信息填充

gifur 2 년 전
부모
커밋
5dc476909d

+ 41 - 24
Module/mod_ResourceWatcher/ResourceWatcherFSM.cpp

@@ -945,7 +945,7 @@ void ResourceWatcherFSM::AfterInit()
         GetEntityBase()->GetFunction()->PostThreadPoolTask(new UploadMonitorInfoTask(this));
     }
     ///**TODO(Gifur@8/10/2023): 联调完成后把它挪到开机时第一次启动时才执行 */
-    CatchSystemBasicInfo();
+    AlarmSystemBasicInfo();
 }
 #else
 int ResourceWatcherFSM::NetProbe() {
@@ -8317,11 +8317,11 @@ int ResourceWatcherFSM::IsWifiConnected()
 
 #endif // _MSC_VER end硬件资源监控相关系统功能 CPU、内存、硬盘、网络wifi
 
-void ResourceWatcherFSM::CatchSystemBasicInfo()
+ErrorCodeEnum ResourceWatcherFSM::CatchSystemBasicInfo(SystemBasicInfo& info)
 {
     CSimpleStringA runCfgPath;
     ErrorCodeEnum errCode = GetEntityBase()->GetFunction()->GetPath("RunCfg", runCfgPath);
-    if (runCfgPath.IsNullOrEmpty()) return;
+    if (runCfgPath.IsNullOrEmpty()) return Error_Null;
     CSimpleStringA storeFilePath = runCfgPath + SPLIT_SLASH_STR + "SMBIOSData.txt";
 
     if (!ExistsFileA(storeFilePath)) {
@@ -8331,28 +8331,25 @@ void ResourceWatcherFSM::CatchSystemBasicInfo()
     std::string succStr, errStr;
     std::string runStr("dmidecode -t system > ");
     runStr += storeFilePath.GetData();
-    if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
-
-    } else {
+    if (!SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
         DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute '%s' failed!", runStr.c_str());
+        if (!ExistsFileA(storeFilePath)) {
+            RemoveFileA(storeFilePath);
+        }
+        return Error_Unexpect;
     }
 
-    CSimpleStringA strResult("{");
     do 
     {
         std::string succStr, errStr;
         std::string runStr("awk -F ':' '(NR>=7)&&(NR<=14)&&($0~\"Manufacturer\"){print$2}' ");
         runStr += storeFilePath.GetData();
         if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
-            SP::Utility::ToTrim(succStr);
+            info.strManufacturer = SP::Utility::ToTrim(succStr).c_str();
         } else {
             succStr = "";
             DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("fetch 'Manufacturer' failed!");
         }
-        if (strResult.GetLength() > 1) {
-            strResult += ", ";
-        }
-        strResult += CSimpleStringA::Format("\"Manufacturer\":\"%s\"", succStr.c_str());
     } while (false);
 
     do {
@@ -8360,15 +8357,11 @@ void ResourceWatcherFSM::CatchSystemBasicInfo()
         std::string runStr("awk -F ':' '(NR>=7)&&(NR<=14)&&($0~\"Product Name\"){print$2}' ");
         runStr += storeFilePath.GetData();
         if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
-            SP::Utility::ToTrim(succStr);
+            info.strProductName = SP::Utility::ToTrim(succStr).c_str();
         } else {
             succStr = "";
             DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("fetch 'Product Name' failed!");
         }
-        if (strResult.GetLength() > 1) {
-            strResult += ", ";
-        }
-        strResult += CSimpleStringA::Format("\"Product Name\":\"%s\"", succStr.c_str());
     } while (false);
 
     do {
@@ -8376,19 +8369,43 @@ void ResourceWatcherFSM::CatchSystemBasicInfo()
         std::string runStr("awk -F ':' '(NR>=7)&&(NR<=14)&&($0~\"Serial Number\"){print$2}' ");
         runStr += storeFilePath.GetData();
         if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
-            SP::Utility::ToTrim(succStr);
+            info.strSerialNumber = SP::Utility::ToTrim(succStr).c_str();
         } else {
             succStr = "";
             DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("fetch 'Serial Number' failed!");
         }
-        if (strResult.GetLength() > 1) {
-            strResult += ", ";
-        }
-        strResult += CSimpleStringA::Format("\"Serial Number\":\"%s\"", succStr.c_str());
     } while (false);
 
-    strResult += "}";
-    LogWarn(Severity_Low, Error_Debug, LOG_INFO_DEVICE_SMBIOS_GET, strResult);
+    if (!ExistsFileA(storeFilePath)) {
+        RemoveFileA(storeFilePath);
+    }
+    return Error_Succeed;
+    
+}
+
+void ResourceWatcherFSM::AlarmSystemBasicInfo()
+{
+    SystemBasicInfo info;
+    if (Error_Succeed == CatchSystemBasicInfo(info)) {
+        CSimpleStringA strResult("{");
+        if (!info.strManufacturer.IsNullOrEmpty()) {
+            strResult += CSimpleStringA::Format("\"Manufacturer\":\"%s\"", info.strManufacturer.GetData());
+        }
+        if (!info.strProductName.IsNullOrEmpty()) {
+            if (strResult.GetLength() > 1) {
+                strResult += ", ";
+            }
+            strResult += CSimpleStringA::Format("\"Product Name\":\"%s\"", info.strProductName.GetData());
+        }
+        if (!info.strSerialNumber.IsNullOrEmpty()) {
+            if (strResult.GetLength() > 1) {
+                strResult += ", ";
+            }
+            strResult += CSimpleStringA::Format("\"Serial Number\":\"%s\"", info.strSerialNumber.GetData());
+        }
+        strResult += "}";
+        LogWarn(Severity_Low, Error_Debug, LOG_INFO_DEVICE_SMBIOS_GET, strResult);
+    }
 }
 
 #ifdef RVC_OS_LINUX

+ 12 - 2
Module/mod_ResourceWatcher/ResourceWatcherFSM.h

@@ -83,7 +83,6 @@ using namespace std;
 #define SYSVAR_FRAMEWORK_FIRST_BOOT_YES "Y"
 #define SYSVAR_FRAMEWORK_FIRST_BOOT_NO  "N"
 
-
 //Black sheet access attribute
 #define BS_DENY_READ				0x00000001
 #define BS_DENY_MODIFY				0x00000002 //Actually Append action.
@@ -297,8 +296,18 @@ struct CPUInforStruct {
 	int level;
 	CSimpleStringA csBrand;
 };
+
 #endif // RVC_OS_LINUX
 
+struct SystemBasicInfo
+{
+	CSimpleStringA strManufacturer;
+	CSimpleStringA strProductName;
+	CSimpleStringA strSerialNumber;
+
+	SystemBasicInfo():strManufacturer(true), strProductName(true), strSerialNumber(true) {}
+};
+
 class ResourceWatcherFSM : public FSMImpl<ResourceWatcherFSM>
 {
 public:
@@ -803,7 +812,8 @@ public:
 	int IsWifiConnected();
 #endif // RVC_OS_LINUX
 
-	void CatchSystemBasicInfo();
+	void AlarmSystemBasicInfo();
+	ErrorCodeEnum CatchSystemBasicInfo(SystemBasicInfo& info);
 };
 
 class RunEvent : public FSMEvent

+ 11 - 1
Module/mod_ResourceWatcher/mod_ResourceWatcher.h

@@ -214,7 +214,17 @@ public:
 	void GetDevInfo(SpReqAnsContext<ResourceWatcherService_GetDevInfo_Req, 
 		ResourceWatcherService_GetDevInfo_Ans>::Pointer ctx)
 	{
-		ctx->Answer(Error_NotImpl);
+		LOG_FUNCTION();
+
+        SystemBasicInfo info;
+		ErrorCodeEnum result = m_fsm.CatchSystemBasicInfo(info);
+		if (Error_Succeed == result) {
+			ctx->Ans.type = info.strProductName;
+			ctx->Ans.model = info.strManufacturer;
+			ctx->Ans.version = info.strSerialNumber;
+			ctx->Ans.state = 0;
+		}
+		ctx->Answer(result);
 	}
 
 	void GetCSwiperStatus(SpReqAnsContext<ResourceWatcherService_GetCardSwiper_Req,

+ 82 - 3
addin/res/ManagerDesktop/js/guide.js

@@ -338,9 +338,13 @@ function MechineTypeSelectChangedAtInit(name)
     $('#gui_init_param_device_model').attr("value", '');
 
     if(name == 'RVC.Stand2S') {
+        $('#gui_init_param_machine_type').text('柜式双屏大机');
+        $('#gui_init_param_machine_type').attr("value", 'RVC.Stand2S');
         generateVendorTypeSelect(VENDOR_4_STAND2S, VENDOR_4_STAND2S_ZHCN, 'gui_init_param_vendor_list');
 
     } else if(name == 'RVC.Stand1SPlus') {
+        $('#gui_init_param_machine_type').text('单屏大机');
+        $('#gui_init_param_machine_type').attr("value", 'RVC.Stand1SPlus');
         generateVendorTypeSelect(VENDOR_4_STAND1S, VENDOR_4_STAND1S_ZHCN, 'gui_init_param_vendor_list');
     }
 }
@@ -374,8 +378,6 @@ function VendorSelectChangedAtInit(name)
             }
         }
     }
-
-
 }
 
 function BranchTypeSelectChange(widget)
@@ -399,6 +401,83 @@ function BranchTypeSelectChange(widget)
     }
 }
 
+function FetchTerminalBasicInfo()
+{
+    MechineTypeSelectChangedAtInit('RVC.Stand2S')
+
+    let req = new Request();
+    req.timeout = 10000;
+    utilStartSubmitDialog("读取终端信息......");
+    RVC.ResourceWatcherEntity.GetDevInfo(req, function(ret) {
+        utilStopSubmitDialog();
+        if(ret.errorCode === 0) {
+            let result = JSON.parse(ret[RVC.EntityController.sigResponseUUID])
+            let productName = result.type
+            let manufacturer = result.model
+            let serialNumber = result.version
+            console.log('ProductName: ' + productName)
+            console.log('Manufacturer: ' + manufacturer)
+            console.log('SerialNumber: ' + serialNumber)
+            var vendorIdx = -1;
+            if(productName != '') {
+                for(var i=0; i<VENDOR_4_STAND1S_MACHINE_TYPE.length; ++i) {
+                    for(var j=0; j<VENDOR_4_STAND1S_MACHINE_TYPE[i].length; ++j) {
+                        console.log(i + ',' + j + ': ' + VENDOR_4_STAND1S_MACHINE_TYPE[i][j]);
+                        if(productName === VENDOR_4_STAND1S_MACHINE_TYPE[i][j]) {
+                            vendorIdx = i;
+                        }
+                    }
+                }
+                if(vendorIdx != -1) {
+                    var manufacturerUpper = manufacturer.toUpperCase()
+                    if(manufacturerUpper === VENDOR_4_STAND1S[vendorIdx]) {
+                        MechineTypeSelectChangedAtInit('RVC.Stand1SPlus')
+                        $('#gui_init_param_vendor').text(VENDOR_4_STAND1S_ZHCN[vendorIdx])
+                            $('#gui_init_param_vendor').attr("value", VENDOR_4_STAND1S[vendorIdx])
+                        VendorSelectChangedAtInit(VENDOR_4_STAND1S[vendorIdx])
+                        $('#guide_init_param_device_sn').val(serialNumber)
+                        return;
+                    } else {
+                        utilStartAlertDialog('设备型号 [' + productName +'] 已匹配,获取的厂商名称错误: [' + manufacturer + '], 请检查!');
+                    }
+
+                } else {
+
+                    for(var i=0; i<VENDOR_4_STAND2S_MACHINE_TYPE.length; ++i) {
+                        for(var j=0; j<VENDOR_4_STAND2S_MACHINE_TYPE[i].length; ++j) {
+                            console.log(i + ',' + j + ': ' + VENDOR_4_STAND2S_MACHINE_TYPE[i][j]);
+                            if(productName === VENDOR_4_STAND2S_MACHINE_TYPE[i][j]) {
+                                vendorIdx = i;
+                            }
+                        }
+                    }
+                    if(vendorIdx != -1) {
+                        var manufacturerUpper = manufacturer.toUpperCase()
+                        if(manufacturerUpper === VENDOR_4_STAND2S[vendorIdx]) {
+                            MechineTypeSelectChangedAtInit('RVC.Stand2S')
+                            $('#gui_init_param_vendor').text(VENDOR_4_STAND2S_ZHCN[vendorIdx])
+                            $('#gui_init_param_vendor').attr("value", VENDOR_4_STAND2S[vendorIdx])
+                            VendorSelectChangedAtInit(VENDOR_4_STAND2S[vendorIdx])
+                            $('#guide_init_param_device_sn').val(serialNumber)
+                            return;
+                        } else {
+                            utilStartAlertDialog('设备型号 [' + productName +'] 已匹配,获取的厂商名称错误: [' + manufacturer + '], 请检查!');
+                        }
+                    } else {
+                        utilShowToast("无法匹配设备型号 [" + productName + "],请手工选择!", 3000);
+                    }
+                }
+            } else {
+                utilShowToast("读取终端信息无效,请手工选择!", 3000);
+            }
+
+        } else {
+            RVC.ResourceWatcherEntity.commErrorCallback(ret);
+        }
+    });
+}
+
+
 //正式环境该参数不可选
 function VendorSelectChanged(name)
 {
@@ -1980,7 +2059,6 @@ $(function () {
             this.hideAllPage();
             switch(step) {
                 case DEPLOY.DeployStep_GetTerminalInfo:
-                    MechineTypeSelectChangedAtInit('RVC.Stand2S');
                     break;
                 case DEPLOY.DeployStep_MediaConfig:
                     FulfillMediaDeviceList();
@@ -2027,6 +2105,7 @@ $(function () {
                     break;
                 case DEPLOY.DeployStep_GetTerminalInfo:
                     InitTerminalRegistInfoUrl();
+                    FetchTerminalBasicInfo();
                     break;
                 case DEPLOY.DeployStep_AdapterConfig:
                     InterestRootSwitch(true);

+ 7 - 0
addin/res/ManagerDesktop/js/public.js

@@ -2357,6 +2357,7 @@ $(function () {
         entityName: 'ResourceWatcher',
         className: 'ResourceWatcherService',
         methodID: {
+            GetDevInfo: 65535,
             UpdateDNS : 8,
             GetNetworkInfo: 9,
             GetThirdPartyInstallState:10,
@@ -2369,6 +2370,7 @@ $(function () {
             FetchSystemSnapshot:18
         },
         methodSignature: {
+            GetDevInfo: 296205965,
             UpdateDNS : 689391692,
             GetNetworkInfo: -799638104,
             GetThirdPartyInstallState:-15861483,
@@ -2380,6 +2382,11 @@ $(function () {
             FilesClean:624348486,
             FetchSystemSnapshot:-1005346345
         },
+        GetDevInfo: function(req, callback) {
+            this.webSocketInvokeEx(req, 
+                ({id:this.methodID.GetDevInfo, sig:this.methodSignature.GetDevInfo}),
+                 callback);
+        },
         GetNetworkInfo: function(req, callback) {
             this.webSocketInvokeEx(req, 
                 ({id:this.methodID.GetNetworkInfo, sig:this.methodSignature.GetNetworkInfo}),