<?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="com.ruoyi.web.modules.booking.mapper.AppAppointmentResourceMapper">

    <resultMap type="com.ruoyi.web.modules.booking.domain.vo.AppointmentResourceVo" id="AppointmentResourceVoResult">
        <id     property="id"                    column="id"/>
        <result property="resourceType"          column="resource_type"/>
        <result property="resourceName"          column="resource_name"/>
        <result property="photoFileUrl"          column="photo_file_url"/>
        <result property="affiliatedUnit"        column="affiliated_unit"/>
        <result property="contactPhone"          column="contact_phone"/>
        <result property="introduction"          column="introduction"/>
        <result property="detailAddress"         column="detail_address"/>
        <result property="serviceStartTime"      column="service_start_time"/>
        <result property="serviceEndTime"        column="service_end_time"/>
        <result property="serviceArea"           column="service_area"/>
        <result property="feeStandard"           column="fee_standard"/>
        <result property="serviceWeekdays"       column="service_weekdays"/>
        <result property="maxDailyAppointments"  column="max_daily_appointments"/>
        <result property="expertRating"          column="expert_rating"/>
        <result property="sysUserId"             column="sys_user_id"/>
        <result property="assignedLoginName"     column="assigned_login_name"/>
        <result property="publishTime"           column="publish_time"/>
    </resultMap>

    <sql id="selectFromView">
        select id, resource_type, resource_name, photo_file_url, affiliated_unit, contact_phone,
               introduction, detail_address, service_start_time, service_end_time, service_area,
               fee_standard, service_weekdays, max_daily_appointments, expert_rating, sys_user_id,
               assigned_login_name, publish_time
        from v_appointment_resource
    </sql>

    <select id="selectAppointmentResourceList"
            parameterType="com.ruoyi.web.modules.booking.domain.AppBookingResourceQuery"
            resultMap="AppointmentResourceVoResult">
        <include refid="selectFromView"/>
        <where>
            resource_type = #{resourceType}
            <if test="resourceName != null and resourceName != ''">
                and resource_name like concat('%', #{resourceName}, '%')
            </if>
            <if test="weekday != null">
                and FIND_IN_SET(#{weekday}, service_weekdays) &gt; 0
            </if>
        </where>
        order by publish_time desc, id desc
    </select>

    <select id="selectAppointmentResourceByIdAndType" resultMap="AppointmentResourceVoResult">
        <include refid="selectFromView"/>
        where id = #{id}
          and resource_type = #{resourceType}
    </select>

</mapper>
