<?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.IntegralBillWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.integral.pojo.IntegralBill">
    <id column="bill_id" property="billId" />
    <result column="bill_sn" property="billSn" />
    <result column="store_id" property="storeId" />
    <result column="store_name" property="storeName" />
    <result column="start_time" property="startTime" />
    <result column="end_time" property="endTime" />
    <result column="cash_amount" property="cashAmount" />
    <result column="integral" property="integral" />
    <result column="integral_cash_amount" property="integralCashAmount" />
    <result column="settle_amount" property="settleAmount" />
    <result column="state" property="state" />
    <result column="payment_remark" property="paymentRemark" />
    <result column="payment_evidence" property="paymentEvidence" />
    <result column="create_time" property="createTime" />
    <result column="update_time" property="updateTime" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="billSn != null">
        `bill_sn`,
      </if>
      <if test="storeId != null">
        `store_id`,
      </if>
      <if test="storeName != null">
        `store_name`,
      </if>
      <if test="startTime != null">
        `start_time`,
      </if>
      <if test="endTime != null">
        `end_time`,
      </if>
      <if test="cashAmount != null">
        `cash_amount`,
      </if>
      <if test="integral != null">
        `integral`,
      </if>
      <if test="integralCashAmount != null">
        `integral_cash_amount`,
      </if>
      <if test="settleAmount != null">
        `settle_amount`,
      </if>
      <if test="state != null">
        `state`,
      </if>
      <if test="paymentRemark != null">
        `payment_remark`,
      </if>
      <if test="paymentEvidence != null">
        `payment_evidence`,
      </if>
      <if test="createTime != null">
        `create_time`,
      </if>
      <if test="updateTime != null">
        `update_time`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `bill_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.billIdNotEquals != null">
          AND `bill_id` != #{example.billIdNotEquals}
        </if>
        <if test="example.billIdIn != null">
          AND `bill_id` in (${example.billIdIn})
        </if>
        <if test="example.billSn != null">
          AND `bill_sn` = #{example.billSn}
        </if>
        <if test="example.billSnLike != null">
          AND `bill_sn` like concat('%',#{example.billSnLike},'%')
        </if>
        <if test="example.storeId != null">
          AND `store_id` = #{example.storeId}
        </if>
        <if test="example.storeName != null">
          AND `store_name` = #{example.storeName}
        </if>
        <if test="example.storeNameLike != null">
          AND `store_name` like concat('%',#{example.storeNameLike},'%')
        </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.cashAmount != null">
          AND `cash_amount` = #{example.cashAmount}
        </if>
        <if test="example.integral != null">
          AND `integral` = #{example.integral}
        </if>
        <if test="example.integralCashAmount != null">
          AND `integral_cash_amount` = #{example.integralCashAmount}
        </if>
        <if test="example.settleAmount != null">
          AND `settle_amount` = #{example.settleAmount}
        </if>
        <if test="example.state != null">
          AND `state` = #{example.state}
        </if>
        <if test="example.stateIn != null">
          AND `state` in (${example.stateIn})
        </if>
        <if test="example.stateNotIn != null">
          AND `state` not in (${example.stateNotIn})
        </if>
        <if test="example.stateNotEquals != null">
          AND `state` != #{example.stateNotEquals}
        </if>
        <if test="example.paymentRemark != null">
          AND `payment_remark` = #{example.paymentRemark}
        </if>
        <if test="example.paymentEvidence != null">
          AND `payment_evidence` = #{example.paymentEvidence}
        </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>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `bill_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.IntegralBillExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `integral_bill`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `integral_bill`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `integral_bill`
    <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_bill`
    <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_bill`
    <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_bill`
    <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_bill`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `integral_bill`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="bill_id" keyProperty="billId" parameterType="com.slodon.b2b2c.integral.pojo.IntegralBill" useGeneratedKeys="true">
    INSERT INTO `integral_bill`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="billSn != null">
        #{billSn},
      </if>
      <if test="storeId != null">
        #{storeId},
      </if>
      <if test="storeName != null">
        #{storeName},
      </if>
      <if test="startTime != null">
        #{startTime},
      </if>
      <if test="endTime != null">
        #{endTime},
      </if>
      <if test="cashAmount != null">
        #{cashAmount},
      </if>
      <if test="integral != null">
        #{integral},
      </if>
      <if test="integralCashAmount != null">
        #{integralCashAmount},
      </if>
      <if test="settleAmount != null">
        #{settleAmount},
      </if>
      <if test="state != null">
        #{state},
      </if>
      <if test="paymentRemark != null">
        #{paymentRemark},
      </if>
      <if test="paymentEvidence != null">
        #{paymentEvidence},
      </if>
      <if test="createTime != null">
        #{createTime},
      </if>
      <if test="updateTime != null">
        #{updateTime},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `integral_bill`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.billSn != null">
        `bill_sn` = #{record.billSn},
      </if>
      <if test="record.storeId != null">
        `store_id` = #{record.storeId},
      </if>
      <if test="record.storeName != null">
        `store_name` = #{record.storeName},
      </if>
      <if test="record.startTime != null">
        `start_time` = #{record.startTime},
      </if>
      <if test="record.endTime != null">
        `end_time` = #{record.endTime},
      </if>
      <if test="record.cashAmount != null">
        `cash_amount` = #{record.cashAmount},
      </if>
      <if test="record.integral != null">
        `integral` = #{record.integral},
      </if>
      <if test="record.integralCashAmount != null">
        `integral_cash_amount` = #{record.integralCashAmount},
      </if>
      <if test="record.settleAmount != null">
        `settle_amount` = #{record.settleAmount},
      </if>
      <if test="record.state != null">
        `state` = #{record.state},
      </if>
      <if test="record.paymentRemark != null">
        `payment_remark` = #{record.paymentRemark},
      </if>
      <if test="record.paymentEvidence != null">
        `payment_evidence` = #{record.paymentEvidence},
      </if>
      <if test="record.createTime != null">
        `create_time` = #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        `update_time` = #{record.updateTime},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `integral_bill`
    <trim prefix="SET" suffixOverrides=",">
      <if test="billSn != null">
        `bill_sn` = #{billSn},
      </if>
      <if test="storeId != null">
        `store_id` = #{storeId},
      </if>
      <if test="storeName != null">
        `store_name` = #{storeName},
      </if>
      <if test="startTime != null">
        `start_time` = #{startTime},
      </if>
      <if test="endTime != null">
        `end_time` = #{endTime},
      </if>
      <if test="cashAmount != null">
        `cash_amount` = #{cashAmount},
      </if>
      <if test="integral != null">
        `integral` = #{integral},
      </if>
      <if test="integralCashAmount != null">
        `integral_cash_amount` = #{integralCashAmount},
      </if>
      <if test="settleAmount != null">
        `settle_amount` = #{settleAmount},
      </if>
      <if test="state != null">
        `state` = #{state},
      </if>
      <if test="paymentRemark != null">
        `payment_remark` = #{paymentRemark},
      </if>
      <if test="paymentEvidence != null">
        `payment_evidence` = #{paymentEvidence},
      </if>
      <if test="createTime != null">
        `create_time` = #{createTime},
      </if>
      <if test="updateTime != null">
        `update_time` = #{updateTime},
      </if>
    </trim>
    WHERE `bill_id` = #{billId}
  </update>
</mapper>