<?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.wisenergy.mapper.SmsLogMapper">

    <select id="getSmsLogById" resultType="cn.wisenergy.model.app.SmsLog">
        select
                id as id,
                codeType as codeType,
                phone as phone,
                message as message,
                failInfo as failInfo,
                status as status,
                createdUserId as createdUserId,
                updatedUserId as updatedUserId,
                creatdTime as creatdTime,
                updatedTime as updatedTime,
                isDelete as isDelete
        from sms_log
        <trim prefix="where" prefixOverrides="and | or">
            <if test="id != null">
                and id=#{id}
            </if>
        </trim>
    </select>

    <select id="getSmsLogListByMap" resultType="cn.wisenergy.model.app.SmsLog" parameterType="java.util.Map">
        select
                id as id,
                codeType as codeType,
                phone as phone,
                message as message,
                failInfo as failInfo,
                status as status,
                createdUserId as createdUserId,
                updatedUserId as updatedUserId,
                creatdTime as creatdTime,
                updatedTime as updatedTime,
                isDelete as isDelete
        from sms_log
        <trim prefix="where" prefixOverrides="and | or">
                    <if test="id != null">
                        and id=#{id}
                    </if>
                    <if test="codeType != null">
                        and codeType=#{codeType}
                    </if>
                    <if test="phone != null and phone!=''">
                        and phone=#{phone}
                    </if>
                    <if test="message != null and message!=''">
                        and message=#{message}
                    </if>
                    <if test="failInfo != null and failInfo!=''">
                        and failInfo=#{failInfo}
                    </if>
                    <if test="status != null">
                        and status=#{status}
                    </if>
                    <if test="createdUserId != null">
                        and createdUserId=#{createdUserId}
                    </if>
                    <if test="updatedUserId != null">
                        and updatedUserId=#{updatedUserId}
                    </if>
                    <if test="null!=creatdTime">
                        and creatdTime=#{creatdTime}
                    </if>
                    <if test="null!=updatedTime">
                        and updatedTime=#{updatedTime}
                    </if>
                    <if test="isDelete != null">
                        and isDelete=#{isDelete}
                    </if>
        </trim>
        <if test="beginPos != null and pageSize != null ">
            limit #{beginPos},#{pageSize}
        </if>
    </select>

    <select id="getSmsLogCountByMap" resultType="Integer"  parameterType="java.util.Map">
        select count(*) from sms_log
        <trim prefix="where" prefixOverrides="and | or">
                <if test="id != null">
                    and id=#{id}
                </if>
                <if test="codeType != null">
                    and codeType=#{codeType}
                </if>
                <if test="phone != null and phone!=''">
                    and phone=#{phone}
                </if>
                <if test="message != null and message!=''">
                    and message=#{message}
                </if>
                <if test="failInfo != null and failInfo!=''">
                    and failInfo=#{failInfo}
                </if>
                <if test="status != null">
                    and status=#{status}
                </if>
                <if test="createdUserId != null">
                    and createdUserId=#{createdUserId}
                </if>
                <if test="updatedUserId != null">
                    and updatedUserId=#{updatedUserId}
                </if>
                <if test="null!=creatdTime">
                    and creatdTime=#{creatdTime}
                </if>
                <if test="null!=updatedTime">
                    and updatedTime=#{updatedTime}
                </if>
                <if test="isDelete != null">
                    and isDelete=#{isDelete}
                </if>
        </trim>
    </select>

    <insert id="insertSmsLog" parameterType="cn.wisenergy.model.app.SmsLog">
        insert into sms_log(
                        codeType,
                        phone,
                        message,
                        failInfo,
                        status,
                        createdUserId,
                        updatedUserId,
                        creatdTime,
                        updatedTime,
                        isDelete)
        values(
                     #{codeType},
                     #{phone},
                     #{message},
                     #{failInfo},
                     #{status},
                     #{createdUserId},
                     #{updatedUserId},
                     #{creatdTime},
                     #{updatedTime},
                    #{isDelete})
    </insert>

    <update id="updateSmsLog" parameterType="cn.wisenergy.model.app.SmsLog">
        update sms_log
        <trim prefix="set" suffixOverrides="," suffix="where id=#{id}">
                            <if test="codeType != null">
                                codeType=#{codeType},
                            </if>
                            <if test="phone != null and phone!=''">
                                phone=#{phone},
                            </if>
                            <if test="message != null and message!=''">
                                message=#{message},
                            </if>
                            <if test="failInfo != null and failInfo!=''">
                                failInfo=#{failInfo},
                            </if>
                            <if test="status != null">
                                status=#{status},
                            </if>
                            <if test="createdUserId != null">
                                createdUserId=#{createdUserId},
                            </if>
                            <if test="updatedUserId != null">
                                updatedUserId=#{updatedUserId},
                            </if>
                            <if test="creatdTime != null">
                                creatdTime=#{creatdTime},
                            </if>
                            <if test="updatedTime != null">
                                updatedTime=#{updatedTime},
                            </if>
                            <if test="isDelete != null">
                                isDelete=#{isDelete}
                            </if>
        </trim>
    </update>

    <delete id="deleteSmsLogById" parameterType="String">
        delete from sms_log where id = #{id}
    </delete>

    <delete id="batchDeleteSmsLog" parameterType="java.util.Map">
        delete from sms_log where id in (
            <foreach collection="ids" item="id" separator=",">
                    #{id}
            </foreach>
        )
    </delete>
</mapper>