<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.mall.promotion.mapper.MallSeckillMapper">

    <resultMap type="org.dromara.mall.promotion.domain.MallSeckill" id="MallSeckillResult">
        <id property="id" column="id"/>
        <result property="promotionId" column="promotion_id"/>
        <result property="skuId" column="sku_id"/>
        <result property="seckillPrice" column="seckill_price"/>
        <result property="seckillStock" column="seckill_stock"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="status" column="status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <resultMap type="org.dromara.mall.promotion.domain.vo.MallSeckillVo" id="MallSeckillVoResult">
        <id property="id" column="id"/>
        <result property="promotionId" column="promotion_id"/>
        <result property="skuId" column="sku_id"/>
        <result property="seckillPrice" column="seckill_price"/>
        <result property="seckillStock" column="seckill_stock"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <!-- 扣减秒杀库存 -->
    <update id="reduceStock">
        UPDATE mall_seckill
        SET seckill_stock = seckill_stock - #{quantity}
        WHERE id = #{id}
          AND seckill_stock >= #{quantity}
    </update>

    <!-- 恢复秒杀库存 -->
    <update id="restoreStock">
        UPDATE mall_seckill
        SET seckill_stock = seckill_stock + #{quantity}
        WHERE id = #{id}
    </update>

</mapper>
