<?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.supervision.grassrootsregistration.mapper.BdglDrillTypeMapper">
    
    <resultMap type="BdglDrillType" id="BdglDrillTypeResult">
        <result property="id"    column="id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="ancestors"    column="ancestors"    />
    </resultMap>

    <sql id="selectBdglDrillTypeVo">
        select id, parent_id, ancestors from bdgl_drill_type
    </sql>

    <select id="selectBdglDrillTypeList" parameterType="BdglDrillType" resultMap="BdglDrillTypeResult">
        <include refid="selectBdglDrillTypeVo"/>
        <where>  
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
        </where>
    </select>
    
    <select id="selectBdglDrillTypeById" parameterType="Long" resultMap="BdglDrillTypeResult">
        <include refid="selectBdglDrillTypeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBdglDrillType" parameterType="BdglDrillType" useGeneratedKeys="true" keyProperty="id">
        insert into bdgl_drill_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,</if>
            <if test="ancestors != null">ancestors,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentId != null">#{parentId},</if>
            <if test="ancestors != null">#{ancestors},</if>
         </trim>
    </insert>

    <update id="updateBdglDrillType" parameterType="BdglDrillType">
        update bdgl_drill_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="ancestors != null">ancestors = #{ancestors},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBdglDrillTypeById" parameterType="Long">
        delete from bdgl_drill_type where id = #{id}
    </delete>

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