<?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.ElderlyAsphyxiationByChokingMapper">

    <select id="selectPageWithElderInfo"
            resultType="cn.iocoder.yudao.module.system.controller.admin.biz.vo.asphyxiationbychoking.ElderlyAsphyxiationByChokingRespVO">
        SELECT
            eabc.*,
            ei.elder_name AS elderName,
            CONCAT_WS('-', ob.build_name, obf.floor_name, obr.room_name, obb.bed_name) AS bedName
        FROM elderly_asphyxiation_by_choking eabc
        LEFT JOIN elderly_info ei ON ei.id = eabc.elder_id
        LEFT JOIN org_build_bed obb ON obb.id = ei.bed_id AND obb.tenant_id = eabc.tenant_id
        LEFT JOIN org_build_room obr ON obr.id = obb.room_id AND obr.tenant_id = obb.tenant_id
        LEFT JOIN org_build_floor obf ON obf.id = obr.floor_id AND obf.tenant_id = obr.tenant_id
        LEFT JOIN org_build ob ON ob.id = obf.build_id AND ob.tenant_id = obf.tenant_id
        WHERE 1 = 1
        <if test="reqVO.tenantIds != null">
            AND eabc.tenant_id IN
            <foreach item="id" collection="reqVO.tenantIds" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="reqVO.elderId != null">
            AND eabc.elder_id = #{reqVO.elderId}
        </if>
        <if test="reqVO.elderName != null and reqVO.elderName != ''">
            AND ei.elder_name LIKE CONCAT('%', #{reqVO.elderName}, '%')
        </if>
        <if test="reqVO.assessor != null and reqVO.assessor != ''">
            AND eabc.assessor LIKE CONCAT('%', #{reqVO.assessor}, '%')
        </if>
        <if test="reqVO.assessDate != null and reqVO.assessDate.length &gt;= 1">
            AND eabc.assess_date &gt;= #{reqVO.assessDate[0]}
        </if>
        <if test="reqVO.assessDate != null and reqVO.assessDate.length == 2">
            AND eabc.assess_date &lt;= #{reqVO.assessDate[1]}
        </if>
        ORDER BY eabc.assess_date DESC, eabc.id DESC
    </select>

    <select id="selectByIdWithElderInfo"
            resultType="cn.iocoder.yudao.module.system.controller.admin.biz.vo.asphyxiationbychoking.ElderlyAsphyxiationByChokingRespVO">
        SELECT
            eabc.*,
            ei.elder_name AS elderName,
            CONCAT_WS('-', ob.build_name, obf.floor_name, obr.room_name, obb.bed_name) AS bedName
        FROM elderly_asphyxiation_by_choking eabc
        LEFT JOIN elderly_info ei ON ei.id = eabc.elder_id
        LEFT JOIN org_build_bed obb ON obb.id = ei.bed_id AND obb.tenant_id = eabc.tenant_id
        LEFT JOIN org_build_room obr ON obr.id = obb.room_id AND obr.tenant_id = obb.tenant_id
        LEFT JOIN org_build_floor obf ON obf.id = obr.floor_id AND obf.tenant_id = obr.tenant_id
        LEFT JOIN org_build ob ON ob.id = obf.build_id AND ob.tenant_id = obf.tenant_id
        WHERE eabc.id = #{id}
    </select>

</mapper>
