Files
smart-customer-service/scripts/start-dev.sh
Ubuntu c68ea3b600 feat: 智能客服系统基础架构完成
 已完成功能:
1. 项目基础设施和Docker开发环境
2. 前端React 18 + TypeScript架构
3. 后端Golang + Gin框架
4. 多租户数据库设计
5. 完整API路由系统
6. 智能客服聊天界面
7. 详细文档和部署指南

🔧 技术栈:
- 前端:React 18, TypeScript, Vite, Zustand
- 后端:Golang, Gin, GORM, PostgreSQL
- 部署:Docker, Docker Compose

🎨 设计规范:
- 无渐变色,无紫色
- 简洁专业的中性色系
- 响应式布局

📊 状态:
- 前端开发服务器:http://localhost:5173
- 后端API服务:http://localhost:8080
- 数据库:PostgreSQL + Redis
- 完整的多租户架构

作者:小弟 (大哥的AI助手)
日期:2026-02-27
2026-02-27 17:00:15 +08:00

162 lines
3.7 KiB
Bash
Executable File
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.
#!/bin/bash
# 智能客服系统 - 开发环境启动脚本
# 作者: 小弟 (大哥的AI助手)
set -e
echo "🚀 启动智能客服系统开发环境..."
echo "========================================"
# 检查Docker是否运行
if ! docker info > /dev/null 2>&1; then
echo "❌ Docker未运行请启动Docker服务"
exit 1
fi
# 检查前端依赖
echo "📦 检查前端依赖..."
cd frontend
if [ ! -d "node_modules" ]; then
echo " 安装前端依赖..."
pnpm install
else
echo " 前端依赖已安装"
fi
cd ..
# 检查后端依赖
echo "📦 检查后端依赖..."
cd backend
if [ ! -f "go.mod" ]; then
echo " 初始化Go模块..."
go mod init smart-customer-service
fi
echo " 整理Go依赖..."
go mod tidy
cd ..
# 创建环境文件(如果不存在)
if [ ! -f ".env" ]; then
echo "🔧 创建环境配置文件..."
cat > .env << 'ENV'
# 服务器配置
SERVER_PORT=8080
SERVER_MODE=debug
# 数据库配置
DB_HOST=postgres
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=customer_service
DB_SSL_MODE=disable
# Redis配置
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0
# JWT配置
JWT_SECRET=dev-secret-key-change-in-production
JWT_EXPIRATION=86400
# AI配置
AI_PROVIDER=openai
AI_API_KEY=your-openai-api-key-here
AI_MODEL=gpt-3.5-turbo
AI_BASE_URL=https://api.openai.com/v1
AI_MAX_TOKENS=1000
AI_TEMPERATURE=0.7
# WebSocket配置
WS_PORT=8081
WS_PATH=/ws
ENV
echo " 环境文件已创建 (.env)"
fi
if [ ! -f "frontend/.env" ]; then
echo "🔧 创建前端环境配置文件..."
cat > frontend/.env << 'ENV'
VITE_API_URL=http://localhost:8080
VITE_WS_URL=ws://localhost:8081
ENV
echo " 前端环境文件已创建 (frontend/.env)"
fi
# 启动Docker服务
echo "🐳 启动Docker服务..."
docker-compose up -d
# 等待数据库就绪
echo "⏳ 等待数据库就绪..."
for i in {1..30}; do
if docker-compose exec postgres pg_isready -U postgres > /dev/null 2>&1; then
echo "✅ 数据库已就绪"
break
fi
echo " 等待数据库... ($i/30)"
sleep 2
done
# 初始化数据库
echo "🗄️ 初始化数据库..."
if docker-compose exec postgres psql -U postgres -d customer_service -c "\dt" | grep -q tenants; then
echo "✅ 数据库已初始化"
else
echo " 执行数据库迁移..."
docker-compose exec -T postgres psql -U postgres -d customer_service < backend/migrations/001_init_schema.sql
echo "✅ 数据库迁移完成"
fi
# 启动后端服务
echo "⚙️ 启动后端服务..."
cd backend
if [ -f "/tmp/test-build" ]; then
echo " 使用预编译版本..."
/tmp/test-build &
else
echo " 编译并启动后端..."
go run cmd/server/main.go &
fi
BACKEND_PID=$!
cd ..
# 启动前端服务
echo "🎨 启动前端服务..."
cd frontend
pnpm dev &
FRONTEND_PID=$!
cd ..
# 显示访问信息
echo ""
echo "========================================"
echo "✅ 智能客服系统启动完成!"
echo ""
echo "📱 访问地址:"
echo " 前端应用: http://localhost:5173"
echo " 后端API: http://localhost:8080"
echo " 健康检查: http://localhost:8080/health"
echo " 数据库管理: http://localhost:8082"
echo ""
echo "🔧 管理命令:"
echo " 查看日志: docker-compose logs -f"
echo " 停止服务: docker-compose down"
echo " 重启服务: ./scripts/start-dev.sh"
echo ""
echo "📝 默认账号:"
echo " 邮箱: admin@example.com"
echo " 密码: admin123"
echo "========================================"
# 设置退出时的清理
trap "echo '🛑 停止服务...'; kill $BACKEND_PID $FRONTEND_PID 2>/dev/null; docker-compose down; echo '✅ 服务已停止'" EXIT
# 保持脚本运行
echo ""
echo "📊 按 Ctrl+C 停止所有服务"
wait