<?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.sems.mapper.TReportThirdMapper">

    <resultMap type="TReportThird" id="TReportThirdResult">
        <result property="id" column="id"/>
        <result property="plantCode" column="plant_code"/>
        <result property="year" column="year"/>
        <result property="fileName" column="file_name"/>
        <result property="filePath" column="file_path"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="type" column="type"/>
        <result property="deptName" column="dept_name"/>
        <result property="delFlag" column="del_flag"/>
        <result property="deptId" column="dept_id"/>
    </resultMap>

    <sql id="selectTReportThirdVo">
        select d.id,
               d.plant_code,
               d.year,
               d.file_name,
               d.file_path,
               d.create_by,
               d.create_time,
               d.update_by,
               d.update_time,
               d.del_flag,
               d.dept_id,
               d.type
        from t_report_third d
    </sql>

    <select id="selectTReportThirdList" parameterType="TReportThird" resultMap="TReportThirdResult">
        <include refid="selectTReportThirdVo"/>
        <where>
            <if test="type != null  and type != ''">and type = #{type}</if>
            and del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScopePlant}
    </select>

    <select id="selectTReportThirdById" parameterType="Long" resultMap="TReportThirdResult">
        <include refid="selectTReportThirdVo"/>
        where id = #{id}
        and del_flag = 0
    </select>

    <insert id="insertTReportThird" parameterType="TReportThird">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_report_third.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_report_third
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null">plant_code,</if>
            <if test="year != null">year,</if>
            <if test="fileName != null">file_name,</if>
            <if test="filePath != null">file_path,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="type != null">type,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null">#{plantCode},</if>
            <if test="year != null">#{year},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="filePath != null">#{filePath},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="type != null">#{type},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateTReportThird" parameterType="TReportThird">
        update t_report_third
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null">plant_code = #{plantCode},</if>
            <if test="year != null">year = #{year},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="filePath != null">file_path = #{filePath},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
        and del_flag = 0
    </update>

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

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

</mapper>
