<?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.cpms.project.safety.mapper.TSafetyFilesMapper">

    <resultMap type="TSafetyFiles" id="TSafetyFilesResult">
        <result property="id"    column="id"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="fileName"    column="file_name"    />
        <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="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTSafetyFilesVo">
        select id, file_url, file_name, del_flag, creater_code, createdate, updater_code, updatedate, dept_id, remarks from t_safety_files
    </sql>

    <select id="selectTSafetyFilesList" parameterType="TSafetyFiles" resultMap="TSafetyFilesResult">
        <include refid="selectTSafetyFilesVo"/>
        <where>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</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="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        and del_flag = 0
        </where>
    </select>

    <select id="selectTSafetyFilesById" parameterType="Long" resultMap="TSafetyFilesResult">
        <include refid="selectTSafetyFilesVo"/>
        where id= #{id}
    </select>

    <insert id="insertTSafetyFiles" parameterType="TSafetyFiles" useGeneratedKeys="true" keyProperty="id">
        insert into t_safety_files
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fileUrl != null and fileUrl != ''">file_url,</if>
            <if test="fileName != null and fileName != ''">file_name,</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="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fileUrl != null and fileUrl != ''">#{fileUrl},</if>
            <if test="fileName != null and fileName != ''">#{fileName},</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="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTSafetyFiles" parameterType="TSafetyFiles">
        update t_safety_files
        <trim prefix="SET" suffixOverrides=",">
            <if test="fileUrl != null and fileUrl != ''">file_url = #{fileUrl},</if>
            <if test="fileName != null and fileName != ''">file_name = #{fileName},</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="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTSafetyFilesById" parameterType="Long">
        update t_safety_files set del_flag=1 where id = #{id}
    </delete>

    <delete id="deleteTSafetyFilesByIds" parameterType="String">
        update t_safety_files set del_flag=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
