ExportReportManager.cpp 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  1. #include "ExportReportManager.h"
  2. #include "ProjectManager.h"
  3. #include "SchemePlanManager.h"
  4. #include "CMindView.h"
  5. #include <view/PlotView.h>
  6. #include <dbService/ClassSet.h>
  7. #include <dbService/SchemeInfoService.h>
  8. #include <dbService/CNodeDataService.h>
  9. #include <dbService/SchemeInfoService.h>
  10. #include <dbService/SchemeProcessService.h>
  11. #include <dbService/MindWeightService.h>
  12. #include <dbService/GradeInfoService.h>
  13. #include <dbService/GradeIndexInfoService.h>
  14. #include <dbService/EffectIndexInfoService.h>
  15. #include <dbService/EffectResultService.h>
  16. #include <dbService/MindScoreService.h>
  17. #include <QWord/QWord.h>
  18. #include <QWord/QWordDemo.h>
  19. #include <QDir>
  20. #include <QDate>
  21. #include <QLabel>
  22. #include <QImageWriter>
  23. #include <QDebug>
  24. ExportReportManager::ExportReportManager(QObject *parent) : QObject(parent)
  25. {
  26. m_word = new QWord(this);
  27. }
  28. ExportReportManager::~ExportReportManager()
  29. {
  30. delete m_word;
  31. }
  32. ProjectInfo *ExportReportManager::proj() const
  33. {
  34. return m_proj;
  35. }
  36. void ExportReportManager::setProj(ProjectInfo *proj)
  37. {
  38. m_proj = proj;
  39. }
  40. int ExportReportManager::evalType() const
  41. {
  42. return m_evalType;
  43. }
  44. void ExportReportManager::setEvalType(int type)
  45. {
  46. m_evalType = type;
  47. }
  48. bool ExportReportManager::exportReport()
  49. {
  50. bool createRet = createWord();
  51. if (createRet == false) {
  52. qDebug() << __FUNCTION__ << __LINE__ << m_word->getStrErrorInfo() << endl;
  53. return false;
  54. }
  55. insertProjectInfo();
  56. if (m_evalType == ProjectManager::DemandEval) {
  57. insertDemandAlg();
  58. insertDemandIndex();
  59. insertDemandTechIndex();
  60. insertDemandWeight();
  61. insertDemandEval();
  62. }
  63. if (m_evalType == ProjectManager::OptimalEval) {
  64. insertSchemeDesignInfo();
  65. insertSchemeIndex();
  66. insertSchemeAlgInfo();
  67. insertSchemeData();
  68. insertSchemeWeightData();
  69. }
  70. if (m_evalType == ProjectManager::EfficiencyEval) {
  71. insertEffiIndex();
  72. insertEffiAlgInfo();
  73. insertEffiConfigData();
  74. insertEffiSchemeData();
  75. insertEffiWeightData();
  76. insertEffiResult();
  77. }
  78. m_word->setVisible(true);
  79. QAxObject *doc = m_word->getWordApp()->querySubObject("ActiveDocument");
  80. doc->dynamicCall("SaveAs(const QString&))", QDir::toNativeSeparators(m_word->getFilePath()));
  81. m_word->close();
  82. return true;
  83. }
  84. bool ExportReportManager::createWord()
  85. {
  86. delete m_word;
  87. m_word = new QWord(this);
  88. // 报告文件夹路径
  89. QString curPath = QDir::currentPath();
  90. QString dateStr = QDate::currentDate().toString("yyyy-MM-dd");
  91. QString reportDir = curPath + "/reports/" + dateStr + "/";
  92. QDir dir(reportDir);
  93. if (!dir.exists()) {
  94. dir.mkpath(reportDir);
  95. }
  96. // 根据模板创建 word 文档
  97. QString typeStr = ProjectManager::reportNameOfEvalType((ProjectManager::EvalType)m_evalType);
  98. QString tempPath = curPath + "/report_templates/" + typeStr + ".docx";
  99. if (!QFile::exists(tempPath)) {
  100. qDebug() << __FUNCTION__ << __LINE__ << "Report template not found" << endl;
  101. return false;
  102. }
  103. QString fileName = m_proj->projectName + "_" + typeStr + ".docx";
  104. QString filePath = reportDir + fileName;
  105. if (QFile::exists(filePath)) {
  106. QFile::remove(filePath);
  107. }
  108. bool ret = QFile::copy(tempPath, filePath);
  109. if (ret) {
  110. ret = m_word->open(filePath, false);
  111. } else {
  112. qDebug() << __FUNCTION__ << __LINE__ << "Copy report template failed" << endl;
  113. }
  114. return ret;
  115. }
  116. void ExportReportManager::insertProjectInfo()
  117. {
  118. insertText("bmProjName", m_proj->projectName);
  119. insertText("bmProjUnit", m_proj->estimateDept);
  120. QString dateStr = QDate::currentDate().toString("yyyy年MM月");
  121. insertText("bmProjDate", dateStr);
  122. insertText("bmEvalPurpose", m_proj->estimateObjective);
  123. }
  124. void ExportReportManager::insertDemandAlg()
  125. {
  126. // bmWeightAlg bmEvalAlg
  127. // bmWeightAlgDscpt bmEvalAlgDscpt
  128. QList<SchemePlanManager::SchemeProcessInfo> processList;
  129. bool processRet = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, 1);
  130. if (processRet == false) {
  131. return;
  132. }
  133. for (int i = 0; i < processList.size(); ++i) {
  134. if (processList[i].type == SchemePlanManager::CalculateWeight) {
  135. SchemePlanManager::Algorithm alg = processList[i].algorithm;
  136. QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
  137. insertText("bmWeightAlg", algStr);
  138. QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
  139. insertText("bmWeightAlgDscpt", dscrpt);
  140. }
  141. }
  142. processRet = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, 2);
  143. if (processRet == false) {
  144. return;
  145. }
  146. for (int i = 0; i < processList.size(); ++i) {
  147. if (processList[i].type == SchemePlanManager::RunEvaluate) {
  148. SchemePlanManager::Algorithm alg = processList[i].algorithm;
  149. QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
  150. insertText("bmEvalAlg", algStr);
  151. QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
  152. insertText("bmEvalAlgDscpt", dscrpt);
  153. }
  154. }
  155. }
  156. void ExportReportManager::insertDemandIndex()
  157. {
  158. insertText("bmProjName21", m_proj->projectName);
  159. insertText("bmProjName22", m_proj->projectName);
  160. QList<CNodeData> nodeList;
  161. bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 1);
  162. if (ret == false) {
  163. return;
  164. }
  165. CMind *mind = new CMind();
  166. mind->setNodeList(nodeList);
  167. QList<CNodeData> leaveNodes = mind->leaves();
  168. int rowCount = leaveNodes.size() + 1;
  169. int columnCount = mind->levels();
  170. // bmIndexTable
  171. QAxObject *table = insertTable("bmIndexTable", rowCount, columnCount);
  172. if (table == nullptr) {
  173. delete mind;
  174. return;
  175. }
  176. for (int i = 2; i <= mind->levels(); ++i) {
  177. if (i < mind->levels()) {
  178. setCellString(table, 1, i - 1, QString("%1级指标").arg(i - 1));
  179. } else {
  180. setCellString(table, 1, i - 1, QString("指标"));
  181. setCellString(table, 1, i, QString("量纲"));
  182. }
  183. QList<CNodeData> nodes = mind->nodesInLevel(i);
  184. int rowPos = 2;
  185. for (int j = 0; j < nodes.size(); ++j) {
  186. CNodeData node = nodes[j];
  187. int leaves = mind->leavesCountOfNode(node);
  188. int textPos = (rowPos + leaves / 2);
  189. setCellString(table, textPos, i - 1, node.name);
  190. if (leaves > 1) {
  191. mergeCells(table, rowPos, i - 1, leaves, 1);
  192. }
  193. rowPos += leaves;
  194. }
  195. }
  196. for (int i = 0; i < leaveNodes.size(); ++i) {
  197. CNodeData node = leaveNodes[i];
  198. setCellString(table, i + 2, columnCount, node.dimension);
  199. }
  200. delete mind;
  201. CMindView *m = new CMindView();
  202. m->setNodeList(nodeList);
  203. m->refreshItems();
  204. int sceneWidth = m->sceneRect().width();
  205. int sceneHeight = m->sceneRect().height();
  206. QRectF sourceRect = QRectF(0, 0, sceneWidth, sceneHeight);
  207. QRectF targetRect = QRectF(10, 10, sceneWidth, sceneHeight);
  208. QPixmap pixmap(QSize(sceneWidth + 20, sceneHeight + 20));
  209. pixmap.fill(QColor(244, 244, 255));
  210. QPainter painter(&pixmap);
  211. painter.setRenderHints(QPainter::Antialiasing);
  212. m->scene()->render(&painter, targetRect, sourceRect);
  213. delete m;
  214. QString imgName = QString("%1_%2_index").arg(m_proj->id).arg(1);
  215. QString path = saveImage(imgName, pixmap);
  216. QImageWriter writer(path);
  217. writer.setFormat("PNG");
  218. ret = writer.write(pixmap.toImage());
  219. if (ret) {
  220. QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmIndexPic");
  221. if (bmWeightPic != nullptr) {
  222. bmWeightPic->dynamicCall("Select(void)");
  223. QAxObject *range = bmWeightPic->querySubObject("Range");
  224. QAxObject *inlineShapes = range->querySubObject("InlineShapes");
  225. QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
  226. if (shape != nullptr) {
  227. int w = pixmap.width();
  228. int h = pixmap.height();
  229. if (w > 400) {
  230. h = h * 400 / w;
  231. w = 400;
  232. }
  233. shape->setProperty("Width", w);
  234. shape->setProperty("Height", h);
  235. }
  236. }
  237. }
  238. }
  239. void ExportReportManager::insertDemandTechIndex()
  240. {
  241. insertText("bmProjName31", m_proj->projectName);
  242. insertText("bmProjName32", m_proj->projectName);
  243. QList<CNodeData> nodeList;
  244. bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 2);
  245. if (ret == false) {
  246. return;
  247. }
  248. CMind *mind = new CMind();
  249. mind->setNodeList(nodeList);
  250. QList<CNodeData> leaveNodes = mind->leaves();
  251. int rowCount = leaveNodes.size() + 1;
  252. int columnCount = mind->levels() - 1;
  253. // bmIndexTable
  254. QAxObject *table = insertTable("bmTechTable", rowCount, columnCount);
  255. if (table == nullptr) {
  256. delete mind;
  257. return;
  258. }
  259. for (int i = 2; i <= mind->levels(); ++i) {
  260. if (i < mind->levels()) {
  261. setCellString(table, 1, i - 1, QString("%1级指标").arg(i - 1));
  262. } else {
  263. setCellString(table, 1, i - 1, QString("指标"));
  264. }
  265. QList<CNodeData> nodes = mind->nodesInLevel(i);
  266. int rowPos = 2;
  267. for (int j = 0; j < nodes.size(); ++j) {
  268. CNodeData node = nodes[j];
  269. int leaves = mind->leavesCountOfNode(node);
  270. int textPos = (rowPos + leaves / 2);
  271. setCellString(table, textPos, i - 1, node.name);
  272. if (leaves > 1) {
  273. mergeCells(table, rowPos, i - 1, leaves, 1);
  274. }
  275. rowPos += leaves;
  276. }
  277. }
  278. delete mind;
  279. CMindView *m = new CMindView();
  280. m->setNodeList(nodeList);
  281. m->refreshItems();
  282. int sceneWidth = m->sceneRect().width();
  283. int sceneHeight = m->sceneRect().height();
  284. QRectF sourceRect = QRectF(0, 0, sceneWidth, sceneHeight);
  285. QRectF targetRect = QRectF(10, 10, sceneWidth, sceneHeight);
  286. QPixmap pixmap(QSize(sceneWidth + 20, sceneHeight + 20));
  287. pixmap.fill(QColor(244, 244, 255));
  288. QPainter painter(&pixmap);
  289. painter.setRenderHints(QPainter::Antialiasing);
  290. m->scene()->render(&painter, targetRect, sourceRect);
  291. delete m;
  292. QString imgName = QString("%1_%2_index").arg(m_proj->id).arg(2);
  293. QString path = saveImage(imgName, pixmap);
  294. QImageWriter writer(path);
  295. writer.setFormat("PNG");
  296. ret = writer.write(pixmap.toImage());
  297. if (ret) {
  298. QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmTechPic");
  299. if (bmWeightPic != nullptr) {
  300. bmWeightPic->dynamicCall("Select(void)");
  301. QAxObject *range = bmWeightPic->querySubObject("Range");
  302. QAxObject *inlineShapes = range->querySubObject("InlineShapes");
  303. QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
  304. if (shape != nullptr) {
  305. int w = pixmap.width();
  306. int h = pixmap.height();
  307. if (w > 400) {
  308. h = h * 400 / w;
  309. w = 400;
  310. }
  311. shape->setProperty("Width", w);
  312. shape->setProperty("Height", h);
  313. }
  314. }
  315. }
  316. }
  317. void ExportReportManager::insertDemandWeight()
  318. {
  319. // 指标权重表:bmWeightTable,指标权重图:bmWeightPic
  320. QList<CNodeData> nodeList;
  321. bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 1);
  322. if (ret == false) {
  323. return;
  324. }
  325. CMind *mind = new CMind();
  326. mind->setNodeList(nodeList);
  327. QList<CNodeData> leaveNodes = mind->leaves();
  328. int rowCount = leaveNodes.size() + 1;
  329. int columnCount = mind->levels();
  330. // bmIndexTable
  331. QAxObject *table = insertTable("bmWeightTable", rowCount, columnCount);
  332. if (table == nullptr) {
  333. delete mind;
  334. return;
  335. }
  336. for (int i = 2; i <= mind->levels(); ++i) {
  337. if (i < mind->levels()) {
  338. setCellString(table, 1, i - 1, QString("%1级指标").arg(i - 1));
  339. } else {
  340. setCellString(table, 1, i - 1, QString("指标"));
  341. setCellString(table, 1, i, QString("权重值"));
  342. }
  343. QList<CNodeData> nodes = mind->nodesInLevel(i);
  344. int rowPos = 2;
  345. for (int j = 0; j < nodes.size(); ++j) {
  346. CNodeData node = nodes[j];
  347. int leaves = mind->leavesCountOfNode(node);
  348. int textPos = (rowPos + leaves / 2);
  349. setCellString(table, textPos, i - 1, node.name);
  350. if (leaves > 1) {
  351. mergeCells(table, rowPos, i - 1, leaves, 1);
  352. }
  353. rowPos += leaves;
  354. }
  355. }
  356. delete mind;
  357. MindWeightInfo info;
  358. ret = MindWeightService().queryWeightData(&info, m_proj->id, 1);
  359. if (ret == false) {
  360. return;
  361. }
  362. if (info.id < 0) {
  363. return;
  364. }
  365. QMap<QString, double> weightData;
  366. QStringList weightList = info.weight.split(";");
  367. for (QString keyValueStr : weightList) {
  368. QStringList keyValue = keyValueStr.split(":");
  369. if (keyValue.size() == 2) {
  370. weightData[keyValue.first()] = keyValue.last().toDouble();
  371. }
  372. }
  373. QVector<PlotView::Data> values;
  374. for (int i = 0; i < leaveNodes.size(); ++i) {
  375. CNodeData node = leaveNodes[i];
  376. QString value = QString("%1").arg(weightData[node.name]);
  377. setCellString(table, i + 2, columnCount, value);
  378. PlotView::Data data { node.name, weightData[node.name] };
  379. values.append(data);
  380. }
  381. PlotView *plot = new PlotView(PlotView::HistogramHorizontal, values, "");
  382. plot->setFixedSize(QSize(600, 600));
  383. plot->plot();
  384. QPixmap pixmap = plot->grab();
  385. plot->deleteLater();
  386. if (pixmap.isNull()) {
  387. return;
  388. }
  389. QString imgName = QString("%1_%2_weight_plot").arg(m_proj->id).arg(1);
  390. QString path = saveImage(imgName, pixmap);
  391. QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmWeightPic");
  392. if (bmWeightPic != nullptr) {
  393. bmWeightPic->dynamicCall("Select(void)");
  394. QAxObject *range = bmWeightPic->querySubObject("Range");
  395. QAxObject *inlineShapes = range->querySubObject("InlineShapes");
  396. QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
  397. if (shape != nullptr) {
  398. shape->setProperty("Width", 400);
  399. shape->setProperty("Height", 400);
  400. }
  401. }
  402. }
  403. void ExportReportManager::insertDemandEval()
  404. {
  405. MindScoreInfo info;
  406. bool ret = MindScoreService().queryScoreData(&info, m_proj->id);
  407. if (ret == false || info.id < 0) {
  408. return;
  409. }
  410. QMap<QString, QString> scoreData;
  411. QStringList keyValueStringList = info.score.split(";");
  412. for (QString keyValueString : keyValueStringList) {
  413. QStringList keyValue = keyValueString.split(":");
  414. if (keyValue.size() == 2) {
  415. scoreData[keyValue.first()] = keyValue.last();
  416. }
  417. }
  418. QList<CNodeData> nodeList;
  419. ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 2);
  420. if (ret == false) {
  421. return;
  422. }
  423. CMind *mind = new CMind();
  424. mind->setNodeList(nodeList);
  425. QList<CNodeData> leaveNodes = mind->leaves();
  426. int rowCount = leaveNodes.size() + 1;
  427. int columnCount = mind->levels();
  428. // bmEvalTable
  429. QAxObject *table = insertTable("bmEvalTable", rowCount, columnCount);
  430. if (table == nullptr) {
  431. delete mind;
  432. return;
  433. }
  434. for (int i = 2; i <= mind->levels(); ++i) {
  435. if (i < mind->levels()) {
  436. setCellString(table, 1, i - 1, QString("%1级指标").arg(i - 1));
  437. } else {
  438. setCellString(table, 1, i - 1, QString("指标"));
  439. setCellString(table, 1, i, QString("重要度"));
  440. }
  441. QList<CNodeData> nodes = mind->nodesInLevel(i);
  442. int rowPos = 2;
  443. for (int j = 0; j < nodes.size(); ++j) {
  444. CNodeData node = nodes[j];
  445. int leaves = mind->leavesCountOfNode(node);
  446. int textPos = (rowPos + leaves / 2);
  447. setCellString(table, textPos, i - 1, node.name);
  448. if (leaves > 1) {
  449. mergeCells(table, rowPos, i - 1, leaves, 1);
  450. }
  451. rowPos += leaves;
  452. }
  453. }
  454. delete mind;
  455. QVector<PlotView::Data> values;
  456. for (int i = 0; i < leaveNodes.size(); ++i) {
  457. CNodeData node = leaveNodes[i];
  458. QString value = scoreData[node.name];
  459. setCellString(table, i + 2, columnCount, value);
  460. PlotView::Data data { node.name, value.toDouble() };
  461. values.append(data);
  462. }
  463. PlotView *plot = new PlotView(PlotView::HistogramHorizontal, values, "");
  464. plot->setFixedSize(QSize(600, 600));
  465. plot->plot();
  466. QPixmap pixmap = plot->grab();
  467. plot->deleteLater();
  468. if (pixmap.isNull()) {
  469. return;
  470. }
  471. QString imgName = QString("%1_%2_priority_plot").arg(m_proj->id).arg(1);
  472. QString path = saveImage(imgName, pixmap);
  473. QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmEvalPic");
  474. if (bmWeightPic != nullptr) {
  475. bmWeightPic->dynamicCall("Select(void)");
  476. QAxObject *range = bmWeightPic->querySubObject("Range");
  477. QAxObject *inlineShapes = range->querySubObject("InlineShapes");
  478. QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
  479. if (shape != nullptr) {
  480. shape->setProperty("Width", 400);
  481. shape->setProperty("Height", 400);
  482. }
  483. }
  484. QString viTech;
  485. double score = 0;
  486. for (QString key : scoreData.keys()) {
  487. if (scoreData[key].toDouble() > score) {
  488. score = scoreData[key].toDouble();
  489. viTech = key;
  490. }
  491. }
  492. insertText("bmVITech1", viTech);
  493. insertText("bmVITech2", viTech);
  494. }
  495. void ExportReportManager::insertSchemeDesignInfo()
  496. {
  497. QList<SchemaEval *> schemeList;
  498. bool ret = SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_proj->id, 0);
  499. if (ret == false) {
  500. qDebug() << __FUNCTION__ << __LINE__ << "query" << endl;
  501. return;
  502. }
  503. for (int i = schemeList.size() - 1; i >= 0; --i) {
  504. // 插入图片
  505. QAxObject *bmSchemes = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmSchemes");
  506. if (bmSchemes != nullptr) {
  507. bmSchemes->dynamicCall("Select(void)");
  508. QAxObject *range = bmSchemes->querySubObject("Range");
  509. QAxObject *inlineShapes = range->querySubObject("InlineShapes");
  510. QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", schemeList[i]->filePath);
  511. if (shape != nullptr) {
  512. shape->setProperty("Width", 200);
  513. shape->setProperty("Height", 200);
  514. }
  515. }
  516. m_word->insertMoveDown();
  517. // 插入图片标题
  518. QString remark = schemeList[i]->remark;
  519. int picTtlIndex = remark.lastIndexOf("(图");
  520. QString subStr = remark.mid(picTtlIndex + 1, 8);
  521. QString picTtl = "";
  522. if (subStr.contains(")")) {
  523. picTtl = subStr.split(")").first();
  524. }
  525. m_word->setFontName(QString::fromLocal8Bit("黑体"));
  526. m_word->setFontSize(9);
  527. m_word->setParagraphAlignment(0);
  528. m_word->insertText(picTtl + " " + "阵地位置图");
  529. m_word->insertMoveDown();
  530. // 插入方案描述
  531. insertText("bmSchemes", schemeList[i]->name + ":" + schemeList[i]->remark);
  532. if (i != 0) {
  533. m_word->insertMoveDown();
  534. }
  535. }
  536. }
  537. void ExportReportManager::insertSchemeIndex()
  538. {
  539. insertText("bmProjName31", m_proj->projectName);
  540. insertText("bmProjName32", m_proj->projectName);
  541. QList<CNodeData> nodeList;
  542. bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 4);
  543. if (ret == false) {
  544. return;
  545. }
  546. CMind *mind = new CMind();
  547. mind->setNodeList(nodeList);
  548. QList<CNodeData> leaveNodes = mind->leaves();
  549. int rowCount = leaveNodes.size() + 1;
  550. int columnCount = mind->levels();
  551. // bmIndexTable
  552. QAxObject *table = insertTable("bmIndexTable", rowCount, columnCount);
  553. if (table == nullptr) {
  554. delete mind;
  555. return;
  556. }
  557. for (int i = 2; i <= mind->levels(); ++i) {
  558. if (i < mind->levels()) {
  559. setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
  560. } else {
  561. setCellString(table, 1, i - 1, QString("指标"));
  562. setCellString(table, 1, i, QString("量纲"));
  563. }
  564. QList<CNodeData> nodes = mind->nodesInLevel(i);
  565. int rowPos = 2;
  566. for (int j = 0; j < nodes.size(); ++j) {
  567. CNodeData node = nodes[j];
  568. int leaves = mind->leavesCountOfNode(node);
  569. int textPos = (rowPos + leaves / 2);
  570. setCellString(table, textPos, i - 1, node.name);
  571. if (leaves > 1) {
  572. mergeCells(table, rowPos, i - 1, leaves, 1);
  573. }
  574. rowPos += leaves;
  575. }
  576. }
  577. for (int i = 0; i < leaveNodes.size(); ++i) {
  578. CNodeData node = leaveNodes[i];
  579. setCellString(table, i + 2, columnCount, node.dimension);
  580. }
  581. delete mind;
  582. CMindView *m = new CMindView();
  583. m->setNodeList(nodeList);
  584. m->refreshItems();
  585. int sceneWidth = m->sceneRect().width();
  586. int sceneHeight = m->sceneRect().height();
  587. QRectF sourceRect = QRectF(0, 0, sceneWidth, sceneHeight);
  588. QRectF targetRect = QRectF(10, 10, sceneWidth, sceneHeight);
  589. QPixmap pixmap(QSize(sceneWidth + 20, sceneHeight + 20));
  590. pixmap.fill(QColor(244, 244, 255));
  591. QPainter painter(&pixmap);
  592. painter.setRenderHints(QPainter::Antialiasing);
  593. m->scene()->render(&painter, targetRect, sourceRect);
  594. delete m;
  595. QString imgName = QString("%1_%2_index").arg(m_proj->id).arg(4);
  596. QString path = saveImage(imgName, pixmap);
  597. QImageWriter writer(path);
  598. writer.setFormat("PNG");
  599. ret = writer.write(pixmap.toImage());
  600. if (ret) {
  601. QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmIndexPic");
  602. if (bmWeightPic != nullptr) {
  603. bmWeightPic->dynamicCall("Select(void)");
  604. QAxObject *range = bmWeightPic->querySubObject("Range");
  605. QAxObject *inlineShapes = range->querySubObject("InlineShapes");
  606. QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
  607. if (shape != nullptr) {
  608. int w = pixmap.width();
  609. int h = pixmap.height();
  610. if (w > 400) {
  611. h = h * 400 / w;
  612. w = 400;
  613. }
  614. shape->setProperty("Width", w);
  615. shape->setProperty("Height", h);
  616. }
  617. }
  618. }
  619. }
  620. void ExportReportManager::insertSchemeData()
  621. {
  622. insertText("bmProjName41", m_proj->projectName);
  623. QList<CNodeData> nodeList;
  624. bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 4);
  625. if (ret == false) {
  626. return;
  627. }
  628. CMind *mind = new CMind();
  629. mind->setNodeList(nodeList);
  630. QMap<int, QMap<QString, double>> schemeData;
  631. QMap<int, QString> schemeNames;
  632. QList<SchemaEval *> schemeList;
  633. ret = SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_proj->id, m_schemeType);
  634. if (ret == false || schemeList.size() <= 0) {
  635. delete mind;
  636. return;
  637. }
  638. for (SchemaEval *scheme : schemeList) {
  639. if (schemeData.keys().contains(scheme->id) == false) {
  640. schemeData[scheme->id] = QMap<QString, double>();
  641. }
  642. QStringList keyValueStringList = scheme->valueStr.split(";");
  643. for (QString keyValueStr : keyValueStringList) {
  644. QStringList keyValue = keyValueStr.split(":");
  645. if (keyValue.size() == 2) {
  646. schemeData[scheme->id][keyValue.first()] = keyValue.last().toDouble();
  647. }
  648. }
  649. schemeNames[scheme->id] = scheme->name;
  650. }
  651. QList<CNodeData> leaveNodes = mind->leaves();
  652. int rowCount = leaveNodes.size() + 1;
  653. int columnCount = schemeNames.keys().size() + 1;
  654. delete mind;
  655. // bmSchemeDataTable
  656. QAxObject *table = insertTable("bmSchemeDataTable", rowCount, columnCount);
  657. if (table == nullptr) {
  658. return;
  659. }
  660. QList<int> schemeIds = schemeNames.keys();
  661. for (int i = 0; i < schemeIds.size() + 1; ++i) {
  662. if (i == 0) {
  663. setCellString(table, 1, i + 1, "指标");
  664. } else {
  665. setCellString(table, 1, i + 1, schemeNames[schemeIds[i - 1]]);
  666. }
  667. }
  668. for (int i = 0; i < leaveNodes.size(); ++i) {
  669. CNodeData node = leaveNodes[i];
  670. setCellString(table, i + 2, 1, node.name);
  671. for (int j = 0; j < schemeIds.size(); ++j) {
  672. QString value = QString("%1").arg(schemeData[schemeIds[j]][node.name]);
  673. setCellString(table, i + 2, j + 2, value);
  674. }
  675. }
  676. // 指标权重表:bmEvalTable,指标权重图:bmEvalPic
  677. QAxObject *scoreTable = insertTable("bmEvalTable", schemeList.size() + 1, 2);
  678. if (scoreTable == nullptr) {
  679. return;
  680. }
  681. QVector<PlotView::Data> values;
  682. setCellString(scoreTable, 1, 2, "得分");
  683. for (int i = 0; i < schemeList.size(); ++i) {
  684. setCellString(scoreTable, i + 2, 1, schemeList[i]->name);
  685. QString str = QString::number(schemeList[i]->score, 'f', 2);
  686. setCellString(scoreTable, i + 2, 2, str);
  687. PlotView::Data data { schemeList[i]->name, schemeList[i]->score };
  688. values.append(data);
  689. }
  690. PlotView *plot = new PlotView(PlotView::HistogramHorizontal, values, "");
  691. plot->setFixedSize(QSize(600, 600));
  692. plot->plot();
  693. QPixmap pixmap = plot->grab();
  694. plot->deleteLater();
  695. if (pixmap.isNull()) {
  696. return;
  697. }
  698. QString imgName = QString("%1_%2_eval").arg(m_proj->id).arg(4);
  699. QString path = saveImage(imgName, pixmap);
  700. QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmEvalPic");
  701. if (bmWeightPic != nullptr) {
  702. bmWeightPic->dynamicCall("Select(void)");
  703. QAxObject *range = bmWeightPic->querySubObject("Range");
  704. QAxObject *inlineShapes = range->querySubObject("InlineShapes");
  705. QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
  706. if (shape != nullptr) {
  707. shape->setProperty("Width", 400);
  708. shape->setProperty("Height", 400);
  709. }
  710. }
  711. // bmSchemeConclusion
  712. QString scores;
  713. int bestIndex = 0;
  714. for (int i = 0; i < schemeList.size(); ++i) {
  715. QString str = QString::number(schemeList[i]->score, 'f', 2);
  716. scores += QString("%1%2,").arg(schemeList[i]->name).arg(str);
  717. if (schemeList[i]->score > schemeList[bestIndex]->score) {
  718. bestIndex = i;
  719. }
  720. }
  721. QString conclusion = QString("经评估分析,%1个方案得分分别为:%2%3为最优方案。")
  722. .arg(schemeList.size())
  723. .arg(scores)
  724. .arg(schemeList[bestIndex]->name);
  725. insertText("bmSchemeConclusion", conclusion);
  726. }
  727. void ExportReportManager::insertSchemeAlgInfo()
  728. {
  729. // bmWeightAlg bmEvalAlg
  730. // bmWeightAlgDscpt bmEvalAlgDscpt
  731. QList<SchemePlanManager::SchemeProcessInfo> processList;
  732. bool processRet = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, 4);
  733. if (processRet == false) {
  734. return;
  735. }
  736. for (int i = 0; i < processList.size(); ++i) {
  737. if (processList[i].type == SchemePlanManager::CalculateWeight) {
  738. SchemePlanManager::Algorithm alg = processList[i].algorithm;
  739. QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
  740. insertText("bmWeightAlg", algStr);
  741. QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
  742. insertText("bmWeightAlgDscpt", dscrpt);
  743. }
  744. if (processList[i].type == SchemePlanManager::RunEvaluate) {
  745. SchemePlanManager::Algorithm alg = processList[i].algorithm;
  746. QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
  747. insertText("bmEvalAlg", algStr);
  748. QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
  749. insertText("bmEvalAlgDscpt", dscrpt);
  750. }
  751. }
  752. }
  753. void ExportReportManager::insertSchemeWeightData()
  754. {
  755. // 指标权重表:bmWeightTable,指标权重图:bmWeightPic
  756. QList<CNodeData> nodeList;
  757. bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 4);
  758. if (ret == false) {
  759. return;
  760. }
  761. CMind *mind = new CMind();
  762. mind->setNodeList(nodeList);
  763. QList<CNodeData> leaveNodes = mind->leaves();
  764. int rowCount = leaveNodes.size() + 1;
  765. int columnCount = mind->levels();
  766. // bmIndexTable
  767. QAxObject *table = insertTable("bmWeightTable", rowCount, columnCount);
  768. if (table == nullptr) {
  769. delete mind;
  770. return;
  771. }
  772. for (int i = 2; i <= mind->levels(); ++i) {
  773. if (i < mind->levels()) {
  774. setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
  775. } else {
  776. setCellString(table, 1, i - 1, QString("指标"));
  777. setCellString(table, 1, i, QString("权重值"));
  778. }
  779. QList<CNodeData> nodes = mind->nodesInLevel(i);
  780. int rowPos = 2;
  781. for (int j = 0; j < nodes.size(); ++j) {
  782. CNodeData node = nodes[j];
  783. int leaves = mind->leavesCountOfNode(node);
  784. int textPos = (rowPos + leaves / 2);
  785. setCellString(table, textPos, i - 1, node.name);
  786. if (leaves > 1) {
  787. mergeCells(table, rowPos, i - 1, leaves, 1);
  788. }
  789. rowPos += leaves;
  790. }
  791. }
  792. delete mind;
  793. MindWeightInfo info;
  794. ret = MindWeightService().queryWeightData(&info, m_proj->id, 4);
  795. if (ret == false) {
  796. return;
  797. }
  798. if (info.id < 0) {
  799. return;
  800. }
  801. QMap<QString, double> weightData;
  802. QStringList weightList = info.weight.split(";");
  803. for (QString keyValueStr : weightList) {
  804. QStringList keyValue = keyValueStr.split(":");
  805. if (keyValue.size() == 2) {
  806. weightData[keyValue.first()] = keyValue.last().toDouble();
  807. }
  808. }
  809. QVector<PlotView::Data> values;
  810. for (int i = 0; i < leaveNodes.size(); ++i) {
  811. CNodeData node = leaveNodes[i];
  812. QString value = QString("%1").arg(weightData[node.name]);
  813. setCellString(table, i + 2, columnCount, value);
  814. PlotView::Data data { node.name, weightData[node.name] };
  815. values.append(data);
  816. }
  817. PlotView *plot = new PlotView(PlotView::HistogramHorizontal, values, "");
  818. plot->setFixedSize(QSize(600, 600));
  819. plot->plot();
  820. QPixmap pixmap = plot->grab();
  821. plot->deleteLater();
  822. if (pixmap.isNull()) {
  823. return;
  824. }
  825. QString imgName = QString("%1_%2_weight_plot").arg(m_proj->id).arg(4);
  826. QString path = saveImage(imgName, pixmap);
  827. QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmWeightPic");
  828. if (bmWeightPic != nullptr) {
  829. bmWeightPic->dynamicCall("Select(void)");
  830. QAxObject *range = bmWeightPic->querySubObject("Range");
  831. QAxObject *inlineShapes = range->querySubObject("InlineShapes");
  832. QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
  833. if (shape != nullptr) {
  834. shape->setProperty("Width", 400);
  835. shape->setProperty("Height", 400);
  836. }
  837. }
  838. }
  839. void ExportReportManager::insertEffiIndex()
  840. {
  841. insertText("bmProjName21", m_proj->projectName);
  842. insertText("bmProjName22", m_proj->projectName);
  843. QList<CNodeData> nodeList;
  844. bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 8);
  845. if (ret == false) {
  846. return;
  847. }
  848. CMind *mind = new CMind();
  849. mind->setNodeList(nodeList);
  850. QList<CNodeData> leaveNodes = mind->leaves();
  851. int rowCount = leaveNodes.size() + 1;
  852. int columnCount = mind->levels();
  853. // bmIndexTable
  854. QAxObject *table = insertTable("bmIndexTable", rowCount, columnCount);
  855. if (table == nullptr) {
  856. delete mind;
  857. return;
  858. }
  859. for (int i = 2; i <= mind->levels(); ++i) {
  860. if (i < mind->levels()) {
  861. setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
  862. } else {
  863. setCellString(table, 1, i - 1, QString("指标"));
  864. setCellString(table, 1, i, QString("量纲"));
  865. }
  866. QList<CNodeData> nodes = mind->nodesInLevel(i);
  867. int rowPos = 2;
  868. for (int j = 0; j < nodes.size(); ++j) {
  869. CNodeData node = nodes[j];
  870. int leaves = mind->leavesCountOfNode(node);
  871. int textPos = (rowPos + leaves / 2);
  872. setCellString(table, textPos, i - 1, node.name);
  873. if (leaves > 1) {
  874. mergeCells(table, rowPos, i - 1, leaves, 1);
  875. }
  876. rowPos += leaves;
  877. }
  878. }
  879. for (int i = 0; i < leaveNodes.size(); ++i) {
  880. CNodeData node = leaveNodes[i];
  881. setCellString(table, i + 2, columnCount, node.dimension);
  882. }
  883. delete mind;
  884. CMindView *m = new CMindView();
  885. m->setNodeList(nodeList);
  886. m->refreshItems();
  887. int sceneWidth = m->sceneRect().width();
  888. int sceneHeight = m->sceneRect().height();
  889. QRectF sourceRect = QRectF(0, 0, sceneWidth, sceneHeight);
  890. QRectF targetRect = QRectF(10, 10, sceneWidth, sceneHeight);
  891. QPixmap pixmap(QSize(sceneWidth + 20, sceneHeight + 20));
  892. pixmap.fill(QColor(244, 244, 255));
  893. QPainter painter(&pixmap);
  894. painter.setRenderHints(QPainter::Antialiasing);
  895. m->scene()->render(&painter, targetRect, sourceRect);
  896. delete m;
  897. QString imgName = QString("%1_%2_index").arg(m_proj->id).arg(8);
  898. QString path = saveImage(imgName, pixmap);
  899. QImageWriter writer(path);
  900. writer.setFormat("PNG");
  901. ret = writer.write(pixmap.toImage());
  902. if (ret) {
  903. QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmIndexPic");
  904. if (bmWeightPic != nullptr) {
  905. bmWeightPic->dynamicCall("Select(void)");
  906. QAxObject *range = bmWeightPic->querySubObject("Range");
  907. QAxObject *inlineShapes = range->querySubObject("InlineShapes");
  908. QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
  909. if (shape != nullptr) {
  910. int w = pixmap.width();
  911. int h = pixmap.height();
  912. if (w > 400) {
  913. h = h * 400 / w;
  914. w = 400;
  915. }
  916. shape->setProperty("Width", w);
  917. shape->setProperty("Height", h);
  918. }
  919. }
  920. }
  921. }
  922. void ExportReportManager::insertEffiAlgInfo()
  923. {
  924. // bmWeightAlg bmEvalAlg
  925. // bmWeightAlgDscpt bmEvalAlgDscpt
  926. QList<SchemePlanManager::SchemeProcessInfo> processList;
  927. bool processRet = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, 8);
  928. if (processRet == false) {
  929. return;
  930. }
  931. for (int i = 0; i < processList.size(); ++i) {
  932. if (processList[i].type == SchemePlanManager::CalculateWeight) {
  933. SchemePlanManager::Algorithm alg = processList[i].algorithm;
  934. QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
  935. insertText("bmWeightAlg", algStr);
  936. QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
  937. insertText("bmWeightAlgDscpt", dscrpt);
  938. }
  939. if (processList[i].type == SchemePlanManager::RunEvaluate) {
  940. SchemePlanManager::Algorithm alg = processList[i].algorithm;
  941. if (alg == SchemePlanManager::MEA) {
  942. m_schemeType = 1;
  943. } else {
  944. m_schemeType = 2;
  945. }
  946. QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
  947. insertText("bmEvalAlg", algStr);
  948. QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
  949. insertText("bmEvalAlgDscpt", dscrpt);
  950. }
  951. }
  952. }
  953. void ExportReportManager::insertEffiConfigData()
  954. {
  955. // bmProjName31, bmProjName32, bmConfigTable
  956. insertText("bmProjName31", m_proj->projectName);
  957. insertText("bmProjName32", m_proj->projectName);
  958. QList<GradeInfo *> gradeInfoList;
  959. int type = m_schemeType == 1 ? 0 : 1;
  960. bool ret = GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, m_proj->id, type);
  961. if (ret == false || gradeInfoList.size() <= 0) {
  962. return;
  963. }
  964. QStringList gradeNames;
  965. for (int i = 0; i < gradeInfoList.size(); ++i) {
  966. gradeNames.append(gradeInfoList[i]->gradeValue);
  967. }
  968. QMap<QString, QString> gradeInfoData;
  969. if (m_schemeType == 1) {
  970. QList<GradeIndexInfo *> gradeIndexInfoList;
  971. ret = GradeIndexInfoService().QueryGradeIndexInfoByProjectId(&gradeIndexInfoList, m_proj->id);
  972. if (ret == false || gradeIndexInfoList.size() <= 0) {
  973. return;
  974. }
  975. for (int i = gradeIndexInfoList.size() - 1; i >= 0; --i) {
  976. QString name = gradeIndexInfoList[i]->gradeIndexName;
  977. QString value = gradeInfoData[name];
  978. if (gradeNames.size() > gradeIndexInfoList[i]->gradeLevel - 1) {
  979. QString grade = gradeNames[gradeIndexInfoList[i]->gradeLevel - 1];
  980. if (value.contains(grade)) {
  981. continue;
  982. } else {
  983. value += grade;
  984. }
  985. }
  986. value += ":";
  987. value += gradeIndexInfoList[i]->gradeIndexValue;
  988. if (gradeIndexInfoList[i]->gradeLevel > 1) {
  989. value += "\n";
  990. }
  991. gradeInfoData[name] = value;
  992. }
  993. } else {
  994. QList<EffectIndexInfo *> effectIndexInfoList;
  995. ret = EffectIndexInfoService().QueryEffectIndexInfoByProjectId(&effectIndexInfoList, m_proj->id);
  996. if (ret == false) {
  997. return;
  998. }
  999. for (EffectIndexInfo *info : effectIndexInfoList) {
  1000. QStringList valueList = info->effectIndexValue.split(",");
  1001. QString value;
  1002. for (int i = valueList.size() - 1; i >= 0; --i) {
  1003. if (gradeNames.size() > i) {
  1004. value += gradeNames[i];
  1005. }
  1006. value += ":";
  1007. value += (valueList[i].replace(":", ","));
  1008. if (i > 0) {
  1009. value += "\n";
  1010. }
  1011. gradeInfoData[info->effectIndexName] = value;
  1012. }
  1013. }
  1014. }
  1015. QList<CNodeData> nodeList;
  1016. ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 8);
  1017. if (ret == false) {
  1018. return;
  1019. }
  1020. CMind *mind = new CMind();
  1021. mind->setNodeList(nodeList);
  1022. QList<CNodeData> leaveNodes = mind->leaves();
  1023. int rowCount = leaveNodes.size() + 1;
  1024. int columnCount = mind->levels();
  1025. // bmConfigTable
  1026. QAxObject *table = insertTable("bmConfigTable", rowCount, columnCount);
  1027. if (table == nullptr) {
  1028. delete mind;
  1029. return;
  1030. }
  1031. for (int i = 2; i <= mind->levels(); ++i) {
  1032. if (i < mind->levels()) {
  1033. setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
  1034. } else {
  1035. setCellString(table, 1, i - 1, QString("指标"));
  1036. setCellString(table, 1, i, QString("效能分级"));
  1037. }
  1038. QList<CNodeData> nodes = mind->nodesInLevel(i);
  1039. int rowPos = 2;
  1040. for (int j = 0; j < nodes.size(); ++j) {
  1041. CNodeData node = nodes[j];
  1042. int leaves = mind->leavesCountOfNode(node);
  1043. int textPos = (rowPos + leaves / 2);
  1044. setCellString(table, textPos, i - 1, node.name);
  1045. if (leaves > 1) {
  1046. mergeCells(table, rowPos, i - 1, leaves, 1);
  1047. }
  1048. rowPos += leaves;
  1049. }
  1050. }
  1051. for (int i = 0; i < leaveNodes.size(); ++i) {
  1052. CNodeData node = leaveNodes[i];
  1053. QString value = QString("%1").arg(gradeInfoData[node.name]);
  1054. setCellString(table, i + 2, columnCount, value);
  1055. }
  1056. delete mind;
  1057. }
  1058. void ExportReportManager::insertEffiSchemeData()
  1059. {
  1060. QList<CNodeData> nodeList;
  1061. bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 8);
  1062. if (ret == false) {
  1063. return;
  1064. }
  1065. CMind *mind = new CMind();
  1066. mind->setNodeList(nodeList);
  1067. QMap<int, QMap<QString, double>> schemeData;
  1068. QMap<int, QString> schemeNames;
  1069. QList<SchemaEval *> schemeList;
  1070. ret = SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_proj->id, m_schemeType);
  1071. if (ret == false || schemeList.size() <= 0) {
  1072. delete mind;
  1073. return;
  1074. }
  1075. for (SchemaEval *scheme : schemeList) {
  1076. if (m_schemeType == 2 && scheme->name != "建设前" && scheme->name != "建设后") {
  1077. continue;
  1078. }
  1079. if (schemeData.keys().contains(scheme->id) == false) {
  1080. schemeData[scheme->id] = QMap<QString, double>();
  1081. }
  1082. QStringList keyValueStringList = scheme->valueStr.split(";");
  1083. for (QString keyValueStr : keyValueStringList) {
  1084. QStringList keyValue = keyValueStr.split(":");
  1085. if (keyValue.size() == 2) {
  1086. schemeData[scheme->id][keyValue.first()] = keyValue.last().toDouble();
  1087. }
  1088. }
  1089. schemeNames[scheme->id] = scheme->name;
  1090. }
  1091. QList<CNodeData> leaveNodes = mind->leaves();
  1092. int rowCount = leaveNodes.size() + 1;
  1093. int columnCount = schemeNames.keys().size() + 1;
  1094. delete mind;
  1095. // bmSchemeDataTable
  1096. QAxObject *table = insertTable("bmEffiDataTable", rowCount, columnCount);
  1097. if (table == nullptr) {
  1098. return;
  1099. }
  1100. QList<int> schemeIds = schemeNames.keys();
  1101. for (int i = 0; i < schemeIds.size() + 1; ++i) {
  1102. if (i == 0) {
  1103. setCellString(table, 1, i + 1, "指标");
  1104. } else {
  1105. setCellString(table, 1, i + 1, schemeNames[schemeIds[i - 1]]);
  1106. }
  1107. }
  1108. for (int i = 0; i < leaveNodes.size(); ++i) {
  1109. CNodeData node = leaveNodes[i];
  1110. setCellString(table, i + 2, 1, node.name);
  1111. for (int j = 0; j < schemeIds.size(); ++j) {
  1112. QString value = QString("%1").arg(schemeData[schemeIds[j]][node.name]);
  1113. setCellString(table, i + 2, j + 2, value);
  1114. }
  1115. }
  1116. }
  1117. void ExportReportManager::insertEffiWeightData()
  1118. {
  1119. // 指标权重表:bmWeightTable,指标权重图:bmWeightPic
  1120. QList<CNodeData> nodeList;
  1121. bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 8);
  1122. if (ret == false) {
  1123. return;
  1124. }
  1125. CMind *mind = new CMind();
  1126. mind->setNodeList(nodeList);
  1127. QList<CNodeData> leaveNodes = mind->leaves();
  1128. int rowCount = leaveNodes.size() + 1;
  1129. int columnCount = mind->levels();
  1130. // bmIndexTable
  1131. QAxObject *table = insertTable("bmWeightTable", rowCount, columnCount);
  1132. if (table == nullptr) {
  1133. delete mind;
  1134. return;
  1135. }
  1136. for (int i = 2; i <= mind->levels(); ++i) {
  1137. if (i < mind->levels()) {
  1138. setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
  1139. } else {
  1140. setCellString(table, 1, i - 1, QString("指标"));
  1141. setCellString(table, 1, i, QString("权重值"));
  1142. }
  1143. QList<CNodeData> nodes = mind->nodesInLevel(i);
  1144. int rowPos = 2;
  1145. for (int j = 0; j < nodes.size(); ++j) {
  1146. CNodeData node = nodes[j];
  1147. int leaves = mind->leavesCountOfNode(node);
  1148. int textPos = (rowPos + leaves / 2);
  1149. setCellString(table, textPos, i - 1, node.name);
  1150. if (leaves > 1) {
  1151. mergeCells(table, rowPos, i - 1, leaves, 1);
  1152. }
  1153. rowPos += leaves;
  1154. }
  1155. }
  1156. delete mind;
  1157. MindWeightInfo info;
  1158. ret = MindWeightService().queryWeightData(&info, m_proj->id, 8);
  1159. if (ret == false) {
  1160. return;
  1161. }
  1162. if (info.id < 0) {
  1163. return;
  1164. }
  1165. QMap<QString, double> weightData;
  1166. QStringList weightList = info.weight.split(";");
  1167. for (QString keyValueStr : weightList) {
  1168. QStringList keyValue = keyValueStr.split(":");
  1169. if (keyValue.size() == 2) {
  1170. weightData[keyValue.first()] = keyValue.last().toDouble();
  1171. }
  1172. }
  1173. QVector<PlotView::Data> values;
  1174. for (int i = 0; i < leaveNodes.size(); ++i) {
  1175. CNodeData node = leaveNodes[i];
  1176. QString value = QString("%1").arg(weightData[node.name]);
  1177. setCellString(table, i + 2, columnCount, value);
  1178. PlotView::Data data { node.name, weightData[node.name] };
  1179. values.append(data);
  1180. }
  1181. PlotView *plot = new PlotView(PlotView::HistogramHorizontal, values, "");
  1182. plot->setFixedSize(QSize(600, 600));
  1183. plot->plot();
  1184. QPixmap pixmap = plot->grab();
  1185. plot->deleteLater();
  1186. if (pixmap.isNull()) {
  1187. return;
  1188. }
  1189. QString imgName = QString("%1_%2_weight_plot").arg(m_proj->id).arg(8);
  1190. QString path = saveImage(imgName, pixmap);
  1191. QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmWeightPic");
  1192. if (bmWeightPic != nullptr) {
  1193. bmWeightPic->dynamicCall("Select(void)");
  1194. QAxObject *range = bmWeightPic->querySubObject("Range");
  1195. QAxObject *inlineShapes = range->querySubObject("InlineShapes");
  1196. QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
  1197. if (shape != nullptr) {
  1198. shape->setProperty("Width", 400);
  1199. shape->setProperty("Height", 400);
  1200. }
  1201. }
  1202. }
  1203. void ExportReportManager::insertEffiResult()
  1204. {
  1205. QList<GradeInfo *> gradeInfoList;
  1206. int type = m_schemeType == 1 ? 0 : 1;
  1207. bool gradeRet = GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, m_proj->id, type);
  1208. if (gradeRet == false) {
  1209. return;
  1210. }
  1211. QStringList gradeNames;
  1212. for (int i = 0; i < gradeInfoList.size(); ++i) {
  1213. gradeNames.append(gradeInfoList[i]->gradeValue);
  1214. }
  1215. QList<EffectResult> effList;
  1216. bool effRet = EffectResultService().queryDataList(effList, m_proj->id);
  1217. if (effRet == false) {
  1218. return;
  1219. }
  1220. QMap<int, QMap<QString, QList<double>>> effData;
  1221. QMap<int, QString> schemeNames;
  1222. int levels = 0;
  1223. for (EffectResult effect : effList) {
  1224. if (effData.keys().contains(effect.schemeId) == false) {
  1225. effData[effect.schemeId] = QMap<QString, QList<double>>();
  1226. schemeNames[effect.schemeId] = effect.schemeName;
  1227. }
  1228. QStringList values = effect.value.split(",");
  1229. levels = values.size();
  1230. QList<double> valueList;
  1231. for (int v = 0; v < values.size(); ++v) {
  1232. valueList.append(values[v].toDouble());
  1233. }
  1234. effData[effect.schemeId][effect.indexName] = valueList;
  1235. }
  1236. QList<CNodeData> nodeList;
  1237. bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 8);
  1238. if (ret == false) {
  1239. return;
  1240. }
  1241. CMind *mind = new CMind();
  1242. mind->setNodeList(nodeList);
  1243. QList<CNodeData> leaveNodes = mind->leaves();
  1244. int rowCount = leaveNodes.size() + 1;
  1245. int columnCount = mind->levels() + schemeNames.size() - 1;
  1246. // bmEvalTable
  1247. QAxObject *table = insertTable("bmEvalTable", rowCount, columnCount);
  1248. if (table == nullptr) {
  1249. delete mind;
  1250. return;
  1251. }
  1252. for (int i = 2; i <= mind->levels(); ++i) {
  1253. if (i < mind->levels()) {
  1254. setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
  1255. } else {
  1256. setCellString(table, 1, i - 1, QString("指标"));
  1257. }
  1258. QList<CNodeData> nodes = mind->nodesInLevel(i);
  1259. int rowPos = 2;
  1260. for (int j = 0; j < nodes.size(); ++j) {
  1261. CNodeData node = nodes[j];
  1262. int leaves = mind->leavesCountOfNode(node);
  1263. int textPos = (rowPos + leaves / 2);
  1264. setCellString(table, textPos, i - 1, node.name);
  1265. if (leaves > 1) {
  1266. mergeCells(table, rowPos, i - 1, leaves, 1);
  1267. }
  1268. rowPos += leaves;
  1269. }
  1270. }
  1271. for (int i = 0; i < schemeNames.size(); ++i) {
  1272. setCellString(table, 1, i + mind->levels(),
  1273. schemeNames[schemeNames.keys()[i]] + "\n(" + gradeNames.join(",") + ")");
  1274. for (int j = 0; j < leaveNodes.size(); ++j) {
  1275. CNodeData node = leaveNodes[j];
  1276. QList<double> values = effData[schemeNames.keys()[i]][node.name];
  1277. int bestIndex = 0;
  1278. QString score;
  1279. for (int k = 0; k < values.size(); ++k) {
  1280. if (values[k] > values[bestIndex]) {
  1281. bestIndex = k;
  1282. }
  1283. score += QString::number(values[k], 'f', 1).replace(".0", "").replace("nan", "0");
  1284. if (k < values.size() - 1) {
  1285. score += ",";
  1286. }
  1287. }
  1288. QString rand = gradeNames[bestIndex];
  1289. QString value = rand + "(" + score + ")";
  1290. setCellString(table, j + 2, i + mind->levels(), value);
  1291. }
  1292. }
  1293. // 指标权重图:bmEvalPic
  1294. for (int i = schemeNames.size() - 1; i >= 0; --i) {
  1295. QString schemeName = schemeNames[schemeNames.keys()[i]];
  1296. QList<double> values = effData[schemeNames.keys()[i]]["综合"];
  1297. QVector<PlotView::Data> plotValues;
  1298. for (int j = 0; j < values.size(); ++j) {
  1299. PlotView::Data data { schemeName + "-" + gradeNames[j], values[j] };
  1300. plotValues.append(data);
  1301. }
  1302. PlotView *plot = new PlotView(PlotView::HistogramHorizontal, plotValues, "");
  1303. plot->setFixedSize(QSize(600, 600));
  1304. plot->plot();
  1305. QPixmap pixmap = plot->grab();
  1306. plot->deleteLater();
  1307. if (pixmap.isNull()) {
  1308. return;
  1309. }
  1310. QString imgName = QString("%1_%2_%3_eval").arg(m_proj->id).arg(8).arg(schemeName);
  1311. QString path = saveImage(imgName, pixmap);
  1312. QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmEvalPic");
  1313. if (bmWeightPic != nullptr) {
  1314. bmWeightPic->dynamicCall("Select(void)");
  1315. QAxObject *range = bmWeightPic->querySubObject("Range");
  1316. QAxObject *inlineShapes = range->querySubObject("InlineShapes");
  1317. QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
  1318. if (shape != nullptr) {
  1319. shape->setProperty("Width", 400);
  1320. shape->setProperty("Height", 400);
  1321. }
  1322. }
  1323. }
  1324. QStringList retList;
  1325. int bestGrade = 0;
  1326. int bestSchemeIndex = 0;
  1327. for (int i = 0; i < schemeNames.size(); ++i) {
  1328. int grade = 0;
  1329. QList<double> values = effData[schemeNames.keys()[i]]["综合"];
  1330. for (int j = 0; j < values.size(); ++j) {
  1331. if (values[j] > values[grade]) {
  1332. grade = j;
  1333. }
  1334. }
  1335. QString ret = schemeNames[schemeNames.keys()[i]] + "的综合评价等级为" + gradeNames[grade];
  1336. retList.append(ret);
  1337. if (grade > bestGrade) {
  1338. bestGrade = grade;
  1339. bestSchemeIndex = i;
  1340. }
  1341. }
  1342. QString bestScheme = schemeNames[schemeNames.keys()[bestSchemeIndex]];
  1343. QString conclusion = "根据评估结果," + retList.join(",") + "。所以" + bestScheme + "更优。";
  1344. insertText("bmEffiConclusion", conclusion);
  1345. delete mind;
  1346. }
  1347. bool ExportReportManager::insertText(const QString &bookmark, const QString &text)
  1348. {
  1349. bool ret = false;
  1350. QAxObject *bmProjName = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", bookmark);
  1351. if (bmProjName != nullptr) {
  1352. bmProjName->dynamicCall("Select(void)");
  1353. QAxObject *range = bmProjName->querySubObject("Range");
  1354. ret = range->setProperty("Text", text);
  1355. }
  1356. return ret;
  1357. }
  1358. QAxObject *ExportReportManager::insertTable(QString bookmark, int row, int column)
  1359. {
  1360. QAxObject *bmTable = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", bookmark);
  1361. if (bmTable) {
  1362. bmTable->dynamicCall("Select(void)");
  1363. QAxObject *selection = m_word->getWordApp()->querySubObject("Selection");
  1364. if (!selection)
  1365. return nullptr;
  1366. selection->dynamicCall("InsertAfter(QString&)", "\n");
  1367. // selection->dynamicCall("MoveLeft(int)", 1);
  1368. selection->querySubObject("ParagraphFormat")->dynamicCall("Alignment", "wdAlignParagraphCenter");
  1369. // selection->dynamicCall("TypeText(QString&)", "Table Test"); //设置标题
  1370. QAxObject *range = selection->querySubObject("Range");
  1371. QAxObject *tables = m_word->getDocument()->querySubObject("Tables");
  1372. QAxObject *table = tables->querySubObject("Add(QVariant,int,int)", range->asVariant(), row, column);
  1373. if (!tables)
  1374. return nullptr;
  1375. for (int i = 1; i <= 6; i++) {
  1376. QString str = QString("Borders(-%1)").arg(i);
  1377. QAxObject *borders = table->querySubObject(str.toLocal8Bit().constData());
  1378. borders->dynamicCall("SetLineStyle(int)", 1);
  1379. }
  1380. return table;
  1381. }
  1382. return nullptr;
  1383. }
  1384. void ExportReportManager::setCellString(QAxObject *table, int row, int column, const QString &text)
  1385. {
  1386. if (table == nullptr) {
  1387. return;
  1388. }
  1389. table->querySubObject("Cell(int,int)", row, column)->querySubObject("Range")->dynamicCall("SetText(QString)", text);
  1390. }
  1391. void ExportReportManager::mergeCells(QAxObject *table, int row, int column, int rowSpan, int columnSpan)
  1392. {
  1393. if (table == nullptr) {
  1394. return;
  1395. }
  1396. QAxObject *startCell = table->querySubObject("Cell(int, int)", row, column);
  1397. QAxObject *endCell = table->querySubObject("Cell(int, int)", row + rowSpan - 1, column + columnSpan - 1);
  1398. if (nullptr == startCell) {
  1399. return;
  1400. }
  1401. if (nullptr == endCell) {
  1402. return;
  1403. }
  1404. startCell->querySubObject("Merge(LPDISPATCH)", endCell->asVariant());
  1405. }
  1406. QString ExportReportManager::saveImage(const QString &name, const QPixmap &pixmap)
  1407. {
  1408. QString curPath = QDir::currentPath();
  1409. QString dateStr = QDate::currentDate().toString("yyyy-MM-dd");
  1410. QString picDir = curPath + "/report_pics/" + dateStr + "/";
  1411. QDir dir(picDir);
  1412. if (!dir.exists()) {
  1413. dir.mkpath(picDir);
  1414. }
  1415. QString filePath = picDir + name + ".png";
  1416. QImageWriter writer(filePath);
  1417. writer.setFormat("PNG");
  1418. bool ret = writer.write(pixmap.toImage());
  1419. if (ret) {
  1420. return filePath;
  1421. } else {
  1422. return "";
  1423. }
  1424. }