<?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.test.test.mapper.TestGroupMapper">

    <resultMap type="TestGroup" id="TestGroupResult">
        <result property="id" column="id"/>
        <result property="parentId" column="parent_id"/>
        <result property="type" column="type"/>
        <result property="name" column="name"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectTestGroupVo">
        select id,
               parent_id,
               type,
               name,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from test_group
    </sql>

    <select id="selectTestGroupList" parameterType="String" resultMap="TestGroupResult">
        <include refid="selectTestGroupVo"/>
        <where>
            type = #{type}
        </where>
    </select>

    <select id="selectTestGroupById" parameterType="Long" resultMap="TestGroupResult">
        <include refid="selectTestGroupVo"/>
        <where>
            id = #{id}
        </where>
    </select>

    <select id="selectTestGroupListByParentIds" parameterType="String" resultMap="TestGroupResult">
        <include refid="selectTestGroupVo"/>
        <where>
            parent_id in
            <foreach item="parentId" collection="list" open="(" separator="," close=")">
                #{parentId}
            </foreach>
        </where>
    </select>

    <select id="selectGroup" parameterType="String" resultMap="TestGroupResult">
        <include refid="selectTestGroupVo"/>
        <where>
            name = #{name} and type = #{type} and parent_id = #{parentId}
        </where>
    </select>

    <insert id="insertTestGroup" parameterType="TestGroup" useGeneratedKeys="true" keyProperty="id">
        insert into test_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,</if>
            <if test="type != null">type,</if>
            <if test="name != null">name,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentId != null">#{parentId},</if>
            <if test="type != null">#{type},</if>
            <if test="name != null">#{name},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateTestGroup" parameterType="TestGroup">
        update test_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="name != null">name = #{name},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

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