123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- #include "DataCollectionWidget.h"
- #include "DataTableWidget.h"
- #include "ConfigExpertDataWidget.h"
- #include "ConfigMeasureDataWidget.h"
- #include "ConfigSchemeDataWidget.h"
- #include "CreateSchemeWidget.h"
- #include "EvalDataManager.h"
- #include "algorithm/HierarchicalAnalysis.h"
- #include "MindEvaluation.h"
- #include "DataEvaluator.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 "dbService/SchemeInfoService.h"
- #include <xlsxdocument.h>
- #include <CNode.h>
- #include <Widgets/Button.h>
- #include <Widgets/ComboBox.h>
- #include <QTabWidget>
- #include <QBoxLayout>
- #include <QMap>
- #include <QFileDialog>
- #include <QMessageBox>
- #include <QComboBox>
- #include <QDebug>
- 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(300);
- 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_comboBox = new QComboBox(this);
- m_comboBox->addItems({ "结果集结", "矩阵集结" });
- m_comboBox->resize(50, 35);
- m_calcBtn = new PushButton("更新数据");
- m_topLayout->addStretch();
- m_topLayout->addWidget(m_comboBox);
- m_topLayout->addSpacing(10);
- m_topLayout->addWidget(m_calcBtn);
- m_addSchemeWidget = new CreateSchemeWidget(this);
- m_evaluator = new DataEvaluator(this);
- 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::sigConfigCurrentChanged, this,
- &DataCollectionWidget::slotConfigSelectionChanged);
- connect(m_configScheme, &ConfigSchemeDataWidget::sigAddScheme, this, &DataCollectionWidget::slotAddScheme);
- connect(m_configScheme, &ConfigSchemeDataWidget::sigDeleteScheme, this, &DataCollectionWidget::slotDeleteScheme);
- connect(m_configMeasure, &ConfigMeasureDataWidget::sigAddData, this, &DataCollectionWidget::slotAddMeasureData);
- connect(m_configMeasure, &ConfigMeasureDataWidget::sigCurrentRowChanged, this,
- &DataCollectionWidget::slotCurrentMeasureDataSelected);
- connect(m_addSchemeWidget, &CreateSchemeWidget::sigSchemeInfoConfirmed, this,
- &DataCollectionWidget::slotAddSchemeInfo);
- }
- void DataCollectionWidget::setType(int type)
- {
- EvalWidget::setType(type);
- setupTabWidget();
- }
- ///
- /// \brief DataCollectionWidget::setupTabWidget
- /// 根据评估类型, 评估方案, 评估算法, 加载合适的数据导入界面
- void DataCollectionWidget::setupTabWidget()
- {
- m_tab->clear();
- QMap<int, QList<CNodeData>> nodeListMap;
- for (int i : indexList()) {
- // 获取指标体系数据
- QList<CNodeData> nodeList;
- bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, i);
- if (ret) {
- nodeListMap[i] = nodeList;
- } else {
- return;
- }
- // 获取方案规划数据
- QList<SchemePlanManager::SchemeProcessInfo> 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 + " - " + "灰色聚类法效能等级配置");
- GreyClusteringSampleTable *gs = new GreyClusteringSampleTable(mind, process.efficiencyGrades);
- m_tab->addTab(gs, indexName + " - " + "收集效能评估数据");
- }
- // 综合效能评估 - 物元分析法: 效能等级配置页面, 导入评估数据页面
- if (process.algorithm == SchemePlanManager::MEA && process.indexType == ProjectManager::EfficiencyIndex) {
- QList<MEConfigItem> 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 + " - " + "收集效能评估数据");
- connect(table, &DataTableWidget::sigMeasureDataEdited, this,
- &DataCollectionWidget::slotMeasureDataEdited);
- }
- // 导入效能评估的权重分析数据
- // 导入其他评估的权重分析数据和评估数据
- 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);
- connect(table, &DataTableWidget::sigMeasureDataEdited, this,
- &DataCollectionWidget::slotMeasureDataEdited);
- }
- }
- }
- }
- void DataCollectionWidget::slotTabCurrentChanged(int index)
- {
- if (index < 0) {
- return;
- }
- DataTableWidget *table = dynamic_cast<DataTableWidget *>(m_tab->widget(index));
- if (table != nullptr) {
- bool expert = (table->process().dSource == SchemePlanManager::FromExpert);
- if (expert) {
- m_configExpert->setProcess(table->process());
- }
- m_configExpert->setVisible(expert);
- if (m_configExpert->isVisible()) {
- m_configExpert->loadData();
- m_configExpert->selectFirstImported();
- }
- bool scheme = (table->process().indexType != ProjectManager::TechIndex
- && table->process().type == SchemePlanManager::ImportEvalData);
- if (scheme) {
- m_configScheme->setProcess(table->process());
- }
- m_configScheme->setVisible(scheme);
- bool meaure = (table->process().dSource == SchemePlanManager::FromMeasurement) && !scheme;
- if (meaure) {
- m_configMeasure->setProcess(table->process());
- m_configMeasure->selectFirst();
- }
- m_configMeasure->setVisible(meaure);
- } else {
- m_configExpert->setHidden(true);
- m_configMeasure->setHidden(true);
- m_configScheme->setHidden(true);
- }
- GreyClusteringSampleTable *gs = dynamic_cast<GreyClusteringSampleTable *>(m_tab->widget(index));
- if (gs != nullptr) {
- gs->refreshData();
- }
- }
- void DataCollectionWidget::slotCalc()
- {
- DataTableWidget *table = dynamic_cast<DataTableWidget *>(m_tab->currentWidget());
- if (table != nullptr) {
- // 打印当前页面概要: 指标体系类型,方案步骤(数据种类), 数据来源(专家/实测)
- QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType);
- QString processName = SchemePlanManager::processName(table->process());
- QString dataSource = SchemePlanManager::stringFromDataSource(table->process().dSource);
- /// 运行评估算法
- m_evaluator->setProcess(table->process());
- m_evaluator->setGatherType((DataEvaluator::GatherType)m_comboBox->currentIndex());
- m_evaluator->evaluate();
- }
- GreyClusteringSampleTable *gcSample = dynamic_cast<GreyClusteringSampleTable *>(m_tab->currentWidget());
- if (gcSample != nullptr) {
- gcSample->compute();
- }
- GreyClusteringConfigWidget *gcConfig = dynamic_cast<GreyClusteringConfigWidget *>(m_tab->currentWidget());
- if (gcConfig != nullptr) {
- qDebug() << __FUNCTION__ << __LINE__ << "gc" << endl;
- }
- }
- 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<NodeMatrixInfo *> 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();
- ordinate = var.toString();
- }
- QXlsx::Cell *cellOrdinate = xlsxR.cellAt(1, c);
- if (cellOrdinate != NULL) {
- QVariant var = cellOrdinate->readValue();
- abscissa = 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)) {
- bool ret = NodeMatrixService().UpdateNodeMatrixNodeValueList(nodeMatrxInfoList);
- qDebug() << __FUNCTION__ << __LINE__ << "import data update" << ret << endl;
- } else {
- bool ret = NodeMatrixService().AddNodeMatrixInfoList(nodeMatrxInfoList);
- qDebug() << __FUNCTION__ << __LINE__ << "import data add" << ret << 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().isNull() ? "" : xlsxR.cellAt(2, 8)->readValue().toString();
- UserService().UpdateUserInfo(user);
- }
- }
- QMessageBox::information(this, tr("成功"), tr("数据保存成功"));
- m_configExpert->loadNodeData();
- m_configExpert->selectConfig(config);
- }
- void DataCollectionWidget::slotConfigSelectionChanged()
- {
- DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
- table->setNodeMatrixData(m_configExpert->selectedData(), true);
- }
- void DataCollectionWidget::slotAddScheme()
- {
- DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
- QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType);
- QString processName = SchemePlanManager::processName(table->process());
- // 判断是否效能评估数据导入
- bool isScheme = table->process().indexType == ProjectManager::EfficiencyIndex
- || table->process().indexType == ProjectManager::OptimalIndex;
- if (isScheme) {
- m_addSchemeWidget->show();
- }
- }
- void DataCollectionWidget::slotDeleteScheme()
- {
- DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
- table->setupModels();
- }
- void DataCollectionWidget::slotAddSchemeInfo(const QString name, const QString remark, const QString path)
- {
- DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
- int type = 0;
- if (table->process().indexType == ProjectManager::EfficiencyIndex) {
- type = 1;
- }
- SchemaEval *scheme = new SchemaEval();
- scheme->engineerId = m_proj->id;
- scheme->name = name;
- scheme->remark = remark;
- scheme->filePath = path;
- scheme->type = type;
- bool ret = SchemeInfoService().AddSchemeInfoList({ scheme });
- if (ret) {
- m_configScheme->loadData();
- table->setupModels();
- m_configScheme->selectLast();
- }
- }
- /// 添加实测数据
- void DataCollectionWidget::slotAddMeasureData()
- {
- static bool isBusing = false;
- if (isBusing) {
- return; // 添加完成后再响应下一次添加
- }
- isBusing = true;
- DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
- QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType);
- QString processName = SchemePlanManager::processName(table->process());
- QDateTime time = QDateTime::currentDateTime();
- QString uuid = QString("%1").arg(time.toMSecsSinceEpoch());
- QList<NodeMatrixInfo *> dataList;
- /// 权重数据
- /// 一种指标: 能力重要度评估指标, 或方案评估指标, 或效能评估指标
- /// 除根节点外, 每个指标一个权重值
- if (table->process().type == SchemePlanManager::ImportWeightData) {
- for (CNodeData n : table->mind1()->nodeList()) {
- if (n.number <= 0) {
- continue;
- }
- NodeMatrixInfo *info = new NodeMatrixInfo();
- info->engineerId = m_proj->id;
- info->mindId = 1;
- info->tableMsg = indexName;
- info->writeDate = time;
- info->strUuid = uuid;
- info->abscissa = n.name;
- info->nodeValue = "0";
- dataList.append(info);
- }
- }
- /// 评估数据
- /// 两种指标: 能力重要度评估指标, 技术措施重要度评估指标
- /// 每个技术措施指标, 对应能力重要度指标体系最后一层指标下的数据
- if (table->process().type == SchemePlanManager::ImportEvalData
- && table->process().indexType == ProjectManager::TechIndex) {
- QList<CNodeData> leaves = table->mind2()->leaves();
- for (CNodeData n1 : table->mind1()->nodeList()) {
- if (n1.number <= 0) {
- continue;
- }
- for (CNodeData n2 : leaves) {
- NodeMatrixInfo *info = new NodeMatrixInfo();
- info->engineerId = m_proj->id;
- info->mindId = 1;
- info->tableMsg = indexName;
- info->writeDate = time;
- info->strUuid = uuid;
- info->abscissa = n1.name;
- info->ordinate = n2.name;
- info->nodeValue = "1";
- dataList.append(info);
- }
- }
- }
- if (dataList.size() > 0) {
- bool ret = NodeMatrixService().AddNodeMatrixInfoList(dataList);
- qDebug() << __FUNCTION__ << __LINE__ << ret << dataList.size() << endl;
- if (ret) {
- m_configMeasure->reloadData();
- m_configMeasure->selectLast();
- }
- }
- isBusing = false;
- }
- void DataCollectionWidget::slotCurrentMeasureDataSelected()
- {
- DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
- table->setNodeMatrixData(m_configMeasure->selectedData(), false);
- }
- void DataCollectionWidget::slotMeasureDataEdited(NodeMatrixInfo *info)
- {
- m_configMeasure->updateNodeValue(info);
- }
|