#include "DataCollectionWidget.h" #include "DataTableWidget.h" #include "ConfigExpertDataWidget.h" #include "ConfigMeasureDataWidget.h" #include "ConfigSchemeDataWidget.h" #include "EvalDataManager.h" #include "algorithm/HierarchicalAnalysis.h" #include "MindEvaluation.h" #include "GreyClusteringConfigWidget.h" // 灰色聚类配置 #include "GreyClusteringSampleTable.h" // 灰色聚类评估 #include "MatterElementConfigWidget.h" // 物元分析配置 #include "dbService/SchemeProcessService.h" #include "dbService/ClassSet.h" #include "dbService/CNodeDataService.h" #include "dbService/NodeMatrixService.h" #include "dbService/UserService.h" #include #include #include #include #include #include #include #include #include DataCollectionWidget::DataCollectionWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent) { setTitle("评估数据采集"); m_configExpert = new ConfigExpertDataWidget(this); m_configMeasure = new ConfigMeasureDataWidget(this); m_configScheme = new ConfigSchemeDataWidget(this); m_configMeasure->setFixedWidth(256); m_configScheme->setFixedWidth(256); m_contentLayout->addWidget(m_configExpert); m_contentLayout->addWidget(m_configMeasure); m_contentLayout->addWidget(m_configScheme); m_configExpert->setHidden(true); m_configMeasure->setHidden(true); m_configScheme->setHidden(true); m_calcBtn = new PushButton("更新数据"); m_topLayout->addStretch(); m_topLayout->addWidget(m_calcBtn); connect(m_calcBtn, &PushButton::clicked, this, &DataCollectionWidget::slotCalc); connect(m_tab, &QTabWidget::currentChanged, this, &DataCollectionWidget::slotTabCurrentChanged); connect(m_configExpert, &ConfigExpertDataWidget::sigImportData, this, &DataCollectionWidget::slotImportData); connect(m_configExpert, &ConfigExpertDataWidget::sigConfigSelected, this, &DataCollectionWidget::slotConfigSelected); } void DataCollectionWidget::setType(int type) { EvalWidget::setType(type); setupTabWidget(); } /// /// \brief DataCollectionWidget::setupTabWidget /// 根据评估类型, 评估方案, 评估算法, 加载合适的数据导入界面 void DataCollectionWidget::setupTabWidget() { m_tab->clear(); QMap> nodeListMap; for (int i : indexList()) { // 获取指标体系数据 QList nodeList; bool ret = CNodeDataService().QueryAll(nodeList, m_proj->id, i); if (ret) { nodeListMap[i] = nodeList; } else { return; } // 获取方案规划数据 QList processList; ret = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, i); if (ret == false) { return; } ProjectManager::IndexType t = (ProjectManager::IndexType)i; QString indexName = ProjectManager::nameOfIndexType(t); // 效能评估方案中导入评估数据的步骤, 选择物元分析法时使用 SchemePlanManager::SchemeProcessInfo importEffiEvalDataProcess; for (SchemePlanManager::SchemeProcessInfo process : processList) { // 综合效能评估 - 灰色聚类法: 效能等级配置页面, 导入评估数据页面 if (process.algorithm == SchemePlanManager::GCE && process.indexType == ProjectManager::EfficiencyIndex) { CMind *mind = new CMind(this); mind->setNodeList(nodeListMap[i]); GreyClusteringConfigWidget *gc = new GreyClusteringConfigWidget(mind, process.efficiencyGrades); m_tab->addTab(gc, indexName + " - " + "灰色聚类法效能等级配置"); QVector items; GreyClusteringSampleTable *gs = new GreyClusteringSampleTable(items, 2, 10); m_tab->addTab(gs, indexName + " - " + "收集效能评估数据"); } // 综合效能评估 - 物元分析法: 效能等级配置页面, 导入评估数据页面 if (process.algorithm == SchemePlanManager::MEA && process.indexType == ProjectManager::EfficiencyIndex) { QList items; CMind *mind = new CMind(this); mind->setNodeList(nodeListMap[i]); MatterElementConfigWidget *mec = new MatterElementConfigWidget(mind, process.efficiencyGrades); m_tab->addTab(mec, indexName + "-" + "物元分析法效能等级配置"); DataTableWidget *table = new DataTableWidget(importEffiEvalDataProcess, this); table->mind1()->setNodeList(nodeListMap[i]); table->setupModels(); m_tab->addTab(table, indexName + " - " + "收集效能评估数据"); } // 导入效能评估的权重分析数据 // 导入其他评估的权重分析数据和评估数据 if (process.dSource >= 0) { if (process.type == SchemePlanManager::ImportEvalData && process.indexType == ProjectManager::EfficiencyIndex) { importEffiEvalDataProcess = process; continue; } DataTableWidget *table = new DataTableWidget(process, this); table->mind1()->setNodeList(nodeListMap[i]); if (i == ProjectManager::TechIndex) { table->mind2()->setNodeList(nodeListMap[ProjectManager::AbilityIndex]); } table->setupModels(); QString processName = SchemePlanManager::processName(process); m_tab->addTab(table, indexName + " - " + processName); } } } } void DataCollectionWidget::slotTabCurrentChanged(int index) { DataTableWidget *table = dynamic_cast(m_tab->widget(index)); if (index >= 0 && table != nullptr) { bool expert = (table->process().dSource == SchemePlanManager::FromExpert); if (expert) { m_configExpert->setProcess(table->process()); } m_configExpert->setVisible(expert); bool meaure = (table->process().dSource == SchemePlanManager::FromMeasurement); if (meaure) { m_configMeasure->setProcess(table->process()); } m_configMeasure->setVisible(meaure); bool scheme = (table->process().dSource == SchemePlanManager::FromScheme); if (scheme) { m_configScheme->setProcess(table->process()); } m_configScheme->setVisible(scheme); } if (table == nullptr) { m_configExpert->setHidden(true); m_configMeasure->setHidden(true); m_configScheme->setHidden(true); } } void DataCollectionWidget::slotCalc() { DataTableWidget *table = dynamic_cast(m_tab->currentWidget()); if (table == nullptr) { return; } } void DataCollectionWidget::slotImportData(UserConfig *config) { QFileDialog::Options options; options |= QFileDialog::DontUseNativeDialog; QString selectedFilter; QString fileName = QFileDialog::getOpenFileName(this, "选择文件", "", "文件(*.csv *.xls *.xlsx)", &selectedFilter, options); bool fileValid = true; if (fileName.isEmpty() || fileName.size() <= 0) { fileValid = false; return; } // 校验提醒 QStringList strList = fileName.split("/"); QStringList names = strList.at(strList.size() - 1).split("-"); if (names.at(0) != config->userName) { QMessageBox::warning(this, tr("失败"), tr("请确认专家名称")); fileValid = false; return; } DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget(); QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType); if (names.at(1) != indexName) { QMessageBox::warning(this, tr("失败"), tr("请确认工程类型")); fileValid = false; return; } if (names.at(2).split(".").at(0) != m_proj->projectName) { QMessageBox::warning(this, tr("失败"), tr("请确认工程名称")); fileValid = false; return; } // 读取文件内容 QXlsx::Document xlsxR(fileName); QStringList str = xlsxR.sheetNames(); qDebug() << __FUNCTION__ << __LINE__ << fileValid << str << endl; int size = 0; bool userinfo = false; if (str.contains("专家信息")) { size = str.size() - 1; userinfo = true; } else { size = str.size(); } // 遍历sheet页 QList nodeMatrxInfoList; for (int i = 0; i < size; i++) { QString mark = "1"; if (i != 0) { mark = "2"; } xlsxR.selectSheet(str.at(i)); if (xlsxR.load()) { int row = xlsxR.dimension().lastRow(); int col = xlsxR.dimension().lastColumn(); for (int r = 2; r <= row; r++) { for (int c = 2; c <= col; c++) { QString abscissa; QString ordinate; QString nodeValue; QXlsx::Cell *cellAbscissa = xlsxR.cellAt(r, 1); if (cellAbscissa != NULL) { QVariant var = cellAbscissa->readValue(); abscissa = var.toString(); } QXlsx::Cell *cellOrdinate = xlsxR.cellAt(1, c); if (cellOrdinate != NULL) { QVariant var = cellOrdinate->readValue(); ordinate = var.toString(); } QXlsx::Cell *value = xlsxR.cellAt(r, c); if (value != NULL) { QVariant var = value->readValue(); nodeValue = var.toString(); } NodeMatrixInfo *nodeInfo = new NodeMatrixInfo(); nodeInfo->expertId = QString::number(config->userId); nodeInfo->expertName = config->userName; nodeInfo->abscissa = abscissa; nodeInfo->ordinate = ordinate; nodeInfo->nodeValue = nodeValue; nodeInfo->engineerId = config->engineerId; nodeInfo->mark = mark; nodeInfo->tableMsg = indexName; nodeInfo->mindId = table->process().dSource; nodeInfo->writeDate = QDateTime::currentDateTime(); if (i != 0) { nodeInfo->node = "1." + QString::number(i) + "." + QString::number(r - 1); } else { nodeInfo->node = "1." + QString::number(r - 1); } nodeMatrxInfoList.append(nodeInfo); } } } } // 更新数据库 if (NodeMatrixService().QueryNodeMatrixListByExpertIdAndEngineerId(QString::number(config->userId), config->engineerId, indexName)) { NodeMatrixService().UpdateNodeMatrixNodeValueList(nodeMatrxInfoList); qDebug() << __FUNCTION__ << __LINE__ << "import data update" << endl; } else { NodeMatrixService().AddNodeMatrixInfoList(nodeMatrxInfoList); qDebug() << __FUNCTION__ << __LINE__ << "import data add" << endl; } // 如果有专家信息更新用户 if (userinfo) { xlsxR.selectSheet(str[size]); QFUser user; if (UserService().QueryUserInfoById(&user, xlsxR.cellAt(2, 1)->readValue().toInt())) { user.workPosition = xlsxR.cellAt(2, 3)->readValue().toString(); user.post = xlsxR.cellAt(2, 4)->readValue().toString(); user.major = xlsxR.cellAt(2, 5)->readValue().toString(); user.phone = xlsxR.cellAt(2, 6)->readValue().toString(); user.writeTime = xlsxR.cellAt(2, 7)->readValue().toString(); user.remark = xlsxR.cellAt(2, 8)->readValue().toString(); UserService().UpdateUserInfo(user); } } QMessageBox::information(this, tr("成功"), tr("数据保存成功")); } void DataCollectionWidget::slotConfigSelected(UserConfig *config) { DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget(); QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType); MindEvaluation *eval = new MindEvaluation(table->mind1(), MindEvaluation::Merge, indexName, table->process().dSource == SchemePlanManager::FromExpert); eval->updateSeqNodes(); eval->computeWeights(); for (MindNodeItem item : eval->mindNodeWeights) { qDebug() << __FUNCTION__ << __LINE__ << item.name << item.value << item.score << endl; } QList data; NodeMatrixService().QueryNodeMatrixListByExpertIdAndEngineerId(&data, config->userId, config->engineerId, indexName); qDebug() << __FUNCTION__ << __LINE__ << config->engineerId << config->userId << indexName << data.size() << endl; table->setData(data); }