package com.ruoyi.web.controller.api;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.common.basic.PageInfo;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.framework.web.service.TokenService;
|
import com.ruoyi.system.domain.*;
|
import com.ruoyi.system.service.*;
|
import com.ruoyi.system.query.CommentQuery;
|
import io.swagger.annotations.ApiOperation;
|
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 javax.naming.ldap.PagedResultsControl;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 课程评论 前端控制器
|
* </p>
|
*
|
* @author luodangjia
|
* @since 2024-09-19
|
*/
|
@RestController
|
@RequestMapping("/t-course-comment")
|
public class TCourseCommentController {
|
@Resource
|
private TCourseCommentService courseCommentService;
|
@Resource
|
private TokenService tokenService;
|
@Resource
|
private TTechnicalTitleService tTechnicalTitleService;
|
@Resource
|
private TCourseService courseService;
|
@Resource
|
private TTitleMajorService majorService;
|
@Resource
|
private TLevelService levelService;
|
|
//列表
|
@ApiOperation(value = "评价列表",tags = {"后台-评价管理","web教学视频查询"})
|
@PostMapping("/list")
|
public R<PageInfo<TCourseComment>> list(@RequestBody CommentQuery commentQuery){
|
PageInfo<TCourseComment> tCourseCommentPageInfo = courseCommentService.pageQuery(commentQuery);
|
List<TCourseComment> records = tCourseCommentPageInfo.getRecords();
|
|
List<Long> courseId = records.stream().map(TCourseComment::getCourseId).collect(Collectors.toList());
|
List<TCourse> courses = courseService.lambdaQuery().in(TCourse::getId, courseId).list();
|
|
List<Long> technicalId = courses.stream().map(TCourse::getTechnicalId).collect(Collectors.toList());
|
List<TTechnicalTitle> tTechnicalTitles = tTechnicalTitleService.lambdaQuery().in(TTechnicalTitle::getId, technicalId).list();
|
|
List<Long> majorId = courses.stream().map(TCourse::getMajorId).collect(Collectors.toList());
|
List<TTitleMajor> tTitleMajors = majorService.lambdaQuery().in(TTitleMajor::getId, majorId).list();
|
|
List<Integer> level = courses.stream().map(TCourse::getLevel).collect(Collectors.toList());
|
List<TLevel> levels = levelService.lambdaQuery().in(TLevel::getId, level).list();
|
for (TCourseComment record : records) {
|
TCourse tCourse = courses.stream().filter(e -> e.getId().equals(record.getCourseId())).findFirst().orElse(null);
|
TTechnicalTitle tTechnicalTitle = tTechnicalTitles.stream().filter(e -> e.getId().equals(tCourse.getTechnicalId())).findFirst().orElse(null);
|
TTitleMajor tTitleMajor = tTitleMajors.stream().filter(e -> e.getId().equals(tCourse.getMajorId())).findFirst().orElse(null);
|
TLevel tLevel = levels.stream().filter(e -> e.getId().equals(tCourse.getLevel())).findFirst().orElse(null);
|
record.setClassName(tTechnicalTitle.getTitileName()+"-"+tTitleMajor.getMajorName()+"-"+tLevel.getName());
|
record.setPrice(tCourse.getCoursePrice());
|
record.setCourseCover(tCourse.getCourseCover());
|
}
|
return R.ok(tCourseCommentPageInfo);
|
}
|
|
|
@ApiOperation(value = "更改是否显示",tags = "后台-评价管理")
|
@PostMapping("/change")
|
public R change(Long id, Integer isVision){
|
TCourseComment courseComment = courseCommentService.getById(id);
|
courseComment.setIsVision(isVision);
|
courseCommentService.updateById(courseComment);
|
return R.ok();
|
}
|
//删除
|
@ApiOperation(value = "删除",tags = "后台-评价管理")
|
@PostMapping("/deleteById")
|
public R deleteById(String ids){
|
courseCommentService.removeBatchByIds(Arrays.asList(ids.split(",")));
|
return R.ok();
|
}
|
|
@ApiOperation(value = "评论",tags = "web教学视频查询")
|
@PostMapping("/course")
|
public R comment(@RequestBody TCourseComment tCourseComment){
|
Long userId = tokenService.getLoginUser().getUserId();
|
tCourseComment.setUserId(userId);
|
tCourseComment.setIsVision(0);
|
courseCommentService.save(tCourseComment);
|
|
return R.ok();
|
}
|
|
}
|