DataCollectionWidget.cpp 14 KB

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