<?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.ssm.manage.mapper.SmsMessagesMapper">

    <resultMap type="com.ssm.manage.entity.SmsMessages" id="baseMap">
        <result property="id" column="id" jdbcType="BIGINT"/>
        <result property="storeId" column="store_id" jdbcType="BIGINT"/>
        <result property="phone" column="phone" jdbcType="VARCHAR"/>
        <result property="content" column="content" jdbcType="LONGVARCHAR"/>
        <result property="sendTime" column="send_time" jdbcType="TIMESTAMP"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="errorMessage" column="error_message" jdbcType="LONGVARCHAR"/>
        <result property="storeId" column="store_id" jdbcType="BIGINT"/>
        <result property="storeNum" column="store_num" jdbcType="VARCHAR"/>
        <result property="storeName" column="store_name" jdbcType="VARCHAR"/>
        <result property="smsAccount" column="sms_account" jdbcType="VARCHAR"/>
        <result property="smsPassword" column="sms_password" jdbcType="VARCHAR"/>
        <result property="smsUrl" column="sms_url" jdbcType="VARCHAR"/>
        <result property="smsType" column="sms_type" jdbcType="INTEGER"/>
    </resultMap>
    <insert id="save">
        insert into sms_messages_${tab} (id,phone,content,send_time,status,error_message,store_id,store_num,store_name,sms_account,sms_password,sms_url,sms_type)
            values (#{id},#{phone},#{content},#{sendTime},#{status},'',#{storeId},#{storeNum},#{storeName},#{smsAccount},#{smsPassword},#{smsUrl},#{smsType})
    </insert>
    <update id="updateById">
        update sms_messages_${tab} set status = #{status} ,error_message = #{errorMessage} where id = #{id}
    </update>

    <select id="createTable" parameterType="java.lang.String">
        create table IF NOT EXISTS sms_messages_${tab} like sms_messages
    </select>
    <select id="selectByDate" resultMap="baseMap" parameterType="com.ssm.manage.query.SmsMessagesRequest">
        select * from sms_messages_${tab} where send_time between #{startTime} and #{endTime}
        <if test="storeId!=null">and store_id = #{storeId} </if>
        <if test="phone!=null">and phone = #{phone} </if>
        <if test="memberName!=null">and content like CONCAT('%', #{memberName}, '%') </if>
        <if test="status!=null">and status = #{status} </if>
        <if test="smsType!=null">and sms_type = #{smsType} </if>
    </select>


</mapper>

