<?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.CardChangeListMapper">
  <resultMap id="BaseResultMap" type="com.ssm.manage.entity.CardChangeList">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="doc_num" jdbcType="VARCHAR" property="docNum" />
    <result column="doc_date" jdbcType="TIMESTAMP" property="docDate" />
    <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_name" jdbcType="VARCHAR" property="memberName" />
    <result column="member_identity_card" jdbcType="VARCHAR" property="memberIdentityCard" />
    <result column="mobile_phone" jdbcType="VARCHAR" property="mobilePhone" />
    <result column="input_id" jdbcType="BIGINT" property="inputId" />
    <result column="input_by" jdbcType="VARCHAR" property="inputBy" />
    <result column="debt_money" jdbcType="DECIMAL" property="debtMoney" />
    <result column="change_in_pay_money" jdbcType="DECIMAL" property="changeInPayMoney" />
    <result column="change_in_money" jdbcType="DECIMAL" property="changeInMoney" />
    <result column="change_out_money" jdbcType="DECIMAL" property="changeOutMoney" />
    <result column="difference_money" jdbcType="DECIMAL" property="differenceMoney" />
    <result column="addition_date" jdbcType="DATE" property="additionDate" />
    <result column="is_addition" jdbcType="INTEGER" property="isAddition" />
    <result column="is_cancel" jdbcType="INTEGER" property="isCancel" />
    <result column="is_debt" jdbcType="INTEGER" property="isDebt" />
    <result column="cancel_date" jdbcType="TIMESTAMP" property="cancelDate" />
    <result column="cancel_id" jdbcType="BIGINT" property="cancelId" />
    <result column="cancel_by" jdbcType="VARCHAR" property="cancelBy" />
    <result column="audit_date" jdbcType="TIMESTAMP" property="auditDate" />
    <result column="audit_id" jdbcType="BIGINT" property="auditId" />
    <result column="audit_by" jdbcType="VARCHAR" property="auditBy" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="description" jdbcType="LONGVARCHAR" property="description" />
  </resultMap>


  <select id="selectFKJ" resultMap="BaseResultMap" parameterType="com.ssm.manage.entity.CardChangeList">
    select * from card_change_list
    <where>
      store_id = #{storeId, jdbcType = BIGINT} and state=3
      and DATE_FORMAT(doc_date, '%Y-%m-%d' ) = DATE_FORMAT(#{docDate} , '%Y-%m-%d' );
    </where>
  </select>
  <resultMap id="selectByDay" type="com.ssm.manage.response.CardChangeDayVo">
    <result column="store_id" property="storeId"/>
    <result column="store_name" property="storeName"/>
    <result column="date" property="date"/>
    <result column="debt_money" property="debtMoney"/>
    <result column="change_in_pay_money" property="changeInPayMoney"/>
  </resultMap>
    <select id="selectByDay" resultMap="selectByDay">
      select store_id,store_name,date(doc_date) as date, sum(ifnull(debt_money,0)) as debt_money,sum(ifnull(change_in_pay_money,0)) as change_in_pay_money
      from card_change_list
      where  state = '3' and store_id in
        <foreach collection="storeIds" separator="," close=")" open="(" item="item">
          #{item}
        </foreach>
      and doc_date between #{startTime} and #{endTime}
      group by store_id,store_name,date(doc_date) order by store_id,date(doc_date);
    </select>
  <resultMap id="StoreDailyMap" type="com.ssm.manage.extendEntity.StoreDaily">
    <!--
      WARNING - @mbg.generated
    -->
    <result column="store_id" property="storeId" jdbcType="BIGINT"/>
    <result column="store_name" property="storeName" jdbcType="VARCHAR"/>
    <result column="date" property="date" jdbcType="TIMESTAMP"/>
    <result column="cash_people_num" jdbcType="INTEGER" property="cashPeopleNum" />
    <result column="cash_money" jdbcType="DECIMAL" property="cashMoney" />
    <result column="course_money" jdbcType="DECIMAL" property="courseMoney" />
    <result column="course_order_num" jdbcType="INTEGER" property="courseOrderNum" />
    <result column="recharge_money" jdbcType="DECIMAL" property="rechargeMoney" />
    <result column="recharge_order_num" jdbcType="INTEGER" property="rechargeOrderNum" />
    <result column="repay_money" jdbcType="DECIMAL" property="repayMoney" />
    <result column="refund_money" jdbcType="DECIMAL" property="refundMoney" />
    <result column="rec_negative_money" jdbcType="BIGINT" property="recNegativeMoney" />
    <result column="member_num" jdbcType="INTEGER" property="memberNum" />
    <result column="new_member_num" jdbcType="INTEGER" property="newMemberNum" />

    <result column="coursex_money" jdbcType="DECIMAL" property="coursexMoney" />
    <result column="coursek_money" jdbcType="DECIMAL" property="coursekMoney" />
    <result column="id" jdbcType="VARCHAR" property="id" />
    <result column="cash_cooperation" property="cooperateAmount"/>
    <result column="change_inpaymoney" jdbcType="DECIMAL" property="changeInPayMoney" />

  </resultMap>

  <select id="selectByDayGroupByDateAndStoreId" resultMap="StoreDailyMap" parameterType="com.ssm.manage.query.StoreDailyRequest">
      select SUBSTRING(doc_date, 1, 10 ) as date,store_id,store_name,sum(change_in_pay_money) as change_inpaymoney from card_change_list
        where state = 3 and
              doc_date between #{startDate} and #{endDate}
        group by SUBSTRING(doc_date, 1, 10 ),store_id
    </select>
    <select id="selectNew"  resultMap="BaseResultMap">
      select * from card_change_list where SUBSTR(doc_date,1,7) = #{strDate}
    </select>
    <select id="selectFKJByDate" resultMap="BaseResultMap" parameterType="com.ssm.manage.entity.CardChangeList">
      select * from card_change_list
      <where>
        store_id = #{storeId, jdbcType = BIGINT} and state=3
        and doc_date between #{startTime} and #{endTime}
      </where>
    </select>
</mapper>