DataCollectionWidget.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. #include "DataCollectionWidget.h"
  2. #include "DataTableWidget.h"
  3. #include "ConfigExpertDataWidget.h"
  4. #include "ConfigMeasureDataWidget.h"
  5. #include "ConfigSchemeDataWidget.h"
  6. #include "AddSchemeWidget.h"
  7. #include "EvalDataManager.h"
  8. #include "algorithm/HierarchicalAnalysis.h"
  9. #include "MindEvaluation.h"
  10. #include "GreyClusteringConfigWidget.h" // 灰色聚类配置
  11. #include "GreyClusteringSampleTable.h" // 灰色聚类评估
  12. #include "MatterElementConfigWidget.h" // 物元分析配置
  13. #include "dbService/SchemeProcessService.h"
  14. #include "dbService/ClassSet.h"
  15. #include "dbService/CNodeDataService.h"
  16. #include "dbService/NodeMatrixService.h"
  17. #include "dbService/UserService.h"
  18. #include "dbService/SchemeInfoService.h"
  19. #include <xlsxdocument.h>
  20. #include <CNode.h>
  21. #include <Widgets/Button.h>
  22. #include <Widgets/ComboBox.h>
  23. #include <QTabWidget>
  24. #include <QBoxLayout>
  25. #include <QMap>
  26. #include <QFileDialog>
  27. #include <QMessageBox>
  28. #include <QComboBox>
  29. #include <QDebug>
  30. DataCollectionWidget::DataCollectionWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent)
  31. {
  32. setTitle("评估数据采集");
  33. m_configExpert = new ConfigExpertDataWidget(this);
  34. m_configMeasure = new ConfigMeasureDataWidget(this);
  35. m_configScheme = new ConfigSchemeDataWidget(this);
  36. m_configMeasure->setFixedWidth(256);
  37. m_configScheme->setFixedWidth(350);
  38. m_contentLayout->addWidget(m_configExpert);
  39. m_contentLayout->addWidget(m_configMeasure);
  40. m_contentLayout->addWidget(m_configScheme);
  41. m_configExpert->setHidden(true);
  42. m_configMeasure->setHidden(true);
  43. m_configScheme->setHidden(true);
  44. m_comboBox = new QComboBox(this);
  45. m_comboBox->addItems({ "结果集结", "矩阵集结" });
  46. m_comboBox->resize(50, 35);
  47. m_calcBtn = new PushButton("更新数据");
  48. m_topLayout->addStretch();
  49. m_topLayout->addWidget(m_comboBox);
  50. m_topLayout->addSpacing(10);
  51. m_topLayout->addWidget(m_calcBtn);
  52. m_addSchemeWidget = new AddSchemeWidget(this);
  53. connect(m_calcBtn, &PushButton::clicked, this, &DataCollectionWidget::slotCalc);
  54. connect(m_tab, &QTabWidget::currentChanged, this, &DataCollectionWidget::slotTabCurrentChanged);
  55. connect(m_configExpert, &ConfigExpertDataWidget::sigImportData, this, &DataCollectionWidget::slotImportData);
  56. connect(m_configExpert, &ConfigExpertDataWidget::sigConfigSelected, this,
  57. &DataCollectionWidget::slotConfigSelected);
  58. connect(m_configScheme, &ConfigSchemeDataWidget::sigAddScheme, this, &DataCollectionWidget::slotAddScheme);
  59. connect(m_configMeasure, &ConfigMeasureDataWidget::sigAddData, this, &DataCollectionWidget::slotAddData);
  60. connect(m_addSchemeWidget, &AddSchemeWidget::sigSchemeInfoConfirmed, this,
  61. &DataCollectionWidget::slotAddSchemeInfo);
  62. }
  63. void DataCollectionWidget::setType(int type)
  64. {
  65. EvalWidget::setType(type);
  66. setupTabWidget();
  67. }
  68. ///
  69. /// \brief DataCollectionWidget::setupTabWidget
  70. /// 根据评估类型, 评估方案, 评估算法, 加载合适的数据导入界面
  71. void DataCollectionWidget::setupTabWidget()
  72. {
  73. m_tab->clear();
  74. QMap<int, QList<CNodeData>> nodeListMap;
  75. for (int i : indexList()) {
  76. // 获取指标体系数据
  77. QList<CNodeData> nodeList;
  78. bool ret = CNodeDataService().QueryAll(nodeList, m_proj->id, i);
  79. if (ret) {
  80. nodeListMap[i] = nodeList;
  81. } else {
  82. return;
  83. }
  84. // 获取方案规划数据
  85. QList<SchemePlanManager::SchemeProcessInfo> processList;
  86. ret = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, i);
  87. if (ret == false) {
  88. return;
  89. }
  90. ProjectManager::IndexType t = (ProjectManager::IndexType)i;
  91. QString indexName = ProjectManager::nameOfIndexType(t);
  92. // 效能评估方案中导入评估数据的步骤, 选择物元分析法时使用
  93. SchemePlanManager::SchemeProcessInfo importEffiEvalDataProcess;
  94. for (SchemePlanManager::SchemeProcessInfo process : processList) {
  95. // 综合效能评估 - 灰色聚类法: 效能等级配置页面, 导入评估数据页面
  96. if (process.algorithm == SchemePlanManager::GCE && process.indexType == ProjectManager::EfficiencyIndex) {
  97. CMind *mind = new CMind(this);
  98. mind->setNodeList(nodeListMap[i]);
  99. GreyClusteringConfigWidget *gc = new GreyClusteringConfigWidget(mind, process.efficiencyGrades);
  100. m_tab->addTab(gc, indexName + " - " + "灰色聚类法效能等级配置");
  101. GreyClusteringSampleTable *gs = new GreyClusteringSampleTable(mind, process.efficiencyGrades);
  102. m_tab->addTab(gs, indexName + " - " + "收集效能评估数据");
  103. }
  104. // 综合效能评估 - 物元分析法: 效能等级配置页面, 导入评估数据页面
  105. if (process.algorithm == SchemePlanManager::MEA && process.indexType == ProjectManager::EfficiencyIndex) {
  106. QList<MEConfigItem> items;
  107. CMind *mind = new CMind(this);
  108. mind->setNodeList(nodeListMap[i]);
  109. MatterElementConfigWidget *mec = new MatterElementConfigWidget(mind, process.efficiencyGrades);
  110. m_tab->addTab(mec, indexName + "-" + "物元分析法效能等级配置");
  111. DataTableWidget *table = new DataTableWidget(importEffiEvalDataProcess, this);
  112. table->mind1()->setNodeList(nodeListMap[i]);
  113. table->setupModels();
  114. m_tab->addTab(table, indexName + " - " + "收集效能评估数据");
  115. }
  116. // 导入效能评估的权重分析数据
  117. // 导入其他评估的权重分析数据和评估数据
  118. if (process.dSource >= 0) {
  119. if (process.type == SchemePlanManager::ImportEvalData
  120. && process.indexType == ProjectManager::EfficiencyIndex) {
  121. importEffiEvalDataProcess = process;
  122. continue;
  123. }
  124. DataTableWidget *table = new DataTableWidget(process, this);
  125. table->mind1()->setNodeList(nodeListMap[i]);
  126. if (i == ProjectManager::TechIndex) {
  127. table->mind2()->setNodeList(nodeListMap[ProjectManager::AbilityIndex]);
  128. }
  129. table->setupModels();
  130. QString processName = SchemePlanManager::processName(process);
  131. m_tab->addTab(table, indexName + " - " + processName);
  132. }
  133. }
  134. }
  135. }
  136. void DataCollectionWidget::refreshSchemeData()
  137. {
  138. m_configScheme->loadData();
  139. }
  140. void DataCollectionWidget::slotTabCurrentChanged(int index)
  141. {
  142. DataTableWidget *table = dynamic_cast<DataTableWidget *>(m_tab->widget(index));
  143. if (index >= 0 && table != nullptr) {
  144. bool expert = (table->process().dSource == SchemePlanManager::FromExpert);
  145. if (expert) {
  146. m_configExpert->setProcess(table->process());
  147. }
  148. m_configExpert->setVisible(expert);
  149. bool scheme = (table->process().indexType != ProjectManager::TechIndex
  150. && table->process().type == SchemePlanManager::ImportEvalData);
  151. if (scheme) {
  152. m_configScheme->setProcess(table->process());
  153. }
  154. m_configScheme->setVisible(scheme);
  155. bool meaure = (table->process().dSource == SchemePlanManager::FromMeasurement) && !scheme;
  156. if (meaure) {
  157. m_configMeasure->setProcess(table->process());
  158. }
  159. m_configMeasure->setVisible(meaure);
  160. }
  161. if (table == nullptr) {
  162. m_configExpert->setHidden(true);
  163. m_configMeasure->setHidden(true);
  164. m_configScheme->setHidden(true);
  165. }
  166. }
  167. void DataCollectionWidget::slotCalc()
  168. {
  169. DataTableWidget *table = dynamic_cast<DataTableWidget *>(m_tab->currentWidget());
  170. if (table != nullptr) {
  171. QTableView *tableView = (QTableView *)table->tabWidget()->currentWidget();
  172. DataTableItemModel *model = (DataTableItemModel *)tableView->model();
  173. int schemeStart = -1; // 表中方案数据开始列
  174. if (table->process().indexType == ProjectManager::OptimalIndex) {
  175. schemeStart = 2;
  176. } else if (table->process().indexType == ProjectManager::EfficiencyIndex) {
  177. schemeStart = 1;
  178. }
  179. qDebug() << schemeStart;
  180. /// 存储方案数据
  181. /// @attention 缺少数据库更新接口
  182. if (model->columnCount() > schemeStart && schemeStart > 0) {
  183. QList<SchemaEval *> schemeList = m_configScheme->schemeList();
  184. for (SchemaEval *scheme : schemeList) {
  185. for (int i = schemeStart; i < model->columnCount(); i++) {
  186. QStandardItem *hHeader = model->horizontalHeaderItem(i);
  187. if (hHeader->text() != scheme->name) {
  188. continue;
  189. }
  190. QStringList list;
  191. for (int j = 0; j < model->rowCount(); j++) {
  192. QStandardItem *vHeader = model->verticalHeaderItem(j);
  193. QStandardItem *item = model->item(j, i);
  194. if (item != nullptr && item->text().trimmed().length() > 0) {
  195. QString value = QString("%1:%2").arg(vHeader->text()).arg(item->text());
  196. list.append(value);
  197. }
  198. }
  199. QString str = list.join(";");
  200. scheme->valueStr = str;
  201. qDebug() << scheme->id << scheme->name << str;
  202. }
  203. }
  204. }
  205. }
  206. GreyClusteringSampleTable *gcSample = dynamic_cast<GreyClusteringSampleTable *>(m_tab->currentWidget());
  207. if (gcSample != nullptr) {
  208. // gcSample->compute();
  209. }
  210. GreyClusteringConfigWidget *gcConfig = dynamic_cast<GreyClusteringConfigWidget *>(m_tab->currentWidget());
  211. if (gcConfig != nullptr) {
  212. qDebug() << __FUNCTION__ << __LINE__ << "gc" << endl;
  213. }
  214. }
  215. void DataCollectionWidget::slotImportData(UserConfig *config)
  216. {
  217. QFileDialog::Options options;
  218. options |= QFileDialog::DontUseNativeDialog;
  219. QString selectedFilter;
  220. QString fileName =
  221. QFileDialog::getOpenFileName(this, "选择文件", "", "文件(*.csv *.xls *.xlsx)", &selectedFilter, options);
  222. bool fileValid = true;
  223. if (fileName.isEmpty() || fileName.size() <= 0) {
  224. fileValid = false;
  225. return;
  226. }
  227. // 校验提醒
  228. QStringList strList = fileName.split("/");
  229. QStringList names = strList.at(strList.size() - 1).split("-");
  230. if (names.at(0) != config->userName) {
  231. QMessageBox::warning(this, tr("失败"), tr("请确认专家名称"));
  232. fileValid = false;
  233. return;
  234. }
  235. DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
  236. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType);
  237. if (names.at(1) != indexName) {
  238. QMessageBox::warning(this, tr("失败"), tr("请确认工程类型"));
  239. fileValid = false;
  240. return;
  241. }
  242. if (names.at(2).split(".").at(0) != m_proj->projectName) {
  243. QMessageBox::warning(this, tr("失败"), tr("请确认工程名称"));
  244. fileValid = false;
  245. return;
  246. }
  247. // 读取文件内容
  248. QXlsx::Document xlsxR(fileName);
  249. QStringList str = xlsxR.sheetNames();
  250. qDebug() << __FUNCTION__ << __LINE__ << fileValid << str << endl;
  251. int size = 0;
  252. bool userinfo = false;
  253. if (str.contains("专家信息")) {
  254. size = str.size() - 1;
  255. userinfo = true;
  256. } else {
  257. size = str.size();
  258. }
  259. // 遍历sheet页
  260. QList<NodeMatrixInfo *> nodeMatrxInfoList;
  261. for (int i = 0; i < size; i++) {
  262. QString mark = "1";
  263. if (i != 0) {
  264. mark = "2";
  265. }
  266. xlsxR.selectSheet(str.at(i));
  267. if (xlsxR.load()) {
  268. int row = xlsxR.dimension().lastRow();
  269. int col = xlsxR.dimension().lastColumn();
  270. for (int r = 2; r <= row; r++) {
  271. for (int c = 2; c <= col; c++) {
  272. QString abscissa;
  273. QString ordinate;
  274. QString nodeValue;
  275. QXlsx::Cell *cellAbscissa = xlsxR.cellAt(r, 1);
  276. if (cellAbscissa != NULL) {
  277. QVariant var = cellAbscissa->readValue();
  278. ordinate = var.toString();
  279. }
  280. QXlsx::Cell *cellOrdinate = xlsxR.cellAt(1, c);
  281. if (cellOrdinate != NULL) {
  282. QVariant var = cellOrdinate->readValue();
  283. abscissa = var.toString();
  284. }
  285. QXlsx::Cell *value = xlsxR.cellAt(r, c);
  286. if (value != NULL) {
  287. QVariant var = value->readValue();
  288. nodeValue = var.toString();
  289. }
  290. NodeMatrixInfo *nodeInfo = new NodeMatrixInfo();
  291. nodeInfo->expertId = QString::number(config->userId);
  292. nodeInfo->expertName = config->userName;
  293. nodeInfo->abscissa = abscissa;
  294. nodeInfo->ordinate = ordinate;
  295. nodeInfo->nodeValue = nodeValue;
  296. nodeInfo->engineerId = config->engineerId;
  297. nodeInfo->mark = mark;
  298. nodeInfo->tableMsg = indexName;
  299. nodeInfo->mindId = table->process().dSource;
  300. nodeInfo->writeDate = QDateTime::currentDateTime();
  301. if (i != 0) {
  302. nodeInfo->node = "1." + QString::number(i) + "." + QString::number(r - 1);
  303. } else {
  304. nodeInfo->node = "1." + QString::number(r - 1);
  305. }
  306. nodeMatrxInfoList.append(nodeInfo);
  307. }
  308. }
  309. }
  310. }
  311. // 更新数据库
  312. if (NodeMatrixService().QueryNodeMatrixListByExpertIdAndEngineerId(QString::number(config->userId),
  313. config->engineerId, indexName)) {
  314. bool ret = NodeMatrixService().UpdateNodeMatrixNodeValueList(nodeMatrxInfoList);
  315. qDebug() << __FUNCTION__ << __LINE__ << "import data update" << ret << endl;
  316. } else {
  317. bool ret = NodeMatrixService().AddNodeMatrixInfoList(nodeMatrxInfoList);
  318. qDebug() << __FUNCTION__ << __LINE__ << "import data add" << ret << endl;
  319. }
  320. // 如果有专家信息更新用户
  321. if (userinfo) {
  322. xlsxR.selectSheet(str[size]);
  323. QFUser user;
  324. if (UserService().QueryUserInfoById(&user, xlsxR.cellAt(2, 1)->readValue().toInt())) {
  325. user.workPosition = xlsxR.cellAt(2, 3)->readValue().toString();
  326. user.post = xlsxR.cellAt(2, 4)->readValue().toString();
  327. user.major = xlsxR.cellAt(2, 5)->readValue().toString();
  328. user.phone = xlsxR.cellAt(2, 6)->readValue().toString();
  329. user.writeTime = xlsxR.cellAt(2, 7)->readValue().toString();
  330. user.remark = xlsxR.cellAt(2, 8)->readValue().isNull() ? "" : xlsxR.cellAt(2, 8)->readValue().toString();
  331. UserService().UpdateUserInfo(user);
  332. }
  333. }
  334. QMessageBox::information(this, tr("成功"), tr("数据保存成功"));
  335. }
  336. void DataCollectionWidget::slotConfigSelected(UserConfig *config)
  337. {
  338. DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
  339. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType);
  340. // MindEvaluation *eval =
  341. // new MindEvaluation(table->mind1(), MindEvaluation::NoMerge, indexName, table->process().dSource);
  342. // eval->updateSeqNodes();
  343. // eval->computeWeights();
  344. // for (MindNodeItem item : eval->mindNodeWeights) {
  345. // qDebug() << __FUNCTION__ << __LINE__ << item.name << item.value << item.score << endl;
  346. // }
  347. QList<NodeMatrixInfo *> data;
  348. NodeMatrixService().QueryNodeMatrixListByExpertIdAndEngineerId(&data, config->userId, config->engineerId,
  349. indexName);
  350. table->setNodeMatrixData(data);
  351. }
  352. void DataCollectionWidget::slotAddScheme()
  353. {
  354. DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
  355. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType);
  356. QString processName = SchemePlanManager::processName(table->process());
  357. // 判断是否效能评估数据导入
  358. bool isScheme = table->process().indexType == ProjectManager::EfficiencyIndex
  359. || table->process().indexType == ProjectManager::OptimalIndex;
  360. if (isScheme) {
  361. m_addSchemeWidget->show();
  362. }
  363. }
  364. void DataCollectionWidget::slotAddSchemeInfo(const QString name, const QString remark, const QString path)
  365. {
  366. DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
  367. int type = 0;
  368. if (table->process().indexType == ProjectManager::EfficiencyIndex) {
  369. type = 1;
  370. }
  371. SchemaEval *scheme = new SchemaEval();
  372. scheme->engineerId = m_proj->id;
  373. scheme->name = name;
  374. scheme->remark = remark;
  375. scheme->filePath = path;
  376. scheme->type = type;
  377. bool ret = SchemeInfoService().AddSchemeInfoList({ scheme });
  378. if (ret) {
  379. refreshSchemeData();
  380. table->addScheme(scheme);
  381. }
  382. }
  383. void DataCollectionWidget::slotAddData()
  384. {
  385. DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
  386. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType);
  387. QString processName = SchemePlanManager::processName(table->process());
  388. qDebug() << __FUNCTION__ << __LINE__ << indexName << processName << endl;
  389. }