CommEntitySettings.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #ifndef RVC_MOD_COMM_ENTITY_SETTINGS_HPP_
  2. #define RVC_MOD_COMM_ENTITY_SETTINGS_HPP_
  3. #include "SpBase.h"
  4. #include "fileutil.h"
  5. namespace SP
  6. {
  7. namespace Module
  8. {
  9. namespace Comm
  10. {
  11. namespace Settings
  12. {
  13. /*!
  14. * @brief 判断当前是否处于安装模式,对于某些实体在安装时需要配合执行功能所以会启动,但是又需要屏蔽掉常规模式下的自动执行
  15. * 就需要通过此接口判断以停止某些功能
  16. * @param[in]
  17. * @param[out]
  18. * @return :
  19. */
  20. static inline bool IsInConfigScheduleMode(CEntityBase* pEntity)
  21. {
  22. CSimpleStringA strtermState;
  23. pEntity->GetFunction()->GetSysVar("TerminalStage", strtermState);
  24. return strtermState.IsStartWith("Z=");
  25. }
  26. static inline ErrorCodeEnum StoreHeadBranchServicesMode(CEntityBase* pEntity, BOOL fEnable)
  27. {
  28. CSmartPointer<IConfigInfo> pConfig;
  29. pEntity->GetFunction()->OpenConfig(Config_Cache, pConfig);
  30. return pConfig->WriteConfigValueInt("MicroServicesConfig", "SourceFrom", fEnable? 2 : 1);
  31. }
  32. /*!
  33. * @brief 提供另外一种保底的方法检测集中配置从哪里下载
  34. * @param[in] 实体句柄
  35. * @return : -1:集中配置文件不存在;0:分行服务;1:总行服务
  36. */
  37. //TODO: 移除,现在全部终端已经切总行,过渡的分行逻辑已经不需要了
  38. static int DetectCenterSettingFilesSyncFromWhere(CEntityBase* pEntity)
  39. {
  40. CSimpleStringA strFilePath;
  41. pEntity->GetFunction()->GetPath("CenterSetting", strFilePath);
  42. if (!ExistsFileA(strFilePath)) {
  43. return -1;
  44. }
  45. CSmartPointer<IConfigInfo> pConfig;
  46. pEntity->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  47. int fromType(0);
  48. pConfig->ReadConfigValueInt("CenterSetting", "ProvideByHeadBank", fromType);
  49. return (fromType == 1) ? 1 : 0;
  50. }
  51. static inline bool IsUsingHeadBranchServices(CEntityBase* pEntity)
  52. {
  53. CSmartPointer<IConfigInfo> pConfig;
  54. pEntity->GetFunction()->OpenConfig(Config_Cache, pConfig);
  55. int enable(0);
  56. pConfig->ReadConfigValueInt("MicroServicesConfig", "SourceFrom", enable);
  57. return (enable == 2);
  58. }
  59. static inline bool IsUsingSubBranchServerConfig(CEntityBase* pEntity)
  60. {
  61. CSmartPointer<IConfigInfo> pConfig;
  62. pEntity->GetFunction()->OpenConfig(Config_Cache, pConfig);
  63. int enable(0);
  64. pConfig->ReadConfigValueInt("MicroServicesConfig", "SourceFrom", enable);
  65. return (enable == 1);
  66. }
  67. /*!
  68. * @brief 先从集中配置中读取信息,如果没有,再从本地cfg实体配置文件读取信息
  69. * section 使用实体名称,从 GetFunction()->GetEntityName中获取
  70. * @param[in] retStrValue 不为空,则说明读的时字符串,retDwValue 不为空说明读取的是数字,不能都为空,也不能都不为空
  71. * @param[out]
  72. * @return :
  73. */
  74. static inline ErrorCodeEnum ReadConfigFromCenterSettings(
  75. CEntityBase* pEntity, LPCTSTR lpcszKey, CSimpleStringA* retStrValue, int* retValue)
  76. {
  77. ErrorCodeEnum result(Error_Succeed);
  78. if ((lpcszKey == NULL || strlen(lpcszKey) == 0)
  79. || (retStrValue == NULL && retValue == NULL)
  80. || (retStrValue != NULL && retValue != NULL)
  81. || pEntity == NULL) {
  82. return Error_Param;
  83. }
  84. CSmartPointer<IConfigInfo> pCenConfig;
  85. result = pEntity->GetFunction()->OpenConfig(Config_CenterSetting, pCenConfig);
  86. if (retStrValue != NULL) {
  87. result = pCenConfig->ReadConfigValue(pEntity->GetEntityName(), lpcszKey, *retStrValue);
  88. } else if(retValue != NULL) {
  89. result = pCenConfig->ReadConfigValueInt(pEntity->GetEntityName(), lpcszKey, *retValue);
  90. }
  91. return result;
  92. }
  93. static inline void InitializeOtherLogSwitch(CEntityBase* pEntity, const CSimpleStringA& strModuleName)
  94. {
  95. LOG_FUNCTION();
  96. if (pEntity == NULL || strModuleName.IsNullOrEmpty()) {
  97. return;
  98. }
  99. struct OtherLogConfig
  100. {
  101. OtherLogConfig() :strLevel("OFF"), strType("FILE"), strDllName(""), strLogPath("") {}
  102. OtherLogConfig(const CSimpleStringA& strModuleName) :strLevel("OFF"), strType("FILE"), strDllName(strModuleName), strLogPath("") {}
  103. CSimpleStringA strLevel;
  104. CSimpleStringA strType;
  105. CSimpleStringA strDllName;
  106. CSimpleStringA strLogPath;
  107. void Settle()
  108. {
  109. toolkit_setenv("VENDOR_RECODE_LEVEL", strLevel);
  110. toolkit_setenv("VENDOR_RECODE_TYPE", strType);
  111. toolkit_setenv("VENDOR_DLL_NAME", strDllName);
  112. toolkit_setenv("VENDOR_LOG_PATH", strLogPath);
  113. }
  114. } stLogConfig(strModuleName);
  115. CSmartPointer<IConfigInfo> centerConfig;
  116. pEntity->GetFunction()->OpenConfig(Config_CenterSetting, centerConfig);
  117. int nSaveFileOrNot(0);
  118. centerConfig->ReadConfigValueInt("Common", "SaveFile", nSaveFileOrNot);
  119. stLogConfig.strType = "UPLOAD";
  120. if ((nSaveFileOrNot & 1) == 1) {
  121. if (!stLogConfig.strType.IsNullOrEmpty()) stLogConfig.strType += "|";
  122. stLogConfig.strType += "FILE";
  123. }
  124. int nUploadLogLevel(1); /*INFO*/
  125. CSimpleStringA strUploadLogLevelEntity(true);
  126. centerConfig->ReadConfigValue(strModuleName.GetData(), "UpLoadLogLevel", strUploadLogLevelEntity);
  127. if (strUploadLogLevelEntity.IsNullOrEmpty()) {
  128. CSimpleStringA strUploadLogLevelComm(true);
  129. centerConfig->ReadConfigValue("Common", "UpLoadLogLevel", strUploadLogLevelComm);
  130. strUploadLogLevelEntity = strUploadLogLevelComm;
  131. }
  132. bool isValidDigit = !strUploadLogLevelEntity.IsNullOrEmpty();
  133. for (int i = 0; i < strUploadLogLevelEntity.GetLength(); ++i) {
  134. if (!(strUploadLogLevelEntity[i] >= '0' && strUploadLogLevelEntity[i] <= '9')) {
  135. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("invalid param: %s", strUploadLogLevelEntity.GetData());
  136. isValidDigit = false;
  137. break;
  138. }
  139. }
  140. if (isValidDigit) {
  141. nUploadLogLevel = atoi(strUploadLogLevelEntity.GetData());
  142. }
  143. switch (nUploadLogLevel)
  144. {
  145. case 0: /*LOG_LEVEL_DEBUG*/
  146. stLogConfig.strLevel = "ALL";
  147. break;
  148. case 1: /*LOG_LEVEL_INFO*/
  149. stLogConfig.strLevel = "INFO";
  150. break;
  151. case 2: /*LOG_LEVEL_WARN*/
  152. stLogConfig.strLevel = "WARN";
  153. break;
  154. case 3: /*LOG_LEVEL_ERROR*/
  155. stLogConfig.strLevel = "ERROR";
  156. break;
  157. case 4: /*LOG_LEVEL_FATAL*/
  158. stLogConfig.strLevel = "FATAL";
  159. break;
  160. default:
  161. stLogConfig.strLevel = "OFF";
  162. break;
  163. }
  164. pEntity->GetFunction()->GetPath("Dbg", stLogConfig.strLogPath);
  165. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("DbgPath: %s", stLogConfig.strLogPath.GetData());
  166. stLogConfig.Settle();
  167. LogEvent(Severity_Low, 0, CSimpleStringA::Format("{\"RecordLevel\":\"%s\", \"RecordType\":\"%s\}", stLogConfig.strLevel.GetData(), stLogConfig.strType.GetData()));
  168. }
  169. } //namespace Settings
  170. } //namespace Comm
  171. } //namespace Module
  172. } //SP
  173. #endif //RVC_MOD_COMM_ENTITY_SETTINGS_HPP_