<?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.ehs.mapper.TApproveAccidentMapper">
    
    <resultMap type="TApproveAccident" id="TApproveAccidentResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="recorderId"    column="recorder_id"    />
        <result property="confirmoneId"    column="confirmone_id"    />
        <result property="confirmtwoId"    column="confirmtwo_id"    />
        <result property="executorId"    column="executor_id"    />
        <result property="verificationId"    column="verification_id"    />
        <result property="managerconId"    column="managercon_id"    />
        <result property="directorconId"    column="directorcon_id"    />
        <result property="ctsmanagerId"    column="ctsmanager_id"    />
        <result property="ctsdirectorId"    column="ctsdirector_id"    />
        <result property="accidentLevel"    column="accident_level"    />
        <result property="accidentContent"    column="accident_content"    />
        <result property="accidentSort"    column="accident_sort"    />
        <result property="rescue"    column="rescue"    />
        <result property="involve"    column="involve"    />
        <result property="measures"    column="measures"    />
        <result property="completeTime"    column="complete_time"    />
        <result property="status"    column="status"    />
        <result property="creattime"    column="creattime"    />
        <result property="endtime"    column="endtime"    />
        <result property="processId"    column="process_id"    />
        <result property="approveNo"    column="approve_no"    />
        <result property="deptId"    column="dept_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTApproveAccidentVo">
        select d.id, d.plant_code, d.recorder_id, d.confirmone_id, d.confirmtwo_id, d.executor_id, d.verification_id, d.managercon_id, d.directorcon_id, d.ctsmanager_id, d.ctsdirector_id, d.accident_level, d.accident_content, d.accident_sort, d.rescue, d.involve, d.measures, d.complete_time, d.status, d.creattime, d.endtime, d.process_id, d.approve_no, d.dept_id, d.del_flag ,s.dept_name from t_approve_accident d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTApproveAccidentList" parameterType="TApproveAccident" resultMap="TApproveAccidentResult">
        <include refid="selectTApproveAccidentVo"/>
        <where>  
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="recorderId != null "> and recorder_id = #{recorderId}</if>
            <if test="confirmoneId != null "> and confirmone_id = #{confirmoneId}</if>
            <if test="confirmtwoId != null "> and confirmtwo_id = #{confirmtwoId}</if>
            <if test="executorId != null "> and executor_id = #{executorId}</if>
            <if test="verificationId != null "> and verification_id = #{verificationId}</if>
            <if test="managerconId != null "> and managercon_id = #{managerconId}</if>
            <if test="directorconId != null "> and directorcon_id = #{directorconId}</if>
            <if test="ctsmanagerId != null "> and ctsmanager_id = #{ctsmanagerId}</if>
            <if test="ctsdirectorId != null "> and ctsdirector_id = #{ctsdirectorId}</if>
            <if test="accidentLevel != null "> and accident_level = #{accidentLevel}</if>
            <if test="accidentContent != null  and accidentContent != ''"> and accident_content = #{accidentContent}</if>
            <if test="accidentSort != null  and accidentSort != ''"> and accident_sort = #{accidentSort}</if>
            <if test="rescue != null  and rescue != ''"> and rescue = #{rescue}</if>
            <if test="involve != null  and involve != ''"> and involve = #{involve}</if>
            <if test="measures != null  and measures != ''"> and measures = #{measures}</if>
            <if test="completeTime != null "> and complete_time = #{completeTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="creattime != null "> and creattime = #{creattime}</if>
            <if test="endtime != null "> and endtime = #{endtime}</if>
            <if test="processId != null "> and process_id = #{processId}</if>
            <if test="approveNo != null  and approveNo != ''"> and approve_no = #{approveNo}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTApproveAccidentById" parameterType="Long" resultMap="TApproveAccidentResult">
        <include refid="selectTApproveAccidentVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTApproveAccident" parameterType="TApproveAccident">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_approve_accident.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_approve_accident
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="recorderId != null">recorder_id,</if>
            <if test="confirmoneId != null">confirmone_id,</if>
            <if test="confirmtwoId != null">confirmtwo_id,</if>
            <if test="executorId != null">executor_id,</if>
            <if test="verificationId != null">verification_id,</if>
            <if test="managerconId != null">managercon_id,</if>
            <if test="directorconId != null">directorcon_id,</if>
            <if test="ctsmanagerId != null">ctsmanager_id,</if>
            <if test="ctsdirectorId != null">ctsdirector_id,</if>
            <if test="accidentLevel != null">accident_level,</if>
            <if test="accidentContent != null and accidentContent != ''">accident_content,</if>
            <if test="accidentSort != null and accidentSort != ''">accident_sort,</if>
            <if test="rescue != null and rescue != ''">rescue,</if>
            <if test="involve != null and involve != ''">involve,</if>
            <if test="measures != null and measures != ''">measures,</if>
            <if test="completeTime != null">complete_time,</if>
            <if test="status != null">status,</if>
            <if test="creattime != null">creattime,</if>
            <if test="endtime != null">endtime,</if>
            <if test="processId != null">process_id,</if>
            <if test="approveNo != null and approveNo != ''">approve_no,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="recorderId != null">#{recorderId},</if>
            <if test="confirmoneId != null">#{confirmoneId},</if>
            <if test="confirmtwoId != null">#{confirmtwoId},</if>
            <if test="executorId != null">#{executorId},</if>
            <if test="verificationId != null">#{verificationId},</if>
            <if test="managerconId != null">#{managerconId},</if>
            <if test="directorconId != null">#{directorconId},</if>
            <if test="ctsmanagerId != null">#{ctsmanagerId},</if>
            <if test="ctsdirectorId != null">#{ctsdirectorId},</if>
            <if test="accidentLevel != null">#{accidentLevel},</if>
            <if test="accidentContent != null and accidentContent != ''">#{accidentContent},</if>
            <if test="accidentSort != null and accidentSort != ''">#{accidentSort},</if>
            <if test="rescue != null and rescue != ''">#{rescue},</if>
            <if test="involve != null and involve != ''">#{involve},</if>
            <if test="measures != null and measures != ''">#{measures},</if>
            <if test="completeTime != null">#{completeTime},</if>
            <if test="status != null">#{status},</if>
            <if test="creattime != null">#{creattime},</if>
            <if test="endtime != null">#{endtime},</if>
            <if test="processId != null">#{processId},</if>
            <if test="approveNo != null and approveNo != ''">#{approveNo},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateTApproveAccident" parameterType="TApproveAccident">
        update t_approve_accident
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="recorderId != null">recorder_id = #{recorderId},</if>
            <if test="confirmoneId != null">confirmone_id = #{confirmoneId},</if>
            <if test="confirmtwoId != null">confirmtwo_id = #{confirmtwoId},</if>
            <if test="executorId != null">executor_id = #{executorId},</if>
            <if test="verificationId != null">verification_id = #{verificationId},</if>
            <if test="managerconId != null">managercon_id = #{managerconId},</if>
            <if test="directorconId != null">directorcon_id = #{directorconId},</if>
            <if test="ctsmanagerId != null">ctsmanager_id = #{ctsmanagerId},</if>
            <if test="ctsdirectorId != null">ctsdirector_id = #{ctsdirectorId},</if>
            <if test="accidentLevel != null">accident_level = #{accidentLevel},</if>
            <if test="accidentContent != null and accidentContent != ''">accident_content = #{accidentContent},</if>
            <if test="accidentSort != null and accidentSort != ''">accident_sort = #{accidentSort},</if>
            <if test="rescue != null and rescue != ''">rescue = #{rescue},</if>
            <if test="involve != null and involve != ''">involve = #{involve},</if>
            <if test="measures != null and measures != ''">measures = #{measures},</if>
            <if test="completeTime != null">complete_time = #{completeTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="creattime != null">creattime = #{creattime},</if>
            <if test="endtime != null">endtime = #{endtime},</if>
            <if test="processId != null">process_id = #{processId},</if>
            <if test="approveNo != null and approveNo != ''">approve_no = #{approveNo},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

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

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