修复课时批量添加

This commit is contained in:
none 2023-03-21 17:07:03 +08:00
parent 4f268732be
commit 1cf7bc13a3
4 changed files with 14 additions and 5 deletions

View File

@ -1,5 +1,6 @@
package xyz.playedu.api.controller.backend; package xyz.playedu.api.controller.backend;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -29,6 +30,7 @@ import java.util.*;
* @create 2023/2/26 17:50 * @create 2023/2/26 17:50
*/ */
@RestController @RestController
@Slf4j
@RequestMapping("/backend/v1/course/{courseId}/hour") @RequestMapping("/backend/v1/course/{courseId}/hour")
public class CourseHourController { public class CourseHourController {
@ -92,7 +94,8 @@ public class CourseHourController {
List<CourseHour> hours = new ArrayList<>(); List<CourseHour> hours = new ArrayList<>();
Date now = new Date(); Date now = new Date();
for (CourseHourMultiRequest.CourseHourItem item : req.getHours()) { for (CourseHourMultiRequest.HourItem item : req.getHours()) {
log.info("hourItem {}", item);
hours.add(new CourseHour() {{ hours.add(new CourseHour() {{
setCourseId(courseId); setCourseId(courseId);
setChapterId(item.getChapterId()); setChapterId(item.getChapterId());

View File

@ -6,6 +6,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
/** /**
@ -24,11 +27,13 @@ public class CourseHour implements Serializable {
/** /**
* 课程ID * 课程ID
*/ */
@JsonProperty("course_id")
private Integer courseId; private Integer courseId;
/** /**
* 章节ID * 章节ID
*/ */
@JsonProperty("chapter_id")
private Integer chapterId; private Integer chapterId;
/** /**
@ -59,6 +64,7 @@ public class CourseHour implements Serializable {
/** /**
* *
*/ */
@JsonIgnore
private Date createdAt; private Date createdAt;
@TableField(exist = false) @TableField(exist = false)

View File

@ -1,5 +1,6 @@
package xyz.playedu.api.request.backend; package xyz.playedu.api.request.backend;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
@ -12,7 +13,8 @@ import java.util.List;
@Data @Data
public class CourseHourMultiRequest { public class CourseHourMultiRequest {
@Data @Data
public class CourseHourItem { public static class HourItem {
@JsonProperty("chapter_id")
private Integer chapterId; private Integer chapterId;
private String title; private String title;
private Integer duration; private Integer duration;
@ -22,5 +24,5 @@ public class CourseHourMultiRequest {
} }
@NotNull(message = "hours参数不存在") @NotNull(message = "hours参数不存在")
private List<CourseHourItem> hours; private List<HourItem> hours;
} }

View File

@ -25,7 +25,6 @@ import java.util.stream.Collectors;
* @createDate 2023-02-24 14:14:01 * @createDate 2023-02-24 14:14:01
*/ */
@Service @Service
@Slf4j
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService { public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {
@Autowired @Autowired
@ -199,7 +198,6 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
.list(courseDepartmentService.query().getWrapper().in("course_id", courseIds)) .list(courseDepartmentService.query().getWrapper().in("course_id", courseIds))
.stream() .stream()
.collect(Collectors.groupingBy(CourseDepartment::getCourseId)); .collect(Collectors.groupingBy(CourseDepartment::getCourseId));
log.info("data {}", data);
Map<Integer, List<Integer>> result = new HashMap<>(); Map<Integer, List<Integer>> result = new HashMap<>();
data.forEach((courseId, records) -> { data.forEach((courseId, records) -> {
result.put(courseId, records.stream().map(CourseDepartment::getDepId).toList()); result.put(courseId, records.stream().map(CourseDepartment::getDepId).toList());