gongxiangp2/scripts/query-material-detail.ps1

66 lines
1.5 KiB
PowerShell

#!/usr/bin/env pwsh
# 查询指定素材的详细信息
param(
[Parameter(Mandatory=$true)]
[string]$MaterialId,
[Parameter(Mandatory=$false)]
[ValidateSet('production', 'shadow')]
[string]$Target = 'shadow'
)
$ErrorActionPreference = 'Stop'
$ServerIP = "192.168.58.20"
if ($Target -eq 'production') {
$DatabaseName = "lobechat"
} else {
$DatabaseName = "lobechat_stage"
}
$SqlQuery = @"
-- 素材基本信息
SELECT
id,
\"materialType\",
\"productModel\",
\"categoryName\",
\"sceneName\",
\"previewUrl\",
\"zipFileName\",
\"zipFileSize\",
task_no,
task_status,
\"createdAt\"
FROM materials
WHERE id = '$MaterialId' AND \"deletedAt\" IS NULL;
-- 素材资产信息
SELECT
id,
asset_type,
file_url,
file_name,
file_size,
sort_order
FROM material_assets
WHERE material_id = '$MaterialId'
ORDER BY sort_order;
"@
Write-Host "查询素材详情: $MaterialId ($Target)" -ForegroundColor Cyan
$QueryBytes = [System.Text.Encoding]::UTF8.GetBytes($SqlQuery)
$QueryBase64 = [Convert]::ToBase64String($QueryBytes)
$RemoteCommand = "echo '$QueryBase64' | base64 -d | docker exec -i gongxiangpan-postgres-1 psql -U gongxiangpan -d $DatabaseName"
$Result = ssh -o StrictHostKeyChecking=no root@$ServerIP $RemoteCommand
if ($LASTEXITCODE -eq 0) {
Write-Host $Result -ForegroundColor Green
} else {
Write-Host "查询失败!" -ForegroundColor Red
Write-Host $Result -ForegroundColor Red
}