<?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.system.mapper.DataRecordMapper">
    
    <resultMap type="DataRecord" id="DataRecordResult">
        <result property="id"    column="id"    />
        <result property="record"    column="record"    />
        <result property="url"    column="url"    />
        <result property="linkurl"    column="linkurl"    />
        <result property="msg"    column="msg"    />
        <result property="timestamp"    column="timestamp"    />
    </resultMap>

    <sql id="selectDataRecordVo">
        select id, record, url, linkurl, msg,timestamp from data_record
    </sql>

    <!--<select id="selectDataRecordList" parameterType="DataRecord" resultMap="DataRecordResult">
        <include refid="selectDataRecordVo"/>
        <where>  
            <if test="record != null  and record != ''"> and record = #{record}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="linkurl != null  and linkurl != ''"> and linkurl = #{linkurl}</if>
            <if test="msg != null  and msg != ''"> and msg = #{msg}</if>
        </where>
    </select>-->

    <select id="selectDataRecordList" parameterType="DataRecord" resultMap="DataRecordResult">
        select id, record, url as url, linkurl, msg,timestamp from data_record where record = #{record}
    </select>

    <select id="selectDataRecordAllList" parameterType="DataRecord" resultMap="DataRecordResult">
        select id, record, GROUP_CONCAT(url SEPARATOR ',') as url, linkurl, msg,timestamp from data_record where (msg like '%no such host%' or msg like '%404%'  )
        and record = #{record}
        group by linkurl
    </select>

    <select id="selectWlDataRecordAllList" parameterType="DataRecord" resultMap="DataRecordResult">
        select id, record, GROUP_CONCAT(url SEPARATOR ',') as url, linkurl, msg,timestamp from data_record where linkurl not like concat('%',#{url}, '%')
        and record = #{record}
        group by linkurl
    </select>
    
    <select id="selectDataRecordById" parameterType="Long" resultMap="DataRecordResult">
        <include refid="selectDataRecordVo"/>
        and id = #{id}
    </select>

    <insert id="insertDataRecord" parameterType="DataRecord" useGeneratedKeys="true" keyProperty="id">
        insert into data_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="record != null">record,</if>
            <if test="url != null">url,</if>
            <if test="linkurl != null">linkurl,</if>
            <if test="msg != null">msg,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="record != null">#{record},</if>
            <if test="url != null">#{url},</if>
            <if test="linkurl != null">#{linkurl},</if>
            <if test="msg != null">#{msg},</if>
         </trim>
    </insert>

    <insert id="batchDataRecord" parameterType="list" useGeneratedKeys="true" keyProperty="id">
        insert into data_record (record,url,linkurl,msg,timestamp) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.record},#{item.url},#{item.linkurl},#{item.msg},#{item.timestamp})
        </foreach>
    </insert>

    <update id="updateDataRecord" parameterType="DataRecord">
        update data_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="record != null">record = #{record},</if>
            <if test="url != null">url = #{url},</if>
            <if test="linkurl != null">linkurl = #{linkurl},</if>
            <if test="msg != null">msg = #{msg},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDataRecordById" parameterType="Long">
        delete from data_record where id = #{id}
    </delete>

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

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

</mapper>