| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.ruoyi.system.model.TBigGiftPackage; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.ruoyi.system.model.TBigGiftPackage; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.apache.ibatis.annotations.Update; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | public interface TBigGiftPackageMapper extends BaseMapper<TBigGiftPackage> { |
| | | |
| | | /** |
| | | * 使用乐观锁扣减库存 |
| | | * |
| | | * @param id 商品ID |
| | | * @param quantity 扣减数量 |
| | | * @return 更新行数(0表示库存不足或并发冲突) |
| | | */ |
| | | @Update("UPDATE t_big_gift_package SET inventory = inventory - #{quantity} WHERE id = #{id} AND inventory >= #{quantity} AND status = 1") |
| | | int deductInventory(@Param("id") Integer id, @Param("quantity") Integer quantity); |
| | | |
| | | } |