<?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.common.mapper.TCommonfileMapper">

    <resultMap type="TCommonfile" id="TCommonfileResult">
        <result property="id"    column="id"    />
        <result property="pId"    column="p_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"    />
        <result property="pType"    column="p_type"    />
        <result property="creator"    column="nick_name"    />
        <result property="fileSize"    column="file_size"    />
        <result property="pValue"    column="p_value"    />
        <result property="pDate"    column="p_date"    />

    </resultMap>

    <sql id="selectTCommonfileVo">
        select d.id, d.p_value, d.p_date , d.p_id, d.file_name, d.file_url, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.p_type ,s.dept_name from t_commonfile d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTCommonfileList" parameterType="TCommonfile" resultMap="TCommonfileResult">
        <include refid="selectTCommonfileVo"/>
        <where>
            <if test="pId != null "> and p_id = #{pId}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat(concat('%', #{fileName}), '%')</if>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="pType != null  and pType != ''"> and p_type = #{pType}</if>
            <if test="pValue != null  and pValue != ''"> and p_value = #{pValue}</if>
            <if test="pDate != null "> and p_date = #{pDate}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTCommonfileById" parameterType="Long" resultMap="TCommonfileResult">
        <include refid="selectTCommonfileVo"/>
        where id = #{id}
    </select>

    <select id="selectAllFileList" parameterType="TCommonfile" resultMap="TCommonfileResult">
        select d.file_size , d.p_value, d.p_date ,u.nick_name, d.id, d.p_id, d.file_name, d.file_url, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.p_type from t_commonfile d
        LEFT JOIN SYS_USER u on d.CREATER_CODE = u.USER_ID
        <where>
            <if test="pId != null "> and p_id = #{pId}</if>
            <if test="pType != null "> and p_type = #{pType}</if>
            <if test="pValue != null  and pValue != ''"> and p_value = #{pValue}</if>
            <if test="pDate != null "> and p_date = #{pDate}</if>
            and d.del_flag = 0
        </where>
        order by p_date desc , d.createdate desc
    </select>

    <insert id="insertTCommonfile" parameterType="TCommonfile">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_commonfile.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_commonfile
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="pId != null">p_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>
            <if test="pType != null">p_type,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="pValue != null">p_value,</if>
            <if test="pDate != null">p_date,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="pId != null">#{pId},</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>
            <if test="pType != null">#{pType},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="pValue != null">#{pValue},</if>
            <if test="pDate != null">#{pDate},</if>
        </trim>
    </insert>

    <update id="updateTCommonfile" parameterType="TCommonfile">
        update t_commonfile
        <trim prefix="SET" suffixOverrides=",">
            <if test="pId != null">p_id = #{pId},</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>
            <if test="pType != null">p_type = #{pType},</if>
            <if test="pValue != null">p_value = #{pValue},</if>
            <if test="pDate != null">p_date = #{pDate},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
