<?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.activity.pick.mapper.AcRetailPickMapper">

    <!-- 更新提货数量 -->
    <update id="updatePickQuantity">
        update ac_retail_pick arp
        set arp.usable_quantity = arp.usable_quantity - #{quantity},
        arp.used_quantity = arp.used_quantity + #{quantity},
        arp.pk_modified = #{pkModified},
        arp.modified_time = sysdate
        where arp.del_flag = 0
        and arp.pk_id = #{pkId}
        <if test="pkMember != null">
            and arp.pk_member = #{pkMember}
        </if>
        and arp.usable_quantity - #{quantity} >= 0
        and arp.used_quantity + #{quantity} >= 0
    </update>

    <!-- 列表数据 -->
    <select id="listData" resultType="com.hzs.common.domain.activity.pick.ext.AcRetailPickExt">
        select arp.*, cm.member_code, cm.member_name
        from ac_retail_pick arp
        left join cu_member cm
        on cm.pk_id = arp.pk_member
        where arp.del_flag = 0
        and arp.pk_country = #{param.pkCountry}
        and arp.system_type = #{param.systemType}
        <if test="param.memberCode != null and param.memberCode != ''">
            and cm.member_code = #{param.memberCode}
        </if>
        order by arp.creation_time desc
    </select>

</mapper>
