|
@@ -4,10 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.train.common.Result;
|
|
import com.train.common.Result;
|
|
|
import com.train.entity.TrainClass;
|
|
import com.train.entity.TrainClass;
|
|
|
import com.train.entity.TrainCourse;
|
|
import com.train.entity.TrainCourse;
|
|
|
|
|
+import com.train.entity.TrainCourseSection;
|
|
|
import com.train.mapper.TrainClassMapper;
|
|
import com.train.mapper.TrainClassMapper;
|
|
|
import com.train.mapper.TrainCourseMapper;
|
|
import com.train.mapper.TrainCourseMapper;
|
|
|
|
|
+import com.train.mapper.TrainCourseSectionMapper;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -18,11 +21,11 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 管理端-课程管理(L0/L1/L2/L3/L4 课程主数据 + 价格)。
|
|
|
|
|
|
|
+ * 管理端-课程管理(L0/L1/L2/L3/L4 课程主数据 + 价格 + 课程版块)。
|
|
|
* <p>报名=报课程:课程级 price/member_price(分)作为报名支付价格来源;
|
|
* <p>报名=报课程:课程级 price/member_price(分)作为报名支付价格来源;
|
|
|
* 班次仅关联课程(course_id),作为助教审核时分配的上课期次。
|
|
* 班次仅关联课程(course_id),作为助教审核时分配的上课期次。
|
|
|
*/
|
|
*/
|
|
|
-@Tag(name = "管理端-课程管理", description = "课程列表、新建、编辑(含价格/时间/状态)")
|
|
|
|
|
|
|
+@Tag(name = "管理端-课程管理", description = "课程列表、新建、编辑(含价格/时间/状态)+ 课程版块维护")
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/api/admin/course")
|
|
@RequestMapping("/api/admin/course")
|
|
|
public class AdminCourseController {
|
|
public class AdminCourseController {
|
|
@@ -31,6 +34,8 @@ public class AdminCourseController {
|
|
|
private TrainCourseMapper trainCourseMapper;
|
|
private TrainCourseMapper trainCourseMapper;
|
|
|
@Resource
|
|
@Resource
|
|
|
private TrainClassMapper trainClassMapper;
|
|
private TrainClassMapper trainClassMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private TrainCourseSectionMapper trainCourseSectionMapper;
|
|
|
|
|
|
|
|
@Operation(summary = "课程列表(含各班次数量/可分配班次)")
|
|
@Operation(summary = "课程列表(含各班次数量/可分配班次)")
|
|
|
@PostMapping("/list")
|
|
@PostMapping("/list")
|
|
@@ -117,4 +122,108 @@ public class AdminCourseController {
|
|
|
.eq(TrainClass::getCourseId, courseId)
|
|
.eq(TrainClass::getCourseId, courseId)
|
|
|
.orderByAsc(TrainClass::getId)));
|
|
.orderByAsc(TrainClass::getId)));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 课程版块维护(D1) ====================
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "课程版块列表")
|
|
|
|
|
+ @PostMapping("/section/list")
|
|
|
|
|
+ public Result<List<TrainCourseSection>> sectionList(@RequestBody Map<String, Object> body) {
|
|
|
|
|
+ if (body == null || body.get("courseId") == null) {
|
|
|
|
|
+ return Result.error("缺少课程ID");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long courseId = Long.valueOf(body.get("courseId").toString());
|
|
|
|
|
+ return Result.success(trainCourseSectionMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<TrainCourseSection>()
|
|
|
|
|
+ .eq(TrainCourseSection::getCourseId, courseId)
|
|
|
|
|
+ .orderByAsc(TrainCourseSection::getSort)
|
|
|
|
|
+ .orderByAsc(TrainCourseSection::getId)));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "新建课程版块")
|
|
|
|
|
+ @PostMapping("/section/create")
|
|
|
|
|
+ public Result<TrainCourseSection> sectionCreate(@RequestBody TrainCourseSection section) {
|
|
|
|
|
+ if (section.getCourseId() == null) {
|
|
|
|
|
+ return Result.error("缺少课程ID");
|
|
|
|
|
+ }
|
|
|
|
|
+ TrainCourse exist = trainCourseMapper.selectById(section.getCourseId());
|
|
|
|
|
+ if (exist == null) {
|
|
|
|
|
+ return Result.error("课程不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!StringUtils.hasText(section.getTitle())) {
|
|
|
|
|
+ return Result.error("版块标题不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ section.setTitle(section.getTitle().trim());
|
|
|
|
|
+ if (section.getSort() == null) {
|
|
|
|
|
+ section.setSort(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (section.getEnabled() == null) {
|
|
|
|
|
+ section.setEnabled(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ trainCourseSectionMapper.insert(section);
|
|
|
|
|
+ return Result.success(section);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "编辑课程版块(标题/说明/排序/启用)")
|
|
|
|
|
+ @PostMapping("/section/update")
|
|
|
|
|
+ public Result<Boolean> sectionUpdate(@RequestBody TrainCourseSection section) {
|
|
|
|
|
+ if (section.getId() == null) {
|
|
|
|
|
+ return Result.error("缺少版块ID");
|
|
|
|
|
+ }
|
|
|
|
|
+ TrainCourseSection exist = trainCourseSectionMapper.selectById(section.getId());
|
|
|
|
|
+ if (exist == null) {
|
|
|
|
|
+ return Result.error("版块不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 仅更新允许编辑的字段,其余保持原值
|
|
|
|
|
+ if (StringUtils.hasText(section.getTitle())) {
|
|
|
|
|
+ exist.setTitle(section.getTitle().trim());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (section.getDescription() != null) {
|
|
|
|
|
+ exist.setDescription(section.getDescription());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (section.getSort() != null) {
|
|
|
|
|
+ exist.setSort(section.getSort());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (section.getEnabled() != null) {
|
|
|
|
|
+ exist.setEnabled(section.getEnabled());
|
|
|
|
|
+ }
|
|
|
|
|
+ trainCourseSectionMapper.updateById(exist);
|
|
|
|
|
+ return Result.success(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "删除课程版块")
|
|
|
|
|
+ @PostMapping("/section/delete")
|
|
|
|
|
+ public Result<Boolean> sectionDelete(@RequestBody Map<String, Object> body) {
|
|
|
|
|
+ if (body == null || body.get("id") == null) {
|
|
|
|
|
+ return Result.error("缺少版块ID");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long id = Long.valueOf(body.get("id").toString());
|
|
|
|
|
+ trainCourseSectionMapper.deleteById(id);
|
|
|
|
|
+ return Result.success(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ @Operation(summary = "版块批量排序(items: [{id, sort}])")
|
|
|
|
|
+ @PostMapping("/section/sort")
|
|
|
|
|
+ public Result<Boolean> sectionSort(@RequestBody Map<String, Object> body) {
|
|
|
|
|
+ if (body == null || body.get("items") == null) {
|
|
|
|
|
+ return Result.error("缺少排序列表");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Map<String, Object>> items = (List<Map<String, Object>>) body.get("items");
|
|
|
|
|
+ if (items.isEmpty()) {
|
|
|
|
|
+ return Result.error("排序列表不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ for (Map<String, Object> item : items) {
|
|
|
|
|
+ Object idObj = item.get("id");
|
|
|
|
|
+ Object sortObj = item.get("sort");
|
|
|
|
|
+ if (idObj == null || sortObj == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ TrainCourseSection exist = trainCourseSectionMapper.selectById(Long.valueOf(idObj.toString()));
|
|
|
|
|
+ if (exist != null) {
|
|
|
|
|
+ exist.setSort(Integer.valueOf(sortObj.toString()));
|
|
|
|
|
+ trainCourseSectionMapper.updateById(exist);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.success(true);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|