<?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="com.yami.shop.coupon.comment.dao.CouponUseRecordMapper">

    <resultMap id="couponUseMap" type="com.yami.shop.coupon.comment.model.CouponUseRecord">
        <id property="couponUseRecordId" column="coupon_use_record_id"/>
        <!--<result property="couponId" column="coupon_id"/>-->
        <result property="couponUserId" column="coupon_user_id"/>
        <result property="orderNumber" column="order_number"/>
        <result property="userId" column="user_id"/>
        <result property="amount" column="amount"/>
        <result property="useTime" column="use_time"/>
    </resultMap>
    <insert id="addCouponUseRecode">
        INSERT INTO tz_coupon_use_record (coupon_user_id,user_id,order_number,amount,use_time,`status`) VALUES
        <foreach collection="couponUseRecordsList" item="couponUseRecord" separator=",">
            (#{couponUseRecord.couponUserId},#{couponUseRecord.userId},#{couponUseRecord.orderNumber},#{couponUseRecord.amount},#{couponUseRecord.useTime},#{couponUseRecord.status})
        </foreach>
    </insert>

    <update id="batchUpdateRecordByStatusAndOrderNums">
        UPDATE tz_coupon_use_record SET `status` = #{status}
        <where>
            order_number IN
            <foreach collection="orderNumberList" item="orderNum" open="(" close=")" separator=",">
                #{orderNum}
            </foreach>
        </where>

    </update>
</mapper>
