DataCollectionWidget.cpp 15 KB

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