2025-02-06 16:36:50 +08:00
|
|
|
#ifndef DATABASE_H
|
|
|
|
|
#define DATABASE_H
|
|
|
|
|
|
|
|
|
|
#include <QSqlDatabase>
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QUuid>
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
2025-03-04 09:44:03 +08:00
|
|
|
struct attributeGroup //属性组(元模)
|
|
|
|
|
{
|
|
|
|
|
int id = 0;
|
|
|
|
|
QString group;
|
|
|
|
|
QString groupName;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct dataType //数据类型(元模)
|
|
|
|
|
{
|
|
|
|
|
int id = 0;
|
|
|
|
|
QString dataType;
|
|
|
|
|
QString databaseType;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct attribute //属性表(元模属性字段)
|
|
|
|
|
{
|
|
|
|
|
int id = 0;
|
|
|
|
|
QString attribute; //属性名
|
2025-03-07 19:24:19 +08:00
|
|
|
int dataType; //数据类型
|
2025-03-04 09:44:03 +08:00
|
|
|
int lengthPrecision=0; //长度限制(varchar)
|
|
|
|
|
int scale=0; //小数点位数
|
|
|
|
|
QString defaultValue; //默认值
|
|
|
|
|
QString valueRange; //数值范围
|
|
|
|
|
int attributeGroup=0; //属性组
|
|
|
|
|
int isNotNull=0; //是否非空
|
2025-03-07 19:24:19 +08:00
|
|
|
int isIndex=0; //是否index
|
2025-03-04 09:44:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct modelAttribute //模型-属性对应表(元模在此表查找)
|
|
|
|
|
{
|
|
|
|
|
int id = 0;
|
|
|
|
|
QString modelType; //元模名
|
|
|
|
|
int attributeId; //属性id
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct modelConnectivity //模型连接性表(元模是否可以连接)
|
|
|
|
|
{
|
|
|
|
|
int id = 0;
|
|
|
|
|
QString fromModel; //属性名
|
|
|
|
|
QString toModel;
|
|
|
|
|
int connectivity=0; //是否可连
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//==================================================
|
2025-02-06 16:36:50 +08:00
|
|
|
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);
|
2025-03-04 09:44:03 +08:00
|
|
|
public:
|
|
|
|
|
//***********元模
|
|
|
|
|
bool getAttributeGroup(); //获取属性组信息
|
|
|
|
|
bool getDataType(); //获取数据类型信息
|
|
|
|
|
bool getAttribute(); //获取属性
|
|
|
|
|
bool getModelAttribute(); //获取元模
|
|
|
|
|
bool getModelConnectivity(); //获取连接性
|
|
|
|
|
|
|
|
|
|
QMap<int,attributeGroup> AttributeGroup() const {return _attributeGroup;}
|
|
|
|
|
QMap<int,dataType> DataType() const {return _dataType;}
|
|
|
|
|
QMap<int,attribute> Attribute() const {return _attribute;}
|
|
|
|
|
QMap<int,modelAttribute> ModelAttribute() const {return _modelAttribute;}
|
|
|
|
|
QMap<int,modelConnectivity> ModelConnectivity() const {return _modelConnectivity;}
|
|
|
|
|
//***********工程模
|
|
|
|
|
bool createProjectManager(); //生成记录表,包含工程模名称,属性组名,启用和关闭的属性字段(json类型)[一个属性组建一个表]
|
|
|
|
|
bool insertProjectManager(const QString& name,const QString& tag,const QString& metaModel,const QString& groupName,int linkType,QJsonObject checkState);
|
2025-03-14 17:18:25 +08:00
|
|
|
bool updateCheckState(const QString& tableName,QJsonObject checkState); //更新属性选中状态
|
|
|
|
|
QMap<QString,int> getProjectFromManager(const QString& sMeta); //返回元模下已创建的工程名
|
2025-03-04 09:44:03 +08:00
|
|
|
QMap<QString,QJsonObject> getCheckStateFromManager(const QString& sProject); //获取当前工程模型所有属性的选择状态 <属性名,选择状态>
|
2025-03-14 17:18:25 +08:00
|
|
|
QMap<QString,QString> getProjectTableName(const QString& sProject); //获取当前工程模型下所有表信息
|
2025-03-04 09:44:03 +08:00
|
|
|
bool createDynamicTable(const QString&, const QStringList&);
|
2025-03-07 19:24:19 +08:00
|
|
|
bool deleteProjectModel(const QString&);
|
2025-03-14 17:18:25 +08:00
|
|
|
bool deleteTable(const QString&); //删除表
|
|
|
|
|
bool deleteRecordFromManager(const QString& sProject,const QString& sGroup); //删除某个模型下的组
|
|
|
|
|
bool modifyProjectTable(QString sTable,QMap<QString,QString> mOld,QMap<QString,QString> mNew);
|
2025-03-04 09:44:03 +08:00
|
|
|
private:
|
|
|
|
|
QMap<int,attributeGroup> _attributeGroup; //属性组的组
|
|
|
|
|
QMap<int,dataType> _dataType; //数据类型组
|
|
|
|
|
QMap<int,attribute> _attribute; //属性组
|
|
|
|
|
QMap<int,modelAttribute> _modelAttribute; //元模组
|
|
|
|
|
QMap<int,modelConnectivity> _modelConnectivity; //连接性组
|
2025-02-06 16:36:50 +08:00
|
|
|
private:
|
|
|
|
|
void initial();
|
2025-03-04 09:44:03 +08:00
|
|
|
//bool createProjectDB();
|
|
|
|
|
//void initialProjectDB();
|
2025-02-06 16:36:50 +08:00
|
|
|
void readXML();
|
|
|
|
|
static DataBase* instance;
|
|
|
|
|
static int _id;
|
|
|
|
|
QSqlDatabase db;
|
2025-03-04 09:44:03 +08:00
|
|
|
//QSqlDatabase prodb;
|
2025-02-06 16:36:50 +08:00
|
|
|
QString m_sFileName;
|
|
|
|
|
QString _DataBaseType;
|
|
|
|
|
QString _DataBaseName;
|
2025-03-04 09:44:03 +08:00
|
|
|
//QString _ProjectDB; //工程模数据库名
|
2025-02-06 16:36:50 +08:00
|
|
|
QString _HostName;
|
|
|
|
|
int _Port;
|
|
|
|
|
QString _UserName;
|
|
|
|
|
QString _PassWord;
|
2025-03-04 09:44:03 +08:00
|
|
|
|
2025-02-06 16:36:50 +08:00
|
|
|
};
|
|
|
|
|
#endif // DATABASE_H
|