<?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.hzs.sale.wares.mapper.BdWaresMemberLimitMapper">

    <!-- 批量更新会员限购数据 -->
    <update id="updateWaresMemberLimitBatch">
        merge into BD_WARES_MEMBER_LIMIT bwml
        using (
        <foreach collection="limitList" item="items" separator=" union ">
            select #{items.pkMember} pk_member,
            #{items.pkWares} pk_wares,
            #{items.limitType} limit_type,
            #{items.quantity} quantity,
            #{items.limitDate} limit_date
            from dual
        </foreach>
        ) tmp
        on (bwml.PK_MEMBER = tmp.pk_member and bwml.PK_WARES = tmp.pk_wares and bwml.limit_date = tmp.limit_date and bwml.del_flag = 0)
        when matched then
        update set
            bwml.quantity = bwml.quantity + tmp.quantity,
            bwml.modified_time = sysdate
        WHEN NOT MATCHED THEN
        insert (
        pk_id,
        pk_member,
        pk_wares,
        limit_type,
        quantity,
        pk_creator,
        limit_date)
        values (
        bd_wares_member_limit_seq.nextval,
        tmp.pk_member,
        tmp.pk_wares,
        tmp.limit_type,
        tmp.quantity,
        tmp.pk_member,
        tmp.limit_date)
    </update>

</mapper>
