|
|
@@ -2,6 +2,7 @@ package com.ylx.massage.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ylx.massage.domain.Product;
|
|
|
import com.ylx.massage.domain.TXiangmu;
|
|
|
@@ -42,9 +43,7 @@ public class ProductSelectionServiceImpl implements ProductSelectionService {
|
|
|
}
|
|
|
|
|
|
// 3. 查询全部 (Type = null)
|
|
|
- // 注意:跨表分页比较复杂,这里采用“分别查询当前页数据然后合并”的策略
|
|
|
- // 如果数据量极大且必须严格排序,建议使用自定义 SQL 或 搜索引擎
|
|
|
- return queryAllProducts(page, dto);
|
|
|
+ return queryAllProductsUnion(page, dto);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -103,79 +102,16 @@ public class ProductSelectionServiceImpl implements ProductSelectionService {
|
|
|
* 3. 获取总列表的大小作为 total。
|
|
|
* 4. 根据分页参数截取当前页的数据。
|
|
|
*/
|
|
|
- private Page<ProductOptionVO> queryAllProducts(Page<ProductOptionVO> page, OptionDTO dto) {
|
|
|
- long current = page.getCurrent();
|
|
|
- long size = page.getSize();
|
|
|
-
|
|
|
- // --- 1. 查出积分商品列表 (全量) ---
|
|
|
- LambdaQueryWrapper<Product> productWrapper = new LambdaQueryWrapper<>();
|
|
|
- productWrapper.eq(Product::getStatus, 1)
|
|
|
- .eq(Product::getDeleted, 0);
|
|
|
- if (StrUtil.isNotEmpty(dto.getTitle())) {
|
|
|
- productWrapper.like(Product::getName, dto.getTitle());
|
|
|
- }
|
|
|
- List<Product> integralList = productService.list(productWrapper);
|
|
|
-
|
|
|
- // --- 2. 查出项目商品列表 (全量) ---
|
|
|
- LambdaQueryWrapper<TXiangmu> xiangmuWrapper = new LambdaQueryWrapper<>();
|
|
|
- xiangmuWrapper.eq(TXiangmu::getIsDelete, 0);
|
|
|
- if (StrUtil.isNotEmpty(dto.getTitle())) {
|
|
|
- xiangmuWrapper.like(TXiangmu::getcTitle, dto.getTitle());
|
|
|
- }
|
|
|
- List<TXiangmu> projectList = xiangmuService.list(xiangmuWrapper);
|
|
|
-
|
|
|
- // --- 3. 转换为 VO 并合并 (关键步骤) ---
|
|
|
- List<ProductOptionVO> totalList = new ArrayList<>();
|
|
|
-
|
|
|
- // 添加积分商品
|
|
|
- totalList.addAll(integralList.stream().map(p -> {
|
|
|
- ProductOptionVO vo = new ProductOptionVO();
|
|
|
- vo.setId(String.valueOf(p.getId()));
|
|
|
- vo.setProductType(1);
|
|
|
- vo.setTitle(p.getName());
|
|
|
- return vo;
|
|
|
- }).collect(Collectors.toList()));
|
|
|
-
|
|
|
- // 添加项目商品
|
|
|
- totalList.addAll(projectList.stream().map(x -> {
|
|
|
- ProductOptionVO vo = new ProductOptionVO();
|
|
|
- vo.setId(x.getcId());
|
|
|
- vo.setProductType(0);
|
|
|
- vo.setTitle(x.getcTitle());
|
|
|
- return vo;
|
|
|
- }).collect(Collectors.toList()));
|
|
|
-
|
|
|
- // --- 4. 计算总记录数 (这就是你要的修正点) ---
|
|
|
- // total 是两张表数据的总和
|
|
|
- long total = totalList.size();
|
|
|
-
|
|
|
- // --- 5. 内存分页截取 ---
|
|
|
- // 计算起始索引
|
|
|
- long offset = (current - 1) * size;
|
|
|
-
|
|
|
- // 边界检查:如果起始位置超过总数,说明这一页没数据
|
|
|
- if (offset >= total) {
|
|
|
- // 返回空列表,但保留 total 以便前端计算页数
|
|
|
- Page<ProductOptionVO> resultPage = new Page<>(current, size);
|
|
|
- resultPage.setRecords(new ArrayList<>());
|
|
|
- resultPage.setTotal(total);
|
|
|
- resultPage.setPages(total == 0 ? 0 : (total + size - 1) / size);
|
|
|
- return resultPage;
|
|
|
- }
|
|
|
-
|
|
|
- // 计算结束索引
|
|
|
- long limit = Math.min(offset + size, total);
|
|
|
-
|
|
|
- // 截取当前页数据
|
|
|
- List<ProductOptionVO> records = totalList.subList((int) offset, (int) limit);
|
|
|
-
|
|
|
- // --- 6. 构建返回结果 ---
|
|
|
- Page<ProductOptionVO> resultPage = new Page<>(current, size);
|
|
|
- resultPage.setRecords(records);
|
|
|
- resultPage.setTotal(total); // 设置总和
|
|
|
- resultPage.setPages(total == 0 ? 0 : (total + size - 1) / size); // 计算总页数
|
|
|
-
|
|
|
- return resultPage;
|
|
|
+ private Page<ProductOptionVO> queryAllProductsUnion(Page page, OptionDTO dto) {
|
|
|
+ // 调用自定义 SQL
|
|
|
+ IPage<ProductOptionVO> resultPage = xiangmuService.selectOptionUnionPage(page, dto);
|
|
|
+
|
|
|
+ // 将 IPage 转为具体的 Page 实现类返回(如果需要)
|
|
|
+ Page<ProductOptionVO> returnPage = new Page<>(page.getCurrent(), page.getSize());
|
|
|
+ returnPage.setRecords(resultPage.getRecords());
|
|
|
+ returnPage.setTotal(resultPage.getTotal());
|
|
|
+ returnPage.setPages(resultPage.getPages());
|
|
|
+ return returnPage;
|
|
|
}
|
|
|
|
|
|
/**
|