Endpoints réservoirs : état agrégé (Etat_systeme/Etat_entrees/alarmes). 4 domaines de lecture désormais couverts.
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
// Types de familles (cf TB_Familles.Type_source / TB_Events.Type_source) :
|
// Types de familles (cf TB_Familles.Type_source / TB_Events.Type_source) :
|
||||||
static const int TYPE_SOURCE_CIRCUIT = 1;
|
static const int TYPE_SOURCE_CIRCUIT = 1;
|
||||||
static const int TYPE_SOURCE_CAPTEUR = 2;
|
static const int TYPE_SOURCE_CAPTEUR = 2;
|
||||||
|
static const int TYPE_SOURCE_RESERVOIR = 3;
|
||||||
static const int TYPE_SOURCE_BATTERIE = 4;
|
static const int TYPE_SOURCE_BATTERIE = 4;
|
||||||
|
|
||||||
// États circuit (cf commentaire colonne TB_Circuits.Etat dans le schéma) :
|
// États circuit (cf commentaire colonne TB_Circuits.Etat dans le schéma) :
|
||||||
@@ -172,10 +173,11 @@ int main(int argc, char *argv[])
|
|||||||
if (type == "circuit") typeSource = TYPE_SOURCE_CIRCUIT;
|
if (type == "circuit") typeSource = TYPE_SOURCE_CIRCUIT;
|
||||||
else if (type == "batterie") typeSource = TYPE_SOURCE_BATTERIE;
|
else if (type == "batterie") typeSource = TYPE_SOURCE_BATTERIE;
|
||||||
else if (type == "capteur") typeSource = TYPE_SOURCE_CAPTEUR;
|
else if (type == "capteur") typeSource = TYPE_SOURCE_CAPTEUR;
|
||||||
|
else if (type == "reservoir") typeSource = TYPE_SOURCE_RESERVOIR;
|
||||||
else {
|
else {
|
||||||
QJsonObject err;
|
QJsonObject err;
|
||||||
err["status"] = "erreur";
|
err["status"] = "erreur";
|
||||||
err["message"] = "type non supporté (circuit, batterie, capteur)";
|
err["message"] = "type non supporté (circuit, batterie, capteur, reservoir)";
|
||||||
return withCors(QHttpServerResponse(QJsonDocument(err).toJson(), QHttpServerResponder::StatusCode::NotImplemented));
|
return withCors(QHttpServerResponse(QJsonDocument(err).toJson(), QHttpServerResponder::StatusCode::NotImplemented));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,6 +278,27 @@ int main(int argc, char *argv[])
|
|||||||
if (age > periodeObsolescenceNmea && etat < 1) etat = 1;
|
if (age > periodeObsolescenceNmea && etat < 1) etat = 1;
|
||||||
if ((etatCapteur > 0 || etatSysteme != 0) && etat < 2) etat = 2;
|
if ((etatCapteur > 0 || etatSysteme != 0) && etat < 2) etat = 2;
|
||||||
}
|
}
|
||||||
|
} else if (type == "reservoir") {
|
||||||
|
// Alarmes (Events) liées à cette famille :
|
||||||
|
QSqlQuery q2;
|
||||||
|
q2.prepare("SELECT COUNT(*) FROM TB_Events WHERE Type_source=:type AND Validite=1 AND Alarme_source>0 "
|
||||||
|
"AND Etat_test=1 AND ID_Source IN (SELECT Cle_primaire FROM TB_Reservoirs WHERE ID_Famille=:famille)");
|
||||||
|
q2.bindValue(":type", typeSource);
|
||||||
|
q2.bindValue(":famille", idFamille);
|
||||||
|
q2.exec();
|
||||||
|
if (q2.next() && q2.value(0).toInt() > 0) etat = 1;
|
||||||
|
|
||||||
|
// Défaut ordre des sondes AUX (Etat_entrees) ou Etat_systeme en défaut :
|
||||||
|
QSqlQuery q3;
|
||||||
|
q3.prepare("SELECT Etat_entrees, Etat_systeme FROM TB_Reservoirs "
|
||||||
|
"WHERE ID_Famille=:famille AND Priorite_affichage_accueil>0");
|
||||||
|
q3.bindValue(":famille", idFamille);
|
||||||
|
q3.exec();
|
||||||
|
while (q3.next()) {
|
||||||
|
const int etatEntrees = q3.value(0).toInt();
|
||||||
|
const int etatSysteme = q3.value(1).toInt();
|
||||||
|
if ((etatEntrees > 0 || etatSysteme != 0) && etat < 2) etat = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
@@ -303,10 +326,10 @@ int main(int argc, char *argv[])
|
|||||||
const QString type = query.queryItemValue("type");
|
const QString type = query.queryItemValue("type");
|
||||||
const QString familleStr = query.queryItemValue("famille");
|
const QString familleStr = query.queryItemValue("famille");
|
||||||
|
|
||||||
if (type != "circuit" && type != "batterie" && type != "capteur") {
|
if (type != "circuit" && type != "batterie" && type != "capteur" && type != "reservoir") {
|
||||||
QJsonObject err;
|
QJsonObject err;
|
||||||
err["status"] = "erreur";
|
err["status"] = "erreur";
|
||||||
err["message"] = "type non supporté (circuit, batterie, capteur)";
|
err["message"] = "type non supporté (circuit, batterie, capteur, reservoir)";
|
||||||
return withCors(QHttpServerResponse(QJsonDocument(err).toJson(), QHttpServerResponder::StatusCode::NotImplemented));
|
return withCors(QHttpServerResponse(QJsonDocument(err).toJson(), QHttpServerResponder::StatusCode::NotImplemented));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,6 +521,44 @@ int main(int argc, char *argv[])
|
|||||||
obj["obsolete"] = (typeEntrees == TYPE_ENTREES_NMEA && age > periodeObsolescenceNmea);
|
obj["obsolete"] = (typeEntrees == TYPE_ENTREES_NMEA && age > periodeObsolescenceNmea);
|
||||||
elements.append(obj);
|
elements.append(obj);
|
||||||
}
|
}
|
||||||
|
} else if (type == "reservoir") {
|
||||||
|
QSqlQuery q;
|
||||||
|
q.prepare(
|
||||||
|
"SELECT Cle_primaire, Nom, Etat_systeme, Niveau, Capacite, Logique, "
|
||||||
|
"(SELECT COUNT(*) FROM TB_Events WHERE Validite=1 AND Type_source=:type AND Alarme_source>0 AND Etat_test=1 "
|
||||||
|
"AND ID_Source=TB_Reservoirs.Cle_primaire) AS Nb_alarmes, "
|
||||||
|
"Etat_entrees "
|
||||||
|
"FROM TB_Reservoirs WHERE ID_Famille=:famille "
|
||||||
|
"ORDER BY Priorite_affichage_accueil"
|
||||||
|
);
|
||||||
|
q.bindValue(":type", TYPE_SOURCE_RESERVOIR);
|
||||||
|
q.bindValue(":famille", idFamille);
|
||||||
|
q.exec();
|
||||||
|
|
||||||
|
while (q.next()) {
|
||||||
|
const int etatSysteme = q.value(2).toInt();
|
||||||
|
const int nbAlarmes = q.value(6).toInt();
|
||||||
|
const int etatEntrees = q.value(7).toInt();
|
||||||
|
|
||||||
|
// État agrégé, même règle que le natif (mise_a_jour_reservoirs()) :
|
||||||
|
// rouge si Etat_systeme en défaut ou défaut d'ordre des sondes AUX,
|
||||||
|
// sinon orange si au moins une alarme, sinon vert.
|
||||||
|
int etat = 0;
|
||||||
|
if (etatSysteme < 0 || etatEntrees > 0) etat = 2;
|
||||||
|
else if (nbAlarmes > 0) etat = 1;
|
||||||
|
|
||||||
|
QJsonObject obj;
|
||||||
|
obj["id"] = q.value(0).toInt();
|
||||||
|
obj["nom"] = q.value(1).toString();
|
||||||
|
obj["etat_systeme"] = etatSysteme;
|
||||||
|
obj["niveau"] = q.value(3).toDouble();
|
||||||
|
obj["capacite"] = q.value(4).toDouble();
|
||||||
|
obj["logique"] = q.value(5).toInt();
|
||||||
|
obj["etat_events"] = nbAlarmes;
|
||||||
|
obj["etat_entrees"] = etatEntrees;
|
||||||
|
obj["etat"] = etat;
|
||||||
|
elements.append(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject reponse;
|
QJsonObject reponse;
|
||||||
|
|||||||
Reference in New Issue
Block a user