<?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.reliability.mapper.TDeviceRiskMapper">
    
    <resultMap type="TDeviceRisk" id="TDeviceRiskResult">
        <result property="id"    column="id"    />
        <result property="remarks"    column="remarks"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="area"    column="area"    />
        <result property="diskLevel"    column="disk_level"    />
        <result property="reason"    column="reason"    />
        <result property="handleType"    column="handle_type"    />
        <result property="disk"    column="disk"    />
        <result property="discoveryDate"    column="discovery_date"    />
        <result property="planRemoveDate"    column="plan_remove_date"    />
        <result property="actualDate"    column="actual_date"    />
        <result property="handleMethods"    column="handle_methods"    />
        <result property="emergencyPlan"    column="emergency_plan"    />

    </resultMap>

    <sql id="selectTDeviceRiskVo">
        select d.id, d.remarks, d.del_flag, d.area, d.disk_level, d.reason, d.handle_type, d.disk, d.discovery_date, d.plan_remove_date, d.actual_date, d.handle_methods, d.emergency_plan  from t_device_risk d

    </sql>

    <select id="selectTDeviceRiskList" parameterType="TDeviceRisk" resultMap="TDeviceRiskResult">
        <include refid="selectTDeviceRiskVo"/>
        <where>  
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="area != null  and area != ''"> and area = #{area}</if>
            <if test="diskLevel != null "> and disk_level = #{diskLevel}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="handleType != null "> and handle_type = #{handleType}</if>
            <if test="disk != null  and disk != ''"> and disk = #{disk}</if>
            <if test="discoveryDate != null "> and discovery_date = #{discoveryDate}</if>
            <if test="planRemoveDate != null "> and plan_remove_date = #{planRemoveDate}</if>
            <if test="actualDate != null "> and actual_date = #{actualDate}</if>
            <if test="handleMethods != null  and handleMethods != ''"> and handle_methods = #{handleMethods}</if>
            <if test="emergencyPlan != null  and emergencyPlan != ''"> and emergency_plan = #{emergencyPlan}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTDeviceRiskById" parameterType="Long" resultMap="TDeviceRiskResult">
        <include refid="selectTDeviceRiskVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTDeviceRisk" parameterType="TDeviceRisk">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_device_risk.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_device_risk
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="remarks != null">remarks,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="area != null">area,</if>
            <if test="diskLevel != null">disk_level,</if>
            <if test="reason != null">reason,</if>
            <if test="handleType != null">handle_type,</if>
            <if test="disk != null">disk,</if>
            <if test="discoveryDate != null">discovery_date,</if>
            <if test="planRemoveDate != null">plan_remove_date,</if>
            <if test="actualDate != null">actual_date,</if>
            <if test="handleMethods != null">handle_methods,</if>
            <if test="emergencyPlan != null">emergency_plan,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="area != null">#{area},</if>
            <if test="diskLevel != null">#{diskLevel},</if>
            <if test="reason != null">#{reason},</if>
            <if test="handleType != null">#{handleType},</if>
            <if test="disk != null">#{disk},</if>
            <if test="discoveryDate != null">#{discoveryDate},</if>
            <if test="planRemoveDate != null">#{planRemoveDate},</if>
            <if test="actualDate != null">#{actualDate},</if>
            <if test="handleMethods != null">#{handleMethods},</if>
            <if test="emergencyPlan != null">#{emergencyPlan},</if>
         </trim>
    </insert>

    <update id="updateTDeviceRisk" parameterType="TDeviceRisk">
        update t_device_risk
        <trim prefix="SET" suffixOverrides=",">
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="area != null">area = #{area},</if>
            <if test="diskLevel != null">disk_level = #{diskLevel},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="handleType != null">handle_type = #{handleType},</if>
            <if test="disk != null">disk = #{disk},</if>
            <if test="discoveryDate != null">discovery_date = #{discoveryDate},</if>
            <if test="planRemoveDate != null">plan_remove_date = #{planRemoveDate},</if>
            <if test="actualDate != null">actual_date = #{actualDate},</if>
            <if test="handleMethods != null">handle_methods = #{handleMethods},</if>
            <if test="emergencyPlan != null">emergency_plan = #{emergencyPlan},</if>
        </trim>
        where id = #{id}
    </update>

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

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