bug
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.peanut.modules.sociology.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
@@ -11,12 +12,15 @@ import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.to.ParamTo;
|
||||
import com.peanut.modules.sociology.service.ShopProductService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service("sociologyShopProduct")
|
||||
@@ -68,7 +72,41 @@ public class ShopProductServiceImpl extends ServiceImpl<ShopProductDao, ShopProd
|
||||
shopProductCourseEntityMPJLambdaWrapper.eq(ShopProductCourseEntity::getProductId,productId);
|
||||
List<CourseEntity> courseEntities = shopProductCourseDao.selectJoinList(CourseEntity.class, shopProductCourseEntityMPJLambdaWrapper);
|
||||
flag.put("courses",courseEntities);
|
||||
|
||||
//查询包含此商品的所有商品的列表
|
||||
List<Integer> book_product_ids = new ArrayList<>();
|
||||
if(bookEntities.size()>0){
|
||||
List<Integer> collect = bookEntities.stream().map(BookEntity::getId).collect(Collectors.toList());
|
||||
LambdaQueryWrapper<ShopProductBookEntity> shopProductBookEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
shopProductBookEntityLambdaQueryWrapper.in(ShopProductBookEntity::getBookId,collect);
|
||||
shopProductBookEntityLambdaQueryWrapper.groupBy(ShopProductBookEntity::getProductId);
|
||||
shopProductBookEntityLambdaQueryWrapper.having("count(product_id)>="+collect.size());
|
||||
List<ShopProductBookEntity> shopProductBookEntities = shopProductBookDao.selectList(shopProductBookEntityLambdaQueryWrapper);
|
||||
book_product_ids = shopProductBookEntities.stream().map(ShopProductBookEntity::getProductId).collect(Collectors.toList());
|
||||
}
|
||||
List<Integer> course_product_ids = new ArrayList<>();
|
||||
if(courseEntities.size()>0){
|
||||
List<Integer> collect = courseEntities.stream().map(CourseEntity::getId).collect(Collectors.toList());
|
||||
LambdaQueryWrapper<ShopProductCourseEntity> shopProductCourseEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
shopProductCourseEntityLambdaQueryWrapper.in(ShopProductCourseEntity::getCourseId,collect);
|
||||
shopProductCourseEntityLambdaQueryWrapper.groupBy(ShopProductCourseEntity::getProductId);
|
||||
shopProductCourseEntityLambdaQueryWrapper.having("count(product_id)>="+collect.size());
|
||||
List<ShopProductCourseEntity> shopProductCourseEntities = shopProductCourseDao.selectList(shopProductCourseEntityLambdaQueryWrapper);
|
||||
course_product_ids = shopProductCourseEntities.stream().map(ShopProductCourseEntity::getProductId).collect(Collectors.toList());
|
||||
}
|
||||
if(book_product_ids.size()==0&&course_product_ids.size()==0){
|
||||
List<ShopProduct> shopProducts = new ArrayList<>();
|
||||
shopProducts.add(product);
|
||||
flag.put("GLProducts",shopProducts);
|
||||
} else if (book_product_ids.size()>0&&course_product_ids.size()>0) {
|
||||
List<Integer> intersection = new ArrayList<>(book_product_ids);
|
||||
intersection.retainAll(course_product_ids);
|
||||
List<ShopProduct> shopProducts = this.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProduct>().in(ShopProduct::getProductId, intersection));
|
||||
flag.put("GLProducts",shopProducts);
|
||||
} else {
|
||||
List<Integer> is = new ArrayList<>(CollectionUtils.union(book_product_ids, course_product_ids));
|
||||
List<ShopProduct> shopProducts = this.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProduct>().in(ShopProduct::getProductId, is));
|
||||
flag.put("GLProducts",shopProducts);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user