Forráskód Böngészése

物元配置完成

Signed-off-by: codeClown <zhaomengshou@126.com>
codeClown 1 éve
szülő
commit
8fcda1f7c6

+ 119 - 117
QFD/dbService/ClassSet.h

@@ -45,19 +45,19 @@ class NodeMatrixInfo
 {
 public:
     int id = -1;
-    QString expertName;   //专家名称
-    QString expertId;     //专家id
-    int engineerId;       //工程id
-    int mindId;           //脑图名称, 区分数据来源
-    QString node;         //节点
-    QString abscissa;     //横坐标
-    QString ordinate;     //纵坐标
-    QString nodeValue;    //节点值
-    QDateTime writeDate;  //填写时间
-    QString mark;         //页码
+    QString expertName;   // 专家名称
+    QString expertId;     // 专家id
+    int engineerId;       // 工程id
+    int mindId;           // 脑图名称, 区分数据来源
+    QString node;         // 节点
+    QString abscissa;     // 横坐标
+    QString ordinate;     // 纵坐标
+    QString nodeValue;    // 节点值
+    QDateTime writeDate;  // 填写时间
+    QString mark;         // 页码
     QString tableMsg;
     int tabIndex;     // tab索引
-    QString strUuid;  //区分组
+    QString strUuid;  // 区分组
 };
 
 class ClassSet
@@ -105,13 +105,13 @@ public:
     static QString nameOfEvalType(EvalType t);
     static QList<IndexType> indexListOfEvalFlags(EvalTypes flags);
 
-    int engineerId = -1;         //工程id
-    QString engineerName;        //工程名称
-    int indexSetId        = -1;  //指标体系id
-    int measureFunctionId = -1;  //测量方法id
-    int schemaEvalId      = -1;  //方案评估id
-    QString remark;              //备注
-    QString effectNameStr;       //生效列(逗号分割)
+    int engineerId = -1;         // 工程id
+    QString engineerName;        // 工程名称
+    int indexSetId        = -1;  // 指标体系id
+    int measureFunctionId = -1;  // 测量方法id
+    int schemaEvalId      = -1;  // 方案评估id
+    QString remark;              // 备注
+    QString effectNameStr;       // 生效列(逗号分割)
 
     EvalTypes evalFlags() const;
     QList<IndexType> indexList() const;
@@ -138,18 +138,18 @@ public:
     static QString nameOfRole(Role role);
 
     int id = -1;              // id
-    QString userName;         //用户名称
-    QString userNo;           //用户账号
-    QString password;         //用户密码
-    Role role;                //角色 0-超级管理员,1-普通管理员,2-专家
-    QString post;             //职务
-    QString major;            //专业
-    QString workPosition;     //工作单位
-    QString educationDegree;  //文化程度
-    QString phone;            //联系方式
-    QString remark;           //注释信息
-    QString projectId;        //工程编号
-    QString writeTime;        //填写时间
+    QString userName;         // 用户名称
+    QString userNo;           // 用户账号
+    QString password;         // 用户密码
+    Role role;                // 角色 0-超级管理员,1-普通管理员,2-专家
+    QString post;             // 职务
+    QString major;            // 专业
+    QString workPosition;     // 工作单位
+    QString educationDegree;  // 文化程度
+    QString phone;            // 联系方式
+    QString remark;           // 注释信息
+    QString projectId;        // 工程编号
+    QString writeTime;        // 填写时间
 
     QFUser();
 
@@ -181,9 +181,9 @@ class PlanInfo
 {
 public:
     int id = -1;       // id
-    QString planName;  //方案名称
-    int engineerId;    //关联工程id
-    QString desc;      //方案描述
+    QString planName;  // 方案名称
+    int engineerId;    // 关联工程id
+    QString desc;      // 方案描述
 };
 
 /**
@@ -196,9 +196,9 @@ class IndexSetPlanInfo
 {
 public:
     int id = -1;     // id
-    int indexSetId;  //指标体系id
-    int planId;      //方案id
-    double weight;   //权重值
+    int indexSetId;  // 指标体系id
+    int planId;      // 方案id
+    double weight;   // 权重值
 };
 
 /**
@@ -213,12 +213,12 @@ public:
     int id = -1;        // id
     int engineerId;     // 工程id
     QString expertId;   // 专家id
-    QString nodeName;   //节点名称
-    double nodeValue;   //需求重要度
-    double nodeWeight;  //权重值
-    int tableIndex;     //表格索引
-    int isValid;        //是否有效
-    int pageIndex;      //页码
+    QString nodeName;   // 节点名称
+    double nodeValue;   // 需求重要度
+    double nodeWeight;  // 权重值
+    int tableIndex;     // 表格索引
+    int isValid;        // 是否有效
+    int pageIndex;      // 页码
     QString tableMsg;
 };
 
@@ -234,11 +234,11 @@ public:
     int id = -1;       // id
     int engineerId;    // 工程id
     QString name;      // 专家id
-    QString remark;    //节点名称
-    QString valueStr;  //指标得分
-    double score;      //得分
-    QString filePath;  //图片地址
-    int type;          //类型0方案1综合效能
+    QString remark;    // 节点名称
+    QString valueStr;  // 指标得分
+    double score;      // 得分
+    QString filePath;  // 图片地址
+    int type;          // 类型0方案1综合效能
 };
 
 /**
@@ -253,8 +253,8 @@ public:
     int id = -1;       // id
     int engineerId;    // 工程id
     int expertId;      // 专家id
-    QString nodeName;  //节点名称
-    double nodeValue;  //技术重要度
+    QString nodeName;  // 节点名称
+    double nodeValue;  // 技术重要度
 };
 
 /**
@@ -264,13 +264,13 @@ class UserConfig
 {
 public:
     int id = -1;
-    int userId;        //用户id
-    QString userName;  //用户名称
-    int engineerId;    //工程id
-    double weight;     //工程权重
+    int userId;        // 用户id
+    QString userName;  // 用户名称
+    int engineerId;    // 工程id
+    double weight;     // 工程权重
     int isValid = 1;
-    QString createTime;  //创建时间
-    QString updateTime;  //更新时间
+    QString createTime;  // 创建时间
+    QString updateTime;  // 更新时间
 };
 
 /**
@@ -282,21 +282,21 @@ public:
 class ProjectInfo
 {
 public:
-    int id = -1;                //项目id
-    QString projectName;        //项目名称
-                                //    int demandMindId    = -1;   //需求分享评估脑图ID
-                                //    int programmeMindId = -1;   //方案优选评估脑图ID
-                                //    int generalMindId   = -1;   //综合效能评估脑图ID
-    QString remark;             //备注
-    QString taskName;           //任务名称
-    QString estimateTime;       //评估时间
-    QString estimateObjective;  //评估目的
-    QString estimateDept;       //评估单位
-    QString estimatePerson;     //评估人员
-    QString estimateType;       //评估类型
-    QString positionalTitles;   //职务
-    QString createTime;         //创建时间
-    QString updateTime;         //更新时间
+    int id = -1;                // 项目id
+    QString projectName;        // 项目名称
+                                //     int demandMindId    = -1;   //需求分享评估脑图ID
+                                //     int programmeMindId = -1;   //方案优选评估脑图ID
+                                //     int generalMindId   = -1;   //综合效能评估脑图ID
+    QString remark;             // 备注
+    QString taskName;           // 任务名称
+    QString estimateTime;       // 评估时间
+    QString estimateObjective;  // 评估目的
+    QString estimateDept;       // 评估单位
+    QString estimatePerson;     // 评估人员
+    QString estimateType;       // 评估类型
+    QString positionalTitles;   // 职务
+    QString createTime;         // 创建时间
+    QString updateTime;         // 更新时间
 };
 
 /**
@@ -308,14 +308,14 @@ public:
 class AlgorithmInfo
 {
 public:
-    int id = -1;         //主键id
-    QString code;        //算法编码
-    QString name;        //算法名称
-    QString desc;        //算法描述
-    int type;            //算法类型
-    int status = 1;      //状态0不可用1可用
-    QString createTime;  //创建时间
-    QString updateTime;  //更新时间
+    int id = -1;         // 主键id
+    QString code;        // 算法编码
+    QString name;        // 算法名称
+    QString desc;        // 算法描述
+    int type;            // 算法类型
+    int status = 1;      // 状态0不可用1可用
+    QString createTime;  // 创建时间
+    QString updateTime;  // 更新时间
 };
 
 /**
@@ -327,13 +327,13 @@ public:
 class ProjectAlgorithmRelation
 {
 public:
-    int id = -1;         //主键id
-    QString code;        //算法编码
-    int projectId;       //工程id
-    int type;            //评估类型
-    int status = 1;      //状态0不可用1可用
-    QString createTime;  //创建时间
-    QString updateTime;  //更新时间
+    int id = -1;         // 主键id
+    QString code;        // 算法编码
+    int projectId;       // 工程id
+    int type;            // 评估类型
+    int status = 1;      // 状态0不可用1可用
+    QString createTime;  // 创建时间
+    QString updateTime;  // 更新时间
 };
 
 /**
@@ -345,12 +345,12 @@ public:
 class ProjectMindRelation
 {
 public:
-    int id = -1;         //主键id
-    int mindId;          //脑图ID
-    int projectId;       //工程id
-    int type;            //评估类型
-    QString createTime;  //创建时间
-    QString updateTime;  //更新时间
+    int id = -1;         // 主键id
+    int mindId;          // 脑图ID
+    int projectId;       // 工程id
+    int type;            // 评估类型
+    QString createTime;  // 创建时间
+    QString updateTime;  // 更新时间
 };
 
 /**
@@ -362,10 +362,10 @@ public:
 class ScaleInfo
 {
 public:
-    int id = -1;         //主键id
-    int projectId;       //工程id
-    QString scaleName;   //标度名称
-    QString scaleValue;  //标度值
+    int id = -1;         // 主键id
+    int projectId;       // 工程id
+    QString scaleName;   // 标度名称
+    QString scaleValue;  // 标度值
 };
 
 /**
@@ -377,11 +377,11 @@ public:
 class GradeInfo
 {
 public:
-    int id = -1;         //主键id
-    int projectId;       //工程id
-    int type;            //类型0物元分析法1灰色聚类法
-    QString gradeName;   //等级名称
-    QString gradeValue;  //等级值
+    int id = -1;         // 主键id
+    int projectId;       // 工程id
+    int type;            // 类型0物元分析法1灰色聚类法
+    QString gradeName;   // 等级名称
+    QString gradeValue;  // 等级值
 };
 /**
  * @projectName   QFD2
@@ -392,10 +392,12 @@ public:
 class GradeIndexInfo
 {
 public:
-    int id = -1;              //主键id
-    int projectId;            //工程id
-    QString gradeIndexName;   //等级指标名称
-    QString gradeIndexValue;  //等级指标值
+    int id = -1;              // 主键id
+    int projectId;            // 工程id
+    int gradeLevel;           // 指标层级
+    QString gradeParentName;  // 等级指标父名称
+    QString gradeIndexName;   // 等级指标名称
+    QString gradeIndexValue;  // 等级指标值
 };
 
 /**
@@ -407,13 +409,13 @@ public:
 class EffectIndexInfo
 {
 public:
-    int id = -1;               //主键id
-    int projectId;             //工程id
-    QString effectIndexName;   //效能指标名称
-    QString effectIndexValue;  //效能指标值
-    QString effectIndexUnit;   //单位
-    QString extendLeft;        //延拓左
-    QString extendRight;       //延拓右
+    int id = -1;               // 主键id
+    int projectId;             // 工程id
+    QString effectIndexName;   // 效能指标名称
+    QString effectIndexValue;  // 效能指标值
+    QString effectIndexUnit;   // 单位
+    QString extendLeft;        // 延拓左
+    QString extendRight;       // 延拓右
 };
 
 /**
@@ -425,12 +427,12 @@ public:
 class EffectResult
 {
 public:
-    int id = -1;           //主键id
-    int projectId;         //工程id
-    QString effectOld;     //效能指标名称
-    QString effectNew;     //效能指标值
-    QString effectResult;  //结果
-    QString createTime;    //创建时间
+    int id = -1;           // 主键id
+    int projectId;         // 工程id
+    QString effectOld;     // 效能指标名称
+    QString effectNew;     // 效能指标值
+    QString effectResult;  // 结果
+    QString createTime;    // 创建时间
 };
 
 #endif  // CLASSSET_H

+ 18 - 9
QFD/dbService/GradeIndexInfoService.cpp

@@ -3,25 +3,30 @@
 #include <QDebug>
 GradeIndexInfoService::GradeIndexInfoService(QObject *parent) { }
 
-bool GradeIndexInfoService::QueryGradeIndexInfoByProjectId(GradeIndexInfo *gradeIndexInfo, int projectId)
+bool GradeIndexInfoService::QueryGradeIndexInfoByProjectId(QList<GradeIndexInfo *> *gradeIndexInfoList, int projectId)
 {
 
     QSqlDatabase db = SqlDBHelper::getDatabase();
     QSqlQuery query(db);
-    bool ret          = false;
-    QString selectSql = QString("SELECT id, project_id,grade_name,grade_value FROM "
-                                "t_grade_index_info WHERE project_id = %1")
-                                .arg(projectId);
+    bool ret = false;
+    QString selectSql =
+            QString("SELECT id, project_id,grade_index_name,grade_index_value,grade_parent_name,grade_level FROM "
+                    "t_grade_index_info WHERE project_id = %1")
+                    .arg(projectId);
     if (query.exec(selectSql)) {
-        if (query.next()) {
+        while (query.next()) {
             if (query.isNull(0) == false) {
+                GradeIndexInfo *gradeIndexInfo  = new GradeIndexInfo;
                 gradeIndexInfo->id              = query.value(0).toInt();
                 gradeIndexInfo->projectId       = query.value(1).toInt();
                 gradeIndexInfo->gradeIndexName  = query.value(2).toString();
                 gradeIndexInfo->gradeIndexValue = query.value(3).toString();
+                gradeIndexInfo->gradeParentName = query.value(4).toString();
+                gradeIndexInfo->gradeLevel      = query.value(5).toInt();
+                gradeIndexInfoList->append(gradeIndexInfo);
             }
-            ret = true;
         }
+        ret = true;
     } else {
         qDebug() << query.lastError();
     }
@@ -33,9 +38,11 @@ int GradeIndexInfoService::AddGradeIndexInfo(const GradeIndexInfo &gradeIndexInf
     int ret = -1;
     try {
         Transaction t(SqlDBHelper::getDatabase());
-        InsertQuery query = t.insertInto("t_grade_index_info(`project_id`, `grade_index_name`, `grade_index_value`)");
+        InsertQuery query = t.insertInto("t_grade_index_info(`project_id`, `grade_index_name`, `grade_index_value`, "
+                                         "`grade_parent_name`, `grade_level`)");
         NonQueryResult result =
-                query.values(gradeIndexInfo.projectId, gradeIndexInfo.gradeIndexName, gradeIndexInfo.gradeIndexValue)
+                query.values(gradeIndexInfo.projectId, gradeIndexInfo.gradeIndexName, gradeIndexInfo.gradeIndexValue,
+                             gradeIndexInfo.gradeParentName, gradeIndexInfo.gradeLevel)
                         .exec();
         t.commit();
         ret = result.lastInsertId().toInt();
@@ -54,6 +61,8 @@ bool GradeIndexInfoService::UpdateGradeIndexInfo(const GradeIndexInfo &gradeInde
         t.update("t_grade_index_info")
                 .set("grade_index_name", gradeIndexInfo.gradeIndexName)
                 .set("grade_index_value", gradeIndexInfo.gradeIndexValue)
+                .set("grade_parent_name", gradeIndexInfo.gradeParentName)
+                .set("grade_level", gradeIndexInfo.gradeLevel)
                 .where("id = ?", gradeIndexInfo.id);
         t.commit();
         ret = true;

+ 1 - 1
QFD/dbService/GradeIndexInfoService.h

@@ -8,7 +8,7 @@ public:
     GradeIndexInfoService(QObject *parent = nullptr);
     int AddGradeIndexInfo(const GradeIndexInfo &gradeIndexInfo);
     bool UpdateGradeIndexInfo(const GradeIndexInfo &gradeIndexInfo);
-    bool QueryGradeIndexInfoByProjectId(GradeIndexInfo *gradeIndexInfo, int projectId);
+    bool QueryGradeIndexInfoByProjectId(QList<GradeIndexInfo *> *gradeIndexInfoList, int projectId);
 };
 
 #endif  // GRADEINDEXINFOSERVICE_H

+ 7 - 4
QFD/dbService/GradeInfoService.cpp

@@ -27,6 +27,7 @@ bool GradeInfoService::UpdateGradeInfo(const GradeInfo &gradeInfo)
         t.update("t_grade_info")
                 .set("grade_name", gradeInfo.gradeName)
                 .set("grade_value", gradeInfo.gradeValue)
+                .set("type", gradeInfo.type)
                 .where("id = ?", gradeInfo.id);
         t.commit();
         ret = true;
@@ -36,26 +37,28 @@ bool GradeInfoService::UpdateGradeInfo(const GradeInfo &gradeInfo)
     return ret;
 }
 
-bool GradeInfoService::QueryGradeByProjectIdAndType(GradeInfo *gradeInfo, int projectId, int type)
+bool GradeInfoService::QueryGradeByProjectIdAndType(QList<GradeInfo *> *gradeInfoList, int projectId, int type)
 {
     QSqlDatabase db = SqlDBHelper::getDatabase();
     QSqlQuery query(db);
     bool ret          = false;
-    QString selectSql = QString("SELECT id, project_id,grade_name,grade_value FROM "
+    QString selectSql = QString("SELECT id, project_id,grade_name,grade_value,type FROM "
                                 "t_grade_info WHERE project_id = %1 and type = %2")
                                 .arg(projectId)
                                 .arg(type);
     if (query.exec(selectSql)) {
-        if (query.next()) {
+        while (query.next()) {
             if (query.isNull(0) == false) {
+                GradeInfo *gradeInfo  = new GradeInfo();
                 gradeInfo->id         = query.value(0).toInt();
                 gradeInfo->projectId  = query.value(1).toInt();
                 gradeInfo->gradeName  = query.value(2).toString();
                 gradeInfo->gradeValue = query.value(3).toString();
                 gradeInfo->type       = query.value(4).toInt();
+                gradeInfoList->append(gradeInfo);
             }
-            ret = true;
         }
+        ret = true;
     } else {
         qDebug() << query.lastError();
     }

+ 1 - 1
QFD/dbService/GradeInfoService.h

@@ -8,7 +8,7 @@ public:
     GradeInfoService(QObject *parent = nullptr);
     int AddGradeInfo(const GradeInfo &gradeInfo);
     bool UpdateGradeInfo(const GradeInfo &gradeInfo);
-    bool QueryGradeByProjectIdAndType(GradeInfo *gradeInfo, int projectId, int type);
+    bool QueryGradeByProjectIdAndType(QList<GradeInfo *> *gradeInfoList, int projectId, int type);
 };
 
 #endif  // GRADEINFOSERVICE_H

+ 7 - 3
QFD/dbService/ScaleInfoService.cpp

@@ -3,6 +3,7 @@
 #include <QDebug>
 
 ScaleInfoService::ScaleInfoService(QObject *parent) { }
+
 int ScaleInfoService::AddScaleInfo(const ScaleInfo &scaleInfo)
 {
     int ret = -1;
@@ -10,6 +11,7 @@ int ScaleInfoService::AddScaleInfo(const ScaleInfo &scaleInfo)
         Transaction t(SqlDBHelper::getDatabase());
         InsertQuery query     = t.insertInto("t_scale_info(`project_id`, `scale_name`, `scale_value`)");
         NonQueryResult result = query.values(scaleInfo.projectId, scaleInfo.scaleName, scaleInfo.scaleValue).exec();
+        qDebug() << result.lastQuery();
         t.commit();
         ret = result.lastInsertId().toInt();
     } catch (const DBException &ex) {
@@ -35,7 +37,7 @@ bool ScaleInfoService::UpdateScaleInfo(const ScaleInfo &scaleInfo)
     return ret;
 }
 
-bool ScaleInfoService::QueryScaleByProjectId(ScaleInfo *scaleInfo, int projectId)
+bool ScaleInfoService::QueryScaleByProjectId(QList<ScaleInfo *> *scaleInfoList, int projectId)
 {
     QSqlDatabase db = SqlDBHelper::getDatabase();
     QSqlQuery query(db);
@@ -44,15 +46,17 @@ bool ScaleInfoService::QueryScaleByProjectId(ScaleInfo *scaleInfo, int projectId
                                 "t_scale_info WHERE project_id = %1")
                                 .arg(projectId);
     if (query.exec(selectSql)) {
-        if (query.next()) {
+        while (query.next()) {
             if (query.isNull(0) == false) {
+                ScaleInfo *scaleInfo  = new ScaleInfo();
                 scaleInfo->id         = query.value(0).toInt();
                 scaleInfo->projectId  = query.value(1).toInt();
                 scaleInfo->scaleName  = query.value(2).toString();
                 scaleInfo->scaleValue = query.value(3).toString();
+                scaleInfoList->append(scaleInfo);
             }
-            ret = true;
         }
+        ret = true;
     } else {
         qDebug() << query.lastError();
     }

+ 1 - 1
QFD/dbService/ScaleInfoService.h

@@ -8,7 +8,7 @@ public:
     ScaleInfoService(QObject *parent = nullptr);
     int AddScaleInfo(const ScaleInfo &scaleInfo);
     bool UpdateScaleInfo(const ScaleInfo &scaleInfo);
-    bool QueryScaleByProjectId(ScaleInfo *scaleInfo, int projectId);
+    bool QueryScaleByProjectId(QList<ScaleInfo *> *scaleInfoList, int projectId);
 };
 
 #endif  // SCALEINFOSERVICE_H

+ 306 - 28
QFD/widgets/MatterElementConfigWidget.cpp

@@ -1,11 +1,17 @@
 #include "MatterElementConfigWidget.h"
 #include "MatterElementItemDelegate.h"
 #include "ui_MatterElementConfigWidget.h"
+#include "dbService/ScaleInfoService.h"
+#include "dbService/GradeInfoService.h"
+#include "dbService/GradeIndexInfoService.h"
 
 #include "CMind.h"
 
 #include <QLineEdit>
-// #include <QDebug>
+#include <QMessageBox>
+#include <QPushButton>
+
+#include <QDebug>
 
 MatterElementConfigWidget::MatterElementConfigWidget(CMind *mind, int domainLevel, QWidget *parent)
     : QWidget(parent), ui(new Ui::MatterElementConfigWidget), m_domainLevel(domainLevel), m_mind(mind)
@@ -34,6 +40,8 @@ void MatterElementConfigWidget::initScaleDivisionTable()
     t->setSelectionMode(QAbstractItemView::SingleSelection);
     t->verticalHeader()->hide();
 
+    int projectId = m_mind->root().projectId;
+
     m_scaleDivisionmodel = new QStandardItemModel;
     t->setModel(m_scaleDivisionmodel);
 
@@ -45,7 +53,32 @@ void MatterElementConfigWidget::initScaleDivisionTable()
 
     QStandardItem *s                  = nullptr;
     MatterElementItemSpinDelegate *sd = new MatterElementItemSpinDelegate(t);
-    const QStringList originValues    = { "1.0", "3.0", "5.0", "7.0", "9.0", "[2.0, 4.0, 6.0, 8.0]" };
+
+    QStringList originValues = { "1.0", "3.0", "5.0", "7.0", "9.0", "[2.0, 4.0, 6.0, 8.0]" };
+
+    QList<ScaleInfo *> scaleInfoList;
+    if (!ScaleInfoService().QueryScaleByProjectId(&scaleInfoList, projectId)) {
+        QMessageBox::warning(this, "警告", "数据库访问失败");
+    } else {
+        if (scaleInfoList.size() == 0) {
+            for (int num = 0; num < originValues.size(); ++num) {
+                ScaleInfo sinfo;
+                sinfo.projectId  = projectId;
+                sinfo.scaleName  = headers.at(num + 1);
+                sinfo.scaleValue = originValues.at(num);
+                if (!ScaleInfoService().AddScaleInfo(sinfo)) {
+                    QMessageBox::warning(this, "警告", "数据库访问失败");
+                }
+            }
+        } else {
+            for (const auto &si : scaleInfoList) {
+                int loc               = headers.indexOf(si->scaleName);
+                originValues[loc - 1] = si->scaleValue;
+            }
+        }
+    }
+    qDeleteAll(scaleInfoList);
+
     for (int i = 0; i < headers.size(); ++i) {
         if (i == 0) {
             s = new QStandardItem("标度");
@@ -66,7 +99,7 @@ void MatterElementConfigWidget::initScaleDivisionTable()
         }
     }
 
-    connect(ui->updateScaleBtn, &QPushButton::clicked, this, &MatterElementConfigWidget::onScaleValueUpdate);
+    connect(ui->updateScaleBtn, &QToolButton::clicked, this, &MatterElementConfigWidget::onScaleValueUpdate);
 }
 
 static void clearTab(QTabWidget *tabWidget)
@@ -83,14 +116,43 @@ void MatterElementConfigWidget::initDomainLevelLayout()
 {
     ui->levelLabel->setText(QString::number(m_domainLevel));
 
+    QList<GradeInfo *> gradeInfoList;
+    QMap<QString, QString> levelMaps;
+    int projectId = m_mind->root().projectId;
+    if (!GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, projectId, 0)) {
+        QMessageBox::warning(this, "警告", "数据库访问失败");
+    } else {
+        if (gradeInfoList.size() == 0) {
+            for (int lvl = 0; lvl < m_domainLevel; ++lvl) {
+                levelMaps.insert(QString("%1级:").arg(lvl + 1), QString("E%1").arg(lvl + 1));
+                GradeInfo ginfo;
+                ginfo.projectId  = projectId;
+                ginfo.gradeName  = QString("%1级").arg(lvl + 1);
+                ginfo.gradeValue = QString("E%1").arg(lvl + 1);
+                ginfo.type       = 0;
+                if (!GradeInfoService().AddGradeInfo(ginfo)) {
+                    QMessageBox::warning(this, "警告", "数据库访问失败");
+                }
+            }
+        } else {
+            for (const auto &gi : gradeInfoList) {
+                levelMaps.insert(gi->gradeName, gi->gradeValue);
+            }
+        }
+    }
+    qDeleteAll(gradeInfoList);
     QFormLayout *formLayout = new QFormLayout;
-    for (int l = 0; l < m_domainLevel; ++l) {
-        auto le = new QLineEdit(QString("E%1").arg(l + 1));
+
+    QMapIterator<QString, QString> iter(levelMaps);
+    while (iter.hasNext()) {
+        iter.next();
+        auto le = new QLineEdit(iter.value());
         le->setMinimumHeight(30);
         le->setMaximumWidth(80);
         m_levelEdits << le;
-        formLayout->addRow(QString("%1级:").arg(l + 1), le);
+        formLayout->addRow(iter.key() + ":", le);
     }
+
     auto levelSaveBtn = new QPushButton("保存");
     levelSaveBtn->setIcon(QIcon(":/qfluentwidgets/images/icons/Save_black.svg"));
     levelSaveBtn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
@@ -114,7 +176,9 @@ void MatterElementConfigWidget::initConfigItems()
         QVector<MEDomain> children;
         for (CNodeData sub : m_mind->subNodes(n)) {
             MEDomain d;
-            d.name = sub.name;
+            d.name        = sub.name;
+            d.leftValues  = QVector<double>(m_domainLevel + 1, 0);
+            d.rightValues = QVector<double>(m_domainLevel + 1, 0);
             children.append(d);
         }
         MEConfigItem i;
@@ -122,23 +186,77 @@ void MatterElementConfigWidget::initConfigItems()
         i.childs     = children;
         m_allConfigItems.append(i);
     }
+
+    QList<GradeIndexInfo *> gradeIndexInfoList;
+    int projectId = m_mind->root().projectId;
+    if (!GradeIndexInfoService().QueryGradeIndexInfoByProjectId(&gradeIndexInfoList, projectId)) {
+        QMessageBox::warning(this, "警告", "数据库访问失败");
+    } else {
+        if (gradeIndexInfoList.size() == 0) {
+            for (const auto &configItem : m_allConfigItems) {
+                for (int c = 0; c < configItem.childs.size(); ++c) {
+                    // 一个指标对应m_domainLevel+1个配置项
+                    for (int domain = 0; domain < m_domainLevel + 1; ++domain) {
+                        GradeIndexInfo gii;
+                        gii.projectId       = projectId;
+                        gii.gradeIndexName  = configItem.childs.at(c).name;
+                        gii.gradeParentName = configItem.parentName;
+                        gii.gradeLevel      = domain + 1;
+                        gii.gradeIndexValue = QString("(%1, %2)")
+                                                      .arg(configItem.childs.at(c).leftValues.at(domain))
+                                                      .arg(configItem.childs.at(c).rightValues.at(domain));
+                        if (!GradeIndexInfoService().AddGradeIndexInfo(gii)) {
+                            QMessageBox::warning(this, "警告", "数据库访问失败");
+                        }
+                    }
+                }
+            }
+        } else {
+            for (auto &configItem : m_allConfigItems) {
+                for (int c = 0; c < configItem.childs.size(); ++c) {
+                    bool found = false;
+                    for (auto gindex : gradeIndexInfoList) {
+                        for (int domain = 0; domain < m_domainLevel + 1; ++domain) {
+                            // 默认指标名具有唯一性
+                            if (gindex->gradeIndexName == configItem.childs[c].name
+                                && gindex->gradeLevel == domain + 1) {
+                                QStringList list = gindex->gradeIndexValue.mid(1, gindex->gradeIndexValue.size() - 2)
+                                                           .replace(" ", "")
+                                                           .split(",");
+                                configItem.childs[c].leftValues[domain]  = list.at(0).toDouble();
+                                configItem.childs[c].rightValues[domain] = list.at(1).toDouble();
+                                found                                    = true;
+                            }
+                        }
+                    }
+                    if (!found) {
+
+                        for (int domain = 0; domain < m_domainLevel + 1; ++domain) {
+                            GradeIndexInfo gii;
+                            gii.projectId       = projectId;
+                            gii.gradeIndexName  = configItem.childs[c].name;
+                            gii.gradeParentName = configItem.parentName;
+                            gii.gradeLevel      = domain + 1;
+                            gii.gradeIndexValue = QString("(%1, %2)")
+                                                          .arg(configItem.childs[c].leftValues.at(domain))
+                                                          .arg(configItem.childs[c].rightValues.at(domain));
+                            if (!GradeIndexInfoService().AddGradeIndexInfo(gii)) {
+                                QMessageBox::warning(this, "警告", "数据库访问失败");
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    qDeleteAll(gradeIndexInfoList);
 }
 
 void MatterElementConfigWidget::initDomainTable()
 {
     initDomainLevelLayout();
 
-    QStringList parentIndexs;
-    QHash<QString, QStringList> indexs;
-
-    for (const auto &item : m_allConfigItems) {
-        parentIndexs << item.parentName;
-        indexs.insert(item.parentName, {});
-        for (const auto &child : item.childs) {
-            indexs[item.parentName] << child.name;
-        }
-    }
-
     m_meRangeDelegate = new MatterElementItemRangeDelegate(this);
 
     const QStringList rangeItems = { "很差",     "较差",     "一般",     "较高",    "很高",
@@ -150,7 +268,7 @@ void MatterElementConfigWidget::initDomainTable()
 
     QStringList domainLevels = getDomainLevels();
 
-    for (int pindex = 0; pindex < parentIndexs.size(); ++pindex) {
+    for (int pindex = 0; pindex < m_allConfigItems.size(); ++pindex) {
         QTableView *table = new QTableView;
         table->setAlternatingRowColors(false);
         table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
@@ -166,14 +284,15 @@ void MatterElementConfigWidget::initDomainTable()
 
         table->setModel(tModel);
 
-        int indexNumber = indexs[parentIndexs.at(pindex)].size();
+        int indexNumber = m_allConfigItems.at(pindex).childs.size();
+        qDebug() << indexNumber;
 
-        tModel->setColumnCount(4 * domainLevels.size());
+        tModel->setColumnCount(4 * m_domainLevel);
         tModel->setRowCount(indexNumber);
 
-        for (int r = 0; r < domainLevels.size() + 1; ++r) {
+        for (int r = 0; r < m_domainLevel + 1; ++r) {
             QStandardItem *s = nullptr;
-            if (r < domainLevels.size()) {
+            if (r < m_domainLevel) {
                 s = new QStandardItem(QString("R%1").arg(r + 1));
             } else {
                 s = new QStandardItem("Rp");
@@ -181,7 +300,7 @@ void MatterElementConfigWidget::initDomainTable()
 
             s->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
             s->setTextAlignment(Qt::AlignCenter);
-            if (r < domainLevels.size()) {
+            if (r < m_domainLevel) {
                 s->setToolTip(QString("经典域R%1").arg(r + 1));
             } else {
                 s->setToolTip("节域p");
@@ -191,7 +310,7 @@ void MatterElementConfigWidget::initDomainTable()
             table->setColumnWidth(r * 4, 20);
             table->setSpan(0, r * 4, indexNumber, 1);
 
-            if (r < domainLevels.size()) {
+            if (r < m_domainLevel) {
                 s = new QStandardItem(domainLevels.at(r));
             } else {
                 s = new QStandardItem("节域p");
@@ -203,21 +322,27 @@ void MatterElementConfigWidget::initDomainTable()
             table->setSpan(0, r * 4 + 1, indexNumber, 1);
 
             for (int k = 0; k < indexNumber; ++k) {
-                s = new QStandardItem(indexs[parentIndexs.at(pindex)].value(k));
+                s = new QStandardItem(m_allConfigItems[pindex].childs[k].name);
                 s->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
                 s->setTextAlignment(Qt::AlignCenter);
                 tModel->setItem(k, r * 4 + 2, s);
 
                 s = new QStandardItem();
                 s->setTextAlignment(Qt::AlignCenter);
+                s->setText(QString("(%1, %2)")
+                                   .arg(m_allConfigItems[pindex].childs[k].leftValues[r])
+                                   .arg(m_allConfigItems[pindex].childs[k].rightValues[r]));
                 tModel->setItem(k, r * 4 + 3, s);
             }
 
             table->setItemDelegateForColumn(r * 4 + 3, m_meRangeDelegate);
         }
 
-        ui->tabWidget->addTab(table, parentIndexs.at(pindex));
+        ui->tabWidget->addTab(table, m_allConfigItems.at(pindex).parentName);
     }
+
+    connect(ui->cleanBtn, &QToolButton::clicked, this, &MatterElementConfigWidget::onClearBtnClick);
+    connect(ui->saveBtn, &QToolButton::clicked, this, &MatterElementConfigWidget::onSaveBtnClick);
 }
 
 QStringList MatterElementConfigWidget::getDomainLevels() const
@@ -262,17 +387,170 @@ void MatterElementConfigWidget::onLevelSaveBtnClick()
             model->item(0, c * 4 + 1)->setText(domainLevels.at(c));
         }
     }
+
+    // 更新数据库等级值
+    QList<GradeInfo *> gradeInfoList;
+    if (!GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, m_mind->root().projectId, 0)) {
+        QMessageBox::warning(this, "警告", "数据库访问失败");
+        return;
+    }
+
+    for (auto gi : gradeInfoList) {
+        int num = gi->gradeName.mid(0, gi->gradeName.size() - 1).toInt();
+        if (gi->gradeValue != domainLevels.at(num - 1)) {
+            gi->gradeValue = domainLevels.at(num - 1);
+            if (!GradeInfoService().UpdateGradeInfo(*gi)) {
+                QMessageBox::warning(this, "警告", "数据库访问失败");
+                return;
+            }
+        }
+    }
+
+    qDeleteAll(gradeInfoList);
 }
 
 void MatterElementConfigWidget::onScaleValueUpdate()
 {
-    ui->scaleDivisionTable->clearSelection();
+    ui->scaleDivisionTable->clearSelection();  // 清除表格选中
 
+    // 把值聚集起来
     QVector<double> rangeValues;
     auto scaleValues = getScaleValues();
     rangeValues << scaleValues.at(0) << scaleValues.at(1);
 
     m_meRangeDelegate->updateOriginValues(rangeValues);
+
+    // 更新数据库
+    QList<ScaleInfo *> scaleInfoList;
+    if (!ScaleInfoService().QueryScaleByProjectId(&scaleInfoList, m_mind->root().projectId)) {
+        QMessageBox::warning(this, "警告", "数据库访问失败");
+        return;
+    } else {
+        for (int c = 1; c < m_scaleDivisionmodel->columnCount(); ++c) {
+            QString header = m_scaleDivisionmodel->horizontalHeaderItem(c)->text();
+            QString value  = m_scaleDivisionmodel->item(0, c)->text();
+            for (auto si : scaleInfoList) {
+                if (si->scaleName == header && value != si->scaleValue) {
+                    si->scaleValue = value;
+                    if (!ScaleInfoService().UpdateScaleInfo(*si)) {
+                        QMessageBox::warning(this, "警告", "数据库访问失败");
+                    }
+                }
+            }
+        }
+    }
+    qDeleteAll(scaleInfoList);
+}
+
+void MatterElementConfigWidget::onClearBtnClick()
+{
+    for (auto &config : m_allConfigItems) {
+        for (auto &child : config.childs) {
+            for (int domain = 0; domain < m_domainLevel + 1; ++domain) {
+                child.leftValues[domain] = child.rightValues[domain] = 0;
+            }
+        }
+    }
+
+    for (int pindex = 0; pindex < m_allConfigItems.size(); ++pindex) {
+
+        QStandardItemModel *tModel = m_domainModels.at(pindex);
+
+        int indexNumber = m_allConfigItems.at(pindex).childs.size();
+        for (int r = 0; r < m_domainLevel + 1; ++r) {
+            for (int k = 0; k < indexNumber; ++k) {
+                tModel->item(k, r * 4 + 3)->setText("(0, 0)");
+            }
+        }
+    }
+}
+
+void MatterElementConfigWidget::onSaveBtnClick()
+{
+
+    for (int pindex = 0; pindex < m_allConfigItems.size(); ++pindex) {
+
+        QStandardItemModel *tModel = m_domainModels.at(pindex);
+
+        int indexNumber = m_allConfigItems.at(pindex).childs.size();
+        for (int r = 0; r < m_domainLevel + 1; ++r) {
+            for (int k = 0; k < indexNumber; ++k) {
+                QString txt      = tModel->item(k, r * 4 + 3)->text().trimmed();
+                QStringList list = txt.mid(1, txt.size() - 2).replace(" ", "").split(",");
+                m_allConfigItems[pindex].childs[k].leftValues[r]  = list.at(0).toDouble();
+                m_allConfigItems[pindex].childs[k].rightValues[r] = list.at(1).toDouble();
+                qDebug() << r << k << list;
+            }
+        }
+    }
+
+    QList<GradeIndexInfo *> gradeIndexInfoList;
+    int projectId = m_mind->root().projectId;
+    if (!GradeIndexInfoService().QueryGradeIndexInfoByProjectId(&gradeIndexInfoList, projectId)) {
+        QMessageBox::warning(this, "警告", "数据库访问失败");
+    } else {
+        if (gradeIndexInfoList.size() == 0) {  // 防止数据库被异步删除
+            for (const auto &configItem : m_allConfigItems) {
+                for (int c = 0; c < configItem.childs.size(); c++) {
+                    for (int domain = 0; domain < m_domainLevel + 1; ++domain) {
+                        GradeIndexInfo gii;
+                        gii.projectId       = projectId;
+                        gii.gradeIndexName  = configItem.childs[c].name;
+                        gii.gradeParentName = configItem.parentName;
+                        gii.gradeLevel      = domain + 1;
+                        gii.gradeIndexValue = QString("(%1, %2)")
+                                                      .arg(configItem.childs[c].leftValues.at(domain))
+                                                      .arg(configItem.childs[c].rightValues.at(domain));
+                        if (!GradeIndexInfoService().AddGradeIndexInfo(gii)) {
+                            QMessageBox::warning(this, "警告", "数据库访问失败");
+                        }
+                    }
+                }
+            }
+        } else {
+            for (const auto &configItem : m_allConfigItems) {
+                for (int c = 0; c < configItem.childs.size(); c++) {
+                    bool found = false;
+                    for (auto &gindex : gradeIndexInfoList) {
+                        for (int domain = 0; domain < m_domainLevel + 1; ++domain) {
+                            if ((gindex->gradeIndexName == configItem.childs[c].name)
+                                && (gindex->gradeLevel == domain + 1)) {
+                                if (gindex->gradeIndexValue
+                                    != QString("(%1, %2)")
+                                               .arg(configItem.childs[c].leftValues.at(domain))
+                                               .arg(configItem.childs[c].rightValues.at(domain))) {
+                                    gindex->gradeIndexValue = QString("(%1, %2)")
+                                                                      .arg(configItem.childs[c].leftValues.at(domain))
+                                                                      .arg(configItem.childs[c].rightValues.at(domain));
+                                    if (!GradeIndexInfoService().UpdateGradeIndexInfo(*gindex)) {
+                                        QMessageBox::warning(this, "警告", "数据库访问失败");
+                                    }
+                                }
+                                found = true;
+                            }
+                        }
+                    }
+                    if (!found) {
+                        for (int domain = 0; domain < m_domainLevel + 1; ++domain) {
+                            GradeIndexInfo gii;
+                            gii.projectId       = projectId;
+                            gii.gradeIndexName  = configItem.childs[c].name;
+                            gii.gradeParentName = configItem.parentName;
+                            gii.gradeLevel      = c + 1;
+                            gii.gradeIndexValue = QString("(%1, %2)")
+                                                          .arg(configItem.childs[c].leftValues.at(domain))
+                                                          .arg(configItem.childs[c].rightValues.at(domain));
+                            if (!GradeIndexInfoService().AddGradeIndexInfo(gii)) {
+                                QMessageBox::warning(this, "警告", "数据库访问失败");
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    qDeleteAll(gradeIndexInfoList);
 }
 
 QList<MEConfigItem> MatterElementConfigWidget::getAllConfigItems() const

+ 4 - 2
QFD/widgets/MatterElementConfigWidget.h

@@ -10,8 +10,8 @@ class CMind;
 struct MEDomain
 {
     QString name;
-    double leftValue;
-    double rightValue;
+    QVector<double> leftValues;   // 与阈值相关 size == m_domainLevel+1
+    QVector<double> rightValues;  // 与阈值相关 size == m_domainLevel+1
 };
 
 struct MEConfigItem
@@ -47,6 +47,8 @@ private:
 private slots:
     void onLevelSaveBtnClick();
     void onScaleValueUpdate();
+    void onClearBtnClick();
+    void onSaveBtnClick();
 
 private:
     Ui::MatterElementConfigWidget *ui;

+ 16 - 2
QFD/widgets/MatterElementConfigWidget.ui

@@ -137,17 +137,31 @@
          </spacer>
         </item>
         <item>
-         <widget class="QPushButton" name="cleanBtn">
+         <widget class="QToolButton" name="cleanBtn">
           <property name="text">
            <string> 清理</string>
           </property>
+          <property name="icon">
+           <iconset resource="../../QFluentWidgets/qfluentwidgets.qrc">
+            <normaloff>:/qfluentwidgets/images/color_dialog/Clear_black.svg</normaloff>:/qfluentwidgets/images/color_dialog/Clear_black.svg</iconset>
+          </property>
+          <property name="toolButtonStyle">
+           <enum>Qt::ToolButtonTextBesideIcon</enum>
+          </property>
          </widget>
         </item>
         <item>
-         <widget class="QPushButton" name="saveBtn">
+         <widget class="QToolButton" name="saveBtn">
           <property name="text">
            <string>保存</string>
           </property>
+          <property name="icon">
+           <iconset resource="../../QFluentWidgets/qfluentwidgets.qrc">
+            <normaloff>:/qfluentwidgets/images/icons/SaveAs_black.svg</normaloff>:/qfluentwidgets/images/icons/SaveAs_black.svg</iconset>
+          </property>
+          <property name="toolButtonStyle">
+           <enum>Qt::ToolButtonTextBesideIcon</enum>
+          </property>
          </widget>
         </item>
        </layout>

+ 1 - 0
QFD/widgets/MatterElementItemDelegate.h

@@ -25,6 +25,7 @@ public:
         layout->setSpacing(2);
         for (int i = 0; i < 4; ++i) {
             auto s = new QDoubleSpinBox;
+            s->setMaximumWidth(60);
             s->setFrame(false);
             s->setMinimum(-10000);
             s->setMaximum(10000);