商城系统开发从0到1(商品库存单独缓存)

本文介绍了商城系统从0开始的开发过程,重点探讨了商品库存的管理。采用Redis进行库存的单独缓存,利用其自增自减的原子性操作确保库存的正确性。当库存减少至0时,系统会提示前端库存不足,并在后续操作中恢复库存。
摘要由CSDN通过智能技术生成

商城系统开发从0到1(商品库存单独缓存)

Service层

package com.ems.emall.common.service;

import com.ems.emall.basic.dto.mall.CheckSubmitOrderDto;
import com.ems.emall.basic.dto.mall.ProductCacheDto;
import com.ems.emall.basic.dto.product.ProductSkuDetailDto;
import com.ems.emall.common.ResultMap;

import java.util.List;

/**
 * 对商品库存
 * 商品限购数量
 * 用户已购买的商品数量
 * 使用缓存统一管理
 *
 */
public interface IProductCacheService {



    /**减库存
     * @param productCacheDto 传入productId,skuId,stock
     * @return true扣减成功,false扣减失败
     */
    boolean subStock(ProductCacheDto productCacheDto);

    /**
     * 用户取消订单或订单超时关闭调用
     * 增加库存
     * @param productCacheDtoList 传入productId,productCount,skuId
     * @return
     */
    boolean addStock(List<ProductCacheDto> productCacheDtoList);

    /**
     * 获取库存
     * 获取当前商品剩余库存
     * @param productCacheDto 传入productId,skuId
     * @return
     */
    Long getStock(ProductCacheDto productCacheDto);


    /**
     * 更新库存
     * 更新当前商品库存
     * @param productCacheDto 传入productId,stock,skuId
     * @return
     */
    boolean setStock(ProductCacheDto productCacheDto);

    /**
     * 初始化数据库的库存到redis
     * 更新当前商品库存和商品限购数量
     * @param productCacheDtoList 传入productId,stock,limitCount,skuId
     * @return
     */
    boolean initStockLimitCount(List<ProductCacheDto> productCacheDtoList);


    /**
     * 获取当前商品限购数量
     * @param productCacheDto   传入productId,skuId
     * @return
     */
    Long getLimitCount(ProductCacheDto productCacheDto);


    /**
     * 更新商品限购数量
     * @param productCacheDto 传入productId,limitCount,skuId
     * @return
     */
    boolean setLimitCount(ProductCacheDto productCacheDto);

    /**
     * 获取当前商品的上下架状态
     * @param productCacheDto  传入productId
     * @return
     */
    Integer getPublishStatus(ProductCacheDto productCacheDto);


    /**
     * 更新商品的上下架状态
     * @param productCacheDto 传入productId,publishStatus
     * @return
     */
    boolean setPublishStatus(ProductCacheDto productCacheDto);



    /**
     * 提交订单使用和结算页使用
     * 更新用户购买的商品数量
     * @param  type (0:结算页校验  1:提交订单)
     * @param productCacheDtoList 传入userId,productId,productCount,skuId
     * @return
     *  [{
     *       "productId" : "11123457856444",
     *       "code" : "100320"
     * }]
     *
     * 返回SUCCESS,代表全部商品的库存和限购数量校验正常
     */
    ResultMap<List<CheckSubmitOrderDto>> addProductCount(List<ProductCacheDto> productCacheDtoList, Integer type);

    /**
     * 在取消订单和退款成功时返还用户的商品限购数量
     * @param productCacheDtoList 传入userId,productId,productCount,skuId
     * @return
     */
    boolean subProductCount(List<ProductCacheDto> productCacheDtoList);

    /**
     * 提交订单使用和结算页使用
     * 更新用户购买的商品数量
     * @param  type (0:结算页校验  1:提交订单)
     * @param productCacheDto 传入userId,productId,productCount,skuId
     * @return
     *  [{
     *       "productId" : "11123457856444",
     *       "code" : "100320"
     * }]
     *
     * 返回SUCCESS,代表全部商品的库存和限购数量校验正常
     */
    ResultMap<List<CheckSubmitOrderDto>> addProductCount(ProductCacheDto productCacheDto, Integer type);

    /**
     * 在取消订单和退款成功时返还用户的商品限购数量
     * @param productCacheDto 传入userId,productId,productCount,skuId
     * @return
     */
    boolean subProductCount(ProductCacheDto productCacheDto);


    /**
     * 获取用户已购买的商品数量
     * @param productCacheDto 传入userId,productId,skuId
     * @return
     */
    Long getProductCount(ProductCacheDto productCacheDto);

    /**
     * 获取用户真实限购数量
     * @param productCacheDto 传入userId,productId,skuId
     * @return
     */
    Long getRealLimitCount(ProductCacheDto productCacheDto);

    /**
     * 获取该商品下所有规格的总库存
     * @param productCacheDto 传入productId
     * @return
     */
    Long getAllStock(ProductCacheDto productCacheDto);

    /**
     * 删除库存,当修改商品的时候规格类型修改的话需要删除原来的库存,不然统计总库存不正确
     * @param productCacheDto 传入productId
     * @return
     */
    boolean deleteStock(ProductCacheDto productCacheDto);

    /**
     * 规格修改的时候,删除已经被删掉的sku
     * @param productCacheDto 传入productId,skuId
     * @return
     */
    boolean deleteSkuStockLimitCount(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值