GlobalVariable.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. #include "GlobalVariable.h"
  2. const QMap<eWeekType, QString> MapWeekTypeToString = {
  3. {eWeekType::Week_Monday, "星期一"},
  4. {eWeekType::Week_Tuesday, "星期二"},
  5. {eWeekType::Week_Wednesday, "星期三"},
  6. {eWeekType::Week_Thursday, "星期四"},
  7. {eWeekType::Week_Friday, "星期五"},
  8. {eWeekType::Week_Saturday, "星期六"},
  9. {eWeekType::Week_Sunday, "星期日"},
  10. {eWeekType::Week_Special, "特殊日期"}
  11. };
  12. /* ====================================================================
  13. * 声卡相关信息结构体
  14. * ==================================================================== */
  15. bool SoundCardRoadInfo_t::operator<(const SoundCardRoadInfo_t &other) const
  16. {
  17. if(nSoundCardNum < other.nSoundCardNum)
  18. {
  19. return true; // 声卡编号小的排在前面
  20. }
  21. if(nSoundCardNum > other.nSoundCardNum)
  22. {
  23. return false; // 声卡编号大的排在后面
  24. }
  25. // 声卡编号相同,比较通道编号
  26. return roadInfo.nRoadNum < other.roadInfo.nRoadNum;
  27. }
  28. /* ====================================================================
  29. * CompareItemInfo_t对比项结构体
  30. * ==================================================================== */
  31. bool CompareItemRoadInfo_t::operator==(const CompareItemRoadInfo_t &other) const
  32. {
  33. return (isEnableRecord == other.isEnableRecord &&
  34. nCompareRoadNum == other.nCompareRoadNum &&
  35. strCompareRoadName == other.strCompareRoadName &&
  36. scRoadInfo.nSoundCardNum == other.scRoadInfo.nSoundCardNum &&
  37. scRoadInfo.strSoundCardID == other.scRoadInfo.strSoundCardID &&
  38. scRoadInfo.strSoundCardName == other.scRoadInfo.strSoundCardName &&
  39. scRoadInfo.roadInfo.nRoadNum == other.scRoadInfo.roadInfo.nRoadNum &&
  40. scRoadInfo.roadInfo.nChannelID == other.scRoadInfo.roadInfo.nChannelID &&
  41. scRoadInfo.roadInfo.strChannelName == other.scRoadInfo.roadInfo.strChannelName
  42. );
  43. }
  44. CompareItemDetectParam_t& CompareItemDetectParam_t::operator=(const CompareItemDetectParam_t &other)
  45. {
  46. if(this == &other)
  47. {
  48. return *this;
  49. }
  50. isEnable = other.isEnable;
  51. threshold = other.threshold;
  52. nLen = other.nLen;
  53. nSensitivity = other.nSensitivity;
  54. return *this;
  55. }
  56. CompareItemInfo_t::CompareItemInfo_t(const CompareItemInfo_t &other)
  57. {
  58. *this = other;
  59. }
  60. CompareItemInfo_t& CompareItemInfo_t::operator=(const CompareItemInfo_t &other)
  61. {
  62. if(this == &other)
  63. {
  64. return *this;
  65. }
  66. nID = other.nID;
  67. strName = other.strName;
  68. isEnable = other.isEnable;
  69. mapRoad = other.mapRoad;
  70. paramMute = other.paramMute;
  71. paramOverload = other.paramOverload;
  72. paramPhase = other.paramPhase;
  73. return *this;
  74. }
  75. /* 判断对比想基础部分是否相等,不包含通道信息 */
  76. bool CompareItemInfo_t::isEqualBase(const CompareItemInfo_t &other) const
  77. {
  78. if(nID != other.nID || strName != other.strName || isEnable != other.isEnable)
  79. {
  80. return false;
  81. }
  82. if(mapRoad.size() != other.mapRoad.size())
  83. {
  84. return false; // 通道数量不同
  85. }
  86. if(paramMute.isEnable != other.paramMute.isEnable ||
  87. paramMute.threshold.nThreshold != other.paramMute.threshold.nThreshold ||
  88. paramMute.nLen != other.paramMute.nLen ||
  89. paramMute.nSensitivity != other.paramMute.nSensitivity)
  90. {
  91. return false;
  92. }
  93. if(paramOverload.isEnable != other.paramOverload.isEnable ||
  94. paramOverload.threshold.nThreshold != other.paramOverload.threshold.nThreshold ||
  95. paramOverload.nLen != other.paramOverload.nLen ||
  96. paramOverload.nSensitivity != other.paramOverload.nSensitivity)
  97. {
  98. return false;
  99. }
  100. if(paramPhase.isEnable != other.paramPhase.isEnable ||
  101. paramPhase.threshold.dThreshold != other.paramPhase.threshold.dThreshold ||
  102. paramPhase.nLen != other.paramPhase.nLen ||
  103. paramPhase.nSensitivity != other.paramPhase.nSensitivity)
  104. {
  105. return false;
  106. }
  107. return true;
  108. }
  109. /* 判断对比项的通道是否相同 */
  110. bool CompareItemInfo_t::isEqualRoads(const CompareItemInfo_t &other) const
  111. {
  112. if(mapRoad.size() != other.mapRoad.size())
  113. {
  114. return false;
  115. }
  116. for(auto it = mapRoad.cbegin(); it != mapRoad.cend(); ++it)
  117. {
  118. auto otherIt = other.mapRoad.find(it.key());
  119. if(otherIt == other.mapRoad.cend())
  120. {
  121. return false; // 在other中找不到对应的通道
  122. }
  123. if(it.value() == otherIt.value())
  124. {
  125. }else {
  126. return false; // 通道信息不相同
  127. }
  128. }
  129. return true;
  130. }
  131. bool DetectPeriodConfig_t::operator==(const DetectPeriodConfig_t &other) const
  132. {
  133. if(&other == this)
  134. {
  135. return true; // 自身比较
  136. }
  137. if( nID != other.nID ||
  138. isApplySlient != other.isApplySlient ||
  139. isApplyOverload != other.isApplyOverload ||
  140. isApplyPhase != other.isApplyPhase ||
  141. isApplyNoise != other.isApplyNoise ||
  142. listDetect.size() != other.listDetect.size() ||
  143. listNoDetect.size() != other.listNoDetect.size())
  144. {
  145. return false;
  146. }
  147. /* 详细对比列表中的每一项 */
  148. for(int i = 0; i < listDetect.size(); ++i)
  149. {
  150. const OnePlan_t& plan1 = listDetect.at(i);
  151. bool found = false;
  152. for(int j = 0; j < other.listDetect.size(); ++j)
  153. {
  154. const OnePlan_t& plan2 = other.listDetect.at(j);
  155. if(plan1 == plan2)
  156. {
  157. found = true;
  158. break; // 找到相同的计划
  159. }
  160. }
  161. if(!found)
  162. {
  163. return false; // 在other中找不到相同的检测计划
  164. }
  165. }
  166. /* 对比非检测计划 */
  167. for(int i = 0; i < listNoDetect.size(); ++i)
  168. {
  169. const OnePlan_t& plan1 = listNoDetect.at(i);
  170. bool found = false;
  171. for(int j = 0; j < other.listNoDetect.size(); ++j)
  172. {
  173. const OnePlan_t& plan2 = other.listNoDetect.at(j);
  174. if(plan1 == plan2)
  175. {
  176. found = true;
  177. break; // 找到相同的计划
  178. }
  179. }
  180. if(!found)
  181. {
  182. return false; // 在other中找不到相同的非检测计划
  183. }
  184. }
  185. return true;
  186. }
  187. /* 判断基础信息是否更改 */
  188. bool DetectPeriodConfig_t::isBaseInfoChanged(const DetectPeriodConfig_t &other) const
  189. {
  190. if(&other == this)
  191. {
  192. return false; // 自身比较
  193. }
  194. if(nID == other.nID &&
  195. isApplySlient == other.isApplySlient &&
  196. isApplyOverload == other.isApplyOverload &&
  197. isApplyPhase == other.isApplyPhase &&
  198. isApplyNoise == other.isApplyNoise)
  199. {
  200. return false;
  201. }
  202. return true;
  203. }
  204. /* =========================================================================================
  205. * 计算线程信息结构体
  206. * =========================================================================================*/
  207. CalculateThreadInfo_t::CalculateThreadInfo_t(const CalculateThreadInfo_t& info)
  208. {
  209. *this = info; // 使用赋值运算符进行深拷贝
  210. }
  211. CalculateThreadInfo_t& CalculateThreadInfo_t::operator=(const CalculateThreadInfo_t& info)
  212. {
  213. if(&info == this)
  214. {
  215. return *this; // 防止自赋值
  216. }
  217. compareItemInfo = info.compareItemInfo;
  218. threadState = info.threadState;
  219. threadType = info.threadType;
  220. // pThread = info.pThread;
  221. return *this;
  222. }
  223. /* =========================================================================================
  224. * 报警信息结构体
  225. * =========================================================================================*/
  226. AlarmInfo_t& AlarmInfo_t::operator=(const AlarmInfo_t& obj)
  227. {
  228. if (this == &obj)
  229. {
  230. return *this; // 防止自赋值
  231. }
  232. isAlarm = obj.isAlarm;
  233. CompareItemID = obj.CompareItemID;
  234. strCompareItemName = obj.strCompareItemName;
  235. RoadInfo = obj.RoadInfo;
  236. RoadType = obj.RoadType;
  237. AlarmType = obj.AlarmType;
  238. StartTime = obj.StartTime;
  239. EndTime = obj.EndTime;
  240. strAlarmFilePath = obj.strAlarmFilePath;
  241. AlarmStartPos = obj.AlarmStartPos;
  242. AlarmFileStartTime = obj.AlarmFileStartTime;
  243. return *this;
  244. }
  245. /* 比较是否相等,主要是比较是否报警、通道ID,报警类型,报警时间 */
  246. bool AlarmInfo_t::operator==(const AlarmInfo_t& other) const
  247. {
  248. return (isAlarm == other.isAlarm) &&
  249. (RoadInfo == other.RoadInfo) &&
  250. (AlarmType == other.AlarmType) &&
  251. (StartTime == other.StartTime) &&
  252. (EndTime == other.EndTime);
  253. }