143 lines
4.4 KiB
C++
143 lines
4.4 KiB
C++
#ifndef DATABASE_H
|
|
#define DATABASE_H
|
|
|
|
#include <QSqlDatabase>
|
|
#include <QObject>
|
|
#include <QUuid>
|
|
#include <QJsonObject>
|
|
|
|
struct availableID //可用id
|
|
{
|
|
int componentId = -1;
|
|
int pageId = -1;
|
|
int stationId = -1;
|
|
int gridId = -1;
|
|
int zoneId = -1;
|
|
int topoId = -1;
|
|
};
|
|
|
|
struct componentInfo
|
|
{
|
|
int id = 0;
|
|
QUuid uuid;
|
|
QString nspath;
|
|
QString tag;
|
|
QString name;
|
|
QString description;
|
|
QString grid;
|
|
QString zone;
|
|
QString station;
|
|
int type = 0;
|
|
bool inService = true;
|
|
int state = 0;
|
|
QJsonObject connected_bus;
|
|
QJsonObject label;
|
|
QJsonObject context;
|
|
int page_id = 0;
|
|
int op = 0;
|
|
componentInfo& operator=(const componentInfo& obj)
|
|
{
|
|
if(this == &obj)
|
|
return *this;
|
|
id = obj.id;
|
|
uuid = obj.uuid;
|
|
nspath = obj.nspath;
|
|
tag = obj.tag;
|
|
name = obj.name;
|
|
description = obj.description;
|
|
grid = obj.grid;
|
|
zone = obj.zone;
|
|
station = obj.station;
|
|
type = obj.type;
|
|
inService = obj.inService;
|
|
state = obj.state;
|
|
connected_bus = obj.connected_bus;
|
|
label = obj.label;
|
|
context = obj.context;
|
|
page_id = obj.page_id;
|
|
op = obj.op;
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
struct busStability
|
|
{
|
|
int componentId = 0;
|
|
double resistance = 0;
|
|
bool anchor_v = false;
|
|
double uv_alarm = 0;
|
|
double ov_alarm = 0;
|
|
bool anchor_i = false;
|
|
double ui_alarm = 0;
|
|
double oi_alarm = 0;
|
|
busStability& operator=(const busStability& obj)
|
|
{
|
|
if(this == &obj)
|
|
return *this;
|
|
componentId = obj.componentId;
|
|
resistance = obj.resistance;
|
|
anchor_v = obj.anchor_v;
|
|
uv_alarm = obj.uv_alarm;
|
|
ov_alarm = obj.ov_alarm;
|
|
anchor_i = obj.anchor_i;
|
|
ui_alarm = obj.ui_alarm;
|
|
oi_alarm = obj.oi_alarm;
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
class DataBase
|
|
{
|
|
//Q_OBJECT
|
|
public:
|
|
DataBase();
|
|
~DataBase();
|
|
static DataBase* GetInstance();
|
|
public:
|
|
availableID structID;
|
|
public:
|
|
void updateId();
|
|
bool insertPage(QString tag,QString name,int status,QJsonObject label,QJsonObject context,QString description,int op);
|
|
bool insertStation(int zoneId,QString name,QString description,bool isLocal,int op);
|
|
bool insertGrid(QString name,QString description,int op);
|
|
bool insertZone(int grid_id,QString name,QString description,int op);
|
|
bool insertTopologic(int page_id,QUuid uuid_from,QUuid uuid_to,int flag,QString description,int op);
|
|
|
|
bool insertBus_stability(int componentId,double resistance,bool anchor_v,double uv_alarm,double ov_alarm,bool anchor_i,double ui_alarm,double oi_alarm,int op);
|
|
bool updateBus_stability(int componentId,double resistance,bool anchor_v,double uv_alarm,double ov_alarm,bool anchor_i,double ui_alarm,double oi_alarm,int op);
|
|
busStability getBusStabilityById(int componentId);
|
|
/*********************************************************************************/
|
|
bool updateComponent(QUuid uuid,QString tag,QString name,QJsonObject context);
|
|
bool insertComponent(QUuid uuid,QString nspath,QString tag,QString name,QString description,QString grid,QString zone,QString station,int type,bool inService,int state,QJsonObject connected_bus,QJsonObject label,QJsonObject context,int page_id,int op);
|
|
componentInfo getComponentInfoByUuid(QString uuid);
|
|
QList<componentInfo> getAllComponents();
|
|
bool componentExist(QString uuid);
|
|
bool deleteComponent(QString uuid);
|
|
|
|
/*********************************************************************************/
|
|
int getPageIdByName(QString name);
|
|
bool updatePage(QString tag,QString name,QJsonObject context);
|
|
QJsonObject getPageContextByName(QString name);
|
|
QStringList getAllPage();
|
|
/*********************************************************************************/
|
|
bool deleteComponentById(int id);
|
|
void select();
|
|
void parallelUpdate();
|
|
|
|
QJsonObject QstringToJson(QString jsonString);
|
|
private:
|
|
void initial();
|
|
void readXML();
|
|
static DataBase* instance;
|
|
static int _id;
|
|
QSqlDatabase db;
|
|
QString m_sFileName;
|
|
QString _DataBaseType;
|
|
QString _DataBaseName;
|
|
QString _HostName;
|
|
int _Port;
|
|
QString _UserName;
|
|
QString _PassWord;
|
|
};
|
|
#endif // DATABASE_H
|