#ifndef VSSCHANNELTBL_MANAGER_H #define VSSCHANNELTBL_MANAGER_H #include "../model/VssChannelTbl.h" #include "BaseDao.h" #define VSSChannelTbl_TABLE_NAME "VSSChannelTbl" /** * 创建二级设备表管理类 */ class VssChannelTblDao : public BaseDao { private: /** 创建二级设备表构造函数 */ VssChannelTblDao() {} public: /** 创建二级设备表单例模式 */ static VssChannelTblDao* instance() { static VssChannelTblDao instance; return &instance; } /** 添加创建二级设备表 keyValuesToAdd 需要添加的列名和列值对map*/ mysqlpp::SimpleResult addVssChannelTbl(std::map& keyValuesToAdd) { QMutexLocker mutexLocker(&m_mutexVisit); return add(keyValuesToAdd, VSSChannelTbl_TABLE_NAME); } /** 删除创建二级设备表 whereKey 列名;whereValue 列值 */ bool deleteByColumn(string whereKey, string whereValue) { std::map whereKeyValues; whereKeyValues[whereKey] = whereValue; return deleteVssChannelTbl(whereKeyValues); } /** 删除创建二级设备表 whereColumnNameValues 列名和列值对条件 */ bool deleteVssChannelTbl(std::map& whereKeyValues) { QMutexLocker mutexLocker(&m_mutexVisit); return del(VSSChannelTbl_TABLE_NAME, whereKeyValues); } /** 更新创建二级设备表 keyValuesToUpdate 需要更新的列名和列值对; whereKeyValues 列名和列值条件 */ bool updateVssChannelTbl(std::map& keyValuesToUpdate, std::map& whereKeyValues) { QMutexLocker mutexLocker(&m_mutexVisit); return update(keyValuesToUpdate, VSSChannelTbl_TABLE_NAME, whereKeyValues); } /** 更新创建二级设备表 keyValuesToUpdate 需要更新的列名和列值对; whereKeyValues 列名和列值条件 */ bool updateVssChannelTbl(std::map& keyValuesToUpdate, string whereKey, string whereValue) { std::map whereKeyValues; whereKeyValues[whereKey] = whereValue; return update(keyValuesToUpdate, VSSChannelTbl_TABLE_NAME, whereKeyValues); } /** 查询创建二级设备表列表 querySql 要查询的sql语句 */ vector findVssChannelTblList(string querySql) { QMutexLocker mutexLocker(&m_mutexVisit); vector vssChannelTblVec; vector> rowDatList = findList(querySql); vssChannelTblVec.reserve(rowDatList.size()); for (auto rowData : rowDatList) { vssChannelTblVec.emplace_back(mapToModel(rowData)); } return vssChannelTblVec; } /**查询创建二级设备表列表 whereKeyValues 列名和列值对条件 */ vector findVssChannelTblList(std::map& whereKeyValues) { return findVssChannelTblList(string("select * from ") + VSSChannelTbl_TABLE_NAME + " where 1=1 " + getWhereColumnNameValuePair(whereKeyValues)); } /**查询所有创建二级设备表列表 */ vector findAllVssChannelTblList() { return findVssChannelTblList(string("select * from ") + VSSChannelTbl_TABLE_NAME + " where 1=1 "); } /** 查询map列表 querySql 要查询的sql语句 */ vector> findMapList(string querySql) { return findList(querySql); } /** 执行sql语句 */ bool execute(string sql) { QMutexLocker mutexLocker(&m_mutexVisit); return exec(move(sql)); } /** map转model类 */ VssChannelTbl mapToModel(map& rowData) { VssChannelTbl vssChannelTbl; string IDValue = rowData[VssChannelTbl_ID]; if (IDValue.length() != 0 && IDValue != "NULL") { vssChannelTbl.ID = std::stoi(IDValue); } string DevPubIDValue = rowData[VssChannelTbl_DevPubID]; if (DevPubIDValue.length() != 0 && DevPubIDValue != "NULL") { vssChannelTbl.DevPubID = DevPubIDValue; } string NicknameValue = rowData[VssChannelTbl_Nickname]; if (NicknameValue.length() != 0 && NicknameValue != "NULL") { vssChannelTbl.Nickname = NicknameValue; } string ChanPubIDValue = rowData[VssChannelTbl_ChanPubID]; if (ChanPubIDValue.length() != 0 && ChanPubIDValue != "NULL") { vssChannelTbl.ChanPubID = ChanPubIDValue; } string AliveValue = rowData[VssChannelTbl_Alive]; if (AliveValue.length() != 0 && AliveValue != "NULL") { vssChannelTbl.Alive = std::stoi(AliveValue); } string CorpIDValue = rowData[VssChannelTbl_CorpID]; if (CorpIDValue.length() != 0 && CorpIDValue != "NULL") { vssChannelTbl.CorpID = CorpIDValue; } string ModelValue = rowData[VssChannelTbl_Model]; if (ModelValue.length() != 0 && ModelValue != "NULL") { vssChannelTbl.Model = ModelValue; } string OwnerValue = rowData[VssChannelTbl_Owner]; if (OwnerValue.length() != 0 && OwnerValue != "NULL") { vssChannelTbl.Owner = OwnerValue; } string CivilCodeValue = rowData[VssChannelTbl_CivilCode]; if (CivilCodeValue.length() != 0 && CivilCodeValue != "NULL") { vssChannelTbl.CivilCode = CivilCodeValue; } string AddressValue = rowData[VssChannelTbl_Address]; if (AddressValue.length() != 0 && AddressValue != "NULL") { vssChannelTbl.Address = AddressValue; } string ParentalValue = rowData[VssChannelTbl_Parental]; if (ParentalValue.length() != 0 && ParentalValue != "NULL") { vssChannelTbl.Parental = std::stoi(ParentalValue); } string ParentIdValue = rowData[VssChannelTbl_ParentId]; if (ParentIdValue.length() != 0 && ParentIdValue != "NULL") { vssChannelTbl.ParentId = ParentIdValue; } string IPValue = rowData[VssChannelTbl_IP]; if (IPValue.length() != 0 && IPValue != "NULL") { vssChannelTbl.IP = IPValue; } string PortValue = rowData[VssChannelTbl_Port]; if (PortValue.length() != 0 && PortValue != "NULL") { vssChannelTbl.Port = std::stoi(PortValue); } string LongitudeValue = rowData[VssChannelTbl_Longitude]; if (LongitudeValue.length() != 0 && LongitudeValue != "NULL") { vssChannelTbl.Longitude = std::stod(LongitudeValue); } string LatitudeValue = rowData[VssChannelTbl_Latitude]; if (LatitudeValue.length() != 0 && LatitudeValue != "NULL") { vssChannelTbl.Latitude = std::stod(LatitudeValue); } string AltitudeValue = rowData[VssChannelTbl_Altitude]; if (AltitudeValue.length() != 0 && AltitudeValue != "NULL") { vssChannelTbl.Altitude = std::stod(AltitudeValue); } string PTZTypeValue = rowData[VssChannelTbl_PTZType]; if (PTZTypeValue.length() != 0 && PTZTypeValue != "NULL") { vssChannelTbl.PTZType = std::stoi(PTZTypeValue); } string RoomTypeValue = rowData[VssChannelTbl_RoomType]; if (RoomTypeValue.length() != 0 && RoomTypeValue != "NULL") { vssChannelTbl.RoomType = std::stoi(RoomTypeValue); } string DirectionTypeValue = rowData[VssChannelTbl_DirectionType]; if (DirectionTypeValue.length() != 0 && DirectionTypeValue != "NULL") { vssChannelTbl.DirectionType = std::stoi(DirectionTypeValue); } string StreamTypeValue = rowData[VssChannelTbl_StreamType]; if (StreamTypeValue.length() != 0 && StreamTypeValue != "NULL") { vssChannelTbl.StreamType = std::stoi(StreamTypeValue); } string DMarkerValue = rowData[VssChannelTbl_DMarker]; if (DMarkerValue.length() != 0 && DMarkerValue != "NULL") { vssChannelTbl.DMarker = std::stoi(DMarkerValue); } string UpdateTimeValue = rowData[VssChannelTbl_UpdateTime]; if (UpdateTimeValue.length() != 0 && UpdateTimeValue != "NULL") { vssChannelTbl.UpdateTime = UpdateTimeValue; } return vssChannelTbl; } }; #endif //VSSCHANNELTBL_MANAGER_H