<?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.fs.course.mapper.FsUserCourseComplaintTypeMapper">

    <resultMap type="FsUserCourseComplaintType" id="FsUserCourseComplaintTypeResult">
        <result property="complaintTypeId"    column="complaint_type_id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="complaintTypeName"    column="complaint_type_name"    />
        <result property="typeLevel"    column="type_level"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectFsUserCourseComplaintTypeVo">
        select complaint_type_id, parent_id, complaint_type_name, type_level, create_time, update_time from fs_user_course_complaint_type
    </sql>

    <select id="selectFsUserCourseComplaintTypeList" parameterType="FsUserCourseComplaintType" resultMap="FsUserCourseComplaintTypeResult">
        <include refid="selectFsUserCourseComplaintTypeVo"/>
        <where>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="complaintTypeName != null  and complaintTypeName != ''"> and complaint_type_name like concat('%', #{complaintTypeName}, '%')</if>
            <if test="typeLevel != null "> and type_level = #{typeLevel}</if>
        </where>
    </select>

    <select id="selectFsUserCourseComplaintTypeByComplaintTypeId" parameterType="Long" resultMap="FsUserCourseComplaintTypeResult">
        <include refid="selectFsUserCourseComplaintTypeVo"/>
        where complaint_type_id = #{complaintTypeId}
    </select>

    <insert id="insertFsUserCourseComplaintType" parameterType="FsUserCourseComplaintType" useGeneratedKeys="true" keyProperty="complaintTypeId">
        insert into fs_user_course_complaint_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,</if>
            <if test="complaintTypeName != null">complaint_type_name,</if>
            <if test="typeLevel != null">type_level,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentId != null">#{parentId},</if>
            <if test="complaintTypeName != null">#{complaintTypeName},</if>
            <if test="typeLevel != null">#{typeLevel},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateFsUserCourseComplaintType" parameterType="FsUserCourseComplaintType">
        update fs_user_course_complaint_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="complaintTypeName != null">complaint_type_name = #{complaintTypeName},</if>
            <if test="typeLevel != null">type_level = #{typeLevel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where complaint_type_id = #{complaintTypeId}
    </update>

    <delete id="deleteFsUserCourseComplaintTypeByComplaintTypeId" parameterType="Long">
        delete from fs_user_course_complaint_type where complaint_type_id = #{complaintTypeId}
    </delete>

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