<?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.system.mapper.TUploadhistoryMapper">
    
    <resultMap type="TUploadhistory" id="TUploadhistoryResult">
        <result property="id"    column="id"    />
        <result property="uploadCode"    column="upload_code"    />
        <result property="uploadDate"    column="upload_date"    />
        <result property="uploadType"    column="upload_type"    />
        <result property="content"    column="content"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTUploadhistoryVo">
        select d.id, d.upload_code, d.upload_date, d.upload_type, d.content, d.dept_id ,s.dept_name from t_uploadhistory d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTUploadhistoryList" parameterType="TUploadhistory" resultMap="TUploadhistoryResult">
        <include refid="selectTUploadhistoryVo"/>
        <where>  
            <if test="uploadCode != null  and uploadCode != ''"> and upload_code = #{uploadCode}</if>
            <if test="uploadDate != null "> and upload_date = #{uploadDate}</if>
            <if test="uploadType != null  and uploadType != ''"> and upload_type = #{uploadType}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTUploadhistoryById" parameterType="Long" resultMap="TUploadhistoryResult">
        <include refid="selectTUploadhistoryVo"/>
        where id = #{id}
    </select>

    <insert id="insertTUploadhistory" parameterType="TUploadhistory">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_uploadhistory.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_uploadhistory
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="uploadCode != null">upload_code,</if>
            <if test="uploadDate != null">upload_date,</if>
            <if test="uploadType != null">upload_type,</if>
            <if test="content != null">content,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="uploadCode != null">#{uploadCode},</if>
            <if test="uploadDate != null">#{uploadDate},</if>
            <if test="uploadType != null">#{uploadType},</if>
            <if test="content != null">#{content},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateTUploadhistory" parameterType="TUploadhistory">
        update t_uploadhistory
        <trim prefix="SET" suffixOverrides=",">
            <if test="uploadCode != null">upload_code = #{uploadCode},</if>
            <if test="uploadDate != null">upload_date = #{uploadDate},</if>
            <if test="uploadType != null">upload_type = #{uploadType},</if>
            <if test="content != null">content = #{content},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>
    
</mapper>