<?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.zehong.system.mapper.TVillageLevelRegionMapper">
    
    <resultMap type="TVillageLevelRegion" id="TVillageLevelRegionResult">
        <result property="fId"    column="f_id"    />
        <result property="fTownId"    column="f_town_id"    />
        <result property="fVillageCode"    column="f_village_code"    />
        <result property="fName"    column="f_name"    />
        <result property="fIsSd"    column="f_is_sd"    />
    </resultMap>

    <sql id="selectTVillageLevelRegionVo">
        select f_id, f_town_id, f_village_code, f_name, f_is_sd from t_village_level_region
    </sql>

    <select id="selectTVillageLevelRegionList" parameterType="TVillageLevelRegion" resultMap="TVillageLevelRegionResult">
        <include refid="selectTVillageLevelRegionVo"/>
        <where>  
            <if test="fTownId != null "> and f_town_id = #{fTownId}</if>
            <if test="fVillageCode != null  and fVillageCode != ''"> and f_village_code = #{fVillageCode}</if>
            <if test="fName != null  and fName != ''"> and f_name like concat('%', #{fName}, '%')</if>
            <if test="fIsSd != null  and fIsSd != ''"> and f_is_sd = #{fIsSd}</if>
        </where>
    </select>
    
    <select id="selectTVillageLevelRegionById" parameterType="Long" resultMap="TVillageLevelRegionResult">
        <include refid="selectTVillageLevelRegionVo"/>
        where f_id = #{fId}
    </select>
        
    <insert id="insertTVillageLevelRegion" parameterType="TVillageLevelRegion">
        insert into t_village_level_region
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fId != null">f_id,</if>
            <if test="fTownId != null">f_town_id,</if>
            <if test="fVillageCode != null and fVillageCode != ''">f_village_code,</if>
            <if test="fName != null and fName != ''">f_name,</if>
            <if test="fIsSd != null and fIsSd != ''">f_is_sd,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fId != null">#{fId},</if>
            <if test="fTownId != null">#{fTownId},</if>
            <if test="fVillageCode != null and fVillageCode != ''">#{fVillageCode},</if>
            <if test="fName != null and fName != ''">#{fName},</if>
            <if test="fIsSd != null and fIsSd != ''">#{fIsSd},</if>
         </trim>
    </insert>

    <update id="updateTVillageLevelRegion" parameterType="TVillageLevelRegion">
        update t_village_level_region
        <trim prefix="SET" suffixOverrides=",">
            <if test="fTownId != null">f_town_id = #{fTownId},</if>
            <if test="fVillageCode != null and fVillageCode != ''">f_village_code = #{fVillageCode},</if>
            <if test="fName != null and fName != ''">f_name = #{fName},</if>
            <if test="fIsSd != null and fIsSd != ''">f_is_sd = #{fIsSd},</if>
        </trim>
        where f_id = #{fId}
    </update>

    <delete id="deleteTVillageLevelRegionById" parameterType="Long">
        delete from t_village_level_region where f_id = #{fId}
    </delete>

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

    <insert id="batchInsertTVillageLevelRegion" parameterType="TVillageLevelRegion">
        insert into t_village_level_region(
            f_id,
            f_town_id,
            f_village_code,
            f_name,
            f_is_sd
        )VALUES
        <foreach collection="list" separator="," item="item">
            (
                #{item.fId},
                #{item.fTownId},
                #{item.fVillageCode},
                #{item.fName},
                #{item.fIsSd}
            )
        </foreach>
    </insert>
</mapper>