<?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.TrsRegionWordsMapper">
    
    <resultMap type="TrsRegionWords" id="TrsRegionWordsResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="parentCode"    column="parent_code"    />
        <result property="isAble"    column="is_able"    />
        <result property="orderNum"    column="order_num"    />
        <result property="bannerName"    column="banner_name"    />
        <result property="regionLevel"    column="region_level"    />
        <result property="shortName"    column="short_name"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectTrsRegionWordsVo">
        select t.id, t.code, t.name, t.parent_code, t.is_able, t.order_num, t.banner_name, t.region_level, t.short_name, t.is_delete, t.status from trs_region_words t
    </sql>

    <select id="selectTrsRegionWordsList" parameterType="TrsRegionWords" resultMap="TrsRegionWordsResult">
        <include refid="selectTrsRegionWordsVo"/>
        <if test="params.dataScope != null and params.dataScope != ''">
            <!-- 添加部门表关联 -->
            LEFT JOIN sys_dept d ON t.dept_id = d.dept_id
        </if>
        <where>  
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="shortName != null  and shortName != ''"> and short_name like concat('%', #{shortName}, '%')</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="selectTrsRegionWordsById" parameterType="Long" resultMap="TrsRegionWordsResult">
        <include refid="selectTrsRegionWordsVo"/>
        where id = #{id}
    </select>

    <insert id="insertTrsRegionWords" parameterType="TrsRegionWords" useGeneratedKeys="true" keyProperty="id">
        insert into trs_region_words
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="code != null">code,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="parentCode != null">parent_code,</if>
            <if test="isAble != null">is_able,</if>
            <if test="orderNum != null">order_num,</if>
            <if test="bannerName != null">banner_name,</if>
            <if test="regionLevel != null">region_level,</if>
            <if test="shortName != null">short_name,</if>
            <if test="isDelete != null">is_delete,</if>
            <if test="status != null">status,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="time != null">time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="code != null">#{code},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="parentCode != null">#{parentCode},</if>
            <if test="isAble != null">#{isAble},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="bannerName != null">#{bannerName},</if>
            <if test="regionLevel != null">#{regionLevel},</if>
            <if test="shortName != null">#{shortName},</if>
            <if test="isDelete != null">#{isDelete},</if>
            <if test="status != null">#{status},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="time != null">#{time},</if>
        </trim>
    </insert>

    <update id="updateTrsRegionWords" parameterType="TrsRegionWords">
        update trs_region_words
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null">code = #{code},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="parentCode != null">parent_code = #{parentCode},</if>
            <if test="isAble != null">is_able = #{isAble},</if>
            <if test="orderNum != null">order_num = #{orderNum},</if>
            <if test="bannerName != null">banner_name = #{bannerName},</if>
            <if test="regionLevel != null">region_level = #{regionLevel},</if>
            <if test="shortName != null">short_name = #{shortName},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="status != null">status = #{status},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="time != null">time = #{time},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTrsRegionWordsById" parameterType="Long">
        delete from trs_region_words where id = #{id}
    </delete>

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

</mapper>