mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
Report upgrade WH
This commit is contained in:
844
LibDataBaseInterface/databaselms_tasks_fim.cpp
Normal file
844
LibDataBaseInterface/databaselms_tasks_fim.cpp
Normal file
@@ -0,0 +1,844 @@
|
||||
#include "databaselms.h"
|
||||
|
||||
#include <QtSql>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlDriver>
|
||||
|
||||
int DataBaseLMS::insertTaskFIM(TaskAmmFim task, int id_trainee)
|
||||
{
|
||||
QString queryStr;
|
||||
bool resBool = false;
|
||||
|
||||
resBool = db->transaction();
|
||||
|
||||
task.title = task.title.replace("'", "''"); //Задваиваем одинарные кавычки
|
||||
|
||||
queryStr = QString("INSERT INTO public.tasks_fim (title, fk_trainee_id) "
|
||||
"VALUES ('%1', %2) "
|
||||
"RETURNING tasks_fim.task_id").arg(
|
||||
task.title,
|
||||
QString::number(id_trainee));
|
||||
|
||||
int task_id = queryExecInt(queryStr);
|
||||
if(!task_id)
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(Malfunction malfanction : task.malfunctionList)
|
||||
{
|
||||
malfanction.description = malfanction.description.replace("'", "''"); //Задваиваем одинарные кавычки
|
||||
|
||||
queryStr = QString("INSERT INTO public.malfunctions (num, dm_code, description, go_name, obj_name, fk_task_fim_id) "
|
||||
"VALUES ('%1', '%2', '%3', '%4', '%5', %6) "
|
||||
"RETURNING malfunctions.malfunction_id").arg(
|
||||
malfanction.num,
|
||||
malfanction.dmCode,
|
||||
malfanction.description,
|
||||
malfanction.goName,
|
||||
malfanction.objName,
|
||||
QString::number(task_id));
|
||||
|
||||
int malfunction_id = queryExecInt(queryStr);
|
||||
if(!malfunction_id)
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Sign
|
||||
for(MalfunctionSign sign : malfanction.malfunctionSigns)
|
||||
{
|
||||
sign.description = sign.description.replace("'", "''"); //Задваиваем одинарные кавычки
|
||||
|
||||
queryStr = QString("INSERT INTO public.malf_signs (type, description, fk_malfunction_id) "
|
||||
"VALUES ('%1', '%2', %3) "
|
||||
"RETURNING malf_signs.sign_id").arg(
|
||||
QString::number(sign.type),
|
||||
sign.description,
|
||||
QString::number(malfunction_id));
|
||||
|
||||
if(!queryExecInt(queryStr))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resBool = db->commit();
|
||||
return task_id;
|
||||
}
|
||||
|
||||
int DataBaseLMS::updateTaskFIM(TaskAmmFim task)
|
||||
{
|
||||
task.title = task.title.replace("'", "''"); //Задваиваем одинарные кавычки
|
||||
|
||||
QString queryStr = QString("UPDATE public.tasks_fim SET title = '%1', status = '%2' "
|
||||
"WHERE task_id = %3 "
|
||||
"RETURNING tasks_fim.task_id").arg(
|
||||
task.title,
|
||||
task.status,
|
||||
QString::number(task.getID()) );
|
||||
|
||||
return queryExecInt(queryStr);
|
||||
}
|
||||
|
||||
int DataBaseLMS::updateStatusTaskFIM(int task_id, QString status)
|
||||
{
|
||||
QString queryStr;
|
||||
bool resBool = false;
|
||||
int id_trainee = 0;
|
||||
|
||||
resBool = db->transaction();
|
||||
|
||||
queryStr = QString("SELECT users.user_id "
|
||||
"FROM public.users JOIN public.tasks_fim ON users.user_id = tasks_fim.fk_trainee_id "
|
||||
"WHERE tasks_fim.task_id = %1 "
|
||||
"ORDER BY users.user_id ASC").arg(
|
||||
QString::number(task_id));
|
||||
|
||||
QSqlQuery query = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &query))
|
||||
{
|
||||
if (query.first())
|
||||
{//Обучаемый
|
||||
id_trainee = query.value(0).toInt();
|
||||
}
|
||||
}
|
||||
if(!id_trainee)
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
queryStr = QString("UPDATE public.tasks_fim SET status = '%1' "
|
||||
"WHERE task_id = %2 "
|
||||
"RETURNING tasks_fim.task_id").arg(
|
||||
status,
|
||||
QString::number(task_id) );
|
||||
|
||||
QSqlQuery query1 = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &query1))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(status == "new")
|
||||
{//Удаляем отчет
|
||||
queryStr = QString("SELECT reports.report_id "
|
||||
"FROM public.reports "
|
||||
"WHERE fk_task_fim_id = %1 "
|
||||
"ORDER BY reports.report_id ASC").arg(
|
||||
QString::number(task_id));
|
||||
|
||||
int report_id = 0;
|
||||
|
||||
QSqlQuery queryReportsSEL = QSqlQuery(*db);
|
||||
if(queryExec(queryStr, &queryReportsSEL))
|
||||
{
|
||||
if (queryReportsSEL.first())
|
||||
{//Отчет
|
||||
report_id = queryReportsSEL.value(0).toInt();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
queryStr = QString("DELETE FROM public.report_items "
|
||||
"WHERE fk_report_id = %1 ").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryItemsDEL = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &queryItemsDEL))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
queryStr = QString("DELETE FROM public.report_wh_items "
|
||||
"WHERE fk_report_id = %1 ").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryWhItemsDEL = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &queryWhItemsDEL))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
queryStr = QString("DELETE FROM public.reports "
|
||||
"WHERE report_id = %1 ").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryReportsDEL = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &queryReportsDEL))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
resBool = db->commit();
|
||||
return id_trainee;
|
||||
}
|
||||
|
||||
int DataBaseLMS::deleteTaskFIM(int id_task)
|
||||
{
|
||||
QString queryStr;
|
||||
bool resBool = false;
|
||||
int id_trainee = 0;
|
||||
|
||||
resBool = db->transaction();
|
||||
|
||||
queryStr = QString("SELECT users.user_id "
|
||||
"FROM public.users JOIN public.tasks_fim ON users.user_id = tasks_fim.fk_trainee_id "
|
||||
"WHERE tasks_fim.task_id = %1 "
|
||||
"ORDER BY users.user_id ASC").arg(
|
||||
QString::number(id_task));
|
||||
|
||||
QSqlQuery queryUserSEL = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &queryUserSEL))
|
||||
{
|
||||
if (queryUserSEL.first())
|
||||
{//Обучаемый
|
||||
id_trainee = queryUserSEL.value(0).toInt();
|
||||
}
|
||||
}
|
||||
if(!id_trainee)
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Выгребаем все malfunction для этой задачи
|
||||
queryStr = QString("SELECT malfunctions.malfunction_id "
|
||||
"FROM public.malfunctions JOIN public.tasks_fim ON tasks_fim.task_id = malfunctions.fk_task_fim_id "
|
||||
"WHERE malfunctions.fk_task_fim_id = %1 "
|
||||
"ORDER BY malfunctions.malfunction_id ASC").arg(
|
||||
id_task);
|
||||
QSqlQuery queryMalfSEL = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &queryMalfSEL))
|
||||
{
|
||||
while (queryMalfSEL.next())
|
||||
{//Неисправность
|
||||
int malfunction_id = 0;
|
||||
|
||||
malfunction_id = queryMalfSEL.value(0).toString().toInt();
|
||||
|
||||
if(malfunction_id)
|
||||
{
|
||||
queryStr = QString("DELETE FROM public.malf_signs "
|
||||
"WHERE fk_malfunction_id = %1 ").arg(
|
||||
malfunction_id);
|
||||
|
||||
QSqlQuery querySignDEL = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &querySignDEL))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
queryStr = QString("DELETE FROM public.malfunctions "
|
||||
"WHERE fk_task_fim_id = %1 ").arg(
|
||||
QString::number(id_task));
|
||||
|
||||
QSqlQuery queryMulfDEL = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &queryMulfDEL))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
queryStr = QString("SELECT reports.report_id "
|
||||
"FROM public.reports "
|
||||
"WHERE fk_task_fim_id = %1 "
|
||||
"ORDER BY reports.report_id ASC").arg(
|
||||
QString::number(id_task));
|
||||
|
||||
int report_id = 0;
|
||||
|
||||
QSqlQuery queryReportsSEL = QSqlQuery(*db);
|
||||
if(queryExec(queryStr, &queryReportsSEL))
|
||||
{
|
||||
if (queryReportsSEL.first())
|
||||
{//Отчет
|
||||
report_id = queryReportsSEL.value(0).toInt();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
queryStr = QString("DELETE FROM public.report_items "
|
||||
"WHERE fk_report_id = %1 ").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryItemsDEL = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &queryItemsDEL))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
queryStr = QString("DELETE FROM public.report_wh_items "
|
||||
"WHERE fk_report_id = %1 ").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryWhItemsDEL = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &queryWhItemsDEL))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
queryStr = QString("DELETE FROM public.reports "
|
||||
"WHERE report_id = %1 ").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryReportsDEL = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &queryReportsDEL))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
queryStr = QString("DELETE FROM public.tasks_fim "
|
||||
"WHERE task_id = %1 "
|
||||
"RETURNING tasks_fim.task_id").arg(
|
||||
QString::number(id_task));
|
||||
|
||||
if(!queryExecInt(queryStr))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
resBool = db->commit();
|
||||
return id_trainee;
|
||||
}
|
||||
|
||||
QList<TaskAmmFim> DataBaseLMS::selectTasksFIMofTrainee(int id_trainee)
|
||||
{
|
||||
QList<TaskAmmFim> listTasks;
|
||||
QString queryStr;
|
||||
bool resBool = false;
|
||||
|
||||
resBool = db->transaction();
|
||||
|
||||
queryStr = QString("SELECT tasks_fim.task_id, tasks_fim.title, tasks_fim.status, "
|
||||
"users.user_id "
|
||||
"FROM public.tasks_fim JOIN public.users ON users.user_id = tasks_fim.fk_trainee_id "
|
||||
"WHERE tasks_fim.fk_trainee_id = %1 "
|
||||
"ORDER BY tasks_fim.task_id ASC").arg(
|
||||
id_trainee);
|
||||
|
||||
QSqlQuery query = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &query))
|
||||
{
|
||||
while (query.next())
|
||||
{//Задача
|
||||
TaskAmmFim task;
|
||||
|
||||
task.setID(query.value(0).toInt());
|
||||
task.title = query.value(1).toString();
|
||||
task.status = query.value(2).toString();
|
||||
|
||||
//Выгребаем все malfunction для этой задачи
|
||||
queryStr = QString("SELECT malfunctions.malfunction_id, malfunctions.num, malfunctions.dm_code, malfunctions.description, malfunctions.go_name, malfunctions.obj_name, "
|
||||
"tasks_fim.task_id "
|
||||
"FROM public.malfunctions JOIN public.tasks_fim ON tasks_fim.task_id = malfunctions.fk_task_fim_id "
|
||||
"WHERE malfunctions.fk_task_fim_id = %1 "
|
||||
"ORDER BY malfunctions.num ASC").arg(
|
||||
task.getID());
|
||||
|
||||
QSqlQuery queryMalf = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &queryMalf))
|
||||
{
|
||||
while (queryMalf.next())
|
||||
{//Неисправность
|
||||
Malfunction malfanction;
|
||||
int malfunction_id = 0;
|
||||
|
||||
malfunction_id = queryMalf.value(0).toString().toInt();
|
||||
malfanction.num = queryMalf.value(1).toString();
|
||||
malfanction.dmCode = queryMalf.value(2).toString();
|
||||
malfanction.description = queryMalf.value(3).toString();
|
||||
malfanction.goName = queryMalf.value(4).toString();
|
||||
malfanction.objName = queryMalf.value(5).toString();
|
||||
|
||||
//Выгребаем сигналы для этой неисправности
|
||||
queryStr = QString("SELECT malf_signs.sign_id, malf_signs.type, malf_signs.description "
|
||||
"FROM public.malf_signs "
|
||||
"WHERE fk_malfunction_id = %1 "
|
||||
"ORDER BY malf_signs.sign_id ASC").arg(
|
||||
QString::number(malfunction_id));
|
||||
|
||||
QSqlQuery querySign = QSqlQuery(*db);
|
||||
if(queryExec(queryStr, &querySign))
|
||||
{
|
||||
while (querySign.next())
|
||||
{//Сигналы
|
||||
MalfunctionSign sign;
|
||||
sign.type = querySign.value(1).toString().toInt();
|
||||
sign.description = querySign.value(2).toString();
|
||||
|
||||
malfanction.malfunctionSigns.append(sign);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return QList<TaskAmmFim>();
|
||||
}
|
||||
|
||||
task.addMalfunction(malfanction);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return QList<TaskAmmFim>();
|
||||
}
|
||||
|
||||
|
||||
//Выгребаем отчет для этой задачи
|
||||
int report_id = 0;
|
||||
queryStr = QString("SELECT reports.report_id "
|
||||
"FROM public.reports "
|
||||
"WHERE fk_task_fim_id = %1 "
|
||||
"ORDER BY reports.report_id ASC").arg(
|
||||
QString::number(task.getID()));
|
||||
|
||||
QSqlQuery queryReport = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &queryReport))
|
||||
{
|
||||
if (queryReport.first())
|
||||
{//Отчет
|
||||
report_id = queryReport.value(0).toInt();
|
||||
task.report.id = report_id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return QList<TaskAmmFim>();
|
||||
}
|
||||
|
||||
if(report_id)
|
||||
{//Отчет есть
|
||||
//Выгребаем все item отчета
|
||||
|
||||
queryStr = QString("SELECT report_items.item_id, report_items.text, report_items.doc, report_items.dm_code, report_items.title, report_items.result, report_items.fk_report_id, report_items.number "
|
||||
"FROM public.report_items "
|
||||
"WHERE fk_report_id = %1 "
|
||||
"ORDER BY report_items.number ASC").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryItems = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &queryItems))
|
||||
{
|
||||
while (queryItems.next())
|
||||
{//report_item
|
||||
FIMReportItem reportItem;
|
||||
reportItem.id = queryItems.value(0).toInt();
|
||||
reportItem.text = queryItems.value(1).toString();
|
||||
reportItem.procedure.doc = queryItems.value(2).toString();
|
||||
reportItem.procedure.dmCode = queryItems.value(3).toString();
|
||||
reportItem.procedure.title = queryItems.value(4).toString();
|
||||
reportItem.procedure.result = queryItems.value(5).toString();
|
||||
//item_report
|
||||
//number
|
||||
|
||||
task.report.itemList.append(reportItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return QList<TaskAmmFim>();
|
||||
}
|
||||
|
||||
//Выгребаем все wh_item отчета
|
||||
|
||||
queryStr = QString("SELECT report_wh_items.wh_item_id, report_wh_items.status, report_wh_items.go_name, report_wh_items.obj_name, report_wh_items.fk_report_id, report_wh_items.number "
|
||||
"FROM public.report_wh_items "
|
||||
"WHERE fk_report_id = %1 "
|
||||
"ORDER BY report_wh_items.number ASC").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryWhItems = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &queryWhItems))
|
||||
{
|
||||
while (queryWhItems.next())
|
||||
{//report_wh_item
|
||||
FIMReportWarehouseItem reportWhItem;
|
||||
reportWhItem.id = queryWhItems.value(0).toInt();
|
||||
reportWhItem.status = queryWhItems.value(1).toInt();
|
||||
reportWhItem.goName = queryWhItems.value(2).toString();
|
||||
reportWhItem.objName = queryWhItems.value(3).toString();
|
||||
|
||||
task.report.warehouseItemList.append(reportWhItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return QList<TaskAmmFim>();
|
||||
}
|
||||
}
|
||||
|
||||
listTasks.append(task);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return QList<TaskAmmFim>();
|
||||
}
|
||||
|
||||
resBool = db->commit();
|
||||
return listTasks;
|
||||
}
|
||||
|
||||
TaskAmmFim DataBaseLMS::selectTaskFIMbyID(int id_task)
|
||||
{
|
||||
TaskAmmFim task;
|
||||
|
||||
QString queryStr;
|
||||
bool resBool = false;
|
||||
|
||||
resBool = db->transaction();
|
||||
|
||||
queryStr = QString("SELECT tasks_fim.task_id, tasks_fim.title, tasks_fim.status "
|
||||
"FROM public.tasks_fim "
|
||||
"WHERE tasks_fim.task_id = %1 "
|
||||
"ORDER BY tasks_fim.task_id ASC").arg(
|
||||
id_task);
|
||||
|
||||
QSqlQuery query = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &query))
|
||||
{
|
||||
if(query.first())
|
||||
{//Задача
|
||||
|
||||
task.setID(query.value(0).toInt());
|
||||
task.title = query.value(1).toString();
|
||||
task.status = query.value(2).toString();
|
||||
|
||||
//Выгребаем все malfunction для этой задачи
|
||||
queryStr = QString("SELECT malfunctions.malfunction_id, malfunctions.num, malfunctions.dm_code, malfunctions.description, malfunctions.go_name, malfunctions.obj_name, "
|
||||
"tasks_fim.task_id "
|
||||
"FROM public.malfunctions JOIN public.tasks_fim ON tasks_fim.task_id = malfunctions.fk_task_fim_id "
|
||||
"WHERE malfunctions.fk_task_fim_id = %1 "
|
||||
"ORDER BY malfunctions.num ASC").arg(
|
||||
task.getID());
|
||||
|
||||
QSqlQuery queryMalf = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &queryMalf))
|
||||
{
|
||||
while (queryMalf.next())
|
||||
{//Неисправность
|
||||
Malfunction malfanction;
|
||||
int malfunction_id = 0;
|
||||
|
||||
malfunction_id = queryMalf.value(0).toString().toInt();
|
||||
malfanction.num = queryMalf.value(1).toString();
|
||||
malfanction.dmCode = queryMalf.value(2).toString();
|
||||
malfanction.description = queryMalf.value(3).toString();
|
||||
malfanction.goName = queryMalf.value(4).toString();
|
||||
malfanction.objName = queryMalf.value(5).toString();
|
||||
|
||||
//Выгребаем сигналы для этой неисправности
|
||||
queryStr = QString("SELECT malf_signs.sign_id, malf_signs.type, malf_signs.description "
|
||||
"FROM public.malf_signs "
|
||||
"WHERE fk_malfunction_id = %1 "
|
||||
"ORDER BY malf_signs.sign_id ASC").arg(
|
||||
QString::number(malfunction_id));
|
||||
|
||||
QSqlQuery querySign = QSqlQuery(*db);
|
||||
if(queryExec(queryStr, &querySign))
|
||||
{
|
||||
while (querySign.next())
|
||||
{//Сигналы
|
||||
MalfunctionSign sign;
|
||||
sign.type = querySign.value(1).toString().toInt();
|
||||
sign.description = querySign.value(2).toString();
|
||||
|
||||
malfanction.malfunctionSigns.append(sign);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return TaskAmmFim();
|
||||
}
|
||||
|
||||
task.addMalfunction(malfanction);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return TaskAmmFim();
|
||||
}
|
||||
|
||||
|
||||
//Выгребаем отчет для этой задачи
|
||||
int report_id = 0;
|
||||
queryStr = QString("SELECT reports.report_id "
|
||||
"FROM public.reports "
|
||||
"WHERE fk_task_fim_id = %1 "
|
||||
"ORDER BY reports.report_id ASC").arg(
|
||||
QString::number(task.getID()));
|
||||
|
||||
QSqlQuery queryReport = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &queryReport))
|
||||
{
|
||||
if (queryReport.first())
|
||||
{//Отчет
|
||||
report_id = queryReport.value(0).toInt();
|
||||
task.report.id = report_id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return TaskAmmFim();
|
||||
}
|
||||
|
||||
if(report_id)
|
||||
{//Отчет есть
|
||||
//Выгребаем все item отчета
|
||||
|
||||
queryStr = QString("SELECT report_items.item_id, report_items.text, report_items.doc, report_items.dm_code, report_items.title, report_items.result, report_items.fk_report_id, report_items.number "
|
||||
"FROM public.report_items "
|
||||
"WHERE fk_report_id = %1 "
|
||||
"ORDER BY report_items.number ASC").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryItems = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &queryItems))
|
||||
{
|
||||
while (queryItems.next())
|
||||
{//report_item
|
||||
FIMReportItem reportItem;
|
||||
reportItem.id = queryItems.value(0).toInt();
|
||||
reportItem.text = queryItems.value(1).toString();
|
||||
reportItem.procedure.doc = queryItems.value(2).toString();
|
||||
reportItem.procedure.dmCode = queryItems.value(3).toString();
|
||||
reportItem.procedure.title = queryItems.value(4).toString();
|
||||
reportItem.procedure.result = queryItems.value(5).toString();
|
||||
//item_report
|
||||
//number
|
||||
|
||||
task.report.itemList.append(reportItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return TaskAmmFim();
|
||||
}
|
||||
|
||||
//Выгребаем все wh_item отчета
|
||||
|
||||
queryStr = QString("SELECT report_wh_items.wh_item_id, report_wh_items.status, report_wh_items.go_name, report_wh_items.obj_name, report_wh_items.fk_report_id, report_wh_items.number "
|
||||
"FROM public.report_wh_items "
|
||||
"WHERE fk_report_id = %1 "
|
||||
"ORDER BY report_wh_items.number ASC").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryWhItems = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &queryWhItems))
|
||||
{
|
||||
while (queryWhItems.next())
|
||||
{//report_wh_item
|
||||
FIMReportWarehouseItem reportWhItem;
|
||||
reportWhItem.id = queryWhItems.value(0).toInt();
|
||||
reportWhItem.status = queryWhItems.value(1).toInt();
|
||||
reportWhItem.goName = queryWhItems.value(2).toString();
|
||||
reportWhItem.objName = queryWhItems.value(3).toString();
|
||||
|
||||
task.report.warehouseItemList.append(reportWhItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return TaskAmmFim();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return TaskAmmFim();
|
||||
}
|
||||
|
||||
resBool = db->commit();
|
||||
return task;
|
||||
}
|
||||
|
||||
int DataBaseLMS::updateReportFIMforTask(TaskAmmFim task)
|
||||
{
|
||||
QString queryStr;
|
||||
bool resBool = false;
|
||||
int report_id = 0;
|
||||
int task_id = task.getID();
|
||||
|
||||
resBool = db->transaction();
|
||||
|
||||
queryStr = QString("SELECT reports.report_id "
|
||||
"FROM public.reports "
|
||||
"WHERE fk_task_fim_id = %1 "
|
||||
"ORDER BY reports.report_id ASC").arg(
|
||||
QString::number(task_id));
|
||||
|
||||
QSqlQuery queryReportsSEL = QSqlQuery(*db);
|
||||
|
||||
if(queryExec(queryStr, &queryReportsSEL))
|
||||
{
|
||||
if (queryReportsSEL.first())
|
||||
{//Отчет
|
||||
report_id = queryReportsSEL.value(0).toInt();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!report_id)
|
||||
{
|
||||
queryStr = QString("INSERT INTO public.reports (fk_task_fim_id, mmel) "
|
||||
"VALUES (%1, %2) "
|
||||
"RETURNING reports.report_id").arg(
|
||||
task.getID(),
|
||||
task.report.mmel);
|
||||
|
||||
report_id = queryExecInt(queryStr);
|
||||
if(!report_id)
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
queryStr = QString("DELETE FROM public.report_items "
|
||||
"WHERE fk_report_id = %1 ").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryItemsDEL = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &queryItemsDEL))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
queryStr = QString("DELETE FROM public.report_wh_items "
|
||||
"WHERE fk_report_id = %1 ").arg(
|
||||
QString::number(report_id));
|
||||
|
||||
QSqlQuery queryWhItemsDEL = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &queryWhItemsDEL))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int number = 0;
|
||||
for(FIMReportItem reportItem : task.report.itemList)
|
||||
{
|
||||
queryStr = QString("INSERT INTO public.report_items (text, doc, dm_code, title, result, fk_report_id, number) "
|
||||
"VALUES ('%1', '%2', '%3', '%4', '%5', %6, %7) "
|
||||
"RETURNING report_items.item_id").arg(
|
||||
reportItem.text,
|
||||
reportItem.procedure.doc,
|
||||
reportItem.procedure.dmCode,
|
||||
reportItem.procedure.title,
|
||||
reportItem.procedure.result,
|
||||
QString::number(report_id),
|
||||
QString::number(++number));
|
||||
|
||||
if(!queryExecInt(queryStr))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
number = 0;
|
||||
for(FIMReportWarehouseItem reportWhItem : task.report.warehouseItemList)
|
||||
{
|
||||
queryStr = QString("INSERT INTO public.report_wh_items (status, go_name, obj_name, code, fk_report_id, number) "
|
||||
"VALUES ('%1', '%2', '%3', '%4', %5, %6) "
|
||||
"RETURNING report_wh_items.wh_item_id").arg(
|
||||
QString::number(reportWhItem.status),
|
||||
reportWhItem.goName,
|
||||
reportWhItem.objName,
|
||||
reportWhItem.code,
|
||||
QString::number(report_id),
|
||||
QString::number(++number));
|
||||
|
||||
if(!queryExecInt(queryStr))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
queryStr = QString("UPDATE public.tasks_fim SET status = '%1' "
|
||||
"WHERE task_id = %2 ").arg(
|
||||
"checkup",
|
||||
QString::number(task_id) );
|
||||
|
||||
QSqlQuery queryTaskUPD = QSqlQuery(*db);
|
||||
if(!queryExec(queryStr, &queryTaskUPD))
|
||||
{
|
||||
resBool = db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
resBool = db->commit();
|
||||
return report_id;
|
||||
}
|
||||
Reference in New Issue
Block a user