fix: rebuild MES as compilable go-zero+ent backend (renamed bj_power_mes), restore 3 workstation projects from pristine original, align naming; all Go projects go build clean
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
# ============================================================================
|
||||
# PostgreSQL 数据库初始化脚本
|
||||
# ============================================================================
|
||||
# 用法 (PowerShell):
|
||||
# .\scripts\init-db.ps1
|
||||
#
|
||||
# 前提条件:
|
||||
# 1. 本地已安装 PostgreSQL
|
||||
# 2. postgres 用户可访问(可能需要输入密码)
|
||||
# 3. psql 命令已在系统 PATH 中
|
||||
# ============================================================================
|
||||
|
||||
param(
|
||||
[string]$DbUser = "postgres",
|
||||
[string]$DbName = "back_cover",
|
||||
[string]$SqlFile = "$PSScriptRoot\..\doc\data.sql"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "PostgreSQL 数据库初始化脚本" -ForegroundColor Cyan
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# 检查 psql 是否可用
|
||||
try {
|
||||
$psqlVersion = psql --version
|
||||
Write-Host "[✓] psql 已安装: $psqlVersion" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "[✗] 错误: 未找到 psql 命令" -ForegroundColor Red
|
||||
Write-Host "请确保 PostgreSQL 已安装且 psql 在系统 PATH 中" -ForegroundColor Yellow
|
||||
Write-Host "下载地址: https://www.postgresql.org/download/windows/" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 步骤 1: 创建数据库
|
||||
Write-Host ""
|
||||
Write-Host "--- 步骤 1: 创建数据库 ---" -ForegroundColor Cyan
|
||||
$dbExists = psql -U $DbUser -tc "SELECT 1 FROM pg_database WHERE datname = '$DbName'" 2>$null
|
||||
if ($dbExists -eq "1") {
|
||||
Write-Host "[!] 数据库 '$DbName' 已存在" -ForegroundColor Yellow
|
||||
$confirm = Read-Host "是否删除并重建? (y/n)"
|
||||
if ($confirm -eq "y" -or $confirm -eq "Y") {
|
||||
Write-Host "正在删除数据库..." -ForegroundColor Yellow
|
||||
psql -U $DbUser -c "DROP DATABASE IF EXISTS $DbName;" 2>&1 | Out-Null
|
||||
Write-Host "[✓] 数据库已删除" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[✓] 跳过数据库创建" -ForegroundColor Green
|
||||
}
|
||||
} else {
|
||||
Write-Host "正在创建数据库 '$DbName'..." -ForegroundColor Yellow
|
||||
psql -U $DbUser -c "CREATE DATABASE $DbName;" 2>&1 | Out-Null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "[✓] 数据库创建成功" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[✗] 数据库创建失败" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# 步骤 2: 提示用户启动应用以创建表结构
|
||||
Write-Host ""
|
||||
Write-Host "--- 步骤 2: 创建表结构 ---" -ForegroundColor Cyan
|
||||
Write-Host "Ent ORM 会在首次启动时自动创建表结构。" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host "请按以下方式操作:" -ForegroundColor Yellow
|
||||
Write-Host " 1. 打开新的终端窗口" -ForegroundColor White
|
||||
Write-Host " 2. 运行: cd $($PSScriptRoot)\.." -ForegroundColor White
|
||||
Write-Host " 3. 运行: go run hougai.go -f etc\hougai-api.yaml" -ForegroundColor White
|
||||
Write-Host " 4. 等待看到 'Starting server at...' 消息" -ForegroundColor White
|
||||
Write-Host " 5. 按 Ctrl+C 停止应用(无需等待完整启动)" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Read-Host "完成后按回车继续..."
|
||||
|
||||
# 步骤 3: 插入种子数据
|
||||
Write-Host ""
|
||||
Write-Host "--- 步骤 3: 插入种子数据 ---" -ForegroundColor Cyan
|
||||
|
||||
if (-not (Test-Path $SqlFile)) {
|
||||
Write-Host "[✗] 错误: SQL 文件不存在: $SqlFile" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "正在执行: $SqlFile" -ForegroundColor Yellow
|
||||
$result = psql -U $DbUser -d $DbName -f $SqlFile 2>&1
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "[✓] 种子数据插入成功" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "执行输出:" -ForegroundColor Cyan
|
||||
Write-Host $result -ForegroundColor Gray
|
||||
} else {
|
||||
Write-Host "[✗] 种子数据插入失败" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Write-Host "错误输出:" -ForegroundColor Red
|
||||
Write-Host $result -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 完成
|
||||
Write-Host ""
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "数据库初始化完成!" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "下一步:" -ForegroundColor Yellow
|
||||
Write-Host " 1. 重启后端应用" -ForegroundColor White
|
||||
Write-Host " go run hougai.go -f etc/hougai-api.yaml" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host " 2. 启动前端开发服务器" -ForegroundColor White
|
||||
Write-Host " cd frontend" -ForegroundColor Gray
|
||||
Write-Host " pnpm dev" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host " 3. 浏览器访问: http://localhost:7070" -ForegroundColor White
|
||||
Write-Host " 用户名: admin" -ForegroundColor Gray
|
||||
Write-Host " 密码: 123456" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
@@ -0,0 +1,214 @@
|
||||
# ============================================================================
|
||||
# 一键安装和启动脚本
|
||||
# ============================================================================
|
||||
# 用法 (PowerShell):
|
||||
# .\scripts\setup-and-run.ps1
|
||||
#
|
||||
# 功能:
|
||||
# 1. 检查并安装 Node.js 依赖
|
||||
# 2. 初始化 PostgreSQL 数据库
|
||||
# 3. 启动后端和前端服务
|
||||
# ============================================================================
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "################################################################" -ForegroundColor Cyan
|
||||
Write-Host "# #" -ForegroundColor Cyan
|
||||
Write-Host "# 智能加工生产线管控系统 - 一键安装和启动 #" -ForegroundColor Cyan
|
||||
Write-Host "# #" -ForegroundColor Cyan
|
||||
Write-Host "################################################################" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# ==================== 检查前置条件 ====================
|
||||
|
||||
Write-Host ">>> 检查前置条件..." -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
|
||||
# 检查 Go
|
||||
try {
|
||||
$goVersion = go version
|
||||
Write-Host "[✓] Go 已安装: $goVersion" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "[✗] 错误: 未找到 Go" -ForegroundColor Red
|
||||
Write-Host "请安装 Go 1.25+: https://golang.org/dl/" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 检查 Node.js
|
||||
try {
|
||||
$nodeVersion = node --version
|
||||
Write-Host "[✓] Node.js 已安装: $nodeVersion" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "[✗] 错误: 未找到 Node.js" -ForegroundColor Red
|
||||
Write-Host "请安装 Node.js 18+: https://nodejs.org/" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 检查 pnpm
|
||||
try {
|
||||
$pnpmVersion = pnpm --version
|
||||
Write-Host "[✓] pnpm 已安装: v$pnpmVersion" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "[✗] 错误: 未找到 pnpm" -ForegroundColor Red
|
||||
Write-Host "请运行: npm install -g pnpm" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 检查 PostgreSQL
|
||||
try {
|
||||
$psqlVersion = psql --version
|
||||
Write-Host "[✓] PostgreSQL 已安装: $psqlVersion" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "[✗] 错误: 未找到 psql 命令" -ForegroundColor Red
|
||||
Write-Host "请确保 PostgreSQL 已安装且 psql 在系统 PATH 中" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "所有前置条件满足!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
# ==================== 安装前端依赖 ====================
|
||||
|
||||
Write-Host ">>> 安装前端依赖..." -ForegroundColor Yellow
|
||||
$frontendPkgJson = "$PSScriptRoot\..\frontend\package.json"
|
||||
if (Test-Path $frontendPkgJson) {
|
||||
$nodeModules = "$PSScriptRoot\..\frontend\node_modules"
|
||||
if (Test-Path $nodeModules) {
|
||||
Write-Host "[✓] frontend/node_modules 已存在,跳过安装" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "正在安装前端依赖(这可能需要几分钟)..." -ForegroundColor Yellow
|
||||
Set-Location "$PSScriptRoot\..\frontend"
|
||||
pnpm install
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "[✗] 前端依赖安装失败" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
Set-Location $PSScriptRoot\..
|
||||
Write-Host "[✓] 前端依赖安装完成" -ForegroundColor Green
|
||||
}
|
||||
} else {
|
||||
Write-Host "[✗] 错误: 未找到 frontend/package.json" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
|
||||
# ==================== 初始化数据库 ====================
|
||||
|
||||
Write-Host ">>> 初始化数据库..." -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
Write-Host "请选择数据库初始化方式:" -ForegroundColor White
|
||||
Write-Host " 1. 使用自动脚本(推荐)" -ForegroundColor White
|
||||
Write-Host " 2. 跳过数据库初始化(已手动初始化)" -ForegroundColor White
|
||||
|
||||
$choice = Read-Host "请输入选择 (1/2)"
|
||||
|
||||
if ($choice -eq "1") {
|
||||
Write-Host ""
|
||||
Write-Host "--- 执行数据库初始化脚本 ---" -ForegroundColor Cyan
|
||||
|
||||
$initScript = "$PSScriptRoot\init-db.ps1"
|
||||
if (Test-Path $initScript) {
|
||||
& $initScript
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "[✗] 数据库初始化失败" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "[✗] 错误: 未找到 init-db.ps1 脚本" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "[!] 跳过数据库初始化" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
|
||||
# ==================== 询问是否启动 ====================
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "准备就绪!" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "下一步操作:" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
Write-Host " 1. 启动服务(推荐)" -ForegroundColor White
|
||||
Write-Host " 这将同时启动后端 API 和前端开发服务器" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host " 2. 稍后手动启动" -ForegroundColor White
|
||||
Write-Host " 后端: go run hougai.go -f etc/hougai-api.yaml" -ForegroundColor Gray
|
||||
Write-Host " 前端: cd frontend && pnpm dev" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
$startNow = Read-Host "是否现在启动服务? (y/n)"
|
||||
|
||||
if ($startNow -ne "y" -and $startNow -ne "Y") {
|
||||
Write-Host ""
|
||||
Write-Host "提示: 你也可以使用 VS Code 调试功能" -ForegroundColor Cyan
|
||||
Write-Host " 按 F5 选择 '全栈: 后端 + 前端 一键启动'" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host "感谢使用!" -ForegroundColor Green
|
||||
exit 0
|
||||
}
|
||||
|
||||
# ==================== 启动服务 ====================
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "启动服务..." -ForegroundColor Cyan
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# 启动后端(后台进程)
|
||||
Write-Host "[1/2] 启动后端 API 服务..." -ForegroundColor Yellow
|
||||
$backendProcess = Start-Process -FilePath "go" `
|
||||
-ArgumentList "run", "hougai.go", "-f", "etc/hougai-api.yaml" `
|
||||
-WorkingDirectory $PSScriptRoot\.. `
|
||||
-PassThru `
|
||||
-NoNewWindow `
|
||||
-RedirectStandardOutput "$PSScriptRoot\..\backend.log" `
|
||||
-RedirectStandardError "$PSScriptRoot\..\backend-error.log"
|
||||
|
||||
Write-Host "[✓] 后端服务已启动 (PID: $($backendProcess.Id))" -ForegroundColor Green
|
||||
Write-Host " 日志文件: backend.log / backend-error.log" -ForegroundColor Gray
|
||||
|
||||
Start-Sleep -Seconds 3
|
||||
|
||||
# 启动前端(后台进程)
|
||||
Write-Host ""
|
||||
Write-Host "[2/2] 启动前端开发服务器..." -ForegroundColor Yellow
|
||||
$frontendProcess = Start-Process -FilePath "pnpm" `
|
||||
-ArgumentList "dev" `
|
||||
-WorkingDirectory $PSScriptRoot\..\frontend `
|
||||
-PassThru `
|
||||
-NoNewWindow `
|
||||
-RedirectStandardOutput "$PSScriptRoot\..\frontend.log" `
|
||||
-RedirectStandardError "$PSScriptRoot\..\frontend-error.log"
|
||||
|
||||
Write-Host "[✓] 前端开发服务器已启动 (PID: $($frontendProcess.Id))" -ForegroundColor Green
|
||||
Write-Host " 日志文件: frontend.log / frontend-error.log" -ForegroundColor Gray
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "服务启动完成!" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "访问地址:" -ForegroundColor Yellow
|
||||
Write-Host " 🌐 管理后台: http://localhost:7070" -ForegroundColor White
|
||||
Write-Host " 🔌 API 服务: http://localhost:8888" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host "登录信息:" -ForegroundColor Yellow
|
||||
Write-Host " 👤 用户名: admin" -ForegroundColor White
|
||||
Write-Host " 🔑 密码: 123456" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host "查看日志:" -ForegroundColor Yellow
|
||||
Write-Host " 后端: Get-Content backend.log -Tail 20 -Follow" -ForegroundColor Gray
|
||||
Write-Host " 前端: Get-Content frontend.log -Tail 20 -Follow" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host "停止服务: 在各个终端窗口按 Ctrl+C" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
Write-Host "提示: 建议使用 VS Code 获得更好的开发体验" -ForegroundColor Cyan
|
||||
Write-Host " 任务: 运行任务 → 启动全栈服务" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Reference in New Issue
Block a user