<?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.shop.mapper.ShopDealerApplyMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*, b.nickname as nickName, b.phone, c.nickname as refereeName, d.rate
        FROM shop_dealer_apply a
        LEFT JOIN gxwebsoft_core.sys_user b ON a.user_id = b.user_id
        LEFT JOIN gxwebsoft_core.sys_user c ON a.referee_id = c.user_id
        LEFT JOIN shop_dealer_user d ON a.user_id = d.user_id
        <where>
            <if test="param.applyId != null">
                AND a.apply_id = #{param.applyId}
            </if>
            <if test="param.type != null">
              AND a.type = #{param.type}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.realName != null">
                AND a.real_name LIKE CONCAT('%', #{param.realName}, '%')
            </if>
            <if test="param.mobile != null">
                AND a.mobile LIKE CONCAT('%', #{param.mobile}, '%')
            </if>
            <if test="param.community != null">
                AND a.community LIKE CONCAT('%', #{param.community}, '%')
            </if>
            <if test="param.buildingNumber != null">
                AND a.building_number = #{param.buildingNumber}
            </if>
            <if test="param.unitNumber != null">
                AND a.unit_number = #{param.unitNumber}
            </if>
            <if test="param.roomNumber != null">
                AND a.room_number = #{param.roomNumber}
            </if>
            <if test="param.dealerName != null">
              AND a.dealer_name LIKE CONCAT('%', #{param.dealerName}, '%')
            </if>
            <if test="param.dealerCode != null">
              AND a.dealer_code = #{param.dealerCode}
            </if>
            <if test="param.refereeId != null">
                AND a.referee_id = #{param.refereeId}
            </if>
            <if test="param.applyType != null">
                AND a.apply_type = #{param.applyType}
            </if>
            <if test="param.applyTime != null">
                AND a.apply_time = #{param.applyTime}
            </if>
            <if test="param.applyStatus != null">
                AND a.apply_status = #{param.applyStatus}
            </if>
            <if test="param.auditTime != null">
                AND a.audit_time = #{param.auditTime}
            </if>
            <if test="param.expirationTime != null">
              AND a.expiration_time = #{param.expirationTime}
            </if>
            <if test="param.rejectReason != null">
                AND a.reject_reason LIKE CONCAT('%', #{param.rejectReason}, '%')
            </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.mobile = #{param.keywords}
                    OR a.real_name LIKE CONCAT('%', #{param.keywords}, '%')
                    OR a.dealer_name LIKE CONCAT('%', #{param.keywords}, '%')
                )
              </if>
        </where>
    </sql>

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

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

</mapper>
