<?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.ssm.manage.mapper.RechargeTypeMapper">
  <resultMap id="BaseResultMap" type="com.ssm.manage.entity.RechargeType">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="recharge_type_num" jdbcType="VARCHAR" property="rechargeTypeNum" />
    <result column="recharge_type_name" jdbcType="VARCHAR" property="rechargeTypeName" />
    <result column="store_id" jdbcType="BIGINT" property="storeId" />
    <result column="store_name" jdbcType="VARCHAR" property="storeName" />
    <result column="discount" jdbcType="DECIMAL" property="discount" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="type_ratio" jdbcType="DECIMAL" property="typeRatio" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="recharge_money" jdbcType="DECIMAL" property="rechargeMoney" />
    <result column="gift_money" jdbcType="DECIMAL" property="giftMoney" />
    <result column="founder_staff" jdbcType="VARCHAR" property="founderStaff" />
    <result column="Founder_datetime" jdbcType="TIMESTAMP" property="founderDatetime" />
    <result column="modify_by" jdbcType="VARCHAR" property="modifyBy" />
    <result column="modify_datetime" jdbcType="TIMESTAMP" property="modifyDatetime" />
    <result column="valid_time" jdbcType="INTEGER" property="validTime" />
    <result column="discount_free_amount" jdbcType="DECIMAL" property="discountFreeAmount" />
    <result column="start_dates" jdbcType="TIMESTAMP" property="startDates" />
    <result column="stop_dates" jdbcType="TIMESTAMP" property="stopDates" />
    <result column="card_type" jdbcType="INTEGER" property="cardType" />
    <result column="lift_card_id" jdbcType="BIGINT" property="liftCardId" />
    <result column="raw_card_id" jdbcType="BIGINT" property="rawCardId" />
    <result column="lift_type" jdbcType="INTEGER" property="liftType" />
    <result column="first_amount" jdbcType="INTEGER" property="firstAmount" />
    <result column="unified_due" jdbcType="TIMESTAMP" property="unifiedDue" />
    <result column="donate_type" jdbcType="INTEGER" property="donateType" />
    <result column="give_type" jdbcType="INTEGER" property="giveType" />
    <result column="store_type" jdbcType="INTEGER" property="storeType" />
  </resultMap>

  <sql id="baseColumnList">
    id,
    recharge_type_num,
    recharge_type_name,
    store_id,
    store_name,
    discount,
    state,
    type_ratio,
    type,
    recharge_money,
    gift_money,
    founder_staff,
    founder_datetime,
    modify_by,
    modify_datetime,
    valid_time,
    discount_free_amount,
    start_dates,
    stop_dates,
    first_amount,
    card_type,
    lift_card_id,
    raw_card_id,
    lift_type,
    unified_due,
    donate_type
  </sql>

  <insert id="insertBatch" parameterType="java.util.ArrayList">
    insert into recharge_type (<include refid="baseColumnList"/>) values
    <foreach collection="list" index="index" separator="," item="item">
      (
      #{item.id},
      #{item.rechargeTypeNum},
      #{item.rechargeTypeName},
      #{item.storeId},
      #{item.storeName},
      #{item.discount},
      #{item.state},
      #{item.typeRatio},
      #{item.type},
      #{item.rechargeMoney},
      #{item.giftMoney},
      #{item.founderStaff},
      #{item.founderDatetime},
      #{item.modifyBy},
      #{item.modifyDatetime},
      #{item.validTime},
      #{item.discountFreeAmount},
      #{item.startDates},
      #{item.stopDates},
      #{item.firstAmount},
      0,
      #{item.liftCardId},
      #{item.rawCardId},
      #{item.liftType},
      #{item.unifiedDue},
      #{item.donateType}
      )
    </foreach>
  </insert>

  <select id="selectRechange" resultMap="BaseResultMap" parameterType="com.ssm.manage.query.RechargeTypeRequest">
    select * from recharge_type
    <where>
      card_type=0
      <if test="rechargeTypeName != null">
        and recharge_type_name like "%" +#{rechargeTypeName}+ "%"
      </if>
      <if test="state != null">
        and state = #{state, jdbcType = INTEGER}
      </if>
      <if test="type != null">
        and type = #{type, jdbcType = INTEGER}
      </if>
      <if test="storeId != null">
        and store_id = #{storeId, jdbcType = INTEGER}
      </if>
      <if test="startDates != null">
        and DATE_FORMAT(STR_TO_DATE(stop_dates,'%Y-%m-%d'),'%Y-%m-%d') >= #{startDates} and DATE_FORMAT(STR_TO_DATE(start_dates,'%Y-%m-%d'),'%Y-%m-%d') &lt;= #{startDates}
      </if>
    </where>
    order by discount desc
  </select>
</mapper>