mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-22 18:29:51 +08:00
课程管理
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package xyz.playedu.api.service;
|
||||
|
||||
import xyz.playedu.api.domain.CategoryCourse;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【category_course】的数据库操作Service
|
||||
* @createDate 2023-02-24 14:48:26
|
||||
*/
|
||||
public interface CategoryCourseService extends IService<CategoryCourse> {
|
||||
List<Integer> getCourseIdsByCategoryIds(Integer[] categoryIds);
|
||||
|
||||
List<Integer> getDepIdsByCourseId(Integer id);
|
||||
|
||||
void removeByCourseId(Integer courseId);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package xyz.playedu.api.service;
|
||||
|
||||
import xyz.playedu.api.domain.CourseDepartment;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【course_department】的数据库操作Service
|
||||
* @createDate 2023-02-24 14:53:52
|
||||
*/
|
||||
public interface CourseDepartmentService extends IService<CourseDepartment> {
|
||||
|
||||
List<Integer> getCourseIdsByDepIds(Integer[] depIds);
|
||||
|
||||
List<Integer> getDepIdsByCourseId(Integer courseId);
|
||||
|
||||
void removeByCourseId(Integer courseId);
|
||||
}
|
||||
17
src/main/java/xyz/playedu/api/service/CourseService.java
Normal file
17
src/main/java/xyz/playedu/api/service/CourseService.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package xyz.playedu.api.service;
|
||||
|
||||
import xyz.playedu.api.domain.Course;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【courses】的数据库操作Service
|
||||
* @createDate 2023-02-24 14:14:01
|
||||
*/
|
||||
public interface CourseService extends IService<Course> {
|
||||
|
||||
PaginationResult<Course> paginate(int page, int size, CoursePaginateFiler filter);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import xyz.playedu.api.domain.CategoryCourse;
|
||||
import xyz.playedu.api.service.CategoryCourseService;
|
||||
import xyz.playedu.api.mapper.CategoryCourseMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【category_course】的数据库操作Service实现
|
||||
* @createDate 2023-02-24 14:48:26
|
||||
*/
|
||||
@Service
|
||||
public class CategoryCourseServiceImpl extends ServiceImpl<CategoryCourseMapper, CategoryCourse>
|
||||
implements CategoryCourseService {
|
||||
@Override
|
||||
public List<Integer> getCourseIdsByCategoryIds(Integer[] categoryIds) {
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
List<CategoryCourse> categoryCourses = list(query().getWrapper().in("category_id", categoryIds));
|
||||
if (categoryCourses.size() == 0) {
|
||||
return ids;
|
||||
}
|
||||
for (CategoryCourse categoryCourse : categoryCourses) {
|
||||
ids.add(categoryCourse.getCourseId());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getDepIdsByCourseId(Integer id) {
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
List<CategoryCourse> categoryCourses = list(query().getWrapper().eq("course_id", id));
|
||||
if (categoryCourses.size() == 0) {
|
||||
return ids;
|
||||
}
|
||||
for (CategoryCourse categoryCourse : categoryCourses) {
|
||||
ids.add(categoryCourse.getCategoryId());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByCourseId(Integer courseId) {
|
||||
remove(query().getWrapper().eq("course_id", courseId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import xyz.playedu.api.domain.CourseDepartment;
|
||||
import xyz.playedu.api.service.CourseDepartmentService;
|
||||
import xyz.playedu.api.mapper.CourseDepartmentMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【course_department】的数据库操作Service实现
|
||||
* @createDate 2023-02-24 14:53:52
|
||||
*/
|
||||
@Service
|
||||
public class CourseDepartmentServiceImpl extends ServiceImpl<CourseDepartmentMapper, CourseDepartment>
|
||||
implements CourseDepartmentService {
|
||||
@Override
|
||||
public List<Integer> getCourseIdsByDepIds(Integer[] depIds) {
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
List<CourseDepartment> courseDepartments = list(query().getWrapper().in("dep_id", depIds));
|
||||
if (courseDepartments.size() == 0) {
|
||||
return ids;
|
||||
}
|
||||
for (CourseDepartment courseDepartment : courseDepartments) {
|
||||
ids.add(courseDepartment.getCourseId());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getDepIdsByCourseId(Integer courseId) {
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
List<CourseDepartment> courseDepartments = list(query().getWrapper().eq("course_id", courseId));
|
||||
if (courseDepartments.size() == 0) {
|
||||
return ids;
|
||||
}
|
||||
for (CourseDepartment courseDepartment : courseDepartments) {
|
||||
ids.add(courseDepartment.getDepId());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByCourseId(Integer courseId) {
|
||||
remove(query().getWrapper().eq("course_id", courseId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import xyz.playedu.api.domain.Course;
|
||||
import xyz.playedu.api.service.CategoryCourseService;
|
||||
import xyz.playedu.api.service.CourseDepartmentService;
|
||||
import xyz.playedu.api.service.CourseService;
|
||||
import xyz.playedu.api.mapper.CourseMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.util.HelperUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【courses】的数据库操作Service实现
|
||||
* @createDate 2023-02-24 14:14:01
|
||||
*/
|
||||
@Service
|
||||
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {
|
||||
|
||||
@Autowired
|
||||
private CourseDepartmentService courseDepartmentService;
|
||||
|
||||
@Autowired
|
||||
private CategoryCourseService categoryCourseService;
|
||||
|
||||
@Override
|
||||
public PaginationResult<Course> paginate(int page, int size, CoursePaginateFiler filter) {
|
||||
QueryWrapper<Course> wrapper = query().getWrapper().eq("1", "1");
|
||||
|
||||
if (filter.getTitle() != null && filter.getTitle().length() > 0) {
|
||||
wrapper.like("title", "%" + filter.getTitle() + "%");
|
||||
}
|
||||
if (filter.getDepIds() != null && filter.getDepIds().length > 0) {
|
||||
List<Integer> courseIds = courseDepartmentService.getCourseIdsByDepIds(filter.getDepIds());
|
||||
if (courseIds.size() == 0) {
|
||||
wrapper.in("id", HelperUtil.zeroIntegerList());
|
||||
} else {
|
||||
wrapper.in("id", courseIds);
|
||||
}
|
||||
}
|
||||
if (filter.getCategoryIds() != null && filter.getCategoryIds().length > 0) {
|
||||
List<Integer> courseIds = categoryCourseService.getCourseIdsByCategoryIds(filter.getCategoryIds());
|
||||
if (courseIds.size() == 0) {
|
||||
wrapper.in("id", HelperUtil.zeroIntegerList());
|
||||
} else {
|
||||
wrapper.in("id", courseIds);
|
||||
}
|
||||
}
|
||||
|
||||
if (filter.getSortAlgo().equals("desc")) {
|
||||
wrapper.orderByDesc(filter.getSortField());
|
||||
} else {
|
||||
wrapper.orderByAsc(filter.getSortField());
|
||||
}
|
||||
|
||||
IPage<Course> pageObj = new Page<>(page, size);
|
||||
pageObj = page(pageObj, wrapper);
|
||||
|
||||
PaginationResult<Course> pageResult = new PaginationResult<>();
|
||||
pageResult.setData(pageObj.getRecords());
|
||||
pageResult.setTotal(pageObj.getTotal());
|
||||
|
||||
return pageResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user