<?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.cmvr.tts.mapper.CorpusCategoryMapper">

    <resultMap type="com.cmvr.tts.domain.CorpusCategory" id="CorpusCategoryResult">
        <result property="id" column="id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="parentId" column="parent_id"/>
        <result property="categoryName" column="category_name"/>
        <result property="sortOrder" column="sort_order"/>
    </resultMap>

    <select id="selectList" parameterType="com.cmvr.tts.domain.CorpusCategory" resultMap="CorpusCategoryResult">
        select id, parent_id, category_name, sort_order, create_by, create_time, update_by, update_time, remark
        from tts_corpus_category
        <where>
            <if test="parentId != null and parentId != ''"> and parent_id = #{parentId}</if>
            <if test="categoryName != null and categoryName != ''"> and category_name like concat('%', #{categoryName}, '%')</if>
        </where>
        order by sort_order asc
    </select>

    <insert id="insert" parameterType="com.cmvr.tts.domain.CorpusCategory">
        insert into tts_corpus_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</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>
            <if test="remark != null">remark,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="categoryName != null">category_name,</if>
            <if test="sortOrder != null">sort_order,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</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>
            <if test="remark != null">#{remark},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="categoryName != null">#{categoryName},</if>
            <if test="sortOrder != null">#{sortOrder},</if>
        </trim>
    </insert>

    <update id="updateById" parameterType="com.cmvr.tts.domain.CorpusCategory">
        update tts_corpus_category
        <trim prefix="SET" suffixOverrides=",">
            <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>
            <if test="remark != null">remark = #{remark},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="categoryName != null">category_name = #{categoryName},</if>
            <if test="sortOrder != null">sort_order = #{sortOrder},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteById" parameterType="String">
        delete from tts_corpus_category where id = #{id}
    </delete>

</mapper>
