查询逻辑修改
This commit is contained in:
parent
11f5697b8b
commit
8b46967c53
|
|
@ -23,10 +23,7 @@ import org.springframework.cache.annotation.CachePut;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -116,21 +113,33 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
|
||||||
@CachePut(value = "app:courseCollect", key = "#userId")
|
@CachePut(value = "app:courseCollect", key = "#userId")
|
||||||
public Result selectByUserId(Integer page, Integer limit, Long userId, Integer classify) {
|
public Result selectByUserId(Integer page, Integer limit, Long userId, Integer classify) {
|
||||||
PageHelper.startPage(page, limit);
|
PageHelper.startPage(page, limit);
|
||||||
Set<Long> courseIdList = baseMapper.selectList(new LambdaQueryWrapper<CourseCollect>()
|
List<CourseCollect> courseCollectList = baseMapper.selectList(new LambdaQueryWrapper<CourseCollect>()
|
||||||
.eq(CourseCollect::getUserId, userId)
|
.eq(CourseCollect::getUserId, userId)
|
||||||
.eq(CourseCollect::getClassify, classify)
|
.eq(CourseCollect::getClassify, classify)
|
||||||
.isNotNull(CourseCollect::getCourseId)
|
.isNotNull(CourseCollect::getCourseId)
|
||||||
.select(CourseCollect::getCourseId, CourseCollect::getUserId))
|
.select(CourseCollect::getCourseId, CourseCollect::getUserId));
|
||||||
.stream().map(CourseCollect::getCourseId).collect(Collectors.toSet());
|
|
||||||
// List<CourseCollect> collectList = baseMapper.selectByUserId(userId, classify);
|
Set<Long> courseIdList = new HashSet<>();
|
||||||
// Set<Long> courseIdList = collectList.stream().map(CourseCollect::getCourseId).collect(Collectors.toSet());
|
HashMap<Long, CourseCollect> courseCollectHashMap = new HashMap<>();
|
||||||
|
for (CourseCollect courseCollect : courseCollectList) {
|
||||||
|
courseIdList.add(courseCollect.getCourseId());
|
||||||
|
courseCollectHashMap.put(courseCollect.getCourseId(), courseCollect);
|
||||||
|
}
|
||||||
|
|
||||||
List<Course> courseList = courseIdList.isEmpty() ? new ArrayList<>() : courseDao.selectList(new LambdaQueryWrapper<Course>().in(Course::getCourseId, courseIdList));
|
List<Course> courseList = courseIdList.isEmpty() ? new ArrayList<>() : courseDao.selectList(new LambdaQueryWrapper<Course>().in(Course::getCourseId, courseIdList));
|
||||||
// List<Course> courseList = baseMapper.selectCourseByCollect(userId, classify);
|
// List<Course> courseList = baseMapper.selectCourseByCollect(userId, classify);
|
||||||
|
Set<Long> detailIdList = courseList.stream().map(Course::getCourseDetailsId).collect(Collectors.toSet());
|
||||||
|
Map<Long, String> courseDetailsMap = detailIdList.isEmpty() ? new HashMap<>() : courseDetailsService.list(new LambdaQueryWrapper<CourseDetails>()
|
||||||
|
.in(CourseDetails::getCourseDetailsId, detailIdList)
|
||||||
|
.select(CourseDetails::getCourseDetailsName)).stream()
|
||||||
|
.collect(Collectors.toMap(CourseDetails::getCourseDetailsId, CourseDetails::getCourseDetailsName));
|
||||||
PageInfo<Course> pageInfo = new PageInfo<>(courseList);
|
PageInfo<Course> pageInfo = new PageInfo<>(courseList);
|
||||||
if (CollectionUtil.isNotEmpty(courseList)) {
|
if (CollectionUtil.isNotEmpty(courseList)) {
|
||||||
List<Course> courses = pageInfo.getList();
|
List<Course> courses = pageInfo.getList();
|
||||||
for (Course course : courses) {
|
for (Course course : courses) {
|
||||||
course.setCourseClassification(courseClassificationDao.selectById(course.getClassifyId()));
|
course.setCourseClassification(courseClassificationDao.selectById(course.getClassifyId()));
|
||||||
|
CourseCollect courseCollect = courseCollectHashMap.get(course.getCourseId());
|
||||||
|
course.setCourseDetailsName(courseCollect == null ? null : courseDetailsMap.get(courseCollect.getCourseDetailsId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Result.success().put("data", PageUtils.page(pageInfo, true));
|
return Result.success().put("data", PageUtils.page(pageInfo, true));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue