<?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.DrawWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.promotion.pojo.Draw">
    <id column="draw_id" property="drawId" />
    <result column="draw_name" property="drawName" />
    <result column="start_time" property="startTime" />
    <result column="end_time" property="endTime" />
    <result column="integral_use" property="integralUse" />
    <result column="rule_type" property="ruleType" />
    <result column="rule_num" property="ruleNum" />
    <result column="background_image" property="backgroundImage" />
    <result column="available_button_image" property="availableButtonImage" />
    <result column="chance_out_button_image" property="chanceOutButtonImage" />
    <result column="open_virtual" property="openVirtual" />
    <result column="draw_description" property="drawDescription" />
    <result column="lose_prize_description" property="losePrizeDescription" />
    <result column="lose_prize_image" property="losePrizeImage" />
    <result column="create_admin_id" property="createAdminId" />
    <result column="create_time" property="createTime" />
    <result column="update_time" property="updateTime" />
    <result column="draw_type" property="drawType" />
    <result column="total_rate" property="totalRate" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="drawId != null">
        `draw_id`,
      </if>
      <if test="drawName != null">
        `draw_name`,
      </if>
      <if test="startTime != null">
        `start_time`,
      </if>
      <if test="endTime != null">
        `end_time`,
      </if>
      <if test="integralUse != null">
        `integral_use`,
      </if>
      <if test="ruleType != null">
        `rule_type`,
      </if>
      <if test="ruleNum != null">
        `rule_num`,
      </if>
      <if test="backgroundImage != null">
        `background_image`,
      </if>
      <if test="availableButtonImage != null">
        `available_button_image`,
      </if>
      <if test="chanceOutButtonImage != null">
        `chance_out_button_image`,
      </if>
      <if test="openVirtual != null">
        `open_virtual`,
      </if>
      <if test="drawDescription != null">
        `draw_description`,
      </if>
      <if test="losePrizeDescription != null">
        `lose_prize_description`,
      </if>
      <if test="losePrizeImage != null">
        `lose_prize_image`,
      </if>
      <if test="createAdminId != null">
        `create_admin_id`,
      </if>
      <if test="createTime != null">
        `create_time`,
      </if>
      <if test="updateTime != null">
        `update_time`,
      </if>
      <if test="drawType != null">
        `draw_type`,
      </if>
      <if test="totalRate != null">
        `total_rate`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `draw_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.drawIdNotEquals != null">
          AND `draw_id` != #{example.drawIdNotEquals}
        </if>
        <if test="example.drawIdIn != null">
          AND `draw_id` in (${example.drawIdIn})
        </if>
        <if test="example.drawId != null">
        AND `draw_id` = #{example.drawId}
        </if>
        <if test="example.drawName != null">
          AND `draw_name` = #{example.drawName}
        </if>
        <if test="example.drawNameLike != null">
          AND `draw_name` like concat('%',#{example.drawNameLike},'%')
        </if>
        <if test="example.startTimeAfter != null">
          AND `start_time` <![CDATA[ >= ]]> #{example.startTimeAfter}
        </if>
        <if test="example.startTimeBefore != null">
          AND `start_time` <![CDATA[ <= ]]> #{example.startTimeBefore}
        </if>
        <if test="example.endTimeAfter != null">
          AND `end_time` <![CDATA[ >= ]]> #{example.endTimeAfter}
        </if>
        <if test="example.endTimeBefore != null">
          AND `end_time` <![CDATA[ <= ]]> #{example.endTimeBefore}
        </if>
        <if test="example.integralUse != null">
          AND `integral_use` = #{example.integralUse}
        </if>
        <if test="example.ruleType != null">
          AND `rule_type` = #{example.ruleType}
        </if>
        <if test="example.ruleNum != null">
          AND `rule_num` = #{example.ruleNum}
        </if>
        <if test="example.backgroundImage != null">
          AND `background_image` = #{example.backgroundImage}
        </if>
        <if test="example.availableButtonImage != null">
          AND `available_button_image` = #{example.availableButtonImage}
        </if>
        <if test="example.chanceOutButtonImage != null">
          AND `chance_out_button_image` = #{example.chanceOutButtonImage}
        </if>
        <if test="example.openVirtual != null">
          AND `open_virtual` = #{example.openVirtual}
        </if>
        <if test="example.drawDescription != null">
          AND `draw_description` = #{example.drawDescription}
        </if>
        <if test="example.losePrizeDescription != null">
          AND `lose_prize_description` = #{example.losePrizeDescription}
        </if>
        <if test="example.losePrizeImage != null">
          AND `lose_prize_image` = #{example.losePrizeImage}
        </if>
        <if test="example.createAdminId != null">
          AND `create_admin_id` = #{example.createAdminId}
        </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.updateTimeAfter != null">
          AND `update_time` <![CDATA[ >= ]]> #{example.updateTimeAfter}
        </if>
        <if test="example.updateTimeBefore != null">
          AND `update_time` <![CDATA[ <= ]]> #{example.updateTimeBefore}
        </if>
        <if test="example.drawType != null">
          AND `draw_type` = #{example.drawType}
        </if>
        <if test="example.totalRate != null">
          AND `total_rate` = #{example.totalRate}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `draw_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.DrawExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `promotion_draw`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_draw`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_draw`
    <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`
    <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`
    <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`
    <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`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `promotion_draw`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="draw_id" keyProperty="drawId" parameterType="com.slodon.b2b2c.promotion.pojo.Draw" useGeneratedKeys="true">
    INSERT INTO `promotion_draw`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="drawId != null">
        #{drawId},
      </if>
      <if test="drawName != null">
        #{drawName},
      </if>
      <if test="startTime != null">
        #{startTime},
      </if>
      <if test="endTime != null">
        #{endTime},
      </if>
      <if test="integralUse != null">
        #{integralUse},
      </if>
      <if test="ruleType != null">
        #{ruleType},
      </if>
      <if test="ruleNum != null">
        #{ruleNum},
      </if>
      <if test="backgroundImage != null">
        #{backgroundImage},
      </if>
      <if test="availableButtonImage != null">
        #{availableButtonImage},
      </if>
      <if test="chanceOutButtonImage != null">
        #{chanceOutButtonImage},
      </if>
      <if test="openVirtual != null">
        #{openVirtual},
      </if>
      <if test="drawDescription != null">
        #{drawDescription},
      </if>
      <if test="losePrizeDescription != null">
        #{losePrizeDescription},
      </if>
      <if test="losePrizeImage != null">
        #{losePrizeImage},
      </if>
      <if test="createAdminId != null">
        #{createAdminId},
      </if>
      <if test="createTime != null">
        #{createTime},
      </if>
      <if test="updateTime != null">
        #{updateTime},
      </if>
      <if test="drawType != null">
        #{drawType},
      </if>
      <if test="totalRate != null">
        #{totalRate},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `promotion_draw`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.drawName != null">
        `draw_name` = #{record.drawName},
      </if>
      <if test="record.startTime != null">
        `start_time` = #{record.startTime},
      </if>
      <if test="record.endTime != null">
        `end_time` = #{record.endTime},
      </if>
      <if test="record.integralUse != null">
        `integral_use` = #{record.integralUse},
      </if>
      <if test="record.ruleType != null">
        `rule_type` = #{record.ruleType},
      </if>
      <if test="record.ruleNum != null">
        `rule_num` = #{record.ruleNum},
      </if>
      <if test="record.backgroundImage != null">
        `background_image` = #{record.backgroundImage},
      </if>
      <if test="record.availableButtonImage != null">
        `available_button_image` = #{record.availableButtonImage},
      </if>
      <if test="record.chanceOutButtonImage != null">
        `chance_out_button_image` = #{record.chanceOutButtonImage},
      </if>
      <if test="record.openVirtual != null">
        `open_virtual` = #{record.openVirtual},
      </if>
      <if test="record.drawDescription != null">
        `draw_description` = #{record.drawDescription},
      </if>
      <if test="record.losePrizeDescription != null">
        `lose_prize_description` = #{record.losePrizeDescription},
      </if>
      <if test="record.losePrizeImage != null">
        `lose_prize_image` = #{record.losePrizeImage},
      </if>
      <if test="record.createAdminId != null">
        `create_admin_id` = #{record.createAdminId},
      </if>
      <if test="record.createTime != null">
        `create_time` = #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        `update_time` = #{record.updateTime},
      </if>
      <if test="record.drawType != null">
        `draw_type` = #{record.drawType},
      </if>
      <if test="record.totalRate != null">
        `total_rate` = #{record.totalRate},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `promotion_draw`
    <trim prefix="SET" suffixOverrides=",">
      <if test="drawName != null">
        `draw_name` = #{drawName},
      </if>
      <if test="startTime != null">
        `start_time` = #{startTime},
      </if>
      <if test="endTime != null">
        `end_time` = #{endTime},
      </if>
      <if test="integralUse != null">
        `integral_use` = #{integralUse},
      </if>
      <if test="ruleType != null">
        `rule_type` = #{ruleType},
      </if>
      <if test="ruleNum != null">
        `rule_num` = #{ruleNum},
      </if>
      <if test="backgroundImage != null">
        `background_image` = #{backgroundImage},
      </if>
      <if test="availableButtonImage != null">
        `available_button_image` = #{availableButtonImage},
      </if>
      <if test="chanceOutButtonImage != null">
        `chance_out_button_image` = #{chanceOutButtonImage},
      </if>
      <if test="openVirtual != null">
        `open_virtual` = #{openVirtual},
      </if>
      <if test="drawDescription != null">
        `draw_description` = #{drawDescription},
      </if>
      <if test="losePrizeDescription != null">
        `lose_prize_description` = #{losePrizeDescription},
      </if>
      <if test="losePrizeImage != null">
        `lose_prize_image` = #{losePrizeImage},
      </if>
      <if test="createAdminId != null">
        `create_admin_id` = #{createAdminId},
      </if>
      <if test="createTime != null">
        `create_time` = #{createTime},
      </if>
      <if test="updateTime != null">
        `update_time` = #{updateTime},
      </if>
      <if test="drawType != null">
        `draw_type` = #{drawType},
      </if>
      <if test="totalRate != null">
        `total_rate` = #{totalRate},
      </if>
    </trim>
    WHERE `draw_id` = #{drawId}
  </update>
</mapper>