Files
tianpu-ems/scripts/quick-start.sh
Du Wenbo 36c53e0e7c feat: complete platform build-out to 95% benchmark-ready
Major additions across backend, frontend, and infrastructure:

Backend:
- IoT collector framework (Modbus TCP, MQTT, HTTP) with manager
- Realistic Beijing solar/weather simulator with cloud transients
- Alarm auto-checker with demo anomaly injection (3-4 events/hour)
- Report generation (PDF/Excel) with sync fallback and E2E testing
- Energy data CSV/XLSX export endpoint
- WebSocket real-time broadcast at /ws/realtime
- Alembic initial migration for all 14 tables
- 77 pytest tests across 9 API routers

Frontend:
- Live notification badge with alarm count (was hardcoded 0)
- Sankey energy flow diagram on dashboard
- Device photos (SVG illustrations) on all device pages
- Report download with status icons
- Energy data export buttons (CSV/Excel)
- WebSocket hook with auto-reconnect and polling fallback
- BigScreen 2D responsive CSS (tablet/mobile)
- Error handling improvements across pages

Infrastructure:
- PostgreSQL + TimescaleDB as primary database
- Production docker-compose with nginx reverse proxy
- Comprehensive Chinese README
- .env.example with documentation
- quick-start.sh deployment script
- nginx config with gzip, caching, security headers

Data:
- 30-day realistic backfill (47K rows, weather-correlated)
- 18 devices, 6 alarm rules, 15 historical alarm events
- Beijing solar position model with seasonal variation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 18:46:42 +08:00

146 lines
3.6 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
# 天普零碳园区智慧能源管理平台 - 快速启动脚本
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# 检查前置依赖
check_prerequisites() {
log_info "检查前置依赖..."
if ! command -v docker &> /dev/null; then
log_error "未找到 Docker请先安装 Docker: https://docs.docker.com/get-docker/"
exit 1
fi
if ! docker compose version &> /dev/null && ! docker-compose version &> /dev/null; then
log_error "未找到 Docker Compose请先安装 Docker Compose"
exit 1
fi
log_info "前置依赖检查通过"
}
# 确定 docker compose 命令
get_compose_cmd() {
if docker compose version &> /dev/null; then
echo "docker compose"
else
echo "docker-compose"
fi
}
# 初始化环境变量
init_env() {
if [ ! -f .env ]; then
log_warn ".env 文件不存在,从模板创建..."
if [ -f .env.example ]; then
cp .env.example .env
log_warn "已创建 .env 文件,请根据实际情况修改配置"
log_warn "当前使用默认配置启动,生产环境请务必修改密码和密钥"
else
log_error "未找到 .env.example 模板文件"
exit 1
fi
else
log_info ".env 文件已存在"
fi
}
# 启动服务
start_services() {
local compose_cmd
compose_cmd=$(get_compose_cmd)
log_info "启动服务..."
$compose_cmd up -d
log_info "等待服务就绪..."
# 等待数据库就绪
local retries=30
while [ $retries -gt 0 ]; do
if docker exec tianpu_db pg_isready -U tianpu -d tianpu_ems &> /dev/null; then
log_info "数据库已就绪"
break
fi
retries=$((retries - 1))
sleep 2
done
if [ $retries -eq 0 ]; then
log_error "数据库启动超时"
exit 1
fi
# 等待后端就绪
retries=30
while [ $retries -gt 0 ]; do
if docker exec tianpu_backend curl -sf http://localhost:8000/health &> /dev/null; then
log_info "后端服务已就绪"
break
fi
retries=$((retries - 1))
sleep 2
done
if [ $retries -eq 0 ]; then
log_error "后端服务启动超时"
exit 1
fi
}
# 初始化数据
init_data() {
log_info "初始化数据库..."
docker exec tianpu_backend python scripts/init_db.py || {
log_warn "数据库初始化跳过(可能已初始化)"
}
log_info "写入种子数据..."
docker exec tianpu_backend python scripts/seed_data.py || {
log_warn "种子数据写入跳过(可能已存在)"
}
}
# 打印访问信息
print_info() {
echo ""
echo "============================================="
echo " 天普零碳园区智慧能源管理平台 启动完成"
echo "============================================="
echo ""
echo " 前端页面: http://localhost:3000"
echo " 后端 API: http://localhost:8000"
echo " API 文档: http://localhost:8000/docs"
echo ""
echo " 默认账号: admin"
echo " 默认密码: admin123"
echo ""
echo " 请在首次登录后修改默认密码"
echo "============================================="
echo ""
}
# 主流程
main() {
log_info "天普零碳园区智慧能源管理平台 - 快速启动"
echo ""
check_prerequisites
init_env
start_services
init_data
print_info
}
main "$@"