首页查询优化
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.sqx.modules.course.service.impl;
|
package com.sqx.modules.course.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
@@ -44,6 +45,7 @@ import java.math.BigDecimal;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -144,7 +146,16 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements
|
|||||||
if(admin==null){
|
if(admin==null){
|
||||||
IPage<Map<String, Object>> mapIPage = baseMapper.selectCourse(pages, classifyId, title, isRecommend, status, bannerId,
|
IPage<Map<String, Object>> mapIPage = baseMapper.selectCourse(pages, classifyId, title, isRecommend, status, bannerId,
|
||||||
sort, startTime, endTime, userId, isPrice, over,wxCourse,dyCourse,wxShow,dyShow);
|
sort, startTime, endTime, userId, isPrice, over,wxCourse,dyCourse,wxShow,dyShow);
|
||||||
|
sort = ObjectUtil.defaultIfNull(sort, 0);
|
||||||
List<Map<String, Object>> records = mapIPage.getRecords();
|
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){
|
for (Map<String, Object> map:records){
|
||||||
Object courseDetailsId = map.get("courseDetailsId");
|
Object courseDetailsId = map.get("courseDetailsId");
|
||||||
Object courseId = map.get("courseId");
|
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,
|
IPage<Map<String, Object>> mapIPage = baseMapper.selectCourseAdmin(pages, classifyId, title, isRecommend, status, bannerId,
|
||||||
sort, startTime, endTime, userId, isPrice, over, wxCourse, dyCourse,wxShow,dyShow);
|
sort, startTime, endTime, userId, isPrice, over, wxCourse, dyCourse,wxShow,dyShow);
|
||||||
List<Map<String, Object>> records = mapIPage.getRecords();
|
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){
|
for (Map<String, Object> map:records){
|
||||||
Object courseId = map.get("courseId");
|
Object courseId = map.get("courseId");
|
||||||
//默认取第一集
|
//默认取第一集
|
||||||
|
|||||||
@@ -116,12 +116,14 @@
|
|||||||
<if test="sort==null">
|
<if test="sort==null">
|
||||||
order by c.sort asc
|
order by c.sort asc
|
||||||
</if>
|
</if>
|
||||||
|
<!--
|
||||||
<if test="sort!=null and sort==1">
|
<if test="sort!=null and sort==1">
|
||||||
order by goodNum desc
|
order by goodNum desc
|
||||||
</if>
|
</if>
|
||||||
<if test="sort!=null and sort==2">
|
<if test="sort!=null and sort==2">
|
||||||
order by weekGoodNum desc
|
order by weekGoodNum desc
|
||||||
</if>
|
</if>
|
||||||
|
-->
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectCourseAdmin" resultType="Map">
|
<select id="selectCourseAdmin" resultType="Map">
|
||||||
@@ -244,12 +246,14 @@
|
|||||||
<if test="sort==null">
|
<if test="sort==null">
|
||||||
order by c.sort asc,c.create_time desc
|
order by c.sort asc,c.create_time desc
|
||||||
</if>
|
</if>
|
||||||
|
<!--
|
||||||
<if test="sort!=null and sort==1">
|
<if test="sort!=null and sort==1">
|
||||||
order by goodNum desc
|
order by goodNum desc
|
||||||
</if>
|
</if>
|
||||||
<if test="sort!=null and sort==2">
|
<if test="sort!=null and sort==2">
|
||||||
order by weekGoodNum desc
|
order by weekGoodNum desc
|
||||||
</if>
|
</if>
|
||||||
|
-->
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectCourseTitle" resultType="Map">
|
<select id="selectCourseTitle" resultType="Map">
|
||||||
|
|||||||
Reference in New Issue
Block a user