CommEntitySettings.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. static inline void InitializeOtherLogSwitch(CEntityBase* pEntity, const CSimpleStringA& strModuleName)
  68. {
  69. LOG_FUNCTION();
  70. if (pEntity == NULL || strModuleName.IsNullOrEmpty()) {
  71. return;
  72. }
  73. struct OtherLogConfig
  74. {
  75. OtherLogConfig() :strLevel("OFF"), strType("FILE"), strDllName(""), strLogPath("") {}
  76. OtherLogConfig(const CSimpleStringA& strModuleName) :strLevel("OFF"), strType("FILE"), strDllName(strModuleName), strLogPath("") {}
  77. CSimpleStringA strLevel;
  78. CSimpleStringA strType;
  79. CSimpleStringA strDllName;
  80. CSimpleStringA strLogPath;
  81. void Settle()
  82. {
  83. toolkit_setenv("VENDOR_RECODE_LEVEL", strLevel);
  84. toolkit_setenv("VENDOR_RECODE_TYPE", strType);
  85. toolkit_setenv("VENDOR_DLL_NAME", strDllName);
  86. toolkit_setenv("VENDOR_LOG_PATH", strLogPath);
  87. }
  88. } stLogConfig(strModuleName);
  89. CSmartPointer<IConfigInfo> centerConfig;
  90. pEntity->GetFunction()->OpenConfig(Config_CenterSetting, centerConfig);
  91. int nSaveFileOrNot(0);
  92. centerConfig->ReadConfigValueInt("Common", "SaveFile", nSaveFileOrNot);
  93. stLogConfig.strType = "UPLOAD";
  94. if ((nSaveFileOrNot & 1) == 1) {
  95. if (!stLogConfig.strType.IsNullOrEmpty()) stLogConfig.strType += "|";
  96. stLogConfig.strType += "FILE";
  97. }
  98. int nUploadLogLevel(1); /*INFO*/
  99. CSimpleStringA strUploadLogLevelEntity(true);
  100. centerConfig->ReadConfigValue(strModuleName.GetData(), "UpLoadLogLevel", strUploadLogLevelEntity);
  101. if (strUploadLogLevelEntity.IsNullOrEmpty()) {
  102. CSimpleStringA strUploadLogLevelComm(true);
  103. centerConfig->ReadConfigValue("Common", "UpLoadLogLevel", strUploadLogLevelComm);
  104. strUploadLogLevelEntity = strUploadLogLevelComm;
  105. }
  106. bool isValidDigit = !strUploadLogLevelEntity.IsNullOrEmpty();
  107. for (int i = 0; i < strUploadLogLevelEntity.GetLength(); ++i) {
  108. if (!(strUploadLogLevelEntity[i] >= '0' && strUploadLogLevelEntity[i] <= '9')) {
  109. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("invalid param: %s", strUploadLogLevelEntity.GetData());
  110. isValidDigit = false;
  111. break;
  112. }
  113. }
  114. if (isValidDigit) {
  115. nUploadLogLevel = atoi(strUploadLogLevelEntity.GetData());
  116. }
  117. switch (nUploadLogLevel)
  118. {
  119. case 0: /*LOG_LEVEL_DEBUG*/
  120. stLogConfig.strLevel = "ALL";
  121. break;
  122. case 1: /*LOG_LEVEL_INFO*/
  123. stLogConfig.strLevel = "INFO";
  124. break;
  125. case 2: /*LOG_LEVEL_WARN*/
  126. stLogConfig.strLevel = "WARN";
  127. break;
  128. case 3: /*LOG_LEVEL_ERROR*/
  129. stLogConfig.strLevel = "ERROR";
  130. break;
  131. case 4: /*LOG_LEVEL_FATAL*/
  132. stLogConfig.strLevel = "FATAL";
  133. break;
  134. default:
  135. stLogConfig.strLevel = "OFF";
  136. break;
  137. }
  138. pEntity->GetFunction()->GetPath("Dbg", stLogConfig.strLogPath);
  139. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("DbgPath: %s", stLogConfig.strLogPath.GetData());
  140. stLogConfig.Settle();
  141. LogEvent(Severity_Low, 0, CSimpleStringA::Format("{\"RecordLevel\":\"%s\", \"RecordType\":\"%s\}", stLogConfig.strLevel.GetData(), stLogConfig.strType.GetData()));
  142. }
  143. } //namespace Settings
  144. } //namespace Comm
  145. } //namespace Module
  146. } //SP
  147. #endif //RVC_MOD_COMM_ENTITY_SETTINGS_HPP_