mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-25 05:42:42 +08:00
优化线上课列表
This commit is contained in:
parent
0689c0d428
commit
17d18da19b
@ -95,7 +95,7 @@ public class CourseController {
|
|||||||
|
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
|
|
||||||
if (req.getHours() != null) {//无章节课时配置
|
if (req.getHours().size() > 0) {//无章节课时配置
|
||||||
List<CourseHour> insertHours = new ArrayList<>();
|
List<CourseHour> insertHours = new ArrayList<>();
|
||||||
final Integer[] chapterSort = {0};
|
final Integer[] chapterSort = {0};
|
||||||
for (CourseRequest.HourItem hourItem : req.getHours()) {
|
for (CourseRequest.HourItem hourItem : req.getHours()) {
|
||||||
@ -117,6 +117,7 @@ public class CourseController {
|
|||||||
if (req.getChapters() == null || req.getChapters().size() == 0) {
|
if (req.getChapters() == null || req.getChapters().size() == 0) {
|
||||||
return JsonResponse.error("请配置课时");
|
return JsonResponse.error("请配置课时");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CourseHour> insertHours = new ArrayList<>();
|
List<CourseHour> insertHours = new ArrayList<>();
|
||||||
final Integer[] chapterSort = {0};
|
final Integer[] chapterSort = {0};
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@ -53,12 +54,10 @@ public class Course implements Serializable {
|
|||||||
@JsonProperty("created_at")
|
@JsonProperty("created_at")
|
||||||
private Date createdAt;
|
private Date createdAt;
|
||||||
|
|
||||||
@JsonProperty("updated_at")
|
@JsonIgnore
|
||||||
private Date updatedAt;
|
private Date updatedAt;
|
||||||
|
|
||||||
/**
|
@JsonIgnore
|
||||||
* 删除时间
|
|
||||||
*/
|
|
||||||
private Date deletedAt;
|
private Date deletedAt;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
|
@ -4,6 +4,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
import xyz.playedu.api.domain.Course;
|
import xyz.playedu.api.domain.Course;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import xyz.playedu.api.types.mapper.CourseCategoryCountMapper;
|
import xyz.playedu.api.types.mapper.CourseCategoryCountMapper;
|
||||||
|
import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -18,6 +19,10 @@ public interface CourseMapper extends BaseMapper<Course> {
|
|||||||
|
|
||||||
List<CourseCategoryCountMapper> getCategoryCount();
|
List<CourseCategoryCountMapper> getCategoryCount();
|
||||||
|
|
||||||
|
List<Course> paginate(CoursePaginateFiler filer);
|
||||||
|
|
||||||
|
Long paginateCount(CoursePaginateFiler filer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package xyz.playedu.api.service.impl;
|
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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -18,7 +15,6 @@ import xyz.playedu.api.service.internal.ResourceCourseCategoryService;
|
|||||||
import xyz.playedu.api.types.mapper.CourseCategoryCountMapper;
|
import xyz.playedu.api.types.mapper.CourseCategoryCountMapper;
|
||||||
import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
||||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||||
import xyz.playedu.api.util.HelperUtil;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -39,51 +35,12 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult<Course> paginate(int page, int size, CoursePaginateFiler filter) {
|
public PaginationResult<Course> paginate(int page, int size, CoursePaginateFiler filter) {
|
||||||
QueryWrapper<Course> wrapper = query().getWrapper().eq("1", "1");
|
filter.setPageStart((page - 1) * size);
|
||||||
|
filter.setPageSize(size);
|
||||||
if (filter.getTitle() != null && filter.getTitle().length() > 0) {
|
|
||||||
wrapper.like("title", "%" + filter.getTitle() + "%");
|
|
||||||
}
|
|
||||||
if (filter.getDepIds() != null && filter.getDepIds().trim().length() > 0) {
|
|
||||||
List<Integer> depIds = Arrays.stream(filter.getDepIds().split(",")).map(Integer::valueOf).toList();
|
|
||||||
List<Integer> courseIds = courseDepartmentService.getCourseIdsByDepIds(depIds);
|
|
||||||
if (courseIds == null || courseIds.size() == 0) {
|
|
||||||
courseIds = HelperUtil.zeroIntegerList();
|
|
||||||
}
|
|
||||||
wrapper.in("id", courseIds);
|
|
||||||
}
|
|
||||||
if (filter.getCategoryIds() != null && filter.getCategoryIds().trim().length() > 0) {
|
|
||||||
List<Integer> categoryIds = Arrays.stream(filter.getCategoryIds().split(",")).map(Integer::valueOf).toList();
|
|
||||||
List<Integer> courseIds = courseCategoryService.getCourseIdsByCategoryIds(categoryIds);
|
|
||||||
if (courseIds == null || courseIds.size() == 0) {
|
|
||||||
courseIds = HelperUtil.zeroIntegerList();
|
|
||||||
}
|
|
||||||
wrapper.in("id", courseIds);
|
|
||||||
}
|
|
||||||
if (filter.getIsShow() != null) {
|
|
||||||
wrapper.eq("is_show", filter.getIsShow());
|
|
||||||
}
|
|
||||||
|
|
||||||
String sortFiled = filter.getSortField();
|
|
||||||
if (sortFiled == null || sortFiled.trim().length() == 0) {
|
|
||||||
sortFiled = "id";
|
|
||||||
}
|
|
||||||
String sortAlgo = filter.getSortAlgo();
|
|
||||||
if (sortAlgo == null || sortAlgo.trim().length() == 0) {
|
|
||||||
sortAlgo = "desc";
|
|
||||||
}
|
|
||||||
if ("desc".equals(sortAlgo)) {
|
|
||||||
wrapper.orderByDesc(sortFiled);
|
|
||||||
} else {
|
|
||||||
wrapper.orderByAsc(sortFiled);
|
|
||||||
}
|
|
||||||
|
|
||||||
IPage<Course> pageObj = new Page<>(page, size);
|
|
||||||
pageObj = page(pageObj, wrapper);
|
|
||||||
|
|
||||||
PaginationResult<Course> pageResult = new PaginationResult<>();
|
PaginationResult<Course> pageResult = new PaginationResult<>();
|
||||||
pageResult.setData(pageObj.getRecords());
|
pageResult.setData(getBaseMapper().paginate(filter));
|
||||||
pageResult.setTotal(pageObj.getTotal());
|
pageResult.setTotal(getBaseMapper().paginateCount(filter));
|
||||||
|
|
||||||
return pageResult;
|
return pageResult;
|
||||||
}
|
}
|
||||||
|
@ -21,4 +21,8 @@ public class CoursePaginateFiler {
|
|||||||
|
|
||||||
private Integer isShow;
|
private Integer isShow;
|
||||||
|
|
||||||
|
private Integer pageStart;
|
||||||
|
|
||||||
|
private Integer pageSize;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,20 @@
|
|||||||
<mapper namespace="xyz.playedu.api.mapper.CourseMapper">
|
<mapper namespace="xyz.playedu.api.mapper.CourseMapper">
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.Course">
|
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.Course">
|
||||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||||
<result property="title" column="title" jdbcType="VARCHAR"/>
|
<result property="title" column="title" jdbcType="VARCHAR"/>
|
||||||
<result property="thumb" column="thumb" jdbcType="VARCHAR"/>
|
<result property="thumb" column="thumb" jdbcType="VARCHAR"/>
|
||||||
<result property="charge" column="charge" jdbcType="INTEGER"/>
|
<result property="charge" column="charge" jdbcType="INTEGER"/>
|
||||||
<result property="classHour" column="class_hour" jdbcType="INTEGER"/>
|
<result property="classHour" column="class_hour" jdbcType="INTEGER"/>
|
||||||
<result property="isShow" column="is_show" jdbcType="TINYINT"/>
|
<result property="isShow" column="is_show" jdbcType="TINYINT"/>
|
||||||
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||||
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
||||||
<result property="deletedAt" column="deleted_at" jdbcType="TIMESTAMP"/>
|
<result property="deletedAt" column="deleted_at" jdbcType="TIMESTAMP"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id,title,thumb,
|
id
|
||||||
|
,title,thumb,
|
||||||
charge,class_hour,is_show,
|
charge,class_hour,is_show,
|
||||||
created_at,updated_at,deleted_at
|
created_at,updated_at,deleted_at
|
||||||
</sql>
|
</sql>
|
||||||
@ -27,4 +28,142 @@
|
|||||||
FROM `resource_course_category`
|
FROM `resource_course_category`
|
||||||
GROUP BY `resource_course_category`.`category_id`;
|
GROUP BY `resource_course_category`.`category_id`;
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="paginate" resultType="xyz.playedu.api.domain.Course">
|
||||||
|
SELECT `courses`.*
|
||||||
|
FROM `courses`
|
||||||
|
<if test="depIds != null and depIds != ''">
|
||||||
|
<choose>
|
||||||
|
<when test="depIds.indexOf('0')==0">
|
||||||
|
LEFT JOIN `course_department` ON `course_department`.`course_id` = `courses`.`id`
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
INNER JOIN `course_department` ON `course_department`.`course_id` = `courses`.`id`
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
<if test="categoryIds != null and categoryIds != ''">
|
||||||
|
<choose>
|
||||||
|
<when test="categoryIds.indexOf('0')==0">
|
||||||
|
LEFT JOIN `resource_course_category` ON `resource_course_category`.`course_id` = `courses`.`id`
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
INNER JOIN `resource_course_category` ON `resource_course_category`.`course_id` = `courses`.`id`
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<where>
|
||||||
|
<if test="depIds != null and depIds != ''">
|
||||||
|
<choose>
|
||||||
|
<when test="depIds.indexOf('0')==0">
|
||||||
|
AND `course_department`.`course_id` IS NULL
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
AND `course_department`.`dep_id` IN (#{depIds})
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
<if test="categoryIds != null and categoryIds != ''">
|
||||||
|
<choose>
|
||||||
|
<when test="categoryIds.indexOf('0')==0">
|
||||||
|
AND `resource_course_category`.`course_id` IS NULL
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
AND `resource_course_category`.`category_id` IN (#{categoryIds})
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="title != null and title != ''">
|
||||||
|
AND `courses`.`title` LIKE concat('%',#{title},'%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
|
||||||
|
<if test="sortAlgo == 'asc'">
|
||||||
|
<choose>
|
||||||
|
<when test="sortField == 'charge'">
|
||||||
|
ORDER BY `courses`.`charge` ASC
|
||||||
|
</when>
|
||||||
|
<when test="sortField == 'class_hour'">
|
||||||
|
ORDER BY `courses`.`class_hour` ASC
|
||||||
|
</when>
|
||||||
|
<when test="sortField == 'created_at'">
|
||||||
|
ORDER BY `courses`.`created_at` ASC
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
ORDER BY `courses`.`id` ASC
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
<if test="sortAlgo != 'asc'">
|
||||||
|
<choose>
|
||||||
|
<when test="sortField == 'charge'">
|
||||||
|
ORDER BY `courses`.`charge` DESC
|
||||||
|
</when>
|
||||||
|
<when test="sortField == 'class_hour'">
|
||||||
|
ORDER BY `courses`.`class_hour` DESC
|
||||||
|
</when>
|
||||||
|
<when test="sortField == 'created_at'">
|
||||||
|
ORDER BY `courses`.`created_at` DESC
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
ORDER BY `courses`.`id` ASC
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
LIMIT #{pageStart}, #{pageSize};
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="paginateCount" resultType="java.lang.Long">
|
||||||
|
SELECT count(1)
|
||||||
|
FROM `courses`
|
||||||
|
<if test="depIds != null and depIds != ''">
|
||||||
|
<choose>
|
||||||
|
<when test="depIds.indexOf('0')==0">
|
||||||
|
LEFT JOIN `course_department` ON `course_department`.`course_id` = `courses`.`id`
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
INNER JOIN `course_department` ON `course_department`.`course_id` = `courses`.`id`
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
<if test="categoryIds != null and categoryIds != ''">
|
||||||
|
<choose>
|
||||||
|
<when test="categoryIds.indexOf('0')==0">
|
||||||
|
LEFT JOIN `resource_course_category` ON `resource_course_category`.`course_id` = `courses`.`id`
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
INNER JOIN `resource_course_category` ON `resource_course_category`.`course_id` = `courses`.`id`
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<where>
|
||||||
|
<if test="depIds != null and depIds != ''">
|
||||||
|
<choose>
|
||||||
|
<when test="depIds.indexOf('0')==0">
|
||||||
|
AND `course_department`.`course_id` IS NULL
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
AND `course_department`.`dep_id` IN (#{depIds})
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
<if test="categoryIds != null and categoryIds != ''">
|
||||||
|
<choose>
|
||||||
|
<when test="categoryIds.indexOf('0')==0">
|
||||||
|
AND `resource_course_category`.`course_id` IS NULL
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
AND `resource_course_category`.`category_id` IN (#{categoryIds})
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="title != null and title != ''">
|
||||||
|
AND `courses`.`title` LIKE concat('%',#{title},'%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user