refactor: 课程包统计与启动脚本优化

1. LessonStatus 枚举:code 值改为大写(与枚举名一致)
2. CoursePackageMapper:新增课程包统计方法
   - incrementUsageCount: 增加使用次数
   - updateTeacherCount: 更新教师数量(去重统计)
3. 启动脚本:端口调整为 8481(后端) 和 5174(前端)
This commit is contained in:
En 2026-03-20 11:15:08 +08:00
parent 79e90410dd
commit 13fc0e720e
4 changed files with 36 additions and 13 deletions

View File

@ -8,10 +8,10 @@ import lombok.Getter;
@Getter
public enum LessonStatus {
SCHEDULED("scheduled", "Scheduled"),
IN_PROGRESS("in_progress", "In Progress"),
COMPLETED("completed", "Completed"),
CANCELLED("cancelled", "Cancelled");
SCHEDULED("SCHEDULED", "Scheduled"),
IN_PROGRESS("IN_PROGRESS", "In Progress"),
COMPLETED("COMPLETED", "Completed"),
CANCELLED("CANCELLED", "Cancelled");
private final String code;
private final String description;

View File

@ -3,7 +3,30 @@ package com.reading.platform.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.reading.platform.entity.CoursePackage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
@Mapper
public interface CoursePackageMapper extends BaseMapper<CoursePackage> {
/**
* 增加课程包使用次数
* @param coursePackageId 课程包 ID
*/
@Update("UPDATE course_package SET usage_count = usage_count + 1 WHERE id = #{coursePackageId}")
void incrementUsageCount(@Param("coursePackageId") Long coursePackageId);
/**
* 更新课程包教师数量去重统计已完成课程的教师
* @param coursePackageId 课程包 ID
*/
@Update("UPDATE course_package cp " +
"SET teacher_count = ( " +
" SELECT COUNT(DISTINCT l.teacher_id) " +
" FROM lesson l " +
" WHERE l.course_id = #{coursePackageId} " +
" AND l.status = 'completed' " +
") " +
"WHERE cp.id = #{coursePackageId}")
void updateTeacherCount(@Param("coursePackageId") Long coursePackageId);
}

View File

@ -33,13 +33,13 @@ check_port() {
}
# 检查并停止占用端口的进程
check_port 8480 "后端"
check_port 8481 "后端"
if [ $? -eq 1 ]; then
echo "❌ 后端启动取消"
exit 1
fi
check_port 5173 "前端"
check_port 5174 "前端"
if [ $? -eq 1 ]; then
echo "❌ 前端启动取消"
exit 1
@ -73,7 +73,7 @@ echo "📄 日志文件:/tmp/reading-platform-java.log"
# 等待后端启动
echo "⏳ 等待后端服务启动..."
for i in {1..60}; do
if curl -s http://localhost:8480/actuator/health > /dev/null 2>&1; then
if curl -s http://localhost:8080/actuator/health > /dev/null 2>&1; then
echo "✅ 后端服务就绪"
break
fi
@ -122,9 +122,9 @@ echo "======================================"
echo " ✅ 所有服务启动成功!"
echo "======================================"
echo ""
echo "📍 后端 API: http://localhost:8480"
echo "📍 后端 API: http://localhost:8080"
echo "📍 前端页面: http://localhost:5173"
echo "📍 API 文档: http://localhost:8480/api/v1"
echo "📍 API 文档: http://localhost:8080/api/v1"
echo ""
echo "📊 查看后端日志tail -f /tmp/reading-platform-java.log"
echo "📊 查看前端日志tail -f /tmp/reading-platform-frontend.log"

View File

@ -9,8 +9,8 @@ echo ""
# 停止后端
echo "🛑 停止后端服务 (Spring Boot)..."
if lsof -ti:8480 > /dev/null 2>&1; then
lsof -ti:8480 | xargs kill -9 2>/dev/null
if lsof -ti:8481 > /dev/null 2>&1; then
lsof -ti:8481 | xargs kill -9 2>/dev/null
echo "✅ 后端服务已停止"
else
echo " 后端服务未运行"
@ -18,8 +18,8 @@ fi
# 停止前端
echo "🛑 停止前端服务..."
if lsof -ti:5173 > /dev/null 2>&1; then
lsof -ti:5173 | xargs kill -9 2>/dev/null
if lsof -ti:5174 > /dev/null 2>&1; then
lsof -ti:5174 | xargs kill -9 2>/dev/null
echo "✅ 前端服务已停止"
else
echo " 前端服务未运行"