<?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.BBusiDezhiVideoPackageMapper">

  <resultMap type="BBusiDezhiVideoPackage" id="BBusiDezhiVideoPackageResult">
    <result property="id" column="id" />
    <result property="type" column="type" />
    <result property="ctype" column="ctype" />
    <result property="course" column="course" />
    <result property="grade" column="grade" />
    <result property="version" column="version" />
    <result property="packId" column="pack_id" />
    <result property="packName" column="pack_name" />
    <result property="packImgurl" column="pack_imgurl" />
    <result property="packIntro" column="pack_intro" />
    <result property="sectionNum" column="section_num" />
    <result property="from" column="from" />
    <result property="priority" column="priority" />
  </resultMap>

  <sql id="selectBBusiDezhiVideoPackageVo">
    select id, type, ctype, course, grade, version, pack_id, pack_name, pack_imgurl, pack_intro, section_num, `from`, priority from b_busi_dezhi_video_package
  </sql>

  <select id="selectBBusiDezhiVideoPackageList" parameterType="BBusiDezhiVideoPackage" resultMap="BBusiDezhiVideoPackageResult">
    <include refid="selectBBusiDezhiVideoPackageVo" />
    <where>
      <if test="type != null "> and type = #{type}</if>
      <if test="ctype != null  and ctype != ''"> and ctype = #{ctype}</if>
      <if test="course != null  and course != ''"> and course = #{course}</if>
      <if test="grade != null  and grade != ''"> and grade = #{grade}</if>
      <if test="version != null  and version != ''"> and version = #{version}</if>
      <if test="packId != null  and packId != ''"> and pack_id = #{packId}</if>
      <if test="packName != null  and packName != ''"> and pack_name like concat('%', #{packName}, '%')</if>
      <if test="packImgurl != null  and packImgurl != ''"> and pack_imgurl = #{packImgurl}</if>
      <if test="packIntro != null  and packIntro != ''"> and pack_intro = #{packIntro}</if>
      <if test="sectionNum != null "> and section_num = #{sectionNum}</if>
      <if test="from != null  and from != ''"> and `from` = #{from}</if>
      <if test="priority != null "> and priority = #{priority}</if>
    </where>
    order by priority  
  </select>

  <select id="selectBBusiDezhiVideoPackageById" parameterType="Long" resultMap="BBusiDezhiVideoPackageResult">
    <include refid="selectBBusiDezhiVideoPackageVo" />
    where id = #{id}
  </select>

  <select id="selectBBusiDezhiVideoPackageByPackId" parameterType="String" resultMap="BBusiDezhiVideoPackageResult">
    <include refid="selectBBusiDezhiVideoPackageVo" />
    where pack_id = #{packId}
  </select>

  <insert id="insertBBusiDezhiVideoPackage" parameterType="BBusiDezhiVideoPackage" useGeneratedKeys="true" keyProperty="id">
    insert into b_busi_dezhi_video_package
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="type != null">type,</if>
      <if test="ctype != null">ctype,</if>
      <if test="course != null">course,</if>
      <if test="grade != null">grade,</if>
      <if test="version != null">version,</if>
      <if test="packId != null and packId != ''">pack_id,</if>
      <if test="packName != null">pack_name,</if>
      <if test="packImgurl != null">pack_imgurl,</if>
      <if test="packIntro != null">pack_intro,</if>
      <if test="sectionNum != null">section_num,</if>
      <if test="from != null">`from`,</if>
      <if test="priority != null">priority,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="type != null">#{type},</if>
      <if test="ctype != null">#{ctype},</if>
      <if test="course != null">#{course},</if>
      <if test="grade != null">#{grade},</if>
      <if test="version != null">#{version},</if>
      <if test="packId != null and packId != ''">#{packId},</if>
      <if test="packName != null">#{packName},</if>
      <if test="packImgurl != null">#{packImgurl},</if>
      <if test="packIntro != null">#{packIntro},</if>
      <if test="sectionNum != null">#{sectionNum},</if>
      <if test="from != null">#{from},</if>
      <if test="priority != null">#{priority},</if>
    </trim>
  </insert>

  <update id="updateBBusiDezhiVideoPackage" parameterType="BBusiDezhiVideoPackage">
    update b_busi_dezhi_video_package
    <trim prefix="SET" suffixOverrides=",">
      <if test="type != null">type = #{type},</if>
      <if test="ctype != null">ctype = #{ctype},</if>
      <if test="course != null">course = #{course},</if>
      <if test="grade != null">grade = #{grade},</if>
      <if test="version != null">version = #{version},</if>
      <if test="packId != null and packId != ''">pack_id = #{packId},</if>
      <if test="packName != null">pack_name = #{packName},</if>
      <if test="packImgurl != null">pack_imgurl = #{packImgurl},</if>
      <if test="packIntro != null">pack_intro = #{packIntro},</if>
      <if test="sectionNum != null">section_num = #{sectionNum},</if>
      <if test="from != null">`from` = #{from},</if>
      <if test="priority != null">priority = #{priority},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteBBusiDezhiVideoPackageById" parameterType="Long">
    delete from b_busi_dezhi_video_package where id = #{id}
  </delete>

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