refactor: 消除课程和套餐状态魔法值,统一使用 CourseStatus 枚举
- 完善 CourseStatus 枚举值:DRAFT, PENDING, REJECTED, PUBLISHED, ARCHIVED, APPROVED - 替换 CoursePackageService 中的魔法值为 CourseStatus 枚举 - 替换 CourseServiceImpl 中的魔法值为 CourseStatus 枚举 - 替换 TeacherStatsServiceImpl 中的魔法值为 CourseStatus 枚举 - 适配前端状态值,使用大写枚举值 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
05d075eefc
commit
a766222733
@ -3,14 +3,17 @@ package com.reading.platform.common.enums;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Course Status Enum
|
* 课程状态枚举
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public enum CourseStatus {
|
public enum CourseStatus {
|
||||||
|
|
||||||
DRAFT("draft", "Draft"),
|
DRAFT("DRAFT", "草稿"),
|
||||||
PUBLISHED("published", "PUBLISHED"),
|
PENDING("PENDING", "待审核"),
|
||||||
ARCHIVED("archived", "Archived");
|
REJECTED("REJECTED", "已驳回"),
|
||||||
|
PUBLISHED("PUBLISHED", "已发布"),
|
||||||
|
ARCHIVED("ARCHIVED", "已下架"),
|
||||||
|
APPROVED("APPROVED", "审核通过");
|
||||||
|
|
||||||
private final String code;
|
private final String code;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.reading.platform.common.enums.CourseStatus;
|
||||||
import com.reading.platform.common.exception.BusinessException;
|
import com.reading.platform.common.exception.BusinessException;
|
||||||
import com.reading.platform.common.response.PageResult;
|
import com.reading.platform.common.response.PageResult;
|
||||||
import com.reading.platform.dto.response.CoursePackageResponse;
|
import com.reading.platform.dto.response.CoursePackageResponse;
|
||||||
@ -170,7 +171,7 @@ public class CoursePackageService extends ServiceImpl<CoursePackageMapper, Cours
|
|||||||
pkg.setDiscountType(discountType);
|
pkg.setDiscountType(discountType);
|
||||||
// 存储为 JSON 数组格式
|
// 存储为 JSON 数组格式
|
||||||
pkg.setGradeLevels(JSON.toJSONString(gradeLevels));
|
pkg.setGradeLevels(JSON.toJSONString(gradeLevels));
|
||||||
pkg.setStatus("DRAFT");
|
pkg.setStatus(CourseStatus.DRAFT.getCode());
|
||||||
pkg.setCourseCount(0);
|
pkg.setCourseCount(0);
|
||||||
pkg.setCreatedAt(LocalDateTime.now());
|
pkg.setCreatedAt(LocalDateTime.now());
|
||||||
|
|
||||||
@ -289,7 +290,7 @@ public class CoursePackageService extends ServiceImpl<CoursePackageMapper, Cours
|
|||||||
throw new BusinessException("套餐必须包含至少一个课程包");
|
throw new BusinessException("套餐必须包含至少一个课程包");
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg.setStatus("PENDING_REVIEW");
|
pkg.setStatus(CourseStatus.PENDING.getCode());
|
||||||
pkg.setSubmittedAt(LocalDateTime.now());
|
pkg.setSubmittedAt(LocalDateTime.now());
|
||||||
pkg.setSubmittedBy(userId);
|
pkg.setSubmittedBy(userId);
|
||||||
packageMapper.updateById(pkg);
|
packageMapper.updateById(pkg);
|
||||||
@ -308,12 +309,12 @@ public class CoursePackageService extends ServiceImpl<CoursePackageMapper, Cours
|
|||||||
throw new BusinessException("套餐不存在");
|
throw new BusinessException("套餐不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!"PENDING_REVIEW".equals(pkg.getStatus())) {
|
if (!CourseStatus.PENDING.getCode().equals(pkg.getStatus())) {
|
||||||
log.warn("套餐审核失败,状态不正确,id={}, status={}", id, pkg.getStatus());
|
log.warn("套餐审核失败,状态不正确,id={}, status={}", id, pkg.getStatus());
|
||||||
throw new BusinessException("只有待审核状态的套餐可以审核");
|
throw new BusinessException("只有待审核状态的套餐可以审核");
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg.setStatus(approved ? "APPROVED" : "REJECTED");
|
pkg.setStatus(approved ? CourseStatus.APPROVED.getCode() : CourseStatus.REJECTED.getCode());
|
||||||
pkg.setReviewedAt(LocalDateTime.now());
|
pkg.setReviewedAt(LocalDateTime.now());
|
||||||
pkg.setReviewedBy(userId);
|
pkg.setReviewedBy(userId);
|
||||||
pkg.setReviewComment(comment);
|
pkg.setReviewComment(comment);
|
||||||
@ -333,12 +334,12 @@ public class CoursePackageService extends ServiceImpl<CoursePackageMapper, Cours
|
|||||||
throw new BusinessException("套餐不存在");
|
throw new BusinessException("套餐不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!"APPROVED".equals(pkg.getStatus())) {
|
if (!CourseStatus.APPROVED.getCode().equals(pkg.getStatus())) {
|
||||||
log.warn("套餐发布失败,状态不正确,id={}, status={}", id, pkg.getStatus());
|
log.warn("套餐发布失败,状态不正确,id={}, status={}", id, pkg.getStatus());
|
||||||
throw new BusinessException("只有已审核通过的套餐可以发布");
|
throw new BusinessException("只有已审核通过的套餐可以发布");
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg.setStatus("PUBLISHED");
|
pkg.setStatus(CourseStatus.PUBLISHED.getCode());
|
||||||
pkg.setPublishedAt(LocalDateTime.now());
|
pkg.setPublishedAt(LocalDateTime.now());
|
||||||
packageMapper.updateById(pkg);
|
packageMapper.updateById(pkg);
|
||||||
log.info("套餐发布成功,id={}", id);
|
log.info("套餐发布成功,id={}", id);
|
||||||
@ -356,7 +357,7 @@ public class CoursePackageService extends ServiceImpl<CoursePackageMapper, Cours
|
|||||||
throw new BusinessException("套餐不存在");
|
throw new BusinessException("套餐不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg.setStatus("OFFLINE");
|
pkg.setStatus(CourseStatus.ARCHIVED.getCode());
|
||||||
packageMapper.updateById(pkg);
|
packageMapper.updateById(pkg);
|
||||||
log.info("套餐下线成功,id={}", id);
|
log.info("套餐下线成功,id={}", id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.reading.platform.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.reading.platform.common.enums.CourseStatus;
|
||||||
import com.reading.platform.common.enums.ErrorCode;
|
import com.reading.platform.common.enums.ErrorCode;
|
||||||
import com.reading.platform.common.exception.BusinessException;
|
import com.reading.platform.common.exception.BusinessException;
|
||||||
import com.reading.platform.dto.request.CourseCreateRequest;
|
import com.reading.platform.dto.request.CourseCreateRequest;
|
||||||
@ -49,7 +50,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
|
|||||||
course.setDifficultyLevel(request.getDifficultyLevel());
|
course.setDifficultyLevel(request.getDifficultyLevel());
|
||||||
course.setDurationMinutes(request.getDurationMinutes());
|
course.setDurationMinutes(request.getDurationMinutes());
|
||||||
course.setObjectives(request.getObjectives());
|
course.setObjectives(request.getObjectives());
|
||||||
course.setStatus("draft");
|
course.setStatus(CourseStatus.DRAFT.getCode());
|
||||||
course.setIsSystem(0);
|
course.setIsSystem(0);
|
||||||
|
|
||||||
// Course Package Fields
|
// Course Package Fields
|
||||||
@ -110,7 +111,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
|
|||||||
course.setDifficultyLevel(request.getDifficultyLevel());
|
course.setDifficultyLevel(request.getDifficultyLevel());
|
||||||
course.setDurationMinutes(request.getDurationMinutes());
|
course.setDurationMinutes(request.getDurationMinutes());
|
||||||
course.setObjectives(request.getObjectives());
|
course.setObjectives(request.getObjectives());
|
||||||
course.setStatus("draft");
|
course.setStatus(CourseStatus.DRAFT.getCode());
|
||||||
course.setIsSystem(1);
|
course.setIsSystem(1);
|
||||||
|
|
||||||
// Course Package Fields
|
// Course Package Fields
|
||||||
@ -357,9 +358,12 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
|
|||||||
// 只过滤系统课程
|
// 只过滤系统课程
|
||||||
wrapper.eq(Course::getIsSystem, 1);
|
wrapper.eq(Course::getIsSystem, 1);
|
||||||
|
|
||||||
// 审核管理页:仅返回待审核和已驳回,排除已通过/已发布
|
// 审核管理页:仅过滤待审核和已驳回,排除已通过/已发布
|
||||||
if (reviewOnly) {
|
if (reviewOnly) {
|
||||||
wrapper.in(Course::getStatus, List.of("PENDING", "pending", "REJECTED", "rejected"));
|
wrapper.in(Course::getStatus, List.of(
|
||||||
|
CourseStatus.PENDING.getCode(),
|
||||||
|
CourseStatus.REJECTED.getCode()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.hasText(keyword)) {
|
if (StringUtils.hasText(keyword)) {
|
||||||
@ -394,7 +398,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void publishCourse(Long id) {
|
public void publishCourse(Long id) {
|
||||||
Course course = getCourseById(id);
|
Course course = getCourseById(id);
|
||||||
course.setStatus("PUBLISHED");
|
course.setStatus(CourseStatus.PUBLISHED.getCode());
|
||||||
course.setPublishedAt(LocalDateTime.now());
|
course.setPublishedAt(LocalDateTime.now());
|
||||||
courseMapper.updateById(course);
|
courseMapper.updateById(course);
|
||||||
log.info("课程发布成功:id={}", id);
|
log.info("课程发布成功:id={}", id);
|
||||||
@ -404,7 +408,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void archiveCourse(Long id) {
|
public void archiveCourse(Long id) {
|
||||||
Course course = getCourseById(id);
|
Course course = getCourseById(id);
|
||||||
course.setStatus("archived");
|
course.setStatus(CourseStatus.ARCHIVED.getCode());
|
||||||
courseMapper.updateById(course);
|
courseMapper.updateById(course);
|
||||||
log.info("课程归档成功:id={}", id);
|
log.info("课程归档成功:id={}", id);
|
||||||
}
|
}
|
||||||
@ -413,10 +417,10 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void rejectCourse(Long id, String comment) {
|
public void rejectCourse(Long id, String comment) {
|
||||||
Course course = getCourseById(id);
|
Course course = getCourseById(id);
|
||||||
if (!"PENDING".equalsIgnoreCase(course.getStatus()) && !"pending".equals(course.getStatus())) {
|
if (!CourseStatus.PENDING.getCode().equalsIgnoreCase(course.getStatus())) {
|
||||||
log.warn("课程状态非待审核,无法驳回:id={}, status={}", id, course.getStatus());
|
log.warn("课程状态非待审核,无法驳回:id={}, status={}", id, course.getStatus());
|
||||||
}
|
}
|
||||||
course.setStatus("REJECTED");
|
course.setStatus(CourseStatus.REJECTED.getCode());
|
||||||
course.setReviewComment(comment);
|
course.setReviewComment(comment);
|
||||||
course.setReviewedAt(LocalDateTime.now());
|
course.setReviewedAt(LocalDateTime.now());
|
||||||
course.setReviewedBy(1L); // TODO: 从 SecurityUtils 获取当前用户
|
course.setReviewedBy(1L); // TODO: 从 SecurityUtils 获取当前用户
|
||||||
@ -433,7 +437,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
|
|||||||
.or()
|
.or()
|
||||||
.eq(Course::getIsSystem, 1)
|
.eq(Course::getIsSystem, 1)
|
||||||
)
|
)
|
||||||
.eq(Course::getStatus, "PUBLISHED")
|
.eq(Course::getStatus, CourseStatus.PUBLISHED.getCode())
|
||||||
.orderByAsc(Course::getName)
|
.orderByAsc(Course::getName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.reading.platform.service.impl;
|
package com.reading.platform.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.reading.platform.common.enums.CourseStatus;
|
||||||
import com.reading.platform.entity.Clazz;
|
import com.reading.platform.entity.Clazz;
|
||||||
import com.reading.platform.entity.Course;
|
import com.reading.platform.entity.Course;
|
||||||
import com.reading.platform.entity.Lesson;
|
import com.reading.platform.entity.Lesson;
|
||||||
@ -78,7 +79,7 @@ public class TeacherStatsServiceImpl implements TeacherStatsService {
|
|||||||
List<Course> recommendedCourses = courseMapper.selectList(
|
List<Course> recommendedCourses = courseMapper.selectList(
|
||||||
new LambdaQueryWrapper<Course>()
|
new LambdaQueryWrapper<Course>()
|
||||||
.eq(Course::getTenantId, tenantId)
|
.eq(Course::getTenantId, tenantId)
|
||||||
.eq(Course::getStatus, "PUBLISHED")
|
.eq(Course::getStatus, CourseStatus.PUBLISHED.getCode())
|
||||||
.orderByDesc(Course::getUsageCount)
|
.orderByDesc(Course::getUsageCount)
|
||||||
.last("LIMIT 5")
|
.last("LIMIT 5")
|
||||||
);
|
);
|
||||||
@ -132,7 +133,7 @@ public class TeacherStatsServiceImpl implements TeacherStatsService {
|
|||||||
return courseMapper.selectList(
|
return courseMapper.selectList(
|
||||||
new LambdaQueryWrapper<Course>()
|
new LambdaQueryWrapper<Course>()
|
||||||
.eq(Course::getTenantId, tenantId)
|
.eq(Course::getTenantId, tenantId)
|
||||||
.eq(Course::getStatus, "PUBLISHED")
|
.eq(Course::getStatus, CourseStatus.PUBLISHED.getCode())
|
||||||
.orderByDesc(Course::getUsageCount)
|
.orderByDesc(Course::getUsageCount)
|
||||||
.last("LIMIT 10")
|
.last("LIMIT 10")
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user