|
@@ -1,10 +1,16 @@
|
|
|
#include "ExportReportManager.h"
|
|
|
|
|
|
#include "ProjectManager.h"
|
|
|
+#include "SchemePlanManager.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 <QWord/QWord.h>
|
|
|
#include <QWord/QWordDemo.h>
|
|
@@ -12,6 +18,7 @@
|
|
|
#include <QDir>
|
|
|
#include <QDate>
|
|
|
#include <QLabel>
|
|
|
+#include <QImageWriter>
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
@@ -53,11 +60,13 @@ bool ExportReportManager::exportReport()
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- insertCommonInfo();
|
|
|
+ insertProjectInfo();
|
|
|
if (m_evalType == ProjectManager::OptimalEval) {
|
|
|
insertSchemeDesignInfo();
|
|
|
insertSchemeIndex();
|
|
|
insertSchemeData();
|
|
|
+ insertSchemeAlgInfo();
|
|
|
+ insertSchemeWeightData();
|
|
|
}
|
|
|
|
|
|
m_word->setVisible(true);
|
|
@@ -83,7 +92,7 @@ bool ExportReportManager::createWord()
|
|
|
|
|
|
// 根据模板创建 word 文档
|
|
|
QString typeStr = ProjectManager::reportNameOfEvalType((ProjectManager::EvalType)m_evalType);
|
|
|
- QString tempPath = "E:/qfd/code/QFD2/bin/report_templates/" + typeStr + ".docx";
|
|
|
+ QString tempPath = curPath + "/report_templates/" + typeStr + ".docx";
|
|
|
if (!QFile::exists(tempPath)) {
|
|
|
qDebug() << __FUNCTION__ << __LINE__ << "Report template not found" << endl;
|
|
|
return false;
|
|
@@ -104,7 +113,7 @@ bool ExportReportManager::createWord()
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-void ExportReportManager::insertCommonInfo()
|
|
|
+void ExportReportManager::insertProjectInfo()
|
|
|
{
|
|
|
insertText("bmProjName", m_proj->projectName);
|
|
|
insertText("bmProjUnit", m_proj->estimateDept);
|
|
@@ -222,6 +231,198 @@ void ExportReportManager::insertSchemeIndex()
|
|
|
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, 0);
|
|
|
+ if (ret == false) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (schemeList.size() <= 0) {
|
|
|
+ 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;
|
|
|
+
|
|
|
+ // 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ delete mind;
|
|
|
+}
|
|
|
+
|
|
|
+void ExportReportManager::insertSchemeAlgInfo()
|
|
|
+{
|
|
|
+ // bmWeightAlg bmEvalAlg
|
|
|
+ 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::stringFromAlgorithm(alg);
|
|
|
+ insertText("bmWeightAlg", algStr);
|
|
|
+ }
|
|
|
+ if (processList[i].type == SchemePlanManager::RunEvaluate) {
|
|
|
+ SchemePlanManager::Algorithm alg = processList[i].algorithm;
|
|
|
+ QString algStr = SchemePlanManager::stringFromAlgorithm(alg);
|
|
|
+ insertText("bmEvalAlg", algStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+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").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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
bool ExportReportManager::insertText(const QString &bookmark, const QString &text)
|
|
@@ -293,3 +494,24 @@ void ExportReportManager::mergeCells(QAxObject *table, int row, int column, int
|
|
|
|
|
|
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 "";
|
|
|
+ }
|
|
|
+}
|