<?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.elderly.ElderlyNursingLogMapper">

    <select id="selectListWithItemName" resultType="cn.iocoder.yudao.module.system.controller.admin.elderly.vo.ElderlyNursingLogRespVO">
        SELECT
            enl.id,
            enl.elder_id AS elderId,
            enl.nurse,
            enl.nursing_plan_item_id AS nursingPlanItemId,
            npi.nurse_item_name AS nursingItemName,
            enl.image,
            enl.remark,
            enl.create_time AS createTime
        FROM elderly_nursing_log enl
        LEFT JOIN elderly_nursing_plan_item npi ON npi.id = enl.nursing_plan_item_id
        WHERE 1 = 1
            <if test="nurse != null and nurse != ''">
                AND enl.nurse LIKE CONCAT('%', #{nurse}, '%')
            </if>
            <if test="tenantId != null">
                AND enl.tenant_id = #{tenantId}
            </if>
            <if test="startDate != null">
                AND enl.nurse_date &gt;= #{startDate}
            </if>
            <if test="endDate != null">
                AND enl.nurse_date &lt;= #{endDate}
            </if>
        ORDER BY enl.nurse_date DESC, enl.id DESC
    </select>

    <select id="selectByElderIdWithItemName" resultType="cn.iocoder.yudao.module.system.controller.admin.elderly.vo.ElderlyNursingLogRespVO">
        SELECT
            enl.id,
            enl.elder_id AS elderId,
            enl.nurse,
            enl.nursing_plan_item_id AS nursingPlanItemId,
            npi.nurse_item_name AS nursingItemName,
            enl.image,
            enl.remark,
            enl.nurse_date AS nurseDate,
            enl.create_time AS createTime
        FROM elderly_nursing_log enl
        LEFT JOIN elderly_nursing_plan_item npi ON npi.id = enl.nursing_plan_item_id
        WHERE enl.elder_id = #{elderId}
            <if test="startDate != null">
                AND enl.nurse_date &gt;= #{startDate}
            </if>
            <if test="endDate != null">
                AND enl.nurse_date &lt;= #{endDate}
            </if>
        ORDER BY enl.nurse_date DESC, enl.id DESC
    </select>

</mapper>
