chengxr 1 rok pred
rodič
commit
2ed897398c

+ 11 - 0
QFD/dbService/ClassSet.h

@@ -435,4 +435,15 @@ public:
     QString createTime;    // 创建时间
 };
 
+class MindWeightInfo
+{
+public:
+    int id = -1;     // 主键 id
+    int projectId;   // 项目 id
+    int indexType;   // 指标体系类型: 能力重要度评估/技术重要度评估/方案优选评估/效能评估
+    int dataSource;  // 数据来源: 导入专家数据/录入实测数据
+    int algorithm;   // 权重分析使用的算法
+    QString weight;  // 指标权重值. 格式 指标名称1:权重;指标名称2:权重;指标名称3:权重
+};
+
 #endif  // CLASSSET_H

+ 103 - 0
QFD/dbService/MindWeightService.cpp

@@ -0,0 +1,103 @@
+#include "MindWeightService.h"
+
+#include "ClassSet.h"
+
+#include "SqlDBHelper.h"
+
+#include <QDebug>
+
+MindWeightService::MindWeightService(QObject *parent) : QObject(parent) { }
+
+bool MindWeightService::saveUniqueWeightData(int projId, int indexType, int dataSource, int algorithm,
+                                             const QString &weight)
+{
+    MindWeightInfo info;
+    bool qRet = queryWeightData(&info, projId, indexType, dataSource, algorithm);
+    if (qRet == false) {
+        return false;
+    }
+
+    if (info.id < 0) {
+        info.projectId  = projId;
+        info.indexType  = indexType;
+        info.dataSource = dataSource;
+        info.algorithm  = algorithm;
+        info.weight     = weight;
+        return saveWeightData(&info);
+    } else {
+        return updateWeightData(info.id, weight);
+    }
+}
+
+bool MindWeightService::queryWeightData(MindWeightInfo *info, int projId, int indexType, int dataSource, int algorithm)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        QString selectSql = QString("SELECT id, project_id, index_type, data_source, algorithm, weight "
+                                    "from t_mind_weight WHERE project_id = %1 and index_type = %2 and "
+                                    "data_source = %3 and algorithm = %4")
+                                    .arg(projId)
+                                    .arg(indexType)
+                                    .arg(dataSource)
+                                    .arg(algorithm);
+        QueryResult queryResult = t.execQuery(selectSql);
+        if (queryResult.next()) {
+            info->id         = queryResult.value(0).toInt();
+            info->projectId  = queryResult.value(1).toInt();
+            info->indexType  = queryResult.value(2).toInt();
+            info->dataSource = queryResult.value(3).toDouble();
+            info->algorithm  = queryResult.value(4).toString();
+            info->weight     = queryResult.value(5).toString();
+        }
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+bool MindWeightService::updateWeightData(int id, const QString &weight)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        t.update("t_mind_weight").set("weight", weight).where("id = ?", id);
+        t.commit();
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+bool MindWeightService::deleteWeightData(int id)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        t.deleteFrom("t_mind_weight").where("id = ?", id);
+        t.commit();
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+bool MindWeightService::saveWeightData(MindWeightInfo *info)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        InsertQuery q = t.insertInto("t_mind_weight (project_id,index_type,data_source,algorithm,weight)");
+        NonQueryResult result =
+                q.values(info->projectId, info->indexType, info->dataSource, info->algorithm, info->weight).exec();
+        t.commit();
+        info->id = result.lastInsertId().toInt();
+        ret      = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}

+ 43 - 0
QFD/dbService/MindWeightService.h

@@ -0,0 +1,43 @@
+#ifndef MINDWEIGHTSERVICE_H
+#define MINDWEIGHTSERVICE_H
+
+#include <QObject>
+
+class MindWeightInfo;
+
+class MindWeightService : public QObject
+{
+    Q_OBJECT
+public:
+    explicit MindWeightService(QObject *parent = nullptr);
+
+    /// 保存权重数据
+    /// 保存前先查询数据是否已存在, 是则更新数据
+    /// 数据的唯一性由项目id,指标体系类型,数据来源,算法共同确定
+    bool saveUniqueWeightData(int projId, int indexType, int dataSource, int algorithm, const QString &weight);
+
+    ///
+    /// \brief queryWeightData 查询权重数据
+    /// \param info 存储权重数据
+    /// \param projId 项目 id
+    /// \param indexType 指标体系类型
+    /// \param dataSource 数据来源
+    /// \param algorithm 算法
+    /// \return 成功 or 失败
+    bool queryWeightData(MindWeightInfo *info, int projId, int indexType, int dataSource, int algorithm);
+
+    ///
+    /// \brief updateWeightData 更新权重数据
+    /// \param id 主键
+    /// \param weight 权重
+    /// \return 成功 or 失败
+    bool updateWeightData(int id, const QString &weight);
+
+private:
+    /// 保存权重数据
+    bool saveWeightData(MindWeightInfo *info);
+
+signals:
+};
+
+#endif  // MINDWEIGHTSERVICE_H

+ 2 - 0
QFD/dbService/dbService.pri

@@ -9,6 +9,7 @@ HEADERS += \
     $$PWD/EngineerService.h \
     $$PWD/GradeIndexInfoService.h \
     $$PWD/GradeInfoService.h \
+    $$PWD/MindWeightService.h \
     $$PWD/NodeMatrixService.h \
     $$PWD/ProjectAlgorithmRelationService.h \
     $$PWD/ProjectMindRelationService.h \
@@ -32,6 +33,7 @@ SOURCES += \
     $$PWD/EngineerService.cpp \
     $$PWD/GradeIndexInfoService.cpp \
     $$PWD/GradeInfoService.cpp \
+    $$PWD/MindWeightService.cpp \
     $$PWD/NodeMatrixService.cpp \
     $$PWD/ProjectAlgorithmRelationService.cpp \
     $$PWD/ProjectMindRelationService.cpp \

+ 1 - 1
QFD/shemeFlow/FlowGraphNodeWidget.cpp

@@ -126,7 +126,7 @@ bool FlowGraphCommonNodeWidget::isTitleHidden() const
 
 void FlowGraphCommonNodeWidget::initWidget()
 {
-    setFixedWidth(240);
+    setFixedWidth(300);
 
     m_label     = new QLabel();
     m_algCombo  = new QComboBox();

+ 9 - 7
QFD/widgets/DataTableWidget.cpp

@@ -664,22 +664,24 @@ void DataTableWidget::itemChanged(QStandardItem *item)
     }
 
     if (schemeData) {
-        int index = item->column() - m_schemeStartIndex;
-        if (index < 0 || index >= m_schemeList.size()) {
+        int schemeIndex = item->column() - m_schemeStartIndex;
+        if (schemeIndex < 0 || schemeIndex >= m_schemeList.size()) {
             return;
         }
-        SchemaEval *scheme = m_schemeList[index];
+        SchemaEval *scheme = m_schemeList[schemeIndex];
 
-        QStringList valueStr;
+        QStringList valueList;
         for (int i = 0; i < item->model()->rowCount(); i++) {
             QStandardItem *vHeader = item->model()->verticalHeaderItem(i);
+            QString indexName      = vHeader->text();
+            QString valueStr       = "";
             QStandardItem *t       = item->model()->item(i, item->column());
             if (t != nullptr && t->text().trimmed().length() > 0) {
-                QString value = QString("%1:%2").arg(vHeader->text()).arg(t->text());
-                valueStr.append(value);
+                valueStr = t->text();
             }
+            valueList.append(QString("%1:%2").arg(indexName).arg(valueStr));
         }
-        scheme->valueStr = valueStr.join(";");
+        scheme->valueStr = valueList.join(";");
         SchemeInfoService().UpdateValueStrById(scheme->id, scheme->valueStr);
     }
 }