<?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.fs.doctor.mapper.DoctorLevelDataMapper">
    
    <resultMap type="DoctorLevelData" id="DoctorLevelDataResult">
        <result property="id"    column="id"    />
        <result property="levelName"    column="level_name"    />
        <result property="sort"    column="sort"    />
        <result property="companyId"    column="company_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="companyName"    column="company_name"    />
    </resultMap>

    <sql id="selectDoctorLevelDataVo">
        select d.id, d.level_name, d.sort, d.company_id, d.create_time, d.update_time,
        c.company_name
        from doctor_level_data d
        left join company c on d.company_id = c.company_id
    </sql>

    <select id="selectDoctorLevelDataList" parameterType="DoctorLevelData" resultMap="DoctorLevelDataResult">
        <include refid="selectDoctorLevelDataVo"/>
        <where>
            <if test="levelName != null and levelName != ''"> and d.level_name like concat('%', #{levelName}, '%')</if>
            <if test="sort != null"> and d.sort = #{sort}</if>
            <if test="companyId != null"> and d.company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectDoctorLevelDataById" parameterType="Long" resultMap="DoctorLevelDataResult">
        <include refid="selectDoctorLevelDataVo"/>
        where d.id = #{id}
    </select>
        
    <insert id="insertDoctorLevelData" parameterType="DoctorLevelData" useGeneratedKeys="true" keyProperty="id">
        insert into doctor_level_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="levelName != null and levelName != ''">level_name,</if>
            <if test="sort != null">sort,</if>
            <if test="companyId != null">company_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="levelName != null and levelName != ''">#{levelName},</if>
            <if test="sort != null">#{sort},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateDoctorLevelData" parameterType="DoctorLevelData">
        update doctor_level_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="levelName != null and levelName != ''">level_name = #{levelName},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDoctorLevelDataById" parameterType="Long">
        delete from doctor_level_data where id = #{id}
    </delete>

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