<?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.mapper.TrsArticleInfoMapper">
    
    <resultMap type="TrsArticleInfo" id="TrsArticleInfoResult">
        <result property="id"    column="id"    />
        <result property="record"    column="record"    />
        <result property="title"    column="title"    />
        <result property="url"    column="url"    />
        <result property="msg"    column="msg"    />
        <result property="content"    column="content"    />
        <result property="sitename"    column="sitename"    />
        <result property="time"    column="time"    />
        <result property="scantime"    column="scantime"    />
    </resultMap>

    <sql id="selectTrsArticleInfoVo">
        select id, record, title, url, msg, content,sitename,time,scantime from trs_article_info
    </sql>

    <select id="selectTrsArticleInfoList" parameterType="TrsArticleInfo" resultMap="TrsArticleInfoResult">
        <include refid="selectTrsArticleInfoVo"/>
        <where>  
            <if test="record != null "> and record = #{record}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="msg != null  and msg != ''"> and msg = #{msg}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="sitename != null  and sitename != ''"> and sitename = #{sitename}</if>
            <if test="params.beginTime != null and params.beginTime != '' and params.endTime != null and params.endTime != ''"> and time between #{params.beginTime} and #{params.endTime}</if>
        </where>
    </select>

    <select id="selectTrsArticleInfoMaxVersion" resultType="Long">
        select max(version) from trs_article_info a
    </select>

    <select id="selectTrsArticleInfoUpdateList" parameterType="TrsArticleInfo" resultMap="TrsArticleInfoResult">
        select a.id, record, title, url, msg, content,a.sitename,time,scantime from trs_article_info a
        left join crawltime ct on a.sitename=ct.sitename
        where a.sitename = #{sitename}
        and a.scantime between ct.starttime AND ct.endtime
    </select>

    <select id="selectTrsArticleInfoFuheList" parameterType="TrsArticleInfo" resultMap="TrsArticleInfoResult">
        select a.id, record, title, url, msg, content,a.sitename,time,scantime from trs_article_info a
        left join crawltime ct on a.sitename=ct.sitename
        <where>
            <if test="record != null "> and record = #{record}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="msg != null  and msg != ''"> and msg = #{msg}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="sitename != null  and sitename != ''"> and a.sitename = #{sitename}</if>
        </where>
        and a.scantime between ct.starttime AND ct.endtime
    </select>

    <select id="selectTrsArticleInfoReviewList"  resultType="java.util.Map">
        select a.content,a.url,a.title,a.time,a.scantime,a.msg,s.wrong_word,s.datakey,s.id,s.correct_word  from trs_article_info a
            left join trs_sensitive_results s on a.url=s.page
            where a.msg='已更新' and s.status='待复核'
    </select>

    <select id="selectTrsArticleInfoReviewList2"  resultType="java.util.Map">
        select a.content,a.url,a.title,a.time,a.scantime,a.msg,s.wrong_word,s.datakey,s.id  from trs_article_info a
            left join trs_policy_results s on a.url=s.page
        where a.msg='已更新' and s.status='待复核'
    </select>

    <select id="selectTrsArticleInfoUrlList" parameterType="TrsArticleInfo">
        select url from trs_article_info where record = #{record}
    </select>
    
    <select id="selectTrsArticleInfoById" parameterType="Long" resultMap="TrsArticleInfoResult">
        <include refid="selectTrsArticleInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertTrsArticleInfo" parameterType="TrsArticleInfo" useGeneratedKeys="true" keyProperty="id">
        insert into trs_article_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="record != null">record,</if>
            <if test="title != null">title,</if>
            <if test="url != null and url != ''">url,</if>
            <if test="msg != null">msg,</if>
            <if test="content != null">content,</if>
            <if test="sitename != null">sitename,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="record != null">#{record},</if>
            <if test="title != null">#{title},</if>
            <if test="url != null and url != ''">#{url},</if>
            <if test="msg != null">#{msg},</if>
            <if test="content != null">#{content},</if>
            <if test="sitename != null">#{sitename},</if>
         </trim>
    </insert>

    <update id="updateTrsArticleInfo" parameterType="TrsArticleInfo">
        update trs_article_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="record != null">record = #{record},</if>
            <if test="title != null">title = #{title},</if>
            <if test="url != null and url != ''">url = #{url},</if>
            <if test="msg != null">msg = #{msg},</if>
            <if test="content != null">content = #{content},</if>
            <if test="sitename != null">sitename = #{sitename},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTrsArticleInfoById" parameterType="Long">
        delete from trs_article_info where id = #{id}
    </delete>

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

</mapper>