Реализована передача репортов вместе с задачами

This commit is contained in:
2025-05-22 12:30:29 +03:00
parent 2b0e7c67d7
commit ab05d1fa61
4 changed files with 113 additions and 7 deletions

View File

@@ -810,6 +810,67 @@ QList<TaskAmmFim> DataBaseLMS::selectTasksFIMofTrainee(int id_trainee)
return QList<TaskAmmFim>();
}
//Выгребаем отчет для этой задачи
int report_id = 0;
queryStr = QString("SELECT reports.report_id "
"FROM public.reports "
"WHERE report_task = %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.item_report, report_items.number "
"FROM public.report_items "
"WHERE item_report = %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>();
}
}
listTasks.append(task);
};
}

View File

@@ -51,6 +51,7 @@ public:
FIMReportItem(){};
~FIMReportItem(){};
public:
int id = 0; // для идентификации в БД
QString text; // текст, вводимый обучаемым
ProcedureID procedure; // ссылка на процедуру, при необходимости
};
@@ -61,6 +62,7 @@ public:
FIMReport(){};
~FIMReport(){};
public:
int id = 0; // для идентификации в БД
QList<FIMReportItem> itemList;
};

View File

@@ -693,17 +693,41 @@ void RecognizeSystem::xmlParserQueryToDB(PacketType packetType, QByteArray array
task.status = taskNode.toElement().attribute("status");
for(int j = 0; j < taskNode.childNodes().count(); j++)
{//Неисправности
QDomNode malfunctionNode = taskNode.childNodes().at(j);
if(malfunctionNode.nodeName() == "malfunction")
{
{
QDomNode malfOrReportNode = taskNode.childNodes().at(j);
if(malfOrReportNode.nodeName() == "malfunction")
{//Неисправность
Malfunction malfunction;
malfunction.num = malfunctionNode.toElement().attribute("num");
malfunction.dmCode = malfunctionNode.toElement().attribute("dmCode");
malfunction.description = malfunctionNode.toElement().attribute("description");
malfunction.num = malfOrReportNode.toElement().attribute("num");
malfunction.dmCode = malfOrReportNode.toElement().attribute("dmCode");
malfunction.description = malfOrReportNode.toElement().attribute("description");
task.malfunctionList.append(malfunction);
}
else
if(malfOrReportNode.nodeName() == "report")
{//Отчет
FIMReport report;
report.id = malfOrReportNode.toElement().attribute("report_id").toInt();
for(int k = 0; k < malfOrReportNode.childNodes().count(); k++)
{
QDomNode reportItemNode = malfOrReportNode.childNodes().at(k);
if(reportItemNode.nodeName() == "reportItem")
{
FIMReportItem reportItem;
reportItem.id = reportItemNode.toElement().attribute("item_id").toInt();
reportItem.text = reportItemNode.toElement().attribute("text");
reportItem.procedure.title = reportItemNode.toElement().attribute("title");
reportItem.procedure.dmCode = reportItemNode.toElement().attribute("dmCode");
reportItem.procedure.result = reportItemNode.toElement().attribute("result");
report.itemList.append(reportItem);
}
}
task.report = report;
}
}
listTasks.append(task);

View File

@@ -153,6 +153,25 @@ QByteArray DBAnswerParser::listTasksFIMofTrainee(bool result, QList<TaskAmmFim>
malfunctionNode.toElement().setAttribute("num", malfunction.num);
malfunctionNode.toElement().setAttribute("description", malfunction.description);
}
{//FIMReport
FIMReport report = task.report;
QDomNode reportNode = commonDOM.createElement("report");
taskNode.appendChild(reportNode);
reportNode.toElement().setAttribute("report_id", report.id);
for(FIMReportItem reportItem : task.report.itemList)
{//report_item
QDomNode reportItemNode = commonDOM.createElement("reportItem");
reportNode.appendChild(reportItemNode);
reportItemNode.toElement().setAttribute("item_id", reportItem.id);
reportItemNode.toElement().setAttribute("text", reportItem.text);
reportItemNode.toElement().setAttribute("title", reportItem.procedure.title);
reportItemNode.toElement().setAttribute("dmCode", reportItem.procedure.dmCode);
reportItemNode.toElement().setAttribute("result", reportItem.procedure.result);
}
}
}
dataParser->saveDOMtoXML("ListTasksFIM.xml", &commonDOM);