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

    <resultMap type="GuidanceFile" id="GuidanceFileResult">
        <result property="fileId" column="file_id"/>
        <result property="fileName" column="file_name"/>
        <result property="fileUrl" column="file_url"/>
        <result property="fileType" column="file_type"/>
        <result property="guidanceId" column="guidance_id"/>
        <result property="createTime" column="create_time"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>

    <sql id="selectGuidanceFileVo">
        select file_id, file_name, file_url, file_type, guidance_id, create_time, del_flag from guidance_file
    </sql>

    <select id="selectGuidanceFileList" parameterType="GuidanceFile" resultMap="GuidanceFileResult">
        <include refid="selectGuidanceFileVo"/>
        <where>
            <if test="fileName != null  and fileName != ''">and file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileUrl != null  and fileUrl != ''">and file_url = #{fileUrl}</if>
            <if test="fileType != null  and fileType != ''">and file_type = #{fileType}</if>
            <if test="guidanceId != null ">and guidance_id = #{guidanceId}</if>
            and del_flag = 0
        </where>
    </select>

    <select id="selectGuidanceFileById" parameterType="String" resultMap="GuidanceFileResult">
        <include refid="selectGuidanceFileVo"/>
        where file_id = #{fileId}
    </select>
    <select id="selectGuidanceFileByGuidanceId" parameterType="String" resultMap="GuidanceFileResult">
        <include refid="selectGuidanceFileVo"/>
        where guidance_id = #{guidanceId} and del_flag = 0
    </select>
    <insert id="insertGuidanceFile" parameterType="GuidanceFile">
        insert into guidance_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fileId != null  and fileId != ''">file_id,</if>
            <if test="fileName != null  and fileName != ''">file_name,</if>
            <if test="fileUrl != null  and fileUrl != ''">file_url,</if>
            <if test="fileType != null  and fileType != ''">file_type,</if>
            <if test="guidanceId != null ">guidance_id,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="delFlag != null  and delFlag != ''">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fileId != null  and fileId != ''">#{fileId},</if>
            <if test="fileName != null  and fileName != ''">#{fileName},</if>
            <if test="fileUrl != null  and fileUrl != ''">#{fileUrl},</if>
            <if test="fileType != null  and fileType != ''">#{fileType},</if>
            <if test="guidanceId != null ">#{guidanceId},</if>
            sysdate(),
            <if test="delFlag != null  and delFlag != ''">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updateGuidanceFile" parameterType="GuidanceFile">
        update guidance_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="fileName != null  and fileName != ''">file_name = #{fileName},</if>
            <if test="fileUrl != null  and fileUrl != ''">file_url = #{fileUrl},</if>
            <if test="fileType != null  and fileType != ''">file_type = #{fileType},</if>
            <if test="guidanceId != null ">guidance_id = #{guidanceId},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="delFlag != null  and delFlag != ''">del_flag = #{delFlag},</if>
        </trim>
        where file_id = #{fileId}
    </update>

    <delete id="deleteGuidanceFileById" parameterType="String">
        delete from guidance_file where file_id = #{fileId}
    </delete>

    <delete id="deleteGuidanceFileByIds" parameterType="String">
        update guidance_file set del_flag=1 where file_id in
        <foreach item="fileId" collection="array" open="(" separator="," close=")">
            #{fileId}
        </foreach>
    </delete>

</mapper>