<?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.zongzhi.mapper.TcSafetyDangerMapper">
    
    <resultMap type="TcSafetyDanger" id="TcSafetyDangerResult">
        <result property="id"    column="id"    />
        <result property="areaId"    column="area_id"    />
        <result property="type"    column="type"    />
        <result property="unitName"    column="unit_name"    />
        <result property="riskName"    column="risk_name"    />
        <result property="level"    column="level"    />
        <result property="riskSource"    column="risk_source"    />
        <result property="ipDns"    column="ip_dns"    />
        <result property="state"    column="state"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="depName"    column="dep_name"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="createId"    column="create_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateId"    column="update_id"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="isStatus"    column="is_status"    />
    </resultMap>

    <sql id="selectTcSafetyDangerVo">
        select id, area_id, type,is_status, unit_name, risk_name, level, risk_source, ip_dns, state, file_name, file_url, dep_name, start_time, end_time, create_id, create_by, create_time, update_id, update_by, update_time, remark from tc_safety_danger
    </sql>

    <select id="selectTcSafetyDangerList" parameterType="TcSafetyDanger" resultMap="TcSafetyDangerResult">
        <include refid="selectTcSafetyDangerVo"/>
        <where>  
            <if test="areaId != null "> and area_id = #{areaId}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="riskName != null  and riskName != ''"> and risk_name like concat('%', #{riskName}, '%')</if>
            <if test="level != null "> and level = #{level}</if>
            <if test="riskSource != null "> and risk_source = #{riskSource}</if>
            <if test="ipDns != null  and ipDns != ''"> and ip_dns = #{ipDns}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="depName != null  and depName != ''"> and dep_name like concat('%', #{depName}, '%')</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="createId != null "> and create_id = #{createId}</if>
            <if test="updateId != null "> and update_id = #{updateId}</if>
            <if test="isStatus != null "> and is_status = #{isStatus}</if>
        </where>
    </select>
    
    <select id="selectTcSafetyDangerById" parameterType="Long" resultMap="TcSafetyDangerResult">
        <include refid="selectTcSafetyDangerVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTcSafetyDanger" parameterType="TcSafetyDanger" useGeneratedKeys="true" keyProperty="id">
        insert into tc_safety_danger
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaId != null">area_id,</if>
            <if test="type != null">type,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="riskName != null">risk_name,</if>
            <if test="level != null">level,</if>
            <if test="riskSource != null">risk_source,</if>
            <if test="ipDns != null">ip_dns,</if>
            <if test="state != null">state,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="depName != null">dep_name,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="createId != null">create_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateId != null">update_id,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="isStatus != null">is_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaId != null">#{areaId},</if>
            <if test="type != null">#{type},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="riskName != null">#{riskName},</if>
            <if test="level != null">#{level},</if>
            <if test="riskSource != null">#{riskSource},</if>
            <if test="ipDns != null">#{ipDns},</if>
            <if test="state != null">#{state},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="depName != null">#{depName},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateId != null">#{updateId},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isStatus != null">#{isStatus},</if>
         </trim>
    </insert>

    <update id="updateTcSafetyDanger" parameterType="TcSafetyDanger">
        update tc_safety_danger
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="riskName != null">risk_name = #{riskName},</if>
            <if test="level != null">level = #{level},</if>
            <if test="riskSource != null">risk_source = #{riskSource},</if>
            <if test="ipDns != null">ip_dns = #{ipDns},</if>
            <if test="state != null">state = #{state},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="depName != null">dep_name = #{depName},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="createId != null">create_id = #{createId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateId != null">update_id = #{updateId},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isStatus != null">is_status=#{isStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTcSafetyDangerById" parameterType="Long">
        delete from tc_safety_danger where id = #{id}
    </delete>

    <delete id="deleteTcSafetyDangerByIds" parameterType="String">
        delete from tc_safety_danger where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>