package com.xinquan.course.controller.client;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.xinquan.common.core.domain.R;
|
import com.xinquan.common.core.utils.page.CollUtils;
|
import com.xinquan.common.core.utils.page.PageDTO;
|
import com.xinquan.common.security.utils.SecurityUtils;
|
import com.xinquan.course.api.domain.CourseChapter;
|
import com.xinquan.course.domain.CourseLearningRecord;
|
import com.xinquan.course.service.CourseChapterService;
|
import com.xinquan.course.service.CourseLearningRecordService;
|
import com.xinquan.user.api.feign.RemoteAppUserService;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.time.LocalDateTime;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 在线章节章节表 前端控制器
|
* </p>
|
*
|
* @author mitao
|
* @since 2024-08-21
|
*/
|
@RestController
|
@RequestMapping("/client/course/course-chapter")
|
public class ClientCourseChapterController {
|
@Autowired
|
private CourseChapterService courseChapterService;
|
@Autowired
|
private CourseLearningRecordService courseLearningRecordService;
|
@PostMapping("/courseChapterManagementList")
|
@ApiOperation(value = "章节列表-分页", tags = {"管理后台-章节管理"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true),
|
@ApiImplicitParam(name = "courseId", value = "课程id", dataType = "String", required = true),
|
@ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true)
|
})
|
public R<PageDTO<CourseChapter>> courseChapterManagementList(@RequestParam(value = "pageCurr")Integer pageCurr,
|
@RequestParam(value = "courseId")String courseId,
|
@RequestParam(value = "pageSize")Integer pageSize) {
|
LambdaQueryWrapper<CourseChapter> courseLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
courseLambdaQueryWrapper.orderByDesc(CourseChapter::getSortNum);
|
courseLambdaQueryWrapper.eq(CourseChapter::getCourseId,courseId);
|
Page<CourseChapter> page = courseChapterService.page(new Page<>(pageCurr, pageSize), courseLambdaQueryWrapper);
|
if (CollUtils.isEmpty(page.getRecords())) {
|
return R.ok(PageDTO.empty(page));
|
}
|
for (CourseChapter record : page.getRecords()) {
|
record.setUid(record.getId()+"");
|
int a = 0;
|
int b = 0;
|
a+= record.getVirtualLearnedNum();
|
Long data1 = remoteAppUserService.getCourseChapterHistoryCount(record.getId()).getData();
|
b+=data1;
|
record.setRealLearnedNum(a+b);
|
}
|
|
return R.ok(PageDTO.of(page, CourseChapter.class));
|
}
|
@PostMapping("/addChapter")
|
@ApiOperation(value = "新增章节管理", tags = "管理后台-章节管理")
|
public R addCourseChapter(@RequestBody CourseChapter homeBackgroundMusic) {
|
homeBackgroundMusic.setCreateBy(SecurityUtils.getUsername());
|
homeBackgroundMusic.setCreateTime(LocalDateTime.now());
|
return R.ok(courseChapterService.save(homeBackgroundMusic));
|
}
|
@Resource
|
private RemoteAppUserService remoteAppUserService;
|
@GetMapping("/detailCourseChapter")
|
@ApiOperation(value = "查看详情章节管理", tags = "管理后台-章节管理")
|
public R<CourseChapter> detailCourseChapter(String uid) {
|
CourseChapter byId = courseChapterService.getById(uid);
|
int a = 0;
|
int b = 0;
|
a+= byId.getVirtualLearnedNum();
|
Long data1 = remoteAppUserService.getCourseChapterHistoryCount(byId.getId()).getData();
|
b+=data1;
|
byId.setRealLearnedNum(a+b);
|
return R.ok(byId);
|
}
|
@PostMapping("/updateCourseChapter")
|
@ApiOperation(value = "修改章节管理", tags = "管理后台-章节管理")
|
public R updateCourseChapter(@RequestBody CourseChapter homeBackgroundMusic) {
|
homeBackgroundMusic.setUpdateBy(SecurityUtils.getUsername());
|
homeBackgroundMusic.setUpdateTime(LocalDateTime.now());
|
return R.ok(courseChapterService.updateById(homeBackgroundMusic));
|
}
|
@PostMapping("/deleteCourseChapter")
|
@ApiOperation(value = "批量删除", tags = "管理后台-章节管理")
|
public R deleteCourseChapter(String ids) {
|
return R.ok(courseChapterService.removeBatchByIds(Arrays.asList(ids.split(",")).stream().map(Long::valueOf).collect(Collectors.toList())));
|
}
|
}
|