<?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.SignRecordWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.promotion.pojo.SignRecord">
    <id column="record_id" property="recordId" />
    <result column="member_id" property="memberId" />
    <result column="activity_id" property="activityId" />
    <result column="mask" property="mask" />
    <result column="continue_num" property="continueNum" />
    <result column="last_time" property="lastTime" />
    <result column="is_bonus" property="isBonus" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="memberId != null">
        `member_id`,
      </if>
      <if test="activityId != null">
        `activity_id`,
      </if>
      <if test="mask != null">
        `mask`,
      </if>
      <if test="continueNum != null">
        `continue_num`,
      </if>
      <if test="lastTime != null">
        `last_time`,
      </if>
      <if test="isBonus != null">
        `is_bonus`,
      </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.memberId != null">
          AND `member_id` = #{example.memberId}
        </if>
        <if test="example.activityId != null">
          AND `activity_id` = #{example.activityId}
        </if>
        <if test="example.mask != null">
          AND `mask` = #{example.mask}
        </if>
        <if test="example.continueNum != null">
          AND `continue_num` = #{example.continueNum}
        </if>
        <if test="example.lastTimeAfter != null">
          AND `last_time` <![CDATA[ >= ]]> #{example.lastTimeAfter}
        </if>
        <if test="example.lastTimeBefore != null">
          AND `last_time` <![CDATA[ <= ]]> #{example.lastTimeBefore}
        </if>
        <if test="example.isBonus != null">
          AND `is_bonus` = #{example.isBonus}
        </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.SignRecordExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `promotion_sign_record`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_sign_record`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_sign_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_sign_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_sign_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_sign_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_sign_record`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `promotion_sign_record`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="record_id" keyProperty="recordId" parameterType="com.slodon.b2b2c.promotion.pojo.SignRecord" useGeneratedKeys="true">
    INSERT INTO `promotion_sign_record`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="memberId != null">
        #{memberId},
      </if>
      <if test="activityId != null">
        #{activityId},
      </if>
      <if test="mask != null">
        #{mask},
      </if>
      <if test="continueNum != null">
        #{continueNum},
      </if>
      <if test="lastTime != null">
        #{lastTime},
      </if>
      <if test="isBonus != null">
        #{isBonus},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `promotion_sign_record`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.memberId != null">
        `member_id` = #{record.memberId},
      </if>
      <if test="record.activityId != null">
        `activity_id` = #{record.activityId},
      </if>
      <if test="record.mask != null">
        `mask` = #{record.mask},
      </if>
      <if test="record.continueNum != null">
        `continue_num` = #{record.continueNum},
      </if>
      <if test="record.lastTime != null">
        `last_time` = #{record.lastTime},
      </if>
      <if test="record.isBonus != null">
        `is_bonus` = #{record.isBonus},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `promotion_sign_record`
    <trim prefix="SET" suffixOverrides=",">
      <if test="memberId != null">
        `member_id` = #{memberId},
      </if>
      <if test="activityId != null">
        `activity_id` = #{activityId},
      </if>
      <if test="mask != null">
        `mask` = #{mask},
      </if>
      <if test="continueNum != null">
        `continue_num` = #{continueNum},
      </if>
      <if test="lastTime != null">
        `last_time` = #{lastTime},
      </if>
      <if test="isBonus != null">
        `is_bonus` = #{isBonus},
      </if>
    </trim>
    WHERE `record_id` = #{recordId}
  </update>
</mapper>