首页查询优化

This commit is contained in:
谭凯凯
2024-12-26 21:27:28 +08:00
committed by Tankaikai
parent da64106678
commit e5ead76f4f
2 changed files with 23 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package com.sqx.modules.course.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -44,6 +45,7 @@ import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
@Service
@Slf4j
@@ -144,7 +146,16 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements
if(admin==null){
IPage<Map<String, Object>> mapIPage = baseMapper.selectCourse(pages, classifyId, title, isRecommend, status, bannerId,
sort, startTime, endTime, userId, isPrice, over,wxCourse,dyCourse,wxShow,dyShow);
sort = ObjectUtil.defaultIfNull(sort, 0);
List<Map<String, Object>> records = mapIPage.getRecords();
if(sort != null && sort == 1){
records = records.stream().sorted(Comparator.comparingInt(item -> (int)item.get("goodNum"))).collect(Collectors.toList());
Collections.reverse(records);
}
if(sort != null && sort == 2){
records = records.stream().sorted(Comparator.comparingInt(item -> (int)item.get("weekGoodNum"))).collect(Collectors.toList());
Collections.reverse(records);
}
for (Map<String, Object> map:records){
Object courseDetailsId = map.get("courseDetailsId");
Object courseId = map.get("courseId");
@@ -172,6 +183,14 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements
IPage<Map<String, Object>> mapIPage = baseMapper.selectCourseAdmin(pages, classifyId, title, isRecommend, status, bannerId,
sort, startTime, endTime, userId, isPrice, over, wxCourse, dyCourse,wxShow,dyShow);
List<Map<String, Object>> records = mapIPage.getRecords();
if(sort != null && sort == 1){
records = records.stream().sorted(Comparator.comparingInt(item -> (int)item.get("goodNum"))).collect(Collectors.toList());
Collections.reverse(records);
}
if(sort != null && sort == 2){
records = records.stream().sorted(Comparator.comparingInt(item -> (int)item.get("weekGoodNum"))).collect(Collectors.toList());
Collections.reverse(records);
}
for (Map<String, Object> map:records){
Object courseId = map.get("courseId");
//默认取第一集

View File

@@ -116,12 +116,14 @@
<if test="sort==null">
order by c.sort asc
</if>
<!--
<if test="sort!=null and sort==1">
order by goodNum desc
</if>
<if test="sort!=null and sort==2">
order by weekGoodNum desc
</if>
-->
</select>
<select id="selectCourseAdmin" resultType="Map">
@@ -244,12 +246,14 @@
<if test="sort==null">
order by c.sort asc,c.create_time desc
</if>
<!--
<if test="sort!=null and sort==1">
order by goodNum desc
</if>
<if test="sort!=null and sort==2">
order by weekGoodNum desc
</if>
-->
</select>
<select id="selectCourseTitle" resultType="Map">