mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-23 04:22:43 +08:00
优化线上课列表
This commit is contained in:
parent
0689c0d428
commit
17d18da19b
@ -95,7 +95,7 @@ public class CourseController {
|
||||
|
||||
Date now = new Date();
|
||||
|
||||
if (req.getHours() != null) {//无章节课时配置
|
||||
if (req.getHours().size() > 0) {//无章节课时配置
|
||||
List<CourseHour> insertHours = new ArrayList<>();
|
||||
final Integer[] chapterSort = {0};
|
||||
for (CourseRequest.HourItem hourItem : req.getHours()) {
|
||||
@ -117,6 +117,7 @@ public class CourseController {
|
||||
if (req.getChapters() == null || req.getChapters().size() == 0) {
|
||||
return JsonResponse.error("请配置课时");
|
||||
}
|
||||
|
||||
List<CourseHour> insertHours = new ArrayList<>();
|
||||
final Integer[] chapterSort = {0};
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ -53,12 +54,10 @@ public class Course implements Serializable {
|
||||
@JsonProperty("created_at")
|
||||
private Date createdAt;
|
||||
|
||||
@JsonProperty("updated_at")
|
||||
@JsonIgnore
|
||||
private Date updatedAt;
|
||||
|
||||
/**
|
||||
* 删除时间
|
||||
*/
|
||||
@JsonIgnore
|
||||
private Date deletedAt;
|
||||
|
||||
@TableField(exist = false)
|
||||
|
@ -4,6 +4,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import xyz.playedu.api.domain.Course;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import xyz.playedu.api.types.mapper.CourseCategoryCountMapper;
|
||||
import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -18,6 +19,10 @@ public interface CourseMapper extends BaseMapper<Course> {
|
||||
|
||||
List<CourseCategoryCountMapper> getCategoryCount();
|
||||
|
||||
List<Course> paginate(CoursePaginateFiler filer);
|
||||
|
||||
Long paginateCount(CoursePaginateFiler filer);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
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 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.paginate.CoursePaginateFiler;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.util.HelperUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -39,51 +35,12 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
||||
|
||||
@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().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);
|
||||
filter.setPageStart((page - 1) * size);
|
||||
filter.setPageSize(size);
|
||||
|
||||
PaginationResult<Course> pageResult = new PaginationResult<>();
|
||||
pageResult.setData(pageObj.getRecords());
|
||||
pageResult.setTotal(pageObj.getTotal());
|
||||
pageResult.setData(getBaseMapper().paginate(filter));
|
||||
pageResult.setTotal(getBaseMapper().paginateCount(filter));
|
||||
|
||||
return pageResult;
|
||||
}
|
||||
|
@ -21,4 +21,8 @@ public class CoursePaginateFiler {
|
||||
|
||||
private Integer isShow;
|
||||
|
||||
private Integer pageStart;
|
||||
|
||||
private Integer pageSize;
|
||||
|
||||
}
|
||||
|
@ -5,19 +5,20 @@
|
||||
<mapper namespace="xyz.playedu.api.mapper.CourseMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.Course">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="title" column="title" jdbcType="VARCHAR"/>
|
||||
<result property="thumb" column="thumb" jdbcType="VARCHAR"/>
|
||||
<result property="charge" column="charge" jdbcType="INTEGER"/>
|
||||
<result property="classHour" column="class_hour" jdbcType="INTEGER"/>
|
||||
<result property="isShow" column="is_show" jdbcType="TINYINT"/>
|
||||
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="deletedAt" column="deleted_at" jdbcType="TIMESTAMP"/>
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="title" column="title" jdbcType="VARCHAR"/>
|
||||
<result property="thumb" column="thumb" jdbcType="VARCHAR"/>
|
||||
<result property="charge" column="charge" jdbcType="INTEGER"/>
|
||||
<result property="classHour" column="class_hour" jdbcType="INTEGER"/>
|
||||
<result property="isShow" column="is_show" jdbcType="TINYINT"/>
|
||||
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="deletedAt" column="deleted_at" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,title,thumb,
|
||||
id
|
||||
,title,thumb,
|
||||
charge,class_hour,is_show,
|
||||
created_at,updated_at,deleted_at
|
||||
</sql>
|
||||
@ -27,4 +28,142 @@
|
||||
FROM `resource_course_category`
|
||||
GROUP BY `resource_course_category`.`category_id`;
|
||||
</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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user