2025-02-06 16:36:50 +08:00
|
|
|
|
#ifndef DATABASE_H
|
|
|
|
|
|
#define DATABASE_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QSqlDatabase>
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
#include <QUuid>
|
|
|
|
|
|
#include <QJsonObject>
|
2025-03-21 12:53:45 +08:00
|
|
|
|
#include "global.h"
|
|
|
|
|
|
#include "export.hpp"
|
2025-02-06 16:36:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-03-21 12:53:45 +08:00
|
|
|
|
class DIAGRAM_DESIGNER_PUBLIC DataBase
|
2025-02-06 16:36:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
//Q_OBJECT
|
|
|
|
|
|
public:
|
|
|
|
|
|
DataBase();
|
|
|
|
|
|
~DataBase();
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QSqlQuery executeSQL(const QString& strSQL, bool createOrDrop = false,const QVariantList& params = {}, bool useTranscation = false);
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 多条批量SQL语句执行接口
|
|
|
|
|
|
* @param sqlStatements SQL语句列表
|
|
|
|
|
|
* @param paramsList 参数列表(要与SQL语句一一对应)
|
|
|
|
|
|
*/
|
|
|
|
|
|
QSqlQuery executeBatchSQL(const QStringList& sqlStatements, bool createOrDrop = false,
|
|
|
|
|
|
const QList<QVariantList>& paramsList = QList<QVariantList>(), bool useTranscation = false);
|
2025-02-06 16:36:50 +08:00
|
|
|
|
static DataBase* GetInstance();
|
2025-03-21 12:53:45 +08:00
|
|
|
|
|
2025-02-06 16:36:50 +08:00
|
|
|
|
public:
|
|
|
|
|
|
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(); //获取数据类型信息
|
2025-03-21 12:53:45 +08:00
|
|
|
|
bool getModelType(); //获取模型类型
|
|
|
|
|
|
bool getModelGroup(); //获取模型组
|
2025-03-04 09:44:03 +08:00
|
|
|
|
bool getAttribute(); //获取属性
|
2025-03-21 12:53:45 +08:00
|
|
|
|
bool getModelAttribute(); //获取模型-属性对照组
|
2025-03-04 09:44:03 +08:00
|
|
|
|
bool getModelConnectivity(); //获取连接性
|
|
|
|
|
|
|
|
|
|
|
|
QMap<int,attributeGroup> AttributeGroup() const {return _attributeGroup;}
|
|
|
|
|
|
QMap<int,dataType> DataType() const {return _dataType;}
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QMap<int,modelType> ModelType() const {return _modelType;}
|
|
|
|
|
|
QMap<int,modelGroup> ModelGroup() const {return _modelGroup;}
|
2025-03-04 09:44:03 +08:00
|
|
|
|
QMap<int,attribute> Attribute() const {return _attribute;}
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QMap<int,modelAttribute> ModelAttribute() const {return _modelAttribute;}
|
2025-03-04 09:44:03 +08:00
|
|
|
|
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-21 12:53:45 +08:00
|
|
|
|
//**********使用工程模
|
|
|
|
|
|
QMap<QString,int> getAllProjectModel(); //获取所有工程模<名称,图元类型>
|
|
|
|
|
|
QMap<QString,projectManager> getProjectModelGroupInfo(const QString&); //获取指定工程模所有属性组信息<属性组名,属性信息>
|
2025-03-04 09:44:03 +08:00
|
|
|
|
private:
|
|
|
|
|
|
QMap<int,attributeGroup> _attributeGroup; //属性组的组
|
|
|
|
|
|
QMap<int,dataType> _dataType; //数据类型组
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QMap<int,modelType> _modelType; //模型类型
|
|
|
|
|
|
QMap<int,modelGroup> _modelGroup; //模型组
|
2025-03-04 09:44:03 +08:00
|
|
|
|
QMap<int,attribute> _attribute; //属性组
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QMap<int,modelAttribute> _modelAttribute; //模型-属性对照组
|
2025-03-04 09:44:03 +08:00
|
|
|
|
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();
|
2025-03-21 12:53:45 +08:00
|
|
|
|
static DataBase* dbInstance;
|
2025-02-06 16:36:50 +08:00
|
|
|
|
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;
|
|
|
|
|
|
};
|
|
|
|
|
|
#endif // DATABASE_H
|