DataCollectionWidget.cpp 13 KB

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