<?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.iit.mapper.IitFilePushMapper">

    <resultMap type="IitFilePush" id="IitFilePushResult">
        <result property="id"    column="id"    />
        <result property="fileId"    column="file_id"    />
        <result property="userNumber"    column="user_number"    />
        <result property="createTime"    column="create_time"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="deptId"    column="dept_id"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileType"    column="file_type"    />
        <result property="fileRemark"    column="remark"    />
    </resultMap>

    <sql id="selectIitFilePushVo">
        select id, file_id, user_number, create_time, user_id, user_name, dept_id from iit_file_push
    </sql>

    <select id="selectIitFilePushList" parameterType="IitFilePush" resultMap="IitFilePushResult">
        SELECT
            u.id,
            u.file_id,
            u.user_number,
            u.create_time,
            u.user_id,
            u.user_name,
            u.dept_id,
            i.file_name,
            i.file_type,
            i.remark
        FROM
            iit_file_push u
        LEFT JOIN
            iit_file_info i on u.file_id = i.id
        WHERE 1 = 1
        <if test="fileName != null  and fileName != ''"> and i.file_name like concat('%', #{fileName}, '%')</if>
        <if test="fileType != null "> and i.file_type = #{fileType}</if>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by u.create_time desc
    </select>

    <select id="selectIitFilePushById" parameterType="Long" resultMap="IitFilePushResult">
        <include refid="selectIitFilePushVo"/>
        where id = #{id}
    </select>

    <insert id="insertIitFilePush" parameterType="IitFilePush" useGeneratedKeys="true" keyProperty="id">
        insert into iit_file_push
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="fileId != null">file_id,</if>
            <if test="userNumber != null">user_number,</if>
            <if test="createTime != null">create_time,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="fileId != null">#{fileId},</if>
            <if test="userNumber != null">#{userNumber},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateIitFilePush" parameterType="IitFilePush">
        update iit_file_push
        <trim prefix="SET" suffixOverrides=",">
            <if test="fileId != null">file_id = #{fileId},</if>
            <if test="userNumber != null">user_number = #{userNumber},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIitFilePushById" parameterType="Long">
        delete from iit_file_push where id = #{id}
    </delete>

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