# 设置输出编码为UTF-8 [Console]::InputEncoding = [System.Text.Encoding]::UTF8 [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $OutputEncoding = [System.Text.Encoding]::UTF8 chcp.com 65001 | Out-Null # 目录配置 $OUTPUT_DIR = "./model" $TARGET_DIR = "../../app/main/model" $HOME_DIR = Join-Path $PSScriptRoot "..\template" # 表名列表(系统简化后保留的表) $tables = @( # ============================================ # 管理员系统表 # ============================================ # "admin_api", # "admin_dict_data", # "admin_dict_type", # "admin_menu", # "admin_role", # "admin_role_api", # "admin_role_menu", # "admin_user", # "admin_user_role", # ============================================ # 代理系统表(简化后) # ============================================ # "agent", # 代理表(简化:移除 level, team_leader_id, invite_code_id) # "agent_commission", # 佣金表(简化:状态只有 1=已发放, 2=已取消) # "agent_config", # 代理配置 # "agent_freeze_task", # 冻结任务 # "agent_link", # 代理链接 # "agent_order", # 代理订单 # "agent_product_config", # 产品配置 # "agent_short_link", # 短链接 # "agent_wallet", # 钱包 # "agent_withdraw" # 提现 # ============================================ # 业务功能表 # ============================================ # "authorization_document", # 授权文档 # "example", # 示例 # "feature", # 功能 # "global_notifications", # 全局通知 # "order" # 订单 # "order_refund", # 订单退款 # "product", # 产品 # "product_feature", # 产品功能 # "query", # 查询 # "query_cleanup_config", # 查询清理配置 # "query_cleanup_detail", # 查询清理详情 # "query_cleanup_log", # 查询清理日志 # "user", # 用户 # "user_auth", # 用户认证 # "user_temp" # 临时用户 "yunyin_sign_pay_order" # 云印签签署流程 ) # 为每个表生成模型 foreach ($table in $tables) { Write-Host "正在生成表: $table" -ForegroundColor Green goctl model mysql datasource -url="jnc:5vg67b3UNHu8@tcp(127.0.0.1:21301)/jnc" -table="$table" -dir="./model" --home="$HOME_DIR" -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 if (Test-Path $OUTPUT_DIR) { Get-ChildItem -Path $OUTPUT_DIR -File | Remove-Item -Force }