Commit cb015642df0c0b9f0e128e9439370661bf5eba45
1 parent
f6b5ef06
feat(mall):商品 SPU tab 计数支持按筛选条件统计
get-count 接收可选 ProductSpuPageReqVO(name/categoryId/createTime),每个 tab 复用 appendTabQuery 拼筛选统计;不传参仍为全局计数,向后兼容。
Showing
4 changed files
with
29 additions
and
16 deletions
yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java
| @@ -118,10 +118,10 @@ public class ProductSpuController { | @@ -118,10 +118,10 @@ public class ProductSpuController { | ||
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | @GetMapping("/get-count") | 120 | @GetMapping("/get-count") |
| 121 | - @Operation(summary = "获得商品 SPU 分页 tab count") | 121 | + @Operation(summary = "获得商品 SPU 分页 tab count(支持按 name/categoryId/createTime 筛选)") |
| 122 | @PreAuthorize("@ss.hasPermission('product:spu:query')") | 122 | @PreAuthorize("@ss.hasPermission('product:spu:query')") |
| 123 | - public CommonResult<Map<Integer, Long>> getSpuCount() { | ||
| 124 | - return success(productSpuService.getTabsCount()); | 123 | + public CommonResult<Map<Integer, Long>> getSpuCount(ProductSpuPageReqVO reqVO) { |
| 124 | + return success(productSpuService.getTabsCount(reqVO)); | ||
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | @GetMapping("/export-excel") | 127 | @GetMapping("/export-excel") |
yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java
| @@ -147,6 +147,22 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { | @@ -147,6 +147,22 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { | ||
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | /** | 149 | /** |
| 150 | + * 按筛选条件 + Tab 统计商品 SPU 数量(用于带筛选的 tab count) | ||
| 151 | + * | ||
| 152 | + * @param reqVO 筛选条件(name/categoryId/createTime) | ||
| 153 | + * @param tabType Tab 标签类型 | ||
| 154 | + * @return 数量 | ||
| 155 | + */ | ||
| 156 | + default Long selectCountByTab(ProductSpuPageReqVO reqVO, Integer tabType) { | ||
| 157 | + LambdaQueryWrapperX<ProductSpuDO> queryWrapper = new LambdaQueryWrapperX<ProductSpuDO>() | ||
| 158 | + .likeIfPresent(ProductSpuDO::getName, reqVO.getName()) | ||
| 159 | + .eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId()) | ||
| 160 | + .betweenIfPresent(ProductSpuDO::getCreateTime, reqVO.getCreateTime()); | ||
| 161 | + appendTabQuery(tabType, queryWrapper); | ||
| 162 | + return selectCount(queryWrapper); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + /** | ||
| 150 | * 更新商品 SPU 浏览量 | 166 | * 更新商品 SPU 浏览量 |
| 151 | * | 167 | * |
| 152 | * @param id 商品 SPU 编号 | 168 | * @param id 商品 SPU 编号 |
yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java
| @@ -118,11 +118,12 @@ public interface ProductSpuService { | @@ -118,11 +118,12 @@ public interface ProductSpuService { | ||
| 118 | void updateSpuStatus(ProductSpuUpdateStatusReqVO updateReqVO); | 118 | void updateSpuStatus(ProductSpuUpdateStatusReqVO updateReqVO); |
| 119 | 119 | ||
| 120 | /** | 120 | /** |
| 121 | - * 获取 SPU 列表标签对应的 Count 数量 | 121 | + * 获取 SPU 列表标签对应的 Count 数量(支持按 name/categoryId/createTime 筛选) |
| 122 | * | 122 | * |
| 123 | + * @param reqVO 筛选条件 | ||
| 123 | * @return Count 数量 | 124 | * @return Count 数量 |
| 124 | */ | 125 | */ |
| 125 | - Map<Integer, Long> getTabsCount(); | 126 | + Map<Integer, Long> getTabsCount(ProductSpuPageReqVO reqVO); |
| 126 | 127 | ||
| 127 | /** | 128 | /** |
| 128 | * 通过分类 categoryId 查询 SPU 个数 | 129 | * 通过分类 categoryId 查询 SPU 个数 |
yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| @@ -256,23 +256,19 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -256,23 +256,19 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | @Override | 258 | @Override |
| 259 | - public Map<Integer, Long> getTabsCount() { | 259 | + public Map<Integer, Long> getTabsCount(ProductSpuPageReqVO reqVO) { |
| 260 | Map<Integer, Long> counts = Maps.newLinkedHashMapWithExpectedSize(5); | 260 | Map<Integer, Long> counts = Maps.newLinkedHashMapWithExpectedSize(5); |
| 261 | - // 查询销售中的商品数量 | 261 | + // 每个 tab 的数量 = 筛选条件(name/categoryId/createTime)+ 该 tab 的状态/库存条件 |
| 262 | counts.put(ProductSpuPageReqVO.FOR_SALE, | 262 | counts.put(ProductSpuPageReqVO.FOR_SALE, |
| 263 | - productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus())); | ||
| 264 | - // 查询仓库中的商品数量 | 263 | + productSpuMapper.selectCountByTab(reqVO, ProductSpuPageReqVO.FOR_SALE)); |
| 265 | counts.put(ProductSpuPageReqVO.IN_WAREHOUSE, | 264 | counts.put(ProductSpuPageReqVO.IN_WAREHOUSE, |
| 266 | - productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.DISABLE.getStatus())); | ||
| 267 | - // 查询售空的商品数量 | 265 | + productSpuMapper.selectCountByTab(reqVO, ProductSpuPageReqVO.IN_WAREHOUSE)); |
| 268 | counts.put(ProductSpuPageReqVO.SOLD_OUT, | 266 | counts.put(ProductSpuPageReqVO.SOLD_OUT, |
| 269 | - productSpuMapper.selectCount(ProductSpuDO::getStock, 0)); | ||
| 270 | - // 查询触发警戒库存的商品数量 | 267 | + productSpuMapper.selectCountByTab(reqVO, ProductSpuPageReqVO.SOLD_OUT)); |
| 271 | counts.put(ProductSpuPageReqVO.ALERT_STOCK, | 268 | counts.put(ProductSpuPageReqVO.ALERT_STOCK, |
| 272 | - productSpuMapper.selectCount()); | ||
| 273 | - // 查询回收站中的商品数量 | 269 | + productSpuMapper.selectCountByTab(reqVO, ProductSpuPageReqVO.ALERT_STOCK)); |
| 274 | counts.put(ProductSpuPageReqVO.RECYCLE_BIN, | 270 | counts.put(ProductSpuPageReqVO.RECYCLE_BIN, |
| 275 | - productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus())); | 271 | + productSpuMapper.selectCountByTab(reqVO, ProductSpuPageReqVO.RECYCLE_BIN)); |
| 276 | return counts; | 272 | return counts; |
| 277 | } | 273 | } |
| 278 | 274 |