<?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.zongzhi.mapper.TcTownMapper">
    
    <resultMap type="TcTown" id="TcTownResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="parentName"    column="parent_name"    />
        <result property="parentId"    column="parent_id"    />
        <result property="level"    column="level"    />
        <result property="createId"    column="create_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateId"    column="update_id"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
        <result property="isStatus"    column="is_status"    />
    </resultMap>

    <sql id="selectTcTownVo">
        select id, name, parent_name, is_status,parent_id, level, create_id, create_time, create_by, update_id, update_by, remark from tc_town
    </sql>

    <select id="selectTcTownList" parameterType="TcTown" resultMap="TcTownResult">
        <include refid="selectTcTownVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="parentName != null  and parentName != ''"> and parent_name like concat('%', #{parentName}, '%')</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="level != null "> and level = #{level}</if>
            <if test="createId != null "> and create_id = #{createId}</if>
            <if test="updateId != null "> and update_id = #{updateId}</if>
            <if test="isStatus != null "> and is_status = #{isStatus}</if>
        </where>
    </select>
    
    <select id="selectTcTownById" parameterType="Long" resultMap="TcTownResult">
        <include refid="selectTcTownVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTcTown" parameterType="TcTown" useGeneratedKeys="true" keyProperty="id">
        insert into tc_town
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="parentName != null">parent_name,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="level != null">level,</if>
            <if test="createId != null">create_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateId != null">update_id,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
            <if test="isStatus != null">is_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="parentName != null">#{parentName},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="level != null">#{level},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateId != null">#{updateId},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isStatus != null">#{isStatus},</if>
         </trim>
    </insert>


    <update id="updateTcTown" parameterType="TcTown">
        update tc_town
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="parentName != null">parent_name = #{parentName},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="level != null">level = #{level},</if>
            <if test="createId != null">create_id = #{createId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateId != null">update_id = #{updateId},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isStatus != null">is_status=#{isStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTcTownById" parameterType="Long">
        delete from tc_town where id = #{id}
    </delete>

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