<?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="cn.iocoder.yudao.module.system.dal.mysql.biz.ElderlyAskLeaveMapper">

    <select id="selectPageWithLocationFilter"
            resultType="cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyAskLeaveDO">
        SELECT eal.*
        FROM elderly_ask_leave eal
                 LEFT JOIN elderly_info ei ON ei.id = eal.elder_id
        WHERE 1 = 1
        <if test="reqVO.orgType != null">
            AND eal.org_type = #{reqVO.orgType}
        </if>
        <if test="reqVO.elderName != null and reqVO.elderName != ''">
            AND eal.elder_name LIKE concat('%', #{reqVO.elderName}, '%')
        </if>
        <if test="reqVO.queryTime != null and reqVO.queryTime.length == 2">
            AND eal.out_date BETWEEN #{reqVO.queryTime[0]} AND #{reqVO.queryTime[1]}
        </if>
        <if test="reqVO.tenantIds != null and reqVO.tenantIds.length > 0">
            AND eal.tenant_id IN
            <foreach collection="reqVO.tenantIds" item="tenantId" open="(" separator="," close=")">
                #{tenantId}
            </foreach>
        </if>
        <if test="reqVO.isUpdated != null">
            <choose>
                <when test="reqVO.isUpdated == 1">
                    AND eal.update_date IS NOT NULL
                </when>
                <otherwise>
                    AND eal.update_date IS NULL
                </otherwise>
            </choose>
        </if>
        <if test="reqVO.buildId != null">
            AND ei.build_id = #{reqVO.buildId}
        </if>
        <if test="reqVO.floorId != null">
            AND ei.floor_id = #{reqVO.floorId}
        </if>
        AND (ei.deleted = 0 OR ei.deleted IS NULL)
        ORDER BY eal.create_date DESC
    </select>

</mapper>

