CommEntitySettings.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. static int DetectCenterSettingFilesSyncFromWhere(CEntityBase* pEntity)
  38. {
  39. CSimpleStringA strFilePath;
  40. pEntity->GetFunction()->GetPath("CenterSetting", strFilePath);
  41. if (!ExistsFileA(strFilePath)) {
  42. return -1;
  43. }
  44. CSmartPointer<IConfigInfo> pConfig;
  45. pEntity->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  46. int fromType(0);
  47. pConfig->ReadConfigValueInt("CenterSetting", "ProvideByHeadBank", fromType);
  48. return (fromType == 1) ? 1 : 0;
  49. }
  50. static inline bool IsUsingHeadBranchServices(CEntityBase* pEntity)
  51. {
  52. CSmartPointer<IConfigInfo> pConfig;
  53. pEntity->GetFunction()->OpenConfig(Config_Cache, pConfig);
  54. int enable(0);
  55. pConfig->ReadConfigValueInt("MicroServicesConfig", "SourceFrom", enable);
  56. return (enable == 2);
  57. }
  58. static inline bool IsUsingSubBranchServerConfig(CEntityBase* pEntity)
  59. {
  60. CSmartPointer<IConfigInfo> pConfig;
  61. pEntity->GetFunction()->OpenConfig(Config_Cache, pConfig);
  62. int enable(0);
  63. pConfig->ReadConfigValueInt("MicroServicesConfig", "SourceFrom", enable);
  64. return (enable == 1);
  65. }
  66. /*!
  67. * @brief 先从集中配置中读取信息,如果没有,再从本地cfg实体配置文件读取信息
  68. * section 使用实体名称,从 GetFunction()->GetEntityName中获取
  69. * @param[in] retStrValue 不为空,则说明读的时字符串,retDwValue 不为空说明读取的是数字,不能都为空,也不能都不为空
  70. * @param[out]
  71. * @return :
  72. */
  73. static inline ErrorCodeEnum ReadConfigFromCenterAfterCfg(
  74. CEntityBase* pEntity, LPCTSTR lpcszKey, CSimpleStringA* retStrValue, int* retValue)
  75. {
  76. ErrorCodeEnum result(Error_Succeed);
  77. if ((lpcszKey == NULL || strlen(lpcszKey) == 0)
  78. || (retStrValue == NULL && retValue == NULL)
  79. || (retStrValue != NULL && retValue != NULL)
  80. || pEntity == NULL) {
  81. return Error_Param;
  82. }
  83. CSmartPointer<IConfigInfo> pCenConfig;
  84. result = pEntity->GetFunction()->OpenConfig(Config_CenterSetting, pCenConfig);
  85. if (retStrValue != NULL) {
  86. result = pCenConfig->ReadConfigValue(pEntity->GetEntityName(), lpcszKey, *retStrValue);
  87. if (retStrValue->IsNullOrEmpty()) {
  88. CSmartPointer<IConfigInfo> pCfgConfig;
  89. result = pEntity->GetFunction()->OpenConfig(Config_Software, pCfgConfig);
  90. result = pCfgConfig->ReadConfigValue(pEntity->GetEntityName(), lpcszKey, *retStrValue);
  91. }
  92. } else if(retValue != NULL) {
  93. result = pCenConfig->ReadConfigValueInt(pEntity->GetEntityName(), lpcszKey, *retValue);
  94. if (*retValue == 0) {
  95. CSmartPointer<IConfigInfo> pCfgConfig;
  96. result = pEntity->GetFunction()->OpenConfig(Config_Software, pCfgConfig);
  97. result = pCfgConfig->ReadConfigValueInt(pEntity->GetEntityName(), lpcszKey, *retValue);
  98. }
  99. }
  100. return result;
  101. }
  102. } //namespace Settings
  103. } //namespace Comm
  104. } //namespace Module
  105. } //SP
  106. #endif //RVC_MOD_COMM_ENTITY_SETTINGS_HPP_