<?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.TrsErrorUrlMapper">
    
    <resultMap type="TrsErrorUrl" id="TrsErrorUrlResult">
        <result property="id"    column="id"    />
        <result property="errorurl"    column="errorurl"    />
        <result property="msg"    column="msg"    />
        <result property="status"    column="status"    />
        <result property="tenant"    column="tenant"    />
        <result property="time"    column="time"    />
        <result property="deptId"    column="dept_id"    />

    </resultMap>

    <sql id="selectTrsErrorUrlVo">
        select t.id, t.errorurl, t.msg, t.status, t.tenant,t.time,t.dept_id from trs_error_url t
    </sql>

    <select id="selectTrsWordsListByErrorWord" parameterType="String" resultMap="TrsErrorUrlResult">
        <include refid="selectTrsErrorUrlVo"/>
        where errorurl = #{errorurl}
    </select>

    <select id="selectTrsErrorUrlList" parameterType="TrsErrorUrl" resultMap="TrsErrorUrlResult">
        <include refid="selectTrsErrorUrlVo"/>
        <if test="params.dataScope != null and params.dataScope != ''">
            <!-- 添加部门表关联 -->
            LEFT JOIN sys_dept d ON t.dept_id = d.dept_id
        </if>
        <where>  
            <if test="errorurl != null  and errorurl != ''"> and errorurl = #{errorurl}</if>
            <if test="msg != null  and msg != ''"> and msg = #{msg}</if>
            <if test="status != null  and status != ''"> and status = #{status}</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>
            <choose>
                <when test="deptId != null and deptId == 100">
                    <!-- 教对部门可以看到所有数据 -->
                    and (t.dept_id = 100 or t.dept_id = 0)
                </when>
                <otherwise>
                    <!-- 数据范围过滤移动到where标签内 -->
                    <if test="params.dataScope != null and params.dataScope != ''">
                        ${params.dataScope}
                    </if>
                </otherwise>
            </choose>
        </where>
        order by t.id desc
    </select>
    
    <select id="selectTrsErrorUrlById" parameterType="Long" resultMap="TrsErrorUrlResult">
        <include refid="selectTrsErrorUrlVo"/>
        where id = #{id}
    </select>

    <insert id="insertTrsErrorUrl" parameterType="TrsErrorUrl" useGeneratedKeys="true" keyProperty="id">
        insert into trs_error_url
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="errorurl != null">errorurl,</if>
            <if test="msg != null">msg,</if>
            <if test="status != null">status,</if>
            <if test="tenant != null">tenant,</if>
            <if test="time != null">time,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="errorurl != null">#{errorurl},</if>
            <if test="msg != null">#{msg},</if>
            <if test="status != null">#{status},</if>
            <if test="tenant != null">#{tenant},</if>
            <if test="time != null">#{time},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateTrsErrorUrl" parameterType="TrsErrorUrl">
        update trs_error_url
        <trim prefix="SET" suffixOverrides=",">
            <if test="errorurl != null">errorurl = #{errorurl},</if>
            <if test="msg != null">msg = #{msg},</if>
            <if test="status != null">status = #{status},</if>
            <if test="tenant != null">tenant = #{tenant},</if>
            <if test="time != null">time = #{time},</if>
            <if test="deptId != null">deptid = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTrsErrorUrlById" parameterType="Long">
        delete from trs_error_url where id = #{id}
    </delete>

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

</mapper>