feat(goods): 添加商品数量统计接口并优化商品查询
- 新增 getGoodsNumVO 接口,用于获取不同状态的商品数量统计 - 在 GoodsSearchParams 中添加 goodsStatus 字段,用于筛选商品状态 - 修改 queryByParams 方法,支持按商品状态进行筛选 - 新增 GoodsNumVO 类,用于返回商品数量统计结果 -优化商品查询性能,通过聚合查询一次性获取所有状态的商品数量
This commit is contained in:
@@ -70,6 +70,9 @@ public class GoodsSearchParams extends PageVO {
|
||||
@ApiModelProperty(value = "审核状态")
|
||||
private String authFlag;
|
||||
|
||||
@ApiModelProperty(value = "商品状态")
|
||||
private String goodsStatus;
|
||||
|
||||
@ApiModelProperty(value = "库存数量")
|
||||
private Integer leQuantity;
|
||||
|
||||
@@ -120,6 +123,23 @@ public class GoodsSearchParams extends PageVO {
|
||||
if (CharSequenceUtil.isNotEmpty(storeCategoryPath)) {
|
||||
queryWrapper.like("store_category_path", storeCategoryPath);
|
||||
}
|
||||
if (CharSequenceUtil.isNotEmpty(goodsStatus)) {
|
||||
if(goodsStatus.equals(GoodsStatusEnum.UPPER.name())){
|
||||
//审核通过+已上架
|
||||
queryWrapper.eq("auth_flag", GoodsAuthEnum.PASS.name());
|
||||
queryWrapper.eq("market_enable", GoodsStatusEnum.UPPER.name());
|
||||
}else if(goodsStatus.equals(GoodsStatusEnum.DOWN.name())){
|
||||
//审核通过+未上架
|
||||
queryWrapper.eq("auth_flag", GoodsAuthEnum.PASS.name());
|
||||
queryWrapper.eq("market_enable", GoodsStatusEnum.DOWN.name());
|
||||
}else if(goodsStatus.equals(GoodsAuthEnum.TOBEAUDITED.name())){
|
||||
//待审核
|
||||
queryWrapper.eq("auth_flag", GoodsAuthEnum.TOBEAUDITED.name());
|
||||
}else if(goodsStatus.equals(GoodsAuthEnum.REFUSE.name())){
|
||||
//审核拒绝
|
||||
queryWrapper.eq("auth_flag", GoodsAuthEnum.REFUSE.name());
|
||||
}
|
||||
}
|
||||
if (selfOperated != null) {
|
||||
queryWrapper.eq("self_operated", selfOperated);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.lili.modules.goods.entity.vos;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GoodsNumVO {
|
||||
|
||||
@ApiModelProperty(value = "出售中的商品数量")
|
||||
private Integer upperGoodsNum;
|
||||
@ApiModelProperty(value = "仓库中的商品数量")
|
||||
private Integer downGoodsNum;
|
||||
@ApiModelProperty(value = "待审核商品数量")
|
||||
private Integer auditGoodsNum;
|
||||
@ApiModelProperty(value = "审核未通过数量")
|
||||
private Integer refuseGoodsNum;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import cn.lili.modules.goods.entity.dto.GoodsOperationDTO;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
|
||||
import cn.lili.modules.goods.entity.vos.GoodsNumVO;
|
||||
import cn.lili.modules.goods.entity.vos.GoodsVO;
|
||||
import cn.lili.modules.store.entity.dos.Store;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -83,6 +84,14 @@ public interface GoodsService extends IService<Goods> {
|
||||
*/
|
||||
IPage<Goods> queryByParams(GoodsSearchParams goodsSearchParams);
|
||||
|
||||
/**
|
||||
* 获取商品数量
|
||||
*
|
||||
* @param goodsSearchParams 查询参数
|
||||
* @return 商品数量
|
||||
*/
|
||||
GoodsNumVO getGoodsNumVO(GoodsSearchParams goodsSearchParams);
|
||||
|
||||
|
||||
/**
|
||||
* 商品查询
|
||||
@@ -191,6 +200,11 @@ public interface GoodsService extends IService<Goods> {
|
||||
*/
|
||||
void categoryGoodsName(String categoryId);
|
||||
|
||||
|
||||
/**
|
||||
* 添加商品评价数量
|
||||
*
|
||||
* @param commentNum 评价数量
|
||||
* @param goodsId 商品ID
|
||||
*/
|
||||
void addGoodsCommentNum(Integer commentNum, String goodsId);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
|
||||
import cn.lili.modules.goods.entity.vos.GoodsNumVO;
|
||||
import cn.lili.modules.goods.entity.vos.GoodsSkuVO;
|
||||
import cn.lili.modules.goods.entity.vos.GoodsVO;
|
||||
import cn.lili.modules.goods.mapper.GoodsMapper;
|
||||
@@ -281,6 +282,40 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
||||
return this.page(PageUtil.initPage(goodsSearchParams), goodsSearchParams.queryWrapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GoodsNumVO getGoodsNumVO(GoodsSearchParams goodsSearchParams) {
|
||||
GoodsNumVO goodsNumVO = new GoodsNumVO();
|
||||
|
||||
// 获取基础查询条件
|
||||
QueryWrapper<Goods> baseWrapper = goodsSearchParams.queryWrapper();
|
||||
|
||||
// 使用聚合查询一次性获取所有状态的商品数量
|
||||
List<Map<String, Object>> results = this.baseMapper.selectMaps(
|
||||
baseWrapper.select(
|
||||
"COUNT(CASE WHEN auth_flag = 'PASS' AND market_enable = 'UPPER' THEN 1 END) as upperGoodsNum",
|
||||
"COUNT(CASE WHEN auth_flag = 'PASS' AND market_enable = 'DOWN' THEN 1 END) as downGoodsNum",
|
||||
"COUNT(CASE WHEN auth_flag = 'TOBEAUDITED' THEN 1 END) as auditGoodsNum",
|
||||
"COUNT(CASE WHEN auth_flag = 'REFUSE' THEN 1 END) as refuseGoodsNum"
|
||||
)
|
||||
);
|
||||
|
||||
if (!results.isEmpty()) {
|
||||
Map<String, Object> result = results.get(0);
|
||||
goodsNumVO.setUpperGoodsNum(((Number) result.get("upperGoodsNum")).intValue());
|
||||
goodsNumVO.setDownGoodsNum(((Number) result.get("downGoodsNum")).intValue());
|
||||
goodsNumVO.setAuditGoodsNum(((Number) result.get("auditGoodsNum")).intValue());
|
||||
goodsNumVO.setRefuseGoodsNum(((Number) result.get("refuseGoodsNum")).intValue());
|
||||
} else {
|
||||
// 如果没有结果,设置默认值为0
|
||||
goodsNumVO.setUpperGoodsNum(0);
|
||||
goodsNumVO.setDownGoodsNum(0);
|
||||
goodsNumVO.setAuditGoodsNum(0);
|
||||
goodsNumVO.setRefuseGoodsNum(0);
|
||||
}
|
||||
|
||||
return goodsNumVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品查询
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user