<?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.DrawRecordWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.promotion.pojo.DrawRecord">
    <id column="record_id" property="recordId" />
    <result column="draw_id" property="drawId" />
    <result column="prize_id" property="prizeId" />
    <result column="prize_name" property="prizeName" />
    <result column="member_id" property="memberId" />
    <result column="member_name" property="memberName" />
    <result column="is_prize" property="isPrize" />
    <result column="record_time" property="recordTime" />
    <result column="use_integral" property="useIntegral" />
    <result column="prize_type" property="prizeType" />
    <result column="description" property="description" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="recordId != null">
        `record_id`,
      </if>
      <if test="drawId != null">
        `draw_id`,
      </if>
      <if test="prizeId != null">
        `prize_id`,
      </if>
      <if test="prizeName != null">
        `prize_name`,
      </if>
      <if test="memberId != null">
        `member_id`,
      </if>
      <if test="memberName != null">
        `member_name`,
      </if>
      <if test="isPrize != null">
        `is_prize`,
      </if>
      <if test="recordTime != null">
        `record_time`,
      </if>
      <if test="useIntegral != null">
        `use_integral`,
      </if>
      <if test="prizeType != null">
        `prize_type`,
      </if>
      <if test="description != null">
        `description`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `record_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.recordIdNotEquals != null">
          AND `record_id` != #{example.recordIdNotEquals}
        </if>
        <if test="example.recordIdIn != null">
          AND `record_id` in (${example.recordIdIn})
        </if>
        <if test="example.drawId != null">
          AND `draw_id` = #{example.drawId}
        </if>
        <if test="example.prizeId != null">
          AND `prize_id` = #{example.prizeId}
        </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.memberId != null">
          AND `member_id` = #{example.memberId}
        </if>
        <if test="example.memberName != null">
          AND `member_name` = #{example.memberName}
        </if>
        <if test="example.memberNameLike != null">
          AND `member_name` like concat('%',#{example.memberNameLike},'%')
        </if>
        <if test="example.isPrize != null">
          AND `is_prize` = #{example.isPrize}
        </if>
        <if test="example.recordTimeAfter != null">
          AND `record_time` <![CDATA[ >= ]]> #{example.recordTimeAfter}
        </if>
        <if test="example.recordTimeBefore != null">
          AND `record_time` <![CDATA[ <= ]]> #{example.recordTimeBefore}
        </if>
        <if test="example.useIntegral != null">
          AND `use_integral` = #{example.useIntegral}
        </if>
        <if test="example.prizeType != null">
          AND `prize_type` = #{example.prizeType}
        </if>
        <if test="example.description != null">
          AND `description` = #{example.description}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `record_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.DrawRecordExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `promotion_draw_record`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_draw_record`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_draw_record`
    <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_record`
    <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_record`
    <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_record`
    <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_record`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `promotion_draw_record`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="record_id" keyProperty="recordId" parameterType="com.slodon.b2b2c.promotion.pojo.DrawRecord" useGeneratedKeys="true">
    INSERT INTO `promotion_draw_record`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="recordId != null">
        #{recordId},
      </if>
      <if test="drawId != null">
        #{drawId},
      </if>
      <if test="prizeId != null">
        #{prizeId},
      </if>
      <if test="prizeName != null">
        #{prizeName},
      </if>
      <if test="memberId != null">
        #{memberId},
      </if>
      <if test="memberName != null">
        #{memberName},
      </if>
      <if test="isPrize != null">
        #{isPrize},
      </if>
      <if test="recordTime != null">
        #{recordTime},
      </if>
      <if test="useIntegral != null">
        #{useIntegral},
      </if>
      <if test="prizeType != null">
        #{prizeType},
      </if>
      <if test="description != null">
        #{description},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `promotion_draw_record`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.drawId != null">
        `draw_id` = #{record.drawId},
      </if>
      <if test="record.prizeId != null">
        `prize_id` = #{record.prizeId},
      </if>
      <if test="record.prizeName != null">
        `prize_name` = #{record.prizeName},
      </if>
      <if test="record.memberId != null">
        `member_id` = #{record.memberId},
      </if>
      <if test="record.memberName != null">
        `member_name` = #{record.memberName},
      </if>
      <if test="record.isPrize != null">
        `is_prize` = #{record.isPrize},
      </if>
      <if test="record.recordTime != null">
        `record_time` = #{record.recordTime},
      </if>
      <if test="record.useIntegral != null">
        `use_integral` = #{record.useIntegral},
      </if>
      <if test="record.prizeType != null">
        `prize_type` = #{record.prizeType},
      </if>
      <if test="record.description != null">
        `description` = #{record.description},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `promotion_draw_record`
    <trim prefix="SET" suffixOverrides=",">
      <if test="drawId != null">
        `draw_id` = #{drawId},
      </if>
      <if test="prizeId != null">
        `prize_id` = #{prizeId},
      </if>
      <if test="prizeName != null">
        `prize_name` = #{prizeName},
      </if>
      <if test="memberId != null">
        `member_id` = #{memberId},
      </if>
      <if test="memberName != null">
        `member_name` = #{memberName},
      </if>
      <if test="isPrize != null">
        `is_prize` = #{isPrize},
      </if>
      <if test="recordTime != null">
        `record_time` = #{recordTime},
      </if>
      <if test="useIntegral != null">
        `use_integral` = #{useIntegral},
      </if>
      <if test="prizeType != null">
        `prize_type` = #{prizeType},
      </if>
      <if test="description != null">
        `description` = #{description},
      </if>
    </trim>
    WHERE `record_id` = #{recordId}
  </update>
</mapper>