<?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.TrsResultsLogMapper">
    
    <resultMap type="TrsResultsLog" id="TrsResultsLogResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="status"    column="status"    />
        <result property="errortype"    column="errortype"    />
        <result property="time"    column="time"    />
        <result property="operuser"    column="operuser"    />
        <result property="ip"    column="ip"    />
    </resultMap>

    <sql id="selectTrsResultsLogVo">
        select t.id, t.title, t.content, t.status, t.errortype, t.time, t.operuser, t.ip from trs_results_log t
    </sql>

    <select id="selectTrsResultsLogList" parameterType="TrsResultsLog" resultMap="TrsResultsLogResult">
        <include refid="selectTrsResultsLogVo"/>
        <if test="params.dataScope != null and params.dataScope != ''">
            <!-- 添加部门表关联 -->
            LEFT JOIN sys_user u ON t.user_id = u.user_id
            LEFT JOIN sys_dept d ON t.dept_id = d.dept_id
        </if>

        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="errortype != null  and errortype != ''"> and errortype = #{errortype}</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标签内 -->
            <if test="params.dataScope != null and params.dataScope != ''">
                ${params.dataScope}
            </if>
        </where>
        order by t.id desc
    </select>

    <select id="selectTrsResultsLogExportList" parameterType="TrsResultsLog" resultType="com.ruoyi.project.domain.TrsResultsLogAdmin">
        select t.title,t.content,t.errortype,t.status,w.content as scontent,w.wrong_word,w.error_type,w.error_grade,w.correct_word,w.source
        from trs_results_log t
        left join trs_word_results w on t.id=w.log_id
        <if test="params.dataScope != null and params.dataScope != ''">
            <!-- 添加部门表关联 -->
            LEFT JOIN sys_user u ON t.user_id = u.user_id
            LEFT JOIN sys_dept d ON t.dept_id = d.dept_id
        </if>

        <where>
            <if test="title != null  and title != ''"> and t.title = #{title}</if>
            <if test="status != null  and status != ''"> and t.status = #{status}</if>
            <if test="errortype != null  and errortype != ''"> and t.errortype = #{errortype}</if>
            <if test="params.beginTime != null and params.beginTime != '' and params.endTime != null and params.endTime != ''"> and t.time between #{params.beginTime} and #{params.endTime}</if>
            <!-- 数据范围过滤移动到where标签内 -->
            <if test="params.dataScope != null and params.dataScope != ''">
                ${params.dataScope}
            </if>
        </where>
        order by t.id desc
    </select>
    
    <select id="selectTrsResultsLogById" parameterType="Long" resultMap="TrsResultsLogResult">
        <include refid="selectTrsResultsLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertTrsResultsLog" parameterType="TrsResultsLog" useGeneratedKeys="true" keyProperty="id">
        insert into trs_results_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="status != null">status,</if>
            <if test="errortype != null">errortype,</if>
            <if test="time != null">time,</if>
            <if test="operuser != null">operuser,</if>
            <if test="ip != null">ip,</if>
            <if test="userId != null">user_id,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="status != null">#{status},</if>
            <if test="errortype != null">#{errortype},</if>
            <if test="time != null">#{time},</if>
            <if test="operuser != null">#{operuser},</if>
            <if test="ip != null">#{ip},</if>
            <if test="userId != null">#{userId},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTrsResultsLog" parameterType="TrsResultsLog">
        update trs_results_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="status != null">status = #{status},</if>
            <if test="errortype != null">errortype = #{errortype},</if>
            <if test="time != null">time = #{time},</if>
            <if test="ip != null">ip = #{ip},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTrsResultsLogById" parameterType="Long">
        delete from trs_results_log where id = #{id}
    </delete>

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

</mapper>