<?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.system.mapper.OperatingHoursMapper">

    <resultMap type="OperatingHours" id="OperatingHoursResult">
        <result property="id"    column="id"    />
        <result property="mdId"    column="md_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="dayOfWeek"    column="day_of_week"    />
        <result property="isOpen"    column="is_open"    />
    </resultMap>

    <sql id="selectOperatingHoursVo">
        select id, md_id, start_time, end_time, day_of_week, is_open from operating_hours
    </sql>

    <select id="selectOperatingHoursList" parameterType="OperatingHours" resultMap="OperatingHoursResult">
        <include refid="selectOperatingHoursVo"/>
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="mdId != null "> and md_id = #{mdId}</if>
            <if test="dayOfWeek != null "> and day_of_week = #{dayOfWeek}</if>
            <if test="isOpen != null "> and is_open = #{isOpen}</if>
        </where>
    </select>

    <select id="selectOperatingHoursById" parameterType="Long" resultMap="OperatingHoursResult">
        <include refid="selectOperatingHoursVo"/>
        where id = #{id}
    </select>

    <insert id="insertOperatingHours" parameterType="OperatingHours" useGeneratedKeys="true" keyProperty="id">
        insert into operating_hours
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mdId != null">md_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="dayOfWeek != null">day_of_week,</if>
            <if test="isOpen != null">is_open,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="mdId != null">#{mdId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="dayOfWeek != null">#{dayOfWeek},</if>
            <if test="isOpen != null">#{isOpen},</if>
         </trim>
    </insert>

    <update id="updateOperatingHours" parameterType="OperatingHours">
        update operating_hours
        <trim prefix="SET" suffixOverrides=",">
            <if test="mdId != null">md_id = #{mdId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="dayOfWeek != null">day_of_week = #{dayOfWeek},</if>
            <if test="isOpen != null">is_open = #{isOpen},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOperatingHoursById" parameterType="Long">
        delete from operating_hours where id = #{id}
    </delete>

    <delete id="deleteOperatingHoursByIds" parameterType="String">
        delete from operating_hours where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
