<?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.xinelu.manage.mapper.trainingcategory.TrainingCategoryMapper">

    <resultMap type="TrainingCategory" id="TrainingCategoryResult">
        <result property="id" column="id"/>
        <result property="parentId" column="parent_id"/>
        <result property="trainingCategoryName" column="training_category_name"/>
        <result property="trainingCategoryCode" column="training_category_code"/>
        <result property="trainingCategoryPictureUrl" column="training_category_picture_url"/>
        <result property="trainingCategorySort" column="training_category_sort"/>
        <result property="remark" column="remark"/>
        <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="selectTrainingCategoryVo">
        select id,
               parent_id,
               training_category_name,
               training_category_code,
               training_category_picture_url,
               training_category_sort,
               remark,
               create_by,
               create_time,
               update_by,
               update_time
        from training_category
    </sql>

    <select id="selectTrainingCategoryList" parameterType="TrainingCategory" resultMap="TrainingCategoryResult">
        <include refid="selectTrainingCategoryVo"/>
        <where>
            <if test="parentId != null ">
                and parent_id = #{parentId}
            </if>
            <if test="trainingCategoryName != null  and trainingCategoryName != ''">
                and training_category_name like concat('%', #{trainingCategoryName}, '%')
            </if>
            <if test="trainingCategoryCode != null  and trainingCategoryCode != ''">
                and training_category_code = #{trainingCategoryCode}
            </if>
            <if test="trainingCategoryPictureUrl != null  and trainingCategoryPictureUrl != ''">
                and training_category_picture_url = #{trainingCategoryPictureUrl}
            </if>
            <if test="trainingCategorySort != null ">
                and training_category_sort = #{trainingCategorySort}
            </if>
        </where>
    </select>

    <select id="selectTrainingCategoryById" parameterType="Long"
            resultMap="TrainingCategoryResult">
        <include refid="selectTrainingCategoryVo"/>
        where id = #{id}
    </select>

    <insert id="insertTrainingCategory" parameterType="TrainingCategory" useGeneratedKeys="true"
            keyProperty="id">
        insert into training_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,
            </if>
            <if test="trainingCategoryName != null">training_category_name,
            </if>
            <if test="trainingCategoryCode != null">training_category_code,
            </if>
            <if test="trainingCategoryPictureUrl != null">training_category_picture_url,
            </if>
            <if test="trainingCategorySort != null">training_category_sort,
            </if>
            <if test="remark != null">remark,
            </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="trainingCategoryName != null">#{trainingCategoryName},
            </if>
            <if test="trainingCategoryCode != null">#{trainingCategoryCode},
            </if>
            <if test="trainingCategoryPictureUrl != null">#{trainingCategoryPictureUrl},
            </if>
            <if test="trainingCategorySort != null">#{trainingCategorySort},
            </if>
            <if test="remark != null">#{remark},
            </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="updateTrainingCategory" parameterType="TrainingCategory">
        update training_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id =
                #{parentId},
            </if>
            <if test="trainingCategoryName != null">training_category_name =
                #{trainingCategoryName},
            </if>
            <if test="trainingCategoryCode != null">training_category_code =
                #{trainingCategoryCode},
            </if>
            <if test="trainingCategoryPictureUrl != null">training_category_picture_url =
                #{trainingCategoryPictureUrl},
            </if>
            <if test="trainingCategorySort != null">training_category_sort =
                #{trainingCategorySort},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </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="deleteTrainingCategoryById" parameterType="Long">
        delete
        from training_category
        where id = #{id}
    </delete>

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

    <select id="selectTrainingCategoryByIds"
            resultType="com.xinelu.manage.domain.trainingcategory.TrainingCategory">
        <include refid="selectTrainingCategoryVo"/>
        where id in
        <foreach item="ids" collection="array" open="(" separator="," close=")">
            #{ids}
        </foreach>
    </select>
</mapper>