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

    <select id="selectPageWithDetail"
            resultType="cn.iocoder.yudao.module.system.controller.admin.biz.vo.ElderlyOrderFoodRespVO">
        SELECT eof.id,
               eof.elder_id AS elderId,
               ei.elder_name AS elderName,
               b.build_name AS buildName,
               f.floor_name AS floorName,
               r.room_name AS roomName,
               eof.order_food_date AS orderFoodDate,
               eof.extra_dishes AS extraDishes,
               eof.tenant_id AS tenantId
        FROM elderly_order_food eof
                 LEFT JOIN elderly_info ei ON ei.id = eof.elder_id
                 LEFT JOIN org_build b ON b.id = ei.build_id
                 LEFT JOIN org_build_floor f ON f.id = ei.floor_id
                 LEFT JOIN org_build_room r ON r.id = ei.room_id
        WHERE 1 = 1
        <if test="reqVO.tenantId != null">
            AND eof.tenant_id = #{reqVO.tenantId}
        </if>
        <if test="reqVO.buildName != null and reqVO.buildName != ''">
            AND b.build_name like concat('%',#{reqVO.buildName},'%')
        </if>
        <if test="reqVO.floorName != null and  reqVO.floorName != ''">
            AND f.floor_name like concat('%',#{reqVO.floorName},'%')
        </if>
        <if test="reqVO.orderFoodDate != null">
            AND eof.order_food_date = #{reqVO.orderFoodDate}
        </if>
        ORDER BY eof.order_food_date DESC, eof.id DESC
    </select>

    <select id="getList"
            resultType="cn.iocoder.yudao.module.system.controller.admin.biz.vo.ElderOrderFoodExportExcelVO">
        SELECT eof.id,
        eof.elder_id AS elderId,
        ei.elder_name AS elderName,
        b.build_name AS buildName,
        f.floor_name AS floorName,
        r.room_name AS roomName,
        eof.order_food_date AS orderFoodDate,
        eof.extra_dishes AS extraDishes,
        eof.tenant_id AS tenantId
        FROM elderly_order_food eof
        LEFT JOIN elderly_info ei ON ei.id = eof.elder_id
        LEFT JOIN org_build b ON b.id = ei.build_id
        LEFT JOIN org_build_floor f ON f.id = ei.floor_id
        LEFT JOIN org_build_room r ON r.id = ei.room_id
        WHERE 1 = 1
        <if test="reqVO.tenantId != null">
            AND eof.tenant_id = #{reqVO.tenantId}
        </if>
        <if test="reqVO.buildName != null and reqVO.buildName != ''">
            AND b.build_name like concat('%',#{reqVO.buildName},'%')
        </if>
        <if test="reqVO.floorName != null and  reqVO.floorName != ''">
            AND f.floor_name like concat('%',#{reqVO.floorName},'%')
        </if>
        <if test="reqVO.orderFoodDate != null">
            AND eof.order_food_date = #{reqVO.orderFoodDate}
        </if>
        ORDER BY b.build_name DESC, f.floor_name DESC, r.room_name DESC, eof.order_food_date DESC,eof.elder_id DESC
    </select>

</mapper>

