<?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.project.document.mapper.TPlantproglistFileMapper">
    
    <resultMap type="TPlantproglistFile" id="TPlantproglistFileResult">
        <result property="id"    column="id"    />
        <result property="plantproglistId"    column="plantproglist_id"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTPlantproglistFileVo">
        select d.id, d.plantproglist_id, d.file_name, d.file_url, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, p.filename from t_plantproglist_file d
      left join t_plantproglist p on p.id = d.plantproglist_id
    </sql>

    <select id="selectTPlantproglistFileList" parameterType="TPlantproglistFile" resultMap="TPlantproglistFileResult">
        <include refid="selectTPlantproglistFileVo"/>
        <where>  
            <if test="plantproglistId != null "> and plantproglist_id = #{plantproglistId}</if>
            and d.del_flag = 0
        </where>
    </select>
    
    <select id="selectTPlantproglistFileById" parameterType="Long" resultMap="TPlantproglistFileResult">
        <include refid="selectTPlantproglistFileVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTPlantproglistFile" parameterType="TPlantproglistFile">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_plantproglist_file.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_plantproglist_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantproglistId != null">plantproglist_id,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantproglistId != null">#{plantproglistId},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTPlantproglistFile" parameterType="TPlantproglistFile">
        update t_plantproglist_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantproglistId != null">plantproglist_id = #{plantproglistId},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTPlantproglistFileById" parameterType="Long">
        update t_plantproglist_file set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTPlantproglistFileByIds" parameterType="String">
        update t_plantproglist_file set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>