add: implement API-Endpoint GisStationsStatusDistrict.js for icons prio "Le" and Color
This commit is contained in:
@@ -1,206 +1,100 @@
|
||||
// /pages/api/talas5/webserviceMap/GisStationsStatusDistrict.js
|
||||
const GisStationsStatusDistrict = {
|
||||
"Name": "Liste aller Statis der Geraete",
|
||||
"Zeitstempel": "2024-05-31T15:28:10.2538122+02:00",
|
||||
"IdMap": "10",
|
||||
"Statis": [
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE04 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE05 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE06 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE07 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE09 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE10 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE12 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE13 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE14 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE15 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE16 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "system",
|
||||
"Le": 4,
|
||||
"Co": "#FF00FF",
|
||||
"Me": "Eingang DE17 kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "minor",
|
||||
"Le": 3,
|
||||
"Co": "#FFFF00",
|
||||
"Me": "Eingang DE01 gehend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "minor",
|
||||
"Le": 3,
|
||||
"Co": "#FFFF00",
|
||||
"Me": "KÜG 07: Übersapnnung kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50004,
|
||||
"Na": "major",
|
||||
"Le": 2,
|
||||
"Co": "#FF9900",
|
||||
"Me": "Fahrbahntemperatur okay",
|
||||
"Feld": 53,
|
||||
"Icon": 25
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "critical",
|
||||
"Le": 1,
|
||||
"Co": "#FF0000",
|
||||
"Me": "KÜG 01: Isolationsminderung kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "critical",
|
||||
"Le": 1,
|
||||
"Co": "#FF0000",
|
||||
"Me": "KÜG 02: Isolationsminderung kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "critical",
|
||||
"Le": 1,
|
||||
"Co": "#FF0000",
|
||||
"Me": "KÜG 03: Isolationsminderung kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "critical",
|
||||
"Le": 1,
|
||||
"Co": "#FF0000",
|
||||
"Me": "KÜG 04: Isolationsminderung kommend",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
},
|
||||
{
|
||||
"IdLD": 50017,
|
||||
"Na": "critical",
|
||||
"Le": 1,
|
||||
"Co": "#FF0000",
|
||||
"Me": "Ping True",
|
||||
"Feld": 3,
|
||||
"Icon": 0
|
||||
}
|
||||
]
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_PORT,
|
||||
};
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { idMap, idUser } = req.query;
|
||||
|
||||
if (!idMap || !idUser) {
|
||||
res.status(400).json({ error: "idMap and idUser are required" });
|
||||
return;
|
||||
}
|
||||
|
||||
// Export an async function handler for the API route.
|
||||
export default async function handler(req, res) {
|
||||
// Initialize an empty params object to store query parameters.
|
||||
const params = {
|
||||
idMap: req.query.idMap,
|
||||
idUser: req.query.idUser
|
||||
};
|
||||
|
||||
// Check if the requested ID map and user match certain conditions.
|
||||
if (params.idMap === '10' && params.idUser === '484') {
|
||||
// If the conditions are met, return the GisStationsStatusDistrict object with a 200 status code.
|
||||
res.status(200).json(GisStationsStatusDistrict);
|
||||
} else {
|
||||
// If not, return a 404 error with the message "Not Found".
|
||||
res.status(404).send('Not Found');
|
||||
}
|
||||
};
|
||||
|
||||
let connection;
|
||||
try {
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
|
||||
let onlySystem = -1;
|
||||
let districtCounter = 0;
|
||||
|
||||
// Get onlySystem
|
||||
const [mapResult] = await connection.execute(
|
||||
"SELECT idsystem_typ FROM maps WHERE id = ?",
|
||||
[idMap]
|
||||
);
|
||||
if (mapResult.length > 0) {
|
||||
onlySystem = mapResult[0].idsystem_typ ?? -1;
|
||||
}
|
||||
|
||||
// Get districtCounter
|
||||
if (idUser > 0) {
|
||||
const [userLayerResult] = await connection.execute(
|
||||
"SELECT count(*) as count FROM user_User_layer1 WHERE iduser = ?",
|
||||
[idUser]
|
||||
);
|
||||
districtCounter = userLayerResult[0].count;
|
||||
}
|
||||
|
||||
// Get GisStatusStations
|
||||
let query = `
|
||||
SELECT ld.idLD, dc.message, p.level, p.name, p.color, ld.idDevice, de.isService, dc.idIcon
|
||||
FROM location as l
|
||||
LEFT JOIN location_coordinates AS co ON l.idLocation = co.idLocation and co.idMaps = ?
|
||||
LEFT JOIN location_device AS ld ON ld.idLocation = l.idLocation
|
||||
LEFT JOIN datapoint as d ON d.idLD = ld.idLD
|
||||
LEFT JOIN datapoint_conditions AS dc ON dc.idcondition = d.last_message_condition
|
||||
LEFT JOIN prio AS p ON p.idPrio = dc.idprio
|
||||
LEFT JOIN devices AS de ON de.idDevice = ld.idDevice
|
||||
LEFT JOIN area as a on a.idArea = l.idArea
|
||||
WHERE p.level < 100 AND co.X > 0
|
||||
`;
|
||||
|
||||
if (districtCounter > 0) {
|
||||
query += ` AND a.iddistrict IN (SELECT iddistrict FROM user_user_layer1 WHERE iduser = ?)`;
|
||||
}
|
||||
|
||||
if (onlySystem >= 0) {
|
||||
query += ` AND de.idsystem_typ = ?`;
|
||||
}
|
||||
|
||||
query += ` ORDER BY p.level desc`;
|
||||
|
||||
const queryParams = [idMap];
|
||||
if (districtCounter > 0) {
|
||||
queryParams.push(idUser);
|
||||
}
|
||||
if (onlySystem >= 0) {
|
||||
queryParams.push(onlySystem);
|
||||
}
|
||||
|
||||
const [results] = await connection.execute(query, queryParams);
|
||||
|
||||
const mpss = {
|
||||
IdMap: idMap.toString(),
|
||||
Statis: results.map((row) => ({
|
||||
IdLD: row.idLD ?? -1,
|
||||
Le: row.level ?? -1,
|
||||
Me: row.message ?? "?",
|
||||
Na: row.name ?? "?",
|
||||
Co: row.color ?? "#ffffff",
|
||||
Feld: row.idDevice ?? -1,
|
||||
Icon: row.idIcon ?? 0,
|
||||
})),
|
||||
};
|
||||
|
||||
res.status(200).json(mpss);
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Daten:", error);
|
||||
res.status(500).json({ error: "Interner Serverfehler" });
|
||||
} finally {
|
||||
if (connection) {
|
||||
await connection.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user