87 lines
3.7 KiB
PowerShell
87 lines
3.7 KiB
PowerShell
# 批量替换API调用方法的PowerShell脚本
|
||
|
||
# 说明:此脚本用于批量修改apirequestService.go中的API调用方法
|
||
# 使用前请先备份文件!
|
||
|
||
$filePath = "app\main\api\internal\service\apirequestService.go"
|
||
|
||
# 检查文件是否存在
|
||
if (-not (Test-Path $filePath)) {
|
||
Write-Host "错误:文件不存在 - $filePath" -ForegroundColor Red
|
||
exit 1
|
||
}
|
||
|
||
# 备份文件
|
||
$backupPath = "$filePath.backup"
|
||
Copy-Item $filePath $backupPath
|
||
Write-Host "已备份文件到: $backupPath" -ForegroundColor Green
|
||
|
||
# 读取文件内容
|
||
$content = Get-Content $filePath -Raw
|
||
|
||
# 需要修改的方法列表(已完成的除外)
|
||
$methodsToSkip = @(
|
||
"ProcessYYSYBE08Request",
|
||
"ProcessFLXG0V4BRequest"
|
||
)
|
||
|
||
# 需要添加ctx声明的模式
|
||
$pattern1 = '(?m)(func \(a \*ApiRequestService\) Process(\w+)Request\(params \[\]byte\) \(\[\]byte, error\) \{)'
|
||
|
||
# 替换API调用
|
||
$pattern2 = 'a\.tianyuanapi\.CallInterface\("'
|
||
$replacement2 = 'a.callTianyuanApiWithLog(ctx, "", "'
|
||
|
||
# 执行替换
|
||
$count = 0
|
||
$content -replace $pattern2, $replacement2 | Out-File $filePath -Encoding UTF8
|
||
|
||
# 统计替换次数
|
||
$matches = [regex]::Matches($content, $pattern2)
|
||
$count = $matches.Count
|
||
|
||
Write-Host "已替换 $count 处 a.tianyuanapi.CallInterface 调用" -ForegroundColor Green
|
||
|
||
Write-Host "`n现在需要手动为每个方法添加 ctx 声明:" -ForegroundColor Yellow
|
||
Write-Host "在每个方法的 func 声明后,第一行添加:" -ForegroundColor Yellow
|
||
Write-Host 'ctx := context.Background()' -ForegroundColor Cyan
|
||
|
||
Write-Host "`n需要修改的方法列表(已完成的除外):" -ForegroundColor Yellow
|
||
Write-Host "ProcessPersonEnterpriseProRequest - 主接口和涉诉查询" -ForegroundColor White
|
||
Write-Host "ProcessFLXG0687Request" -ForegroundColor White
|
||
Write-Host "ProcessFLXG3D56Request" -ForegroundColor White
|
||
Write-Host "ProcessIVYZ5733Request" -ForegroundColor White
|
||
Write-Host "ProcessIVYZ9A2BRequest" -ForegroundColor White
|
||
Write-Host "ProcessJRZQ0A03Request" -ForegroundColor White
|
||
Write-Host "ProcessJRZQ8203Request" -ForegroundColor White
|
||
Write-Host "ProcessJRZQ4AA8Request" -ForegroundColor White
|
||
Write-Host "ProcessQYGL8271Request" -ForegroundColor White
|
||
Write-Host "ProcessQYGL6F2DRequest" -ForegroundColor White
|
||
Write-Host "ProcessQCXG7A2BRequest" -ForegroundColor White
|
||
Write-Host "ProcessYYSY09CDRequest" -ForegroundColor White
|
||
Write-Host "ProcessDWBG8B4DRequest" -ForegroundColor White
|
||
Write-Host "ProcessDWBG6A2CRequest" -ForegroundColor White
|
||
Write-Host "ProcessJRZQ4B6CRequest" -ForegroundColor White
|
||
Write-Host "ProcessJRZQ09J8Request" -ForegroundColor White
|
||
Write-Host "ProcessJRZQ5E9FRequest" -ForegroundColor White
|
||
Write-Host "ProcessQYGL3F8ERequest" -ForegroundColor White
|
||
Write-Host "ProcessIVYZ81NCRequest" -ForegroundColor White
|
||
Write-Host "ProcessIVYZ7F3ARequest" -ForegroundColor White
|
||
Write-Host "ProcessDWBG7F3ARequest" -ForegroundColor White
|
||
Write-Host "ProcessJRZQ8A2DRequest" -ForegroundColor White
|
||
Write-Host "ProcessYYSY8B1CRequest" -ForegroundColor White
|
||
Write-Host "ProcessYYSY7D3ERequest" -ForegroundColor White
|
||
Write-Host "ProcessFLXG7E8FRequest" -ForegroundColor White
|
||
Write-Host "ProcessIVYZ8I9JRequest" -ForegroundColor White
|
||
Write-Host "ProcessJRZQ7F1ARequest" -ForegroundColor White
|
||
Write-Host "ProcessIVYZ3P9MRequest" -ForegroundColor White
|
||
Write-Host "ProcessJRZQ6F2ARequest" -ForegroundColor White
|
||
|
||
Write-Host "`n总计需要修改 30 个方法" -ForegroundColor Yellow
|
||
Write-Host "`n提示:在IDE中使用查找替换功能会更方便" -ForegroundColor Cyan
|
||
Write-Host "查找:a.tianyuanapi.CallInterface(`(" -ForegroundColor Cyan
|
||
Write-Host "替换:a.callTianyuanApiWithLog(ctx, `", `(" -ForegroundColor Cyan
|
||
|
||
Write-Host "`n`n操作完成!请检查文件并手动添加 ctx 声明" -ForegroundColor Green
|
||
|