DataCollectionWidget.cpp 12 KB

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