diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java index f6b966a41..8d1bbee5f 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java @@ -1,12 +1,11 @@ package cn.iocoder.yudao.module.product.controller.admin.spu.vo; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; import cn.iocoder.yudao.framework.common.pojo.PageParam; -import org.springframework.format.annotation.DateTimeFormat; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; @ApiModel("管理后台 - 商品 SPU 分页 Request VO") @Data @@ -26,7 +25,7 @@ public class ProductSpuPageReqVO extends PageParam { @ApiModelProperty(value = "商品品牌编号", example = "1") private Long brandId; - @ApiModelProperty(value = "上下架状态", example = "1", notes = "参见 CommonStatusEnum 枚举值") + @ApiModelProperty(value = "上下架状态", example = "1", notes = "参见 ProductSpuStatusEnum 枚举值") private Integer status; @ApiModelProperty(value = "销量最小值", example = "1") @@ -41,8 +40,7 @@ public class ProductSpuPageReqVO extends PageParam { @ApiModelProperty(value = "市场价最大值", example = "1024") private Integer marketPriceMax; - // TODO @luowenfeng: 这个可以改成前端基于 tab, 传递不同的条件么? - @ApiModelProperty(value = "tab 状态 null 全部, 0:销售中(上架) 1:仓库中(下架) 2:预警中", example = "1") - private Integer tabStatus; + @ApiModelProperty(value = "是否库存告警", example = "true") + private Boolean alarmStock; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java index 6698007c6..dfc8fd4ff 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java +++ b/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 { } } - // TODO @luowenfeng: selectListByRemind,虽然不是很好,但是感觉会更清晰一些 - default List selectRemindSpuIds(){ + default List selectListByAlarmStock(){ return selectList(new QueryWrapper().apply("stock <= warn_stock")); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java index dc39133d5..eea12f62f 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java +++ b/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 import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import org.apache.ibatis.annotations.Mapper; -import java.util.List; +import java.util.Set; /** * 商品spu Mapper @@ -29,8 +29,8 @@ public interface ProductSpuMapper extends BaseMapperX { .orderByDesc(ProductSpuDO::getSort)); } - default PageResult selectPage(ProductSpuPageReqVO reqVO, List spuIds) { - LambdaQueryWrapperX productSpuDOLambdaQueryWrapperX = new LambdaQueryWrapperX() + default PageResult selectPage(ProductSpuPageReqVO reqVO, Set alarmStockSpuIds) { + return selectPage(reqVO, new LambdaQueryWrapperX() .likeIfPresent(ProductSpuDO::getName, reqVO.getName()) .eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId()) .eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus()) @@ -38,16 +38,9 @@ public interface ProductSpuMapper extends BaseMapperX { .geIfPresent(ProductSpuDO::getSalesCount, reqVO.getSalesCountMin()) .leIfPresent(ProductSpuDO::getMarketPrice, reqVO.getMarketPriceMax()) .geIfPresent(ProductSpuDO::getMarketPrice, reqVO.getMarketPriceMin()) - .orderByDesc(ProductSpuDO::getSort); - // TODO @芋艿: 需要优化下这里的代码 - if(reqVO.getTabStatus()!= null && reqVO.getTabStatus() == 2){ - productSpuDOLambdaQueryWrapperX.inIfPresent(ProductSpuDO::getId, spuIds); - }else{ - productSpuDOLambdaQueryWrapperX.eqIfPresent(ProductSpuDO::getStatus, reqVO.getTabStatus()); - } - - return selectPage(reqVO, productSpuDOLambdaQueryWrapperX); + .inIfPresent(ProductSpuDO::getId, alarmStockSpuIds) // 库存告警 + .eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus()) + .orderByDesc(ProductSpuDO::getSort)); } - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java index 9da746427..acde66a4a 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java +++ b/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; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; -import javax.validation.Valid; import java.util.Collection; import java.util.List; @@ -84,10 +83,10 @@ public interface ProductSkuService { void deleteSkuBySpuId(Long spuId); /** - * 获得商品预警中的 SPU 集合 + * 获得库存预警的 SKU 数组 * - * @return 商品spuId集合 + * @return SKU 数组 */ - List getRemindSpuIds(); + List getSkusByAlarmStock(); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java index cd9b68bff..952fbeb74 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java @@ -1,11 +1,7 @@ package cn.iocoder.yudao.module.product.service.sku; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; @@ -17,18 +13,15 @@ import cn.iocoder.yudao.module.product.enums.ErrorCodeConstants; import cn.iocoder.yudao.module.product.enums.spu.ProductSpuSpecTypeEnum; import cn.iocoder.yudao.module.product.service.property.ProductPropertyService; import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.*; -import java.util.function.Function; import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; /** @@ -138,8 +131,8 @@ public class ProductSkuServiceImpl implements ProductSkuService { } @Override - public List getRemindSpuIds() { - return productSkuMapper.selectRemindSpuIds(); + public List getSkusByAlarmStock() { + return productSkuMapper.selectListByAlarmStock(); } @Override diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index 6cdebdee4..dafa26428 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.product.service.spu; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyViewRespVO; @@ -28,10 +29,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -181,18 +179,21 @@ public class ProductSpuServiceImpl implements ProductSpuService { @Override public PageResult getSpuPage(ProductSpuPageReqVO pageReqVO) { - List remindSpuIds = null; - if (pageReqVO.getTabStatus() != null && pageReqVO.getTabStatus() == 2) { - remindSpuIds = productSkuService.getRemindSpuIds().stream().map(ProductSkuDO::getSpuId).distinct().collect(Collectors.toList()); - if (remindSpuIds.isEmpty()) { - remindSpuIds.add(null); + // 库存告警的 SPU 编号的集合 + Set alarmStockSpuIds = null; + if (Boolean.TRUE.equals(pageReqVO.getAlarmStock())) { + alarmStockSpuIds = CollectionUtils.convertSet(productSkuService.getSkusByAlarmStock(), ProductSkuDO::getSpuId); + if (CollUtil.isEmpty(alarmStockSpuIds)) { + return PageResult.empty(); } } - return ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(pageReqVO, remindSpuIds)); + // 分页查询 + return ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(pageReqVO, alarmStockSpuIds)); } @Override public PageResult getSpuPage(AppSpuPageReqVO pageReqVO) { + // TODO 芋艿:貌似实现不太合理 PageResult productSpuDOPageResult = productSpuMapper.selectPage(ProductSpuConvert.INSTANCE.convert(pageReqVO)); PageResult pageResult = new PageResult<>(); // TODO @芋艿 这里用convert如何解决 diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java index 0bddf59ce..a254f636d 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java +++ b/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 { Assertions.assertIterableEquals(createReqVO, spuList); } + // TODO @luowenfeng:单测要分情况;类似你这个,可以分 2 个单测;一个是有预存预警的;一个是没库存预警的; + // 然后,参考其它模块的 getPage 类型的方法的单测。 @Test void getSpuPage() { // 准备参数 diff --git a/yudao-ui-admin/src/views/mall/product/spu/index.vue b/yudao-ui-admin/src/views/mall/product/spu/index.vue index 68c673f00..3061c8417 100644 --- a/yudao-ui-admin/src/views/mall/product/spu/index.vue +++ b/yudao-ui-admin/src/views/mall/product/spu/index.vue @@ -222,6 +222,7 @@ import {deleteSpu, getSpuPage,} from "@/api/mall/product/spu"; import {getProductCategoryList} from "@/api/mall/product/category"; import {getBrandList} from "@/api/mall/product/brand"; +import {ProductSpuStatusEnum} from "@/utils/constants"; export default { name: "Spu", @@ -260,7 +261,6 @@ export default { salesCountMax: null, marketPriceMin: null, marketPriceMax: null, - tabStatus: null, }, }; }, @@ -341,15 +341,17 @@ export default { // 选中 tab handleClick(val) { if (val.name === "all") { - this.queryParams.tabStatus = null; + this.queryParams.status = undefined; + this.queryParams.alarmStock = undefined; } else if (val.name === "on") { - this.queryParams.tabStatus = 0; + this.queryParams.status = ProductSpuStatusEnum.ENABLE.status; + this.queryParams.alarmStock = undefined; } else if (val.name === "off") { - this.queryParams.tabStatus = 1; + this.queryParams.status = ProductSpuStatusEnum.DISABLE.status; + this.queryParams.alarmStock = undefined; } else if (val.name === "remind") { - this.queryParams.tabStatus = 2; - } else { - this.queryParams.tabStatus = null; + this.queryParams.status = undefined; + this.queryParams.alarmStock = true; } this.getList(); }