<?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.backendsys.mapper.System.SysMobileSMSHistoryMapper">

    <sql id="includeMobileSMSHistory">
        id,
        COALESCE(origin, '') origin,
        phone,
        COALESCE(sms_code, '') sms_code,
        COALESCE(ip, '') ip,
        COALESCE(ua, '') ua,
        create_time
    </sql>

    <resultMap id="resultMapMobileSMSHistoryList" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="origin" column="origin" />
        <result property="phone" column="phone" />
        <result property="sms_code" column="sms_code" />
        <result property="ip" column="ip" />
        <result property="ua" column="ua" />
        <result property="create_time" column="create_time" />
    </resultMap>

    <!-- 查询 列表 -->
    <select id="queryMobileSMSHistoryList" resultMap="resultMapMobileSMSHistoryList">
        SELECT <include refid="includeMobileSMSHistory" />
        FROM sys_mobile_sms_history
        <where>
            <if test="origin != null and origin != ''">
                AND origin = #{origin}
            </if>
            <if test="phone != null and phone != ''">
                AND phone = #{phone}
            </if>
            <if test="ip != null and ip != ''">
                AND ip = #{ip}
            </if>
            <if test="create_time_begin != null and create_time_begin != '' and create_time_end != null and create_time_end != ''">
                AND create_time BETWEEN #{create_time_begin} AND #{create_time_end}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>

    <!-- 创建 -->
    <insert id="insertMobileSMSHistory" parameterType="com.backendsys.entity.System.SysSMSDTO"
        useGeneratedKeys="true" keyProperty="id">
        INSERT INTO sys_mobile_sms_history (
            phone
            <if test="origin != null and origin != ''">, origin</if>
            <if test="sms_code != null and sms_code != ''">, sms_code</if>
            <if test="ip != null and ip != ''">, ip</if>
            <if test="ua != null and ua != ''">, ua</if>
        ) VALUES (
            #{phone}
            <if test="origin != null and origin != ''">, #{origin}</if>
            <if test="sms_code != null and sms_code != ''">, #{sms_code}</if>
            <if test="ip != null and ip != ''">, #{ip}</if>
            <if test="ua != null and ua != ''">, #{ua}</if>
        )
    </insert>

</mapper>