<?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.tower.mapper.TowerCustomerMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM tower_customer a
        <where>
            <if test="param.customerId != null">
                AND a.customer_id = #{param.customerId}
            </if>
            <if test="param.name != null">
                AND a.name LIKE CONCAT('%', #{param.name}, '%')
            </if>
            <if test="param.fullName != null">
                AND a.full_name LIKE CONCAT('%', #{param.fullName}, '%')
            </if>
            <if test="param.creditCode != null">
                AND a.credit_code LIKE CONCAT('%', #{param.creditCode}, '%')
            </if>
            <if test="param.address != null">
                AND a.address LIKE CONCAT('%', #{param.address}, '%')
            </if>
            <if test="param.contact != null">
                AND a.contact LIKE CONCAT('%', #{param.contact}, '%')
            </if>
            <if test="param.phone != null">
                AND a.phone LIKE CONCAT('%', #{param.phone}, '%')
            </if>
            <if test="param.telPhone != null">
                AND a.tel_phone LIKE CONCAT('%', #{param.telPhone}, '%')
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.avatar != null">
                AND a.avatar LIKE CONCAT('%', #{param.avatar}, '%')
            </if>
            <if test="param.remark != null">
                AND a.remark LIKE CONCAT('%', #{param.remark}, '%')
            </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.userId != null">
                AND a.user_id = #{param.userId}
            </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.tower.entity.TowerCustomer">
        <include refid="selectSql"></include>
    </select>

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

</mapper>
