<?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.dormitory.mapper.DormitoryApplyMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM dormitory_apply a
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </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.dealerName != null">
                AND a.dealer_name LIKE CONCAT('%', #{param.dealerName}, '%')
            </if>
            <if test="param.dealerCode != null">
                AND a.dealer_code LIKE CONCAT('%', #{param.dealerCode}, '%')
            </if>
            <if test="param.address != null">
                AND a.address LIKE CONCAT('%', #{param.address}, '%')
            </if>
            <if test="param.money != null">
                AND a.money = #{param.money}
            </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.applyStatus != null">
                AND a.apply_status = #{param.applyStatus}
            </if>
            <if test="param.applyTime != null">
                AND a.apply_time LIKE CONCAT('%', #{param.applyTime}, '%')
            </if>
            <if test="param.auditTime != null">
                AND a.audit_time LIKE CONCAT('%', #{param.auditTime}, '%')
            </if>
            <if test="param.contractTime != null">
                AND a.contract_time LIKE CONCAT('%', #{param.contractTime}, '%')
            </if>
            <if test="param.expirationTime != null">
                AND a.expiration_time LIKE CONCAT('%', #{param.expirationTime}, '%')
            </if>
            <if test="param.rejectReason != null">
                AND a.reject_reason LIKE CONCAT('%', #{param.rejectReason}, '%')
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </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.comments LIKE CONCAT('%', #{param.keywords}, '%')
                )
              </if>
        </where>
    </sql>

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

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

</mapper>
