DataCollectionWidget.cpp 13 KB

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