<?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.MemberInitMapper">
  <resultMap id="BaseResultMap" type="com.ssm.manage.entity.MemberInit">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="init_num" jdbcType="VARCHAR" property="initNum" />
    <result column="store_id" jdbcType="BIGINT" property="storeId" />
    <result column="store_name" jdbcType="VARCHAR" property="storeName" />
    <result column="member_id" jdbcType="BIGINT" property="memberId" />
    <result column="member_num" jdbcType="VARCHAR" property="memberNum" />
    <result column="member_name" jdbcType="VARCHAR" property="memberName" />
    <result column="sex" jdbcType="INTEGER" property="sex" />
    <result column="member_state" jdbcType="INTEGER" property="memberState" />
    <result column="mobile_phone" jdbcType="VARCHAR" property="mobilePhone" />
    <result column="trade_id" jdbcType="BIGINT" property="tradeId" />
    <result column="trade_name" jdbcType="VARCHAR" property="tradeName" />
    <result column="standard_money" jdbcType="DECIMAL" property="standardMoney" />
    <result column="standard_count" jdbcType="INTEGER" property="standardCount" />
    <result column="last_consume_time" jdbcType="TIMESTAMP" property="lastConsumeTime" />
    <result column="doc_num" jdbcType="VARCHAR" property="docNum" />
    <result column="doc_date" jdbcType="DATE" property="docDate" />
    <result column="card_type" jdbcType="INTEGER" property="cardType" />
    <result column="card_state" jdbcType="INTEGER" property="cardState" />
    <result column="rest_money" jdbcType="DECIMAL" property="restMoney" />
    <result column="rest_count" jdbcType="INTEGER" property="restCount" />
    <result column="card_gift_money" jdbcType="DECIMAL" property="cardGiftMoney" />
    <result column="discount" jdbcType="DECIMAL" property="discount" />
    <result column="card_consume_money" jdbcType="DECIMAL" property="cardConsumeMoney" />
    <result column="gift_consume_money" jdbcType="DECIMAL" property="giftConsumeMoney" />
    <result column="course_consume_count" jdbcType="INTEGER" property="courseConsumeCount" />
    <result column="debt_money" jdbcType="DECIMAL" property="debtMoney" />
    <result column="type_ratio" jdbcType="DECIMAL" property="typeRatio" />
    <result column="end_time" jdbcType="DATE" property="endTime" />
    <result column="account_id" jdbcType="BIGINT" property="accountId" />
    <result column="init_state" jdbcType="INTEGER" property="initState" />
    <result column="modify_id" jdbcType="BIGINT" property="modifyId" />
    <result column="modify_by" jdbcType="VARCHAR" property="modifyBy" />
    <result column="modify_date" jdbcType="TIMESTAMP" property="modifyDate" />

    <result column="old_project_num" jdbcType="VARCHAR" property="oldProjectNum" />
    <result column="old_project_name" jdbcType="VARCHAR" property="oldProjectName" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="course_rest_price" property="courseRestPrice" jdbcType="DECIMAL"/>
    <result property="courseConsumePrice" column="course_consum_price" jdbcType="DECIMAL"/>
    <result property="giveType" column="give_type" jdbcType="INTEGER"/>
  </resultMap>

  <sql id="baseColumnList">
    id,
    init_num,
    store_id,
    store_name,
    member_id,
    member_num,
    member_name,
    sex,
    member_state,
    mobile_phone,
    trade_id,
    trade_name,
    standard_money,
    standard_count,
    last_consume_time,
    doc_num,
    doc_date,
    card_type,
    card_state,
    rest_money,
    rest_count,
    card_gift_money,
    discount,
    card_consume_money,
    gift_consume_money,
    course_consume_count,
    debt_money,
    type_ratio,
    end_time,
    account_id,
    init_state,
    modify_id,
    modify_by,
    modify_date,
        give_type
  </sql>

  <insert id="insertBatch" parameterType="java.util.ArrayList">
    insert into member_init (<include refid="baseColumnList" />) values
    <foreach collection="list" index="index" item="item" separator=",">
      (
      #{item.id},
      #{item.initNum},
      #{item.storeId},
      #{item.storeName},
      #{item.memberId},
      #{item.memberNum},
      #{item.memberName},
      #{item.sex},
      #{item.memberState},
      #{item.mobilePhone},
      #{item.tradeId},
      #{item.tradeName},
      #{item.standardMoney},
      #{item.standardCount},
      #{item.lastConsumeTime},
      #{item.docNum},
      #{item.docDate},
      #{item.cardType},
      #{item.cardState},
      #{item.restMoney},
      #{item.restCount},
      #{item.cardGiftMoney},
      #{item.discount},
      #{item.cardConsumeMoney},
      #{item.giftConsumeMoney},
      #{item.courseConsumeCount},
      #{item.debtMoney},
      #{item.typeRatio},
      #{item.endTime},
      #{item.accountId},
      #{item.initState},
      #{item.modifyId},
      #{item.modifyBy},
      #{item.modifyDate},
       #{item.giveType}
      )
    </foreach>
  </insert>

  <update id="updateBatch" parameterType="java.util.ArrayList">
    <foreach close="" collection="list" index="index" item="item" open="" separator=";">
      update member_init
      <trim prefix="set" suffixOverrides=",">
        <if test="item.memberName != null">
          member_name = #{item.memberName},
        </if>
        <if test="item.memberNum != null">
          member_num = #{item.memberNum},
        </if>
        <if test="item.mobilePhone != null">
          mobile_phone = #{item.mobilePhone},
        </if>
        <if test="item.memberState != null">
          member_state = #{item.memberState},
        </if>
        <if test="item.sex != null">
          sex = #{item.sex},
        </if>

        <if test="item.tradeId != null">
          trade_id = #{item.tradeId},
        </if>
        <if test="item.tradeName != null">
          trade_name = #{item.tradeName},
        </if>
        <if test="item.standardMoney != null">
          standard_money = #{item.standardMoney},
        </if>
        <if test="item.standardCount != null">
          standard_count = #{item.standardCount},
        </if>
        <if test="item.lastConsumeTime != null">
          last_consume_time = #{item.lastConsumeTime},
        </if>

        <if test="item.docNum != null">
          doc_num = #{item.docNum},
        </if>
        <if test="item.docDate != null">
          doc_date = #{item.docDate},
        </if>
        <if test="item.cardType != null">
          card_type = #{item.cardType},
        </if>
        <if test="item.cardState != null">
          card_state = #{item.cardState},
        </if>
        <if test="item.restMoney != null">
          rest_money = #{item.restMoney},
        </if>
        <if test="item.restCount != null">
          rest_count = #{item.restCount},
        </if>
        <if test="item.cardGiftMoney != null">
          card_gift_money = #{item.cardGiftMoney},
        </if>
        <if test="item.discount != null">
          discount = #{item.discount},
        </if>
        <if test="item.cardConsumeMoney != null">
          card_consume_money = #{item.cardConsumeMoney},
        </if>
        <if test="item.giftConsumeMoney != null">
          gift_consume_money = #{item.giftConsumeMoney},
        </if>
        <if test="item.courseConsumeCount != null">
          course_consume_count = #{item.courseConsumeCount},
        </if>
        <if test="item.debtMoney != null">
          debt_money = #{item.debtMoney},
        </if>
        <if test="item.typeRatio != null">
          type_ratio = #{item.typeRatio},
        </if>
        <if test="item.endTime != null">
          end_time = #{item.endTime},
        </if>
        <if test="item.accountId != null">
          account_id = #{item.accountId},
        </if>
        <if test="item.initState != null">
          init_state = #{item.initState},
        </if>
        <if test="item.modifyId != null">
          modify_id = #{item.modifyId},
        </if>
        <if test="item.modifyBy != null">
          modify_by = #{item.modifyBy},
        </if>
        <if test="item.modifyDate != null">
          modify_date = #{item.modifyDate},
        </if>

      </trim>
      where id = #{item.id}
    </foreach>
  </update>


  <select id="selectFKJ" resultMap="BaseResultMap" parameterType="com.ssm.manage.entity.MemberInit">
    select * from member_init
    <where>
      store_id = #{storeId, jdbcType = BIGINT} and init_state=4
      and DATE_FORMAT(doc_date, '%Y-%m-%d' ) = DATE_FORMAT(#{docDate} , '%Y-%m-%d' );
    </where>
  </select>
    <select id="selectFKJByDate" resultMap="BaseResultMap" parameterType="com.ssm.manage.entity.MemberInit">
      select * from member_init
      <where>
        store_id = #{storeId, jdbcType = BIGINT} and init_state=4
        and modify_date between #{startTime} and #{endTime}
      </where>
    </select>
</mapper>