<?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.roadm.mapper.SmsPhonepoolLogMapper">

    <resultMap id="BaseResultMap" type="cn.roadm.bo.SmsPhonepoolLog">
        <result column="id" property="id"/>
        <result column="phone" property="phone"/>
        <result column="gid" property="gid"/>
        <result column="operation_time" property="operationTime"/>
        <result column="operation_type" property="operationType"/>
        <result column="ip" property="ip"/>
        <result column="uid" property="uid"/>
        <result column="remark" property="remark"/>
        <result column="operation_name" property="operation_name"/>
        <result column="gname" property="gname"/>
        <result column="user_name" property="user_name"/>

    </resultMap>
    <sql id="Base_Column_List">
        `id`,`phone`,`gid`,`operation_time`,`operation_type`,`ip`,`uid`,`remark`
    </sql>

    <insert id="insertSmsPhonepoolLog" parameterType="SmsPhonepoolLog" useGeneratedKeys="true" keyProperty="id">
        insert into sms_phonepool_log (`phone`,`gid`,`operation_time`,`operation_type`,`ip`,`uid`,`remark`)
        value (#{phone,jdbcType=VARCHAR}, #{gid},#{operationTime},#{operationType},#{ip},#{uid},#{remark})
    </insert>
    
     <select id="listPagePhonepoolLog" resultMap="BaseResultMap">
    	SELECT
			spl.*,
			spo.operation_name,
			spg.`name` gname,
			sui.user_name 
		FROM
			sms_phonepool_log spl
			LEFT JOIN sms_phonepool_operation spo ON spl.operation_type = spo.id
			LEFT JOIN sms_phonepool_group spg ON spl.gid = spg.id
			LEFT JOIN sms_user_info sui ON spl.uid = sui.id
		<where>
			<if test="operationType!=null and operationType!=''">
				and spo.id=#{operationType}
			</if>
			<if test="gid!=null and gid!=''">
				and spg.id=#{gid}
			</if>
			<if test="uid!=null and uid!=''">
				and sui.id=#{uid}
			</if>
			<if test="phone !=null and phone!=''">
				and spl.phone=#{phone}
			</if>
			<if test="createTime!=null and createTime!=''">
				and operation_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
			</if>
			<if test="createTime1!=null and createTime1!=''">
				and
				operation_time&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL
				1 DAY)
			</if>
		</where>
		order by operation_time desc
    </select>
    
    
</mapper>