From 895275757e97fa2663012ba4a159f72b0ddf7a8e Mon Sep 17 00:00:00 2001 From: 92451 <924518135@qq.com> Date: Fri, 30 Oct 2026 20:21:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8A=A0=E5=9B=BA=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=AE=9D=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/company-alipay-direct/README.md | 2 ++ .../company-alipay-direct/install-daily-task.ps1 | 12 +++++------- scripts/company-alipay-direct/run-alipay-daily.cmd | 10 ++++++++++ scripts/company-alipay-direct/run-alipay-daily.ps1 | 14 +++++++++++++- 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 scripts/company-alipay-direct/run-alipay-daily.cmd diff --git a/scripts/company-alipay-direct/README.md b/scripts/company-alipay-direct/README.md index 2c81eff1..3b486384 100644 --- a/scripts/company-alipay-direct/README.md +++ b/scripts/company-alipay-direct/README.md @@ -27,4 +27,6 @@ pwsh -File scripts\company-alipay-direct\install-daily-task.ps1 账号、密码、账户简称和浏览器登录态仅保存在 `runtime/private/`,不会进入 Git。私有文件需包含 `账号:`、`密码:` 和 `支付宝账户简称:` 三项。任一登录失效、验证页面出现、空数据或导入失败都会保留上一版数据并记录日志。 +定时任务通过 `run-alipay-daily.cmd` 启动,并优先使用系统 Node.js;若仅在 Codex 运行时可用,会自动使用当前固定运行时路径。任务宿主错误记录在同目录的 `task-host.log`,业务错误记录在日期日志中。 + 账单导入生产时统一通过服务器受限批处理入口执行,使用独立批处理容器、上游同步锁和资源上限;支付宝登录与账单导出仍只在本机运行。 diff --git a/scripts/company-alipay-direct/install-daily-task.ps1 b/scripts/company-alipay-direct/install-daily-task.ps1 index 6326e59a..f0b0bc76 100644 --- a/scripts/company-alipay-direct/install-daily-task.ps1 +++ b/scripts/company-alipay-direct/install-daily-task.ps1 @@ -11,14 +11,12 @@ param( Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' -$runner = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot 'run-alipay-daily.ps1')).Path -$windowsPowerShell = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe' +$cmdPath = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot 'run-alipay-daily.cmd')).Path $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name $arguments = @( - '-NoProfile', - '-ExecutionPolicy', 'Bypass', - '-WindowStyle', 'Hidden', - '-File', ('"' + $runner + '"') + '/d', + '/c', + ('""' + $cmdPath + '""') ) -join ' ' if (-not $PSCmdlet.ShouldProcess($TaskName, "register daily Alipay export at $Time")) { @@ -51,7 +49,7 @@ try { $trigger.Enabled = $true $action = $definition.Actions.Create(0) - $action.Path = $windowsPowerShell + $action.Path = $env:ComSpec $action.Arguments = $arguments $action.WorkingDirectory = $PSScriptRoot diff --git a/scripts/company-alipay-direct/run-alipay-daily.cmd b/scripts/company-alipay-direct/run-alipay-daily.cmd new file mode 100644 index 00000000..609747d0 --- /dev/null +++ b/scripts/company-alipay-direct/run-alipay-daily.cmd @@ -0,0 +1,10 @@ +@echo off +setlocal EnableExtensions + +set "SCRIPT_DIR=%~dp0" +set "LOG_DIR=%SCRIPT_DIR%..\..\runtime\private\alipay-exports\logs" +if not exist "%LOG_DIR%" mkdir "%LOG_DIR%" +set "TASK_LOG=%LOG_DIR%\task-host.log" + +"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%run-alipay-daily.ps1" %* >> "%TASK_LOG%" 2>&1 +exit /b %ERRORLEVEL% diff --git a/scripts/company-alipay-direct/run-alipay-daily.ps1 b/scripts/company-alipay-direct/run-alipay-daily.ps1 index 60556d86..aa12f9a5 100644 --- a/scripts/company-alipay-direct/run-alipay-daily.ps1 +++ b/scripts/company-alipay-direct/run-alipay-daily.ps1 @@ -53,7 +53,19 @@ $localFile = Join-Path $outputDir ('alipay-company-' + $Date + '.csv') if (-not [string]::IsNullOrWhiteSpace($InputFile)) { $localFile = (Resolve-Path -LiteralPath $InputFile -ErrorAction Stop).Path } else { - $node = (Get-Command node.exe -ErrorAction Stop).Source + $nodeCommand = Get-Command node.exe -ErrorAction SilentlyContinue | Select-Object -First 1 + $node = if ($null -ne $nodeCommand) { $nodeCommand.Source } else { $null } + if ([string]::IsNullOrWhiteSpace($node)) { + $nodeCandidates = @( + (Join-Path $env:ProgramFiles 'nodejs\node.exe'), + (Join-Path $env:USERPROFILE '.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe') + ) + $node = $nodeCandidates | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1 + } + if ([string]::IsNullOrWhiteSpace($node)) { + Write-Log '未找到 node.exe;未写入财务台账' + throw '未找到 Node.js,请安装 Node.js 后重新触发任务' + } Write-Log ('开始导出支付宝账单:' + $Date) $exportOutput = (& $node $exportScript ('--date=' + $Date) ('--out=' + $outputDir) 2>&1 | Out-String) if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath $localFile -PathType Leaf)) { -- 2.47.2