<?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.oa.mapper.CustomerMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM oa_customer a
        <where>
            <if test="param.customerId != null">
                AND a.customer_id = #{param.customerId}
            </if>
            <if test="param.customerName != null">
                AND a.customer_name LIKE CONCAT('%', #{param.customerName}, '%')
            </if>
            <if test="param.customerCode != null">
                AND a.customer_code LIKE CONCAT('%', #{param.customerCode}, '%')
            </if>
            <if test="param.customerFullName != null">
                AND a.customer_full_name LIKE CONCAT('%', #{param.customerFullName}, '%')
            </if>
            <if test="param.customerAvatar != null">
                AND a.customer_avatar LIKE CONCAT('%', #{param.customerAvatar}, '%')
            </if>
            <if test="param.customerType != null">
                AND a.customer_type LIKE CONCAT('%', #{param.customerType}, '%')
            </if>
            <if test="param.emptyType != null">
              AND a.customer_type = ''
            </if>
            <if test="param.customerSource != null">
                AND a.customer_source LIKE CONCAT('%', #{param.customerSource}, '%')
            </if>
            <if test="param.customerPhone != null">
                AND a.customer_phone LIKE CONCAT('%', #{param.customerPhone}, '%')
            </if>
            <if test="param.customerMobile != null">
                AND a.customer_mobile LIKE CONCAT('%', #{param.customerMobile}, '%')
            </if>
            <if test="param.customerContacts != null">
                AND a.customer_contacts LIKE CONCAT('%', #{param.customerContacts}, '%')
            </if>
            <if test="param.customerProvince != null">
                AND a.customer_province LIKE CONCAT('%', #{param.customerProvince}, '%')
            </if>
            <if test="param.customerCity != null">
                AND a.customer_city LIKE CONCAT('%', #{param.customerCity}, '%')
            </if>
            <if test="param.customerRegion != null">
                AND a.customer_region LIKE CONCAT('%', #{param.customerRegion}, '%')
            </if>
            <if test="param.customerAddress != null">
                AND a.customer_address LIKE CONCAT('%', #{param.customerAddress}, '%')
            </if>
            <if test="param.progress != null">
                AND a.progress LIKE CONCAT('%', #{param.progress}, '%')
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.organizationId != null">
                AND a.organization_id = #{param.organizationId}
            </if>
            <if test="param.visibility != null">
                AND a.visibility LIKE CONCAT('%', #{param.visibility}, '%')
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </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>
          <if test="param.keywords != null">
            AND (a.customer_name LIKE CONCAT('%', #{param.keywords}, '%')
            OR a.customer_contacts LIKE CONCAT('%', #{param.keywords}, '%')
            OR a.customer_mobile LIKE CONCAT('%', #{param.keywords}, '%')
            )
          </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.oa.entity.Customer">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.oa.entity.Customer">
        <include refid="selectSql"></include>
    </select>

</mapper>
