<?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.integral.IntegralGoodsBindLabelWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.integral.pojo.IntegralGoodsBindLabel">
    <id column="bind_id" property="bindId" />
    <result column="goods_id" property="goodsId" />
    <result column="label_id1" property="labelId1" />
    <result column="label_id2" property="labelId2" />
    <result column="grade" property="grade" />
    <result column="label_path" property="labelPath" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="goodsId != null">
        `goods_id`,
      </if>
      <if test="labelId1 != null">
        `label_id1`,
      </if>
      <if test="labelId2 != null">
        `label_id2`,
      </if>
      <if test="grade != null">
        `grade`,
      </if>
      <if test="labelPath != null">
        `label_path`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `bind_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.bindIdNotEquals != null">
          AND `bind_id` != #{example.bindIdNotEquals}
        </if>
        <if test="example.bindIdIn != null">
          AND `bind_id` in (${example.bindIdIn})
        </if>
        <if test="example.goodsId != null">
          AND `goods_id` = #{example.goodsId}
        </if>
        <if test="example.labelId1 != null">
          AND `label_id1` = #{example.labelId1}
        </if>
        <if test="example.labelId2 != null">
          AND `label_id2` = #{example.labelId2}
        </if>
        <if test="example.grade != null">
          AND `grade` = #{example.grade}
        </if>
        <if test="example.labelPath != null">
          AND `label_path` = #{example.labelPath}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `bind_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.integral.example.IntegralGoodsBindLabelExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `integral_goods_bind_label`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `integral_goods_bind_label`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `integral_goods_bind_label`
    <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 `integral_goods_bind_label`
    <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 `integral_goods_bind_label`
    <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 `integral_goods_bind_label`
    <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 `integral_goods_bind_label`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `integral_goods_bind_label`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="bind_id" keyProperty="bindId" parameterType="com.slodon.b2b2c.integral.pojo.IntegralGoodsBindLabel" useGeneratedKeys="true">
    INSERT INTO `integral_goods_bind_label`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="goodsId != null">
        #{goodsId},
      </if>
      <if test="labelId1 != null">
        #{labelId1},
      </if>
      <if test="labelId2 != null">
        #{labelId2},
      </if>
      <if test="grade != null">
        #{grade},
      </if>
      <if test="labelPath != null">
        #{labelPath},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `integral_goods_bind_label`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.goodsId != null">
        `goods_id` = #{record.goodsId},
      </if>
      <if test="record.labelId1 != null">
        `label_id1` = #{record.labelId1},
      </if>
      <if test="record.labelId2 != null">
        `label_id2` = #{record.labelId2},
      </if>
      <if test="record.grade != null">
        `grade` = #{record.grade},
      </if>
      <if test="record.labelPath != null">
        `label_path` = #{record.labelPath},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `integral_goods_bind_label`
    <trim prefix="SET" suffixOverrides=",">
      <if test="goodsId != null">
        `goods_id` = #{goodsId},
      </if>
      <if test="labelId1 != null">
        `label_id1` = #{labelId1},
      </if>
      <if test="labelId2 != null">
        `label_id2` = #{labelId2},
      </if>
      <if test="grade != null">
        `grade` = #{grade},
      </if>
      <if test="labelPath != null">
        `label_path` = #{labelPath},
      </if>
    </trim>
    WHERE `bind_id` = #{bindId}
  </update>
</mapper>