package cn.ysk.cashier.mybatis.mapper;

import cn.ysk.cashier.pojo.product.TbProductSku;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


public interface TbProducSkutMapper extends BaseMapper<TbProductSku> {


    @Select("select * from tb_product_sku where id=#{id} and product_id=#{productId}")
    TbProductSku selectByProIdAndId(@Param("id") Integer id, @Param("productId") Integer productId);

    @Update("update tb_product_sku set stock_number=#{stocktakinNum} where id=#{id} and stock_number=#{stockNumber}")
    Integer updateStock(@Param("id") Integer id,@Param("stockNumber") Double stockNumber,@Param("stocktakinNum") Integer stocktakinNum);

    @Update("update tb_product_sku set stock_number=stock_number+#{addNum} WHERE id=#{skuId}")
    int incrStock(@Param("skuId") Integer skuId, @Param("addNum") Integer addNum);

    @Update("update tb_product_sku set real_sales_number=real_sales_number+#{num} WHERE id=#{skuId}")
    int incrRealSalesNumber(@Param("skuId") Integer skuId, @Param("num") Integer num);

    @Update("update tb_product_sku set stock_number=stock_number-#{num} WHERE id=#{id} and stock_number-#{num} >= 0")
    int decrStock(String id, int num);

    @Update("update tb_product_sku set stock_number=stock_number-#{num} WHERE id=#{id} ")
    int decrStockUnCheck(String id, int num);
}
