<?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.DoctorLevelMaterialMapper">
    
    <resultMap type="DoctorLevelMaterial" id="DoctorLevelMaterialResult">
        <result property="id"    column="id"    />
        <result property="companyId"    column="company_id"    />
        <result property="applyId"    column="apply_id"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileSize"    column="file_size"    />
        <result property="fileType"    column="file_type"    />
        <result property="sortOrder"    column="sort_order"    />
        <result property="createTime"    column="create_time"    />
        <result property="deleted"    column="deleted"    />
        <result property="companyName"    column="company_name"    />
    </resultMap>

    <sql id="selectDoctorLevelMaterialVo">
        select
        m.id,
        m.company_id,
        c.company_name,
        m.apply_id,
        m.file_url,
        m.file_name,
        m.file_size,
        m.file_type,
        m.sort_order,
        m.create_time,
        m.deleted
        from doctor_level_material m
        left join company c on c.company_id = m.company_id
    </sql>

    <select id="selectDoctorLevelMaterialList" parameterType="DoctorLevelMaterial" resultMap="DoctorLevelMaterialResult">
        <include refid="selectDoctorLevelMaterialVo"/>
        <where>
            <if test="companyId != null"> and m.company_id = #{companyId}</if>
            <if test="applyId != null"> and m.apply_id = #{applyId}</if>
            <if test="fileUrl != null and fileUrl != ''"> and m.file_url = #{fileUrl}</if>
            <if test="fileName != null and fileName != ''"> and m.file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileSize != null"> and m.file_size = #{fileSize}</if>
            <if test="fileType != null and fileType != ''"> and m.file_type = #{fileType}</if>
            <if test="sortOrder != null"> and m.sort_order = #{sortOrder}</if>
            <if test="deleted != null"> and m.deleted = #{deleted}</if>
        </where>
        order by m.create_time desc

    </select>
    
    <select id="selectDoctorLevelMaterialById" parameterType="Long" resultMap="DoctorLevelMaterialResult">
        <include refid="selectDoctorLevelMaterialVo"/>
        where m.id = #{id}
    </select>
        
    <insert id="insertDoctorLevelMaterial" parameterType="DoctorLevelMaterial" useGeneratedKeys="true" keyProperty="id">
        insert into doctor_level_material
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="applyId != null">apply_id,</if>
            <if test="fileUrl != null and fileUrl != ''">file_url,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="fileType != null">file_type,</if>
            <if test="sortOrder != null">sort_order,</if>
            <if test="createTime != null">create_time,</if>
            <if test="deleted != null">deleted,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="applyId != null">#{applyId},</if>
            <if test="fileUrl != null and fileUrl != ''">#{fileUrl},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="fileType != null">#{fileType},</if>
            <if test="sortOrder != null">#{sortOrder},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="deleted != null">#{deleted},</if>
         </trim>
    </insert>

    <update id="updateDoctorLevelMaterial" parameterType="DoctorLevelMaterial">
        update doctor_level_material
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="applyId != null">apply_id = #{applyId},</if>
            <if test="fileUrl != null and fileUrl != ''">file_url = #{fileUrl},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="fileType != null">file_type = #{fileType},</if>
            <if test="sortOrder != null">sort_order = #{sortOrder},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="deleted != null">deleted = #{deleted},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDoctorLevelMaterialById" parameterType="Long">
        delete from doctor_level_material where id = #{id}
    </delete>

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



    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO doctor_level_material
        (company_id, apply_id, file_url, file_name, file_size, file_type, sort_order, deleted)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.companyId}, #{item.applyId}, #{item.fileUrl},
            #{item.fileName}, #{item.fileSize}, #{item.fileType},
            #{item.sortOrder}, #{item.deleted})
        </foreach>
    </insert>



    <delete id="deleteDoctorLevelMaterialByDoctorLevelApplyIds">
        delete from doctor_level_material
        where apply_id in
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>






</mapper>