v1.0
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
# 设置输出编码为UTF-8
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
# 数据库连接信息 - 修改了URL格式
|
||||
$DB_URL = "ycc:5vg67b3UNHu8@(127.0.0.1:21001)/ycc"
|
||||
# 目录配置
|
||||
$OUTPUT_DIR = "./model"
|
||||
$TEMPLATE_DIR = "../template"
|
||||
$TARGET_DIR = "../../app/main/model"
|
||||
|
||||
# 表名列表
|
||||
$tables = @(
|
||||
# ============================================
|
||||
# 新代理系统表
|
||||
# ============================================
|
||||
"agent",
|
||||
# "agent",
|
||||
# "agent_audit",
|
||||
# "agent_wallet",
|
||||
# "agent_relation",
|
||||
@@ -20,9 +19,12 @@ $tables = @(
|
||||
# "agent_rebate",
|
||||
# "agent_upgrade",
|
||||
# "agent_withdrawal",
|
||||
# "agent_config",
|
||||
# "agent_product_config",
|
||||
"agent_real_name"
|
||||
# "agent_config"
|
||||
# "agent_product_config"
|
||||
# "agent_invite_code_usage"
|
||||
# "agent_freeze_task"
|
||||
"agent_short_link"
|
||||
# "agent_real_name"
|
||||
# "agent_withdrawal_tax"
|
||||
# "agent_invite_code"
|
||||
# ============================================
|
||||
@@ -60,5 +62,68 @@ $tables = @(
|
||||
|
||||
# 为每个表生成模型
|
||||
foreach ($table in $tables) {
|
||||
Write-Host "正在生成表: $table" -ForegroundColor Green
|
||||
goctl model mysql datasource -url="ycc:5vg67b3UNHu8@tcp(127.0.0.1:21001)/ycc" -table="$table" -dir="./model" --home="../template" -cache=true --style=goZero
|
||||
|
||||
# 移动生成的文件到目标目录
|
||||
if (Test-Path $OUTPUT_DIR) {
|
||||
$sourceFiles = Get-ChildItem -Path $OUTPUT_DIR -File
|
||||
|
||||
foreach ($file in $sourceFiles) {
|
||||
$fileName = $file.Name
|
||||
$targetPath = Join-Path $TARGET_DIR $fileName
|
||||
$sourcePath = $file.FullName
|
||||
|
||||
# 检查文件类型并决定是否移动
|
||||
$shouldMove = $false
|
||||
$shouldOverwrite = $false
|
||||
|
||||
if ($fileName -eq "vars.go") {
|
||||
# vars.go: 如果目标目录不存在才移动
|
||||
if (-not (Test-Path $targetPath)) {
|
||||
$shouldMove = $true
|
||||
Write-Host " 移动 $fileName (vars.go 不存在于目标目录)" -ForegroundColor Yellow
|
||||
}
|
||||
else {
|
||||
Write-Host " 跳过 $fileName (vars.go 已存在于目标目录,防止覆盖)" -ForegroundColor Cyan
|
||||
}
|
||||
}
|
||||
elseif ($fileName -match "_gen\.go$") {
|
||||
# 带 _gen 后缀的文件: 直接覆盖
|
||||
$shouldMove = $true
|
||||
$shouldOverwrite = $true
|
||||
Write-Host " 移动 $fileName (覆盖 _gen 文件)" -ForegroundColor Yellow
|
||||
}
|
||||
else {
|
||||
# 不带 _gen 后缀的文件: 如果目标目录不存在才移动
|
||||
if (-not (Test-Path $targetPath)) {
|
||||
$shouldMove = $true
|
||||
Write-Host " 移动 $fileName (非 _gen 文件不存在于目标目录)" -ForegroundColor Yellow
|
||||
}
|
||||
else {
|
||||
Write-Host " 跳过 $fileName (非 _gen 文件已存在于目标目录,防止覆盖)" -ForegroundColor Cyan
|
||||
}
|
||||
}
|
||||
|
||||
# 执行移动操作
|
||||
if ($shouldMove) {
|
||||
# 确保目标目录存在
|
||||
if (-not (Test-Path $TARGET_DIR)) {
|
||||
New-Item -ItemType Directory -Path $TARGET_DIR -Force | Out-Null
|
||||
}
|
||||
|
||||
# 如果目标文件存在且需要覆盖,先删除
|
||||
if ($shouldOverwrite -and (Test-Path $targetPath)) {
|
||||
Remove-Item -Path $targetPath -Force
|
||||
}
|
||||
|
||||
# 移动文件
|
||||
Move-Item -Path $sourcePath -Destination $targetPath -Force
|
||||
Write-Host " ✓ 已移动到: $targetPath" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host '所有模型文件生成并移动完成!' -ForegroundColor Green
|
||||
|
||||
Reference in New Issue
Block a user