<?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.inspect.system.mapper.SysWarningMapper">

    <resultMap type="com.inspect.base.core.domain.SysWarning" id="SysWarningResult">
        <id property="id" column="id"/>
        <result property="text" column="text"/>
        <result property="userName" column="user_name"/>
        <result property="sourceName" column="source_name"/>
        <result property="level" column="level"/>
        <result property="type" column="type"/>
        <result property="time" column="time"/>

    </resultMap>

    <select id="queryWarningList" resultType="com.inspect.base.core.domain.SysWarning" resultMap="SysWarningResult">
        select id,text,user_name,source_name,level,type,time
        from sys_warning
        <where>
            <if test="level != null ">
                AND level = #{level}
            </if>
            <if test="type != null ">
                AND type = #{type}
            </if>
            <if test="begin != null and end != null">
                AND time between #{begin} and #{end}
            </if>
            <if test="userName != null ">
                AND user_name like concat('%', #{userName}, '%')
            </if>
        </where>
        order by time desc

    </select>


    <insert id="insertWarning" parameterType="com.inspect.base.core.domain.SysWarning">
        insert into sys_warning(
        <if test="text != null and text != ''">text,</if>
        <if test="userName != null and userName != ''">user_name,</if>
        <if test="sourceName != null and sourceName != ''">source_name,</if>
        <if test="level != null ">level,</if>
        <if test="type != null">type,</if>
        time
        )values(
        <if test="text != null and text != ''">#{text},</if>
        <if test="userName != null and userName != ''">#{userName},</if>
        <if test="sourceName != null and sourceName != ''">#{sourceName},</if>
        <if test="level != null ">#{level},</if>
        <if test="type != null ">#{type},</if>
        sysdate()
        )
    </insert>


</mapper> 