|
|
@@ -0,0 +1,148 @@
|
|
|
+package com.train.controller.admin;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.train.common.Result;
|
|
|
+import com.train.entity.TrainCourse;
|
|
|
+import com.train.entity.TrainModule;
|
|
|
+import com.train.mapper.TrainCourseMapper;
|
|
|
+import com.train.mapper.TrainModuleMapper;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+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.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 管理端-课程模块(模块化教学:L1/L2 按三本账方向拆模块 + 插班制)。
|
|
|
+ * <p>模块挂课程(course_id),管理端维护模块增删改/排序/启用;
|
|
|
+ * 模块价(分)为插班按模块收费的支付来源。
|
|
|
+ */
|
|
|
+@Tag(name = "管理端-课程模块", description = "模块列表、新建、编辑、删除、排序")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/admin/module")
|
|
|
+public class AdminModuleController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TrainModuleMapper trainModuleMapper;
|
|
|
+ @Resource
|
|
|
+ private TrainCourseMapper trainCourseMapper;
|
|
|
+
|
|
|
+ @Operation(summary = "模块列表(按课程,可按学习路径过滤)")
|
|
|
+ @PostMapping("/list")
|
|
|
+ public Result<List<TrainModule>> list(@RequestBody Map<String, Object> body) {
|
|
|
+ if (body == null || body.get("courseId") == null) {
|
|
|
+ return Result.error("缺少课程ID");
|
|
|
+ }
|
|
|
+ Long courseId = Long.valueOf(body.get("courseId").toString());
|
|
|
+ LambdaQueryWrapper<TrainModule> wrapper = new LambdaQueryWrapper<TrainModule>()
|
|
|
+ .eq(TrainModule::getCourseId, courseId);
|
|
|
+ if (body.get("track") != null && StringUtils.hasText(body.get("track").toString())) {
|
|
|
+ wrapper.eq(TrainModule::getTrack, body.get("track").toString());
|
|
|
+ }
|
|
|
+ wrapper.orderByAsc(TrainModule::getSort).orderByAsc(TrainModule::getId);
|
|
|
+ return Result.success(trainModuleMapper.selectList(wrapper));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "新建课程模块")
|
|
|
+ @PostMapping("/create")
|
|
|
+ public Result<TrainModule> create(@RequestBody TrainModule module) {
|
|
|
+ if (module.getCourseId() == null) {
|
|
|
+ return Result.error("缺少课程ID");
|
|
|
+ }
|
|
|
+ TrainCourse exist = trainCourseMapper.selectById(module.getCourseId());
|
|
|
+ if (exist == null) {
|
|
|
+ return Result.error("课程不存在");
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(module.getName())) {
|
|
|
+ return Result.error("模块名称不能为空");
|
|
|
+ }
|
|
|
+ module.setName(module.getName().trim());
|
|
|
+ if (module.getPrice() == null) {
|
|
|
+ module.setPrice(0);
|
|
|
+ }
|
|
|
+ if (module.getSort() == null) {
|
|
|
+ module.setSort(0);
|
|
|
+ }
|
|
|
+ if (module.getEnabled() == null) {
|
|
|
+ module.setEnabled(1);
|
|
|
+ }
|
|
|
+ trainModuleMapper.insert(module);
|
|
|
+ return Result.success(module);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "编辑课程模块(名称/说明/路径/价格/排序/启用)")
|
|
|
+ @PostMapping("/update")
|
|
|
+ public Result<Boolean> update(@RequestBody TrainModule module) {
|
|
|
+ if (module.getId() == null) {
|
|
|
+ return Result.error("缺少模块ID");
|
|
|
+ }
|
|
|
+ TrainModule exist = trainModuleMapper.selectById(module.getId());
|
|
|
+ if (exist == null) {
|
|
|
+ return Result.error("模块不存在");
|
|
|
+ }
|
|
|
+ // 仅更新允许编辑的字段,其余保持原值
|
|
|
+ if (StringUtils.hasText(module.getName())) {
|
|
|
+ exist.setName(module.getName().trim());
|
|
|
+ }
|
|
|
+ if (module.getDescription() != null) {
|
|
|
+ exist.setDescription(module.getDescription());
|
|
|
+ }
|
|
|
+ if (module.getTrack() != null) {
|
|
|
+ exist.setTrack(module.getTrack());
|
|
|
+ }
|
|
|
+ if (module.getPrice() != null) {
|
|
|
+ exist.setPrice(module.getPrice());
|
|
|
+ }
|
|
|
+ if (module.getSort() != null) {
|
|
|
+ exist.setSort(module.getSort());
|
|
|
+ }
|
|
|
+ if (module.getEnabled() != null) {
|
|
|
+ exist.setEnabled(module.getEnabled());
|
|
|
+ }
|
|
|
+ trainModuleMapper.updateById(exist);
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "删除课程模块")
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public Result<Boolean> delete(@RequestBody Map<String, Object> body) {
|
|
|
+ if (body == null || body.get("id") == null) {
|
|
|
+ return Result.error("缺少模块ID");
|
|
|
+ }
|
|
|
+ Long id = Long.valueOf(body.get("id").toString());
|
|
|
+ trainModuleMapper.deleteById(id);
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Operation(summary = "模块排序(items: [{id, sort}])")
|
|
|
+ @PostMapping("/sort")
|
|
|
+ public Result<Boolean> sort(@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;
|
|
|
+ }
|
|
|
+ TrainModule exist = trainModuleMapper.selectById(Long.valueOf(idObj.toString()));
|
|
|
+ if (exist != null) {
|
|
|
+ exist.setSort(Integer.valueOf(sortObj.toString()));
|
|
|
+ trainModuleMapper.updateById(exist);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+}
|