12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670 |
- #include "ExportReportManager.h"
- #include "ProjectManager.h"
- #include "SchemePlanManager.h"
- #include "CMindView.h"
- #include <view/PlotView.h>
- #include <dbService/ClassSet.h>
- #include <dbService/SchemeInfoService.h>
- #include <dbService/CNodeDataService.h>
- #include <dbService/SchemeInfoService.h>
- #include <dbService/SchemeProcessService.h>
- #include <dbService/MindWeightService.h>
- #include <dbService/GradeInfoService.h>
- #include <dbService/GradeIndexInfoService.h>
- #include <dbService/EffectIndexInfoService.h>
- #include <dbService/EffectResultService.h>
- #include <dbService/MindScoreService.h>
- #include <QWord/QWord.h>
- #include <QWord/QWordDemo.h>
- #include <QDir>
- #include <QDate>
- #include <QLabel>
- #include <QImageWriter>
- #include <QDebug>
- ExportReportManager::ExportReportManager(QObject *parent) : QObject(parent)
- {
- m_word = new QWord(this);
- }
- ExportReportManager::~ExportReportManager()
- {
- delete m_word;
- }
- ProjectInfo *ExportReportManager::proj() const
- {
- return m_proj;
- }
- void ExportReportManager::setProj(ProjectInfo *proj)
- {
- m_proj = proj;
- }
- int ExportReportManager::evalType() const
- {
- return m_evalType;
- }
- void ExportReportManager::setEvalType(int type)
- {
- m_evalType = type;
- }
- bool ExportReportManager::exportReport()
- {
- bool createRet = createWord();
- if (createRet == false) {
- qDebug() << __FUNCTION__ << __LINE__ << m_word->getStrErrorInfo() << endl;
- return false;
- }
- insertProjectInfo();
- if (m_evalType == ProjectManager::DemandEval) {
- insertDemandAlg();
- insertDemandIndex();
- insertDemandTechIndex();
- insertDemandWeight();
- insertDemandEval();
- }
- if (m_evalType == ProjectManager::OptimalEval) {
- insertSchemeDesignInfo();
- insertSchemeIndex();
- insertSchemeAlgInfo();
- insertSchemeData();
- insertSchemeWeightData();
- }
- if (m_evalType == ProjectManager::EfficiencyEval) {
- insertEffiIndex();
- insertEffiAlgInfo();
- insertEffiConfigData();
- insertEffiSchemeData();
- insertEffiWeightData();
- insertEffiResult();
- }
- m_word->setVisible(true);
- QAxObject *doc = m_word->getWordApp()->querySubObject("ActiveDocument");
- doc->dynamicCall("SaveAs(const QString&))", QDir::toNativeSeparators(m_word->getFilePath()));
- m_word->close();
- return true;
- }
- bool ExportReportManager::createWord()
- {
- delete m_word;
- m_word = new QWord(this);
- // 报告文件夹路径
- QString curPath = QDir::currentPath();
- QString dateStr = QDate::currentDate().toString("yyyy-MM-dd");
- QString reportDir = curPath + "/reports/" + dateStr + "/";
- QDir dir(reportDir);
- if (!dir.exists()) {
- dir.mkpath(reportDir);
- }
- // 根据模板创建 word 文档
- QString typeStr = ProjectManager::reportNameOfEvalType((ProjectManager::EvalType)m_evalType);
- QString tempPath = curPath + "/report_templates/" + typeStr + ".docx";
- if (!QFile::exists(tempPath)) {
- qDebug() << __FUNCTION__ << __LINE__ << "Report template not found" << endl;
- return false;
- }
- QString fileName = m_proj->projectName + "_" + typeStr + ".docx";
- QString filePath = reportDir + fileName;
- if (QFile::exists(filePath)) {
- QFile::remove(filePath);
- }
- bool ret = QFile::copy(tempPath, filePath);
- if (ret) {
- ret = m_word->open(filePath, false);
- } else {
- qDebug() << __FUNCTION__ << __LINE__ << "Copy report template failed" << endl;
- }
- return ret;
- }
- void ExportReportManager::insertProjectInfo()
- {
- insertText("bmProjName", m_proj->projectName);
- insertText("bmProjUnit", m_proj->estimateDept);
- QString dateStr = QDate::currentDate().toString("yyyy年MM月");
- insertText("bmProjDate", dateStr);
- insertText("bmEvalPurpose", m_proj->estimateObjective);
- }
- void ExportReportManager::insertDemandAlg()
- {
- // bmWeightAlg bmEvalAlg
- // bmWeightAlgDscpt bmEvalAlgDscpt
- QList<SchemePlanManager::SchemeProcessInfo> processList;
- bool processRet = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, 1);
- if (processRet == false) {
- return;
- }
- for (int i = 0; i < processList.size(); ++i) {
- if (processList[i].type == SchemePlanManager::CalculateWeight) {
- SchemePlanManager::Algorithm alg = processList[i].algorithm;
- QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
- insertText("bmWeightAlg", algStr);
- QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
- insertText("bmWeightAlgDscpt", dscrpt);
- }
- }
- processRet = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, 2);
- if (processRet == false) {
- return;
- }
- for (int i = 0; i < processList.size(); ++i) {
- if (processList[i].type == SchemePlanManager::RunEvaluate) {
- SchemePlanManager::Algorithm alg = processList[i].algorithm;
- QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
- insertText("bmEvalAlg", algStr);
- QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
- insertText("bmEvalAlgDscpt", dscrpt);
- }
- }
- }
- void ExportReportManager::insertDemandIndex()
- {
- insertText("bmProjName21", m_proj->projectName);
- insertText("bmProjName22", m_proj->projectName);
- QList<CNodeData> nodeList;
- bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 1);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = mind->levels();
- // bmIndexTable
- QAxObject *table = insertTable("bmIndexTable", rowCount, columnCount);
- if (table == nullptr) {
- delete mind;
- return;
- }
- for (int i = 2; i <= mind->levels(); ++i) {
- if (i < mind->levels()) {
- setCellString(table, 1, i - 1, QString("%1级指标").arg(i - 1));
- } else {
- setCellString(table, 1, i - 1, QString("指标"));
- setCellString(table, 1, i, QString("量纲"));
- }
- QList<CNodeData> nodes = mind->nodesInLevel(i);
- int rowPos = 2;
- for (int j = 0; j < nodes.size(); ++j) {
- CNodeData node = nodes[j];
- int leaves = mind->leavesCountOfNode(node);
- int textPos = (rowPos + leaves / 2);
- setCellString(table, textPos, i - 1, node.name);
- if (leaves > 1) {
- mergeCells(table, rowPos, i - 1, leaves, 1);
- }
- rowPos += leaves;
- }
- }
- for (int i = 0; i < leaveNodes.size(); ++i) {
- CNodeData node = leaveNodes[i];
- setCellString(table, i + 2, columnCount, node.dimension);
- }
- delete mind;
- CMindView *m = new CMindView();
- m->setNodeList(nodeList);
- m->refreshItems();
- int sceneWidth = m->sceneRect().width();
- int sceneHeight = m->sceneRect().height();
- QRectF sourceRect = QRectF(0, 0, sceneWidth, sceneHeight);
- QRectF targetRect = QRectF(10, 10, sceneWidth, sceneHeight);
- QPixmap pixmap(QSize(sceneWidth + 20, sceneHeight + 20));
- pixmap.fill(QColor(244, 244, 255));
- QPainter painter(&pixmap);
- painter.setRenderHints(QPainter::Antialiasing);
- m->scene()->render(&painter, targetRect, sourceRect);
- delete m;
- QString imgName = QString("%1_%2_index").arg(m_proj->id).arg(1);
- QString path = saveImage(imgName, pixmap);
- QImageWriter writer(path);
- writer.setFormat("PNG");
- ret = writer.write(pixmap.toImage());
- if (ret) {
- QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmIndexPic");
- if (bmWeightPic != nullptr) {
- bmWeightPic->dynamicCall("Select(void)");
- QAxObject *range = bmWeightPic->querySubObject("Range");
- QAxObject *inlineShapes = range->querySubObject("InlineShapes");
- QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
- if (shape != nullptr) {
- int w = pixmap.width();
- int h = pixmap.height();
- if (w > 400) {
- h = h * 400 / w;
- w = 400;
- }
- shape->setProperty("Width", w);
- shape->setProperty("Height", h);
- }
- }
- }
- }
- void ExportReportManager::insertDemandTechIndex()
- {
- insertText("bmProjName31", m_proj->projectName);
- insertText("bmProjName32", m_proj->projectName);
- QList<CNodeData> nodeList;
- bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 2);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = mind->levels() - 1;
- // bmIndexTable
- QAxObject *table = insertTable("bmTechTable", rowCount, columnCount);
- if (table == nullptr) {
- delete mind;
- return;
- }
- for (int i = 2; i <= mind->levels(); ++i) {
- if (i < mind->levels()) {
- setCellString(table, 1, i - 1, QString("%1级指标").arg(i - 1));
- } else {
- setCellString(table, 1, i - 1, QString("指标"));
- }
- QList<CNodeData> nodes = mind->nodesInLevel(i);
- int rowPos = 2;
- for (int j = 0; j < nodes.size(); ++j) {
- CNodeData node = nodes[j];
- int leaves = mind->leavesCountOfNode(node);
- int textPos = (rowPos + leaves / 2);
- setCellString(table, textPos, i - 1, node.name);
- if (leaves > 1) {
- mergeCells(table, rowPos, i - 1, leaves, 1);
- }
- rowPos += leaves;
- }
- }
- delete mind;
- CMindView *m = new CMindView();
- m->setNodeList(nodeList);
- m->refreshItems();
- int sceneWidth = m->sceneRect().width();
- int sceneHeight = m->sceneRect().height();
- QRectF sourceRect = QRectF(0, 0, sceneWidth, sceneHeight);
- QRectF targetRect = QRectF(10, 10, sceneWidth, sceneHeight);
- QPixmap pixmap(QSize(sceneWidth + 20, sceneHeight + 20));
- pixmap.fill(QColor(244, 244, 255));
- QPainter painter(&pixmap);
- painter.setRenderHints(QPainter::Antialiasing);
- m->scene()->render(&painter, targetRect, sourceRect);
- delete m;
- QString imgName = QString("%1_%2_index").arg(m_proj->id).arg(2);
- QString path = saveImage(imgName, pixmap);
- QImageWriter writer(path);
- writer.setFormat("PNG");
- ret = writer.write(pixmap.toImage());
- if (ret) {
- QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmTechPic");
- if (bmWeightPic != nullptr) {
- bmWeightPic->dynamicCall("Select(void)");
- QAxObject *range = bmWeightPic->querySubObject("Range");
- QAxObject *inlineShapes = range->querySubObject("InlineShapes");
- QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
- if (shape != nullptr) {
- int w = pixmap.width();
- int h = pixmap.height();
- if (w > 400) {
- h = h * 400 / w;
- w = 400;
- }
- shape->setProperty("Width", w);
- shape->setProperty("Height", h);
- }
- }
- }
- }
- void ExportReportManager::insertDemandWeight()
- {
- // 指标权重表:bmWeightTable,指标权重图:bmWeightPic
- QList<CNodeData> nodeList;
- bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 1);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = mind->levels();
- // bmIndexTable
- QAxObject *table = insertTable("bmWeightTable", rowCount, columnCount);
- if (table == nullptr) {
- delete mind;
- return;
- }
- for (int i = 2; i <= mind->levels(); ++i) {
- if (i < mind->levels()) {
- setCellString(table, 1, i - 1, QString("%1级指标").arg(i - 1));
- } else {
- setCellString(table, 1, i - 1, QString("指标"));
- setCellString(table, 1, i, QString("权重值"));
- }
- QList<CNodeData> nodes = mind->nodesInLevel(i);
- int rowPos = 2;
- for (int j = 0; j < nodes.size(); ++j) {
- CNodeData node = nodes[j];
- int leaves = mind->leavesCountOfNode(node);
- int textPos = (rowPos + leaves / 2);
- setCellString(table, textPos, i - 1, node.name);
- if (leaves > 1) {
- mergeCells(table, rowPos, i - 1, leaves, 1);
- }
- rowPos += leaves;
- }
- }
- delete mind;
- MindWeightInfo info;
- ret = MindWeightService().queryWeightData(&info, m_proj->id, 1);
- if (ret == false) {
- return;
- }
- if (info.id < 0) {
- return;
- }
- QMap<QString, double> weightData;
- QStringList weightList = info.weight.split(";");
- for (QString keyValueStr : weightList) {
- QStringList keyValue = keyValueStr.split(":");
- if (keyValue.size() == 2) {
- weightData[keyValue.first()] = keyValue.last().toDouble();
- }
- }
- QVector<PlotView::Data> values;
- for (int i = 0; i < leaveNodes.size(); ++i) {
- CNodeData node = leaveNodes[i];
- QString value = QString("%1").arg(weightData[node.name]);
- setCellString(table, i + 2, columnCount, value);
- PlotView::Data data { node.name, weightData[node.name] };
- values.append(data);
- }
- PlotView *plot = new PlotView(PlotView::HistogramHorizontal, values, "");
- plot->setFixedSize(QSize(600, 600));
- plot->plot();
- QPixmap pixmap = plot->grab();
- plot->deleteLater();
- if (pixmap.isNull()) {
- return;
- }
- QString imgName = QString("%1_%2_weight_plot").arg(m_proj->id).arg(1);
- QString path = saveImage(imgName, pixmap);
- QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmWeightPic");
- if (bmWeightPic != nullptr) {
- bmWeightPic->dynamicCall("Select(void)");
- QAxObject *range = bmWeightPic->querySubObject("Range");
- QAxObject *inlineShapes = range->querySubObject("InlineShapes");
- QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
- if (shape != nullptr) {
- shape->setProperty("Width", 400);
- shape->setProperty("Height", 400);
- }
- }
- }
- void ExportReportManager::insertDemandEval()
- {
- MindScoreInfo info;
- bool ret = MindScoreService().queryScoreData(&info, m_proj->id);
- if (ret == false || info.id < 0) {
- return;
- }
- QMap<QString, QString> scoreData;
- QStringList keyValueStringList = info.score.split(";");
- for (QString keyValueString : keyValueStringList) {
- QStringList keyValue = keyValueString.split(":");
- if (keyValue.size() == 2) {
- scoreData[keyValue.first()] = keyValue.last();
- }
- }
- QList<CNodeData> nodeList;
- ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 2);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = mind->levels();
- // bmEvalTable
- QAxObject *table = insertTable("bmEvalTable", rowCount, columnCount);
- if (table == nullptr) {
- delete mind;
- return;
- }
- for (int i = 2; i <= mind->levels(); ++i) {
- if (i < mind->levels()) {
- setCellString(table, 1, i - 1, QString("%1级指标").arg(i - 1));
- } else {
- setCellString(table, 1, i - 1, QString("指标"));
- setCellString(table, 1, i, QString("重要度"));
- }
- QList<CNodeData> nodes = mind->nodesInLevel(i);
- int rowPos = 2;
- for (int j = 0; j < nodes.size(); ++j) {
- CNodeData node = nodes[j];
- int leaves = mind->leavesCountOfNode(node);
- int textPos = (rowPos + leaves / 2);
- setCellString(table, textPos, i - 1, node.name);
- if (leaves > 1) {
- mergeCells(table, rowPos, i - 1, leaves, 1);
- }
- rowPos += leaves;
- }
- }
- delete mind;
- QVector<PlotView::Data> values;
- for (int i = 0; i < leaveNodes.size(); ++i) {
- CNodeData node = leaveNodes[i];
- QString value = scoreData[node.name];
- setCellString(table, i + 2, columnCount, value);
- PlotView::Data data { node.name, value.toDouble() };
- values.append(data);
- }
- PlotView *plot = new PlotView(PlotView::HistogramHorizontal, values, "");
- plot->setFixedSize(QSize(600, 600));
- plot->plot();
- QPixmap pixmap = plot->grab();
- plot->deleteLater();
- if (pixmap.isNull()) {
- return;
- }
- QString imgName = QString("%1_%2_priority_plot").arg(m_proj->id).arg(1);
- QString path = saveImage(imgName, pixmap);
- QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmEvalPic");
- if (bmWeightPic != nullptr) {
- bmWeightPic->dynamicCall("Select(void)");
- QAxObject *range = bmWeightPic->querySubObject("Range");
- QAxObject *inlineShapes = range->querySubObject("InlineShapes");
- QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
- if (shape != nullptr) {
- shape->setProperty("Width", 400);
- shape->setProperty("Height", 400);
- }
- }
- QString viTech;
- double score = 0;
- for (QString key : scoreData.keys()) {
- if (scoreData[key].toDouble() > score) {
- score = scoreData[key].toDouble();
- viTech = key;
- }
- }
- insertText("bmVITech1", viTech);
- insertText("bmVITech2", viTech);
- }
- void ExportReportManager::insertSchemeDesignInfo()
- {
- QList<SchemaEval *> schemeList;
- bool ret = SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_proj->id, 0);
- if (ret == false) {
- qDebug() << __FUNCTION__ << __LINE__ << "query" << endl;
- return;
- }
- for (int i = schemeList.size() - 1; i >= 0; --i) {
- // 插入图片
- QAxObject *bmSchemes = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmSchemes");
- if (bmSchemes != nullptr) {
- bmSchemes->dynamicCall("Select(void)");
- QAxObject *range = bmSchemes->querySubObject("Range");
- QAxObject *inlineShapes = range->querySubObject("InlineShapes");
- QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", schemeList[i]->filePath);
- if (shape != nullptr) {
- shape->setProperty("Width", 200);
- shape->setProperty("Height", 200);
- }
- }
- m_word->insertMoveDown();
- // 插入图片标题
- QString remark = schemeList[i]->remark;
- int picTtlIndex = remark.lastIndexOf("(图");
- QString subStr = remark.mid(picTtlIndex + 1, 8);
- QString picTtl = "";
- if (subStr.contains(")")) {
- picTtl = subStr.split(")").first();
- }
- m_word->setFontName(QString::fromLocal8Bit("黑体"));
- m_word->setFontSize(9);
- m_word->setParagraphAlignment(0);
- m_word->insertText(picTtl + " " + "阵地位置图");
- m_word->insertMoveDown();
- // 插入方案描述
- insertText("bmSchemes", schemeList[i]->name + ":" + schemeList[i]->remark);
- if (i != 0) {
- m_word->insertMoveDown();
- }
- }
- }
- void ExportReportManager::insertSchemeIndex()
- {
- insertText("bmProjName31", m_proj->projectName);
- insertText("bmProjName32", m_proj->projectName);
- QList<CNodeData> nodeList;
- bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 4);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = mind->levels();
- // bmIndexTable
- QAxObject *table = insertTable("bmIndexTable", rowCount, columnCount);
- if (table == nullptr) {
- delete mind;
- return;
- }
- for (int i = 2; i <= mind->levels(); ++i) {
- if (i < mind->levels()) {
- setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
- } else {
- setCellString(table, 1, i - 1, QString("指标"));
- setCellString(table, 1, i, QString("量纲"));
- }
- QList<CNodeData> nodes = mind->nodesInLevel(i);
- int rowPos = 2;
- for (int j = 0; j < nodes.size(); ++j) {
- CNodeData node = nodes[j];
- int leaves = mind->leavesCountOfNode(node);
- int textPos = (rowPos + leaves / 2);
- setCellString(table, textPos, i - 1, node.name);
- if (leaves > 1) {
- mergeCells(table, rowPos, i - 1, leaves, 1);
- }
- rowPos += leaves;
- }
- }
- for (int i = 0; i < leaveNodes.size(); ++i) {
- CNodeData node = leaveNodes[i];
- setCellString(table, i + 2, columnCount, node.dimension);
- }
- delete mind;
- CMindView *m = new CMindView();
- m->setNodeList(nodeList);
- m->refreshItems();
- int sceneWidth = m->sceneRect().width();
- int sceneHeight = m->sceneRect().height();
- QRectF sourceRect = QRectF(0, 0, sceneWidth, sceneHeight);
- QRectF targetRect = QRectF(10, 10, sceneWidth, sceneHeight);
- QPixmap pixmap(QSize(sceneWidth + 20, sceneHeight + 20));
- pixmap.fill(QColor(244, 244, 255));
- QPainter painter(&pixmap);
- painter.setRenderHints(QPainter::Antialiasing);
- m->scene()->render(&painter, targetRect, sourceRect);
- delete m;
- QString imgName = QString("%1_%2_index").arg(m_proj->id).arg(4);
- QString path = saveImage(imgName, pixmap);
- QImageWriter writer(path);
- writer.setFormat("PNG");
- ret = writer.write(pixmap.toImage());
- if (ret) {
- QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmIndexPic");
- if (bmWeightPic != nullptr) {
- bmWeightPic->dynamicCall("Select(void)");
- QAxObject *range = bmWeightPic->querySubObject("Range");
- QAxObject *inlineShapes = range->querySubObject("InlineShapes");
- QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
- if (shape != nullptr) {
- int w = pixmap.width();
- int h = pixmap.height();
- if (w > 400) {
- h = h * 400 / w;
- w = 400;
- }
- shape->setProperty("Width", w);
- shape->setProperty("Height", h);
- }
- }
- }
- }
- void ExportReportManager::insertSchemeData()
- {
- insertText("bmProjName41", m_proj->projectName);
- QList<CNodeData> nodeList;
- bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 4);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QMap<int, QMap<QString, double>> schemeData;
- QMap<int, QString> schemeNames;
- QList<SchemaEval *> schemeList;
- ret = SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_proj->id, m_schemeType);
- if (ret == false || schemeList.size() <= 0) {
- delete mind;
- return;
- }
- for (SchemaEval *scheme : schemeList) {
- if (schemeData.keys().contains(scheme->id) == false) {
- schemeData[scheme->id] = QMap<QString, double>();
- }
- QStringList keyValueStringList = scheme->valueStr.split(";");
- for (QString keyValueStr : keyValueStringList) {
- QStringList keyValue = keyValueStr.split(":");
- if (keyValue.size() == 2) {
- schemeData[scheme->id][keyValue.first()] = keyValue.last().toDouble();
- }
- }
- schemeNames[scheme->id] = scheme->name;
- }
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = schemeNames.keys().size() + 1;
- delete mind;
- // bmSchemeDataTable
- QAxObject *table = insertTable("bmSchemeDataTable", rowCount, columnCount);
- if (table == nullptr) {
- return;
- }
- QList<int> schemeIds = schemeNames.keys();
- for (int i = 0; i < schemeIds.size() + 1; ++i) {
- if (i == 0) {
- setCellString(table, 1, i + 1, "指标");
- } else {
- setCellString(table, 1, i + 1, schemeNames[schemeIds[i - 1]]);
- }
- }
- for (int i = 0; i < leaveNodes.size(); ++i) {
- CNodeData node = leaveNodes[i];
- setCellString(table, i + 2, 1, node.name);
- for (int j = 0; j < schemeIds.size(); ++j) {
- QString value = QString("%1").arg(schemeData[schemeIds[j]][node.name]);
- setCellString(table, i + 2, j + 2, value);
- }
- }
- // 指标权重表:bmEvalTable,指标权重图:bmEvalPic
- QAxObject *scoreTable = insertTable("bmEvalTable", schemeList.size() + 1, 2);
- if (scoreTable == nullptr) {
- return;
- }
- QVector<PlotView::Data> values;
- setCellString(scoreTable, 1, 2, "得分");
- for (int i = 0; i < schemeList.size(); ++i) {
- setCellString(scoreTable, i + 2, 1, schemeList[i]->name);
- QString str = QString::number(schemeList[i]->score, 'f', 2);
- setCellString(scoreTable, i + 2, 2, str);
- PlotView::Data data { schemeList[i]->name, schemeList[i]->score };
- values.append(data);
- }
- PlotView *plot = new PlotView(PlotView::HistogramHorizontal, values, "");
- plot->setFixedSize(QSize(600, 600));
- plot->plot();
- QPixmap pixmap = plot->grab();
- plot->deleteLater();
- if (pixmap.isNull()) {
- return;
- }
- QString imgName = QString("%1_%2_eval").arg(m_proj->id).arg(4);
- QString path = saveImage(imgName, pixmap);
- QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmEvalPic");
- if (bmWeightPic != nullptr) {
- bmWeightPic->dynamicCall("Select(void)");
- QAxObject *range = bmWeightPic->querySubObject("Range");
- QAxObject *inlineShapes = range->querySubObject("InlineShapes");
- QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
- if (shape != nullptr) {
- shape->setProperty("Width", 400);
- shape->setProperty("Height", 400);
- }
- }
- // bmSchemeConclusion
- QString scores;
- int bestIndex = 0;
- for (int i = 0; i < schemeList.size(); ++i) {
- QString str = QString::number(schemeList[i]->score, 'f', 2);
- scores += QString("%1%2,").arg(schemeList[i]->name).arg(str);
- if (schemeList[i]->score > schemeList[bestIndex]->score) {
- bestIndex = i;
- }
- }
- QString conclusion = QString("经评估分析,%1个方案得分分别为:%2%3为最优方案。")
- .arg(schemeList.size())
- .arg(scores)
- .arg(schemeList[bestIndex]->name);
- insertText("bmSchemeConclusion", conclusion);
- }
- void ExportReportManager::insertSchemeAlgInfo()
- {
- // bmWeightAlg bmEvalAlg
- // bmWeightAlgDscpt bmEvalAlgDscpt
- QList<SchemePlanManager::SchemeProcessInfo> processList;
- bool processRet = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, 4);
- if (processRet == false) {
- return;
- }
- for (int i = 0; i < processList.size(); ++i) {
- if (processList[i].type == SchemePlanManager::CalculateWeight) {
- SchemePlanManager::Algorithm alg = processList[i].algorithm;
- QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
- insertText("bmWeightAlg", algStr);
- QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
- insertText("bmWeightAlgDscpt", dscrpt);
- }
- if (processList[i].type == SchemePlanManager::RunEvaluate) {
- SchemePlanManager::Algorithm alg = processList[i].algorithm;
- QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
- insertText("bmEvalAlg", algStr);
- QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
- insertText("bmEvalAlgDscpt", dscrpt);
- }
- }
- }
- void ExportReportManager::insertSchemeWeightData()
- {
- // 指标权重表:bmWeightTable,指标权重图:bmWeightPic
- QList<CNodeData> nodeList;
- bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 4);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = mind->levels();
- // bmIndexTable
- QAxObject *table = insertTable("bmWeightTable", rowCount, columnCount);
- if (table == nullptr) {
- delete mind;
- return;
- }
- for (int i = 2; i <= mind->levels(); ++i) {
- if (i < mind->levels()) {
- setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
- } else {
- setCellString(table, 1, i - 1, QString("指标"));
- setCellString(table, 1, i, QString("权重值"));
- }
- QList<CNodeData> nodes = mind->nodesInLevel(i);
- int rowPos = 2;
- for (int j = 0; j < nodes.size(); ++j) {
- CNodeData node = nodes[j];
- int leaves = mind->leavesCountOfNode(node);
- int textPos = (rowPos + leaves / 2);
- setCellString(table, textPos, i - 1, node.name);
- if (leaves > 1) {
- mergeCells(table, rowPos, i - 1, leaves, 1);
- }
- rowPos += leaves;
- }
- }
- delete mind;
- MindWeightInfo info;
- ret = MindWeightService().queryWeightData(&info, m_proj->id, 4);
- if (ret == false) {
- return;
- }
- if (info.id < 0) {
- return;
- }
- QMap<QString, double> weightData;
- QStringList weightList = info.weight.split(";");
- for (QString keyValueStr : weightList) {
- QStringList keyValue = keyValueStr.split(":");
- if (keyValue.size() == 2) {
- weightData[keyValue.first()] = keyValue.last().toDouble();
- }
- }
- QVector<PlotView::Data> values;
- for (int i = 0; i < leaveNodes.size(); ++i) {
- CNodeData node = leaveNodes[i];
- QString value = QString("%1").arg(weightData[node.name]);
- setCellString(table, i + 2, columnCount, value);
- PlotView::Data data { node.name, weightData[node.name] };
- values.append(data);
- }
- PlotView *plot = new PlotView(PlotView::HistogramHorizontal, values, "");
- plot->setFixedSize(QSize(600, 600));
- plot->plot();
- QPixmap pixmap = plot->grab();
- plot->deleteLater();
- if (pixmap.isNull()) {
- return;
- }
- QString imgName = QString("%1_%2_weight_plot").arg(m_proj->id).arg(4);
- QString path = saveImage(imgName, pixmap);
- QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmWeightPic");
- if (bmWeightPic != nullptr) {
- bmWeightPic->dynamicCall("Select(void)");
- QAxObject *range = bmWeightPic->querySubObject("Range");
- QAxObject *inlineShapes = range->querySubObject("InlineShapes");
- QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
- if (shape != nullptr) {
- shape->setProperty("Width", 400);
- shape->setProperty("Height", 400);
- }
- }
- }
- void ExportReportManager::insertEffiIndex()
- {
- insertText("bmProjName21", m_proj->projectName);
- insertText("bmProjName22", m_proj->projectName);
- QList<CNodeData> nodeList;
- bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 8);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = mind->levels();
- // bmIndexTable
- QAxObject *table = insertTable("bmIndexTable", rowCount, columnCount);
- if (table == nullptr) {
- delete mind;
- return;
- }
- for (int i = 2; i <= mind->levels(); ++i) {
- if (i < mind->levels()) {
- setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
- } else {
- setCellString(table, 1, i - 1, QString("指标"));
- setCellString(table, 1, i, QString("量纲"));
- }
- QList<CNodeData> nodes = mind->nodesInLevel(i);
- int rowPos = 2;
- for (int j = 0; j < nodes.size(); ++j) {
- CNodeData node = nodes[j];
- int leaves = mind->leavesCountOfNode(node);
- int textPos = (rowPos + leaves / 2);
- setCellString(table, textPos, i - 1, node.name);
- if (leaves > 1) {
- mergeCells(table, rowPos, i - 1, leaves, 1);
- }
- rowPos += leaves;
- }
- }
- for (int i = 0; i < leaveNodes.size(); ++i) {
- CNodeData node = leaveNodes[i];
- setCellString(table, i + 2, columnCount, node.dimension);
- }
- delete mind;
- CMindView *m = new CMindView();
- m->setNodeList(nodeList);
- m->refreshItems();
- int sceneWidth = m->sceneRect().width();
- int sceneHeight = m->sceneRect().height();
- QRectF sourceRect = QRectF(0, 0, sceneWidth, sceneHeight);
- QRectF targetRect = QRectF(10, 10, sceneWidth, sceneHeight);
- QPixmap pixmap(QSize(sceneWidth + 20, sceneHeight + 20));
- pixmap.fill(QColor(244, 244, 255));
- QPainter painter(&pixmap);
- painter.setRenderHints(QPainter::Antialiasing);
- m->scene()->render(&painter, targetRect, sourceRect);
- delete m;
- QString imgName = QString("%1_%2_index").arg(m_proj->id).arg(8);
- QString path = saveImage(imgName, pixmap);
- QImageWriter writer(path);
- writer.setFormat("PNG");
- ret = writer.write(pixmap.toImage());
- if (ret) {
- QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmIndexPic");
- if (bmWeightPic != nullptr) {
- bmWeightPic->dynamicCall("Select(void)");
- QAxObject *range = bmWeightPic->querySubObject("Range");
- QAxObject *inlineShapes = range->querySubObject("InlineShapes");
- QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
- if (shape != nullptr) {
- int w = pixmap.width();
- int h = pixmap.height();
- if (w > 400) {
- h = h * 400 / w;
- w = 400;
- }
- shape->setProperty("Width", w);
- shape->setProperty("Height", h);
- }
- }
- }
- }
- void ExportReportManager::insertEffiAlgInfo()
- {
- // bmWeightAlg bmEvalAlg
- // bmWeightAlgDscpt bmEvalAlgDscpt
- QList<SchemePlanManager::SchemeProcessInfo> processList;
- bool processRet = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, 8);
- if (processRet == false) {
- return;
- }
- for (int i = 0; i < processList.size(); ++i) {
- if (processList[i].type == SchemePlanManager::CalculateWeight) {
- SchemePlanManager::Algorithm alg = processList[i].algorithm;
- QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
- insertText("bmWeightAlg", algStr);
- QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
- insertText("bmWeightAlgDscpt", dscrpt);
- }
- if (processList[i].type == SchemePlanManager::RunEvaluate) {
- SchemePlanManager::Algorithm alg = processList[i].algorithm;
- if (alg == SchemePlanManager::MEA) {
- m_schemeType = 1;
- } else {
- m_schemeType = 2;
- }
- QString algStr = SchemePlanManager::nameOfAlgorithm(alg);
- insertText("bmEvalAlg", algStr);
- QString dscrpt = SchemePlanManager::descriptionOfAlgorithm(alg);
- insertText("bmEvalAlgDscpt", dscrpt);
- }
- }
- }
- void ExportReportManager::insertEffiConfigData()
- {
- // bmProjName31, bmProjName32, bmConfigTable
- insertText("bmProjName31", m_proj->projectName);
- insertText("bmProjName32", m_proj->projectName);
- QList<GradeInfo *> gradeInfoList;
- int type = m_schemeType == 1 ? 0 : 1;
- bool ret = GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, m_proj->id, type);
- if (ret == false || gradeInfoList.size() <= 0) {
- return;
- }
- QStringList gradeNames;
- for (int i = 0; i < gradeInfoList.size(); ++i) {
- gradeNames.append(gradeInfoList[i]->gradeValue);
- }
- QMap<QString, QString> gradeInfoData;
- if (m_schemeType == 1) {
- QList<GradeIndexInfo *> gradeIndexInfoList;
- ret = GradeIndexInfoService().QueryGradeIndexInfoByProjectId(&gradeIndexInfoList, m_proj->id);
- if (ret == false || gradeIndexInfoList.size() <= 0) {
- return;
- }
- for (int i = gradeIndexInfoList.size() - 1; i >= 0; --i) {
- QString name = gradeIndexInfoList[i]->gradeIndexName;
- QString value = gradeInfoData[name];
- if (gradeNames.size() > gradeIndexInfoList[i]->gradeLevel - 1) {
- QString grade = gradeNames[gradeIndexInfoList[i]->gradeLevel - 1];
- if (value.contains(grade)) {
- continue;
- } else {
- value += grade;
- }
- }
- value += ":";
- value += gradeIndexInfoList[i]->gradeIndexValue;
- if (gradeIndexInfoList[i]->gradeLevel > 1) {
- value += "\n";
- }
- gradeInfoData[name] = value;
- }
- } else {
- QList<EffectIndexInfo *> effectIndexInfoList;
- ret = EffectIndexInfoService().QueryEffectIndexInfoByProjectId(&effectIndexInfoList, m_proj->id);
- if (ret == false) {
- return;
- }
- for (EffectIndexInfo *info : effectIndexInfoList) {
- QStringList valueList = info->effectIndexValue.split(",");
- QString value;
- for (int i = valueList.size() - 1; i >= 0; --i) {
- if (gradeNames.size() > i) {
- value += gradeNames[i];
- }
- value += ":";
- value += (valueList[i].replace(":", ","));
- if (i > 0) {
- value += "\n";
- }
- gradeInfoData[info->effectIndexName] = value;
- }
- }
- }
- QList<CNodeData> nodeList;
- ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 8);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = mind->levels();
- // bmConfigTable
- QAxObject *table = insertTable("bmConfigTable", rowCount, columnCount);
- if (table == nullptr) {
- delete mind;
- return;
- }
- for (int i = 2; i <= mind->levels(); ++i) {
- if (i < mind->levels()) {
- setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
- } else {
- setCellString(table, 1, i - 1, QString("指标"));
- setCellString(table, 1, i, QString("效能分级"));
- }
- QList<CNodeData> nodes = mind->nodesInLevel(i);
- int rowPos = 2;
- for (int j = 0; j < nodes.size(); ++j) {
- CNodeData node = nodes[j];
- int leaves = mind->leavesCountOfNode(node);
- int textPos = (rowPos + leaves / 2);
- setCellString(table, textPos, i - 1, node.name);
- if (leaves > 1) {
- mergeCells(table, rowPos, i - 1, leaves, 1);
- }
- rowPos += leaves;
- }
- }
- for (int i = 0; i < leaveNodes.size(); ++i) {
- CNodeData node = leaveNodes[i];
- QString value = QString("%1").arg(gradeInfoData[node.name]);
- setCellString(table, i + 2, columnCount, value);
- }
- delete mind;
- }
- void ExportReportManager::insertEffiSchemeData()
- {
- QList<CNodeData> nodeList;
- bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 8);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QMap<int, QMap<QString, double>> schemeData;
- QMap<int, QString> schemeNames;
- QList<SchemaEval *> schemeList;
- ret = SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_proj->id, m_schemeType);
- if (ret == false || schemeList.size() <= 0) {
- delete mind;
- return;
- }
- for (SchemaEval *scheme : schemeList) {
- if (m_schemeType == 2 && scheme->name != "建设前" && scheme->name != "建设后") {
- continue;
- }
- if (schemeData.keys().contains(scheme->id) == false) {
- schemeData[scheme->id] = QMap<QString, double>();
- }
- QStringList keyValueStringList = scheme->valueStr.split(";");
- for (QString keyValueStr : keyValueStringList) {
- QStringList keyValue = keyValueStr.split(":");
- if (keyValue.size() == 2) {
- schemeData[scheme->id][keyValue.first()] = keyValue.last().toDouble();
- }
- }
- schemeNames[scheme->id] = scheme->name;
- }
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = schemeNames.keys().size() + 1;
- delete mind;
- // bmSchemeDataTable
- QAxObject *table = insertTable("bmEffiDataTable", rowCount, columnCount);
- if (table == nullptr) {
- return;
- }
- QList<int> schemeIds = schemeNames.keys();
- for (int i = 0; i < schemeIds.size() + 1; ++i) {
- if (i == 0) {
- setCellString(table, 1, i + 1, "指标");
- } else {
- setCellString(table, 1, i + 1, schemeNames[schemeIds[i - 1]]);
- }
- }
- for (int i = 0; i < leaveNodes.size(); ++i) {
- CNodeData node = leaveNodes[i];
- setCellString(table, i + 2, 1, node.name);
- for (int j = 0; j < schemeIds.size(); ++j) {
- QString value = QString("%1").arg(schemeData[schemeIds[j]][node.name]);
- setCellString(table, i + 2, j + 2, value);
- }
- }
- }
- void ExportReportManager::insertEffiWeightData()
- {
- // 指标权重表:bmWeightTable,指标权重图:bmWeightPic
- QList<CNodeData> nodeList;
- bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 8);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = mind->levels();
- // bmIndexTable
- QAxObject *table = insertTable("bmWeightTable", rowCount, columnCount);
- if (table == nullptr) {
- delete mind;
- return;
- }
- for (int i = 2; i <= mind->levels(); ++i) {
- if (i < mind->levels()) {
- setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
- } else {
- setCellString(table, 1, i - 1, QString("指标"));
- setCellString(table, 1, i, QString("权重值"));
- }
- QList<CNodeData> nodes = mind->nodesInLevel(i);
- int rowPos = 2;
- for (int j = 0; j < nodes.size(); ++j) {
- CNodeData node = nodes[j];
- int leaves = mind->leavesCountOfNode(node);
- int textPos = (rowPos + leaves / 2);
- setCellString(table, textPos, i - 1, node.name);
- if (leaves > 1) {
- mergeCells(table, rowPos, i - 1, leaves, 1);
- }
- rowPos += leaves;
- }
- }
- delete mind;
- MindWeightInfo info;
- ret = MindWeightService().queryWeightData(&info, m_proj->id, 8);
- if (ret == false) {
- return;
- }
- if (info.id < 0) {
- return;
- }
- QMap<QString, double> weightData;
- QStringList weightList = info.weight.split(";");
- for (QString keyValueStr : weightList) {
- QStringList keyValue = keyValueStr.split(":");
- if (keyValue.size() == 2) {
- weightData[keyValue.first()] = keyValue.last().toDouble();
- }
- }
- QVector<PlotView::Data> values;
- for (int i = 0; i < leaveNodes.size(); ++i) {
- CNodeData node = leaveNodes[i];
- QString value = QString("%1").arg(weightData[node.name]);
- setCellString(table, i + 2, columnCount, value);
- PlotView::Data data { node.name, weightData[node.name] };
- values.append(data);
- }
- PlotView *plot = new PlotView(PlotView::HistogramHorizontal, values, "");
- plot->setFixedSize(QSize(600, 600));
- plot->plot();
- QPixmap pixmap = plot->grab();
- plot->deleteLater();
- if (pixmap.isNull()) {
- return;
- }
- QString imgName = QString("%1_%2_weight_plot").arg(m_proj->id).arg(8);
- QString path = saveImage(imgName, pixmap);
- QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmWeightPic");
- if (bmWeightPic != nullptr) {
- bmWeightPic->dynamicCall("Select(void)");
- QAxObject *range = bmWeightPic->querySubObject("Range");
- QAxObject *inlineShapes = range->querySubObject("InlineShapes");
- QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
- if (shape != nullptr) {
- shape->setProperty("Width", 400);
- shape->setProperty("Height", 400);
- }
- }
- }
- void ExportReportManager::insertEffiResult()
- {
- QList<GradeInfo *> gradeInfoList;
- int type = m_schemeType == 1 ? 0 : 1;
- bool gradeRet = GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, m_proj->id, type);
- if (gradeRet == false) {
- return;
- }
- QStringList gradeNames;
- for (int i = 0; i < gradeInfoList.size(); ++i) {
- gradeNames.append(gradeInfoList[i]->gradeValue);
- }
- QList<EffectResult> effList;
- bool effRet = EffectResultService().queryDataList(effList, m_proj->id);
- if (effRet == false) {
- return;
- }
- QMap<int, QMap<QString, QList<double>>> effData;
- QMap<int, QString> schemeNames;
- int levels = 0;
- for (EffectResult effect : effList) {
- if (effData.keys().contains(effect.schemeId) == false) {
- effData[effect.schemeId] = QMap<QString, QList<double>>();
- schemeNames[effect.schemeId] = effect.schemeName;
- }
- QStringList values = effect.value.split(",");
- levels = values.size();
- QList<double> valueList;
- for (int v = 0; v < values.size(); ++v) {
- valueList.append(values[v].toDouble());
- }
- effData[effect.schemeId][effect.indexName] = valueList;
- }
- QList<CNodeData> nodeList;
- bool ret = CNodeDataService().QueryAllValid(nodeList, m_proj->id, 8);
- if (ret == false) {
- return;
- }
- CMind *mind = new CMind();
- mind->setNodeList(nodeList);
- QList<CNodeData> leaveNodes = mind->leaves();
- int rowCount = leaveNodes.size() + 1;
- int columnCount = mind->levels() + schemeNames.size() - 1;
- // bmEvalTable
- QAxObject *table = insertTable("bmEvalTable", rowCount, columnCount);
- if (table == nullptr) {
- delete mind;
- return;
- }
- for (int i = 2; i <= mind->levels(); ++i) {
- if (i < mind->levels()) {
- setCellString(table, 1, i - 1, QString("%1级指标\n(能力项)").arg(i - 1));
- } else {
- setCellString(table, 1, i - 1, QString("指标"));
- }
- QList<CNodeData> nodes = mind->nodesInLevel(i);
- int rowPos = 2;
- for (int j = 0; j < nodes.size(); ++j) {
- CNodeData node = nodes[j];
- int leaves = mind->leavesCountOfNode(node);
- int textPos = (rowPos + leaves / 2);
- setCellString(table, textPos, i - 1, node.name);
- if (leaves > 1) {
- mergeCells(table, rowPos, i - 1, leaves, 1);
- }
- rowPos += leaves;
- }
- }
- for (int i = 0; i < schemeNames.size(); ++i) {
- setCellString(table, 1, i + mind->levels(),
- schemeNames[schemeNames.keys()[i]] + "\n(" + gradeNames.join(",") + ")");
- for (int j = 0; j < leaveNodes.size(); ++j) {
- CNodeData node = leaveNodes[j];
- QList<double> values = effData[schemeNames.keys()[i]][node.name];
- int bestIndex = 0;
- QString score;
- for (int k = 0; k < values.size(); ++k) {
- if (values[k] > values[bestIndex]) {
- bestIndex = k;
- }
- score += QString::number(values[k], 'f', 1).replace(".0", "").replace("nan", "0");
- if (k < values.size() - 1) {
- score += ",";
- }
- }
- QString rand = gradeNames[bestIndex];
- QString value = rand + "(" + score + ")";
- setCellString(table, j + 2, i + mind->levels(), value);
- }
- }
- // 指标权重图:bmEvalPic
- for (int i = schemeNames.size() - 1; i >= 0; --i) {
- QString schemeName = schemeNames[schemeNames.keys()[i]];
- QList<double> values = effData[schemeNames.keys()[i]]["综合"];
- QVector<PlotView::Data> plotValues;
- for (int j = 0; j < values.size(); ++j) {
- PlotView::Data data { schemeName + "-" + gradeNames[j], values[j] };
- plotValues.append(data);
- }
- PlotView *plot = new PlotView(PlotView::HistogramHorizontal, plotValues, "");
- plot->setFixedSize(QSize(600, 600));
- plot->plot();
- QPixmap pixmap = plot->grab();
- plot->deleteLater();
- if (pixmap.isNull()) {
- return;
- }
- QString imgName = QString("%1_%2_%3_eval").arg(m_proj->id).arg(8).arg(schemeName);
- QString path = saveImage(imgName, pixmap);
- QAxObject *bmWeightPic = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", "bmEvalPic");
- if (bmWeightPic != nullptr) {
- bmWeightPic->dynamicCall("Select(void)");
- QAxObject *range = bmWeightPic->querySubObject("Range");
- QAxObject *inlineShapes = range->querySubObject("InlineShapes");
- QAxObject *shape = inlineShapes->querySubObject("AddPicture(const QString&)", path);
- if (shape != nullptr) {
- shape->setProperty("Width", 400);
- shape->setProperty("Height", 400);
- }
- }
- }
- QStringList retList;
- int bestGrade = 0;
- int bestSchemeIndex = 0;
- for (int i = 0; i < schemeNames.size(); ++i) {
- int grade = 0;
- QList<double> values = effData[schemeNames.keys()[i]]["综合"];
- for (int j = 0; j < values.size(); ++j) {
- if (values[j] > values[grade]) {
- grade = j;
- }
- }
- QString ret = schemeNames[schemeNames.keys()[i]] + "的综合评价等级为" + gradeNames[grade];
- retList.append(ret);
- if (grade > bestGrade) {
- bestGrade = grade;
- bestSchemeIndex = i;
- }
- }
- QString bestScheme = schemeNames[schemeNames.keys()[bestSchemeIndex]];
- QString conclusion = "根据评估结果," + retList.join(",") + "。所以" + bestScheme + "更优。";
- insertText("bmEffiConclusion", conclusion);
- delete mind;
- }
- bool ExportReportManager::insertText(const QString &bookmark, const QString &text)
- {
- bool ret = false;
- QAxObject *bmProjName = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", bookmark);
- if (bmProjName != nullptr) {
- bmProjName->dynamicCall("Select(void)");
- QAxObject *range = bmProjName->querySubObject("Range");
- ret = range->setProperty("Text", text);
- }
- return ret;
- }
- QAxObject *ExportReportManager::insertTable(QString bookmark, int row, int column)
- {
- QAxObject *bmTable = m_word->getDocument()->querySubObject("Bookmarks(QVariant)", bookmark);
- if (bmTable) {
- bmTable->dynamicCall("Select(void)");
- QAxObject *selection = m_word->getWordApp()->querySubObject("Selection");
- if (!selection)
- return nullptr;
- selection->dynamicCall("InsertAfter(QString&)", "\n");
- // selection->dynamicCall("MoveLeft(int)", 1);
- selection->querySubObject("ParagraphFormat")->dynamicCall("Alignment", "wdAlignParagraphCenter");
- // selection->dynamicCall("TypeText(QString&)", "Table Test"); //设置标题
- QAxObject *range = selection->querySubObject("Range");
- QAxObject *tables = m_word->getDocument()->querySubObject("Tables");
- QAxObject *table = tables->querySubObject("Add(QVariant,int,int)", range->asVariant(), row, column);
- if (!tables)
- return nullptr;
- for (int i = 1; i <= 6; i++) {
- QString str = QString("Borders(-%1)").arg(i);
- QAxObject *borders = table->querySubObject(str.toLocal8Bit().constData());
- borders->dynamicCall("SetLineStyle(int)", 1);
- }
- return table;
- }
- return nullptr;
- }
- void ExportReportManager::setCellString(QAxObject *table, int row, int column, const QString &text)
- {
- if (table == nullptr) {
- return;
- }
- table->querySubObject("Cell(int,int)", row, column)->querySubObject("Range")->dynamicCall("SetText(QString)", text);
- }
- void ExportReportManager::mergeCells(QAxObject *table, int row, int column, int rowSpan, int columnSpan)
- {
- if (table == nullptr) {
- return;
- }
- QAxObject *startCell = table->querySubObject("Cell(int, int)", row, column);
- QAxObject *endCell = table->querySubObject("Cell(int, int)", row + rowSpan - 1, column + columnSpan - 1);
- if (nullptr == startCell) {
- return;
- }
- if (nullptr == endCell) {
- return;
- }
- startCell->querySubObject("Merge(LPDISPATCH)", endCell->asVariant());
- }
- QString ExportReportManager::saveImage(const QString &name, const QPixmap &pixmap)
- {
- QString curPath = QDir::currentPath();
- QString dateStr = QDate::currentDate().toString("yyyy-MM-dd");
- QString picDir = curPath + "/report_pics/" + dateStr + "/";
- QDir dir(picDir);
- if (!dir.exists()) {
- dir.mkpath(picDir);
- }
- QString filePath = picDir + name + ".png";
- QImageWriter writer(filePath);
- writer.setFormat("PNG");
- bool ret = writer.write(pixmap.toImage());
- if (ret) {
- return filePath;
- } else {
- return "";
- }
- }
|