DataCollectionWidget.cpp 14 KB

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