<?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.gxwebsoft.cms.mapper.CmsContactLeadMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM cms_contact_lead a
        <where>
            <if test="param.leadId != null">
                AND a.lead_id = #{param.leadId}
            </if>
            <if test="param.name != null">
                AND a.name LIKE CONCAT('%', #{param.name}, '%')
            </if>
            <if test="param.phone != null">
                AND a.phone LIKE CONCAT('%', #{param.phone}, '%')
            </if>
            <if test="param.company != null">
                AND a.company LIKE CONCAT('%', #{param.company}, '%')
            </if>
            <if test="param.delivery != null">
                AND a.delivery = #{param.delivery}
            </if>
            <if test="param.source != null">
                AND a.source = #{param.source}
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.keywords != null">
                AND (
                    a.name LIKE CONCAT('%', #{param.keywords}, '%')
                    OR a.phone LIKE CONCAT('%', #{param.keywords}, '%')
                    OR a.company LIKE CONCAT('%', #{param.keywords}, '%')
                    OR a.need LIKE CONCAT('%', #{param.keywords}, '%')
                )
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.cms.entity.CmsContactLead">
        <include refid="selectSql"/>
        ORDER BY a.create_time DESC
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.cms.entity.CmsContactLead">
        <include refid="selectSql"/>
        ORDER BY a.create_time DESC
    </select>

</mapper>
