Parcourir la source

'算法库添加'

zsf il y a 1 an
Parent
commit
c1c7e0cf1a

+ 129 - 0
QFD/dbService/AlgorithmService.cpp

@@ -0,0 +1,129 @@
+#include "AlgorithmService.h"
+#include "SqlDBHelper.h"
+#include <QDebug>
+AlgorithmService::AlgorithmService(QObject *parent) { }
+
+int AlgorithmService::AddAlgorithm(const AlgorithmInfo &info)
+{
+    int ret = -1;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        InsertQuery query = t.insertInto("t_algorithm_info( `code`, `name`, `desc`, `type`, `status`, `create_time`)");
+
+        NonQueryResult result =
+                query.values(info.code, info.name, info.desc, info.type, info.status, info.createTime).exec();
+        t.commit();
+        ret = result.lastInsertId().toInt();
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+bool AlgorithmService::UpdateAlgorithm(const AlgorithmInfo &info)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        t.update("t_algorithm_info")
+                .set("code", info.code)
+                .set("name", info.name)
+                .set("desc", info.desc)
+                .set("type", info.type)
+                .set("updateTime", info.updateTime)
+                .where("id = ?", info.id);
+        t.commit();
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+bool AlgorithmService::QueryByCode(QString code)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString("SELECT * FROM t_algorithm_info WHERE code = %1 and status=1").arg(code);
+    if (query.exec(selectSql)) {
+        if (query.next()) {
+            ret = true;
+        }
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
+bool AlgorithmService::QueryByType(QList<AlgorithmInfo *> *infos, int type)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret = false;
+    QString selectSql =
+            QString("SELECT id, code,name,desc,type FROM t_algorithm_info WHERE type = %1 and status=1").arg(type);
+    if (query.exec(selectSql)) {
+        while (query.next()) {
+            if (query.isNull(0) == false) {
+                AlgorithmInfo *info = new AlgorithmInfo();
+                info->id            = query.value(0).toInt();
+                info->code          = query.value(1).toString();
+                info->name          = query.value(2).toString();
+                info->desc          = query.value(3).toString();
+                info->type          = query.value(5).toInt();
+                infos->append(info);
+            }
+        }
+        ret = true;
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
+bool AlgorithmService::QueryAll(QList<AlgorithmInfo *> *infos)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString(
+            "SELECT id, code,name,desc,type,status,create_time,update_time FROM t_algorithm_info order by type,status");
+    if (query.exec(selectSql)) {
+        while (query.next()) {
+            if (query.isNull(0) == false) {
+                AlgorithmInfo *info = new AlgorithmInfo();
+                info->id            = query.value(0).toInt();
+                info->code          = query.value(1).toString();
+                info->name          = query.value(2).toString();
+                info->desc          = query.value(3).toString();
+                info->type          = query.value(5).toInt();
+                info->status        = query.value(6).toInt();
+                info->createTime    = query.value(7).toString();
+                info->updateTime    = query.value(8).toString();
+                infos->append(info);
+            }
+        }
+        ret = true;
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
+bool AlgorithmService::deleteById(int id)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        t.update("t_algorithm_info")
+                .set("status", 1)
+                .set("update_time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
+                .where("id = ?", id);
+        t.commit();
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}

+ 29 - 0
QFD/dbService/AlgorithmService.h

@@ -0,0 +1,29 @@
+#ifndef ALGORITHMSERVICE_H
+#define ALGORITHMSERVICE_H
+#include "ClassSet.h"
+
+class AlgorithmService
+{
+public:
+    AlgorithmService(QObject *parent = nullptr);
+
+    //添加算法
+    int AddAlgorithm(const AlgorithmInfo &info);
+
+    //更新算法
+    bool UpdateAlgorithm(const AlgorithmInfo &info);
+
+    //根据编号查询是否存在
+    bool QueryByCode(QString code);
+
+    //根据类型获取到列表
+    bool QueryByType(QList<AlgorithmInfo *> *infos, int type);
+
+    //获取所有
+    bool QueryAll(QList<AlgorithmInfo *> *infos);
+
+    //根据id禁用
+    bool deleteById(int id);
+};
+
+#endif  // ALGORITHMSERVICE_H

+ 19 - 0
QFD/dbService/ClassSet.h

@@ -283,4 +283,23 @@ public:
     QString updateTime;         //更新时间
 };
 
+/**
+ * @projectName   QFD2
+ * @author        mimang
+ * @date          2023-09-14
+ * @desc          算法信息
+ */
+class AlgorithmInfo
+{
+public:
+    int id = -1;         //主键id
+    QString code;        //算法编码
+    QString name;        //算法名称
+    QString desc;        //算法描述
+    int type;            //算法类型
+    int status = 1;      //状态0不可用1可用
+    QString createTime;  //创建时间
+    QString updateTime;  //更新时间
+};
+
 #endif  // CLASSSET_H

+ 21 - 0
QFD/dbService/ProjectService.cpp

@@ -134,6 +134,27 @@ bool ProjectService::QueryProjectById(ProjectInfo *proJectInfo, int id)
     return ret;
 }
 
+//判断项目名是否存在
+bool ProjectService::QueryProjectByName(QString name)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString("SELECT id, project_name, demand_mind_id, programme_mind_id, "
+                                "general_mind_id,remark,task_name,estimate_time,estimate_objective,estimate_dept,"
+                                "estimate_person,positional_titles,create_time,update_time,estimate_type FROM "
+                                "t_project_info WHERE project_name = %1")
+                                .arg(name);
+    if (query.exec(selectSql)) {
+        if (query.next()) {
+            ret = true;
+        }
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
 bool ProjectService::QueryAll(QList<ProjectInfo *> *projectInfoList)
 {
     QSqlDatabase db = SqlDBHelper::getDatabase();

+ 3 - 0
QFD/dbService/ProjectService.h

@@ -18,6 +18,9 @@ public:
     /*根据项目id查询项目信息*/
     bool QueryProjectById(ProjectInfo *proJectInfo, int id);
 
+    /*根据项目名称查询项目*/
+    bool QueryProjectByName(QString name);
+
     //查询所有
     bool QueryAll(QList<ProjectInfo *> *projectInfoList);
 

+ 2 - 0
QFD/dbService/dbService.pri

@@ -1,4 +1,5 @@
 HEADERS += \
+    $$PWD/AlgorithmService.h \
     $$PWD/ClassSet.h \
     $$PWD/DBServiceSet.h \
     $$PWD/DemandWeightService.h \
@@ -11,6 +12,7 @@ HEADERS += \
     $$PWD/UserService.h
 
 SOURCES += \
+    $$PWD/AlgorithmService.cpp \
     $$PWD/ClassSet.cpp \
     $$PWD/DBServiceSet.cpp \
     $$PWD/DemandWeightService.cpp \