|
@@ -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;
|
|
|
+}
|