<?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.ruoyi.system.mapper.ClewPhoneMapper">

    <resultMap type="ClewPhone" id="ClewPhoneResult">
        <result property="id"    column="id"    />
        <result property="phone"    column="phone"    />
        <result property="sourceApp"    column="source_app"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectClewPhoneVo">
        select id, phone,status,source_app, create_time, create_by, update_by, update_time, remark from clew_phone
    </sql>

    <select id="selectClewPhoneList" parameterType="ClewPhone" resultMap="ClewPhoneResult">
        <include refid="selectClewPhoneVo"/>
        <where>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="sourceApp != null"> and source_app = #{sourceApp}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
            <if test="remark != null and remark != ''">
                and remark = #{remark}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectClewPhoneById" parameterType="Long" resultMap="ClewPhoneResult">
        <include refid="selectClewPhoneVo"/>
        where id = #{id}
    </select>

    <insert id="insertClewPhone" parameterType="ClewPhone" useGeneratedKeys="true" keyProperty="id">
        insert into clew_phone
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="phone != null">phone,</if>
            <if test="sourceApp != null">source_app,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="phone != null">#{phone},</if>
            <if test="sourceApp != null">#{sourceApp},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark}</if>
        </trim>
    </insert>

    <update id="updateClewPhone" parameterType="ClewPhone">
        update clew_phone
        <trim prefix="SET" suffixOverrides=",">
            <if test="phone != null">phone = #{phone},</if>
            <if test="sourceApp != null">source_app = #{sourceApp},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark}</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteClewPhoneById" parameterType="Long">
        delete from clew_phone where id = #{id}
    </delete>

    <delete id="deleteClewPhoneByIds" parameterType="String">
        delete from clew_phone where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>