<?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.seller.StoreGradeWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.seller.pojo.StoreGrade">
    <id column="grade_id" property="gradeId" />
    <result column="grade_name" property="gradeName" />
    <result column="goods_limit" property="goodsLimit" />
    <result column="recommend_limit" property="recommendLimit" />
    <result column="price" property="price" />
    <result column="confirm" property="confirm" />
    <result column="sort" property="sort" />
    <result column="description" property="description" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="gradeName != null">
        `grade_name`,
      </if>
      <if test="goodsLimit != null">
        `goods_limit`,
      </if>
      <if test="recommendLimit != null">
        `recommend_limit`,
      </if>
      <if test="price != null">
        `price`,
      </if>
      <if test="confirm != null">
        `confirm`,
      </if>
      <if test="sort != null">
        `sort`,
      </if>
      <if test="description != null">
        `description`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `grade_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.gradeIdNotEquals != null">
          AND `grade_id` != #{example.gradeIdNotEquals}
        </if>
        <if test="example.gradeIdIn != null">
          AND `grade_id` in (${example.gradeIdIn})
        </if>
        <if test="example.gradeName != null">
          AND `grade_name` = #{example.gradeName}
        </if>
        <if test="example.gradeNameLike != null">
          AND `grade_name` like concat('%',#{example.gradeNameLike},'%')
        </if>
        <if test="example.goodsLimit != null">
          AND `goods_limit` = #{example.goodsLimit}
        </if>
        <if test="example.recommendLimit != null">
          AND `recommend_limit` = #{example.recommendLimit}
        </if>
        <if test="example.price != null">
          AND `price` = #{example.price}
        </if>
        <if test="example.confirm != null">
          AND `confirm` = #{example.confirm}
        </if>
        <if test="example.sort != null">
          AND `sort` = #{example.sort}
        </if>
        <if test="example.description != null">
          AND `description` = #{example.description}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `grade_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.seller.example.StoreGradeExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `store_grade`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `store_grade`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `store_grade`
    <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 `store_grade`
    <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 `store_grade`
    <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 `store_grade`
    <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 `store_grade`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `store_grade`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="grade_id" keyProperty="gradeId" parameterType="com.slodon.b2b2c.seller.pojo.StoreGrade" useGeneratedKeys="true">
    INSERT INTO `store_grade`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="gradeName != null">
        #{gradeName},
      </if>
      <if test="goodsLimit != null">
        #{goodsLimit},
      </if>
      <if test="recommendLimit != null">
        #{recommendLimit},
      </if>
      <if test="price != null">
        #{price},
      </if>
      <if test="confirm != null">
        #{confirm},
      </if>
      <if test="sort != null">
        #{sort},
      </if>
      <if test="description != null">
        #{description},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `store_grade`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.gradeName != null">
        `grade_name` = #{record.gradeName},
      </if>
      <if test="record.goodsLimit != null">
        `goods_limit` = #{record.goodsLimit},
      </if>
      <if test="record.recommendLimit != null">
        `recommend_limit` = #{record.recommendLimit},
      </if>
      <if test="record.price != null">
        `price` = #{record.price},
      </if>
      <if test="record.confirm != null">
        `confirm` = #{record.confirm},
      </if>
      <if test="record.sort != null">
        `sort` = #{record.sort},
      </if>
      <if test="record.description != null">
        `description` = #{record.description},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `store_grade`
    <trim prefix="SET" suffixOverrides=",">
      <if test="gradeName != null">
        `grade_name` = #{gradeName},
      </if>
      <if test="goodsLimit != null">
        `goods_limit` = #{goodsLimit},
      </if>
      <if test="recommendLimit != null">
        `recommend_limit` = #{recommendLimit},
      </if>
      <if test="price != null">
        `price` = #{price},
      </if>
      <if test="confirm != null">
        `confirm` = #{confirm},
      </if>
      <if test="sort != null">
        `sort` = #{sort},
      </if>
      <if test="description != null">
        `description` = #{description},
      </if>
    </trim>
    WHERE `grade_id` = #{gradeId}
  </update>
</mapper>