BasicConfig.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-03-28 09:03:02
  6. * @LastEditors: Your Name lishengyin@sz-sunwin.com
  7. * @LastEditTime: 2022-09-04 21:29:28
  8. */
  9. #ifndef __BASICECONFIG_H_
  10. #define __BASICECONFIG_H_
  11. #include <iostream>
  12. #include <vector>
  13. #include <rapidjson/document.h>
  14. #include <rapidjson/rapidjson.h>
  15. #include <rapidjson/stringbuffer.h>
  16. #include <rapidjson/writer.h>
  17. using namespace std;
  18. class BasicConfig
  19. {
  20. public:
  21. // usr
  22. std::string usr;
  23. std::string pwd;
  24. // NettyIp;
  25. std::string NettyIP;
  26. int NettyPort;
  27. std::string mysql_IP;
  28. int mysql_port;
  29. double DiskUsageThreshold;
  30. int HardDiskCleanupTime;
  31. int InferDataRetentionTime;
  32. int interval;
  33. int sensitivity;
  34. int TimeOut;
  35. int debug;
  36. int getHistoryVideoFlag;
  37. int ClearPastRecords;
  38. int LowVersion = 0;
  39. double bboxSize = 0.0;
  40. int ExpelInterval = 0;
  41. std::string com_port = "";
  42. int ExpelPort = 19002;
  43. int InferInterval = 2000;
  44. std::string payServerIP = "10.81.160.141";
  45. int filterLevel = 2;
  46. int vpn = 0;
  47. int InferChecker = 0;
  48. std::string InferCheckerIP = "192.168.31.219";
  49. int InferCheckerPort = 8860;
  50. public:
  51. BasicConfig(){}
  52. ~BasicConfig(){}
  53. /**
  54. * @description: json转换为object
  55. * @param {string&} json
  56. * @return {*}
  57. */
  58. bool JsonToObject(std::string& json){
  59. rapidjson::Document doc;
  60. if (doc.Parse<rapidjson::kParseCommentsFlag>(json.c_str()).HasParseError()) {
  61. return false;
  62. }
  63. // get members
  64. const auto end = doc.MemberEnd();
  65. // json_type
  66. if(end == doc.FindMember("usr") || !doc["usr"].IsString()) {
  67. return false;
  68. }else{
  69. usr = doc["usr"].GetString();
  70. }
  71. if(end == doc.FindMember("pwd") || !doc["pwd"].IsString()) {
  72. return false;
  73. }else{
  74. pwd = doc["pwd"].GetString();
  75. }
  76. if(end == doc.FindMember("NettyIP") || !doc["NettyIP"].IsString()) {
  77. return false;
  78. }else{
  79. NettyIP = doc["NettyIP"].GetString();
  80. }
  81. if(end == doc.FindMember("NettyPort") || !doc["NettyPort"].IsString()) {
  82. return false;
  83. }else{
  84. NettyPort = std::atoi(doc["NettyPort"].GetString());
  85. }
  86. if(end == doc.FindMember("DiskUsageThreshold") || !doc["DiskUsageThreshold"].IsString()) {
  87. return false;
  88. }else{
  89. DiskUsageThreshold = std::atof(doc["DiskUsageThreshold"].GetString());
  90. }
  91. if(end == doc.FindMember("HardDiskCleanupTime") || !doc["HardDiskCleanupTime"].IsString()) {
  92. return false;
  93. }else{
  94. HardDiskCleanupTime = std::atoi(doc["HardDiskCleanupTime"].GetString());
  95. }
  96. if(end == doc.FindMember("InferDataRetentionTime") || !doc["InferDataRetentionTime"].IsString()) {
  97. return false;
  98. }else{
  99. InferDataRetentionTime = std::atoi(doc["InferDataRetentionTime"].GetString());
  100. }
  101. if(end == doc.FindMember("interval") || !doc["interval"].IsString()) {
  102. return false;
  103. }else{
  104. interval = std::atoi(doc["interval"].GetString());
  105. }
  106. if(end == doc.FindMember("sensitivity") || !doc["sensitivity"].IsString()) {
  107. return false;
  108. }else{
  109. sensitivity = std::atoi(doc["sensitivity"].GetString());
  110. }
  111. if(end == doc.FindMember("TimeOut") || !doc["TimeOut"].IsString()) {
  112. return false;
  113. }else{
  114. TimeOut = std::atoi(doc["TimeOut"].GetString());
  115. }
  116. if(end == doc.FindMember("mysql_IP") || !doc["mysql_IP"].IsString()) {
  117. return false;
  118. }else{
  119. mysql_IP = doc["mysql_IP"].GetString();
  120. }
  121. if(end == doc.FindMember("mysql_port") || !doc["mysql_port"].IsString()) {
  122. return false;
  123. }else{
  124. mysql_port = std::atoi(doc["mysql_port"].GetString());
  125. }
  126. if(end != doc.FindMember("com_port") && doc["com_port"].IsString()) {
  127. com_port = doc["com_port"].GetString();
  128. }
  129. if(end != doc.FindMember("Debug") && doc["Debug"].IsString()) {
  130. debug = std::atoi(doc["Debug"].GetString());
  131. }
  132. if(end != doc.FindMember("getHistoryVideoFlag") && doc["getHistoryVideoFlag"].IsString()) {
  133. getHistoryVideoFlag = std::atoi(doc["getHistoryVideoFlag"].GetString());
  134. }
  135. if(end != doc.FindMember("ClearPastRecords") && doc["ClearPastRecords"].IsString()) {
  136. ClearPastRecords = std::atoi(doc["ClearPastRecords"].GetString());
  137. }
  138. if(end != doc.FindMember("bboxSize") && doc["bboxSize"].IsString()) {
  139. bboxSize = std::atof(doc["bboxSize"].GetString());
  140. }
  141. if(end != doc.FindMember("ExpelInterval") && doc["ExpelInterval"].IsString()) {
  142. ExpelInterval = std::atoi(doc["ExpelInterval"].GetString());
  143. }
  144. if(end != doc.FindMember("LowVersion") && doc["LowVersion"].IsString()){
  145. LowVersion = std::atoi(doc["LowVersion"].GetString());
  146. }
  147. if(end != doc.FindMember("ExpelPort") && doc["ExpelPort"].IsString()){
  148. ExpelPort = std::atoi(doc["ExpelPort"].GetString());
  149. }
  150. if(end != doc.FindMember("InferInterval") && doc["InferInterval"].IsString()){
  151. InferInterval = std::atoi(doc["InferInterval"].GetString());
  152. }
  153. if(end != doc.FindMember("payServerIP") && doc["payServerIP"].IsString()){
  154. payServerIP = doc["payServerIP"].GetString();
  155. }
  156. if(end != doc.FindMember("filterLevel") && doc["filterLevel"].IsString()){
  157. filterLevel = std::atoi(doc["filterLevel"].GetString());
  158. }
  159. if(end != doc.FindMember("vpn") && doc["vpn"].IsString()){
  160. vpn = std::atoi(doc["vpn"].GetString());
  161. }
  162. if(end != doc.FindMember("InferChecker") && doc["InferChecker"].IsString()){
  163. InferChecker = std::atoi(doc["InferChecker"].GetString());
  164. }
  165. if(end != doc.FindMember("InferCheckerIP") && doc["InferCheckerIP"].IsString()){
  166. InferCheckerIP = doc["InferCheckerIP"].GetString();
  167. }
  168. if(end != doc.FindMember("InferCheckerPort") && doc["InferCheckerPort"].IsString()){
  169. InferCheckerPort = std::atoi(doc["InferCheckerPort"].GetString());
  170. }
  171. return true;
  172. }
  173. };
  174. #endif