<?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.TrsNamenmgWordsMapper">
    
    <resultMap type="TrsNamenmgWords" id="TrsNamenmgWordsResult">
        <result property="id"    column="id"    />
        <result property="wrongWord"    column="wrong_word"    />
        <result property="country"    column="country"    />
        <result property="dutyAll"    column="duty_all"    />
        <result property="dutyShort"    column="duty_short"    />
        <result property="sort"    column="sort"    />
        <result property="dictType"    column="dict_type"    />
        <result property="flag"    column="flag"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectTrsNamenmgWordsVo">
        select t.id, t.wrong_word, t.country, t.duty_all, t.duty_short, t.sort, t.dict_type, t.flag, t.status from trs_namenmg_words t
    </sql>

    <select id="selectTrsNamenmgWordsList" parameterType="TrsNamenmgWords" resultMap="TrsNamenmgWordsResult">
        <include refid="selectTrsNamenmgWordsVo"/>
        <if test="params.dataScope != null and params.dataScope != ''">
            <!-- 添加部门表关联 -->
            LEFT JOIN sys_dept d ON t.dept_id = d.dept_id
        </if>
        <where>  
            <if test="wrongWord != null  and wrongWord != ''"> and wrong_word like concat('%', #{wrongWord}, '%')</if>
            <if test="country != null  and country != ''"> and country like concat('%',  #{country}, '%')</if>
            <if test="dutyAll != null  and dutyAll != ''"> and duty_all like concat('%', #{dutyAll}, '%')</if>
            <if test="dutyShort != null  and dutyShort != ''"> and duty_short like concat('%',  #{dutyShort}, '%')</if>
            <if test="sort != null  and sort != ''"> and sort = #{sort}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <!-- 数据范围过滤移动到where标签内 -->
            <if test="params.dataScope != null and params.dataScope != ''">
                ${params.dataScope}
            </if>
        </where>
        order by t.id desc
    </select>
    
    <select id="selectTrsNamenmgWordsById" parameterType="Long" resultMap="TrsNamenmgWordsResult">
        <include refid="selectTrsNamenmgWordsVo"/>
        where id = #{id}
    </select>

    <insert id="insertTrsNamenmgWords" parameterType="TrsNamenmgWords" useGeneratedKeys="true" keyProperty="id">
        insert into trs_namenmg_words
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wrongWord != null and wrongWord != ''">wrong_word,</if>
            <if test="country != null">country,</if>
            <if test="dutyAll != null">duty_all,</if>
            <if test="dutyShort != null">duty_short,</if>
            <if test="sort != null">sort,</if>
            <if test="dictType != null">dict_type,</if>
            <if test="flag != null">flag,</if>
            <if test="status != null">status,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wrongWord != null and wrongWord != ''">#{wrongWord},</if>
            <if test="country != null">#{country},</if>
            <if test="dutyAll != null">#{dutyAll},</if>
            <if test="dutyShort != null">#{dutyShort},</if>
            <if test="sort != null">#{sort},</if>
            <if test="dictType != null">#{dictType},</if>
            <if test="flag != null">#{flag},</if>
            <if test="status != null">#{status},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTrsNamenmgWords" parameterType="TrsNamenmgWords">
        update trs_namenmg_words
        <trim prefix="SET" suffixOverrides=",">
            <if test="wrongWord != null and wrongWord != ''">wrong_word = #{wrongWord},</if>
            <if test="country != null">country = #{country},</if>
            <if test="dutyAll != null">duty_all = #{dutyAll},</if>
            <if test="dutyShort != null">duty_short = #{dutyShort},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="dictType != null">dict_type = #{dictType},</if>
            <if test="flag != null">flag = #{flag},</if>
            <if test="status != null">status = #{status},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTrsNamenmgWordsById" parameterType="Long">
        delete from trs_namenmg_words where id = #{id}
    </delete>

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

</mapper>