完成数据库更新(增加用来存储公共属性组属性数据的model_attribute_public数据表)的逻辑适配
This commit is contained in:
parent
f46f9acc98
commit
4a5a076880
|
|
@ -27,6 +27,7 @@ public:
|
|||
const QVector<AttributeGroup> getAttributeGroup(const QString&);
|
||||
const QString getAttributeGroupName(const QString&, int);
|
||||
const AttributeGroup getAttributeGroupData(const QString&, int);
|
||||
bool isPublicAttributeGroup(const QString&, int);
|
||||
bool removeAttributeGroup(const QString&, int, int);
|
||||
//模型相关
|
||||
const QVector<Model> getModels(const QString&);
|
||||
|
|
|
|||
|
|
@ -353,11 +353,19 @@ void AttributeTableModel::loadPageData()
|
|||
}
|
||||
else //按具体模型的具体属性组读取数据
|
||||
{
|
||||
QString strSQL = QString("SELECT attribute_id FROM basic.model_attribute WHERE model_type_id = %1 AND attribute_group_id = %2 LIMIT %3 OFFSET %4")
|
||||
.arg(m_modelAttributeGroup.modelID)
|
||||
.arg(m_modelAttributeGroup.groupID)
|
||||
.arg(m_paginationInfo.entriesPerPage)
|
||||
.arg((m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage);
|
||||
QString strSQL = "";
|
||||
bool isPublicGroup = SqlQueryExecutor::instance().isPublicAttributeGroup(m_connection, m_modelAttributeGroup.groupID);
|
||||
if(isPublicGroup)
|
||||
strSQL = QString("SELECT attribute_id FROM basic.model_attribute_public WHERE attribute_group_id = %1 LIMIT %2 OFFSET %3")
|
||||
.arg(m_modelAttributeGroup.groupID)
|
||||
.arg(m_paginationInfo.entriesPerPage)
|
||||
.arg((m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage);
|
||||
else
|
||||
strSQL = QString("SELECT attribute_id FROM basic.model_attribute WHERE model_type_id = %1 AND attribute_group_id = %2 LIMIT %3 OFFSET %4")
|
||||
.arg(m_modelAttributeGroup.modelID)
|
||||
.arg(m_modelAttributeGroup.groupID)
|
||||
.arg(m_paginationInfo.entriesPerPage)
|
||||
.arg((m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage);
|
||||
try
|
||||
{
|
||||
QSqlQuery query = SqlQueryExecutor::instance().executeSQL(m_connection, strSQL);
|
||||
|
|
|
|||
|
|
@ -513,6 +513,26 @@ const AttributeGroup SqlQueryExecutor::getAttributeGroupData(const QString& conn
|
|||
return group;
|
||||
}
|
||||
|
||||
bool SqlQueryExecutor::isPublicAttributeGroup(const QString& connectionName, int groupID)
|
||||
{
|
||||
bool isPublic = false;
|
||||
QString strSQL = "SELECT is_public FROM basic.attribute_group WHERE id = :id";
|
||||
QVariantHash params;
|
||||
params.insert(":id", groupID);
|
||||
try
|
||||
{
|
||||
QSqlQuery query = executeSQL(connectionName, strSQL, params);
|
||||
if(query.next())
|
||||
isPublic = query.value(0).toBool();
|
||||
}
|
||||
catch (const DatabaseException& e)
|
||||
{
|
||||
LOG_ERROR("SQL", QString::fromWCharArray(L"获取属性组类型失败,id:%1").arg(QString::number(groupID)));
|
||||
}
|
||||
|
||||
return isPublic;
|
||||
}
|
||||
|
||||
bool SqlQueryExecutor::removeAttributeGroup(const QString& connectionName, int modelID, int groupID)
|
||||
{
|
||||
//从model_attribute和model_group两个map表中对相关记录进行删除(暂时不做属性本体的删除)
|
||||
|
|
@ -694,7 +714,12 @@ bool SqlQueryExecutor::batchInsertAttributes(const QString& connectionName, int
|
|||
}
|
||||
//插入数据到关联表
|
||||
QSqlQuery linkQuery(db);
|
||||
QString strSQL = "INSERT INTO basic.model_attribute (model_type_id, attribute_group_id, attribute_id) VALUES (?, ?, ?)";
|
||||
QString strSQL = "";
|
||||
bool isPublicGroup = isPublicAttributeGroup(connectionName, attributeGroupID);
|
||||
if(isPublicGroup)
|
||||
strSQL = "INSERT INTO basic.model_attribute_public (attribute_group_id, attribute_id) VALUES (?, ?)";
|
||||
else
|
||||
strSQL = "INSERT INTO basic.model_attribute (model_type_id, attribute_group_id, attribute_id) VALUES (?, ?, ?)";
|
||||
if(!linkQuery.prepare(strSQL))
|
||||
{
|
||||
LOG_ERROR("SQL", QString("SQL '%1' prepare fialed. error: %2").arg(strSQL, linkQuery.lastError().databaseText()));
|
||||
|
|
@ -707,11 +732,13 @@ bool SqlQueryExecutor::batchInsertAttributes(const QString& connectionName, int
|
|||
QVariantList modelIds, groupIds, attributeIds;
|
||||
for(const qint64& attributeID : attributeIDList)
|
||||
{
|
||||
modelIds << modelID;
|
||||
if(!isPublicGroup)
|
||||
modelIds << modelID;
|
||||
groupIds << attributeGroupID;
|
||||
attributeIds << attributeID;
|
||||
}
|
||||
linkQuery.addBindValue(modelIds);
|
||||
if(!isPublicGroup)
|
||||
linkQuery.addBindValue(modelIds);
|
||||
linkQuery.addBindValue(groupIds);
|
||||
linkQuery.addBindValue(attributeIds);
|
||||
if( !linkQuery.execBatch() )
|
||||
|
|
@ -751,7 +778,12 @@ bool SqlQueryExecutor::batchDeleteAttributes(const QString& connectionName, int
|
|||
}
|
||||
|
||||
QSqlQuery query(db);
|
||||
QString strSQL = "DELETE FROM basic.model_attribute WHERE model_type_id = ? AND attribute_group_id = ? AND attribute_id = ?";
|
||||
QString strSQL = "";
|
||||
bool isPublicGroup = isPublicAttributeGroup(connectionName, attributeGroupID);
|
||||
if(isPublicGroup)
|
||||
strSQL = "DELETE FROM basic.model_attribute_public WHERE attribute_group_id = ? AND attribute_id = ?";
|
||||
else
|
||||
strSQL = "DELETE FROM basic.model_attribute WHERE model_type_id = ? AND attribute_group_id = ? AND attribute_id = ?";
|
||||
if(!query.prepare(strSQL))
|
||||
{
|
||||
LOG_ERROR("SQL", QString("SQL '%1' prepare fialed. error: %2").arg(strSQL, query.lastError().databaseText()));
|
||||
|
|
@ -764,11 +796,13 @@ bool SqlQueryExecutor::batchDeleteAttributes(const QString& connectionName, int
|
|||
QVariantList modelIds, groupIds, attributeIds;
|
||||
for(const int& attributeID : attributes)
|
||||
{
|
||||
modelIds << modelID;
|
||||
if(!isPublicGroup)
|
||||
modelIds << modelID;
|
||||
groupIds << attributeGroupID;
|
||||
attributeIds << attributeID;
|
||||
}
|
||||
query.addBindValue(modelIds);
|
||||
if(!isPublicGroup)
|
||||
query.addBindValue(modelIds);
|
||||
query.addBindValue(groupIds);
|
||||
query.addBindValue(attributeIds);
|
||||
if( !query.execBatch() )
|
||||
|
|
|
|||
Loading…
Reference in New Issue