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