Browse Source

'添加工程评估算法关联接口'

zsf 1 year ago
parent
commit
d51dc78f5c

+ 1 - 1
QFD/dbService/AlgorithmService.cpp

@@ -111,7 +111,7 @@ bool AlgorithmService::QueryAll(QList<AlgorithmInfo *> *infos)
     return ret;
 }
 
-bool AlgorithmService::deleteById(int id)
+bool AlgorithmService::DeleteById(int id)
 {
     bool ret = false;
     try {

+ 1 - 1
QFD/dbService/AlgorithmService.h

@@ -23,7 +23,7 @@ public:
     bool QueryAll(QList<AlgorithmInfo *> *infos);
 
     //根据id禁用
-    bool deleteById(int id);
+    bool DeleteById(int id);
 };
 
 #endif  // ALGORITHMSERVICE_H

+ 18 - 0
QFD/dbService/ClassSet.h

@@ -302,4 +302,22 @@ public:
     QString updateTime;  //更新时间
 };
 
+/**
+ * @projectName   QFD2
+ * @author        mimang
+ * @date          2023-09-15
+ * @desc          工程算法关联信息
+ */
+class ProjectAlgorithmRelation
+{
+public:
+    int id = -1;         //主键id
+    QString code;        //算法编码
+    int projectId;       //工程id
+    int type;            //评估类型
+    int status = 1;      //状态0不可用1可用
+    QString createTime;  //创建时间
+    QString updateTime;  //更新时间
+};
+
 #endif  // CLASSSET_H

+ 58 - 0
QFD/dbService/ProjectAlgorithmRelationService.cpp

@@ -0,0 +1,58 @@
+#include "ProjectAlgorithmRelationService.h"
+#include "SqlDBHelper.h"
+#include <QDebug>
+
+ProjectAlgorithmRelationService::ProjectAlgorithmRelationService(QObject *parent) { }
+
+bool ProjectAlgorithmRelationService::AddOrUpdateRelation(const ProjectAlgorithmRelation &relation)
+{
+    bool ret = false;
+    try {
+        QString nowDate = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
+        Transaction t(SqlDBHelper::getDatabase());
+        int id = relation.id;
+        if (id == -1) {
+            t.update("t_project_algorithm_ralation")
+                    .set("code", relation.code)
+                    .set("type", relation.type)
+                    .set("projectId", relation.projectId)
+                    .set("updateTime", nowDate)
+                    .where("id = ?", id);
+        } else {
+            InsertQuery query = t.insertInto(
+                    "t_project_algorithm_ralation( `code`, `project_id`, `type`, `status`, `create_time`)");
+
+            NonQueryResult result =
+                    query.values(relation.code, relation.projectId, relation.type, relation.status, nowDate).exec();
+        }
+        t.commit();
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+bool ProjectAlgorithmRelationService::QueryByProjectIdAndType(ProjectAlgorithmRelation *relation, int projectId,
+                                                              int type)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString("SELECT id, code,project_id,type FROM t_project_algorithm_ralation WHERE type = %1 and "
+                                "project_id = %2 and status=1")
+                                .arg(type)
+                                .arg(projectId);
+    if (query.exec(selectSql)) {
+        if (query.isNull(0) == false) {
+            relation->id        = query.value(0).toInt();
+            relation->code      = query.value(1).toString();
+            relation->projectId = query.value(0).toInt();
+            relation->type      = query.value(0).toInt();
+        }
+        ret = true;
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}

+ 17 - 0
QFD/dbService/ProjectAlgorithmRelationService.h

@@ -0,0 +1,17 @@
+#ifndef PROJECTALGORITHMRELATIONSERVICE_H
+#define PROJECTALGORITHMRELATIONSERVICE_H
+#include "ClassSet.h"
+
+class ProjectAlgorithmRelationService
+{
+public:
+    ProjectAlgorithmRelationService(QObject *parent = nullptr);
+
+    //新增或更新关联信息
+    bool AddOrUpdateRelation(const ProjectAlgorithmRelation &relation);
+
+    //根据工程id和类型查询数据
+    bool QueryByProjectIdAndType(ProjectAlgorithmRelation *relation, int projectId, int type);
+};
+
+#endif  // PROJECTALGORITHMRELATIONSERVICE_H

+ 2 - 0
QFD/dbService/dbService.pri

@@ -5,6 +5,7 @@ HEADERS += \
     $$PWD/DemandWeightService.h \
     $$PWD/EngineerService.h \
     $$PWD/NodeMatrixService.h \
+    $$PWD/ProjectAlgorithmRelationService.h \
     $$PWD/ProjectService.h \
     $$PWD/ReturnMessage.h \
     $$PWD/SqlDBHelper.h \
@@ -18,6 +19,7 @@ SOURCES += \
     $$PWD/DemandWeightService.cpp \
     $$PWD/EngineerService.cpp \
     $$PWD/NodeMatrixService.cpp \
+    $$PWD/ProjectAlgorithmRelationService.cpp \
     $$PWD/ProjectService.cpp \
     $$PWD/ReturnMessage.cpp \
     $$PWD/SqlDBHelper.cpp \