<?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.shiftmgr.mapper.TShiftAccidentMapper">
    
    <resultMap type="TShiftAccident" id="TShiftAccidentResult">
        <result property="id"    column="id"    />
        <result property="accidentId"    column="accident_id"    />
        <result property="personLiable"    column="person_liable"    />
        <result property="reporter"    column="reporter"    />
        <result property="reportDate"    column="report_date"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <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="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTShiftAccidentVo">
        select d.id, d.accident_id, d.person_liable, d.reporter, d.report_date, d.title, d.content, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id from t_shift_accident d
    </sql>

    <select id="selectTShiftAccidentList" parameterType="TShiftAccident" resultMap="TShiftAccidentResult">
        <include refid="selectTShiftAccidentVo"/>
        <where>  
            <if test="accidentId != null  and accidentId != ''"> and accident_id = #{accidentId}</if>
            <if test="personLiable != null  and personLiable != ''"> and person_liable = #{personLiable}</if>
            <if test="reporter != null  and reporter != ''"> and reporter = #{reporter}</if>
            <if test="reportDate != null "> and report_date = #{reportDate}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTShiftAccidentById" parameterType="Long" resultMap="TShiftAccidentResult">
        <include refid="selectTShiftAccidentVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTShiftAccident" parameterType="TShiftAccident">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT SEQ_T_SHIFT_ACCIDENT.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_shift_accident
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="accidentId != null">accident_id,</if>
            <if test="personLiable != null">person_liable,</if>
            <if test="reporter != null">reporter,</if>
            <if test="reportDate != null">report_date,</if>
            <if test="title != null">title,</if>
            <if test="content != null">content,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="accidentId != null">#{accidentId},</if>
            <if test="personLiable != null">#{personLiable},</if>
            <if test="reporter != null">#{reporter},</if>
            <if test="reportDate != null">#{reportDate},</if>
            <if test="title != null">#{title},</if>
            <if test="content != null">#{content},</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>
         </trim>
    </insert>

    <update id="updateTShiftAccident" parameterType="TShiftAccident">
        update t_shift_accident
        <trim prefix="SET" suffixOverrides=",">
            <if test="accidentId != null">accident_id = #{accidentId},</if>
            <if test="personLiable != null">person_liable = #{personLiable},</if>
            <if test="reporter != null">reporter = #{reporter},</if>
            <if test="reportDate != null">report_date = #{reportDate},</if>
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</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>
        </trim>
        where id = #{id}
    </update>

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

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