<?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.AcPickLogMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.activity.pick.AcPickLog">
        <id column="PK_ID" property="pkId"/>
        <result column="PK_PICK" property="pkPick"/>
        <result column="PK_USER" property="pkUser"/>
        <result column="QUANTITY" property="quantity"/>
        <result column="OPERATOR_TIME" property="operatorTime"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
    </resultMap>

    <!-- 查询列表 -->
    <select id="queryList" resultType="com.hzs.common.domain.activity.pick.ext.AcPickLogExt">
        select apl.*, cm.member_code, ap.pick_type, su.nick_name
        from AC_PICK_LOG apl
        inner join AC_PICK ap
        on ap.pk_id = apl.pk_pick
        inner join CU_MEMBER cm
        on cm.pk_id = ap.pk_member
        inner join sys_user su
        on su.user_id apl.pk_user
        where apl.pk_country = #{pkCountry}
        <if test="param.memberCode != null and param.memberCode != ''">
            and cm.member_code like #{param.memberCode} || '%'
        </if>
        <if test="param.pickType != null">
            and ap.pick_type = #{param.pickType}
        </if>
        <if test="param.creationTime != null">
            and apl.operator_time >= #{param.creationTime[0]}
            and #{param.creationTime[1]} >= apl.operator_time
        </if>
    </select>

    <!-- 批量插入 -->
    <insert id="insertBatch">
        insert into AC_PICK_LOG (PK_ID, PK_PICK, PK_USER, QUANTITY, PK_COUNTRY)
        select AC_PICK_LOG_SEQ.NEXTVAL, t.*
        from (
        <foreach collection="logList" item="item" separator=" union all ">
            select #{item.pkPick} as PK_PICK, #{item.pkUser} as PK_USER, #{item.quantity} as QUANTITY, #{item.pkCountry} as PK_COUNTRY
            from dual
        </foreach>
        ) t
    </insert>

</mapper>
