From 64bc633a6f12f52473c3e91c7f1a8b1f309e92a4 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Tue, 5 Aug 2025 18:49:04 +0200 Subject: [PATCH] updated importing fcps for rml compatibility --- .../ADBRimoFcp/ADBRimoFcpController.php | 51 ++++++++++++++----- public/js/pages/ADBRimoFcp/ADBRimoFcp.js | 8 +-- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/application/ADBRimoFcp/ADBRimoFcpController.php b/application/ADBRimoFcp/ADBRimoFcpController.php index 5a1c36fb2..8a8828081 100644 --- a/application/ADBRimoFcp/ADBRimoFcpController.php +++ b/application/ADBRimoFcp/ADBRimoFcpController.php @@ -28,6 +28,10 @@ class ADBRimoFcpController extends TTCrud { $this->columns[0]['modal']['items'] = $netzgebiete; } + public function afterInit() { + $this->model = ADBRimoFcp::class; + } + public function ImportFCPsAction() { $input = json_decode(file_get_contents('php://input'), true); $fcpList = $input['data'] ?? []; @@ -37,20 +41,30 @@ class ADBRimoFcpController extends TTCrud { $now = date('U'); foreach ($fcpList as $fcpIn) { - $rimoId = $fcpIn['ExternalID'] ?? null; - if ($rimoId === null) $rimoId = $fcpIn['External ID'] ?? null; + $rimoId = $fcpIn['ExternalID'] ?? $fcpIn['External ID'] ?? $fcpIn['Externe ID'] ?? null; if ($rimoId === null) continue; + if (!is_numeric($networkAreaId)) { + $netzgebiet = ADBNetzgebietModel::getFirst(['extref' => + explode(':', $fcpIn['FCP Cluster'] ?? '')[0] ?? 'DEFINETLY_NOT_A_VALID_EXTREF' + ]); + + if ($netzgebiet) { + $networkAreaId = $netzgebiet->id; + } else { + continue; + } + } $data = [ 'netzgebiet_id' => $networkAreaId, - 'name' => $fcpIn['Name'] ?? null, + 'name' => $fcpIn['Name'] ?? $fcpIn['Name/ID'] ?? null, 'rimo_id' => $rimoId, - 'label' => $fcpIn['User label'] ?? null, - 'building_type' => $fcpIn['Building type'] ?? null, - 'rimo_ex_state' => $fcpIn['Execution state'] ?? null, - 'rimo_op_state' => $fcpIn['Operational state'] ?? null, - 'gps_lat' => floatval(str_replace(',', '.', $fcpIn['Latitude'] ?? '0')), - 'gps_long' => floatval(str_replace(',', '.', $fcpIn['Longitude'] ?? '0')), + 'label' => $fcpIn['User label'] ?? $fcpIn['Bezeichnung'] ?? null, + 'building_type' => $fcpIn['Building type'] ?? $fcpIn['Typ'] ?? null, + 'rimo_ex_state' => $fcpIn['Execution state'] ?? $fcpIn['Ausführungsstatus'] ?? null, + 'rimo_op_state' => $fcpIn['Operational state'] ?? $fcpIn['Betriebszustand'] ?? null, + 'gps_lat' => isset($fcpIn['Latitude']) ? floatval(str_replace(',', '.', $fcpIn['Latitude'] ?? '0')) : null, + 'gps_long' => isset($fcpIn['Latitude']) ? floatval(str_replace(',', '.', $fcpIn['Longitude'] ?? '0')) : null, 'edit' => $now ]; @@ -79,9 +93,20 @@ class ADBRimoFcpController extends TTCrud { $counts = ['upd' => 0, 'fcpNF' => 0, 'noFCP' => 0, 'noExtId' => 0]; foreach ($input['data'] as $loc) { - $fcpName = trim($loc['FCP cluster name'] ?? ''); - $extId = $loc['ExternalID'] ?? null; - if ($extId === null) $extId = $loc['External ID'] ?? null; + if (empty($fcpsByName)) { + $fcpCluster = explode(':', $loc['FCP Cluster'] ?? ''); + $network = ADBNetzgebietModel::getFirst(['extref' => $fcpCluster[0] ?? '']); + if ($network) { + $fcpsByName = array_column(ADBRimoFcp::getAll(['netzgebiet_id' => $network->id]), null, 'name'); + } else { + $counts['fcpNF']++; + continue; + } + } + + $fcpName = trim($loc['FCP cluster name'] ?? $loc['FCP Clustername'] ?? ''); + $extId = $loc['ExternalID'] ?? $loc['Externe ID'] ?? null; + if ($extId === null) $extId = $loc['External ID'] ?? $loc['Externe ID'] ?? null; if ($fcpName === '') { $counts['noFCP']++; continue; } @@ -92,7 +117,7 @@ class ADBRimoFcpController extends TTCrud { if ($hn = ADBHausnummerModel::getFirst(['rimo_id' => $extId])) { $hn->fcp_id = $fcp->id; $hn->rimo_fcp_name = $fcp->name; - $hn->save(); + $hn->save(["no_aftersave" => true]); $counts['upd']++; } } diff --git a/public/js/pages/ADBRimoFcp/ADBRimoFcp.js b/public/js/pages/ADBRimoFcp/ADBRimoFcp.js index 517613048..54b35385a 100644 --- a/public/js/pages/ADBRimoFcp/ADBRimoFcp.js +++ b/public/js/pages/ADBRimoFcp/ADBRimoFcp.js @@ -81,10 +81,10 @@ Vue.component('csv-import-modal', { this.errorMessage = 'Bitte wählen Sie zuerst eine Datei aus.'; return; } - if (this.showNetworkAreas && !this.selectedNetworkArea) { - this.errorMessage = 'Bitte wählen Sie einen Netzbereich aus.'; - return; - } + // if (this.showNetworkAreas && !this.selectedNetworkArea) { + // this.errorMessage = 'Bitte wählen Sie einen Netzbereich aus.'; + // return; + // } this.errorMessage = null; this.loading = true;