|
@@ -0,0 +1,123 @@
|
|
|
+package com.ynfy.app.api.v1.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.ynfy.app.api.v1.entity.dto.CourseDTO;
|
|
|
+import com.ynfy.app.api.v1.util.TokenUtil;
|
|
|
+import com.ynfy.buss.course.course.entity.Course;
|
|
|
+import com.ynfy.buss.course.course.service.ICourseService;
|
|
|
+import com.ynfy.buss.course.coursecatalog.service.ICourseCatalogService;
|
|
|
+import com.ynfy.buss.course.usercoursecatalog.entity.vo.UserCourseStudyVO;
|
|
|
+import com.ynfy.buss.course.usercoursecatalog.service.IUserCourseCatalogService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.jeecg.modules.system.service.ISysPositionService;
|
|
|
+import org.jeecg.modules.system.service.ISysUserService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+@Api(tags = "course")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/v1/course")
|
|
|
+@Slf4j
|
|
|
+public class ApiCourseController extends ApiBaseController {
|
|
|
+ @Autowired
|
|
|
+ private ICourseService courseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICourseCatalogService courseCatalogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysPositionService sysPositionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserCourseCatalogService userCourseCatalogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页列表查询
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "course-分页列表查询", notes = "course-分页列表查询")
|
|
|
+ @PostMapping(value = "/list")
|
|
|
+ public Result<IPage<Course>> queryPageList(@RequestBody CourseDTO dto) {
|
|
|
+ Page<Course> page = new Page<>(dto.getPageNo(), dto.getPageSize());
|
|
|
+ Course course = new Course();
|
|
|
+ course.setName(dto.getName());
|
|
|
+ LoginUser user = sysUserService.getLoginUser(TokenUtil.getToken(request));
|
|
|
+ IPage<Course> pageList = courseService.selectCourseList(page, course, user);
|
|
|
+
|
|
|
+ //设置课程分类
|
|
|
+ courseService.setCategory(pageList);
|
|
|
+ if (!CollectionUtils.isEmpty(pageList.getRecords())) {
|
|
|
+ List<String> courseIdList = pageList.getRecords().stream().map(Course::getId).collect(Collectors.toList());
|
|
|
+ List<UserCourseStudyVO> studyList = userCourseCatalogService.getUserCourseStudy(courseIdList,
|
|
|
+ TokenUtil.getUserId(TokenUtil.getToken(request)));
|
|
|
+ if (!CollectionUtils.isEmpty(studyList)) {
|
|
|
+ pageList.getRecords().forEach((o) -> courseService.setCourseStudyProcess(studyList, o));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.OK(pageList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ //@AutoLog(value = "course-通过id查询")
|
|
|
+ @ApiOperation(value = "course-通过id查询", notes = "course-通过id查询")
|
|
|
+ @GetMapping(value = "/queryById")
|
|
|
+ public Result<Course> queryById(@RequestParam(name = "id", required = true) String id) {
|
|
|
+ Course course = courseService.queryById(id);
|
|
|
+ if (course == null) {
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+ course.setCatalogList(courseCatalogService.listByCourseId(course.getId()));
|
|
|
+ return Result.OK(course);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取课程学习明细
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "获取课程学习明细", notes = "获取课程学习明细")
|
|
|
+ @GetMapping(value = "/getCourseStudyDetail")
|
|
|
+ public Result<Course> getCourseStudyDetail(@RequestParam String id) {
|
|
|
+ Course course = courseService.queryById(id);
|
|
|
+ if (course == null) {
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+ course.setCatalogList(courseCatalogService.listByCourseId(course.getId()));
|
|
|
+ if (StringUtils.isNotBlank(course.getTeacherPost())) {
|
|
|
+ course.setTeacherPost(sysPositionService.listByCodes(Arrays.asList(course.getTeacherPost().split(","))));
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取课程学习进度
|
|
|
+ List<String> courseIdList = new ArrayList<>();
|
|
|
+ courseIdList.add(course.getId());
|
|
|
+ courseService.setCourseStudyProcess(userCourseCatalogService.getUserCourseStudy(courseIdList,
|
|
|
+ TokenUtil.getUserId(TokenUtil.getToken(request))), course);
|
|
|
+
|
|
|
+ return Result.OK(course);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|