<?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.syzy.mapper.BBusiSyghVideoMapper">

  <resultMap type="BBusiSyghVideo" id="BBusiSyghVideoResult">
    <result property="id" column="id" />
    <result property="type" column="type" />
    <result property="name" column="name" />
    <result property="aliid" column="aliId" />
    <result property="pictUrl" column="pict_url" />
    <result property="plays" column="plays" />
    <result property="createTime" column="createTime" />
    <result property="status" column="status" />
  </resultMap>

  <select id="subjectNames" resultMap="BBusiSyghVideoResult">
    select distinct subjectId, subjectName from b_busi_sygh_video
  </select>

  <select id="knowledgeNames" resultMap="BBusiSyghVideoResult"> <!-- where status &gt; 0 -->
    select distinct knowledgeId, knowledgeName from b_busi_sygh_video where subjectId = #{subjectId}
  </select>

  <sql id="selectBBusiSyghVideoVo">
    select id, type, subjectName, knowledgeName, name, aliId, pict_url, plays, createTime, status from b_busi_sygh_video
  </sql>

  <select id="selectBBusiSyghVideoList" parameterType="BBusiSyghVideo" resultMap="BBusiSyghVideoResult">
    <include refid="selectBBusiSyghVideoVo" />
    <where>
      <if test="type != null "> and type = #{type}</if>
      <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
      <if test="subjectName != null  and subjectName != ''"> and subjectName = #{subjectName}</if>
      <if test="subjectId != null"> and subjectId = #{subjectId}</if>
      <if test="knowledgeName != null  and knowledgeName != ''"> and knowledgeName = #{knowledgeName}</if>
      <if test="knowledgeId != null"> and knowledgeId = #{knowledgeId}</if>
      <if test="aliid != null  and aliid != ''"> and aliId = #{aliid}</if>
      <if test="pictUrl != null  and pictUrl != ''"> and pict_url = #{pictUrl}</if>
      <if test="plays != null "> and plays = #{plays}</if>
      <if test="createTime != null "> and createTime = #{createTime}</if>
      <if test="status != null "> and status = #{status}</if>
      <if test="status == null "> and status &gt; 0 </if>
    </where>
    order by id asc 
  </select>

  <select id="selectBBusiSyghVideoById" parameterType="Long" resultMap="BBusiSyghVideoResult">
    <include refid="selectBBusiSyghVideoVo" />
    where id = #{id}
  </select>

  <insert id="insertBBusiSyghVideo" parameterType="BBusiSyghVideo" useGeneratedKeys="true" keyProperty="id">
    insert into b_busi_sygh_video
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="type != null">type,</if>
      <if test="name != null">name,</if>
      <if test="aliid != null">aliId,</if>
      <if test="pictUrl != null">pict_url,</if>
      <if test="plays != null">plays,</if>
      <if test="createTime != null">createTime,</if>
      <if test="status != null">status,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="type != null">#{type},</if>
      <if test="name != null">#{name},</if>
      <if test="aliid != null">#{aliid},</if>
      <if test="pictUrl != null">#{pictUrl},</if>
      <if test="plays != null">#{plays},</if>
      <if test="createTime != null">#{createTime},</if>
      <if test="status != null">#{status},</if>
    </trim>
  </insert>

  <update id="updateBBusiSyghVideo" parameterType="BBusiSyghVideo">
    update b_busi_sygh_video
    <trim prefix="SET" suffixOverrides=",">
      <if test="type != null">type = #{type},</if>
      <if test="name != null">name = #{name},</if>
      <if test="aliid != null">aliId = #{aliid},</if>
      <if test="pictUrl != null">pict_url = #{pictUrl},</if>
      <if test="plays != null">plays = #{plays},</if>
      <if test="createTime != null">createTime = #{createTime},</if>
      <if test="status != null">status = #{status},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteBBusiSyghVideoById" parameterType="Long">
    UPDATE b_busi_sygh_video set status=0 where id = #{id}
  </delete>

  <delete id="deleteBBusiSyghVideoByIds" parameterType="String">
    UPDATE b_busi_sygh_video set status=0 where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
      #{id}
    </foreach>
  </delete>
</mapper>