224 lines
13 KiB
C
224 lines
13 KiB
C
|
|
#ifndef DATABASE_H
|
|||
|
|
#define DATABASE_H
|
|||
|
|
|
|||
|
|
#include <QSqlDatabase>
|
|||
|
|
#include <QObject>
|
|||
|
|
#include <QUuid>
|
|||
|
|
#include <QJsonObject>
|
|||
|
|
//#include "global.h"
|
|||
|
|
#include "common/backend/project_model.h"
|
|||
|
|
#include "common/core_model/topology.h"
|
|||
|
|
#include "common/backend/meta_model.h"
|
|||
|
|
#include "common/frontend/monitor_item.h"
|
|||
|
|
#include "common/core_model/diagram.h"
|
|||
|
|
#include "export.hpp"
|
|||
|
|
|
|||
|
|
|
|||
|
|
class DIAGRAM_DESIGNER_PUBLIC DataBase
|
|||
|
|
{
|
|||
|
|
//Q_OBJECT
|
|||
|
|
public:
|
|||
|
|
DataBase();
|
|||
|
|
~DataBase();
|
|||
|
|
QSqlQuery executeSQL(const QString& strSQL, bool isDDl = false,const QVariantList& params = {}, bool useTranscation = false); //ddl:create,delete,alter etc
|
|||
|
|
/**
|
|||
|
|
* @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);
|
|||
|
|
static DataBase* GetInstance();
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
bool insertPage(QString tag,QString name,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(QUuid uuid_from,QUuid uuid_to,QJsonObject context,int flag,QString description,int op);
|
|||
|
|
|
|||
|
|
QString getGridNameById(int);
|
|||
|
|
QString getZoneNameById(int);
|
|||
|
|
QString getStationNameById(int);
|
|||
|
|
|
|||
|
|
QList<GridInfo> getAllGrid();
|
|||
|
|
QList<ZoneInfo> getAllZone();
|
|||
|
|
QList<StationInfo> getAllStation();
|
|||
|
|
|
|||
|
|
QList<TopologyInfo> getAllTopologics();
|
|||
|
|
int topologicExist(QUuid fromItem,QUuid toItem);
|
|||
|
|
TopologyInfo getTopologicById(int id);
|
|||
|
|
bool deleteTopologic(QUuid fromPin,QUuid toPin);
|
|||
|
|
/*********************************************************************************/
|
|||
|
|
bool updateComponent(QUuid uuid,QString tag,QString name,QJsonObject context,bool inService,int state,int status);
|
|||
|
|
bool insertComponent(QUuid uuid,QString modelName,QString nspath,QString tag,QString name,QString description,QString grid,QString zone,QString station,int type,bool inService,int state,int status,QJsonObject connected_bus,QJsonObject label,QJsonObject context,int op);
|
|||
|
|
bool insertDynamicProperty(QUuid uuid,GroupStateValue groupValue);
|
|||
|
|
bool updateDynamicProperty(QUuid uuid,GroupStateValue groupValue);
|
|||
|
|
ComponentInfo getComponentInfoByUuid(QString uuid);
|
|||
|
|
QList<ComponentInfo> getAllComponents();
|
|||
|
|
bool componentExist(QString uuid);
|
|||
|
|
bool deleteComponent(QString uuid);
|
|||
|
|
|
|||
|
|
QMap<int,ComponentTypeInfo> getAllComponentType(); //获取所有支持的元件种类
|
|||
|
|
/*********************************************************************************/
|
|||
|
|
int getPageIdByName(QString name);
|
|||
|
|
bool updatePage(QString tag,QString name,QJsonObject context);
|
|||
|
|
QJsonObject getPageContextByName(QString name);
|
|||
|
|
QList<PageInfo> getAllPage();
|
|||
|
|
/*********************************************************************************/
|
|||
|
|
bool insertBay(QUuid uuid,QString name,QString tag,QString type,double unom,double fla,double capacity,QString description,bool inService,int nState,QString grid,QString zone,QString station,QJsonObject business,QJsonObject fromUuid,QJsonObject toUuid,QJsonObject protect,QJsonObject faultRec,QJsonObject status,QJsonObject dynSense,QJsonObject instruct,QJsonObject etc,QList<QUuid> components,QJsonObject context);
|
|||
|
|
bool updateBay(QUuid uuid,QString name,QString tag,double unom,double fla,double capacity,QString description,bool inService,int nState,QJsonObject business,QJsonObject fromUuid,QJsonObject toUuid,QJsonObject protect,QJsonObject faultRec,QJsonObject status,QJsonObject dynSense,QJsonObject instruct,QJsonObject etc,QList<QUuid> components,QJsonObject context);
|
|||
|
|
BayInfo getBay(QUuid uuid);
|
|||
|
|
QList<BayInfo> getAllBay();
|
|||
|
|
bool ifBayExist(QUuid uuid);
|
|||
|
|
bool deleteBay(QUuid uuid);
|
|||
|
|
/*********************************************************************************/
|
|||
|
|
bool insertMeasurement(QString name,QString tag,int type,QJsonObject dataSource,QJsonObject eventPlan,QJsonObject binding,int size,QUuid bayId,QUuid componentId);
|
|||
|
|
bool updateMeasurement(QString name,int type,QJsonObject dataSource,QJsonObject eventPlan,QJsonObject binding,int size,QUuid componentId);
|
|||
|
|
bool delteMeasurement(QString name,QUuid componentId);
|
|||
|
|
bool ifMeasureExist(QString name,QUuid componentId);
|
|||
|
|
bool ifBayMeasureExist(QString name,QUuid bayId);
|
|||
|
|
QList<MeasurementInfo> getMeasurement(QUuid componentId);
|
|||
|
|
QList<MeasurementInfo> getBayMeasurement(QUuid bayUuid); //返回间隔下的所有量测
|
|||
|
|
QMap<QString,MeasurementInfo> getAllMeasurements();
|
|||
|
|
/*********************************************************************************/
|
|||
|
|
bool insertExtraProperty(ExtraProperty); //属性层级与连接信息
|
|||
|
|
bool updateExtraProperty(ExtraProperty);
|
|||
|
|
bool deleteExtraProperty(QString code);
|
|||
|
|
bool ifExtraPropertyExist(QString code);
|
|||
|
|
QList<ExtraProperty> getCompoExtraProperty(QUuid uid); //获取component中的层级信息
|
|||
|
|
QList<ExtraProperty> getBayExtraProperty(QString bayTag); //获取间隔的层级信息
|
|||
|
|
QList<ExtraProperty> getAllExtraProperty();
|
|||
|
|
/*********************************************************************************/
|
|||
|
|
bool deleteComponentById(int id);
|
|||
|
|
|
|||
|
|
QJsonObject QstringToJson(QString jsonString);
|
|||
|
|
QList<QUuid> parseUuidArray(const QString& pgArray); //转化UUID[]类型
|
|||
|
|
public:
|
|||
|
|
//***********元模
|
|||
|
|
bool getAttributeGroup(); //获取属性组信息
|
|||
|
|
bool getDataType(); //获取数据类型信息
|
|||
|
|
bool getModelType(); //获取模型类型
|
|||
|
|
bool getModelGroup(); //获取模型组
|
|||
|
|
bool getAttribute(); //获取属性
|
|||
|
|
bool getModelAttribute(); //获取模型-属性对照组
|
|||
|
|
bool getModelAttributePublic(); //获取公共属性组
|
|||
|
|
bool getModelConnectivity(); //获取连接性
|
|||
|
|
|
|||
|
|
QMap<int,attributeGroup> AttributeGroup() const {return _attributeGroup;}
|
|||
|
|
QMap<int,dataType> DataType() const {return _dataType;}
|
|||
|
|
QMap<int,modelType> ModelType() const {return _modelType;}
|
|||
|
|
QMap<int,modelGroup> ModelGroup() const {return _modelGroup;}
|
|||
|
|
QMap<int,attribute> Attribute() const {return _attribute;}
|
|||
|
|
QMap<int,modelAttribute> ModelAttribute() const {return _modelAttribute;}
|
|||
|
|
QMap<int,modelAttributePublic> ModelAttributePublic() const {return _modelAttributePublic;}
|
|||
|
|
QMap<int,modelConnectivity> ModelConnectivity() const {return _modelConnectivity;}
|
|||
|
|
//***********工程模
|
|||
|
|
bool insertProjectSetting(const QString& baseModel,const QString& modelName,QJsonObject setting); //插入工程模设置信息(图标等选择信息)
|
|||
|
|
bool updateProjectSetting(const QString& baseModel,const QString& modelName,QJsonObject setting);
|
|||
|
|
QJsonObject getProjectSetting(const QString& baseModel,const QString& modelName);
|
|||
|
|
QStringList getProjectWithinBase(const QString& baseModel); //获取基模下的所有工程模名称
|
|||
|
|
bool deleteProjectSetting(const QString& baseModel,const QString& modelName);
|
|||
|
|
|
|||
|
|
bool createProjectManager(); //生成记录表,包含工程模名称,属性组名,启用和关闭的属性字段(json类型)[一个属性组建一个表]
|
|||
|
|
bool insertProjectManager(const QString& name,const QString& tag,const QString& metaModel,const QString& groupName,int linkType,QJsonObject checkState,bool isPublic = false);
|
|||
|
|
bool updateCheckState(const QString& tableName,QJsonObject checkState); //更新属性选中状态
|
|||
|
|
QMap<QString,int> getProjectFromManager(const QString& sMeta); //返回元模下已创建的工程名
|
|||
|
|
QMap<QString,QJsonObject> getCheckStateFromManager(const QString& sProject); //获取当前工程模型所有属性的选择状态 <属性名,选择状态>
|
|||
|
|
QMap<QString,QJsonObject> getPublicStateFromManager(); //获取公共属性组
|
|||
|
|
QMap<QString,QString> getProjectTableName(const QString& sProject); //获取当前工程模型下所有表信息
|
|||
|
|
bool createDynamicTable(const QString&, const QStringList&);
|
|||
|
|
bool deleteProjectModel(const QString&);
|
|||
|
|
bool ifDynamicTableExist(const QString&); //动态表是否存在
|
|||
|
|
bool updateProjectName(const QString& newTable,const QString& newPro,const QString& oldTable); //更新mangager工程模名称
|
|||
|
|
bool alterTableName(const QString& oldTable,const QString& newTable); //修改表名
|
|||
|
|
bool updateComponentModelName(const QString& strOld,const QString& strNew); //修改component中的模型名
|
|||
|
|
|
|||
|
|
bool deleteTable(const QString&); //删除表
|
|||
|
|
bool deleteRecordFromManager(const QString& sProject,const QString& sGroup); //删除某个模型下的组
|
|||
|
|
bool modifyProjectTable(QString sTable,QMap<QString,QString> mOld,QMap<QString,QString> mNew);
|
|||
|
|
|
|||
|
|
QStringList ifModelOccupy(const QString&); //判断模型是否被使用
|
|||
|
|
//**********使用工程模
|
|||
|
|
QMap<QString,int> getAllProjectModel(); //获取所有工程模<名称,图元类型>
|
|||
|
|
QMap<QString,PropertyGroupState> getModelInfo(const QString&); //获取模型信息
|
|||
|
|
QMap<QString,PropertyGroupState> getPublicInfo(); //获取公共属性组信息
|
|||
|
|
QMap<QString,ProjectManagerStruct> getProjectModelGroupInfo(const QString&); //获取指定工程模所有属性组信息<属性组名,属性信息>
|
|||
|
|
QMap<QUuid,PropertyValueInfo> selectGroupPropertyByState(const QString& tableName,QMap<QString,PropertyStateInfo> mapPro); //返回属性组表中的信息
|
|||
|
|
PropertyValueInfo selectGroupPropertyByValue(const QString& tableName,QUuid uuid,PropertyValueInfo value); //通过已有结构更新数据
|
|||
|
|
|
|||
|
|
QList<MeasureAttributeType> getMeasureAttributeTypes(); //获取所有量测属性
|
|||
|
|
|
|||
|
|
/************************************运行模式(监控)*********************************************/
|
|||
|
|
bool insertMonitor(QUuid uid,QString tag,QString name,QString parent,QJsonObject context);
|
|||
|
|
QUuid getMonitorIdByName(QString name);
|
|||
|
|
bool updateMonitor(QString tag,QJsonObject context);
|
|||
|
|
QJsonObject getMonitorContextByTag(QString tag);
|
|||
|
|
QList<MonitorPageInfo> getAllMonitor();
|
|||
|
|
|
|||
|
|
bool insertHMI(QUuid uid,QString tag,QString name,QJsonObject context);
|
|||
|
|
QUuid getHMIdByName(QString name);
|
|||
|
|
bool updateHMI(QString tag,QJsonObject context);
|
|||
|
|
QJsonObject getHMIContextByTag(QString tag);
|
|||
|
|
QList<HMIPageInfo> getAllHMI();
|
|||
|
|
|
|||
|
|
bool insertHMIimage(int baseType,QString imageName,QByteArray hash256,QByteArray svgData); //hmi使用的图片
|
|||
|
|
bool insertHMIimagesBatch(const QVector<HMIImageInfo>& imageList);
|
|||
|
|
bool insertHMIimagesWithCheck(const QVector<HMIImageInfo>& imageList); // 智能批量插入(先查重)
|
|||
|
|
QVector<bool> batchCheckHMIimagesExists(const QVector<QByteArray>& hashList);
|
|||
|
|
QByteArray findHMIimage(QByteArray hash256);
|
|||
|
|
QList<HMIImageInfo> getAllHMIimage();
|
|||
|
|
|
|||
|
|
|
|||
|
|
bool inserHMIimageRef(QUuid hmiId,QString model,QByteArray hash256,int slot);
|
|||
|
|
bool insertHMIimageRefBatch(const QList<HMIImageRef>& refList);
|
|||
|
|
QList<HMIImageRef> getHMIRefAll(QUuid hmiId); //获取hmi所有资源信息
|
|||
|
|
QList<HMIImageRef> getHMIRef(QUuid hmiId,QString model);
|
|||
|
|
bool removeHMIRef(QUuid hmiId,QString model); //移除hmi中某类模型的图片引用
|
|||
|
|
bool removeHMIRefAll(QUuid hmiId); //移除某个HMI中所有引用关系
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
/***********************************editor编辑器**********************************************/
|
|||
|
|
bool insertEditorProject(QUuid,QString,QString);
|
|||
|
|
QList<EditorProjectInfo> getAllEditorProject();
|
|||
|
|
bool deleteEditorProject(QString);
|
|||
|
|
bool ifEditorProjectExist(QString name);
|
|||
|
|
/***********************************baseSetting**********************************************/
|
|||
|
|
bool insertBaseSetting(QUuid,QString,QString,QByteArray,QUuid,QString ts);
|
|||
|
|
bool updateBaseSetting(QUuid,QByteArray context,QString ts);
|
|||
|
|
QByteArray getBaseSettingByUid(QUuid);
|
|||
|
|
EditorBaseSettingInfo getBaseSettingInfo(QUuid);
|
|||
|
|
QList<EditorBaseSettingInfo> getAllBaseSetting();
|
|||
|
|
bool deleteBaseSetting(QUuid);
|
|||
|
|
bool ifBaseSettingExist(QUuid);
|
|||
|
|
private:
|
|||
|
|
QMap<int,attributeGroup> _attributeGroup; //属性组的组
|
|||
|
|
QMap<int,dataType> _dataType; //数据类型组
|
|||
|
|
QMap<int,modelType> _modelType; //模型类型
|
|||
|
|
QMap<int,modelGroup> _modelGroup; //模型组
|
|||
|
|
QMap<int,attribute> _attribute; //属性组
|
|||
|
|
QMap<int,modelAttribute> _modelAttribute; //模型-属性对照组
|
|||
|
|
QMap<int,modelAttributePublic> _modelAttributePublic; //公共属性组
|
|||
|
|
QMap<int,modelConnectivity> _modelConnectivity; //连接性组
|
|||
|
|
|
|||
|
|
QMap<int,ComponentTypeInfo> _componentType; //存储系统支持的类型列表
|
|||
|
|
private:
|
|||
|
|
void initial();
|
|||
|
|
//bool createProjectDB();
|
|||
|
|
//void initialProjectDB();
|
|||
|
|
void readXML();
|
|||
|
|
static DataBase* dbInstance;
|
|||
|
|
static int _id;
|
|||
|
|
QSqlDatabase db;
|
|||
|
|
//QSqlDatabase prodb;
|
|||
|
|
QString m_sFileName;
|
|||
|
|
QString _DataBaseType;
|
|||
|
|
QString _DataBaseName;
|
|||
|
|
//QString _ProjectDB; //工程模数据库名
|
|||
|
|
QString _HostName;
|
|||
|
|
int _Port;
|
|||
|
|
QString _UserName;
|
|||
|
|
QString _PassWord;
|
|||
|
|
};
|
|||
|
|
#endif // DATABASE_H
|