<?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.framework.system.mapper.DoctorsMapper">
    
    <resultMap type="Doctors" id="DoctorsResult">
        <result property="DoctorID"    column="DoctorID"    />
        <result property="FirstName"    column="FirstName"    />
        <result property="LastName"    column="LastName"    />
        <result property="Specialty"    column="Specialty"    />
        <result property="ContactInfo"    column="ContactInfo"    />
        <result property="Address"    column="Address"    />
        <result property="LicenseNumber"    column="LicenseNumber"    />
        <result property="CreatedAt"    column="CreatedAt"    />
        <result property="UpdatedAt"    column="UpdatedAt"    />
    </resultMap>

    <sql id="selectDoctorsVo">
        select DoctorID, FirstName, LastName, Specialty, ContactInfo, Address, LicenseNumber, CreatedAt, UpdatedAt from Doctors
    </sql>

    <select id="selectDoctorsList" parameterType="Doctors" resultMap="DoctorsResult">
        <include refid="selectDoctorsVo"/>
        <where>  
            <if test="FirstName != null  and FirstName != ''"> and FirstName like concat('%', #{FirstName}, '%')</if>
            <if test="LastName != null  and LastName != ''"> and LastName like concat('%', #{LastName}, '%')</if>
            <if test="Specialty != null  and Specialty != ''"> and Specialty = #{Specialty}</if>
            <if test="ContactInfo != null  and ContactInfo != ''"> and ContactInfo = #{ContactInfo}</if>
            <if test="Address != null  and Address != ''"> and Address = #{Address}</if>
            <if test="LicenseNumber != null  and LicenseNumber != ''"> and LicenseNumber = #{LicenseNumber}</if>
            <if test="CreatedAt != null "> and CreatedAt = #{CreatedAt}</if>
            <if test="UpdatedAt != null "> and UpdatedAt = #{UpdatedAt}</if>
        </where>
    </select>
    
    <select id="selectDoctorsByDoctorID" parameterType="Long" resultMap="DoctorsResult">
        <include refid="selectDoctorsVo"/>
        where DoctorID = #{DoctorID}
    </select>

    <insert id="insertDoctors" parameterType="Doctors" useGeneratedKeys="true" keyProperty="DoctorID">
        insert into Doctors
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="FirstName != null and FirstName != ''">FirstName,</if>
            <if test="LastName != null and LastName != ''">LastName,</if>
            <if test="Specialty != null">Specialty,</if>
            <if test="ContactInfo != null">ContactInfo,</if>
            <if test="Address != null">Address,</if>
            <if test="LicenseNumber != null and LicenseNumber != ''">LicenseNumber,</if>
            <if test="CreatedAt != null">CreatedAt,</if>
            <if test="UpdatedAt != null">UpdatedAt,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="FirstName != null and FirstName != ''">#{FirstName},</if>
            <if test="LastName != null and LastName != ''">#{LastName},</if>
            <if test="Specialty != null">#{Specialty},</if>
            <if test="ContactInfo != null">#{ContactInfo},</if>
            <if test="Address != null">#{Address},</if>
            <if test="LicenseNumber != null and LicenseNumber != ''">#{LicenseNumber},</if>
            <if test="CreatedAt != null">#{CreatedAt},</if>
            <if test="UpdatedAt != null">#{UpdatedAt},</if>
         </trim>
    </insert>

    <update id="updateDoctors" parameterType="Doctors">
        update Doctors
        <trim prefix="SET" suffixOverrides=",">
            <if test="FirstName != null and FirstName != ''">FirstName = #{FirstName},</if>
            <if test="LastName != null and LastName != ''">LastName = #{LastName},</if>
            <if test="Specialty != null">Specialty = #{Specialty},</if>
            <if test="ContactInfo != null">ContactInfo = #{ContactInfo},</if>
            <if test="Address != null">Address = #{Address},</if>
            <if test="LicenseNumber != null and LicenseNumber != ''">LicenseNumber = #{LicenseNumber},</if>
            <if test="CreatedAt != null">CreatedAt = #{CreatedAt},</if>
            <if test="UpdatedAt != null">UpdatedAt = #{UpdatedAt},</if>
        </trim>
        where DoctorID = #{DoctorID}
    </update>

    <delete id="deleteDoctorsByDoctorID" parameterType="Long">
        delete from Doctors where DoctorID = #{DoctorID}
    </delete>

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