This commit is contained in:
wuchunlei
2024-03-27 17:04:29 +08:00
5 changed files with 49 additions and 3 deletions

View File

@@ -1,9 +1,10 @@
package com.peanut.modules.master.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.peanut.common.utils.R;
import com.peanut.modules.common.dao.CourseDao;
import com.peanut.modules.common.entity.CourseEntity;
import com.peanut.modules.common.entity.CourseSociologyEntity;
import com.peanut.modules.common.entity.CourseToSociologyEntity;
import com.peanut.modules.common.to.ParamTo;
import com.peanut.modules.master.service.CourseService;
import com.peanut.modules.master.service.CourseSociologyService;
@@ -12,7 +13,6 @@ import lombok.extern.slf4j.Slf4j;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@@ -57,4 +57,21 @@ public class CourseSociologyController {
return R.ok().put("courseList",courseListForSociology);
}
@RequestMapping("/getCourseListCanSociology")
public R getCourseListCanSociology(@RequestBody ParamTo param){
Page courseListCanSociology = courseService.getCourseListCanSociology(param);
return R.ok().put("page",courseListCanSociology);
}
@RequestMapping("/bindCourseAndSociology")
public R bindCourseAndSociology(@RequestBody CourseToSociologyEntity courseToSociologyEntity){
return courseToSociologyService.bindCourseAndSociology(courseToSociologyEntity);
}
@RequestMapping("/unbindCourseAndSociology")
public R unbindCourseAndSociology(@RequestBody CourseToSociologyEntity courseToSociologyEntity){
courseToSociologyService.removeById(courseToSociologyEntity.getId());
return R.ok();
}
}

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.CourseEntity;
import com.peanut.modules.common.to.ParamTo;
import java.util.List;
import java.util.Map;
@@ -15,4 +16,6 @@ public interface CourseService extends IService<CourseEntity> {
R delCourse(int id);
List<CourseEntity> getCourseListForSociology(int sociologyId);
Page getCourseListCanSociology(ParamTo param);
}

View File

@@ -1,7 +1,10 @@
package com.peanut.modules.master.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.CourseToSociologyEntity;
public interface CourseToSociologyService extends IService<CourseToSociologyEntity> {
R bindCourseAndSociology(CourseToSociologyEntity courseToSociologyEntity);
}

View File

@@ -1,6 +1,7 @@
package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
@@ -8,6 +9,7 @@ import com.peanut.common.utils.ObjectUtils;
import com.peanut.common.utils.R;
import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.to.ParamTo;
import com.peanut.modules.master.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -102,6 +104,16 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
return courseEntities;
}
@Override
public Page getCourseListCanSociology(ParamTo param) {
List<Integer> collect = courseToSociologyDao.selectList(new LambdaQueryWrapper<CourseToSociologyEntity>().eq(CourseToSociologyEntity::getSociologyId, param.getId())).stream().map(CourseToSociologyEntity::getCourseId).collect(Collectors.toList());
LambdaQueryWrapper<CourseEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.notIn(CourseEntity::getId,collect);
wrapper.like(StringUtils.isNotBlank(param.getKeywords()),CourseEntity::getTitle,param.getKeywords());
Page<CourseEntity> page = this.page(new Page<>(param.getPage(), param.getLimit()), wrapper);
return page;
}
private List<Integer> categoryIds(Integer id){
ArrayList<Integer> integers = new ArrayList<>();
CourseCategoryEntity courseCategoryEntity = courseCategoryDao.selectById(id);

View File

@@ -1,6 +1,8 @@
package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.common.utils.R;
import com.peanut.modules.common.dao.CourseToSociologyDao;
import com.peanut.modules.common.entity.CourseToSociologyEntity;
import com.peanut.modules.master.service.CourseToSociologyService;
@@ -12,5 +14,14 @@ import org.springframework.stereotype.Service;
public class CourseToSociologyServiceImpl extends ServiceImpl<CourseToSociologyDao, CourseToSociologyEntity> implements CourseToSociologyService {
@Override
public R bindCourseAndSociology(CourseToSociologyEntity courseToSociologyEntity) {
//去重
CourseToSociologyEntity one = this.getOne(new LambdaQueryWrapper<CourseToSociologyEntity>().eq(CourseToSociologyEntity::getCourseId, courseToSociologyEntity.getCourseId()).eq(CourseToSociologyEntity::getSociologyId, courseToSociologyEntity.getSociologyId()));
if(one != null){
return R.error(501,"绑定失败,绑定关系已将存在");
}
this.save(courseToSociologyEntity);
return R.ok();
}
}