<?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.third.sms.mapper.TSmsRecordMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.third.sms.TSmsRecord">
        <id column="PK_ID" property="pkId"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_SMS_TEMPLATE" property="pkSmsTemplate"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="PHONE" property="phone"/>
        <result column="CONTENT" property="content"/>
        <result column="SEND_SCOPE" property="sendScope"/>
        <result column="SEND_TYPE" property="sendType"/>
        <result column="SEND_STATUS" property="sendStatus"/>
        <result column="SEND_RESULT" property="sendResult"/>
        <result column="SEND_TIME" property="sendTime"/>
    </resultMap>

    <!-- 查询列表 -->
    <select id="queryList" resultType="com.hzs.common.domain.third.sms.ext.TSmsRecordExt">
        select tsr.*, tst.template_code, tst.template_name
        from T_SMS_RECORD tsr
        inner join T_SMS_TEMPLATE tst
        on tst.pk_id = tsr.pk_sms_template
        where tsr.del_flag = 0
        and tst.del_flag = 0
        and tsr.pk_country = #{pkCountry}
        <if test="param.phone != null and param.phone != ''">
            and tsr.phone = #{param.phone}
        </if>
        <if test="param.templateName != null and param.templateName != ''">
            and tst.template_name like #{param.templateName} || '%'
        </if>
        <if test="param.sendType != null">
            and tsr.send_type = #{param.sendType}
        </if>
        <if test="param.sendStatus != null">
            and tsr.send_status = #{param.sendStatus}
        </if>
        <if test="param.modifiedTime != null">
            and tsr.modified_time >= #{param.modifiedTime[0]}
            and #{param.modifiedTime[1]} >= tsr.modified_time
        </if>
        order by tsr.CREATION_TIME desc
    </select>

    <!-- 批量插入 -->
    <insert id="insertBatch">
        INSERT ALL
        <foreach collection="list" item="item" separator=" ">
            into T_SMS_RECORD (
            PK_SMS_TEMPLATE, PK_MEMBER, PHONE, CONTENT,
            SEND_SCOPE, SEND_TYPE, SEND_STATUS, SEND_RESULT,
            SEND_TIME, PK_COUNTRY, PK_CREATOR
            )
            values (
            #{item.pkSmsTemplate}, #{item.pkMember, jdbcType=NUMERIC}, #{item.phone}, #{item.content},
            #{item.sendScope}, #{item.sendType}, #{item.sendStatus}, #{item.sendResult},
            #{item.sendTime}, #{item.pkCountry}, #{item.pkCreator}
            )
        </foreach>
        SELECT 1 FROM dual
    </insert>

</mapper>
