123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- #include "ProtoCvt.h"
- #include "DBMgr.h"
- #include "StreamDef.h"
- #include "Logger.h"
- NAMESPACE_MAS_BEGIN
- void ProtoCvt::Json2Tbl(
- const UserInfo & from, TblUserInfoItem & to)
- {
- to.Tb_Username = from.Username;
- to.Tb_Password = from.Password;
- to.Tb_Role = from.Role;
- to.Tb_CreateTime = from.CreateTime;
- to.Tb_LoginTime = from.LoginTime;
- to.Tb_Description = from.Description;
- }
- void ProtoCvt::Tbl2Json(
- const TblUserInfoItem & from, UserInfo & to)
- {
- to.Username = from.Tb_Username;
- to.Password = from.Tb_Password;
- to.Role = from.Tb_Role;
- to.CreateTime = from.Tb_CreateTime;
- to.LoginTime = from.Tb_LoginTime;
- to.Description = from.Tb_Description;
- }
- void ProtoCvt::Json2Tbl(
- const SceneInfo & from, TblSceneInfoItem & to)
- {
- to.Tb_Id = from.Id;
- to.Tb_Name = from.Name;
- to.Tb_Enable = from.Enable;
- to.Tb_GpuEnable = from.GpuEnable;
- to.Tb_StrategyCfg = from.StrategyCfg;
- to.Tb_Description = from.Description;
- to.Tb_Label = from.Label;
- to.Tb_StrategyId = from.Strategy.Id;
- to.Tb_Confs = tzc::json::ArrayToJson(from.Confs);
- }
- void ProtoCvt::Tbl2Json(
- const TblSceneInfoItem & from, SceneInfo & to)
- {
- to.Id = from.Tb_Id;
- to.Name = from.Tb_Name;
- to.Enable = from.Tb_Enable;
- to.GpuEnable = from.Tb_GpuEnable;
- to.StrategyCfg = from.Tb_StrategyCfg;
- to.Description = from.Tb_Description;
- to.Label = from.Tb_Label;
- TblStrategyInfoItem tstrategy;
- tstrategy.Tb_Id = from.Tb_StrategyId;
- auto irst = DBMGR->QueryTblStrategyInfoByKey(tstrategy);
- if (irst)
- {
- TZLogWarn("query strategy by key %d failed!!!", from.Tb_StrategyId);
- return;
- }
- ProtoCvt::Tbl2Json(tstrategy, to.Strategy);
- std::list<TblSceneDetectorInfoItem> infos;
- sdb::QueryConditions qc(sdb::ValuePair(
- TblSceneDetectorInfo::COL_SCENE_ID, from.Tb_Id));
- ORDER_PAIR pair;
- irst = DBMGR->QueryTblSceneDetectorInfoByCd(qc, pair, infos);
- if (irst)
- {
- TZLogWarn("query scene det by sceneid %d failed!!!", from.Tb_Id);
- return;
- }
- for (auto & mem : infos)
- {
- SceneDetectorInfo info;
-
- ProtoCvt::Tbl2Json(mem, info);
- to.Confs.push_back(info);
- }
- }
- void ProtoCvt::Json2Tbl(
- const StrategyInfo & from, TblStrategyInfoItem & to)
- {
- to.Tb_Id = from.Id;
- to.Tb_Key = from.Key;
- to.Tb_Name = from.Name;
- to.Tb_Version = from.Version;
- to.Tb_Author = from.Author;
- to.Tb_Path = from.Path;
- to.Tb_Description = from.Description;
- to.Tb_StraDets = tzc::json::ArrayToJson(from.StraDets);
- to.Tb_StraCfgs= tzc::json::ArrayToJson(from.StraCfgs);
- to.Tb_StraRsts = tzc::json::ArrayToJson(from.StraRsts);
- }
- void ProtoCvt::Tbl2Json(
- const TblStrategyInfoItem & from, StrategyInfo & to)
- {
- to.Id = from.Tb_Id;
- to.Author = from.Tb_Author;
- to.Key = from.Tb_Key;
- to.Name = from.Tb_Name;
- to.Path = from.Tb_Path;
- to.Version = from.Tb_Version;
- to.Description = from.Tb_Description;
- tzc::json::JsonDoc document;
- document.Parse(from.Tb_StraDets.c_str());
- tzc::json::JsonToArray(document, to.StraDets);
- document.Parse(from.Tb_StraCfgs.c_str());
- tzc::json::JsonToArray(document, to.StraCfgs);
- document.Parse(from.Tb_StraRsts.c_str());
- tzc::json::JsonToArray(document, to.StraRsts);
- }
- void ProtoCvt::Json2Tbl(
- const SceneGroupInfo & from,
- TblSceneGroupItem & to,
- std::list<TblSgroupSceneItem> & rels)
- {
- to.Tb_Id = from.Id;
- to.Tb_Label = from.Label;
- to.Tb_Name = from.Name;
- for (auto & mem : from.Scenes)
- {
- TblSgroupSceneItem rel;
- rel.Tb_SceneGrpId = from.Id;
- rel.Tb_SceneId = mem.Id;
- rels.emplace_back(rel);
- }
- }
- void ProtoCvt::Tbl2Json(
- TblSceneGroupItem & from,
- std::list<TblSgroupSceneItem> & rels,
- SceneGroupInfo & to)
- {
- to.Id = from.Tb_Id;
- to.Label = from.Tb_Label;
- to.Name = from.Tb_Name;
- for (auto & mem : rels)
- {
- TblSceneInfoItem tscene;
- tscene.Tb_Id = mem.Tb_SceneId;
- auto irst = DBMGR->QueryTblSceneInfoByKey(tscene);
- if (irst) continue;
- SceneInfo info;
- ProtoCvt::Tbl2Json(tscene, info);
- to.Scenes.emplace_back(info);
- }
- }
- void ProtoCvt::Json2Tbl(
- const SysConfig & from, TblSysConfigItem & to)
- {
- to.Tb_ParamKey = from.ParamKey;
- to.Tb_ParamValue = from.ParamValue;
- to.Tb_ParamGroup = from.ParamGroup;
- }
- void ProtoCvt::Tbl2Json(
- const TblSysConfigItem & from, SysConfig & to)
- {
- to.ParamKey = from.Tb_ParamKey;
- to.ParamValue = from.Tb_ParamValue;
- to.ParamGroup = from.Tb_ParamGroup;
- }
- void ProtoCvt::Json2Tbl(
- const MediaSrcInfo & from, TblMediaSrcInfoItem & to)
- {
- to.Tb_Id = from.Id;
- to.Tb_Type = from.Type;
- to.Tb_Subtype = from.Subtype;
- to.Tb_Port = from.Port;
- to.Tb_Mode = from.Mode;
- to.Tb_Capability = from.Capability;
- to.Tb_Vendor = from.Vendor;
- to.Tb_Name = from.Name;
- to.Tb_Address = from.Address;
- to.Tb_Username = from.Username;
- to.Tb_Password = from.Password;
- to.Tb_Detail = from.Detail;
- to.Tb_Description = from.Description;
- }
- void ProtoCvt::Tbl2Json(
- const TblMediaSrcInfoItem & from, MediaSrcInfo & to)
- {
- to.Id = from.Tb_Id;
- to.Type = from.Tb_Type;
- to.Subtype = from.Tb_Subtype;
- to.Port = from.Tb_Port;
- to.Mode = from.Tb_Mode;
- to.Capability = from.Tb_Capability;
- to.Name = from.Tb_Name;
- to.Vendor = from.Tb_Vendor;
- to.Address = from.Tb_Address;
- to.Username = from.Tb_Username;
- to.Password = from.Tb_Password;
- to.Detail = from.Tb_Detail;
- to.Description = from.Tb_Description;
- }
- void ProtoCvt::Json2Tbl(
- const MediaRscInfo & from, TblMediaRscInfoItem & to)
- {
- to.Tb_Id = from.Id;
- to.Tb_Name = from.Name;
- to.Tb_SrcId = from.SrcId;
- to.Tb_Idx = from.Idx;
- to.Tb_RscType = from.RscType;
- to.Tb_TransFormat = from.TransFormat;
- to.Tb_EncodeFormat = from.EncodeFormat;
- to.Tb_StreamType = from.StreamType;
- }
- void ProtoCvt::Tbl2Json(
- const TblMediaRscInfoItem & from, MediaRscInfo & to)
- {
- to.Id = from.Tb_Id;
- to.Name = from.Tb_Name;
- to.SrcId = from.Tb_SrcId;
- to.Idx = from.Tb_Idx;
- to.RscType = from.Tb_RscType;
- to.TransFormat = from.Tb_TransFormat;
- to.EncodeFormat = from.Tb_EncodeFormat;
- to.StreamType = from.Tb_StreamType;
- }
- void ProtoCvt::Json2Tbl(
- const DetectorInfo & from, TblDetectorInfoItem & to)
- {
- to.Tb_Id = from.Id;
- to.Tb_Key = from.Key;
- to.Tb_Name = from.Name;
- to.Tb_Version = from.Version;
- to.Tb_Author = from.Author;
- to.Tb_RstTemp = from.RstTemp;
- to.Tb_ParamTemp = from.ParamTemp;
- to.Tb_BuildTemp = from.BuildTemp;
- to.Tb_AreaTemp = from.AreaTemp;
- to.Tb_InputType = from.InputType;
- to.Tb_Description = from.Description;
- to.Tb_Path = from.Path;
- to.Tb_InitParam = from.InitParam;
- }
- void ProtoCvt::Tbl2Json(
- const TblDetectorInfoItem & from, DetectorInfo & to)
- {
- to.Id = from.Tb_Id;
- to.Key = from.Tb_Key;
- to.Name = from.Tb_Name;
- to.Version = from.Tb_Version;
- to.Author = from.Tb_Author;
- to.Path = from.Tb_Path;
- to.InitParam = from.Tb_InitParam;
- to.RstTemp = from.Tb_RstTemp;
- to.ParamTemp = from.Tb_ParamTemp;
- to.BuildTemp = from.Tb_BuildTemp;
- to.InputType = from.Tb_InputType;
- to.AreaTemp = from.Tb_AreaTemp;
- to.Description = from.Tb_Description;
- }
- void ProtoCvt::Json2Tbl(
- const PlanInfo & from, TblPlanInfoItem & to)
- {
- to.Tb_Id = from.Id;
- to.Tb_Reverse = from.Reverse;
- to.Tb_Type = from.Type;
- to.Tb_Time = from.Time;
- to.Tb_Day = from.Day;
- to.Tb_Date = from.Date;
- to.Tb_Description = from.Description;
- to.Tb_SceneId = from.Scene.Id;
- }
- void ProtoCvt::Tbl2Json(
- const TblPlanInfoItem & from, PlanInfo & to)
- {
- to.Id = from.Tb_Id;
- to.Reverse = from.Tb_Reverse;
- to.Type = from.Tb_Type;
- to.Time = from.Tb_Time;
- to.Day = from.Tb_Day;
- to.Date = from.Tb_Date;
- to.Description = from.Tb_Description;
- to.Scene.Id = from.Tb_SceneId;
- }
- void ProtoCvt::Json2Tbl(
- const EventRecord & from, TblEventRecordItem & to)
- {
- to.Tb_Id = from.Id;
- to.Tb_SceneId = from.SceneId;
- to.Tb_BeginTime = from.BeginTime;
- to.Tb_EndTime = from.EndTime;
- to.Tb_Type = from.Type;
- to.Tb_Name = from.Name;
- to.Tb_Externs = from.Externs;
- to.Tb_SceneName = from.SceneName;
- to.Tb_StrategyName = from.StrategyName;
- to.Tb_Description = from.Description;
- }
- void ProtoCvt::Tbl2Json(
- const TblEventRecordItem & from, EventRecord & to)
- {
- to.Id = from.Tb_Id;
- to.SceneId = from.Tb_SceneId;
- to.BeginTime = from.Tb_BeginTime;
- to.EndTime = from.Tb_EndTime;
- to.Type = from.Tb_Type;
- to.Name = from.Tb_Name;
- to.Externs = from.Tb_Externs;
- to.SceneName = from.Tb_SceneName;
- to.StrategyName = from.Tb_StrategyName;
- to.Description = from.Tb_Description;
- }
- void ProtoCvt::Json2Tbl(
- const MediaRecord & from, TblMediaRecordItem & to)
- {
- to.Tb_Id = from.Id;
- to.Tb_RscId = from.RscId;
- to.Tb_Type = from.Type;
- to.Tb_CreateTime = from.CreateTime;
- to.Tb_Duration = from.Duration;
- to.Tb_Size = from.Size;
- to.Tb_Name = from.Name;
- to.Tb_Path = from.Path;
- to.Tb_Description = from.Description;
- }
- void ProtoCvt::Tbl2Json(
- const TblMediaRecordItem & from, MediaRecord & to)
- {
- to.Id = from.Tb_Id;
- to.RscId = from.Tb_RscId;
- to.Type = from.Tb_Type;
- to.CreateTime = from.Tb_CreateTime;
- to.Duration = from.Tb_Duration;
- to.Size = from.Tb_Size;
- to.Name = from.Tb_Name;
- to.Path = from.Tb_Path;
- to.Description = from.Tb_Description;
- }
- void ProtoCvt::Json2Tbl(
- const OpRecord & from, TblOpRecordItem & to)
- {
- to.Tb_Id = from.Id;
- to.Tb_Result = from.Result;
- to.Tb_OccurTime = from.OccurTime;
- to.Tb_Operation = from.Operation;
- to.Tb_Username = from.Username;
- to.Tb_UserAddr = from.UserAddr;
- to.Tb_Description = from.Description;
- }
- void ProtoCvt::Tbl2Json(
- const TblOpRecordItem & from, OpRecord & to)
- {
- to.Id = from.Tb_Id;
- to.Result = from.Tb_Result;
- to.OccurTime = from.Tb_OccurTime;
- to.Operation = from.Tb_Operation;
- to.Username = from.Tb_Username;
- to.UserAddr = from.Tb_UserAddr;
- to.Description = from.Tb_Description;
- }
- void ProtoCvt::Json2Tbl(
- const PerformanceRecord & from, TblPerformanceRecordItem & to)
- {
- to.Tb_Id = from.Id;
- to.Tb_RecordTime = from.RecordTime;
- to.Tb_Cpu = from.Cpu;
- to.Tb_Memory = from.Memory;
- to.Tb_Nic = from.Nic;
- to.Tb_GpuUtil = from.GpuUtil;
- to.Tb_GpuMemory = from.GpuMemory;
- to.Tb_Disk = from.Disk;
- }
- void ProtoCvt::Tbl2Json(
- const TblPerformanceRecordItem & from, PerformanceRecord & to)
- {
- to.Id = from.Tb_Id;
- to.RecordTime = from.Tb_RecordTime;
- to.Cpu = from.Tb_Cpu;
- to.Memory = from.Tb_Memory;
- to.Nic = from.Tb_Nic;
- to.GpuUtil = from.Tb_GpuUtil;
- to.GpuMemory = from.Tb_GpuMemory;
- to.Disk = from.Tb_Disk;
- }
- void ProtoCvt::Json2Tbl(
- const SceneDetectorInfo & from, TblSceneDetectorInfoItem & to)
- {
- to.Tb_Id = from.Id;
- to.Tb_SceneId = from.SceneId;
- to.Tb_DetectorId = from.DetectorId;
- to.Tb_RscId = from.RscId;
- to.Tb_Idx = from.Idx;
- to.Tb_SIdx = from.SIdx;
- to.Tb_DetectorCfg = from.DetectorCfg;
- to.Tb_Description = from.Description;
- }
- void ProtoCvt::Tbl2Json(
- const TblSceneDetectorInfoItem & from, SceneDetectorInfo & to)
- {
- to.Id = from.Tb_Id;
- to.SceneId = from.Tb_SceneId;
- to.DetectorId = from.Tb_DetectorId;
- to.RscId = from.Tb_RscId;
- to.Idx = from.Tb_Idx;
- to.SIdx = from.Tb_SIdx;
- to.DetectorCfg = from.Tb_DetectorCfg;
- to.Description = from.Tb_Description;
- }
- void ProtoCvt::Cvt(const class ExcepInfo & from, TZ_INT type,
- TZ_HANDLE handle, TZ_HANDLE shandle, PipeException & to)
- {
- to.Name = from.Name;
- to.Status = from.OutputState.load();
- to.Threshold = from.Threshold;
- to.Type = type;
- to.Tag = handle;
- to.SuperTag = shandle;
- }
- void ProtoCvt::Cvt(const QueryCondition & from,
- ORDER_PAIR & order, std::vector<sdb::ValuePair> & pairs)
- {
- order = from.Sorts.size() ?
- ORDER_PAIR{ from.Sorts.begin()->Key,
- sdb::EN_ORDER(from.Sorts.begin()->Value)} :
- ORDER_PAIR{ "", sdb::OT_ORDER };
- for (auto & mem : from.Predicates)
- {
- PUSH_CONDITION_VALUE_PAIR(pairs, mem.Key, mem.Value, mem.Code);
- }
- }
- NAMESPACE_MAS_END
|