<?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.goods.GoodsRankWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.goods.pojo.GoodsRank">
    <id column="rank_id" property="rankId" />
    <result column="rank_name" property="rankName" />
    <result column="category_id" property="categoryId" />
    <result column="category_name" property="categoryName" />
    <result column="sort" property="sort" />
    <result column="background_image" property="backgroundImage" />
    <result column="rank_type" property="rankType" />
    <result column="goods_category_id" property="goodsCategoryId" />
    <result column="goods_category_name" property="goodsCategoryName" />
    <result column="stats_time" property="statsTime" />
    <result column="best_seller_rank_rule" property="bestSellerRankRule" />
    <result column="new_product_rank_rule" property="newProductRankRule" />
    <result column="high_comment_num" property="highCommentNum" />
    <result column="high_comment_rate" property="highCommentRate" />
    <result column="is_auto_update" property="isAutoUpdate" />
    <result column="state" property="state" />
    <result column="description" property="description" />
    <result column="create_time" property="createTime" />
    <result column="create_admin_id" property="createAdminId" />
    <result column="update_time" property="updateTime" />
    <result column="update_admin_id" property="updateAdminId" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="rankName != null">
        `rank_name`,
      </if>
      <if test="categoryId != null">
        `category_id`,
      </if>
      <if test="categoryName != null">
        `category_name`,
      </if>
      <if test="sort != null">
        `sort`,
      </if>
      <if test="backgroundImage != null">
        `background_image`,
      </if>
      <if test="rankType != null">
        `rank_type`,
      </if>
      <if test="goodsCategoryId != null">
        `goods_category_id`,
      </if>
      <if test="goodsCategoryName != null">
        `goods_category_name`,
      </if>
      <if test="statsTime != null">
        `stats_time`,
      </if>
      <if test="bestSellerRankRule != null">
        `best_seller_rank_rule`,
      </if>
      <if test="newProductRankRule != null">
        `new_product_rank_rule`,
      </if>
      <if test="highCommentNum != null">
        `high_comment_num`,
      </if>
      <if test="highCommentRate != null">
        `high_comment_rate`,
      </if>
      <if test="isAutoUpdate != null">
        `is_auto_update`,
      </if>
      <if test="state != null">
        `state`,
      </if>
      <if test="description != null">
        `description`,
      </if>
      <if test="createTime != null">
        `create_time`,
      </if>
      <if test="createAdminId != null">
        `create_admin_id`,
      </if>
      <if test="updateTime != null">
        `update_time`,
      </if>
      <if test="updateAdminId != null">
        `update_admin_id`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `rank_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.rankIdNotEquals != null">
          AND `rank_id` != #{example.rankIdNotEquals}
        </if>
        <if test="example.rankIdIn != null">
          AND `rank_id` in (${example.rankIdIn})
        </if>
        <if test="example.rankName != null">
          AND `rank_name` = #{example.rankName}
        </if>
        <if test="example.rankNameLike != null">
          AND `rank_name` like concat('%',#{example.rankNameLike},'%')
        </if>
        <if test="example.categoryId != null">
          AND `category_id` = #{example.categoryId}
        </if>
        <if test="example.categoryName != null">
          AND `category_name` = #{example.categoryName}
        </if>
        <if test="example.categoryNameLike != null">
          AND `category_name` like concat('%',#{example.categoryNameLike},'%')
        </if>
        <if test="example.sort != null">
          AND `sort` = #{example.sort}
        </if>
        <if test="example.backgroundImage != null">
          AND `background_image` = #{example.backgroundImage}
        </if>
        <if test="example.rankType != null">
          AND `rank_type` = #{example.rankType}
        </if>
        <if test="example.goodsCategoryId != null">
          AND `goods_category_id` = #{example.goodsCategoryId}
        </if>
        <if test="example.goodsCategoryName != null">
          AND `goods_category_name` = #{example.goodsCategoryName}
        </if>
        <if test="example.goodsCategoryNameLike != null">
          AND `goods_category_name` like concat('%',#{example.goodsCategoryNameLike},'%')
        </if>
        <if test="example.statsTime != null">
          AND `stats_time` = #{example.statsTime}
        </if>
        <if test="example.bestSellerRankRule != null">
          AND `best_seller_rank_rule` = #{example.bestSellerRankRule}
        </if>
        <if test="example.newProductRankRule != null">
          AND `new_product_rank_rule` = #{example.newProductRankRule}
        </if>
        <if test="example.highCommentNum != null">
          AND `high_comment_num` = #{example.highCommentNum}
        </if>
        <if test="example.highCommentRate != null">
          AND `high_comment_rate` = #{example.highCommentRate}
        </if>
        <if test="example.isAutoUpdate != null">
          AND `is_auto_update` = #{example.isAutoUpdate}
        </if>
        <if test="example.state != null">
          AND `state` = #{example.state}
        </if>
        <if test="example.stateIn != null">
          AND `state` in (${example.stateIn})
        </if>
        <if test="example.stateNotIn != null">
          AND `state` not in (${example.stateNotIn})
        </if>
        <if test="example.stateNotEquals != null">
          AND `state` != #{example.stateNotEquals}
        </if>
        <if test="example.description != null">
          AND `description` = #{example.description}
        </if>
        <if test="example.createTimeAfter != null">
          AND `create_time` <![CDATA[ >= ]]> #{example.createTimeAfter}
        </if>
        <if test="example.createTimeBefore != null">
          AND `create_time` <![CDATA[ <= ]]> #{example.createTimeBefore}
        </if>
        <if test="example.createAdminId != null">
          AND `create_admin_id` = #{example.createAdminId}
        </if>
        <if test="example.updateTimeAfter != null">
          AND `update_time` <![CDATA[ >= ]]> #{example.updateTimeAfter}
        </if>
        <if test="example.updateTimeBefore != null">
          AND `update_time` <![CDATA[ <= ]]> #{example.updateTimeBefore}
        </if>
        <if test="example.updateAdminId != null">
          AND `update_admin_id` = #{example.updateAdminId}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `rank_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.goods.example.GoodsRankExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `goods_rank`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `goods_rank`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `goods_rank`
    <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 `goods_rank`
    <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 `goods_rank`
    <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 `goods_rank`
    <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 `goods_rank`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `goods_rank`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="rank_id" keyProperty="rankId" parameterType="com.slodon.b2b2c.goods.pojo.GoodsRank" useGeneratedKeys="true">
    INSERT INTO `goods_rank`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="rankName != null">
        #{rankName},
      </if>
      <if test="categoryId != null">
        #{categoryId},
      </if>
      <if test="categoryName != null">
        #{categoryName},
      </if>
      <if test="sort != null">
        #{sort},
      </if>
      <if test="backgroundImage != null">
        #{backgroundImage},
      </if>
      <if test="rankType != null">
        #{rankType},
      </if>
      <if test="goodsCategoryId != null">
        #{goodsCategoryId},
      </if>
      <if test="goodsCategoryName != null">
        #{goodsCategoryName},
      </if>
      <if test="statsTime != null">
        #{statsTime},
      </if>
      <if test="bestSellerRankRule != null">
        #{bestSellerRankRule},
      </if>
      <if test="newProductRankRule != null">
        #{newProductRankRule},
      </if>
      <if test="highCommentNum != null">
        #{highCommentNum},
      </if>
      <if test="highCommentRate != null">
        #{highCommentRate},
      </if>
      <if test="isAutoUpdate != null">
        #{isAutoUpdate},
      </if>
      <if test="state != null">
        #{state},
      </if>
      <if test="description != null">
        #{description},
      </if>
      <if test="createTime != null">
        #{createTime},
      </if>
      <if test="createAdminId != null">
        #{createAdminId},
      </if>
      <if test="updateTime != null">
        #{updateTime},
      </if>
      <if test="updateAdminId != null">
        #{updateAdminId},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `goods_rank`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.rankName != null">
        `rank_name` = #{record.rankName},
      </if>
      <if test="record.categoryId != null">
        `category_id` = #{record.categoryId},
      </if>
      <if test="record.categoryName != null">
        `category_name` = #{record.categoryName},
      </if>
      <if test="record.sort != null">
        `sort` = #{record.sort},
      </if>
      <if test="record.backgroundImage != null">
        `background_image` = #{record.backgroundImage},
      </if>
      <if test="record.rankType != null">
        `rank_type` = #{record.rankType},
      </if>
      <if test="record.goodsCategoryId != null">
        `goods_category_id` = #{record.goodsCategoryId},
      </if>
      <if test="record.goodsCategoryName != null">
        `goods_category_name` = #{record.goodsCategoryName},
      </if>
      <if test="record.statsTime != null">
        `stats_time` = #{record.statsTime},
      </if>
      <if test="record.bestSellerRankRule != null">
        `best_seller_rank_rule` = #{record.bestSellerRankRule},
      </if>
      <if test="record.newProductRankRule != null">
        `new_product_rank_rule` = #{record.newProductRankRule},
      </if>
      <if test="record.highCommentNum != null">
        `high_comment_num` = #{record.highCommentNum},
      </if>
      <if test="record.highCommentRate != null">
        `high_comment_rate` = #{record.highCommentRate},
      </if>
      <if test="record.isAutoUpdate != null">
        `is_auto_update` = #{record.isAutoUpdate},
      </if>
      <if test="record.state != null">
        `state` = #{record.state},
      </if>
      <if test="record.description != null">
        `description` = #{record.description},
      </if>
      <if test="record.createTime != null">
        `create_time` = #{record.createTime},
      </if>
      <if test="record.createAdminId != null">
        `create_admin_id` = #{record.createAdminId},
      </if>
      <if test="record.updateTime != null">
        `update_time` = #{record.updateTime},
      </if>
      <if test="record.updateAdminId != null">
        `update_admin_id` = #{record.updateAdminId},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `goods_rank`
    <trim prefix="SET" suffixOverrides=",">
      <if test="rankName != null">
        `rank_name` = #{rankName},
      </if>
      <if test="categoryId != null">
        `category_id` = #{categoryId},
      </if>
      <if test="categoryName != null">
        `category_name` = #{categoryName},
      </if>
      <if test="sort != null">
        `sort` = #{sort},
      </if>
      <if test="backgroundImage != null">
        `background_image` = #{backgroundImage},
      </if>
      <if test="rankType != null">
        `rank_type` = #{rankType},
      </if>
      <if test="goodsCategoryId != null">
        `goods_category_id` = #{goodsCategoryId},
      </if>
      <if test="goodsCategoryName != null">
        `goods_category_name` = #{goodsCategoryName},
      </if>
      <if test="statsTime != null">
        `stats_time` = #{statsTime},
      </if>
      <if test="bestSellerRankRule != null">
        `best_seller_rank_rule` = #{bestSellerRankRule},
      </if>
      <if test="newProductRankRule != null">
        `new_product_rank_rule` = #{newProductRankRule},
      </if>
      <if test="highCommentNum != null">
        `high_comment_num` = #{highCommentNum},
      </if>
      <if test="highCommentRate != null">
        `high_comment_rate` = #{highCommentRate},
      </if>
      <if test="isAutoUpdate != null">
        `is_auto_update` = #{isAutoUpdate},
      </if>
      <if test="state != null">
        `state` = #{state},
      </if>
      <if test="description != null">
        `description` = #{description},
      </if>
      <if test="createTime != null">
        `create_time` = #{createTime},
      </if>
      <if test="createAdminId != null">
        `create_admin_id` = #{createAdminId},
      </if>
      <if test="updateTime != null">
        `update_time` = #{updateTime},
      </if>
      <if test="updateAdminId != null">
        `update_admin_id` = #{updateAdminId},
      </if>
    </trim>
    WHERE `rank_id` = #{rankId}
  </update>
</mapper>