<?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.VideoGoodsWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.video.pojo.VideoGoods">
    <id column="video_goods_id" property="videoGoodsId" />
    <result column="video_id" property="videoId" />
    <result column="video_type" property="videoType" />
    <result column="author_id" property="authorId" />
    <result column="goods_id" property="goodsId" />
    <result column="goods_name" property="goodsName" />
    <result column="goods_brief" property="goodsBrief" />
    <result column="goods_price" property="goodsPrice" />
    <result column="goods_image" property="goodsImage" />
    <result column="default_product_id" property="defaultProductId" />
    <result column="click_num" property="clickNum" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="videoId != null">
        `video_id`,
      </if>
      <if test="videoType != null">
        `video_type`,
      </if>
      <if test="authorId != null">
        `author_id`,
      </if>
      <if test="goodsId != null">
        `goods_id`,
      </if>
      <if test="goodsName != null">
        `goods_name`,
      </if>
      <if test="goodsBrief != null">
        `goods_brief`,
      </if>
      <if test="goodsPrice != null">
        `goods_price`,
      </if>
      <if test="goodsImage != null">
        `goods_image`,
      </if>
      <if test="defaultProductId != null">
        `default_product_id`,
      </if>
      <if test="clickNum != null">
        `click_num`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `video_goods_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.videoGoodsIdNotEquals != null">
          AND `video_goods_id` != #{example.videoGoodsIdNotEquals}
        </if>
        <if test="example.videoGoodsIdIn != null">
          AND `video_goods_id` in (${example.videoGoodsIdIn})
        </if>
        <if test="example.videoId != null">
          AND `video_id` = #{example.videoId}
        </if>
        <if test="example.videoType != null">
          AND `video_type` = #{example.videoType}
        </if>
        <if test="example.authorId != null">
          AND `author_id` = #{example.authorId}
        </if>
        <if test="example.goodsId != null">
          AND `goods_id` = #{example.goodsId}
        </if>
        <if test="example.goodsName != null">
          AND `goods_name` = #{example.goodsName}
        </if>
        <if test="example.goodsNameLike != null">
          AND `goods_name` like concat('%',#{example.goodsNameLike},'%')
        </if>
        <if test="example.goodsBrief != null">
          AND `goods_brief` = #{example.goodsBrief}
        </if>
        <if test="example.goodsPrice != null">
          AND `goods_price` = #{example.goodsPrice}
        </if>
        <if test="example.goodsImage != null">
          AND `goods_image` = #{example.goodsImage}
        </if>
        <if test="example.defaultProductId != null">
          AND `default_product_id` = #{example.defaultProductId}
        </if>
        <if test="example.clickNum != null">
          AND `click_num` = #{example.clickNum}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `video_goods_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.VideoGoodsExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `video_goods`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `video_goods`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `video_goods`
    <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 `video_goods`
    <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 `video_goods`
    <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 `video_goods`
    <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 `video_goods`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `video_goods`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="video_goods_id" keyProperty="videoGoodsId" parameterType="com.slodon.b2b2c.video.pojo.VideoGoods" useGeneratedKeys="true">
    INSERT INTO `video_goods`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="videoId != null">
        #{videoId},
      </if>
      <if test="videoType != null">
        #{videoType},
      </if>
      <if test="authorId != null">
        #{authorId},
      </if>
      <if test="goodsId != null">
        #{goodsId},
      </if>
      <if test="goodsName != null">
        #{goodsName},
      </if>
      <if test="goodsBrief != null">
        #{goodsBrief},
      </if>
      <if test="goodsPrice != null">
        #{goodsPrice},
      </if>
      <if test="goodsImage != null">
        #{goodsImage},
      </if>
      <if test="defaultProductId != null">
        #{defaultProductId},
      </if>
      <if test="clickNum != null">
        #{clickNum},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `video_goods`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.videoId != null">
        `video_id` = #{record.videoId},
      </if>
      <if test="record.videoType != null">
        `video_type` = #{record.videoType},
      </if>
      <if test="record.authorId != null">
        `author_id` = #{record.authorId},
      </if>
      <if test="record.goodsId != null">
        `goods_id` = #{record.goodsId},
      </if>
      <if test="record.goodsName != null">
        `goods_name` = #{record.goodsName},
      </if>
      <if test="record.goodsBrief != null">
        `goods_brief` = #{record.goodsBrief},
      </if>
      <if test="record.goodsPrice != null">
        `goods_price` = #{record.goodsPrice},
      </if>
      <if test="record.goodsImage != null">
        `goods_image` = #{record.goodsImage},
      </if>
      <if test="record.defaultProductId != null">
        `default_product_id` = #{record.defaultProductId},
      </if>
      <if test="record.clickNum != null">
        `click_num` = #{record.clickNum},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `video_goods`
    <trim prefix="SET" suffixOverrides=",">
      <if test="videoId != null">
        `video_id` = #{videoId},
      </if>
      <if test="videoType != null">
        `video_type` = #{videoType},
      </if>
      <if test="authorId != null">
        `author_id` = #{authorId},
      </if>
      <if test="goodsId != null">
        `goods_id` = #{goodsId},
      </if>
      <if test="goodsName != null">
        `goods_name` = #{goodsName},
      </if>
      <if test="goodsBrief != null">
        `goods_brief` = #{goodsBrief},
      </if>
      <if test="goodsPrice != null">
        `goods_price` = #{goodsPrice},
      </if>
      <if test="goodsImage != null">
        `goods_image` = #{goodsImage},
      </if>
      <if test="defaultProductId != null">
        `default_product_id` = #{defaultProductId},
      </if>
      <if test="clickNum != null">
        `click_num` = #{clickNum},
      </if>
    </trim>
    WHERE `video_goods_id` = #{videoGoodsId}
  </update>
</mapper>