212 lines
10 KiB
Java
212 lines
10 KiB
Java
package com.peanut.modules.taihumed.controller;
|
||
|
||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||
import com.peanut.common.utils.R;
|
||
import com.peanut.common.utils.ShiroUtils;
|
||
import com.peanut.modules.common.entity.*;
|
||
import com.peanut.modules.common.service.*;
|
||
import com.peanut.modules.master.service.CourseService;
|
||
import com.peanut.modules.master.service.UserCourseBuyService;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.lang.StringUtils;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.RequestBody;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.stream.Collectors;
|
||
|
||
@Slf4j
|
||
@RestController("taihumedCourse")
|
||
@RequestMapping("taihumed/course")
|
||
public class CourseController {
|
||
|
||
@Autowired
|
||
private CourseTaihumedService courseTaihumedService;
|
||
@Autowired
|
||
private CourseToTaihumedService courseToTaihumedService;
|
||
@Autowired
|
||
private CourseToTalentService courseToTalentService;
|
||
@Autowired
|
||
private TaihuTalentService taihuTalentService;
|
||
@Autowired
|
||
private CourseService courseService;
|
||
@Autowired
|
||
private UserVipService userVipService;
|
||
@Autowired
|
||
private UserCourseBuyService userCourseBuyService;
|
||
|
||
|
||
//课程标签列表
|
||
@RequestMapping("/getCourseTaihumedList")
|
||
public R getCourseTaihumedList(){
|
||
List<CourseTaihumed> list = courseTaihumedService.list(new LambdaQueryWrapper<CourseTaihumed>()
|
||
.eq(CourseTaihumed::getPid,0)
|
||
.orderByAsc(CourseTaihumed::getSort));
|
||
return R.ok().put("list",list);
|
||
}
|
||
|
||
//标签下课程列表
|
||
@RequestMapping("/getCourseToTaihumedList")
|
||
public R getCourseToTaihumedList(@RequestBody Map<String,Object> params){
|
||
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper();
|
||
wrapper.rightJoin(CourseToTaihumed.class,CourseToTaihumed::getCourseId,CourseEntity::getId);
|
||
wrapper.orderByAsc(CourseToTaihumed::getSort);
|
||
wrapper.selectAll(CourseEntity.class);
|
||
wrapper.eq(CourseToTaihumed::getTaihumedId,params.get("taihumedId"));
|
||
if (StringUtils.isNotEmpty(params.get("userName").toString())){
|
||
wrapper.leftJoin(CourseToTalent.class,CourseToTalent::getCourseId,CourseEntity::getId);
|
||
wrapper.leftJoin(TaihuTalent.class,TaihuTalent::getId,CourseToTalent::getTalentId);
|
||
wrapper.selectAs(TaihuTalent::getId,"taihuTalentId");
|
||
wrapper.like(StringUtils.isNotEmpty(params.get("userName").toString()),TaihuTalent::getName,params.get("userName"));
|
||
}
|
||
wrapper.like(StringUtils.isNotEmpty(params.get("courseName").toString()),CourseEntity::getTitle,params.get("courseName"));
|
||
Page<CourseEntity> pageRes = courseService.page(new Page<>(Long.parseLong(params.get("current").toString())
|
||
, Long.parseLong(params.get("limit").toString())),wrapper);
|
||
for (CourseEntity course:pageRes.getRecords()){
|
||
if (course.getTaihuTalentId()!=null){
|
||
course.setTaihuTalent(taihuTalentService.getById(course.getTaihuTalentId()));
|
||
}else {
|
||
CourseToTalent courseToTalent = courseToTalentService.getOne(new LambdaQueryWrapper<CourseToTalent>()
|
||
.eq(CourseToTalent::getCourseId,course.getId()));
|
||
if (courseToTalent!=null){
|
||
TaihuTalent taihuTalent = taihuTalentService.getById(courseToTalent.getTalentId());
|
||
course.setTaihuTalent(taihuTalent);
|
||
}
|
||
}
|
||
}
|
||
return R.ok().put("pageRes",pageRes);
|
||
}
|
||
|
||
//当前课程是否可看
|
||
@RequestMapping("/checkPermission")
|
||
public R checkPermission(@RequestBody Map<String,Object> params){
|
||
boolean flag = false;
|
||
String endTime = "";
|
||
//查询当前课程绑定的标签
|
||
List<CourseToTaihumed> courseToTaihumeds = courseToTaihumedService.list(new LambdaQueryWrapper<CourseToTaihumed>()
|
||
.eq(CourseToTaihumed::getCourseId,params.get("courseId")));
|
||
List<Integer> taihumedLabelIds = new ArrayList<>();
|
||
//当前课程的顶级标签
|
||
for (CourseToTaihumed ctt:courseToTaihumeds){
|
||
topLael(taihumedLabelIds,ctt.getTaihumedId());
|
||
}
|
||
//超级vip可看当前板块所有课程
|
||
for (int i:taihumedLabelIds){
|
||
if (i==99&&userVipService.is4569SVip(ShiroUtils.getUId())){
|
||
flag = true;
|
||
}
|
||
if (i==100&&userVipService.is78SVip(ShiroUtils.getUId())){
|
||
flag = true;
|
||
}
|
||
}
|
||
if (!flag){
|
||
//太湖英才可看自己和当前板块的所有课程
|
||
TaihuTalent taihuTalent = taihuTalentService.getOne(new LambdaQueryWrapper<TaihuTalent>()
|
||
.eq(TaihuTalent::getUserId,ShiroUtils.getUId()));
|
||
if (taihuTalent != null){
|
||
List<CourseToTalent> courseToTalents = courseToTalentService.list(new LambdaQueryWrapper<CourseToTalent>()
|
||
.eq(CourseToTalent::getTalentId,taihuTalent.getId()));
|
||
List<Integer> collect = courseToTalents.stream().map(CourseToTalent::getCourseId).collect(Collectors.toList());
|
||
List<CourseToTaihumed> cTTs = courseToTaihumedService.list(new LambdaQueryWrapper<CourseToTaihumed>()
|
||
.in(CourseToTaihumed::getCourseId,collect)
|
||
.ne(CourseToTaihumed::getTaihumedId,101));
|
||
List<Integer> tls = new ArrayList<>();
|
||
for (CourseToTaihumed ctt:cTTs){
|
||
topLael(tls,ctt.getTaihumedId());
|
||
}
|
||
for (int i:tls){
|
||
for (int j:taihumedLabelIds){
|
||
if (i==j){
|
||
flag = true;
|
||
}
|
||
}
|
||
}
|
||
if (!flag){
|
||
//会议论坛
|
||
if (collect.contains(params.get("courseId"))){
|
||
flag = true;
|
||
}
|
||
}
|
||
}
|
||
if (!flag){
|
||
//不是太湖英才,不是vip,查询买课
|
||
List<UserCourseBuyEntity> ucbs = userCourseBuyService.list(new LambdaQueryWrapper<UserCourseBuyEntity>()
|
||
.eq(UserCourseBuyEntity::getUserId,ShiroUtils.getUId())
|
||
.eq(UserCourseBuyEntity::getCatalogueId,params.get("catalogueId"))
|
||
.orderByDesc(UserCourseBuyEntity::getEndTime));
|
||
if (ucbs.size() > 0){
|
||
flag = true;
|
||
endTime = ucbs.get(0).getEndTime()==null?"":ucbs.get(0).getEndTime().toString();
|
||
}
|
||
}
|
||
}
|
||
return R.ok().put("flag",flag).put("endTime",endTime);
|
||
}
|
||
|
||
//我的课程
|
||
@RequestMapping("/getMyCourseList")
|
||
public R getMyCourseList(@RequestBody Map<String,Object> params){
|
||
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
|
||
wrapper.distinct();
|
||
wrapper.rightJoin(CourseToTaihumed.class,CourseToTaihumed::getCourseId,CourseEntity::getId);
|
||
wrapper.leftJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCourseId,CourseEntity::getId);
|
||
wrapper.eq(UserCourseBuyEntity::getUserId,ShiroUtils.getUId());
|
||
wrapper.selectAll(CourseEntity.class);
|
||
wrapper.orderByAsc(CourseEntity::getSort);
|
||
Page<CourseEntity> pageRes = courseService.page(new Page<>(Long.parseLong(params.get("current").toString())
|
||
, Long.parseLong(params.get("limit").toString())),wrapper);
|
||
return R.ok().put("pageRes",pageRes);
|
||
}
|
||
|
||
//我的课程-过期课程
|
||
@RequestMapping("/getCourseExpire")
|
||
public R getCourseExpire(){
|
||
List courseEntities = new ArrayList();
|
||
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
|
||
wrapper.distinct();
|
||
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId);
|
||
//关掉本次查询del_flg = 0的条件,查询过期课程
|
||
wrapper.disableSubLogicDel().rightJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCatalogueId,CourseCatalogueEntity::getId);
|
||
wrapper.rightJoin(CourseToTaihumed.class,CourseToTaihumed::getCourseId,CourseEntity::getId);
|
||
wrapper.eq(UserCourseBuyEntity::getUserId,ShiroUtils.getUId());
|
||
wrapper.eq(UserCourseBuyEntity::getDelFlag,-1);
|
||
wrapper.selectAll(CourseEntity.class);
|
||
wrapper.selectAs(CourseCatalogueEntity::getId,"catalogueId");
|
||
wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueTitle");
|
||
wrapper.orderByAsc(CourseEntity::getSort);
|
||
wrapper.orderByAsc(CourseCatalogueEntity::getSort);
|
||
List<Map<String,Object>> list = courseService.listMaps(wrapper);
|
||
for (Map<String,Object> courseEntity : list) {
|
||
int ucb = userCourseBuyService.count(new LambdaQueryWrapper<UserCourseBuyEntity>()
|
||
.eq(UserCourseBuyEntity::getUserId,ShiroUtils.getUId())
|
||
.eq(UserCourseBuyEntity::getCatalogueId,courseEntity.get("catalogueId")));
|
||
if (ucb == 0) {
|
||
courseEntities.add(courseEntity);
|
||
}
|
||
}
|
||
return R.ok().put("courseList",courseEntities);
|
||
}
|
||
|
||
|
||
|
||
public void topLael(List<Integer> list, int courseTaihumedId){
|
||
CourseTaihumed courseTaihumed = courseTaihumedService.getById(courseTaihumedId);
|
||
if (courseTaihumed.getPid()==0){
|
||
list.add(courseTaihumed.getId());
|
||
}else {
|
||
CourseTaihumed pCourseTaihumed = courseTaihumedService.getOne(new LambdaQueryWrapper<CourseTaihumed>()
|
||
.eq(CourseTaihumed::getId,courseTaihumed.getPid()));
|
||
topLael(list,pCourseTaihumed.getId());
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}
|