<?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.TrsSiteconfigMapper">
    
    <resultMap type="TrsSiteconfig" id="TrsSiteconfigResult">
        <result property="id"    column="id"    />
        <result property="sitename"    column="sitename"    />
        <result property="record"    column="record"    />
        <result property="domain"    column="domain"    />
        <result property="filepath"    column="filepath"    />
        <result property="msg"    column="msg"    />
        <result property="other"    column="other"    />
        <result property="starttime"    column="starttime"    />
        <result property="endtime"    column="endtime"    />
        <result property="version"    column="version"    />
    </resultMap>

    <sql id="selectTrsSiteconfigVo">
        select id, sitename, record, domain, filepath, msg, other from trs_siteconfig
    </sql>

    <select id="selectTrsSiteconfigList" parameterType="TrsSiteconfig" resultMap="TrsSiteconfigResult">
        <include refid="selectTrsSiteconfigVo"/>
        <where>  
            <if test="sitename != null  and sitename != ''"> and sitename like concat('%', #{sitename}, '%')</if>
            <if test="record != null  and record != ''"> and record = #{record}</if>
            <if test="domain != null  and domain != ''"> and domain = #{domain}</if>
            <if test="filepath != null  and filepath != ''"> and filepath = #{filepath}</if>
            <if test="msg != null  and msg != ''"> and msg = #{msg}</if>
            <if test="other != null  and other != ''"> and other = #{other}</if>
            <if test="params.starttime != null and params.starttime != '' and params.endtime != null and params.endTime != ''"> and time between #{params.starttime} and #{params.endtime}</if>
            <if test="version != null  and version != ''"> and version = #{version}</if>
        </where>
    </select>
    
    <select id="selectTrsSiteconfigById" parameterType="Long" resultMap="TrsSiteconfigResult">
        <include refid="selectTrsSiteconfigVo"/>
        where id = #{id}
    </select>

    <insert id="insertTrsSiteconfig" parameterType="TrsSiteconfig" useGeneratedKeys="true" keyProperty="id">
        insert into trs_siteconfig
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sitename != null and sitename != ''">sitename,</if>
            <if test="record != null and record != ''">record,</if>
            <if test="domain != null and domain != ''">domain,</if>
            <if test="filepath != null">filepath,</if>
            <if test="msg != null">msg,</if>
            <if test="other != null">other,</if>
            <if test="starttime != null">starttime,</if>
            <if test="endtime != null">endtime,</if>
            <if test="version != null">version,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sitename != null and sitename != ''">#{sitename},</if>
            <if test="record != null and record != ''">#{record},</if>
            <if test="domain != null and domain != ''">#{domain},</if>
            <if test="filepath != null">#{filepath},</if>
            <if test="msg != null">#{msg},</if>
            <if test="other != null">#{other},</if>
            <if test="starttime != null">#{starttime},</if>
            <if test="endtime != null">#{endtime},</if>
            <if test="version != null">#{version},</if>
         </trim>
    </insert>

    <update id="updateTrsSiteconfig" parameterType="TrsSiteconfig">
        update trs_siteconfig
        <trim prefix="SET" suffixOverrides=",">
            <if test="sitename != null and sitename != ''">sitename = #{sitename},</if>
            <if test="record != null and record != ''">record = #{record},</if>
            <if test="domain != null and domain != ''">domain = #{domain},</if>
            <if test="filepath != null">filepath = #{filepath},</if>
            <if test="msg != null">msg = #{msg},</if>
            <if test="other != null">other = #{other},</if>
            <if test="starttime != null">#{starttime},</if>
            <if test="endtime != null">#{endtime},</if>
            <if test="version != null">#{version},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTrsSiteconfigById" parameterType="Long">
        delete from trs_siteconfig where id = #{id}
    </delete>

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

    <!--做统计用-->
    <!-- 统计总文本数 -->
    <select id="getTotalTexts" resultType="java.lang.Integer">
        SELECT
        COUNT(1)
        FROM
        trs_article_info
        <where>
            1=1
            <!-- 站点条件 -->
            <if test="sitename != null and sitename != ''">
                AND sitename = #{sitename}
            </if>
            <!-- 时间范围条件 -->
            <if test="startDate != null">
                AND time >= #{startDate}
            </if>
            <if test="endDate != null">
                AND time <![CDATA[ <= ]]> #{endDate}
            </if>
--             AND version = 1
        </where>
    </select>

    <select id="getProblemTexts" resultType="java.lang.Integer">
        SELECT
        COUNT(DISTINCT datakey)
        FROM
        trs_sensitive_results
        <where>
            1=1
            <!-- 站点条件 -->
            <if test="sitename != null and sitename != ''">
                AND sitename = #{sitename}
            </if>
            <!-- 时间范围条件 -->
            <if test="startDate != null">
                AND time >= #{startDate}
            </if>
            <if test="endDate != null">
                AND time <![CDATA[ <= ]]> #{endDate}
            </if>
        </where>
    </select>

    <select id="getHighFrequencyErrors" resultType="java.util.Map">
        SELECT
        wrong_word AS word,
        COUNT(*) AS count
        FROM (
        SELECT DISTINCT datakey, wrong_word
        FROM trs_sensitive_results
        WHERE 1=1
        <!-- 时间范围条件 -->
        <if test="startDate != null">
            AND time >= #{startDate}
        </if>
        <if test="endDate != null">
            AND time <![CDATA[ <= ]]> #{endDate}
        </if>
        <if test="sitename != null and sitename != ''">
            AND sitename = #{sitename}
        </if>
        ) AS distinct_results
        GROUP BY wrong_word
        ORDER BY count DESC
        LIMIT 10  <!-- 取前10个高频错词 -->
    </select>


    <!-- 按状态统计数量 -->
    <select id="countByStatus" resultType="java.lang.Integer">
        SELECT COUNT(DISTINCT datakey)
        FROM trs_sensitive_results
        <where>
            1=1
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
            <if test="sitename != null and sitename != ''">
                AND sitename = #{sitename}
            </if>
            <if test="startDate != null">
                AND time >= #{startDate}
            </if>
            <if test="endDate != null">
                AND time <![CDATA[ <= ]]> #{endDate}
            </if>
        </where>
    </select>


    <!-- 按错误类型统计数量 -->
    <select id="countByType" resultType="java.lang.Integer">
        SELECT COUNT(DISTINCT datakey)
        FROM trs_sensitive_results
        <where>
            1=1
            <if test="errorType != null">
                AND error_type LIKE concat('%', #{errorType}, '%')
            </if>
            <if test="sitename != null and sitename != ''">
                AND sitename = #{sitename}
            </if>
            <if test="startDate != null">
                AND time >= #{startDate}
            </if>
            <if test="endDate != null">
                AND time <![CDATA[ <= ]]> #{endDate}
            </if>
        </where>
    </select>



    <!--做统计用jd-->
    <!-- 统计总文本数 -->
    <select id="getTotalTexts_jd" resultType="java.lang.Integer">
        SELECT
        COUNT(1)
        FROM
        trs_results_log
        <where>
            1=1
            <if test="sitename != null and sitename != ''">
                AND log_id = #{sitename}
            </if>
            <if test="startDate != null">
                AND time >= #{startDate}
            </if>
            <if test="endDate != null">
                AND time <![CDATA[ <= ]]> #{endDate}
            </if>
        </where>
    </select>

    <select id="getProblemTexts_jd" resultType="java.lang.Integer">
        SELECT
        COUNT(1)
        FROM
        trs_results_log
        <where>
            1=1
            <if test="sitename != null and sitename != ''">
                AND log_id = #{sitename}
            </if>
            <!-- 时间范围条件 -->
            <if test="startDate != null">
                AND time >= #{startDate}
            </if>
            <if test="endDate != null">
                AND time <![CDATA[ <= ]]> #{endDate}
            </if>
            AND status = '有结果'
        </where>
    </select>

    <select id="getHighFrequencyErrors_jd" resultType="java.util.Map">
        SELECT
        wrong_word AS word,
        correct_word AS cword,
        error_type AS ctype,
        COUNT(*) AS count
        FROM trs_word_results
        WHERE 1=1
        <if test="sitename != null and sitename != ''">
            AND log_id = #{sitename}
        </if>
        <if test="res != null and res != ''">
            AND res = #{res}
        </if>
        <!-- 时间范围条件 -->
        <if test="startDate != null">
            AND time >= #{startDate}
        </if>
        <if test="endDate != null">
            AND time <![CDATA[ <= ]]> #{endDate}
        </if>
        AND sitename = 'common'
        GROUP BY wrong_word
        ORDER BY count DESC
        LIMIT 100  <!-- 取前100个高频错词 -->
    </select>


    <!-- 按状态统计数量 -->
    <select id="countByStatus_jd" resultType="java.lang.Integer">
        SELECT COUNT(1)
        FROM trs_word_results
        <where>
            1=1
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
            <if test="sitename != null and sitename != ''">
                AND sitename = #{sitename}
            </if>
            <if test="errorGrade != null and errorGrade != ''">
                AND error_grade = #{errorGrade}
            </if>
            <if test="startDate != null">
                AND time >= #{startDate}
            </if>
            <if test="endDate != null">
                AND time <![CDATA[ <= ]]> #{endDate}
            </if>
            AND sitename = 'common'

        </where>
    </select>


    <!-- 按错误类型统计数量 -->
    <select id="countByType_jd" resultType="java.lang.Integer">
        SELECT COUNT(1)
        FROM trs_word_results
        <where>
            1=1
            <if test="errorType != null">
                AND error_type LIKE concat('%', #{errorType}, '%')
            </if>
            <if test="sitename != null and sitename != ''">
                AND sitename = #{sitename}
            </if>
            <if test="startDate != null">
                AND time >= #{startDate}
            </if>
            <if test="endDate != null">
                AND time <![CDATA[ <= ]]> #{endDate}
            </if>
            AND sitename = 'common'

        </where>
    </select>


</mapper>