<?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.TApproveDangerMapper">
    
    <resultMap type="TApproveDanger" id="TApproveDangerResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="recorderId"    column="recorder_id"    />
        <result property="executorId"    column="executor_id"    />
        <result property="verificationId"    column="verification_id"    />
        <result property="confirmoneId"    column="confirmone_id"    />
        <result property="confirmtwoId"    column="confirmtwo_id"    />
        <result property="hiddendangerLevel"    column="hiddendanger_level"    />
        <result property="hiddendangerContent"    column="hiddendanger_content"    />
        <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" />
        <result property="discoveryTime"    column="discovery_time"    />
        <result property="remarks"    column="remarks"    />
        <result property="participants"    column="participants"    />
        <result property="dangerSort"    column="danger_sort"    />
        <result property="url"    column="url"    />
        <result property="filename"    column="filename"    />
        <result property="beforeUrl"    column="before_url"    />
        <result property="beforeFilename"    column="before_filename"    />
        <result property="afterUrl"    column="after_url"    />
        <result property="afterFilename"    column="after_filename"    />
    </resultMap>

    <sql id="selectTApproveDangerVo">
        select d.id, d.plant_code, d.recorder_id, d.hiddendanger_level, d.hiddendanger_content, d.measures, d.complete_time, d.status, d.creattime, d.endtime, d.process_id, d.approve_no, d.dept_id, d.del_flag, d.executor_id, d.verification_id, d.confirmone_id, d.confirmtwo_id, d.discovery_time, d.remarks, d.participants, d.danger_sort, d.url, d.filename, d.before_url, d.before_filename, d.after_url, d.after_filename ,s.dept_name from t_approve_danger d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTApproveDangerList" parameterType="TApproveDanger" resultMap="TApproveDangerResult">
        <include refid="selectTApproveDangerVo"/>
        <where>
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="recorderId != null "> and recorder_id = #{recorderId}</if>
            <if test="hiddendangerLevel != null "> and hiddendanger_level = #{hiddendangerLevel}</if>
            <if test="hiddendangerContent != null  and hiddendangerContent != ''"> and hiddendanger_content = #{hiddendangerContent}</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>
            <if test="executorId != null "> and executor_id = #{executorId}</if>
            <if test="verificationId != null "> and verification_id = #{verificationId}</if>
            <if test="confirmoneId != null "> and confirmone_id = #{confirmoneId}</if>
            <if test="confirmtwoId != null "> and confirmtwo_id = #{confirmtwoId}</if>
            <if test="discoveryTime != null "> and discovery_time = #{discoveryTime}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="participants != null  and participants != ''"> and participants = #{participants}</if>
            <if test="dangerSort != null "> and danger_sort = #{dangerSort}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="filename != null  and filename != ''"> and filename = #{filename}</if>
            <if test="beforeUrl != null  and beforeUrl != ''"> and before_url = #{beforeUrl}</if>
            <if test="beforeFilename != null  and beforeFilename != ''"> and before_filename = #{beforeFilename}</if>
            <if test="afterUrl != null  and afterUrl != ''"> and after_url = #{afterUrl}</if>
            <if test="afterFilename != null  and afterFilename != ''"> and after_filename = #{afterFilename}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTApproveDangerById" parameterType="Long" resultMap="TApproveDangerResult">
        <include refid="selectTApproveDangerVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTApproveDanger" parameterType="TApproveDanger">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_approve_danger.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_approve_danger
        <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="executorId != null">executor_id,</if>
            <if test="verificationId != null">verification_id,</if>
            <if test="confirmoneId != null">confirmone_id,</if>
            <if test="confirmtwoId != null">confirmtwo_id,</if>
            <if test="hiddendangerLevel != null">hiddendanger_level,</if>
            <if test="hiddendangerContent != null and hiddendangerContent != ''">hiddendanger_content,</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>
            <if test="discoveryTime != null">discovery_time,</if>
            <if test="remarks != null">remarks,</if>
            <if test="participants != null">participants,</if>
            <if test="dangerSort != null">danger_sort,</if>
            <if test="url != null">url,</if>
            <if test="filename != null">filename,</if>
            <if test="beforeUrl != null">before_url,</if>
            <if test="beforeFilename != null">before_filename,</if>
            <if test="afterUrl != null">after_url,</if>
            <if test="afterFilename != null">after_filename,</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="executorId != null">#{executorId},</if>
            <if test="verificationId != null">#{verificationId},</if>
            <if test="confirmoneId != null">#{confirmoneId},</if>
            <if test="confirmtwoId != null">#{confirmtwoId},</if>
            <if test="hiddendangerLevel != null">#{hiddendangerLevel},</if>
            <if test="hiddendangerContent != null and hiddendangerContent != ''">#{hiddendangerContent},</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>
            <if test="discoveryTime != null">#{discoveryTime},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="participants != null">#{participants},</if>
            <if test="dangerSort != null">#{dangerSort},</if>
            <if test="url != null">#{url},</if>
            <if test="filename != null">#{filename},</if>
            <if test="beforeUrl != null">#{beforeUrl},</if>
            <if test="beforeFilename != null">#{beforeFilename},</if>
            <if test="afterUrl != null">#{afterUrl},</if>
            <if test="afterFilename != null">#{afterFilename},</if>
         </trim>
    </insert>

    <update id="updateTApproveDanger" parameterType="TApproveDanger">
        update t_approve_danger
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="recorderId != null">recorder_id = #{recorderId},</if>
            <if test="executorId != null">executor_id = #{executorId},</if>
            <if test="verificationId != null">verification_id = #{verificationId},</if>
            <if test="confirmoneId != null">confirmone_id = #{confirmoneId},</if>
            <if test="confirmtwoId != null">confirmtwo_id = #{confirmtwoId},</if>
            <if test="hiddendangerLevel != null">hiddendanger_level = #{hiddendangerLevel},</if>
            <if test="hiddendangerContent != null and hiddendangerContent != ''">hiddendanger_content = #{hiddendangerContent},</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>
            <if test="discoveryTime != null">discovery_time = #{discoveryTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="participants != null">participants = #{participants},</if>
            <if test="dangerSort != null">danger_sort = #{dangerSort},</if>
            <if test="url != null">url = #{url},</if>
            <if test="filename != null">filename = #{filename},</if>
            <if test="beforeUrl != null">before_url = #{beforeUrl},</if>
            <if test="beforeFilename != null">before_filename = #{beforeFilename},</if>
            <if test="afterUrl != null">after_url = #{afterUrl},</if>
            <if test="afterFilename != null">after_filename = #{afterFilename},</if>
        </trim>
        where id = #{id}
    </update>

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

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