<?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.ruoyi.project.benyi.mapper.ByMicrocourseMapper">

    <resultMap type="ByMicrocourse" id="ByMicrocourseResult">
        <result property="id" column="id"/>
        <result property="title" column="title"/>
        <result property="author" column="author"/>
        <result property="contents" column="contents"/>
        <result property="type" column="type"/>
        <result property="scpoe" column="scpoe"/>
        <result property="upanddown" column="upanddown"/>
        <result property="sort" column="sort"/>
        <result property="createTime" column="create_time"/>
        <result property="parentId" column="parent_id"/>
    </resultMap>

    <sql id="selectByMicrocourseVo">
        select id, title, author, contents, type, scpoe, upanddown, sort, create_time from by_microcourse
    </sql>

    <sql id="selectByMicrocourseVoTree">
select dict_value+9999 id, 0 parent_id,dict_label title,dict_sort sort   from sys_dict_data where dict_type='sys_yebjlx' and dict_label !='托班（2-3岁）'
                union all
				select 1000101 ,concat(10001),'上册',5
				union all
				select 1000102 ,concat(10001),'下册',6
				union all
				select 1000201 ,concat(10002),'上册',7
				union all
				select 1000202 ,concat(10002),'下册',8
				union all
				select 1000301 ,concat(10003),'上册',9
				union all
				select 1000302 ,concat(10003),'下册',10
				union all
				select concat(1000101,dict_value), 1000101,dict_label title,dict_sort sort   from sys_dict_data where dict_type='sys_dm_wxkclx' and (dict_label not in ('百家姓','绕口令','游戏','孟子名言','谚语','千字文','韩非子名言','《诗经》名言','《春秋左传》名言','脑筋急转弯','《易经》名言 ','老子名言'))
				union all
				select concat(1000102,dict_value), 1000102,dict_label title,dict_sort sort   from sys_dict_data where dict_type='sys_dm_wxkclx' and (dict_label not in ('百家姓','绕口令','游戏','孟子名言','谚语','千字文','韩非子名言','《诗经》名言','《春秋左传》名言','脑筋急转弯','《易经》名言 ','老子名言'))
				union all
				select concat(1000201,dict_value), 1000201,dict_label title,dict_sort sort   from sys_dict_data where dict_type='sys_dm_wxkclx' and (dict_label not in ('三字经（节选）','千字文','语言游戏','孔子名言','韩非子名言','《诗经》名言','《春秋左传》名言','脑筋急转弯','《易经》名言 ','老子名言'))
				union all
				select concat(1000202,dict_value), 1000202,dict_label title,dict_sort sort   from sys_dict_data where dict_type='sys_dm_wxkclx' and (dict_label not in ('三字经（节选）','千字文','语言游戏','孔子名言','韩非子名言','《诗经》名言','《春秋左传》名言','孟子名言','脑筋急转弯','《易经》名言 '))
				union all
				select concat(1000301,dict_value), 1000301,dict_label title,dict_sort sort   from sys_dict_data where dict_type='sys_dm_wxkclx' and (dict_label not in ('百家姓','三字经（节选）','语言游戏','孔子名言','歇后语','孟子名言','《春秋左传》名言','《易经》名言 ','老子名言'))
				union all
				select concat(1000302,dict_value), 1000302,dict_label title,dict_sort sort   from sys_dict_data where dict_type='sys_dm_wxkclx' and (dict_label not in ('百家姓','三字经（节选）','语言游戏','孔子名言','歇后语','孟子名言','韩非子名言','《诗经》名言','老子名言'))
				union all
        select id, CONCAT(scpoe+9999,upanddown,type), title, sort from by_microcourse
    </sql>

    <select id="selectByMicrocourseListTree" parameterType="ByMicrocourse" resultMap="ByMicrocourseResult">
        <include refid="selectByMicrocourseVoTree"/>
        <where>
            <if test="title != null  and title != ''">and title like concat('%', #{title}, '%')</if>
        </where>
        order by sort
    </select>

    <select id="selectByMicrocourseList" parameterType="ByMicrocourse" resultMap="ByMicrocourseResult">
        <include refid="selectByMicrocourseVo"/>
        <where>
            <if test="title != null  and title != ''">and title like concat('%', #{title}, '%')</if>
            <if test="author != null  and author != ''">and author like concat('%', #{author}, '%')</if>
            <if test="contents != null  and contents != ''">and contents = #{contents}</if>
            <if test="type != null  and type != ''">and type = #{type}</if>
            <if test="scpoe != null  and scpoe != ''">and scpoe = #{scpoe}</if>
            <if test="upanddown != null  and upanddown != ''">and upanddown = #{upanddown}</if>
        </where>
        order by sort
    </select>

    <select id="selectByMicrocourseById" parameterType="Long" resultMap="ByMicrocourseResult">
        <include refid="selectByMicrocourseVo"/>
        where id = #{id}
    </select>

    <insert id="insertByMicrocourse" parameterType="ByMicrocourse" useGeneratedKeys="true" keyProperty="id">
        insert into by_microcourse
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null  and title != ''">title,</if>
            <if test="author != null  and author != ''">author,</if>
            <if test="contents != null  and contents != ''">contents,</if>
            <if test="type != null  and type != ''">type,</if>
            <if test="scpoe != null  and scpoe != ''">scpoe,</if>
            <if test="upanddown != null  and upanddown != ''">upanddown,</if>
            <if test="sort != null ">sort,</if>
            <if test="createTime != null ">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null  and title != ''">#{title},</if>
            <if test="author != null  and author != ''">#{author},</if>
            <if test="contents != null  and contents != ''">#{contents},</if>
            <if test="type != null  and type != ''">#{type},</if>
            <if test="scpoe != null  and scpoe != ''">#{scpoe},</if>
            <if test="upanddown != null  and upanddown != ''">#{upanddown},</if>
            <if test="sort != null ">#{sort},</if>
            <if test="createTime != null ">#{createTime},</if>
        </trim>
    </insert>

    <update id="updateByMicrocourse" parameterType="ByMicrocourse">
        update by_microcourse
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null  and title != ''">title = #{title},</if>
            <if test="author != null  and author != ''">author = #{author},</if>
            <if test="contents != null  and contents != ''">contents = #{contents},</if>
            <if test="type != null  and type != ''">type = #{type},</if>
            <if test="scpoe != null  and scpoe != ''">scpoe = #{scpoe},</if>
            <if test="upanddown != null  and upanddown != ''">upanddown = #{upanddown},</if>
            <if test="sort != null ">sort = #{sort},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteByMicrocourseById" parameterType="Long">
        delete from by_microcourse where id = #{id}
    </delete>

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

</mapper>