GroupPanelWidget.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #include "GroupPanelWidget.h"
  2. #include "GroupTableWidget.h"
  3. #include "dbService/DBServiceSet.h"
  4. #include "dbService/UserService.h"
  5. #include "dbService/UserConfigService.h"
  6. #include "dbService/NodeMatrixService.h"
  7. #include "dbService/DemandWeightService.h"
  8. #include "ui_GroupPanelWidget.h"
  9. #include <QDebug>
  10. GroupPanelWidget::GroupPanelWidget(QWidget *parent) : QWidget(parent), ui(new Ui::GroupPanelWidget)
  11. {
  12. ui->setupUi(this);
  13. firstLayout = new QGridLayout;
  14. firstPlainWidget = nullptr;
  15. ui->stackedWidget->widget(0)->setLayout(firstLayout);
  16. }
  17. GroupPanelWidget::~GroupPanelWidget()
  18. {
  19. if (currentMindNodes) {
  20. delete currentMindNodes;
  21. }
  22. if (classifiedNodes) {
  23. delete classifiedNodes;
  24. }
  25. if (indexsRefClassifiedNodes) {
  26. delete indexsRefClassifiedNodes;
  27. }
  28. delete ui;
  29. }
  30. void GroupPanelWidget::init(const QStringList &indexsRef, const QStringList &indexs, int engineerId)
  31. {
  32. indexsRefClassifiedNodes = nullptr;
  33. if (!indexsRef.isEmpty()) {
  34. MindNodeManager *indexsRefNodes = new MindNodeManager(); //是否参考指标体系
  35. getMindNodes(indexsRefNodes, indexsRef);
  36. indexsRefClassifiedNodes = new QList<QList<MindNodeManager::NodeMessage>>;
  37. sortMindNodes(*indexsRefNodes, indexsRefClassifiedNodes);
  38. delete indexsRefNodes;
  39. } else {
  40. indexsRefClassifiedNodes = nullptr;
  41. }
  42. if (!indexs.isEmpty()) {
  43. currentMindNodes = new MindNodeManager();
  44. classifiedNodes = new QList<QList<MindNodeManager::NodeMessage>>;
  45. getMindNodes(currentMindNodes, indexs);
  46. sortMindNodes(*currentMindNodes, classifiedNodes);
  47. } else {
  48. currentMindNodes = nullptr;
  49. classifiedNodes = nullptr;
  50. }
  51. initPlainWidget(engineerId);
  52. }
  53. void GroupPanelWidget::setViewType(int type)
  54. {
  55. analysisViewType = type;
  56. }
  57. void GroupPanelWidget::setArithmeticMethod(QString method)
  58. {
  59. arithmeticMethod = method;
  60. }
  61. //节点排序
  62. void GroupPanelWidget::sortMindNodes(const MindNodeManager &manager,
  63. QList<QList<MindNodeManager::NodeMessage>> *classify)
  64. {
  65. for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
  66. QStringList nodePonit = msg.node.split(".");
  67. while (nodePonit.count() - 1 > classify->count()) {
  68. (*classify) << QList<MindNodeManager::NodeMessage>();
  69. }
  70. (*classify)[nodePonit.count() - 2] << msg;
  71. }
  72. }
  73. //获取脑图节点
  74. void GroupPanelWidget::getMindNodes(MindNodeManager *manager, QStringList listNodes)
  75. {
  76. int sn[16];
  77. memset(sn, 0, sizeof(int) * 16);
  78. int spaceNum = -1;
  79. int level = 0;
  80. MindNodeManager::NodeMessage temp;
  81. manager->setMindName(listNodes[0].trimmed());
  82. for (int i = 1; i < listNodes.count(); i++) {
  83. int tempSpace = 0;
  84. for (QString s : listNodes[i]) {
  85. if (s == " ") {
  86. tempSpace++;
  87. } else {
  88. break;
  89. }
  90. }
  91. tempSpace /= 4;
  92. if (tempSpace == 1) { //一级
  93. spaceNum = tempSpace;
  94. level = 0;
  95. sn[level]++;
  96. memset((void *)&sn[1], 0, sizeof(int) * 15);
  97. } else {
  98. if (spaceNum < tempSpace) { //空格增加
  99. spaceNum = tempSpace;
  100. level++;
  101. sn[level]++;
  102. } else if (spaceNum == tempSpace) { //同一级
  103. sn[level]++;
  104. } else {
  105. memset((void *)&sn[tempSpace], 0, sizeof(int) * (16 - tempSpace));
  106. level -= spaceNum - tempSpace;
  107. spaceNum = tempSpace;
  108. sn[level]++;
  109. }
  110. }
  111. QString node = "1";
  112. for (int l : sn) {
  113. if (l > 0) {
  114. node += QString(".%1").arg(l);
  115. } else {
  116. break;
  117. }
  118. }
  119. if (listNodes[i].trimmed().isEmpty()) {
  120. temp.name = QString("NULL(节点%1)").arg(node);
  121. temp.node = node;
  122. temp.remark = "";
  123. manager->pushNewMind(temp);
  124. } else {
  125. temp.name = listNodes[i].trimmed().split("\t")[0];
  126. temp.node = node;
  127. temp.remark = listNodes[i].trimmed().split("\t")[1];
  128. manager->pushNewMind(temp);
  129. }
  130. }
  131. }
  132. QStringList GroupPanelWidget::getFirstIndexNodes(const MindNodeManager &manager)
  133. {
  134. QList<QList<MindNodeManager::NodeMessage>> classify;
  135. for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
  136. QStringList nodePonit = msg.node.split(".");
  137. while (nodePonit.count() - 1 > classify.count()) {
  138. classify << QList<MindNodeManager::NodeMessage>();
  139. }
  140. classify[nodePonit.count() - 2] << msg;
  141. }
  142. QStringList firstNodes;
  143. for (MindNodeManager::NodeMessage msg : classify.first()) {
  144. firstNodes << msg.name;
  145. }
  146. return firstNodes;
  147. }
  148. QStringList GroupPanelWidget::getLastIndexNodes(const MindNodeManager &manager)
  149. {
  150. QList<QList<MindNodeManager::NodeMessage>> classify;
  151. for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
  152. QStringList nodePonit = msg.node.split(".");
  153. while (nodePonit.count() - 1 > classify.count()) {
  154. classify << QList<MindNodeManager::NodeMessage>();
  155. }
  156. classify[nodePonit.count() - 2] << msg;
  157. }
  158. QStringList lastNodes;
  159. for (MindNodeManager::NodeMessage msg : classify.last()) {
  160. lastNodes << msg.name;
  161. }
  162. return lastNodes;
  163. }
  164. void GroupPanelWidget::initPlainWidget(int engineerId)
  165. {
  166. demandLists.clear();
  167. technicalImportLists.clear();
  168. //准备第一页,非tab的
  169. GroupTableWidget *table = new GroupTableWidget;
  170. connect(table, &GroupTableWidget::returnModel, this, &GroupPanelWidget::getTableModel);
  171. //获取专家
  172. QList<QFUser *> userInfoList;
  173. if (!UserService().QueryUserListByEngineerId(&userInfoList, engineerId)) {
  174. // QMessageBox::critical(this, "异常", "数据库访问异常!");
  175. return;
  176. }
  177. //获取技术措施指标权重
  178. for (int i = 0; i < userInfoList.size(); i++) {
  179. const QFUser *user = userInfoList.at(i);
  180. QString str = "专家" + QString::number(i + 1) + "-" + user->userName;
  181. UserConfig userConfig;
  182. UserConfigService().QueryUserConfigListInfoByUserIdAndEngineerId(&userConfig, user->id, engineerId);
  183. table->addColNode(QString::number(user->id), str, QString::number(userConfig.weight / 100));
  184. if (analysisViewType == IndexType::IndexTech) {
  185. QList<DemandWeight *> nodeValueInfoList;
  186. DemandWeightService().QuerySecondDemandWeightByEngineerId(&nodeValueInfoList, userInfoList.at(i)->id,
  187. engineerId, "能力重要度评估指标体系");
  188. demandLists.append(nodeValueInfoList);
  189. } else if (analysisViewType == IndexType::SchemaEval) {
  190. QList<DemandWeight *> nodeValueInfoList;
  191. DemandWeightService().QueryLastPageDemandWeightByEngineerId(
  192. &nodeValueInfoList, QString::number(userInfoList.at(i)->id), engineerId, "方案评估指标体系",
  193. (classifiedNodes->count() - 1));
  194. demandLists.append(nodeValueInfoList);
  195. } else {
  196. QList<TechnicalImport *> nodeValueInfoList;
  197. DBServiceSet().QueryTechnicalImportInfoByEngineerId(&nodeValueInfoList, userInfoList.at(i)->id, engineerId);
  198. technicalImportLists.append(nodeValueInfoList);
  199. }
  200. }
  201. if (classifiedNodes->isEmpty()) {
  202. return;
  203. }
  204. if (analysisViewType == IndexType::IndexTech || analysisViewType == SchemaEval) {
  205. for (MindNodeManager::NodeMessage msg : classifiedNodes->last()) {
  206. table->addRowNode(msg.node, msg.name, msg.remark);
  207. }
  208. table->paintDemandTable(demandLists, arithmeticMethod);
  209. } else if (analysisViewType == IndexType::TechMessaure) {
  210. for (MindNodeManager::NodeMessage msg : classifiedNodes->first()) {
  211. table->addRowNode(msg.node, msg.name, msg.remark);
  212. }
  213. table->paintTechnicalTable(technicalImportLists, arithmeticMethod);
  214. } else {
  215. for (MindNodeManager::NodeMessage msg : classifiedNodes->first()) {
  216. table->addRowNode(msg.node, msg.name, msg.remark);
  217. }
  218. table->setTableType(analysisViewType);
  219. table->paintDemandTable(demandLists, arithmeticMethod);
  220. }
  221. firstLayout->addWidget(table);
  222. qDeleteAll(userInfoList);
  223. }
  224. void GroupPanelWidget::getTableModel(QStandardItemModel *item)
  225. {
  226. emit returnModel(item);
  227. }