add: implement API-Endpoint GisStationsStatusDistrict.js for icons prio "Le" and Color

This commit is contained in:
ISA
2024-06-25 09:35:25 +02:00
parent 01d9a2945a
commit a6e2e5a4f2
4 changed files with 197 additions and 260 deletions

View File

@@ -478,60 +478,6 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
initMap.flyTo([x, y], zoom);
}
//------------------------------------------
/* const getIconPath = (status, iconNumber, marker) => {
let path = status
? `img/icons/${status}-marker-icon-${iconNumber}.png`
: `img/icons/marker-icon-${iconNumber}.png`;
for (let priority of priorityConfig) {
if (path.includes(priority.name.toLowerCase())) {
marker.setBouncingOptions({
bounceHeight: 15,
contractHeight: 12,
bounceSpeed: 52,
contractSpeed: 52,
shadowAngle: null,
});
if (path.includes(priority.name.toLowerCase())) {
marker.bounce(3);
}
break;
}
}
return path;
}; */
//---------
/* function getIconPath(status, iconNumber, marker) {
let path = status
? `img/icons/${status}-marker-icon-${iconNumber}.png`
: `img/icons/marker-icon-${iconNumber}.png`;
// Wenn der Pfad das Wort "critical" oder "major" enthält, dann den Marker bouncing options setzen
if (
//Stationsausfall
path.includes("Stationsausfall") || // Priorität 1, Level 0
path.includes("critical") || // Priorität 2, Level 1
path.includes("major") || // Priorität 3, Level 2
path.includes("minor") || // Priorität 4, Level 3
path.includes("system") // Priorität 5, Level 4
) {
// Setze Bouncing-Optionen
marker.setBouncingOptions({
bounceHeight: 15, // Höhe des Bounces
contractHeight: 12, // Höhe des Einzugs beim Landen
bounceSpeed: 52, // Geschwindigkeit des Bounces
contractSpeed: 52, // Geschwindigkeit des Einzugs
shadowAngle: null, // Standard-Schattenwinkel
});
// Check if the icon path includes 'critical'
if (path.includes("critical")) {
// marker.bounce(3);
}
}
return path;
} */
//------------------------------------------
// Funktionen zur Überwachung der Internetverbindung
const checkInternet = () => {

98
package-lock.json generated
View File

@@ -1,5 +1,5 @@
{
"name": "nodeMap 28.05.2024 branch Dev",
"name": "nodeMap 24.06.2024",
"lockfileVersion": 3,
"requires": true,
"packages": {
@@ -13,6 +13,7 @@
"leaflet.smooth_marker_bouncing": "^3.0.3",
"lodash": "^4.17.21",
"mysql": "^2.18.1",
"mysql2": "^3.10.1",
"next": "^14.2.3",
"overlapping-marker-spiderfier-leaflet": "^0.2.7",
"react": "^18.2.0",
@@ -869,6 +870,14 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/denque": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz",
"integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==",
"engines": {
"node": ">=0.10"
}
},
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
@@ -1212,6 +1221,14 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/generate-function": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz",
"integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==",
"dependencies": {
"is-property": "^1.0.2"
}
},
"node_modules/get-intrinsic": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz",
@@ -1468,6 +1485,11 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/is-property": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz",
"integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g=="
},
"node_modules/isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
@@ -1546,6 +1568,11 @@
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/long": {
"version": "5.2.3",
"resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz",
"integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q=="
},
"node_modules/loose-envify": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
@@ -1681,6 +1708,51 @@
"node": ">= 0.6"
}
},
"node_modules/mysql2": {
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.10.1.tgz",
"integrity": "sha512-6zo1T3GILsXMCex3YEu7hCz2OXLUarxFsxvFcUHWMpkPtmZLeTTWgRdc1gWyNJiYt6AxITmIf9bZDRy/jAfWew==",
"dependencies": {
"denque": "^2.1.0",
"generate-function": "^2.3.1",
"iconv-lite": "^0.6.3",
"long": "^5.2.1",
"lru-cache": "^8.0.0",
"named-placeholders": "^1.1.3",
"seq-queue": "^0.0.5",
"sqlstring": "^2.3.2"
},
"engines": {
"node": ">= 8.0"
}
},
"node_modules/mysql2/node_modules/iconv-lite": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/mysql2/node_modules/lru-cache": {
"version": "8.0.5",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.5.tgz",
"integrity": "sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==",
"engines": {
"node": ">=16.14"
}
},
"node_modules/mysql2/node_modules/sqlstring": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz",
"integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mz": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz",
@@ -1692,6 +1764,25 @@
"thenify-all": "^1.0.0"
}
},
"node_modules/named-placeholders": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz",
"integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==",
"dependencies": {
"lru-cache": "^7.14.1"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/named-placeholders/node_modules/lru-cache": {
"version": "7.18.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",
"integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==",
"engines": {
"node": ">=12"
}
},
"node_modules/nanoid": {
"version": "3.3.7",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz",
@@ -2390,6 +2481,11 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
},
"node_modules/seq-queue": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz",
"integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q=="
},
"node_modules/serve-static": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz",

View File

@@ -8,6 +8,7 @@
"leaflet.smooth_marker_bouncing": "^3.0.3",
"lodash": "^4.17.21",
"mysql": "^2.18.1",
"mysql2": "^3.10.1",
"next": "^14.2.3",
"overlapping-marker-spiderfier-leaflet": "^0.2.7",
"react": "^18.2.0",

View File

@@ -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();
}
}
}