#ifndef RVC_MOD_COMM_ENTITY_SETTINGS_HPP_ #define RVC_MOD_COMM_ENTITY_SETTINGS_HPP_ #include "SpBase.h" #include "fileutil.h" namespace SP { namespace Module { namespace Comm { namespace Settings { /*! * @brief 判断当前是否处于安装模式,对于某些实体在安装时需要配合执行功能所以会启动,但是又需要屏蔽掉常规模式下的自动执行 * 就需要通过此接口判断以停止某些功能 * @param[in] * @param[out] * @return : */ static inline bool IsInConfigScheduleMode(CEntityBase* pEntity) { CSimpleStringA strtermState; pEntity->GetFunction()->GetSysVar("TerminalStage", strtermState); return strtermState.IsStartWith("Z="); } static inline ErrorCodeEnum StoreHeadBranchServicesMode(CEntityBase* pEntity, BOOL fEnable) { CSmartPointer pConfig; pEntity->GetFunction()->OpenConfig(Config_Cache, pConfig); return pConfig->WriteConfigValueInt("MicroServicesConfig", "SourceFrom", fEnable? 2 : 1); } /*! * @brief 提供另外一种保底的方法检测集中配置从哪里下载 * @param[in] 实体句柄 * @return : -1:集中配置文件不存在;0:分行服务;1:总行服务 */ //TODO: 移除,现在全部终端已经切总行,过渡的分行逻辑已经不需要了 static int DetectCenterSettingFilesSyncFromWhere(CEntityBase* pEntity) { CSimpleStringA strFilePath; pEntity->GetFunction()->GetPath("CenterSetting", strFilePath); if (!ExistsFileA(strFilePath)) { return -1; } CSmartPointer pConfig; pEntity->GetFunction()->OpenConfig(Config_CenterSetting, pConfig); int fromType(0); pConfig->ReadConfigValueInt("CenterSetting", "ProvideByHeadBank", fromType); return (fromType == 1) ? 1 : 0; } static inline bool IsUsingHeadBranchServices(CEntityBase* pEntity) { CSmartPointer pConfig; pEntity->GetFunction()->OpenConfig(Config_Cache, pConfig); int enable(0); pConfig->ReadConfigValueInt("MicroServicesConfig", "SourceFrom", enable); return (enable == 2); } static inline bool IsUsingSubBranchServerConfig(CEntityBase* pEntity) { CSmartPointer pConfig; pEntity->GetFunction()->OpenConfig(Config_Cache, pConfig); int enable(0); pConfig->ReadConfigValueInt("MicroServicesConfig", "SourceFrom", enable); return (enable == 1); } static inline void InitializeOtherLogSwitch(CEntityBase* pEntity, const CSimpleStringA& strModuleName) { LOG_FUNCTION(); if (pEntity == NULL || strModuleName.IsNullOrEmpty()) { return; } struct OtherLogConfig { OtherLogConfig() :strLevel("OFF"), strType("FILE"), strDllName(""), strLogPath("") {} OtherLogConfig(const CSimpleStringA& strModuleName) :strLevel("OFF"), strType("FILE"), strDllName(strModuleName), strLogPath("") {} CSimpleStringA strLevel; CSimpleStringA strType; CSimpleStringA strDllName; CSimpleStringA strLogPath; void Settle() { toolkit_setenv("VENDOR_RECODE_LEVEL", strLevel); toolkit_setenv("VENDOR_RECODE_TYPE", strType); toolkit_setenv("VENDOR_DLL_NAME", strDllName); toolkit_setenv("VENDOR_LOG_PATH", strLogPath); } } stLogConfig(strModuleName); CSmartPointer centerConfig; pEntity->GetFunction()->OpenConfig(Config_CenterSetting, centerConfig); int nSaveFileOrNot(0); centerConfig->ReadConfigValueInt("Common", "SaveFile", nSaveFileOrNot); stLogConfig.strType = "UPLOAD"; if ((nSaveFileOrNot & 1) == 1) { if (!stLogConfig.strType.IsNullOrEmpty()) stLogConfig.strType += "|"; stLogConfig.strType += "FILE"; } int nUploadLogLevel(1); /*INFO*/ CSimpleStringA strUploadLogLevelEntity(true); centerConfig->ReadConfigValue(strModuleName.GetData(), "UpLoadLogLevel", strUploadLogLevelEntity); if (strUploadLogLevelEntity.IsNullOrEmpty()) { CSimpleStringA strUploadLogLevelComm(true); centerConfig->ReadConfigValue("Common", "UpLoadLogLevel", strUploadLogLevelComm); strUploadLogLevelEntity = strUploadLogLevelComm; } bool isValidDigit = !strUploadLogLevelEntity.IsNullOrEmpty(); for (int i = 0; i < strUploadLogLevelEntity.GetLength(); ++i) { if (!(strUploadLogLevelEntity[i] >= '0' && strUploadLogLevelEntity[i] <= '9')) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("invalid param: %s", strUploadLogLevelEntity.GetData()); isValidDigit = false; break; } } if (isValidDigit) { nUploadLogLevel = atoi(strUploadLogLevelEntity.GetData()); } switch (nUploadLogLevel) { case 0: /*LOG_LEVEL_DEBUG*/ stLogConfig.strLevel = "ALL"; break; case 1: /*LOG_LEVEL_INFO*/ stLogConfig.strLevel = "INFO"; break; case 2: /*LOG_LEVEL_WARN*/ stLogConfig.strLevel = "WARN"; break; case 3: /*LOG_LEVEL_ERROR*/ stLogConfig.strLevel = "ERROR"; break; case 4: /*LOG_LEVEL_FATAL*/ stLogConfig.strLevel = "FATAL"; break; default: stLogConfig.strLevel = "OFF"; break; } pEntity->GetFunction()->GetPath("Dbg", stLogConfig.strLogPath); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("DbgPath: %s", stLogConfig.strLogPath.GetData()); stLogConfig.Settle(); LogEvent(Severity_Low, 0, CSimpleStringA::Format("{\"RecordLevel\":\"%s\", \"RecordType\":\"%s\}", stLogConfig.strLevel.GetData(), stLogConfig.strType.GetData())); } } //namespace Settings } //namespace Comm } //namespace Module } //SP #endif //RVC_MOD_COMM_ENTITY_SETTINGS_HPP_