DataCollectionWidget.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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(256);
  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. GreyClusteringSampleTable *gcSample = dynamic_cast<GreyClusteringSampleTable *>(m_tab->currentWidget());
  172. if (gcSample != nullptr) {
  173. gcSample->compute();
  174. }
  175. QTableView *tableView = (QTableView *)table->tabWidget()->currentWidget();
  176. DataTableItemModel *model = (DataTableItemModel *)tableView->model();
  177. qDebug() << __FUNCTION__ << __LINE__ << tableView << model << endl;
  178. GreyClusteringConfigWidget *gc = dynamic_cast<GreyClusteringConfigWidget *>(m_tab->currentWidget());
  179. if (gc != nullptr) {
  180. qDebug() << __FUNCTION__ << __LINE__ << "gc" << endl;
  181. }
  182. }
  183. void DataCollectionWidget::slotImportData(UserConfig *config)
  184. {
  185. QFileDialog::Options options;
  186. options |= QFileDialog::DontUseNativeDialog;
  187. QString selectedFilter;
  188. QString fileName =
  189. QFileDialog::getOpenFileName(this, "选择文件", "", "文件(*.csv *.xls *.xlsx)", &selectedFilter, options);
  190. bool fileValid = true;
  191. if (fileName.isEmpty() || fileName.size() <= 0) {
  192. fileValid = false;
  193. return;
  194. }
  195. // 校验提醒
  196. QStringList strList = fileName.split("/");
  197. QStringList names = strList.at(strList.size() - 1).split("-");
  198. if (names.at(0) != config->userName) {
  199. QMessageBox::warning(this, tr("失败"), tr("请确认专家名称"));
  200. fileValid = false;
  201. return;
  202. }
  203. DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
  204. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType);
  205. if (names.at(1) != indexName) {
  206. QMessageBox::warning(this, tr("失败"), tr("请确认工程类型"));
  207. fileValid = false;
  208. return;
  209. }
  210. if (names.at(2).split(".").at(0) != m_proj->projectName) {
  211. QMessageBox::warning(this, tr("失败"), tr("请确认工程名称"));
  212. fileValid = false;
  213. return;
  214. }
  215. // 读取文件内容
  216. QXlsx::Document xlsxR(fileName);
  217. QStringList str = xlsxR.sheetNames();
  218. qDebug() << __FUNCTION__ << __LINE__ << fileValid << str << endl;
  219. int size = 0;
  220. bool userinfo = false;
  221. if (str.contains("专家信息")) {
  222. size = str.size() - 1;
  223. userinfo = true;
  224. } else {
  225. size = str.size();
  226. }
  227. // 遍历sheet页
  228. QList<NodeMatrixInfo *> nodeMatrxInfoList;
  229. for (int i = 0; i < size; i++) {
  230. QString mark = "1";
  231. if (i != 0) {
  232. mark = "2";
  233. }
  234. xlsxR.selectSheet(str.at(i));
  235. if (xlsxR.load()) {
  236. int row = xlsxR.dimension().lastRow();
  237. int col = xlsxR.dimension().lastColumn();
  238. for (int r = 2; r <= row; r++) {
  239. for (int c = 2; c <= col; c++) {
  240. QString abscissa;
  241. QString ordinate;
  242. QString nodeValue;
  243. QXlsx::Cell *cellAbscissa = xlsxR.cellAt(r, 1);
  244. if (cellAbscissa != NULL) {
  245. QVariant var = cellAbscissa->readValue();
  246. ordinate = var.toString();
  247. }
  248. QXlsx::Cell *cellOrdinate = xlsxR.cellAt(1, c);
  249. if (cellOrdinate != NULL) {
  250. QVariant var = cellOrdinate->readValue();
  251. abscissa = var.toString();
  252. }
  253. QXlsx::Cell *value = xlsxR.cellAt(r, c);
  254. if (value != NULL) {
  255. QVariant var = value->readValue();
  256. nodeValue = var.toString();
  257. }
  258. NodeMatrixInfo *nodeInfo = new NodeMatrixInfo();
  259. nodeInfo->expertId = QString::number(config->userId);
  260. nodeInfo->expertName = config->userName;
  261. nodeInfo->abscissa = abscissa;
  262. nodeInfo->ordinate = ordinate;
  263. nodeInfo->nodeValue = nodeValue;
  264. nodeInfo->engineerId = config->engineerId;
  265. nodeInfo->mark = mark;
  266. nodeInfo->tableMsg = indexName;
  267. nodeInfo->mindId = table->process().dSource;
  268. nodeInfo->writeDate = QDateTime::currentDateTime();
  269. if (i != 0) {
  270. nodeInfo->node = "1." + QString::number(i) + "." + QString::number(r - 1);
  271. } else {
  272. nodeInfo->node = "1." + QString::number(r - 1);
  273. }
  274. nodeMatrxInfoList.append(nodeInfo);
  275. }
  276. }
  277. }
  278. }
  279. // 更新数据库
  280. if (NodeMatrixService().QueryNodeMatrixListByExpertIdAndEngineerId(QString::number(config->userId),
  281. config->engineerId, indexName)) {
  282. bool ret = NodeMatrixService().UpdateNodeMatrixNodeValueList(nodeMatrxInfoList);
  283. qDebug() << __FUNCTION__ << __LINE__ << "import data update" << ret << endl;
  284. } else {
  285. bool ret = NodeMatrixService().AddNodeMatrixInfoList(nodeMatrxInfoList);
  286. qDebug() << __FUNCTION__ << __LINE__ << "import data add" << ret << endl;
  287. }
  288. // 如果有专家信息更新用户
  289. if (userinfo) {
  290. xlsxR.selectSheet(str[size]);
  291. QFUser user;
  292. if (UserService().QueryUserInfoById(&user, xlsxR.cellAt(2, 1)->readValue().toInt())) {
  293. user.workPosition = xlsxR.cellAt(2, 3)->readValue().toString();
  294. user.post = xlsxR.cellAt(2, 4)->readValue().toString();
  295. user.major = xlsxR.cellAt(2, 5)->readValue().toString();
  296. user.phone = xlsxR.cellAt(2, 6)->readValue().toString();
  297. user.writeTime = xlsxR.cellAt(2, 7)->readValue().toString();
  298. user.remark = xlsxR.cellAt(2, 8)->readValue().isNull() ? "" : xlsxR.cellAt(2, 8)->readValue().toString();
  299. UserService().UpdateUserInfo(user);
  300. }
  301. }
  302. QMessageBox::information(this, tr("成功"), tr("数据保存成功"));
  303. }
  304. void DataCollectionWidget::slotConfigSelected(UserConfig *config)
  305. {
  306. DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
  307. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType);
  308. // MindEvaluation *eval =
  309. // new MindEvaluation(table->mind1(), MindEvaluation::NoMerge, indexName, table->process().dSource);
  310. // eval->updateSeqNodes();
  311. // eval->computeWeights();
  312. // for (MindNodeItem item : eval->mindNodeWeights) {
  313. // qDebug() << __FUNCTION__ << __LINE__ << item.name << item.value << item.score << endl;
  314. // }
  315. QList<NodeMatrixInfo *> data;
  316. NodeMatrixService().QueryNodeMatrixListByExpertIdAndEngineerId(&data, config->userId, config->engineerId,
  317. indexName);
  318. table->setNodeMatrixData(data);
  319. }
  320. void DataCollectionWidget::slotAddScheme()
  321. {
  322. DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
  323. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType);
  324. QString processName = SchemePlanManager::processName(table->process());
  325. // 判断是否效能评估数据导入
  326. bool isScheme = table->process().indexType == ProjectManager::EfficiencyIndex
  327. || table->process().indexType == ProjectManager::OptimalIndex;
  328. if (isScheme) {
  329. m_addSchemeWidget->show();
  330. }
  331. }
  332. void DataCollectionWidget::slotAddSchemeInfo(const QString name, const QString remark, const QString path)
  333. {
  334. DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
  335. int type = 0;
  336. if (table->process().indexType == ProjectManager::EfficiencyIndex) {
  337. type = 1;
  338. }
  339. SchemaEval *scheme = new SchemaEval();
  340. scheme->engineerId = m_proj->id;
  341. scheme->name = name;
  342. scheme->remark = remark;
  343. scheme->filePath = path;
  344. scheme->type = type;
  345. bool ret = SchemeInfoService().AddSchemeInfoList({ scheme });
  346. if (ret) {
  347. refreshSchemeData();
  348. table->addScheme(scheme);
  349. }
  350. }
  351. void DataCollectionWidget::slotAddData()
  352. {
  353. DataTableWidget *table = (DataTableWidget *)m_tab->currentWidget();
  354. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)table->process().indexType);
  355. QString processName = SchemePlanManager::processName(table->process());
  356. qDebug() << __FUNCTION__ << __LINE__ << indexName << processName << endl;
  357. }