|
@@ -3,7 +3,12 @@ package com.zxyj.mapper;
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
import com.zxyj.entity.Product;
|
|
import com.zxyj.entity.Product;
|
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
|
|
|
+import org.apache.ibatis.annotations.Param;
|
|
|
|
|
+import org.apache.ibatis.annotations.Update;
|
|
|
|
|
|
|
|
@Mapper
|
|
@Mapper
|
|
|
public interface ProductMapper extends BaseMapper<Product> {
|
|
public interface ProductMapper extends BaseMapper<Product> {
|
|
|
|
|
+
|
|
|
|
|
+ @Update("UPDATE products SET stock = stock - #{quantity}, sales_count = sales_count + #{quantity}, updated_at = NOW() WHERE id = #{productId} AND stock >= #{quantity}")
|
|
|
|
|
+ int decreaseStockAtomic(@Param("productId") Long productId, @Param("quantity") Integer quantity);
|
|
|
}
|
|
}
|