<?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.promotion.DrawPrizeWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.promotion.pojo.DrawPrize">
    <id column="prize_id" property="prizeId" />
    <result column="draw_id" property="drawId" />
    <result column="prize_name" property="prizeName" />
    <result column="prize_image" property="prizeImage" />
    <result column="prize_type" property="prizeType" />
    <result column="integral_num" property="integralNum" />
    <result column="coupon_id" property="couponId" />
    <result column="coupon_name" property="couponName" />
    <result column="coupon_content" property="couponContent" />
    <result column="prize_num" property="prizeNum" />
    <result column="rate" property="rate" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="drawId != null">
        `draw_id`,
      </if>
      <if test="prizeName != null">
        `prize_name`,
      </if>
      <if test="prizeImage != null">
        `prize_image`,
      </if>
      <if test="prizeType != null">
        `prize_type`,
      </if>
      <if test="integralNum != null">
        `integral_num`,
      </if>
      <if test="couponId != null">
        `coupon_id`,
      </if>
      <if test="couponName != null">
        `coupon_name`,
      </if>
      <if test="couponContent != null">
        `coupon_content`,
      </if>
      <if test="prizeNum != null">
        `prize_num`,
      </if>
      <if test="rate != null">
        `rate`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `prize_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.prizeIdNotEquals != null">
          AND `prize_id` != #{example.prizeIdNotEquals}
        </if>
        <if test="example.prizeIdIn != null">
          AND `prize_id` in (${example.prizeIdIn})
        </if>
        <if test="example.drawId != null">
          AND `draw_id` = #{example.drawId}
        </if>
        <if test="example.prizeName != null">
          AND `prize_name` = #{example.prizeName}
        </if>
        <if test="example.prizeNameLike != null">
          AND `prize_name` like concat('%',#{example.prizeNameLike},'%')
        </if>
        <if test="example.prizeImage != null">
          AND `prize_image` = #{example.prizeImage}
        </if>
        <if test="example.prizeType != null">
          AND `prize_type` = #{example.prizeType}
        </if>
        <if test="example.integralNum != null">
          AND `integral_num` = #{example.integralNum}
        </if>
        <if test="example.couponId != null">
          AND `coupon_id` = #{example.couponId}
        </if>
        <if test="example.couponName != null">
          AND `coupon_name` = #{example.couponName}
        </if>
        <if test="example.couponNameLike != null">
          AND `coupon_name` like concat('%',#{example.couponNameLike},'%')
        </if>
        <if test="example.couponContent != null">
          AND `coupon_content` = #{example.couponContent}
        </if>
        <if test="example.couponContentLike != null">
          AND `coupon_content` like concat('%',#{example.couponContentLike},'%')
        </if>
        <if test="example.prizeNum != null">
          AND `prize_num` = #{example.prizeNum}
        </if>
        <if test="example.rate != null">
          AND `rate` = #{example.rate}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `prize_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.promotion.example.DrawPrizeExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `promotion_draw_prize`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_draw_prize`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_draw_prize`
    <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 `promotion_draw_prize`
    <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 `promotion_draw_prize`
    <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 `promotion_draw_prize`
    <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 `promotion_draw_prize`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `promotion_draw_prize`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="prize_id" keyProperty="prizeId" parameterType="com.slodon.b2b2c.promotion.pojo.DrawPrize" useGeneratedKeys="true">
    INSERT INTO `promotion_draw_prize`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="drawId != null">
        #{drawId},
      </if>
      <if test="prizeName != null">
        #{prizeName},
      </if>
      <if test="prizeImage != null">
        #{prizeImage},
      </if>
      <if test="prizeType != null">
        #{prizeType},
      </if>
      <if test="integralNum != null">
        #{integralNum},
      </if>
      <if test="couponId != null">
        #{couponId},
      </if>
      <if test="couponName != null">
        #{couponName},
      </if>
      <if test="couponContent != null">
        #{couponContent},
      </if>
      <if test="prizeNum != null">
        #{prizeNum},
      </if>
      <if test="rate != null">
        #{rate},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `promotion_draw_prize`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.drawId != null">
        `draw_id` = #{record.drawId},
      </if>
      <if test="record.prizeName != null">
        `prize_name` = #{record.prizeName},
      </if>
      <if test="record.prizeImage != null">
        `prize_image` = #{record.prizeImage},
      </if>
      <if test="record.prizeType != null">
        `prize_type` = #{record.prizeType},
      </if>
      <if test="record.integralNum != null">
        `integral_num` = #{record.integralNum},
      </if>
      <if test="record.couponId != null">
        `coupon_id` = #{record.couponId},
      </if>
      <if test="record.couponName != null">
        `coupon_name` = #{record.couponName},
      </if>
      <if test="record.couponContent != null">
        `coupon_content` = #{record.couponContent},
      </if>
      <if test="record.prizeNum != null">
        `prize_num` = #{record.prizeNum},
      </if>
      <if test="record.rate != null">
        `rate` = #{record.rate},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `promotion_draw_prize`
    <trim prefix="SET" suffixOverrides=",">
      <if test="drawId != null">
        `draw_id` = #{drawId},
      </if>
      <if test="prizeName != null">
        `prize_name` = #{prizeName},
      </if>
      <if test="prizeImage != null">
        `prize_image` = #{prizeImage},
      </if>
      <if test="prizeType != null">
        `prize_type` = #{prizeType},
      </if>
      <if test="integralNum != null">
        `integral_num` = #{integralNum},
      </if>
      <if test="couponId != null">
        `coupon_id` = #{couponId},
      </if>
      <if test="couponName != null">
        `coupon_name` = #{couponName},
      </if>
      <if test="couponContent != null">
        `coupon_content` = #{couponContent},
      </if>
      <if test="prizeNum != null">
        `prize_num` = #{prizeNum},
      </if>
      <if test="rate != null">
        `rate` = #{rate},
      </if>
    </trim>
    WHERE `prize_id` = #{prizeId}
  </update>
</mapper>