#!/bin/bash
# 一键启动所有 HZHub 服务

# JWT 密钥（必须 >= 32 字节 / 256 bits，所有后端服务共享）
export JWT_SECRET="${JWT_SECRET:-Om1fovSeKIA1oLIoHdDPMF-trbqbrPQoDS3H4u1xoRY}"

echo "========================================="
echo " 启动所有 HZHub 服务"
echo "========================================="

# 启动 AI 服务
echo ""
echo "1️⃣  启动 AI 服务 (hzhub-ai)..."
cd /data/hzhub/hzhub-ai
./start.sh

# 启动系统服务
echo ""
echo "2️⃣  启动系统服务 (hzhub-system)..."
cd /data/hzhub/hzhub-system
./start.sh

# 启动 Gateway
echo ""
echo "3️⃣  启动 API 网关 (hzhub-gateway)..."
cd /data/hzhub/hzhub-gateway
./start.sh

# 启动 ERP 服务
echo ""
echo "4️⃣  启动 ERP 服务 (hzhub-erp)..."
cd /data/hzhub/hzhub-erp
./start.sh

# 等待后端服务启动
echo ""
echo "⏳ 等待后端服务启动 (10秒)..."
sleep 10

# 启动管理后台
echo ""
echo "5️⃣  启动管理后台 (hzhub-admin)..."
cd /data/hzhub/hzhub-admin
./start.sh

# 启动员工门户
echo ""
echo "6️⃣  启动员工门户 (hzhub-portal-employee)..."
cd /data/hzhub/hzhub-portal-employee
./start.sh

# 启动经销商门户
#echo ""
#echo "7️⃣  启动经销商门户 (hzhub-portal-dealer)..."
#cd /data/hzhub/hzhub-portal-dealer
#./start.sh

echo ""
echo "========================================="
echo " ✅ 所有服务启动完成"
echo "========================================="
echo ""
echo "服务地址:"
echo "  API网关:    http://localhost:8080 (统一入口)"
echo "  AI服务:     http://localhost:6039 (直连)"
echo "  系统服务:   http://localhost:8083 (认证/系统/工作流/代码生成)"
echo "  ERP服务:    http://localhost:8082 (直连)"
echo "  管理后台:   http://localhost:5666"
echo "  员工门户:   http://localhost:5137"
#echo "  经销商门户: http://localhost:5138"
echo ""
echo "查看服务状态:"
echo "  ./status-all.sh"
echo ""
