<?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.dezhi.mapper.BBusiDezhiVideoPackageChapterMapper">

  <resultMap type="BBusiDezhiVideoPackageChapter" id="BBusiDezhiVideoPackageChapterResult">
    <result property="id" column="id" />
    <result property="packId" column="pack_id" />
    <result property="chapterId" column="chapter_id" />
    <result property="chapterName" column="chapter_name" />
    <result property="from" column="from" />
  </resultMap>

  <sql id="selectBBusiDezhiVideoPackageChapterVo">
    select id, pack_id, chapter_id, chapter_name, `from` from b_busi_dezhi_video_package_chapter
  </sql>

  <select id="selectBBusiDezhiVideoPackageChapterList" parameterType="BBusiDezhiVideoPackageChapter" resultMap="BBusiDezhiVideoPackageChapterResult">
    <include refid="selectBBusiDezhiVideoPackageChapterVo" />
    <where>
      <if test="packId != null  and packId != ''"> and pack_id = #{packId}</if>
      <if test="chapterId != null  and chapterId != ''"> and chapter_id = #{chapterId}</if>
      <if test="chapterName != null  and chapterName != ''"> and chapter_name like concat('%', #{chapterName}, '%')</if>
      <if test="from != null  and from != ''"> and `from` = #{from}</if>
    </where>
  </select>

  <select id="selectBBusiDezhiVideoPackageChapterById" parameterType="Long" resultMap="BBusiDezhiVideoPackageChapterResult">
    <include refid="selectBBusiDezhiVideoPackageChapterVo" />
    where id = #{id}
  </select>

  <select id="selectBBusiDezhiVideoPackageChapterByChapterId" parameterType="String" resultMap="BBusiDezhiVideoPackageChapterResult">
    <include refid="selectBBusiDezhiVideoPackageChapterVo" />
    where chapter_id = #{chapterId}
  </select>

  <select id="selectBBusiDezhiVideoPackageChapterByPackId" parameterType="String" resultMap="BBusiDezhiVideoPackageChapterResult">
    <include refid="selectBBusiDezhiVideoPackageChapterVo" />
    where pack_id = #{packId}
  </select>

  <insert id="insertBBusiDezhiVideoPackageChapter" parameterType="BBusiDezhiVideoPackageChapter" useGeneratedKeys="true" keyProperty="id">
    insert into b_busi_dezhi_video_package_chapter
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="packId != null and packId != ''">pack_id,</if>
      <if test="chapterId != null">chapter_id,</if>
      <if test="chapterName != null">chapter_name,</if>
      <if test="from != null">`from`,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="packId != null and packId != ''">#{packId},</if>
      <if test="chapterId != null">#{chapterId},</if>
      <if test="chapterName != null">#{chapterName},</if>
      <if test="from != null">#{from},</if>
    </trim>
  </insert>

  <update id="updateBBusiDezhiVideoPackageChapter" parameterType="BBusiDezhiVideoPackageChapter">
    update b_busi_dezhi_video_package_chapter
    <trim prefix="SET" suffixOverrides=",">
      <if test="packId != null and packId != ''">pack_id = #{packId},</if>
      <if test="chapterId != null">chapter_id = #{chapterId},</if>
      <if test="chapterName != null">chapter_name = #{chapterName},</if>
      <if test="from != null">`from` = #{from},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteBBusiDezhiVideoPackageChapterById" parameterType="Long">
    delete from b_busi_dezhi_video_package_chapter where id = #{id}
  </delete>

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