Commit 7bf37fcb647d685a8bd3fb65f1550db87129120a
1 parent
c00ded3e
优化管理后台的商品分页的查询
Showing
8 changed files
with
42 additions
and
55 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java
| 1 | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; | 1 | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; |
| 2 | 2 | ||
| 3 | -import lombok.*; | ||
| 4 | -import java.util.*; | ||
| 5 | -import io.swagger.annotations.*; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageParam; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 7 | -import org.springframework.format.annotation.DateTimeFormat; | ||
| 8 | - | ||
| 9 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | 4 | +import io.swagger.annotations.ApiModel; |
| 5 | +import io.swagger.annotations.ApiModelProperty; | ||
| 6 | +import lombok.Data; | ||
| 7 | +import lombok.EqualsAndHashCode; | ||
| 8 | +import lombok.ToString; | ||
| 10 | 9 | ||
| 11 | @ApiModel("管理后台 - 商品 SPU 分页 Request VO") | 10 | @ApiModel("管理后台 - 商品 SPU 分页 Request VO") |
| 12 | @Data | 11 | @Data |
| @@ -26,7 +25,7 @@ public class ProductSpuPageReqVO extends PageParam { | @@ -26,7 +25,7 @@ public class ProductSpuPageReqVO extends PageParam { | ||
| 26 | @ApiModelProperty(value = "商品品牌编号", example = "1") | 25 | @ApiModelProperty(value = "商品品牌编号", example = "1") |
| 27 | private Long brandId; | 26 | private Long brandId; |
| 28 | 27 | ||
| 29 | - @ApiModelProperty(value = "上下架状态", example = "1", notes = "参见 CommonStatusEnum 枚举值") | 28 | + @ApiModelProperty(value = "上下架状态", example = "1", notes = "参见 ProductSpuStatusEnum 枚举值") |
| 30 | private Integer status; | 29 | private Integer status; |
| 31 | 30 | ||
| 32 | @ApiModelProperty(value = "销量最小值", example = "1") | 31 | @ApiModelProperty(value = "销量最小值", example = "1") |
| @@ -41,8 +40,7 @@ public class ProductSpuPageReqVO extends PageParam { | @@ -41,8 +40,7 @@ public class ProductSpuPageReqVO extends PageParam { | ||
| 41 | @ApiModelProperty(value = "市场价最大值", example = "1024") | 40 | @ApiModelProperty(value = "市场价最大值", example = "1024") |
| 42 | private Integer marketPriceMax; | 41 | private Integer marketPriceMax; |
| 43 | 42 | ||
| 44 | - // TODO @luowenfeng: 这个可以改成前端基于 tab, 传递不同的条件么? | ||
| 45 | - @ApiModelProperty(value = "tab 状态 null 全部, 0:销售中(上架) 1:仓库中(下架) 2:预警中", example = "1") | ||
| 46 | - private Integer tabStatus; | 43 | + @ApiModelProperty(value = "是否库存告警", example = "true") |
| 44 | + private Boolean alarmStock; | ||
| 47 | 45 | ||
| 48 | } | 46 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java
| @@ -40,8 +40,7 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> { | @@ -40,8 +40,7 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> { | ||
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | - // TODO @luowenfeng: selectListByRemind,虽然不是很好,但是感觉会更清晰一些 | ||
| 44 | - default List<ProductSkuDO> selectRemindSpuIds(){ | 43 | + default List<ProductSkuDO> selectListByAlarmStock(){ |
| 45 | return selectList(new QueryWrapper<ProductSkuDO>().apply("stock <= warn_stock")); | 44 | return selectList(new QueryWrapper<ProductSkuDO>().apply("stock <= warn_stock")); |
| 46 | } | 45 | } |
| 47 | 46 |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java
| @@ -7,7 +7,7 @@ import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReq | @@ -7,7 +7,7 @@ import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReq | ||
| 7 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | 7 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 8 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | ||
| 10 | -import java.util.List; | 10 | +import java.util.Set; |
| 11 | 11 | ||
| 12 | /** | 12 | /** |
| 13 | * 商品spu Mapper | 13 | * 商品spu Mapper |
| @@ -29,8 +29,8 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { | @@ -29,8 +29,8 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { | ||
| 29 | .orderByDesc(ProductSpuDO::getSort)); | 29 | .orderByDesc(ProductSpuDO::getSort)); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | - default PageResult<ProductSpuDO> selectPage(ProductSpuPageReqVO reqVO, List<Long> spuIds) { | ||
| 33 | - LambdaQueryWrapperX<ProductSpuDO> productSpuDOLambdaQueryWrapperX = new LambdaQueryWrapperX<ProductSpuDO>() | 32 | + default PageResult<ProductSpuDO> selectPage(ProductSpuPageReqVO reqVO, Set<Long> alarmStockSpuIds) { |
| 33 | + return selectPage(reqVO, new LambdaQueryWrapperX<ProductSpuDO>() | ||
| 34 | .likeIfPresent(ProductSpuDO::getName, reqVO.getName()) | 34 | .likeIfPresent(ProductSpuDO::getName, reqVO.getName()) |
| 35 | .eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId()) | 35 | .eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId()) |
| 36 | .eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus()) | 36 | .eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus()) |
| @@ -38,16 +38,9 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { | @@ -38,16 +38,9 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { | ||
| 38 | .geIfPresent(ProductSpuDO::getSalesCount, reqVO.getSalesCountMin()) | 38 | .geIfPresent(ProductSpuDO::getSalesCount, reqVO.getSalesCountMin()) |
| 39 | .leIfPresent(ProductSpuDO::getMarketPrice, reqVO.getMarketPriceMax()) | 39 | .leIfPresent(ProductSpuDO::getMarketPrice, reqVO.getMarketPriceMax()) |
| 40 | .geIfPresent(ProductSpuDO::getMarketPrice, reqVO.getMarketPriceMin()) | 40 | .geIfPresent(ProductSpuDO::getMarketPrice, reqVO.getMarketPriceMin()) |
| 41 | - .orderByDesc(ProductSpuDO::getSort); | ||
| 42 | - // TODO @芋艿: 需要优化下这里的代码 | ||
| 43 | - if(reqVO.getTabStatus()!= null && reqVO.getTabStatus() == 2){ | ||
| 44 | - productSpuDOLambdaQueryWrapperX.inIfPresent(ProductSpuDO::getId, spuIds); | ||
| 45 | - }else{ | ||
| 46 | - productSpuDOLambdaQueryWrapperX.eqIfPresent(ProductSpuDO::getStatus, reqVO.getTabStatus()); | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | - return selectPage(reqVO, productSpuDOLambdaQueryWrapperX); | 41 | + .inIfPresent(ProductSpuDO::getId, alarmStockSpuIds) // 库存告警 |
| 42 | + .eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus()) | ||
| 43 | + .orderByDesc(ProductSpuDO::getSort)); | ||
| 50 | } | 44 | } |
| 51 | 45 | ||
| 52 | - | ||
| 53 | } | 46 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.product.service.sku; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.product.service.sku; | ||
| 3 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; | 3 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; |
| 4 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | 4 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 5 | 5 | ||
| 6 | -import javax.validation.Valid; | ||
| 7 | import java.util.Collection; | 6 | import java.util.Collection; |
| 8 | import java.util.List; | 7 | import java.util.List; |
| 9 | 8 | ||
| @@ -84,10 +83,10 @@ public interface ProductSkuService { | @@ -84,10 +83,10 @@ public interface ProductSkuService { | ||
| 84 | void deleteSkuBySpuId(Long spuId); | 83 | void deleteSkuBySpuId(Long spuId); |
| 85 | 84 | ||
| 86 | /** | 85 | /** |
| 87 | - * 获得商品预警中的 SPU 集合 | 86 | + * 获得库存预警的 SKU 数组 |
| 88 | * | 87 | * |
| 89 | - * @return 商品spuId集合 | 88 | + * @return SKU 数组 |
| 90 | */ | 89 | */ |
| 91 | - List<ProductSkuDO> getRemindSpuIds(); | 90 | + List<ProductSkuDO> getSkusByAlarmStock(); |
| 92 | 91 | ||
| 93 | } | 92 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
| 1 | package cn.iocoder.yudao.module.product.service.sku; | 1 | package cn.iocoder.yudao.module.product.service.sku; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.collection.CollUtil; | ||
| 4 | -import cn.hutool.core.collection.CollectionUtil; | ||
| 5 | import cn.hutool.core.util.ObjectUtil; | 3 | import cn.hutool.core.util.ObjectUtil; |
| 6 | -import cn.hutool.core.util.StrUtil; | ||
| 7 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 4 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 8 | -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 9 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO; | 5 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO; |
| 10 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; | 6 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; |
| 11 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; | 7 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; |
| @@ -17,18 +13,15 @@ import cn.iocoder.yudao.module.product.enums.ErrorCodeConstants; | @@ -17,18 +13,15 @@ import cn.iocoder.yudao.module.product.enums.ErrorCodeConstants; | ||
| 17 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuSpecTypeEnum; | 13 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuSpecTypeEnum; |
| 18 | import cn.iocoder.yudao.module.product.service.property.ProductPropertyService; | 14 | import cn.iocoder.yudao.module.product.service.property.ProductPropertyService; |
| 19 | import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; | 15 | import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; |
| 20 | -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 21 | import org.springframework.stereotype.Service; | 16 | import org.springframework.stereotype.Service; |
| 22 | import org.springframework.transaction.annotation.Transactional; | 17 | import org.springframework.transaction.annotation.Transactional; |
| 23 | import org.springframework.validation.annotation.Validated; | 18 | import org.springframework.validation.annotation.Validated; |
| 24 | 19 | ||
| 25 | import javax.annotation.Resource; | 20 | import javax.annotation.Resource; |
| 26 | import java.util.*; | 21 | import java.util.*; |
| 27 | -import java.util.function.Function; | ||
| 28 | import java.util.stream.Collectors; | 22 | import java.util.stream.Collectors; |
| 29 | 23 | ||
| 30 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 24 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 31 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | ||
| 32 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; | 25 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; |
| 33 | 26 | ||
| 34 | /** | 27 | /** |
| @@ -138,8 +131,8 @@ public class ProductSkuServiceImpl implements ProductSkuService { | @@ -138,8 +131,8 @@ public class ProductSkuServiceImpl implements ProductSkuService { | ||
| 138 | } | 131 | } |
| 139 | 132 | ||
| 140 | @Override | 133 | @Override |
| 141 | - public List<ProductSkuDO> getRemindSpuIds() { | ||
| 142 | - return productSkuMapper.selectRemindSpuIds(); | 134 | + public List<ProductSkuDO> getSkusByAlarmStock() { |
| 135 | + return productSkuMapper.selectListByAlarmStock(); | ||
| 143 | } | 136 | } |
| 144 | 137 | ||
| 145 | @Override | 138 | @Override |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| 1 | package cn.iocoder.yudao.module.product.service.spu; | 1 | package cn.iocoder.yudao.module.product.service.spu; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 6 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 6 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyViewRespVO; | 7 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyViewRespVO; |
| @@ -28,10 +29,7 @@ import org.springframework.transaction.annotation.Transactional; | @@ -28,10 +29,7 @@ import org.springframework.transaction.annotation.Transactional; | ||
| 28 | import org.springframework.validation.annotation.Validated; | 29 | import org.springframework.validation.annotation.Validated; |
| 29 | 30 | ||
| 30 | import javax.annotation.Resource; | 31 | import javax.annotation.Resource; |
| 31 | -import java.util.ArrayList; | ||
| 32 | -import java.util.Collection; | ||
| 33 | -import java.util.List; | ||
| 34 | -import java.util.Map; | 32 | +import java.util.*; |
| 35 | import java.util.stream.Collectors; | 33 | import java.util.stream.Collectors; |
| 36 | 34 | ||
| 37 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 35 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -181,18 +179,21 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -181,18 +179,21 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 181 | 179 | ||
| 182 | @Override | 180 | @Override |
| 183 | public PageResult<ProductSpuRespVO> getSpuPage(ProductSpuPageReqVO pageReqVO) { | 181 | public PageResult<ProductSpuRespVO> getSpuPage(ProductSpuPageReqVO pageReqVO) { |
| 184 | - List<Long> remindSpuIds = null; | ||
| 185 | - if (pageReqVO.getTabStatus() != null && pageReqVO.getTabStatus() == 2) { | ||
| 186 | - remindSpuIds = productSkuService.getRemindSpuIds().stream().map(ProductSkuDO::getSpuId).distinct().collect(Collectors.toList()); | ||
| 187 | - if (remindSpuIds.isEmpty()) { | ||
| 188 | - remindSpuIds.add(null); | 182 | + // 库存告警的 SPU 编号的集合 |
| 183 | + Set<Long> alarmStockSpuIds = null; | ||
| 184 | + if (Boolean.TRUE.equals(pageReqVO.getAlarmStock())) { | ||
| 185 | + alarmStockSpuIds = CollectionUtils.convertSet(productSkuService.getSkusByAlarmStock(), ProductSkuDO::getSpuId); | ||
| 186 | + if (CollUtil.isEmpty(alarmStockSpuIds)) { | ||
| 187 | + return PageResult.empty(); | ||
| 189 | } | 188 | } |
| 190 | } | 189 | } |
| 191 | - return ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(pageReqVO, remindSpuIds)); | 190 | + // 分页查询 |
| 191 | + return ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(pageReqVO, alarmStockSpuIds)); | ||
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | @Override | 194 | @Override |
| 195 | public PageResult<AppSpuPageRespVO> getSpuPage(AppSpuPageReqVO pageReqVO) { | 195 | public PageResult<AppSpuPageRespVO> getSpuPage(AppSpuPageReqVO pageReqVO) { |
| 196 | + // TODO 芋艿:貌似实现不太合理 | ||
| 196 | PageResult<ProductSpuDO> productSpuDOPageResult = productSpuMapper.selectPage(ProductSpuConvert.INSTANCE.convert(pageReqVO)); | 197 | PageResult<ProductSpuDO> productSpuDOPageResult = productSpuMapper.selectPage(ProductSpuConvert.INSTANCE.convert(pageReqVO)); |
| 197 | PageResult<AppSpuPageRespVO> pageResult = new PageResult<>(); | 198 | PageResult<AppSpuPageRespVO> pageResult = new PageResult<>(); |
| 198 | // TODO @芋艿 这里用convert如何解决 | 199 | // TODO @芋艿 这里用convert如何解决 |
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java
| @@ -208,6 +208,8 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { | @@ -208,6 +208,8 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { | ||
| 208 | Assertions.assertIterableEquals(createReqVO, spuList); | 208 | Assertions.assertIterableEquals(createReqVO, spuList); |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | + // TODO @luowenfeng:单测要分情况;类似你这个,可以分 2 个单测;一个是有预存预警的;一个是没库存预警的; | ||
| 212 | + // 然后,参考其它模块的 getPage 类型的方法的单测。 | ||
| 211 | @Test | 213 | @Test |
| 212 | void getSpuPage() { | 214 | void getSpuPage() { |
| 213 | // 准备参数 | 215 | // 准备参数 |
yudao-ui-admin/src/views/mall/product/spu/index.vue
| @@ -222,6 +222,7 @@ | @@ -222,6 +222,7 @@ | ||
| 222 | import {deleteSpu, getSpuPage,} from "@/api/mall/product/spu"; | 222 | import {deleteSpu, getSpuPage,} from "@/api/mall/product/spu"; |
| 223 | import {getProductCategoryList} from "@/api/mall/product/category"; | 223 | import {getProductCategoryList} from "@/api/mall/product/category"; |
| 224 | import {getBrandList} from "@/api/mall/product/brand"; | 224 | import {getBrandList} from "@/api/mall/product/brand"; |
| 225 | +import {ProductSpuStatusEnum} from "@/utils/constants"; | ||
| 225 | 226 | ||
| 226 | export default { | 227 | export default { |
| 227 | name: "Spu", | 228 | name: "Spu", |
| @@ -260,7 +261,6 @@ export default { | @@ -260,7 +261,6 @@ export default { | ||
| 260 | salesCountMax: null, | 261 | salesCountMax: null, |
| 261 | marketPriceMin: null, | 262 | marketPriceMin: null, |
| 262 | marketPriceMax: null, | 263 | marketPriceMax: null, |
| 263 | - tabStatus: null, | ||
| 264 | }, | 264 | }, |
| 265 | }; | 265 | }; |
| 266 | }, | 266 | }, |
| @@ -341,15 +341,17 @@ export default { | @@ -341,15 +341,17 @@ export default { | ||
| 341 | // 选中 tab | 341 | // 选中 tab |
| 342 | handleClick(val) { | 342 | handleClick(val) { |
| 343 | if (val.name === "all") { | 343 | if (val.name === "all") { |
| 344 | - this.queryParams.tabStatus = null; | 344 | + this.queryParams.status = undefined; |
| 345 | + this.queryParams.alarmStock = undefined; | ||
| 345 | } else if (val.name === "on") { | 346 | } else if (val.name === "on") { |
| 346 | - this.queryParams.tabStatus = 0; | 347 | + this.queryParams.status = ProductSpuStatusEnum.ENABLE.status; |
| 348 | + this.queryParams.alarmStock = undefined; | ||
| 347 | } else if (val.name === "off") { | 349 | } else if (val.name === "off") { |
| 348 | - this.queryParams.tabStatus = 1; | 350 | + this.queryParams.status = ProductSpuStatusEnum.DISABLE.status; |
| 351 | + this.queryParams.alarmStock = undefined; | ||
| 349 | } else if (val.name === "remind") { | 352 | } else if (val.name === "remind") { |
| 350 | - this.queryParams.tabStatus = 2; | ||
| 351 | - } else { | ||
| 352 | - this.queryParams.tabStatus = null; | 353 | + this.queryParams.status = undefined; |
| 354 | + this.queryParams.alarmStock = true; | ||
| 353 | } | 355 | } |
| 354 | this.getList(); | 356 | this.getList(); |
| 355 | } | 357 | } |