From 67cd940347bfe38ef6aab075a2dbd738bec41ed3 Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期六, 03 十月 2026 14:43:44 +0800
Subject: [PATCH] feat(holiday): support 2019 and previous-day data in new templates

---
 deploy-templates/backend/install-service.ps1 |   76 +++++++++++++++++++++++++++----------
 1 files changed, 55 insertions(+), 21 deletions(-)

diff --git a/deploy-templates/backend/install-service.ps1 b/deploy-templates/backend/install-service.ps1
index 2b8f094..98373d6 100644
--- a/deploy-templates/backend/install-service.ps1
+++ b/deploy-templates/backend/install-service.ps1
@@ -45,6 +45,21 @@
 $appConfig = Join-Path $root 'application.yml'
 $serviceId = 'TrafficAuditBackend'
 
+# Any terminating error below lands here instead of dumping a raw stack trace
+# at the operator. The line number is kept so a copy of this window is enough
+# to diagnose a report.
+trap {
+  Write-Host ''
+  Write-Host '=============================================================='
+  Write-Host ' ERROR: the installer stopped before finishing.'
+  Write-Host ('        ' + $_.Exception.Message)
+  Write-Host ('        at line ' + $_.InvocationInfo.ScriptLineNumber + ' of install-service.ps1')
+  Write-Host ' The service may not be installed. Send this window text to the'
+  Write-Host ' developer if the reason is not obvious.'
+  Write-Host '=============================================================='
+  exit 1
+}
+
 function Assert-Admin {
   $identity  = [Security.Principal.WindowsIdentity]::GetCurrent()
   $principal = New-Object Security.Principal.WindowsPrincipal($identity)
@@ -146,6 +161,45 @@
   }
 }
 
+function Test-AppConfigPassword {
+  param([string]$Path)
+
+  # Returns $true when the datasource password looks usable. Prints a WARN and
+  # returns $false for the states that break startup with
+  # "Access denied ... (using password: NO)": missing file / empty value / placeholder.
+  if (-not (Test-Path -LiteralPath $Path)) {
+    Write-Host 'WARN: application.yml is missing next to the jar.'
+    Write-Host '      The built-in password placeholder resolves to an empty string and startup will fail with'
+    Write-Host "      Java SQLException: Access denied for user 'root'@'localhost' (using password: NO)."
+    return $false
+  }
+
+  $line = Select-String -LiteralPath $Path -Pattern '^\s*password\s*:' | Select-Object -First 1
+  if (-not $line) {
+    Write-Host "WARN: no 'password:' entry found in application.yml; check the datasource block."
+    return $false
+  }
+
+  # Trim() takes a single char, so strip whitespace, then one quote kind at a
+  # time. Passing a 2-char string here throws
+  # "cannot convert value ... to type System.Char" and aborts the script.
+  $value = $line.Line -replace '^\s*password\s*:\s*', ''
+  $value = $value.Trim()
+  $value = $value.Trim("'")
+  $value = $value.Trim('"')
+
+  if ($value -eq '') {
+    Write-Host "WARN: spring.datasource.password is empty in application.yml; startup may fail with '(using password: NO)'."
+    return $false
+  }
+  if ($value -match '[^\x00-\x7F]') {
+    Write-Host 'WARN: the datasource password contains non-ASCII characters.'
+    Write-Host '      If it is still the Chinese placeholder text, replace it with the real MySQL password first.'
+    return $false
+  }
+  return $true
+}
+
 # ---------- read-only status: no elevation needed ----------
 if ($Status) {
   $service = Get-ServiceState
@@ -197,27 +251,7 @@
 if (-not (Test-Path $wrapper)) {
   throw "Missing wrapper executable: $wrapper`nRebuild the deploy package with pack-deploy.ps1 (it provides WinSW), or copy WinSW-x64.exe here renamed to trafficAudit.exe."
 }
-$passwordOk = $false
-if (-not (Test-Path $appConfig)) {
-  Write-Host "WARN: application.yml is missing next to the jar."
-  Write-Host "      The built-in password placeholder resolves to an empty string and startup will fail with"
-  Write-Host "      Java SQLException: Access denied for user 'root'@'localhost' (using password: NO)."
-} else {
-  $line = Select-String -LiteralPath $appConfig -Pattern '^\s*password\s*:' | Select-Object -First 1
-  if (-not $line) {
-    Write-Host "WARN: no 'password:' entry found in application.yml; check the datasource block."
-  } else {
-    $value = ($line.Line -replace '^\s*password\s*:\s*', '').Trim(' ''', '"')
-    if ($value -eq '') {
-      Write-Host "WARN: spring.datasource.password is empty in application.yml; startup may fail with '(using password: NO)'."
-    } elseif ($value -match '[^\x00-\x7F]') {
-      Write-Host "WARN: the datasource password contains non-ASCII characters."
-      Write-Host "      If it is still the Chinese placeholder text, replace it with the real MySQL password first."
-    } else {
-      $passwordOk = $true
-    }
-  }
-}
+$passwordOk = Test-AppConfigPassword -Path $appConfig
 
 $java = Resolve-JavaPath -Explicit $JavaPath
 Set-WrapperJavaPath -JavaExe $java

--
Gitblit v1.9.1