更新属性按关键词搜索时获取结果数量逻辑
This commit is contained in:
parent
399ee6340d
commit
2dd33f2280
|
|
@ -23,7 +23,9 @@ public:
|
|||
AttributeSelector(const QString& connection = "", QWidget *parent = nullptr);
|
||||
~AttributeSelector();
|
||||
|
||||
void setMainWindow(MainWindow*);
|
||||
void setMainWindow(MainWindow* window) {m_pMainWindow = window;}
|
||||
// const QString& connection() {return m_connection;}
|
||||
// void setConnection(const QString& conn) {m_connection = conn;}
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent*) override;
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ public:
|
|||
bool addModleGrpus(const QString&, int, QVector<int>);
|
||||
QVector<int> getModelGroups(const QString&, int);
|
||||
//属性相关
|
||||
int getAttributeCount(const QString&, int, int);
|
||||
int getAllAttributeCount(const QString&);
|
||||
int getAttributeCount(const QString&, int, int, const QString& filterChars = "");
|
||||
int getAllAttributeCount(const QString&, const QString& filterChars = "");
|
||||
bool getAttributeInfo(const QString&, const QString&, Attribute&);
|
||||
int getAttributeID(const QString&, const QString&);
|
||||
bool attributeTypeUseByModelGroup(const QString&, int, int, int);
|
||||
|
|
|
|||
|
|
@ -178,11 +178,6 @@ bool AttributeSelector::eventFilter(QObject* obj, QEvent* event)
|
|||
return QDialog::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void AttributeSelector::setMainWindow(MainWindow* window)
|
||||
{
|
||||
m_pMainWindow = window;
|
||||
}
|
||||
|
||||
void AttributeSelector::onBtnClicked_search()
|
||||
{
|
||||
if(m_fliterChars_type != ui->lineEdit_attributeType->text() || m_curModelName != ui->comboBox_model->currentText()
|
||||
|
|
|
|||
|
|
@ -355,8 +355,9 @@ void AttributeTableModel::loadPageData()
|
|||
if(m_modelAttributeGroup.modelID == -1) //表示当前加载数据对象是所有属性
|
||||
{
|
||||
columns.append("id"); //将id放到最后,和按照具体模型、具体属性组读取数据方式时逻辑统一,具体见下面分支逻辑
|
||||
QString strSQL = QString("SELECT %1 FROM basic.attribute ORDER BY id ASC LIMIT %2 OFFSET %3")
|
||||
QString strSQL = QString("SELECT %1 FROM basic.attribute WHERE attribute LIKE '%%2%' ORDER BY id ASC LIMIT %3 OFFSET %4")
|
||||
.arg(columns.join(", "))
|
||||
.arg(m_filterChars_attributeType)
|
||||
.arg(m_paginationInfo.entriesPerPage)
|
||||
.arg((m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage);
|
||||
try
|
||||
|
|
@ -364,9 +365,9 @@ void AttributeTableModel::loadPageData()
|
|||
QSqlQuery query = SqlQueryExecutor::instance().executeSQL(m_connection, strSQL);
|
||||
while(query.next())
|
||||
{
|
||||
QString type = query.value(0).toString();
|
||||
if(!m_filterChars_attributeType.isEmpty() && !type.contains(m_filterChars_attributeType))
|
||||
continue;
|
||||
// QString type = query.value(0).toString();
|
||||
// if(!m_filterChars_attributeType.isEmpty() && !type.contains(m_filterChars_attributeType))
|
||||
// continue;
|
||||
|
||||
RowData data;
|
||||
for(int i = 0; i < columns.count(); i++)
|
||||
|
|
@ -501,7 +502,7 @@ void AttributeTableModel::updateTotalCount()
|
|||
}*/
|
||||
|
||||
if(m_modelAttributeGroup.modelID == -1)
|
||||
m_paginationInfo.totalEntries = SqlQueryExecutor::instance().getAllAttributeCount(m_connection);
|
||||
m_paginationInfo.totalEntries = SqlQueryExecutor::instance().getAllAttributeCount(m_connection, m_filterChars_attributeType);
|
||||
else
|
||||
m_paginationInfo.totalEntries = SqlQueryExecutor::instance().getAttributeCount(m_connection, m_modelAttributeGroup.modelID, m_modelAttributeGroup.groupID);
|
||||
|
||||
|
|
|
|||
|
|
@ -578,15 +578,27 @@ bool SqlQueryExecutor::removeAttributeGroup(const QString& connectionName, int m
|
|||
return true;
|
||||
}
|
||||
|
||||
int SqlQueryExecutor::getAttributeCount(const QString& connectionName, int modelID, int groupID)
|
||||
int SqlQueryExecutor::getAttributeCount(const QString& connectionName, int modelID, int groupID, const QString& filterChars)
|
||||
{
|
||||
int count = 0;
|
||||
QString strSQL = "";
|
||||
bool isPublicGroup = isPublicAttributeGroup(connectionName, groupID);
|
||||
if(isPublicGroup)
|
||||
strSQL = QString("SELECT COUNT(*) FROM basic.model_attribute_public WHERE attribute_group_id = %1").arg(groupID);
|
||||
strSQL = QString("SELECT COUNT(*) FROM basic.model_attribute_public AS map "
|
||||
"INNER JOIN basic.attribute AS a ON map.attribute_id = a.id "
|
||||
"WHERE attribute_group_id = %1 "
|
||||
"AND a.attribute LIKE '%%2%'")
|
||||
.arg(groupID)
|
||||
.arg(filterChars);
|
||||
else
|
||||
strSQL = QString("SELECT COUNT(*) FROM basic.model_attribute WHERE model_type_id = %1 AND attribute_group_id = %2").arg(modelID).arg(groupID);
|
||||
strSQL = QString("SELECT COUNT(*) FROM basic.model_attribute AS map "
|
||||
"INNER JOIN basic.attribute AS a ON map.attribute_id = a.id "
|
||||
"WHERE model_type_id = %1 "
|
||||
"AND attribute_group_id = %2 "
|
||||
"AND a.attribute LIKE '%%3%'")
|
||||
.arg(modelID)
|
||||
.arg(groupID)
|
||||
.arg(filterChars);
|
||||
try
|
||||
{
|
||||
QSqlQuery query = executeSQL(connectionName, strSQL);
|
||||
|
|
@ -601,16 +613,18 @@ int SqlQueryExecutor::getAttributeCount(const QString& connectionName, int model
|
|||
return count;
|
||||
}
|
||||
|
||||
int SqlQueryExecutor::getAllAttributeCount(const QString& connectionName)
|
||||
int SqlQueryExecutor::getAllAttributeCount(const QString& connectionName, const QString& filterChars)
|
||||
{
|
||||
int count = 0;
|
||||
QString strSQL = QString("SELECT COUNT(*) FROM basic.attribute");
|
||||
QString strSQL = QString("SELECT COUNT(*) FROM basic.attribute WHERE attribute LIKE '%") + filterChars + "%'";
|
||||
try
|
||||
{
|
||||
QSqlQuery query = executeSQL(connectionName, strSQL);
|
||||
if(query.next())
|
||||
{
|
||||
count = query.value(0).toInt();
|
||||
}
|
||||
}
|
||||
catch (const DatabaseException& e)
|
||||
{
|
||||
LOG_ERROR("SQL", QString::fromWCharArray(L"获取属性数量失败"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue