<?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.slodon.b2b2c.dao.write.video.SvideoThemeVideoWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.video.pojo.SvideoThemeVideo">
    <id column="theme_video_id" property="themeVideoId" />
    <result column="theme_id" property="themeId" />
    <result column="video_id" property="videoId" />
    <result column="video_name" property="videoName" />
    <result column="video_image" property="videoImage" />
    <result column="video_path" property="videoPath" />
    <result column="introduction" property="introduction" />
    <result column="video_type" property="videoType" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="themeId != null">
        `theme_id`,
      </if>
      <if test="videoId != null">
        `video_id`,
      </if>
      <if test="videoName != null">
        `video_name`,
      </if>
      <if test="videoImage != null">
        `video_image`,
      </if>
      <if test="videoPath != null">
        `video_path`,
      </if>
      <if test="introduction != null">
        `introduction`,
      </if>
      <if test="videoType != null">
        `video_type`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `theme_video_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.themeVideoIdNotEquals != null">
          AND `theme_video_id` != #{example.themeVideoIdNotEquals}
        </if>
        <if test="example.themeVideoIdIn != null">
          AND `theme_video_id` in (${example.themeVideoIdIn})
        </if>
        <if test="example.themeId != null">
          AND `theme_id` = #{example.themeId}
        </if>
        <if test="example.videoId != null">
          AND `video_id` = #{example.videoId}
        </if>
        <if test="example.videoName != null">
          AND `video_name` = #{example.videoName}
        </if>
        <if test="example.videoNameLike != null">
          AND `video_name` like concat('%',#{example.videoNameLike},'%')
        </if>
        <if test="example.videoImage != null">
          AND `video_image` = #{example.videoImage}
        </if>
        <if test="example.videoPath != null">
          AND `video_path` = #{example.videoPath}
        </if>
        <if test="example.introduction != null">
          AND `introduction` = #{example.introduction}
        </if>
        <if test="example.videoType != null">
          AND `video_type` = #{example.videoType}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `theme_video_id` DESC
  </sql>
  <sql id="orderByOther">
    order by ${example.orderBy}
  </sql>
  <!--分组条件-->
  <sql id="groupBy">
    group by ${example.groupBy}
  </sql>
  <!--分页条件-->
  <sql id="limit">
    <if test="size != null and size &gt; 0">
      limit #{startRow},#{size}
    </if>
  </sql>
  <!--查询符合条件的记录数-->
  <select id="countByExample" parameterType="com.slodon.b2b2c.video.example.SvideoThemeVideoExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `svideo_theme_video`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `svideo_theme_video`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `svideo_theme_video`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(所有字段)-->
  <select id="listPageByExample" resultMap="resultMap">
    SELECT
      *
    FROM `svideo_theme_video`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--查询符合条件的记录(指定字段)-->
  <select id="listFieldsByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `svideo_theme_video`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(指定字段)-->
  <select id="listFieldsPageByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `svideo_theme_video`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--根据条件删除记录，可多条删除-->
  <delete id="deleteByExample">
    DELETE FROM `svideo_theme_video`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `svideo_theme_video`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="theme_video_id" keyProperty="themeVideoId" parameterType="com.slodon.b2b2c.video.pojo.SvideoThemeVideo" useGeneratedKeys="true">
    INSERT INTO `svideo_theme_video`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="themeId != null">
        #{themeId},
      </if>
      <if test="videoId != null">
        #{videoId},
      </if>
      <if test="videoName != null">
        #{videoName},
      </if>
      <if test="videoImage != null">
        #{videoImage},
      </if>
      <if test="videoPath != null">
        #{videoPath},
      </if>
      <if test="introduction != null">
        #{introduction},
      </if>
      <if test="videoType != null">
        #{videoType},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `svideo_theme_video`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.themeId != null">
        `theme_id` = #{record.themeId},
      </if>
      <if test="record.videoId != null">
        `video_id` = #{record.videoId},
      </if>
      <if test="record.videoName != null">
        `video_name` = #{record.videoName},
      </if>
      <if test="record.videoImage != null">
        `video_image` = #{record.videoImage},
      </if>
      <if test="record.videoPath != null">
        `video_path` = #{record.videoPath},
      </if>
      <if test="record.introduction != null">
        `introduction` = #{record.introduction},
      </if>
      <if test="record.videoType != null">
        `video_type` = #{record.videoType},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `svideo_theme_video`
    <trim prefix="SET" suffixOverrides=",">
      <if test="themeId != null">
        `theme_id` = #{themeId},
      </if>
      <if test="videoId != null">
        `video_id` = #{videoId},
      </if>
      <if test="videoName != null">
        `video_name` = #{videoName},
      </if>
      <if test="videoImage != null">
        `video_image` = #{videoImage},
      </if>
      <if test="videoPath != null">
        `video_path` = #{videoPath},
      </if>
      <if test="introduction != null">
        `introduction` = #{introduction},
      </if>
      <if test="videoType != null">
        `video_type` = #{videoType},
      </if>
    </trim>
    WHERE `theme_video_id` = #{themeVideoId}
  </update>
</mapper>