DataCollectionWidget.cpp 13 KB

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