Browse Source

数据库配置文件调整

zsf 1 year ago
parent
commit
9d9aea9f49

+ 5 - 5
QFD/common/ExpertManager.cpp

@@ -1,7 +1,7 @@
 #include "ExpertManager.h"
 
 #include <dbService/ClassSet.h>
-#include <dbService/DBServiceSet.h>
+#include <dbService/UserService.h>
 
 int ExpertManager::addUser(QFUser user)
 {
@@ -17,7 +17,7 @@ int ExpertManager::addUser(QFUser user)
         return QF_CODE_EMPTY_USERNAME;
     }
 
-    if (-1 == DBServiceSet().AddUserInfo(user)) {
+    if (-1 == UserService().AddUserInfo(user)) {
         return QF_CODE_ACCOUNT_OCCUPIED;
     }
 
@@ -26,11 +26,11 @@ int ExpertManager::addUser(QFUser user)
 
 int ExpertManager::deleteUser(int userId)
 {
-    bool ret = DBServiceSet().DeleteUserById(userId);
+    bool ret = UserService().DeleteUserById(userId);
     if (!ret) {
         return QF_CODE_DELETE_USER_FAILED;
     }
 
-    DBServiceSet().DeleteUserConfigByEngineerId(userId);
-    return QF_CODE_DELETE_USER_SUCCEEDED;
+    // UserService().DeleteUserConfigByEngineerId(userId);
+    // return QF_CODE_DELETE_USER_SUCCEEDED;
 }

+ 4 - 4
QFD/dbService/ClassSet.cpp

@@ -1,7 +1,7 @@
 #include "ClassSet.h"
 
 #include "DBServiceSet.h"
-
+#include "UserService.h"
 #include <QCryptographicHash>
 #include <QSettings>
 
@@ -178,7 +178,7 @@ int QFUser::resetAdmin(QString account, QString password, QString repeatPassword
     QByteArray md5bytes = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5);
     md5str.prepend(md5bytes.toHex());
 
-    bool ret = DBServiceSet().UpdateUserById(account, md5str, id);
+    bool ret = UserService().UpdateUserById(account, md5str, id);
     if (ret) {
         return QF_CODE_SUCCEEDED;
     } else {
@@ -200,7 +200,7 @@ int QFUser::login()
         return QF_CODE_EMPTY_PASSWORD;
     }
 
-    if (!DBServiceSet().QueryUserByNo(this, userNo)) {
+    if (!UserService().QueryUserByNo(this, userNo)) {
         return QF_CODE_USER_NOT_EXISTS;
     }
 
@@ -210,7 +210,7 @@ int QFUser::login()
     md5str.prepend(md5bytes.toHex());
 
     m_currentUser = new QFUser(userNo, m_rawPassword);
-    if (!DBServiceSet().QueryUserByNoAndPassword(m_currentUser, userNo, md5str)) {
+    if (!UserService().QueryUserByNoAndPassword(m_currentUser, userNo, md5str)) {
         delete m_currentUser;
         m_currentUser = nullptr;
         return QF_CODE_WRONG_PASSWORD;

+ 0 - 510
QFD/dbService/DBServiceSet.cpp

@@ -1711,516 +1711,6 @@ bool DBServiceSet::DeleteEngineerNotInId(int id, QString dbPath)
 }
 //////////////////////工程信息表-end////////////////////
 
-//////////////////////用户信息表-start////////////////////
-int DBServiceSet::AddUserInfo(const QFUser &userInfo)
-{
-    int returnId = -1;
-    try {
-
-        returnId = getNextId("t_user_info");
-        Transaction t(SqlDBHelper::getDatabase());
-        InsertQuery query = t.insertInto("t_user_info (user_name, user_no, password, role, post, "
-                                         "major,work_position,education_degree,phone,project_id,write_time,remark)");
-        NonQueryResult result =
-                query.values(userInfo.userName, userInfo.userNo, userInfo.password, userInfo.role, userInfo.post,
-                             userInfo.major, userInfo.workPosition, userInfo.educationDegree, userInfo.phone,
-                             userInfo.projectId, userInfo.writeTime, userInfo.remark)
-                        .exec();
-        t.commit();
-        returnId = result.lastInsertId().toInt();
-
-    } catch (const DBException &ex) {
-        qDebug() << ex.lastError.text();
-        returnId = -1;
-    }
-    return returnId;
-}
-/*暂时用id修改*/
-bool DBServiceSet::UpdateUserInfo(const QFUser &userInfo)
-{
-    bool ret = false;
-    try {
-        Transaction t(SqlDBHelper::getDatabase());
-        t.update("t_user_info")
-                .set("user_name", userInfo.userName)
-                .set("user_no", userInfo.userNo)
-                .set("password", userInfo.password)
-                .set("role", userInfo.role)
-                .set("post", userInfo.post)
-                .set("major", userInfo.major)
-                .set("work_position", userInfo.workPosition)
-                .set("education_degree", userInfo.educationDegree)
-                .set("phone", userInfo.phone)
-                .set("remark", userInfo.remark)
-                .set("project_id", userInfo.projectId)
-                .where("id=?", userInfo.id);
-        t.commit();
-        ret = true;
-    } catch (const DBException &ex) {
-        qDebug() << ex.lastError.text();
-    }
-    return ret;
-}
-
-bool DBServiceSet::UpdateUserPassword(QString userNo, QString password)
-{
-    bool ret = false;
-    try {
-        Transaction t(SqlDBHelper::getDatabase());
-        t.update("t_user_info").set("password", password).where("user_no=?", userNo);
-        t.commit();
-        ret = true;
-    } catch (const DBException &ex) {
-        qDebug() << ex.lastError.text();
-    }
-    return ret;
-}
-
-bool DBServiceSet::UpdateUserById(QString userNo, QString password, int id)
-{
-    bool ret = false;
-    try {
-        Transaction t(SqlDBHelper::getDatabase());
-        t.update("t_user_info").set("password", password).set("user_no", userNo).where("id=?", id);
-        t.commit();
-        ret = true;
-    } catch (const DBException &ex) {
-        qDebug() << ex.lastError.text();
-    }
-    return ret;
-}
-
-bool DBServiceSet::QueryUserInfoById(QFUser *userInfo, int userId)
-{
-    QSqlDatabase db = SqlDBHelper::getDatabase();
-    QSqlQuery query(db);
-    bool ret          = false;
-    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
-                                "major,work_position,education_degree,phone,remark,project_id,"
-                                "write_time from "
-                                "t_user_info WHERE id = %1")
-                                .arg(userId);
-    if (query.exec(selectSql)) {
-        if (query.next()) {
-            if (query.isNull(0) == false) {
-                userInfo->id              = query.value(0).toInt();
-                userInfo->userName        = query.value(1).toString();
-                userInfo->userNo          = query.value(2).toString();
-                userInfo->password        = query.value(3).toString();
-                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
-                userInfo->post            = query.value(5).toString();
-                userInfo->major           = query.value(6).toString();
-                userInfo->workPosition    = query.value(7).toString();
-                userInfo->educationDegree = query.value(8).toString();
-                userInfo->phone           = query.value(9).toString();
-                userInfo->remark          = query.value(10).toString();
-                userInfo->projectId       = query.value(11).toString();
-                userInfo->writeTime       = query.value(12).toString();
-            }
-            ret = true;
-        }
-    } else {
-        qDebug() << query.lastError();
-    }
-    return ret;
-}
-
-bool DBServiceSet::QueryUserInfoByUnserInfo(const QFUser &paramInfo, QFUser &queryInfo)
-{
-    QSqlDatabase db = SqlDBHelper::getDatabase();
-    QSqlQuery query(db);
-    bool ret          = false;
-    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
-                                "major,work_position,education_degree,phone,project_id,write_time from "
-                                "t_user_info WHERE 1 = 1 ");
-    if (!paramInfo.userName.isNull() && !paramInfo.userName.isEmpty()) {
-        selectSql += " and user_name = '" + paramInfo.userName + "'";
-    }
-    if (!paramInfo.userNo.isNull() && !paramInfo.userNo.isEmpty()) {
-        selectSql += " and user_no = '" + paramInfo.userNo + "'";
-    }
-    if (!paramInfo.post.isNull() && !paramInfo.post.isEmpty()) {
-        selectSql += " and post = '" + paramInfo.post + "'";
-    }
-    if (!paramInfo.major.isNull() && !paramInfo.major.isEmpty()) {
-        selectSql += " and major = '" + paramInfo.major + "'";
-    }
-    if (!paramInfo.workPosition.isNull() && !paramInfo.workPosition.isEmpty()) {
-        selectSql += " and work_position = '" + paramInfo.workPosition + "'";
-    }
-    if (!paramInfo.educationDegree.isNull() && !paramInfo.educationDegree.isEmpty()) {
-        selectSql += " and education_degree = '" + paramInfo.educationDegree + "'";
-    }
-    if (!paramInfo.phone.isNull() && !paramInfo.phone.isEmpty()) {
-        selectSql += " and phone = '" + paramInfo.phone + "'";
-    }
-    if (!paramInfo.projectId.isNull() && !paramInfo.projectId.isEmpty()) {
-        selectSql += " and project_id = '" + paramInfo.projectId + "'";
-    }
-    int role = paramInfo.role;
-    if (role == 0) {
-        selectSql += " and role != '" + QString::number(role) + "'";
-    } else {
-        selectSql += " and role = '" + QString::number(role) + "'";
-    }
-
-    if (query.exec(selectSql)) {
-        if (query.next()) {
-            queryInfo    = paramInfo;
-            queryInfo.id = query.value(0).toInt();
-            ret          = true;
-        }
-    } else {
-        qDebug() << query.lastError();
-    }
-    return ret;
-}
-/*获取到用户列表*/
-bool DBServiceSet::QueryUserListByEngineerId(QList<QFUser *> *userInfoList, int engineerId)
-{
-    QSqlDatabase db = SqlDBHelper::getDatabase();
-    QSqlQuery query(db);
-    bool ret          = false;
-    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
-                                "major,work_position,education_degree,phone,remark,project_id,"
-                                "write_time "
-                                "from t_user_info"
-                                " WHERE id in (select uc.user_id from t_user_config uc where "
-                                "uc.engineer_id = %1 and uc.is_valid =1 )")
-                                .arg(engineerId);
-    // qDebug() << selectSql;
-    if (query.exec(selectSql)) {
-        while (query.next()) {
-            if (query.isNull(0) == false) {
-                QFUser *userInfo          = new QFUser();
-                userInfo->id              = query.value(0).toInt();
-                userInfo->userName        = query.value(1).toString();
-                userInfo->userNo          = query.value(2).toString();
-                userInfo->password        = query.value(3).toString();
-                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
-                userInfo->post            = query.value(5).toString();
-                userInfo->major           = query.value(6).toString();
-                userInfo->workPosition    = query.value(7).toString();
-                userInfo->educationDegree = query.value(8).toString();
-                userInfo->phone           = query.value(9).toString();
-                userInfo->remark          = query.value(10).toString();
-                userInfo->projectId       = query.value(11).toString();
-                userInfo->writeTime       = query.value(12).toString();
-                userInfoList->append(userInfo);
-            }
-            ret = true;
-        }
-    } else {
-        qDebug() << query.lastError();
-    }
-    return ret;
-}
-
-bool DBServiceSet::QueryUserListByColumnAndColumnValue(QList<QFUser *> *userInfoList, QString columnName,
-                                                       QString columnValue)
-{
-    QSqlDatabase db = SqlDBHelper::getDatabase();
-    QSqlQuery query(db);
-    bool ret          = false;
-    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
-                                "major,work_position,education_degree,phone,remark,project_id,"
-                                "write_time "
-                                "from t_user_info"
-                                " WHERE %1 = '%2'")
-                                .arg(columnName)
-                                .arg(columnValue);
-    // qDebug() << selectSql;
-    if (query.exec(selectSql)) {
-        while (query.next()) {
-            if (query.isNull(0) == false) {
-                QFUser *userInfo          = new QFUser();
-                userInfo->id              = query.value(0).toInt();
-                userInfo->userName        = query.value(1).toString();
-                userInfo->userNo          = query.value(2).toString();
-                userInfo->password        = query.value(3).toString();
-                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
-                userInfo->post            = query.value(5).toString();
-                userInfo->major           = query.value(6).toString();
-                userInfo->workPosition    = query.value(7).toString();
-                userInfo->educationDegree = query.value(8).toString();
-                userInfo->phone           = query.value(9).toString();
-                userInfo->remark          = query.value(10).toString();
-                userInfo->projectId       = query.value(11).toString();
-                userInfo->writeTime       = query.value(12).toString();
-                userInfoList->append(userInfo);
-            }
-            ret = true;
-        }
-    } else {
-        qDebug() << query.lastError();
-    }
-    return ret;
-}
-bool DBServiceSet::QueryUserList(QList<QFUser *> *userInfoList)
-{
-    QSqlDatabase db = SqlDBHelper::getDatabase();
-    QSqlQuery query(db);
-    bool ret          = false;
-    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
-                                "major,work_position,education_degree,phone,remark,project_id,"
-                                "write_time from t_user_info");
-    if (query.exec(selectSql)) {
-        while (query.next()) {
-            if (query.isNull(0) == false) {
-                QFUser *userInfo          = new QFUser();
-                userInfo->id              = query.value(0).toInt();
-                userInfo->userName        = query.value(1).toString();
-                userInfo->userNo          = query.value(2).toString();
-                userInfo->password        = query.value(3).toString();
-                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
-                userInfo->post            = query.value(5).toString();
-                userInfo->major           = query.value(6).toString();
-                userInfo->workPosition    = query.value(7).toString();
-                userInfo->educationDegree = query.value(8).toString();
-                userInfo->phone           = query.value(9).toString();
-                userInfo->remark          = query.value(10).toString();
-                userInfo->projectId       = query.value(11).toString();
-                userInfo->writeTime       = query.value(12).toString();
-                userInfoList->append(userInfo);
-            }
-            ret = true;
-        }
-    } else {
-        qDebug() << query.lastError();
-    }
-    return ret;
-}
-
-bool DBServiceSet::QueryUserListNotAdmin(QList<QFUser *> *userInfoList)
-{
-    QSqlDatabase db = SqlDBHelper::getDatabase();
-    QSqlQuery query(db);
-    bool ret = false;
-    try {
-        QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
-                                    "major,work_position,education_degree,phone,remark,project_id,"
-                                    "write_time from t_user_info where role !=0");
-        if (query.exec(selectSql)) {
-            while (query.next()) {
-                if (query.isNull(0) == false) {
-                    QFUser *userInfo          = new QFUser();
-                    userInfo->id              = query.value(0).toInt();
-                    userInfo->userName        = query.value(1).toString();
-                    userInfo->userNo          = query.value(2).toString();
-                    userInfo->password        = query.value(3).toString();
-                    userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
-                    userInfo->post            = query.value(5).toString();
-                    userInfo->major           = query.value(6).toString();
-                    userInfo->workPosition    = query.value(7).toString();
-                    userInfo->educationDegree = query.value(8).toString();
-                    userInfo->phone           = query.value(9).toString();
-                    userInfo->remark          = query.value(10).toString();
-                    userInfo->projectId       = query.value(11).toString();
-                    userInfo->writeTime       = query.value(12).toString();
-                    userInfoList->append(userInfo);
-                }
-            }
-        } else {
-            qDebug() << query.lastError();
-        }
-        ret = true;
-
-    } catch (const DBException &ex) {
-        qDebug() << ex.lastError.text();
-    }
-    return ret;
-}
-bool DBServiceSet::DeleteUserById(int Id)
-{
-    QSqlDatabase db = SqlDBHelper::getDatabase();
-    QSqlQuery query(db);
-    bool ret          = false;
-    QString deleteSql = QString("DELETE FROM t_user_info WHERE id = %1").arg(Id);
-    if (query.exec(deleteSql)) {
-        ret = true;
-        qDebug() << "deleteSql success!";
-    } else {
-        qDebug() << query.lastError();
-    }
-    return ret;
-}
-
-//删除除管理管外的所有用户
-bool DBServiceSet::DeleteUserByRole(int roleType)
-{
-    QSqlDatabase db = SqlDBHelper::getDatabase();
-    QSqlQuery query(db);
-    bool ret          = false;
-    QString deleteSql = QString("DELETE FROM t_user_info WHERE role != %1").arg(roleType);
-    if (query.exec(deleteSql)) {
-        ret = true;
-        qDebug() << "deleteSql success!";
-    } else {
-        qDebug() << query.lastError();
-    }
-    return ret;
-}
-
-bool DBServiceSet::QueryUserByNoAndPassword(QFUser *userInfo, QString userNo, QString password)
-{
-    QSqlDatabase db = SqlDBHelper::getDatabase();
-    QSqlQuery query(db);
-    bool ret          = false;
-    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
-                                "major,work_position,education_degree,phone,remark,project_id,"
-                                "write_time from "
-                                "t_user_info WHERE user_no = %1 and password = %2")
-                                .arg("'" + userNo + "'")
-                                .arg("'" + password + "'");
-
-    if (query.exec(selectSql)) {
-        if (query.next()) {
-            if (query.isNull(0) == false) {
-                userInfo->id              = query.value(0).toInt();
-                userInfo->userName        = query.value(1).toString();
-                userInfo->userNo          = query.value(2).toString();
-                userInfo->password        = query.value(3).toString();
-                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
-                userInfo->post            = query.value(5).toString();
-                userInfo->major           = query.value(6).toString();
-                userInfo->workPosition    = query.value(7).toString();
-                userInfo->educationDegree = query.value(8).toString();
-                userInfo->phone           = query.value(9).toString();
-                userInfo->remark          = query.value(10).toString();
-                userInfo->projectId       = query.value(11).toString();
-                userInfo->writeTime       = query.value(12).toString();
-            }
-            ret = true;
-        }
-    } else {
-        qDebug() << query.lastError();
-    }
-    return ret;
-}
-
-bool DBServiceSet::QueryUserByNo(QFUser *userInfo, QString userNo)
-{
-    QSqlDatabase db = SqlDBHelper::getDatabase();
-    QSqlQuery query(db);
-    bool ret          = false;
-    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
-                                "major,work_position,education_degree,phone,remark,project_id,"
-                                "write_time from "
-                                "t_user_info WHERE user_no = %1 ")
-                                .arg("'" + userNo + "'");
-
-    if (query.exec(selectSql)) {
-        if (query.next()) {
-            if (query.isNull(0) == false) {
-                userInfo->id              = query.value(0).toInt();
-                userInfo->userName        = query.value(1).toString();
-                userInfo->userNo          = query.value(2).toString();
-                userInfo->password        = query.value(3).toString();
-                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
-                userInfo->post            = query.value(5).toString();
-                userInfo->major           = query.value(6).toString();
-                userInfo->workPosition    = query.value(7).toString();
-                userInfo->educationDegree = query.value(8).toString();
-                userInfo->phone           = query.value(9).toString();
-                userInfo->remark          = query.value(10).toString();
-                userInfo->projectId       = query.value(11).toString();
-                userInfo->writeTime       = query.value(12).toString();
-            }
-            ret = true;
-        }
-    } else {
-        qDebug() << query.lastError();
-    }
-    return ret;
-}
-
-bool DBServiceSet::QueryUserInfoById2(QFUser *userInfo, int userId)
-{
-    QSqlDatabase db = SqlDBHelper::getDatabase2();
-    QSqlQuery query(db);
-    bool ret          = false;
-    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
-                                "major,work_position,education_degree,phone,remark,project_id,"
-                                "write_time from "
-                                "t_user_info WHERE id = %1")
-                                .arg(userId);
-    qDebug() << selectSql;
-    if (query.exec(selectSql)) {
-        if (query.next()) {
-            if (query.isNull(0) == false) {
-                userInfo->id              = query.value(0).toInt();
-                userInfo->userName        = query.value(1).toString();
-                userInfo->userNo          = query.value(2).toString();
-                userInfo->password        = query.value(3).toString();
-                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
-                userInfo->post            = query.value(5).toString();
-                userInfo->major           = query.value(6).toString();
-                userInfo->workPosition    = query.value(7).toString();
-                userInfo->educationDegree = query.value(8).toString();
-                userInfo->phone           = query.value(9).toString();
-                userInfo->remark          = query.value(10).toString();
-                userInfo->projectId       = query.value(11).toString();
-                userInfo->writeTime       = query.value(12).toString();
-            }
-            ret = true;
-        }
-    } else {
-        qDebug() << query.lastError();
-    }
-    return ret;
-}
-
-bool DBServiceSet::UpdateUserInfo2(const QFUser &userInfo)
-{
-    bool ret = false;
-    try {
-        Transaction t(SqlDBHelper::getDatabase2());
-        t.update("t_user_info")
-                .set("user_name", userInfo.userName)
-                .set("user_no", userInfo.userNo)
-                .set("password", userInfo.password)
-                .set("role", userInfo.role)
-                .set("post", userInfo.post)
-                .set("major", userInfo.major)
-                .set("work_position", userInfo.workPosition)
-                .set("education_degree", userInfo.educationDegree)
-                .set("phone", userInfo.phone)
-                .set("remark", userInfo.remark)
-                .set("project_id", userInfo.projectId)
-                .where("id=?", userInfo.id);
-        t.commit();
-        ret = true;
-    } catch (const DBException &ex) {
-        qDebug() << ex.lastError.text();
-    }
-    return ret;
-}
-
-int DBServiceSet::AddUserInfo2(const QFUser &userInfo)
-{
-    int returnId = -1;
-    try {
-
-        Transaction t(SqlDBHelper::getDatabase2());
-        InsertQuery query = t.insertInto("t_user_info (id,user_name, user_no, password, role, post, "
-                                         "major,work_position,education_degree,phone,project_id,write_time)");
-        NonQueryResult result =
-                query.values(userInfo.id, userInfo.userName, userInfo.userNo, userInfo.password, userInfo.role,
-                             userInfo.post, userInfo.major, userInfo.workPosition, userInfo.educationDegree,
-                             userInfo.phone, userInfo.projectId, userInfo.writeTime)
-                        .exec();
-        t.commit();
-        returnId = result.lastInsertId().toInt();
-
-    } catch (const DBException &ex) {
-        qDebug() << ex.lastError.text();
-        returnId = -1;
-    }
-    return returnId;
-}
-
-//////////////////////用户信息表-end////////////////////
-
 //////////////////////评估方案信息表-start////////////////////
 bool DBServiceSet::AddPlanInfo(const PlanInfo &planInfo)
 {

+ 0 - 30
QFD/dbService/DBServiceSet.h

@@ -181,36 +181,6 @@ public:
     //////////////////////工程信息表-end////////////////////
 
     //////////////////////用户信息表-start////////////////////
-    //添加信息
-    int AddUserInfo(const QFUser &userInfo);
-    /*修改用户信息*/
-    bool UpdateUserInfo(const QFUser &userInfo);
-    bool UpdateUserPassword(QString userNo, QString password);
-    bool UpdateUserById(QString userNo, QString password, int id);
-    /*根据用户id查询用户信息*/
-    bool QueryUserInfoById(QFUser *userInfo, int userId);
-    bool QueryUserInfoByUnserInfo(const QFUser &paramInfo, QFUser &queryInfo);
-    // int QueryUserInfoByUserNoAndPhone(QString);
-    /*根据列名称和列值模糊查询用户信息,列名称为实体类中的属性名称*/
-    bool QueryUserListByColumnAndColumnValue(QList<QFUser *> *userInfoList, QString columnName, QString columnValue);
-    bool QueryUserList(QList<QFUser *> *userInfoList);
-    bool QueryUserListNotAdmin(QList<QFUser *> *userInfoList);
-    /*根据用户编号删除用户信息*/
-    bool DeleteUserById(int Id);
-    bool QueryUserByNoAndPassword(QFUser *userInfo, QString userNo, QString password);
-    bool QueryUserByNo(QFUser *userInfo, QString userNo);
-    /*获取工程用户列表*/
-    bool QueryUserListByEngineerId(QList<QFUser *> *userInfoList, int engineerId);
-
-    //删除除管理管外的所有用户
-    bool DeleteUserByRole(int roleType);
-
-    //专家本地库查询信息
-    bool QueryUserInfoById2(QFUser *userInfo, int userId);
-
-    bool UpdateUserInfo2(const QFUser &userInfo);
-
-    int AddUserInfo2(const QFUser &userInfo);
 
     //////////////////////用户信息表-end////////////////////
 

+ 6 - 0
QFD/dbService/EngineerService.cpp

@@ -0,0 +1,6 @@
+#include "EngineerService.h"
+
+EngineerService::EngineerService()
+{
+
+}

+ 11 - 0
QFD/dbService/EngineerService.h

@@ -0,0 +1,11 @@
+#ifndef ENGINEERSERVICE_H
+#define ENGINEERSERVICE_H
+
+
+class EngineerService
+{
+public:
+    EngineerService();
+};
+
+#endif // ENGINEERSERVICE_H

+ 9 - 1
QFD/dbService/SqlDBHelper.cpp

@@ -24,7 +24,15 @@ QSqlDatabase SqlDBHelper::getDatabase(SqlDBHelper::SqlDBType dbType, const QStri
         if (configFinished) {
             return SqlFactory::getInstance()->getDatabase();
         } else {
-            SqlFactory::DBSetting setting("QMYSQL", "101.43.129.26", 3306, "root", "Lab501db#", "qfd");
+            QSettings datasource("datasource.ini", QSettings::IniFormat);
+            datasource.setIniCodec("UTF-8");
+            QString url      = datasource.value("DATASOURCE/url", "").toString();
+            int port         = datasource.value("DATASOURCE/port", "").toInt();
+            QString username = datasource.value("DATASOURCE/username", "").toString();
+            QString password = datasource.value("DATASOURCE/password", "").toString();
+            QString database = datasource.value("DATASOURCE/database", "").toString();
+            qDebug() << url << port << username << password << database;
+            SqlFactory::DBSetting setting("QMYSQL", url, port, username, password, database);
             configFinished = true;
             return SqlFactory::getInstance()->config(setting, connectionName)->getDatabase();
         }

+ 515 - 0
QFD/dbService/UserService.cpp

@@ -0,0 +1,515 @@
+#include "UserService.h"
+#include "SqlDBHelper.h"
+#include <QDebug>
+#include "DBServiceSet.h"
+
+UserService::UserService(QObject *parent) { }
+//////////////////////用户信息表-start////////////////////
+int UserService::AddUserInfo(const QFUser &userInfo)
+{
+    int returnId = -1;
+    try {
+
+        // returnId = DBServiceSet::getNextId("t_user_info");
+        Transaction t(SqlDBHelper::getDatabase());
+        InsertQuery query = t.insertInto("t_user_info (user_name, user_no, password, role, post, "
+                                         "major,work_position,education_degree,phone,project_id,write_time,remark)");
+        NonQueryResult result =
+                query.values(userInfo.userName, userInfo.userNo, userInfo.password, userInfo.role, userInfo.post,
+                             userInfo.major, userInfo.workPosition, userInfo.educationDegree, userInfo.phone,
+                             userInfo.projectId, userInfo.writeTime, userInfo.remark)
+                        .exec();
+        t.commit();
+        returnId = result.lastInsertId().toInt();
+
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+        returnId = -1;
+    }
+    return returnId;
+}
+/*暂时用id修改*/
+bool UserService::UpdateUserInfo(const QFUser &userInfo)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        t.update("t_user_info")
+                .set("user_name", userInfo.userName)
+                .set("user_no", userInfo.userNo)
+                .set("password", userInfo.password)
+                .set("role", userInfo.role)
+                .set("post", userInfo.post)
+                .set("major", userInfo.major)
+                .set("work_position", userInfo.workPosition)
+                .set("education_degree", userInfo.educationDegree)
+                .set("phone", userInfo.phone)
+                .set("remark", userInfo.remark)
+                .set("project_id", userInfo.projectId)
+                .where("id=?", userInfo.id);
+        t.commit();
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+bool UserService::UpdateUserPassword(QString userNo, QString password)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        t.update("t_user_info").set("password", password).where("user_no=?", userNo);
+        t.commit();
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+bool UserService::UpdateUserById(QString userNo, QString password, int id)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        t.update("t_user_info").set("password", password).set("user_no", userNo).where("id=?", id);
+        t.commit();
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+bool UserService::QueryUserInfoById(QFUser *userInfo, int userId)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
+                                "major,work_position,education_degree,phone,remark,project_id,"
+                                "write_time from "
+                                "t_user_info WHERE id = %1")
+                                .arg(userId);
+    if (query.exec(selectSql)) {
+        if (query.next()) {
+            if (query.isNull(0) == false) {
+                userInfo->id              = query.value(0).toInt();
+                userInfo->userName        = query.value(1).toString();
+                userInfo->userNo          = query.value(2).toString();
+                userInfo->password        = query.value(3).toString();
+                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
+                userInfo->post            = query.value(5).toString();
+                userInfo->major           = query.value(6).toString();
+                userInfo->workPosition    = query.value(7).toString();
+                userInfo->educationDegree = query.value(8).toString();
+                userInfo->phone           = query.value(9).toString();
+                userInfo->remark          = query.value(10).toString();
+                userInfo->projectId       = query.value(11).toString();
+                userInfo->writeTime       = query.value(12).toString();
+            }
+            ret = true;
+        }
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
+bool UserService::QueryUserInfoByUnserInfo(const QFUser &paramInfo, QFUser &queryInfo)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
+                                "major,work_position,education_degree,phone,project_id,write_time from "
+                                "t_user_info WHERE 1 = 1 ");
+    if (!paramInfo.userName.isNull() && !paramInfo.userName.isEmpty()) {
+        selectSql += " and user_name = '" + paramInfo.userName + "'";
+    }
+    if (!paramInfo.userNo.isNull() && !paramInfo.userNo.isEmpty()) {
+        selectSql += " and user_no = '" + paramInfo.userNo + "'";
+    }
+    if (!paramInfo.post.isNull() && !paramInfo.post.isEmpty()) {
+        selectSql += " and post = '" + paramInfo.post + "'";
+    }
+    if (!paramInfo.major.isNull() && !paramInfo.major.isEmpty()) {
+        selectSql += " and major = '" + paramInfo.major + "'";
+    }
+    if (!paramInfo.workPosition.isNull() && !paramInfo.workPosition.isEmpty()) {
+        selectSql += " and work_position = '" + paramInfo.workPosition + "'";
+    }
+    if (!paramInfo.educationDegree.isNull() && !paramInfo.educationDegree.isEmpty()) {
+        selectSql += " and education_degree = '" + paramInfo.educationDegree + "'";
+    }
+    if (!paramInfo.phone.isNull() && !paramInfo.phone.isEmpty()) {
+        selectSql += " and phone = '" + paramInfo.phone + "'";
+    }
+    if (!paramInfo.projectId.isNull() && !paramInfo.projectId.isEmpty()) {
+        selectSql += " and project_id = '" + paramInfo.projectId + "'";
+    }
+    int role = paramInfo.role;
+    if (role == 0) {
+        selectSql += " and role != '" + QString::number(role) + "'";
+    } else {
+        selectSql += " and role = '" + QString::number(role) + "'";
+    }
+
+    if (query.exec(selectSql)) {
+        if (query.next()) {
+            queryInfo    = paramInfo;
+            queryInfo.id = query.value(0).toInt();
+            ret          = true;
+        }
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+/*获取到用户列表*/
+bool UserService::QueryUserListByEngineerId(QList<QFUser *> *userInfoList, int engineerId)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
+                                "major,work_position,education_degree,phone,remark,project_id,"
+                                "write_time "
+                                "from t_user_info"
+                                " WHERE id in (select uc.user_id from t_user_config uc where "
+                                "uc.engineer_id = %1 and uc.is_valid =1 )")
+                                .arg(engineerId);
+    // qDebug() << selectSql;
+    if (query.exec(selectSql)) {
+        while (query.next()) {
+            if (query.isNull(0) == false) {
+                QFUser *userInfo          = new QFUser();
+                userInfo->id              = query.value(0).toInt();
+                userInfo->userName        = query.value(1).toString();
+                userInfo->userNo          = query.value(2).toString();
+                userInfo->password        = query.value(3).toString();
+                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
+                userInfo->post            = query.value(5).toString();
+                userInfo->major           = query.value(6).toString();
+                userInfo->workPosition    = query.value(7).toString();
+                userInfo->educationDegree = query.value(8).toString();
+                userInfo->phone           = query.value(9).toString();
+                userInfo->remark          = query.value(10).toString();
+                userInfo->projectId       = query.value(11).toString();
+                userInfo->writeTime       = query.value(12).toString();
+                userInfoList->append(userInfo);
+            }
+            ret = true;
+        }
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
+bool UserService::QueryUserListByColumnAndColumnValue(QList<QFUser *> *userInfoList, QString columnName,
+                                                      QString columnValue)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
+                                "major,work_position,education_degree,phone,remark,project_id,"
+                                "write_time "
+                                "from t_user_info"
+                                " WHERE %1 = '%2'")
+                                .arg(columnName)
+                                .arg(columnValue);
+    // qDebug() << selectSql;
+    if (query.exec(selectSql)) {
+        while (query.next()) {
+            if (query.isNull(0) == false) {
+                QFUser *userInfo          = new QFUser();
+                userInfo->id              = query.value(0).toInt();
+                userInfo->userName        = query.value(1).toString();
+                userInfo->userNo          = query.value(2).toString();
+                userInfo->password        = query.value(3).toString();
+                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
+                userInfo->post            = query.value(5).toString();
+                userInfo->major           = query.value(6).toString();
+                userInfo->workPosition    = query.value(7).toString();
+                userInfo->educationDegree = query.value(8).toString();
+                userInfo->phone           = query.value(9).toString();
+                userInfo->remark          = query.value(10).toString();
+                userInfo->projectId       = query.value(11).toString();
+                userInfo->writeTime       = query.value(12).toString();
+                userInfoList->append(userInfo);
+            }
+            ret = true;
+        }
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+bool UserService::QueryUserList(QList<QFUser *> *userInfoList)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
+                                "major,work_position,education_degree,phone,remark,project_id,"
+                                "write_time from t_user_info");
+    if (query.exec(selectSql)) {
+        while (query.next()) {
+            if (query.isNull(0) == false) {
+                QFUser *userInfo          = new QFUser();
+                userInfo->id              = query.value(0).toInt();
+                userInfo->userName        = query.value(1).toString();
+                userInfo->userNo          = query.value(2).toString();
+                userInfo->password        = query.value(3).toString();
+                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
+                userInfo->post            = query.value(5).toString();
+                userInfo->major           = query.value(6).toString();
+                userInfo->workPosition    = query.value(7).toString();
+                userInfo->educationDegree = query.value(8).toString();
+                userInfo->phone           = query.value(9).toString();
+                userInfo->remark          = query.value(10).toString();
+                userInfo->projectId       = query.value(11).toString();
+                userInfo->writeTime       = query.value(12).toString();
+                userInfoList->append(userInfo);
+            }
+            ret = true;
+        }
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
+bool UserService::QueryUserListNotAdmin(QList<QFUser *> *userInfoList)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret = false;
+    try {
+        QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
+                                    "major,work_position,education_degree,phone,remark,project_id,"
+                                    "write_time from t_user_info where role !=0");
+        if (query.exec(selectSql)) {
+            while (query.next()) {
+                if (query.isNull(0) == false) {
+                    QFUser *userInfo          = new QFUser();
+                    userInfo->id              = query.value(0).toInt();
+                    userInfo->userName        = query.value(1).toString();
+                    userInfo->userNo          = query.value(2).toString();
+                    userInfo->password        = query.value(3).toString();
+                    userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
+                    userInfo->post            = query.value(5).toString();
+                    userInfo->major           = query.value(6).toString();
+                    userInfo->workPosition    = query.value(7).toString();
+                    userInfo->educationDegree = query.value(8).toString();
+                    userInfo->phone           = query.value(9).toString();
+                    userInfo->remark          = query.value(10).toString();
+                    userInfo->projectId       = query.value(11).toString();
+                    userInfo->writeTime       = query.value(12).toString();
+                    userInfoList->append(userInfo);
+                }
+            }
+        } else {
+            qDebug() << query.lastError();
+        }
+        ret = true;
+
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+bool UserService::DeleteUserById(int Id)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString deleteSql = QString("DELETE FROM t_user_info WHERE id = %1").arg(Id);
+    if (query.exec(deleteSql)) {
+        ret = true;
+        qDebug() << "deleteSql success!";
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
+//删除除管理管外的所有用户
+bool UserService::DeleteUserByRole(int roleType)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString deleteSql = QString("DELETE FROM t_user_info WHERE role != %1").arg(roleType);
+    if (query.exec(deleteSql)) {
+        ret = true;
+        qDebug() << "deleteSql success!";
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
+bool UserService::QueryUserByNoAndPassword(QFUser *userInfo, QString userNo, QString password)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
+                                "major,work_position,education_degree,phone,remark,project_id,"
+                                "write_time from "
+                                "t_user_info WHERE user_no = %1 and password = %2")
+                                .arg("'" + userNo + "'")
+                                .arg("'" + password + "'");
+
+    if (query.exec(selectSql)) {
+        if (query.next()) {
+            if (query.isNull(0) == false) {
+                userInfo->id              = query.value(0).toInt();
+                userInfo->userName        = query.value(1).toString();
+                userInfo->userNo          = query.value(2).toString();
+                userInfo->password        = query.value(3).toString();
+                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
+                userInfo->post            = query.value(5).toString();
+                userInfo->major           = query.value(6).toString();
+                userInfo->workPosition    = query.value(7).toString();
+                userInfo->educationDegree = query.value(8).toString();
+                userInfo->phone           = query.value(9).toString();
+                userInfo->remark          = query.value(10).toString();
+                userInfo->projectId       = query.value(11).toString();
+                userInfo->writeTime       = query.value(12).toString();
+            }
+            ret = true;
+        }
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
+bool UserService::QueryUserByNo(QFUser *userInfo, QString userNo)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
+                                "major,work_position,education_degree,phone,remark,project_id,"
+                                "write_time from "
+                                "t_user_info WHERE user_no = %1 ")
+                                .arg("'" + userNo + "'");
+
+    if (query.exec(selectSql)) {
+        if (query.next()) {
+            if (query.isNull(0) == false) {
+                userInfo->id              = query.value(0).toInt();
+                userInfo->userName        = query.value(1).toString();
+                userInfo->userNo          = query.value(2).toString();
+                userInfo->password        = query.value(3).toString();
+                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
+                userInfo->post            = query.value(5).toString();
+                userInfo->major           = query.value(6).toString();
+                userInfo->workPosition    = query.value(7).toString();
+                userInfo->educationDegree = query.value(8).toString();
+                userInfo->phone           = query.value(9).toString();
+                userInfo->remark          = query.value(10).toString();
+                userInfo->projectId       = query.value(11).toString();
+                userInfo->writeTime       = query.value(12).toString();
+            }
+            ret = true;
+        }
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
+bool UserService::QueryUserInfoById2(QFUser *userInfo, int userId)
+{
+    QSqlDatabase db = SqlDBHelper::getDatabase2();
+    QSqlQuery query(db);
+    bool ret          = false;
+    QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, "
+                                "major,work_position,education_degree,phone,remark,project_id,"
+                                "write_time from "
+                                "t_user_info WHERE id = %1")
+                                .arg(userId);
+    qDebug() << selectSql;
+    if (query.exec(selectSql)) {
+        if (query.next()) {
+            if (query.isNull(0) == false) {
+                userInfo->id              = query.value(0).toInt();
+                userInfo->userName        = query.value(1).toString();
+                userInfo->userNo          = query.value(2).toString();
+                userInfo->password        = query.value(3).toString();
+                userInfo->role            = static_cast<QFUser::Role>(query.value(4).toInt());
+                userInfo->post            = query.value(5).toString();
+                userInfo->major           = query.value(6).toString();
+                userInfo->workPosition    = query.value(7).toString();
+                userInfo->educationDegree = query.value(8).toString();
+                userInfo->phone           = query.value(9).toString();
+                userInfo->remark          = query.value(10).toString();
+                userInfo->projectId       = query.value(11).toString();
+                userInfo->writeTime       = query.value(12).toString();
+            }
+            ret = true;
+        }
+    } else {
+        qDebug() << query.lastError();
+    }
+    return ret;
+}
+
+bool UserService::UpdateUserInfo2(const QFUser &userInfo)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase2());
+        t.update("t_user_info")
+                .set("user_name", userInfo.userName)
+                .set("user_no", userInfo.userNo)
+                .set("password", userInfo.password)
+                .set("role", userInfo.role)
+                .set("post", userInfo.post)
+                .set("major", userInfo.major)
+                .set("work_position", userInfo.workPosition)
+                .set("education_degree", userInfo.educationDegree)
+                .set("phone", userInfo.phone)
+                .set("remark", userInfo.remark)
+                .set("project_id", userInfo.projectId)
+                .where("id=?", userInfo.id);
+        t.commit();
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+int UserService::AddUserInfo2(const QFUser &userInfo)
+{
+    int returnId = -1;
+    try {
+
+        Transaction t(SqlDBHelper::getDatabase2());
+        InsertQuery query = t.insertInto("t_user_info (id,user_name, user_no, password, role, post, "
+                                         "major,work_position,education_degree,phone,project_id,write_time)");
+        NonQueryResult result =
+                query.values(userInfo.id, userInfo.userName, userInfo.userNo, userInfo.password, userInfo.role,
+                             userInfo.post, userInfo.major, userInfo.workPosition, userInfo.educationDegree,
+                             userInfo.phone, userInfo.projectId, userInfo.writeTime)
+                        .exec();
+        t.commit();
+        returnId = result.lastInsertId().toInt();
+
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+        returnId = -1;
+    }
+    return returnId;
+}
+
+//////////////////////用户信息表-end////////////////////

+ 41 - 0
QFD/dbService/UserService.h

@@ -0,0 +1,41 @@
+#ifndef USERSERVICE_H
+#define USERSERVICE_H
+#include "ClassSet.h"
+
+class UserService
+{
+public:
+    explicit UserService(QObject *parent = nullptr);
+    //添加信息
+    int AddUserInfo(const QFUser &userInfo);
+    /*修改用户信息*/
+    bool UpdateUserInfo(const QFUser &userInfo);
+    bool UpdateUserPassword(QString userNo, QString password);
+    bool UpdateUserById(QString userNo, QString password, int id);
+    /*根据用户id查询用户信息*/
+    bool QueryUserInfoById(QFUser *userInfo, int userId);
+    bool QueryUserInfoByUnserInfo(const QFUser &paramInfo, QFUser &queryInfo);
+    // int QueryUserInfoByUserNoAndPhone(QString);
+    /*根据列名称和列值模糊查询用户信息,列名称为实体类中的属性名称*/
+    bool QueryUserListByColumnAndColumnValue(QList<QFUser *> *userInfoList, QString columnName, QString columnValue);
+    bool QueryUserList(QList<QFUser *> *userInfoList);
+    bool QueryUserListNotAdmin(QList<QFUser *> *userInfoList);
+    /*根据用户编号删除用户信息*/
+    bool DeleteUserById(int Id);
+    bool QueryUserByNoAndPassword(QFUser *userInfo, QString userNo, QString password);
+    bool QueryUserByNo(QFUser *userInfo, QString userNo);
+    /*获取工程用户列表*/
+    bool QueryUserListByEngineerId(QList<QFUser *> *userInfoList, int engineerId);
+
+    //删除除管理管外的所有用户
+    bool DeleteUserByRole(int roleType);
+
+    //专家本地库查询信息
+    bool QueryUserInfoById2(QFUser *userInfo, int userId);
+
+    bool UpdateUserInfo2(const QFUser &userInfo);
+
+    int AddUserInfo2(const QFUser &userInfo);
+};
+
+#endif  // USERSERVICE_H

+ 6 - 2
QFD/dbService/dbService.pri

@@ -1,13 +1,17 @@
 HEADERS += \
     $$PWD/ClassSet.h \
     $$PWD/DBServiceSet.h \
+    $$PWD/EngineerService.h \
     $$PWD/ReturnMessage.h \
-    $$PWD/SqlDBHelper.h
+    $$PWD/SqlDBHelper.h \
+    $$PWD/UserService.h
 
 SOURCES += \
     $$PWD/ClassSet.cpp \
     $$PWD/DBServiceSet.cpp \
+    $$PWD/EngineerService.cpp \
     $$PWD/ReturnMessage.cpp \
-    $$PWD/SqlDBHelper.cpp
+    $$PWD/SqlDBHelper.cpp \
+    $$PWD/UserService.cpp
 
 FORMS +=

+ 2 - 1
QFD/main.cpp

@@ -4,6 +4,7 @@
 #include <QApplication>
 
 #include <QTranslator>
+#include <QSqlDatabase>
 
 #include <QDebug>
 
@@ -23,7 +24,7 @@ int main(int argc, char *argv[])
 
     MainWindow m;
     m.show();
-
+    qDebug() << QSqlDatabase::drivers();
     Q_INIT_RESOURCE(qfluentwidgets);
 
     return a.exec();

+ 3 - 2
QFD/shemeTable/GroupPanelWidget.cpp

@@ -1,6 +1,7 @@
 #include "GroupPanelWidget.h"
 #include "GroupTableWidget.h"
 #include "dbService/DBServiceSet.h"
+#include "dbService/UserService.h"
 #include "ui_GroupPanelWidget.h"
 
 #include <QDebug>
@@ -187,14 +188,14 @@ void GroupPanelWidget::initPlainWidget(int engineerId)
     connect(table, &GroupTableWidget::returnModel, this, &GroupPanelWidget::getTableModel);
     //获取专家
     QList<QFUser *> userInfoList;
-    if (!DBServiceSet().QueryUserListByEngineerId(&userInfoList, engineerId)) {
+    if (!UserService().QueryUserListByEngineerId(&userInfoList, engineerId)) {
         // QMessageBox::critical(this, "异常", "数据库访问异常!");
         return;
     }
     //获取技术措施指标权重
     for (int i = 0; i < userInfoList.size(); i++) {
         const QFUser *user = userInfoList.at(i);
-        QString str          = "专家" + QString::number(i + 1) + "-" + user->userName;
+        QString str        = "专家" + QString::number(i + 1) + "-" + user->userName;
         UserConfig userConfig;
         DBServiceSet().QueryUserConfigListInfoByUserIdAndEngineerId(&userConfig, user->id, engineerId);
         table->addColNode(QString::number(user->id), str, QString::number(userConfig.weight / 100));

+ 6 - 5
QFD/shemeTable/ProfessionInfo.cpp

@@ -1,6 +1,7 @@
 #include "ProfessionInfo.h"
 #include "ui_ProfessionInfo.h"
 #include "dbService/DBServiceSet.h"
+#include "dbService/UserService.h"
 #include <QAction>
 #include <QCryptographicHash>
 
@@ -217,12 +218,12 @@ void ProfessionalInfo::on_saveBtn_clicked()
 
     if (m_completeIt) {
         user.id = m_userId;
-        if (!DBServiceSet().UpdateUserInfo(user)) {
+        if (!UserService().UpdateUserInfo(user)) {
             ui->errorMsglabel->setText("更新用户信息出错!");
             return;
         }
     } else {
-        if (-1 == DBServiceSet().AddUserInfo(user)) {
+        if (-1 == UserService().AddUserInfo(user)) {
             ui->errorMsglabel->setText("用户名已存在或者数据库存储异常!");
             return;
         }
@@ -353,13 +354,13 @@ void ProfessionalInfo::on_sureButton_clicked()
     user.id = m_userId;
 
     QFUser info;
-    if (DBServiceSet().QueryUserInfoById2(&info, user.id)) {
-        if (!DBServiceSet().UpdateUserInfo2(user)) {
+    if (UserService().QueryUserInfoById2(&info, user.id)) {
+        if (!UserService().UpdateUserInfo2(user)) {
             ui->errorMsglabel->setText("更新用户信息出错!");
             return;
         }
     } else {
-        if (-1 == DBServiceSet().AddUserInfo2(user)) {
+        if (-1 == UserService().AddUserInfo2(user)) {
             ui->errorMsglabel->setText("用户名已存在或者数据库存储异常!");
             return;
         }

+ 4 - 3
QFD/shemeTable/UserConfigDlg.cpp

@@ -1,6 +1,7 @@
 #include "UserConfigDlg.h"
 #include "ui_UserConfigDlg.h"
 #include "dbService/DBServiceSet.h"
+#include "dbService/UserService.h"
 
 #include <QDoubleSpinBox>
 #include <QComboBox>
@@ -36,7 +37,7 @@ void UserConfigDlg::userItemClicked(QListWidgetItem *item)
 {
     int id = item->data(Qt::UserRole).toInt();
     QFUser user;
-    if (!DBServiceSet().QueryUserInfoById(&user, id)) {
+    if (!UserService().QueryUserInfoById(&user, id)) {
         qDebug() << "用户 " << item->text() << " " << id << " 数据库查询失败!";
         return;
     }
@@ -291,7 +292,7 @@ void UserConfigDlg::deleteUserAction()
     QListWidgetItem *curItem = ui->listWidget->currentItem();
     if (curItem) {
         int userId = curItem->data(Qt::UserRole).toInt();
-        if (DBServiceSet().DeleteUserById(userId)) {
+        if (UserService().DeleteUserById(userId)) {
             DBServiceSet().DeleteUserConfigByUserId(userId);
             ui->tableWidget->clearContents();
             ui->tableWidget->setRowCount(0);
@@ -332,7 +333,7 @@ void UserConfigDlg::init()
 void UserConfigDlg::refreshUserList()
 {
     QList<QFUser *> users;
-    if (!DBServiceSet().QueryUserList(&users)) {
+    if (!UserService().QueryUserList(&users)) {
         qDebug() << "用户数据库查询失败!";
         return;
     }

+ 2 - 2
QFD/view/ExpertManageView.cpp

@@ -8,7 +8,7 @@
 #include "ExpertManager.h"
 #include "QFDAlert.h"
 
-#include <dbService/DBServiceSet.h>
+#include <dbService/UserService.h>
 
 #include <Widgets/Button.h>
 #include <Widgets/LineEdit.h>
@@ -137,7 +137,7 @@ void ExpertManageView::refreshList()
 {
     qDeleteAll(m_userList);
     m_userList.clear();
-    if (!DBServiceSet().QueryUserListNotAdmin(&m_userList)) {
+    if (!UserService().QueryUserListNotAdmin(&m_userList)) {
         QFDAlert::showAlertWithCode(QF_CODE_DATA_ERROR, this);
         return;
     }

+ 6 - 0
bin/datasource.ini

@@ -0,0 +1,6 @@
+[DATASOURCE]
+url=101.43.129.26
+username=root
+password=Lab501db#
+port=3306
+database=qfd