ProtoCvt.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. #include "ProtoCvt.h"
  2. #include "DBMgr.h"
  3. #include "StreamDef.h"
  4. #include "Logger.h"
  5. NAMESPACE_MAS_BEGIN
  6. void ProtoCvt::Json2Tbl(
  7. const UserInfo & from, TblUserInfoItem & to)
  8. {
  9. to.Tb_Username = from.Username;
  10. to.Tb_Password = from.Password;
  11. to.Tb_Role = from.Role;
  12. to.Tb_CreateTime = from.CreateTime;
  13. to.Tb_LoginTime = from.LoginTime;
  14. to.Tb_Description = from.Description;
  15. }
  16. void ProtoCvt::Tbl2Json(
  17. const TblUserInfoItem & from, UserInfo & to)
  18. {
  19. to.Username = from.Tb_Username;
  20. to.Password = from.Tb_Password;
  21. to.Role = from.Tb_Role;
  22. to.CreateTime = from.Tb_CreateTime;
  23. to.LoginTime = from.Tb_LoginTime;
  24. to.Description = from.Tb_Description;
  25. }
  26. void ProtoCvt::Json2Tbl(
  27. const SceneInfo & from, TblSceneInfoItem & to)
  28. {
  29. to.Tb_Id = from.Id;
  30. to.Tb_Name = from.Name;
  31. to.Tb_Enable = from.Enable;
  32. to.Tb_GpuEnable = from.GpuEnable;
  33. to.Tb_StrategyCfg = from.StrategyCfg;
  34. to.Tb_Description = from.Description;
  35. to.Tb_Label = from.Label;
  36. to.Tb_StrategyId = from.Strategy.Id;
  37. to.Tb_Confs = tzc::json::ArrayToJson(from.Confs);
  38. }
  39. void ProtoCvt::Tbl2Json(
  40. const TblSceneInfoItem & from, SceneInfo & to)
  41. {
  42. to.Id = from.Tb_Id;
  43. to.Name = from.Tb_Name;
  44. to.Enable = from.Tb_Enable;
  45. to.GpuEnable = from.Tb_GpuEnable;
  46. to.StrategyCfg = from.Tb_StrategyCfg;
  47. to.Description = from.Tb_Description;
  48. to.Label = from.Tb_Label;
  49. TblStrategyInfoItem tstrategy;
  50. tstrategy.Tb_Id = from.Tb_StrategyId;
  51. auto irst = DBMGR->QueryTblStrategyInfoByKey(tstrategy);
  52. if (irst)
  53. {
  54. TZLogWarn("query strategy by key %d failed!!!", from.Tb_StrategyId);
  55. return;
  56. }
  57. ProtoCvt::Tbl2Json(tstrategy, to.Strategy);
  58. std::list<TblSceneDetectorInfoItem> infos;
  59. sdb::QueryConditions qc(sdb::ValuePair(
  60. TblSceneDetectorInfo::COL_SCENE_ID, from.Tb_Id));
  61. ORDER_PAIR pair;
  62. irst = DBMGR->QueryTblSceneDetectorInfoByCd(qc, pair, infos);
  63. if (irst)
  64. {
  65. TZLogWarn("query scene det by sceneid %d failed!!!", from.Tb_Id);
  66. return;
  67. }
  68. for (auto & mem : infos)
  69. {
  70. SceneDetectorInfo info;
  71. ProtoCvt::Tbl2Json(mem, info);
  72. to.Confs.push_back(info);
  73. }
  74. }
  75. void ProtoCvt::Json2Tbl(
  76. const StrategyInfo & from, TblStrategyInfoItem & to)
  77. {
  78. to.Tb_Id = from.Id;
  79. to.Tb_Key = from.Key;
  80. to.Tb_Name = from.Name;
  81. to.Tb_Version = from.Version;
  82. to.Tb_Author = from.Author;
  83. to.Tb_Path = from.Path;
  84. to.Tb_Description = from.Description;
  85. to.Tb_StraDets = tzc::json::ArrayToJson(from.StraDets);
  86. to.Tb_StraCfgs= tzc::json::ArrayToJson(from.StraCfgs);
  87. to.Tb_StraRsts = tzc::json::ArrayToJson(from.StraRsts);
  88. }
  89. void ProtoCvt::Tbl2Json(
  90. const TblStrategyInfoItem & from, StrategyInfo & to)
  91. {
  92. to.Id = from.Tb_Id;
  93. to.Author = from.Tb_Author;
  94. to.Key = from.Tb_Key;
  95. to.Name = from.Tb_Name;
  96. to.Path = from.Tb_Path;
  97. to.Version = from.Tb_Version;
  98. to.Description = from.Tb_Description;
  99. tzc::json::JsonDoc document;
  100. document.Parse(from.Tb_StraDets.c_str());
  101. tzc::json::JsonToArray(document, to.StraDets);
  102. document.Parse(from.Tb_StraCfgs.c_str());
  103. tzc::json::JsonToArray(document, to.StraCfgs);
  104. document.Parse(from.Tb_StraRsts.c_str());
  105. tzc::json::JsonToArray(document, to.StraRsts);
  106. }
  107. void ProtoCvt::Json2Tbl(
  108. const SceneGroupInfo & from,
  109. TblSceneGroupItem & to,
  110. std::list<TblSgroupSceneItem> & rels)
  111. {
  112. to.Tb_Id = from.Id;
  113. to.Tb_Label = from.Label;
  114. to.Tb_Name = from.Name;
  115. for (auto & mem : from.Scenes)
  116. {
  117. TblSgroupSceneItem rel;
  118. rel.Tb_SceneGrpId = from.Id;
  119. rel.Tb_SceneId = mem.Id;
  120. rels.emplace_back(rel);
  121. }
  122. }
  123. void ProtoCvt::Tbl2Json(
  124. TblSceneGroupItem & from,
  125. std::list<TblSgroupSceneItem> & rels,
  126. SceneGroupInfo & to)
  127. {
  128. to.Id = from.Tb_Id;
  129. to.Label = from.Tb_Label;
  130. to.Name = from.Tb_Name;
  131. for (auto & mem : rels)
  132. {
  133. TblSceneInfoItem tscene;
  134. tscene.Tb_Id = mem.Tb_SceneId;
  135. auto irst = DBMGR->QueryTblSceneInfoByKey(tscene);
  136. if (irst) continue;
  137. SceneInfo info;
  138. ProtoCvt::Tbl2Json(tscene, info);
  139. to.Scenes.emplace_back(info);
  140. }
  141. }
  142. void ProtoCvt::Json2Tbl(
  143. const SysConfig & from, TblSysConfigItem & to)
  144. {
  145. to.Tb_ParamKey = from.ParamKey;
  146. to.Tb_ParamValue = from.ParamValue;
  147. to.Tb_ParamGroup = from.ParamGroup;
  148. }
  149. void ProtoCvt::Tbl2Json(
  150. const TblSysConfigItem & from, SysConfig & to)
  151. {
  152. to.ParamKey = from.Tb_ParamKey;
  153. to.ParamValue = from.Tb_ParamValue;
  154. to.ParamGroup = from.Tb_ParamGroup;
  155. }
  156. void ProtoCvt::Json2Tbl(
  157. const MediaSrcInfo & from, TblMediaSrcInfoItem & to)
  158. {
  159. to.Tb_Id = from.Id;
  160. to.Tb_Type = from.Type;
  161. to.Tb_Subtype = from.Subtype;
  162. to.Tb_Port = from.Port;
  163. to.Tb_Mode = from.Mode;
  164. to.Tb_Capability = from.Capability;
  165. to.Tb_Vendor = from.Vendor;
  166. to.Tb_Name = from.Name;
  167. to.Tb_Address = from.Address;
  168. to.Tb_Username = from.Username;
  169. to.Tb_Password = from.Password;
  170. to.Tb_Detail = from.Detail;
  171. to.Tb_Description = from.Description;
  172. }
  173. void ProtoCvt::Tbl2Json(
  174. const TblMediaSrcInfoItem & from, MediaSrcInfo & to)
  175. {
  176. to.Id = from.Tb_Id;
  177. to.Type = from.Tb_Type;
  178. to.Subtype = from.Tb_Subtype;
  179. to.Port = from.Tb_Port;
  180. to.Mode = from.Tb_Mode;
  181. to.Capability = from.Tb_Capability;
  182. to.Name = from.Tb_Name;
  183. to.Vendor = from.Tb_Vendor;
  184. to.Address = from.Tb_Address;
  185. to.Username = from.Tb_Username;
  186. to.Password = from.Tb_Password;
  187. to.Detail = from.Tb_Detail;
  188. to.Description = from.Tb_Description;
  189. }
  190. void ProtoCvt::Json2Tbl(
  191. const MediaRscInfo & from, TblMediaRscInfoItem & to)
  192. {
  193. to.Tb_Id = from.Id;
  194. to.Tb_Name = from.Name;
  195. to.Tb_SrcId = from.SrcId;
  196. to.Tb_Idx = from.Idx;
  197. to.Tb_RscType = from.RscType;
  198. to.Tb_TransFormat = from.TransFormat;
  199. to.Tb_EncodeFormat = from.EncodeFormat;
  200. to.Tb_StreamType = from.StreamType;
  201. }
  202. void ProtoCvt::Tbl2Json(
  203. const TblMediaRscInfoItem & from, MediaRscInfo & to)
  204. {
  205. to.Id = from.Tb_Id;
  206. to.Name = from.Tb_Name;
  207. to.SrcId = from.Tb_SrcId;
  208. to.Idx = from.Tb_Idx;
  209. to.RscType = from.Tb_RscType;
  210. to.TransFormat = from.Tb_TransFormat;
  211. to.EncodeFormat = from.Tb_EncodeFormat;
  212. to.StreamType = from.Tb_StreamType;
  213. }
  214. void ProtoCvt::Json2Tbl(
  215. const DetectorInfo & from, TblDetectorInfoItem & to)
  216. {
  217. to.Tb_Id = from.Id;
  218. to.Tb_Key = from.Key;
  219. to.Tb_Name = from.Name;
  220. to.Tb_Version = from.Version;
  221. to.Tb_Author = from.Author;
  222. to.Tb_RstTemp = from.RstTemp;
  223. to.Tb_ParamTemp = from.ParamTemp;
  224. to.Tb_BuildTemp = from.BuildTemp;
  225. to.Tb_AreaTemp = from.AreaTemp;
  226. to.Tb_InputType = from.InputType;
  227. to.Tb_Description = from.Description;
  228. to.Tb_Path = from.Path;
  229. to.Tb_InitParam = from.InitParam;
  230. }
  231. void ProtoCvt::Tbl2Json(
  232. const TblDetectorInfoItem & from, DetectorInfo & to)
  233. {
  234. to.Id = from.Tb_Id;
  235. to.Key = from.Tb_Key;
  236. to.Name = from.Tb_Name;
  237. to.Version = from.Tb_Version;
  238. to.Author = from.Tb_Author;
  239. to.Path = from.Tb_Path;
  240. to.InitParam = from.Tb_InitParam;
  241. to.RstTemp = from.Tb_RstTemp;
  242. to.ParamTemp = from.Tb_ParamTemp;
  243. to.BuildTemp = from.Tb_BuildTemp;
  244. to.InputType = from.Tb_InputType;
  245. to.AreaTemp = from.Tb_AreaTemp;
  246. to.Description = from.Tb_Description;
  247. }
  248. void ProtoCvt::Json2Tbl(
  249. const PlanInfo & from, TblPlanInfoItem & to)
  250. {
  251. to.Tb_Id = from.Id;
  252. to.Tb_Reverse = from.Reverse;
  253. to.Tb_Type = from.Type;
  254. to.Tb_Time = from.Time;
  255. to.Tb_Day = from.Day;
  256. to.Tb_Date = from.Date;
  257. to.Tb_Description = from.Description;
  258. to.Tb_SceneId = from.Scene.Id;
  259. }
  260. void ProtoCvt::Tbl2Json(
  261. const TblPlanInfoItem & from, PlanInfo & to)
  262. {
  263. to.Id = from.Tb_Id;
  264. to.Reverse = from.Tb_Reverse;
  265. to.Type = from.Tb_Type;
  266. to.Time = from.Tb_Time;
  267. to.Day = from.Tb_Day;
  268. to.Date = from.Tb_Date;
  269. to.Description = from.Tb_Description;
  270. to.Scene.Id = from.Tb_SceneId;
  271. }
  272. void ProtoCvt::Json2Tbl(
  273. const EventRecord & from, TblEventRecordItem & to)
  274. {
  275. to.Tb_Id = from.Id;
  276. to.Tb_SceneId = from.SceneId;
  277. to.Tb_BeginTime = from.BeginTime;
  278. to.Tb_EndTime = from.EndTime;
  279. to.Tb_Type = from.Type;
  280. to.Tb_Name = from.Name;
  281. to.Tb_Externs = from.Externs;
  282. to.Tb_SceneName = from.SceneName;
  283. to.Tb_StrategyName = from.StrategyName;
  284. to.Tb_Description = from.Description;
  285. }
  286. void ProtoCvt::Tbl2Json(
  287. const TblEventRecordItem & from, EventRecord & to)
  288. {
  289. to.Id = from.Tb_Id;
  290. to.SceneId = from.Tb_SceneId;
  291. to.BeginTime = from.Tb_BeginTime;
  292. to.EndTime = from.Tb_EndTime;
  293. to.Type = from.Tb_Type;
  294. to.Name = from.Tb_Name;
  295. to.Externs = from.Tb_Externs;
  296. to.SceneName = from.Tb_SceneName;
  297. to.StrategyName = from.Tb_StrategyName;
  298. to.Description = from.Tb_Description;
  299. }
  300. void ProtoCvt::Json2Tbl(
  301. const MediaRecord & from, TblMediaRecordItem & to)
  302. {
  303. to.Tb_Id = from.Id;
  304. to.Tb_RscId = from.RscId;
  305. to.Tb_Type = from.Type;
  306. to.Tb_CreateTime = from.CreateTime;
  307. to.Tb_Duration = from.Duration;
  308. to.Tb_Size = from.Size;
  309. to.Tb_Name = from.Name;
  310. to.Tb_Path = from.Path;
  311. to.Tb_Description = from.Description;
  312. }
  313. void ProtoCvt::Tbl2Json(
  314. const TblMediaRecordItem & from, MediaRecord & to)
  315. {
  316. to.Id = from.Tb_Id;
  317. to.RscId = from.Tb_RscId;
  318. to.Type = from.Tb_Type;
  319. to.CreateTime = from.Tb_CreateTime;
  320. to.Duration = from.Tb_Duration;
  321. to.Size = from.Tb_Size;
  322. to.Name = from.Tb_Name;
  323. to.Path = from.Tb_Path;
  324. to.Description = from.Tb_Description;
  325. }
  326. void ProtoCvt::Json2Tbl(
  327. const OpRecord & from, TblOpRecordItem & to)
  328. {
  329. to.Tb_Id = from.Id;
  330. to.Tb_Result = from.Result;
  331. to.Tb_OccurTime = from.OccurTime;
  332. to.Tb_Operation = from.Operation;
  333. to.Tb_Username = from.Username;
  334. to.Tb_UserAddr = from.UserAddr;
  335. to.Tb_Description = from.Description;
  336. }
  337. void ProtoCvt::Tbl2Json(
  338. const TblOpRecordItem & from, OpRecord & to)
  339. {
  340. to.Id = from.Tb_Id;
  341. to.Result = from.Tb_Result;
  342. to.OccurTime = from.Tb_OccurTime;
  343. to.Operation = from.Tb_Operation;
  344. to.Username = from.Tb_Username;
  345. to.UserAddr = from.Tb_UserAddr;
  346. to.Description = from.Tb_Description;
  347. }
  348. void ProtoCvt::Json2Tbl(
  349. const PerformanceRecord & from, TblPerformanceRecordItem & to)
  350. {
  351. to.Tb_Id = from.Id;
  352. to.Tb_RecordTime = from.RecordTime;
  353. to.Tb_Cpu = from.Cpu;
  354. to.Tb_Memory = from.Memory;
  355. to.Tb_Nic = from.Nic;
  356. to.Tb_GpuUtil = from.GpuUtil;
  357. to.Tb_GpuMemory = from.GpuMemory;
  358. to.Tb_Disk = from.Disk;
  359. }
  360. void ProtoCvt::Tbl2Json(
  361. const TblPerformanceRecordItem & from, PerformanceRecord & to)
  362. {
  363. to.Id = from.Tb_Id;
  364. to.RecordTime = from.Tb_RecordTime;
  365. to.Cpu = from.Tb_Cpu;
  366. to.Memory = from.Tb_Memory;
  367. to.Nic = from.Tb_Nic;
  368. to.GpuUtil = from.Tb_GpuUtil;
  369. to.GpuMemory = from.Tb_GpuMemory;
  370. to.Disk = from.Tb_Disk;
  371. }
  372. void ProtoCvt::Json2Tbl(
  373. const SceneDetectorInfo & from, TblSceneDetectorInfoItem & to)
  374. {
  375. to.Tb_Id = from.Id;
  376. to.Tb_SceneId = from.SceneId;
  377. to.Tb_DetectorId = from.DetectorId;
  378. to.Tb_RscId = from.RscId;
  379. to.Tb_Idx = from.Idx;
  380. to.Tb_SIdx = from.SIdx;
  381. to.Tb_DetectorCfg = from.DetectorCfg;
  382. to.Tb_Description = from.Description;
  383. }
  384. void ProtoCvt::Tbl2Json(
  385. const TblSceneDetectorInfoItem & from, SceneDetectorInfo & to)
  386. {
  387. to.Id = from.Tb_Id;
  388. to.SceneId = from.Tb_SceneId;
  389. to.DetectorId = from.Tb_DetectorId;
  390. to.RscId = from.Tb_RscId;
  391. to.Idx = from.Tb_Idx;
  392. to.SIdx = from.Tb_SIdx;
  393. to.DetectorCfg = from.Tb_DetectorCfg;
  394. to.Description = from.Tb_Description;
  395. }
  396. void ProtoCvt::Cvt(const class ExcepInfo & from, TZ_INT type,
  397. TZ_HANDLE handle, TZ_HANDLE shandle, PipeException & to)
  398. {
  399. to.Name = from.Name;
  400. to.Status = from.OutputState.load();
  401. to.Threshold = from.Threshold;
  402. to.Type = type;
  403. to.Tag = handle;
  404. to.SuperTag = shandle;
  405. }
  406. void ProtoCvt::Cvt(const QueryCondition & from,
  407. ORDER_PAIR & order, std::vector<sdb::ValuePair> & pairs)
  408. {
  409. order = from.Sorts.size() ?
  410. ORDER_PAIR{ from.Sorts.begin()->Key,
  411. sdb::EN_ORDER(from.Sorts.begin()->Value)} :
  412. ORDER_PAIR{ "", sdb::OT_ORDER };
  413. for (auto & mem : from.Predicates)
  414. {
  415. PUSH_CONDITION_VALUE_PAIR(pairs, mem.Key, mem.Value, mem.Code);
  416. }
  417. }
  418. NAMESPACE_MAS_END