<?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.extra.ElderlyExtraSignatureProxyApplicationMapper">

    <select id="selectPageWithJoin"
            resultType="cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraSignatureProxyApplicationDO">
        SELECT spa.*,
               ei.elder_name AS elderName,
               CONCAT(build.build_name, '-', floor.floor_name, '-', room.room_name, '-', bed.bed_name) AS bedNumber
        FROM elderly_extra_signature_proxy_application spa
                 LEFT JOIN elderly_info ei ON ei.id = spa.elder_id AND (ei.deleted = 0 OR ei.deleted IS NULL)
                 LEFT JOIN org_build_bed bed ON bed.id = ei.bed_id
                 LEFT JOIN org_build_room room ON room.id = bed.room_id
                 LEFT JOIN org_build_floor floor ON floor.id = bed.floor_id
                 LEFT JOIN org_build build ON build.id = bed.build_id
        WHERE 1 = 1
        <if test="reqVO.elderName != null and reqVO.elderName != ''">
            AND ei.elder_name LIKE CONCAT('%', #{reqVO.elderName}, '%')
        </if>
        <if test="reqVO.recorder != null and reqVO.recorder != ''">
            AND spa.recorder LIKE CONCAT('%', #{reqVO.recorder}, '%')
        </if>
        <if test="reqVO.recordDate != null and reqVO.recordDate.length == 2">
            AND spa.record_date BETWEEN #{reqVO.recordDate[0]} AND #{reqVO.recordDate[1]}
        </if>
        ORDER BY spa.create_time DESC
    </select>

</mapper>
