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

    <select id="selectElderlyServiceOrderPage"
            resultType="cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlyorder.ElderlyServiceOrderRespVO">
        SELECT
            eso.id,
            eso.elder_name,
            eso.elder_sex,
            eso.elder_age,
            eso.elder_address,
            eso.id_card,
            eso.service_item,
            eso.service_name,
            eso.order_time,
            eso.service_begin_time,
            eso.service_end_time,
            eso.service_hour,
            eso.is_expire,
            eso.order_status
        FROM elderly_service_order eso
        WHERE 1=1
            <if test="pageVO.serviceName != null and pageVO.serviceName != ''">
                AND eso.service_name LIKE CONCAT('%', #{pageVO.serviceName}, '%')
            </if>
            <if test="pageVO.elderName != null and pageVO.elderName != ''">
                AND eso.elder_name LIKE CONCAT('%', #{pageVO.elderName}, '%')
            </if>
            <if test="pageVO.orderStatus != null">
                AND eso.order_status = #{pageVO.orderStatus}
            </if>
            <if test="pageVO.tenantIds != null and pageVO.tenantIds.length &gt; 0">
                AND eso.tenant_id IN
                <foreach collection="pageVO.tenantIds" item="tid" open="(" separator="," close=")">
                    #{tid}
                </foreach>
            </if>
            <if test="pageVO.discoveryTime != null and pageVO.discoveryTime.length == 2">
                <if test="pageVO.discoveryTime[0] != null">
                    AND eso.order_time &gt;= #{pageVO.discoveryTime[0]}
                </if>
                <if test="pageVO.discoveryTime[1] != null">
                    AND eso.order_time &lt; #{pageVO.discoveryTime[1]} + INTERVAL 1 DAY
                </if>
            </if>
        ORDER BY eso.id DESC
    </select>

</mapper>

