Browse Source

'添加等级接口'

zsf 1 year ago
parent
commit
9bb7c8012b

+ 135 - 5
ExpertClient/EXDataTableView.cpp

@@ -5,6 +5,8 @@
 #include "ProjectManager.h"
 #include <dbService/CNodeDataService.h>
 #include <dbService/ClassSet.h>
+#include <dbService/UserService.h>
+#include <dbService/NodeMatrixService.h>
 
 #include <Widgets/Button.h>
 #include <QBoxLayout>
@@ -19,6 +21,8 @@
 #include <QHeaderView>
 #include <QApplication>
 #include <QDesktopWidget>
+#include <QDateTime>
+#include <QFileDialog>
 
 #include <QDebug>
 
@@ -32,6 +36,11 @@ EXDataTableView::EXDataTableView(SchemePlanManager::SchemeProcessInfo process, Q
     connectSignalsAndSlots();
 
     m_comboDelegate = new EXDataTableComboDelegate(this);
+
+    m_user = new QFUser();
+    UserService().QueryUserInfoById(m_user, 62);
+
+    m_export = new QXlsx::Document(this);
 }
 
 SchemePlanManager::SchemeProcessInfo EXDataTableView::process() const
@@ -39,6 +48,11 @@ SchemePlanManager::SchemeProcessInfo EXDataTableView::process() const
     return m_process;
 }
 
+void EXDataTableView::setProjectInfo(ProjectInfo *proj)
+{
+    m_proj = proj;
+}
+
 void EXDataTableView::initWidget()
 {
     m_dataTab = new QTabWidget(this);
@@ -46,6 +60,7 @@ void EXDataTableView::initWidget()
     m_pageLab  = new QLabel(this);
     m_previous = new PushButton("上一级指标", this);
     m_next     = new PushButton("下一级指标", this);
+    m_save     = new PushButton("保存", this);
 }
 
 void EXDataTableView::initLayout()
@@ -61,6 +76,7 @@ void EXDataTableView::initLayout()
     m_pageLayout->addWidget(m_pageLab);
     m_pageLayout->addWidget(m_next);
     m_pageLayout->addStretch();
+    m_pageLayout->addWidget(m_save);
 }
 
 void EXDataTableView::connectSignalsAndSlots()
@@ -68,6 +84,7 @@ void EXDataTableView::connectSignalsAndSlots()
     connect(m_previous, &PushButton::clicked, this, &EXDataTableView::slotPrevious);
     connect(m_next, &PushButton::clicked, this, &EXDataTableView::slotNext);
     connect(m_dataTab, &QTabWidget::currentChanged, this, &EXDataTableView::slotTabCurrentChanged);
+    connect(m_save, &PushButton::clicked, this, &EXDataTableView::slotSave);
 }
 
 void EXDataTableView::setupTabWidget()
@@ -77,7 +94,11 @@ void EXDataTableView::setupTabWidget()
     /// 所以使用 m_isSettingTable 标记此过程, 以采取必要措施来规避一些异常操作
     m_isSettingTable = true;
     m_dataTab->clear();
-    for (CNodeData n : m_mind1->nodesInLevel(m_currentPage)) {
+
+    QList<CNodeData> nodeList = m_mind1->nodesInLevel(m_currentPage);
+
+    for (int i = 0; i < nodeList.count(); i++) {
+        CNodeData n   = nodeList[i];
         QTableView *t = new QTableView(m_dataTab);
         t->setAlternatingRowColors(m_mind2->nodeList().count() > 0);
         t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
@@ -88,9 +109,21 @@ void EXDataTableView::setupTabWidget()
 
         m_dataTab->addTab(t, n.name);
 
-        QStandardItemModel *model = new QStandardItemModel(t);
+        QList<QStandardItemModel *> modelList;
+        if (m_models.keys().contains(m_currentPage)) {
+            modelList = m_models[m_currentPage];
+        }
+        QStandardItemModel *model;
+        if (modelList.count() <= i) {
+            model = new QStandardItemModel(t);
+            modelList.append(model);
+        } else {
+            model = modelList[i];
+        }
+        m_models[m_currentPage] = modelList;
+
         t->setModel(model);
-        connect(t, &QTableView::clicked, this, &EXDataTableView::itemClicked);
+        connect(t, &QTableView::clicked, this, &EXDataTableView::slotItemClicked);
     }
     m_isSettingTable = false;
 }
@@ -225,7 +258,6 @@ void EXDataTableView::updateCurrentTable()
             for (int j = 0; j < hList.count(); j++) {
                 QStandardItem *item = new QStandardItem();
                 item->setData(Qt::AlignCenter, Qt::TextAlignmentRole);
-                //                item->setEditable(false);
                 model->setItem(i, j, item);
                 table->setItemDelegate(m_comboDelegate);
             }
@@ -243,6 +275,68 @@ CMind *EXDataTableView::mind2() const
     return m_mind2;
 }
 
+void EXDataTableView::exportData()
+{
+    qDebug() << __FUNCTION__ << __LINE__ << endl;
+
+    //文件夹路径
+    QFileDialog::Options options;
+    options |= QFileDialog::DontUseNativeDialog;
+    QString filePath = QFileDialog::getExistingDirectory(nullptr, "导出资源包", "/", options);
+    if (filePath.isEmpty()) {
+        return;
+    }
+    QString fileName = m_user->userName + "-"
+            + ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_process.indexType) + "-"
+            + m_proj->projectName;
+    // QString filePath = "";
+    // filePath         = QCoreApplication::applicationDirPath();
+    QDir dirReportPath(filePath);
+    if (!dirReportPath.exists()) {
+        if (dirReportPath.mkpath(filePath)) {
+            filePath = filePath + "/" + fileName + tr(".xlsx");
+        }
+    } else {
+        filePath = filePath + "/" + fileName + tr(".xlsx");
+    }
+    QFile file(fileName);
+    if (file.exists()) {
+        file.remove();
+    }
+
+    for (int i = 1; i < m_mind1->levels(); i++) {
+        if (m_models.keys().contains(i) == false) {
+            continue;
+        }
+        QList<CNodeData> nodes = m_mind1->nodesInLevel(i);
+
+        for (int j = 0; j < m_models[i].count(); j++) {
+            CNodeData node            = nodes[j];
+            QStandardItemModel *model = m_models[i][j];
+            m_export->addSheet(node.name);
+            int row = model->rowCount();
+            int col = model->columnCount();
+
+            m_export->setColumnWidth(1, 20);
+            for (int c = 2; c < col + 2; c++) {
+                QStandardItem *head = model->horizontalHeaderItem(c - 2);
+                m_export->write(1, c, head->text());
+                m_export->setColumnWidth(c, head->text().size() == 0 ? 40 : head->text().size() * 4);
+            }
+            for (int r = 2; r < row + 2; r++) {
+                QStandardItem *head = model->verticalHeaderItem(r - 2);
+                m_export->write(r, 1, head->text());
+
+                for (int c = 2; c < col + 2; c++) {
+                    QStandardItem *head = model->item(r - 2, c - 2);
+                    m_export->write(r, c, head->text());
+                }
+            }
+        }
+
+        m_export->saveAs(filePath);
+    }
+}
 void EXDataTableView::editItemData(const QModelIndex &index, const QString &val)
 {
     int c                     = m_dataTab->currentIndex();
@@ -278,7 +372,7 @@ void EXDataTableView::slotTabCurrentChanged(int c)
     updateCurrentTable();
 }
 
-void EXDataTableView::itemClicked(const QModelIndex &index)
+void EXDataTableView::slotItemClicked(const QModelIndex &index)
 {
     if (index.row() >= index.column()) {
         return;
@@ -309,3 +403,39 @@ void EXDataTableView::itemClicked(const QModelIndex &index)
     }
     scheme->move(p);
 }
+
+void EXDataTableView::slotSave()
+{
+    return;
+    int c                     = m_dataTab->currentIndex();
+    QTableView *table         = (QTableView *)m_dataTab->widget(c);
+    QStandardItemModel *model = (QStandardItemModel *)table->model();
+
+    QList<NodeMatrixInfo *> values;
+
+    if (m_process.type == SchemePlanManager::ImportWeightData) {
+        for (int i = 0; i < model->rowCount(); i++) {
+            QStandardItem *row = model->verticalHeaderItem(i);
+            for (int j = 0; j < model->columnCount(); j++) {
+                QStandardItem *col  = model->horizontalHeaderItem(j);
+                QStandardItem *item = model->item(i, j);
+
+                NodeMatrixInfo *info = new NodeMatrixInfo();
+                info->expertName     = m_user->userName;
+                info->expertId       = QString("%1").arg(m_user->id);
+                info->engineerId     = m_process.projectId;
+                info->mindId         = m_process.dSource;
+                info->abscissa       = col->text();
+                info->ordinate       = row->text();
+                info->writeDate      = QDateTime::currentDateTime();
+                info->mark           = QString("%1").arg(m_currentPage);
+                info->nodeValue      = item->text();
+                info->tableMsg       = QString("%1").arg(m_process.indexType);
+
+                values.append(info);
+            }
+        }
+    }
+
+    NodeMatrixService().AddNodeMatrixInfoList2(values);
+}

+ 23 - 2
ExpertClient/EXDataTableView.h

@@ -4,9 +4,14 @@
 #include <QWidget>
 
 #include "SchemePlanManager.h"
+#include "CNode.h"
 
 #include <dbService/ClassSet.h>
 
+#include <xlsxdocument.h>
+
+class QFUser;
+
 class CMind;
 class ProjectInfo;
 class PushButton;
@@ -19,6 +24,8 @@ class QHBoxLayout;
 
 class EXDataTableComboDelegate;
 
+class QStandardItemModel;
+
 /**
  * @brief The DataTableWidget class
  * 数据表, 整体上是包含多个 QTableView 的 QTabWidget
@@ -35,6 +42,8 @@ public:
 
     SchemePlanManager::SchemeProcessInfo process() const;
 
+    void setProjectInfo(ProjectInfo *proj);
+
     void initWidget();
 
     void initLayout();
@@ -52,6 +61,8 @@ public:
     CMind *mind1() const;
     CMind *mind2() const;
 
+    void exportData();
+
 private:
     void editItemData(const QModelIndex &index, const QString &val);
 
@@ -59,11 +70,19 @@ private slots:
     void slotPrevious();
     void slotNext();
     void slotTabCurrentChanged(int c);
-    void itemClicked(const QModelIndex &index);
+    void slotItemClicked(const QModelIndex &index);
+    void slotSave();
 
 private:
     SchemePlanManager::SchemeProcessInfo m_process;
 
+    QMap<int, QList<QStandardItemModel *>> m_models;
+
+    QXlsx::Document *m_export;
+
+    ProjectInfo *m_proj = nullptr;
+    QFUser *m_user;
+
     int m_currentPage = 0;
 
     CMind *m_mind1 = nullptr;
@@ -83,9 +102,11 @@ private:
     QStringList m_hNodes;
     QStringList m_vNodes;
 
-    QVector<qreal> m_values;
+    QVector<NodeMatrixInfo *> m_values;
 
     EXDataTableComboDelegate *m_comboDelegate;
+
+    PushButton *m_save = nullptr;
 };
 
 #endif  // EXDATATABLEVIEW_H

+ 20 - 0
ExpertClient/EXDataView.cpp

@@ -5,6 +5,7 @@
 #include "dbService/SchemeProcessService.h"
 #include "dbService/ClassSet.h"
 #include "dbService/CNodeDataService.h"
+#include "dbService/NodeMatrixService.h"
 
 #include <CNode.h>
 
@@ -97,6 +98,7 @@ void EXDataView::setupTabWidget()
                 }
 
                 EXDataTableView *table = new EXDataTableView(process, this);
+                table->setProjectInfo(m_proj);
                 table->mind1()->setNodeList(nodeListMap[i]);
                 if (i == ProjectManager::TechIndex) {
                     table->mind2()->setNodeList(nodeListMap[ProjectManager::AbilityIndex]);
@@ -111,3 +113,21 @@ void EXDataView::setupTabWidget()
 }
 
 void EXDataView::slotTabCurrentChanged(int index) { }
+
+void EXDataView::slotExportData()
+{
+    EXDataTableView *table = dynamic_cast<EXDataTableView *>(m_tab->currentWidget());
+    if (table == nullptr) {
+        return;
+    }
+
+    table->exportData();
+
+    SchemePlanManager::SchemeProcessInfo process = table->process();
+    qDebug() << __FUNCTION__ << __LINE__
+             << ProjectManager::nameOfIndexType((ProjectManager::IndexType)process.indexType) << endl;
+
+    QList<NodeMatrixInfo *> values;
+    NodeMatrixService().QueryNodeMatrixListByExpertIdAndEngineerId2(&values, 62, 110,
+                                                                    QString("%1").arg(process.indexType));
+}

+ 3 - 1
ExpertClient/EXDataView.h

@@ -23,9 +23,11 @@ public:
 private:
     void setupTabWidget();
 
-private slots:
+public slots:
     void slotTabCurrentChanged(int index);
 
+    void slotExportData();
+
 signals:
 
 private:

+ 41 - 6
ExpertClient/EXDataViewDelegate.cpp

@@ -7,6 +7,8 @@
 #include <QDebug>
 
 #include <QComboBox>
+#include <QSettings>
+#include <QMessageBox>
 
 SchemeBar::SchemeBar(const QString &lLabel, const QString &rLabel, const QStringList &vlist, QWidget *parent)
     : QDialog(parent), leftLabel(lLabel), rightLabel(rLabel), barValueList(vlist)
@@ -48,15 +50,44 @@ void SchemeBar::barClicked(QAbstractButton *btn)
     this->close();
 }
 
-EXDataTableComboDelegate::EXDataTableComboDelegate(QObject *parent) : QStyledItemDelegate(parent) { }
+EXDataTableComboDelegate::EXDataTableComboDelegate(QObject *parent) : QStyledItemDelegate(parent)
+{
+    QSettings config("config.ini", QSettings::IniFormat);
+    config.setIniCodec("UTF-8");
+    QStringList techMessaureValues = config.value("USERCONFIG/TechMessaureConfig", {}).toStringList();
+    bool empty                     = true;
+
+    if (!techMessaureValues.isEmpty()) {
+        bool ok = false;
+        for (auto &v : techMessaureValues) {
+            v.toInt(&ok);
+            if (!ok) {
+                empty = true;
+                break;
+            } else {
+                empty = false;
+            }
+        }
+    }
+    if (empty) {
+        QMessageBox::warning(nullptr, "配置数据无效", "技术措施重要度输入参数配置无效,恢复默认值");
+        m_items << "9"
+                << "7"
+                << "5"
+                << "3"
+                << "0"
+                << "-3"
+                << "-5";
+    } else {
+        m_items = techMessaureValues;
+    }
+}
 
 QWidget *EXDataTableComboDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */,
                                                 const QModelIndex & /* index */) const
 {
     QComboBox *w = new QComboBox(parent);
-
-    w->addItems({ "9", "5", "4", "3", "1" });
-
+    w->addItems(m_items);
     return w;
 }
 
@@ -69,8 +100,12 @@ void EXDataTableComboDelegate::setEditorData(QWidget *editor, const QModelIndex
 
 void EXDataTableComboDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
 {
-    QComboBox *spinBox = static_cast<QComboBox *>(editor);
-    QString value      = spinBox->currentText();
+    QComboBox *comboBox = static_cast<QComboBox *>(editor);
+    QString value       = comboBox->currentText();
+    if (!m_items.contains(value)) {
+        QMessageBox::warning(nullptr, "输入无效", "只可填写9、7、5、3、0、-3、-5");
+        value = "0";
+    }
     model->setData(index, value, Qt::EditRole);
 }
 

+ 3 - 0
ExpertClient/EXDataViewDelegate.h

@@ -36,6 +36,9 @@ public:
 
     void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
                               const QModelIndex &index) const override;
+
+private:
+    QStringList m_items;
 };
 
 #endif  // EXDATAVIEWDELEGATE_H

+ 0 - 13
ExpertClient/EXIndexView.cpp

@@ -35,18 +35,5 @@ void EXIndexView::setupTabWidget()
         if (ret) {
             m->setNodeList(list);
         }
-
-        CMind *mind = m->mind();
-        for (int i = 1; i < mind->levels(); i++) {
-            QList<CNodeData> nodes = mind->nodesInLevel(i);
-            for (CNodeData node : nodes) {
-                qDebug() << __FUNCTION__ << __LINE__ << "第" << i << "级节点" << node.name << endl;
-                qDebug() << __FUNCTION__ << __LINE__ << "子节点:" << endl;
-                QList<CNodeData> list = mind->subNodes(node);
-                for (CNodeData subNode : list) {
-                    qDebug() << __FUNCTION__ << __LINE__ << subNode.name << endl;
-                }
-            }
-        }
     }
 }

+ 8 - 0
ExpertClient/EXProjectView.cpp

@@ -6,6 +6,7 @@
 #include "ProjectManager.h"
 
 #include <dbService/ClassSet.h>
+#include <common/QFDIcon.h>
 
 #include <Widgets/Button.h>
 #include <Widgets/LineEdit.h>
@@ -14,6 +15,7 @@
 #include <QBoxLayout>
 #include <QLabel>
 #include <QStackedWidget>
+#include <QPushButton>
 
 #include <QDebug>
 
@@ -92,6 +94,9 @@ void EXProjectView::initWidgets()
 
     m_stack->addWidget(m_indexSystem);
     m_stack->addWidget(m_dataCollection);
+
+    m_export = new PushButton("导出", this);
+    m_user   = new PushButton("user");
 }
 
 void EXProjectView::initLayout()
@@ -105,6 +110,8 @@ void EXProjectView::initLayout()
     m_headerLayout->addWidget(m_title);
     m_headerLayout->addSpacing(20);
     m_headerLayout->addStretch();
+    m_headerLayout->addWidget(m_export);
+    m_headerLayout->addWidget(m_user);
 
     m_contentLayout->addWidget(m_tree);
     m_contentLayout->addWidget(m_seperator);
@@ -114,6 +121,7 @@ void EXProjectView::initLayout()
 void EXProjectView::connectSigalsAndSlots()
 {
     connect(m_tree, &TreeWidget::itemClicked, this, &EXProjectView::itemClicked);
+    connect(m_export, &PushButton::clicked, m_dataCollection, &EXDataView::slotExportData);
 }
 
 void EXProjectView::itemClicked(QTreeWidgetItem *item, int column)

+ 4 - 1
ExpertClient/EXProjectView.h

@@ -8,7 +8,7 @@ class ProjectInfo;
 class EXIndexView;
 class EXDataView;
 
-class PushButton;
+class QPushButton;
 class TreeWidget;
 
 class QVBoxLayout;
@@ -52,6 +52,9 @@ private:
     QStackedWidget *m_stack      = nullptr;
     EXIndexView *m_indexSystem   = nullptr;
     EXDataView *m_dataCollection = nullptr;
+
+    QPushButton *m_export = nullptr;
+    QPushButton *m_user   = nullptr;
 };
 
 #endif  // EXPROJECTVIEW_H

+ 15 - 2
ExpertClient/MainWindow.cpp

@@ -5,6 +5,8 @@
 
 #include <dbService/ClassSet.h>
 #include <dbService/ProjectService.h>
+#include <dbService/UserConfigService.h>
+#include <dbService/UserService.h>
 
 #include <QDebug>
 
@@ -13,12 +15,23 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
     ui->setupUi(this);
     setWindowTitle("");
 
+    int projId = 110;
+
+    QList<UserConfig *> cfgList;
+    bool ret = UserConfigService().QueryUserConfigListInfoByEngineerId(&cfgList, projId);
+    if (!ret) {
+        return;
+    }
     ProjectInfo *proj = new ProjectInfo();
-    ProjectService().QueryProjectById(proj, 110);
-    if (proj->id < 0) {
+    ret               = ProjectService().QueryProjectById(proj, 110);
+    if (!ret) {
         return;
     }
 
+    for (UserConfig *cfg : cfgList) {
+        qDebug() << __FUNCTION__ << __LINE__ << cfg->userId << cfg->userName << endl;
+    }
+
     EXProjectView *projView = new EXProjectView(proj, this);
     setCentralWidget(projView);
 }

+ 1 - 8
QFD/dbService/dbService.pri

@@ -14,6 +14,7 @@ HEADERS += \
     $$PWD/ReturnMessage.h \    \
     $$PWD/ScaleInfoService.h \
     $$PWD/SchemeInfoService.h
+
     $$PWD/SchemeProcessService.h \
     $$PWD/SqlDBHelper.h \
     $$PWD/UserConfigService.h \
@@ -39,11 +40,3 @@ SOURCES += \
     $$PWD/SqlDBHelper.cpp \
     $$PWD/UserConfigService.cpp \
     $$PWD/UserService.cpp
-
-#contains(DEFINES, QFD2_APP) {
-#HEADERS += \
-#    $$PWD/SchemeProcessService.h \
-
-#SOURCES += \
-#    $$PWD/SchemeProcessService.cpp \
-#}

+ 1 - 0
QFD/widgets/ConfigExpertDataWidget.cpp

@@ -301,6 +301,7 @@ void ConfigListItemWidget::initWidget()
 {
     m_name   = new QLabel(this);
     m_weight = new QSpinBox(this);
+    m_weight->setPrefix("权重");
     m_weight->setSuffix("%");
     m_weight->setMaximum(100);
     m_weight->setMinimum(0);