Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7202a6244 | ||
|
|
c6f64de4cc | ||
|
|
724e3e1073 | ||
|
|
b02f249166 | ||
|
|
8f2bd92ee0 | ||
|
|
205ae6aa4e | ||
|
|
2de394ccae | ||
|
|
3bc9304fa9 | ||
|
|
a2ba73e33d | ||
|
|
bb669ef422 | ||
|
|
44beaa164d |
@@ -48,7 +48,7 @@ steps:
|
||||
commands:
|
||||
- echo "$DOCKER_PASSWORD" | docker login "$DOCKER_REGISTRY" -u "$DOCKER_USERNAME" --password-stdin
|
||||
- cd frontend
|
||||
- docker build -t $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:test -f Dockerfile --build-arg VITE_API_BASE_URL=https://kpl.ireborn.com.cn .
|
||||
- docker build -t $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:test -f Dockerfile --target production --build-arg VITE_API_BASE_URL=https://kpl.ireborn.com.cn .
|
||||
- docker tag $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:test $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:${DRONE_COMMIT_SHA:0:8}
|
||||
- docker push $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:test
|
||||
- docker push $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:${DRONE_COMMIT_SHA:0:8}
|
||||
@@ -105,7 +105,7 @@ steps:
|
||||
commands:
|
||||
- echo "$DOCKER_PASSWORD" | docker login "$DOCKER_REGISTRY" -u "$DOCKER_USERNAME" --password-stdin
|
||||
- cd frontend
|
||||
- docker build -t $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:staging -f Dockerfile --build-arg VITE_API_BASE_URL=https://aiedu.ireborn.com.cn .
|
||||
- docker build -t $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:staging -f Dockerfile --target production --build-arg VITE_API_BASE_URL=https://aiedu.ireborn.com.cn .
|
||||
- docker push $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:staging
|
||||
|
||||
volumes:
|
||||
@@ -161,7 +161,7 @@ steps:
|
||||
commands:
|
||||
- echo "$DOCKER_PASSWORD" | docker login "$DOCKER_REGISTRY" -u "$DOCKER_USERNAME" --password-stdin
|
||||
- cd frontend
|
||||
- docker build -t $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:main -f Dockerfile --build-arg VITE_API_BASE_URL=https://hua.ireborn.com.cn .
|
||||
- docker build -t $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:main -f Dockerfile --target production --build-arg VITE_API_BASE_URL=https://hua.ireborn.com.cn .
|
||||
- docker tag $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:main $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:latest
|
||||
- docker push $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:main
|
||||
- docker push $DOCKER_REGISTRY/ireborn/kaopeilian-frontend:latest
|
||||
|
||||
@@ -41,6 +41,7 @@ UPLOAD_DIR=uploads
|
||||
COZE_OAUTH_CLIENT_ID=1114009328887
|
||||
COZE_OAUTH_PUBLIC_KEY_ID=GGs9pw0BDHx2k9vGGehUyRgKV-PyUWLBncDs-YNNN_I
|
||||
COZE_OAUTH_PRIVATE_KEY_PATH=/app/secrets/coze_private_key.pem
|
||||
COZE_WORKSPACE_ID=7461992708538974244
|
||||
COZE_PRACTICE_BOT_ID=7602204855037591602
|
||||
|
||||
# Dify 工作流 API Key 配置
|
||||
|
||||
@@ -734,14 +734,27 @@ async def end_practice_session(
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 将 ORM 对象转换为响应格式,避免 DetachedInstanceError
|
||||
session_data = PracticeSessionResponse(
|
||||
id=session.id,
|
||||
session_id=session.session_id,
|
||||
user_id=session.user_id,
|
||||
scene_id=session.scene_id,
|
||||
scene_name=session.scene_name or "",
|
||||
scene_type=session.scene_type,
|
||||
conversation_id=session.conversation_id,
|
||||
start_time=session.start_time,
|
||||
end_time=session.end_time,
|
||||
duration_seconds=session.duration_seconds or 0,
|
||||
turns=session.turns or 0,
|
||||
status=session.status,
|
||||
created_at=session.created_at
|
||||
)
|
||||
|
||||
return ResponseModel(
|
||||
code=200,
|
||||
message="会话已结束",
|
||||
data={
|
||||
"session": session,
|
||||
"exp_result": exp_result,
|
||||
"new_badges": new_badges
|
||||
}
|
||||
data=session_data
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
@@ -815,7 +828,23 @@ async def analyze_practice_session(
|
||||
# 解析分析结果
|
||||
analysis_result = analysis_data.get("analysis", {})
|
||||
|
||||
# 保存分析报告
|
||||
# 检查报告是否已存在
|
||||
existing_report = await db.execute(
|
||||
select(PracticeReport).where(PracticeReport.session_id == session_id)
|
||||
)
|
||||
report = existing_report.scalar_one_or_none()
|
||||
|
||||
if report:
|
||||
# 更新现有报告
|
||||
report.total_score = analysis_result.get("total_score")
|
||||
report.score_breakdown = analysis_result.get("score_breakdown")
|
||||
report.ability_dimensions = analysis_result.get("ability_dimensions")
|
||||
report.dialogue_review = analysis_result.get("dialogue_annotations")
|
||||
report.suggestions = analysis_result.get("suggestions")
|
||||
report.workflow_run_id = f"{v2_result.ai_provider}_{v2_result.ai_latency_ms}ms"
|
||||
logger.info(f"更新现有分析报告: session_id={session_id}")
|
||||
else:
|
||||
# 创建新报告
|
||||
report = PracticeReport(
|
||||
session_id=session_id,
|
||||
total_score=analysis_result.get("total_score"),
|
||||
@@ -826,8 +855,8 @@ async def analyze_practice_session(
|
||||
workflow_run_id=f"{v2_result.ai_provider}_{v2_result.ai_latency_ms}ms",
|
||||
task_id=None
|
||||
)
|
||||
|
||||
db.add(report)
|
||||
|
||||
await db.commit()
|
||||
|
||||
logger.info(f"分析报告已保存: session_id={session_id}, total_score={report.total_score}")
|
||||
@@ -883,7 +912,53 @@ async def get_practice_report(
|
||||
report = result.scalar_one_or_none()
|
||||
|
||||
if not report:
|
||||
raise HTTPException(status_code=404, detail="分析报告不存在,请先生成报告")
|
||||
# 报告不存在,自动生成
|
||||
logger.info(f"报告不存在,自动生成: session_id={session_id}")
|
||||
|
||||
# 查询对话历史
|
||||
result = await db.execute(
|
||||
select(PracticeDialogue).where(
|
||||
PracticeDialogue.session_id == session_id
|
||||
).order_by(PracticeDialogue.sequence)
|
||||
)
|
||||
dialogue_list = result.scalars().all()
|
||||
|
||||
if not dialogue_list:
|
||||
raise HTTPException(status_code=404, detail="没有对话记录,无法生成报告")
|
||||
|
||||
# 构建对话历史
|
||||
dialogue_history = [
|
||||
{"role": "user" if d.speaker == "user" else "assistant", "content": d.content}
|
||||
for d in dialogue_list
|
||||
]
|
||||
|
||||
# 调用分析服务
|
||||
from app.services.ai.practice_analysis_service import PracticeAnalysisService
|
||||
import json
|
||||
|
||||
practice_analysis_service = PracticeAnalysisService()
|
||||
analysis_result = await practice_analysis_service.analyze(dialogue_history, db=db)
|
||||
|
||||
if not analysis_result.success:
|
||||
raise HTTPException(status_code=500, detail=f"分析失败: {analysis_result.error}")
|
||||
|
||||
analysis_data = analysis_result.to_dict()
|
||||
|
||||
# 保存报告
|
||||
report = PracticeReport(
|
||||
session_id=session_id,
|
||||
total_score=analysis_data.get("overall_score", 0),
|
||||
score_breakdown=analysis_data.get("score_breakdown", []),
|
||||
ability_dimensions=analysis_data.get("ability_dimensions", []),
|
||||
dialogue_review=analysis_data.get("dialogue_review", []),
|
||||
suggestions=analysis_data.get("suggestions", []),
|
||||
summary=analysis_data.get("summary", ""),
|
||||
raw_response=json.dumps(analysis_data, ensure_ascii=False)
|
||||
)
|
||||
db.add(report)
|
||||
await db.commit()
|
||||
await db.refresh(report)
|
||||
logger.info(f"报告自动生成成功: session_id={session_id}, 总分={report.total_score}")
|
||||
|
||||
# 3. 查询完整对话记录(从数据库)
|
||||
result = await db.execute(
|
||||
|
||||
@@ -309,6 +309,7 @@ class MistakeService:
|
||||
ExamMistake.question_type,
|
||||
ExamMistake.knowledge_point_id,
|
||||
KnowledgePoint.name.label("knowledge_point_name"),
|
||||
ExamMistake.mastery_status,
|
||||
ExamMistake.created_at
|
||||
).select_from(ExamMistake).join(
|
||||
Exam, ExamMistake.exam_id == Exam.id
|
||||
@@ -339,6 +340,7 @@ class MistakeService:
|
||||
"question_type": row.question_type,
|
||||
"knowledge_point_id": row.knowledge_point_id,
|
||||
"knowledge_point_name": row.knowledge_point_name,
|
||||
"mastery_status": row.mastery_status,
|
||||
"created_at": row.created_at
|
||||
})
|
||||
|
||||
|
||||
218
deploy/scripts/deploy-tenant.sh
Normal file
218
deploy/scripts/deploy-tenant.sh
Normal file
@@ -0,0 +1,218 @@
|
||||
#!/bin/bash
|
||||
# ================================================================
|
||||
# 租户后端部署脚本
|
||||
# 用于创建/更新租户的后端容器,确保包含所有必要的挂载
|
||||
#
|
||||
# 使用方法:
|
||||
# ./deploy-tenant.sh <tenant_code> [image_tag]
|
||||
#
|
||||
# 示例:
|
||||
# ./deploy-tenant.sh ex main # 部署 ex 租户,使用 main 镜像
|
||||
# ./deploy-tenant.sh hua # 部署 hua 租户,默认 main 镜像
|
||||
# ./deploy-tenant.sh all # 部署所有租户
|
||||
#
|
||||
# 注意:
|
||||
# - 此脚本需要在服务器 120.79.247.16 上执行
|
||||
# - 确保 secrets 目录存在:/data/prod-envs/secrets/coze_private_key.pem
|
||||
# ================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# 配置
|
||||
IMAGE_REGISTRY="crpi-na6dit5kd0bonqed.cn-guangzhou.personal.cr.aliyuncs.com/ireborn/kaopeilian-backend"
|
||||
ENV_DIR="/root/aiedu/kaopeilian-backend"
|
||||
DATA_DIR="/data/prod-envs"
|
||||
SECRETS_DIR="/data/prod-envs/secrets"
|
||||
|
||||
# 租户配置(端口映射)
|
||||
declare -A TENANT_PORTS=(
|
||||
["hua"]="8010"
|
||||
["yy"]="8011"
|
||||
["hl"]="8012"
|
||||
["xy"]="8013"
|
||||
["fw"]="8014"
|
||||
["ex"]="8015"
|
||||
["cxw"]="8016"
|
||||
)
|
||||
|
||||
# 所有租户列表
|
||||
ALL_TENANTS=("hua" "yy" "hl" "xy" "fw" "ex" "cxw")
|
||||
|
||||
# 颜色输出
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
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 "检查前置条件..."
|
||||
|
||||
# 检查 Docker
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
log_error "Docker 未运行"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查 secrets 目录
|
||||
if [ ! -f "${SECRETS_DIR}/coze_private_key.pem" ]; then
|
||||
log_error "私钥文件不存在: ${SECRETS_DIR}/coze_private_key.pem"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "前置条件检查通过"
|
||||
}
|
||||
|
||||
# 部署单个租户
|
||||
deploy_tenant() {
|
||||
local tenant=$1
|
||||
local image_tag=${2:-main}
|
||||
local port=${TENANT_PORTS[$tenant]}
|
||||
|
||||
if [ -z "$port" ]; then
|
||||
log_error "未知租户: $tenant"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local container_name="${tenant}-backend"
|
||||
local env_file="${ENV_DIR}/.env.${tenant}"
|
||||
local image="${IMAGE_REGISTRY}:${image_tag}"
|
||||
|
||||
log_info "=========================================="
|
||||
log_info "部署租户: ${tenant}"
|
||||
log_info "容器名: ${container_name}"
|
||||
log_info "端口: ${port}:8000"
|
||||
log_info "镜像: ${image}"
|
||||
log_info "=========================================="
|
||||
|
||||
# 检查环境变量文件
|
||||
if [ ! -f "$env_file" ]; then
|
||||
log_error "环境变量文件不存在: $env_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 创建必要的目录
|
||||
mkdir -p "${DATA_DIR}/uploads-${tenant}"
|
||||
mkdir -p "${DATA_DIR}/logs-${tenant}"
|
||||
|
||||
# 拉取最新镜像
|
||||
log_info "拉取镜像..."
|
||||
docker pull "$image" || {
|
||||
log_warn "拉取镜像失败,使用本地镜像"
|
||||
}
|
||||
|
||||
# 停止并删除旧容器
|
||||
if docker ps -a --format '{{.Names}}' | grep -q "^${container_name}$"; then
|
||||
log_info "停止旧容器..."
|
||||
docker stop "$container_name" 2>/dev/null || true
|
||||
docker rm "$container_name" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# 创建新容器
|
||||
log_info "创建新容器..."
|
||||
docker run -d \
|
||||
--name "$container_name" \
|
||||
--restart unless-stopped \
|
||||
--env-file "$env_file" \
|
||||
-e TZ=Asia/Shanghai \
|
||||
-e PYTHONPATH=/app \
|
||||
-e WORKERS=4 \
|
||||
-e RELOAD=false \
|
||||
-p "${port}:8000" \
|
||||
-v "${DATA_DIR}/uploads-${tenant}:/app/uploads:rw" \
|
||||
-v "${DATA_DIR}/logs-${tenant}:/app/logs:rw" \
|
||||
-v "${SECRETS_DIR}:/app/secrets:ro" \
|
||||
-v /etc/localtime:/etc/localtime:ro \
|
||||
-v /etc/timezone:/etc/timezone:ro \
|
||||
--network kaopeilian-network \
|
||||
--label "com.centurylinklabs.watchtower.enable=false" \
|
||||
"$image"
|
||||
|
||||
# 连接到 prod-network
|
||||
log_info "连接网络..."
|
||||
docker network connect prod-network "$container_name" 2>/dev/null || true
|
||||
|
||||
# 等待容器启动
|
||||
log_info "等待容器启动..."
|
||||
sleep 5
|
||||
|
||||
# 检查容器状态
|
||||
local status=$(docker inspect "$container_name" --format '{{.State.Status}}' 2>/dev/null)
|
||||
if [ "$status" = "running" ]; then
|
||||
log_info "✓ ${container_name} 部署成功"
|
||||
|
||||
# 验证 secrets 挂载
|
||||
if docker exec "$container_name" ls /app/secrets/coze_private_key.pem > /dev/null 2>&1; then
|
||||
log_info "✓ secrets 挂载验证成功"
|
||||
else
|
||||
log_warn "✗ secrets 挂载验证失败"
|
||||
fi
|
||||
else
|
||||
log_error "✗ ${container_name} 启动失败,状态: $status"
|
||||
docker logs "$container_name" --tail 20
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 部署所有租户
|
||||
deploy_all_tenants() {
|
||||
local image_tag=${1:-main}
|
||||
|
||||
log_info "部署所有租户 (镜像标签: $image_tag)"
|
||||
|
||||
for tenant in "${ALL_TENANTS[@]}"; do
|
||||
deploy_tenant "$tenant" "$image_tag"
|
||||
echo ""
|
||||
done
|
||||
|
||||
log_info "所有租户部署完成"
|
||||
}
|
||||
|
||||
# 显示帮助
|
||||
show_help() {
|
||||
echo "用法: $0 <tenant_code|all> [image_tag]"
|
||||
echo ""
|
||||
echo "租户代码:"
|
||||
echo " hua - 华尔倍丽"
|
||||
echo " yy - 杨扬宠物"
|
||||
echo " hl - 武汉禾丽"
|
||||
echo " xy - 芯颜定制"
|
||||
echo " fw - 飞沃"
|
||||
echo " ex - 恩喜成都总院"
|
||||
echo " cxw - 崔曦文"
|
||||
echo " all - 所有租户"
|
||||
echo ""
|
||||
echo "镜像标签 (可选, 默认: main):"
|
||||
echo " main - 生产环境"
|
||||
echo " staging - 预发布环境"
|
||||
echo " test - 测试环境"
|
||||
echo ""
|
||||
echo "示例:"
|
||||
echo " $0 ex main # 部署 ex 租户"
|
||||
echo " $0 all # 部署所有租户"
|
||||
}
|
||||
|
||||
# 主函数
|
||||
main() {
|
||||
local tenant=${1:-}
|
||||
local image_tag=${2:-main}
|
||||
|
||||
if [ -z "$tenant" ] || [ "$tenant" = "-h" ] || [ "$tenant" = "--help" ]; then
|
||||
show_help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
check_prerequisites
|
||||
|
||||
if [ "$tenant" = "all" ]; then
|
||||
deploy_all_tenants "$image_tag"
|
||||
else
|
||||
deploy_tenant "$tenant" "$image_tag"
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -28,7 +28,8 @@ COPY package*.json ./
|
||||
RUN npm config set registry https://registry.npmmirror.com
|
||||
|
||||
# 安装所有依赖(包括开发依赖,跳过husky)
|
||||
RUN npm install --silent --ignore-scripts
|
||||
# 注意:NODE_ENV=production 会跳过 devDependencies,所以用 --include=dev
|
||||
RUN npm install --silent --ignore-scripts --include=dev
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
@@ -43,7 +44,8 @@ RUN echo "======================================" && \
|
||||
echo "======================================"
|
||||
|
||||
# 构建应用(使用环境变量中的API地址)
|
||||
RUN npm run build
|
||||
# 增加 Node.js 内存限制避免 OOM
|
||||
RUN NODE_OPTIONS="--max-old-space-size=4096" npm run build
|
||||
|
||||
# ============================================
|
||||
# 生产阶段 - 轻量级nginx镜像
|
||||
|
||||
@@ -583,7 +583,7 @@ const loadMistakes = async () => {
|
||||
id: item.id,
|
||||
type: item.question_type || 'single',
|
||||
difficulty: 'medium', // 暂无此字段
|
||||
masteryStatus: 'unmastered', // 暂无此字段
|
||||
masteryStatus: item.mastery_status || 'unmastered',
|
||||
title: item.question_content,
|
||||
yourAnswer: item.user_answer,
|
||||
correctAnswer: item.correct_answer,
|
||||
|
||||
@@ -552,6 +552,13 @@
|
||||
<el-icon><Search /></el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
<el-button
|
||||
type="primary"
|
||||
:plain="!isAllSelected"
|
||||
@click="toggleSelectAll"
|
||||
>
|
||||
{{ isAllSelected ? '取消全选' : '全选' }}
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<div class="available-positions">
|
||||
@@ -719,6 +726,30 @@ const filteredAvailablePositions = computed(() => {
|
||||
return filtered
|
||||
})
|
||||
|
||||
// 是否全选
|
||||
const isAllSelected = computed(() => {
|
||||
if (filteredAvailablePositions.value.length === 0) return false
|
||||
return filteredAvailablePositions.value.every(
|
||||
(p: any) => selectedPositions.value.includes(p.id)
|
||||
)
|
||||
})
|
||||
|
||||
// 全选/取消全选
|
||||
const toggleSelectAll = () => {
|
||||
if (isAllSelected.value) {
|
||||
// 取消全选:移除当前筛选结果中的所有岗位
|
||||
const filteredIds = filteredAvailablePositions.value.map((p: any) => p.id)
|
||||
selectedPositions.value = selectedPositions.value.filter(
|
||||
id => !filteredIds.includes(id)
|
||||
)
|
||||
} else {
|
||||
// 全选:添加当前筛选结果中的所有岗位
|
||||
const filteredIds = filteredAvailablePositions.value.map((p: any) => p.id)
|
||||
const newSelection = new Set([...selectedPositions.value, ...filteredIds])
|
||||
selectedPositions.value = Array.from(newSelection)
|
||||
}
|
||||
}
|
||||
|
||||
// 考试设置相关
|
||||
const examSettingsLoading = ref(false)
|
||||
const examSettings = reactive({
|
||||
@@ -2920,6 +2951,9 @@ const loadAvailablePositions = async () => {
|
||||
// 岗位选择器样式
|
||||
.position-selector-content {
|
||||
.selector-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user