<?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.IitFileInfoMapper">

    <resultMap type="IitFileInfo" id="IitFileInfoResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileType"    column="file_type"    />
        <result property="fileSize"    column="file_size"    />
        <result property="filePath"    column="file_path"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="remark"    column="remark"    />
        <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="pushTimes"    column="push_times"    />
    </resultMap>

    <sql id="selectIitFileInfoVo">
        select id, name, file_name, file_type, file_size, file_path, file_url, remark, create_time, user_id, user_name, dept_id,push_times from iit_file_info
    </sql>

    <select id="selectIitFileInfoList" parameterType="IitFileInfo" resultMap="IitFileInfoResult">
        select
            u.id, u.name, u.file_name,u.file_type, u.file_size, u.file_path,
            u.file_url, u.remark, u.create_time, u.user_id, u.user_name, u.dept_id,u.push_times
        from iit_file_info u
        where  1 = 1
        <if test="name != null  and name != ''"> and u.name like concat('%', #{name}, '%')</if>
        <if test="fileName != null  and fileName != ''"> and u.file_name like concat('%', #{fileName}, '%')</if>
        <if test="fileType != null "> and u.file_type = #{fileType}</if>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by u.create_time desc
    </select>

    <select id="selectMyselfList" parameterType="IitFileInfo" resultMap="IitFileInfoResult">
        select
            u.id, u.name, u.file_name,u.file_type, u.file_size, u.file_path,
            u.file_url, u.remark, u.create_time, u.user_id, u.user_name, u.dept_id,u.push_times
        from iit_file_info u
        INNER JOIN  iit_myself_file m on u.id = m.file_id
        WHERE m.user_id = #{userId}
        <if test="name != null  and name != ''"> and u.name like concat('%', #{name}, '%')</if>
        <if test="fileName != null  and fileName != ''"> and u.file_name like concat('%', #{fileName}, '%')</if>
        <if test="fileType != null "> and u.file_type = #{fileType}</if>
        order by u.create_time desc
    </select>

    <select id="selectIitFileInfoById" parameterType="Long" resultMap="IitFileInfoResult">
        <include refid="selectIitFileInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertIitFileInfo" parameterType="IitFileInfo" useGeneratedKeys="true" keyProperty="id">
        insert into iit_file_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileType != null">file_type,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="filePath != null">file_path,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="remark != null">remark,</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>
            <if test="pushTimes != null">push_times,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileType != null">#{fileType},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="filePath != null">#{filePath},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="remark != null">#{remark},</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>
            <if test="pushTimes != null">#{pushTimes},</if>
        </trim>
    </insert>

    <update id="updateIitFileInfo" parameterType="IitFileInfo">
        update iit_file_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileType != null">file_type = #{fileType},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="filePath != null">file_path = #{filePath},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="remark != null">remark = #{remark},</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>
            <if test="pushTimes != null">push_times = #{pushTimes},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIitFileInfoById" parameterType="Long">
        delete from iit_file_info where id = #{id}
    </delete>

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

    <update id="updatePushTimes" parameterType="Long">
        update iit_file_info set push_times = push_times + 1 where id = #{id}
    </update>
</mapper>
