<?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="cn.pluss.platform.mapper.PhoneValidateCodeMapper">

    <insert id="savePhoneValidateCode" parameterType="cn.pluss.platform.entity.PhoneValidateCode">
        	insert into tb_pluss_phone_validate_code(phone,code,sendDt,status,remark)VALUES(#{phone},#{code},#{sendDt},#{status},#{remark})
    </insert>

    <insert id="savePhoneValidateCodeBatch">
        insert into tb_pluss_phone_validate_code(phone,code,sendDt,status,remark) VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (#{phone},#{code},#{sendDt},#{status},#{remark} )
        </foreach>
    </insert>

    <select id="queryPhoneValidateCode" parameterType="cn.pluss.platform.entity.PhoneValidateCode"
            resultType="cn.pluss.platform.entity.PhoneValidateCode">
        SELECT * from tb_pluss_phone_validate_code
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="phone != null and phone != ''">
                and phone = #{phone}
            </if>
            <if test="code != null and code != ''">
                and code = #{code}
            </if>
            <if test="sendDt != null">
                and sendDt = #{sendDt}
            </if>
            <if test="status != null and status != ''">
                and status = #{status}
            </if>
            <if test="remark != null and remark != ''">
                and remark = #{remark}
            </if>
            <if test="limitTime != null">
                and sendDt >= DATE_SUB(NOW(),INTERVAL ${limitTime / 1000} SECOND)
            </if>
        </where>
        ORDER BY sendDt DESC
        LIMIT 0, 1
    </select>

    <select id="queryPhoneValidateCodeList" parameterType="cn.pluss.platform.entity.PhoneValidateCode"
            resultType="cn.pluss.platform.entity.PhoneValidateCode">
        SELECT * from tb_pluss_phone_validate_code
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="phone!= null">
                and phone = #{phone}
            </if>
            <if test="code!= null">
                and code = #{code}
            </if>
            <if test="sendDt!= null">
                and sendDt = #{sendDt}
            </if>
            <if test="status!= null">
                and status = #{status}
            </if>
            <if test="remark!= null">
                and remark = #{remark}
            </if>
            order by sendDt desc

        </where>
    </select>

    <update id="updatePhoneValidateCode" parameterType="cn.pluss.platform.entity.PhoneValidateCode">
        update tb_pluss_phone_validate_code
        <set>
            <if test="phone!= null">
                phone = #{phone},
            </if>
            <if test="code!= null">
                code = #{code},
            </if>
            <if test="sendDt!= null">
                sendDt = #{sendDt},
            </if>
            <if test="status!= null">
                status = #{status},
            </if>
            <if test="remark!= null">
                remark = #{remark}
            </if>
        </set>
        where id=#{id}
    </update>

    <delete id="deletePhoneValidateCode" parameterType="cn.pluss.platform.entity.PhoneValidateCode">
			DELETE FROM tb_pluss_phone_validate_code where id=#{id} or phone=#{phone}
		</delete>

    <select id="queryPhoneValidateCodePage" parameterType="java.util.Map"
            resultType="cn.pluss.platform.entity.PhoneValidateCode">
        SELECT * from tb_pluss_phone_validate_code
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="phone!= null">
                and phone = #{phone}
            </if>
            <if test="code!= null">
                and code = #{code}
            </if>
            <if test="sendDt!= null">
                and sendDt = #{sendDt}
            </if>
            <if test="status!= null">
                and status = #{status}
            </if>
            <if test="remark!= null">
                and remark = #{remark}
            </if>
        </where>
        order by id desc limit #{pageSize} offset #{offset}
    </select>

    <select id="queryPhoneValidateCodePageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT count(*) from tb_pluss_phone_validate_code
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="phone!= null">
                and phone = #{phone}
            </if>
            <if test="code!= null">
                and code = #{code}
            </if>
            <if test="sendDt!= null">
                and sendDt = #{sendDt}
            </if>
            <if test="status!= null">
                and status = #{status}
            </if>
            <if test="remark!= null">
                and remark = #{remark}
            </if>
        </where>
    </select>

</mapper>
