<?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.RefundOrderListMapper">
  <resultMap id="BaseResultMap" type="com.ssm.manage.entity.RefundOrderList">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="refund_num" jdbcType="VARCHAR" property="refundNum" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="refund_date" jdbcType="TIMESTAMP" property="refundDate" />
    <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="refund_money" jdbcType="DECIMAL" property="refundMoney" />
    <result column="compensation" jdbcType="DECIMAL" property="compensation" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="input_id" jdbcType="BIGINT" property="inputId" />
    <result column="input_by" jdbcType="VARCHAR" property="inputBy" />
    <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="actual_refund_money" jdbcType="DECIMAL" property="actualRefundMoney" />
    <result column="rec_refund_money" jdbcType="DECIMAL" property="recRefundMoney" />
    <result column="couse_refund_money" jdbcType="DECIMAL" property="couseRefundMoney" />
    <result column="source_doc_num" jdbcType="VARCHAR" property="sourceDocNum" />
    <result column="refund_type" jdbcType="VARCHAR" property="refundType" />
    <result column="refund_account" jdbcType="VARCHAR" property="refundAccount" />
    <result column="payee" jdbcType="VARCHAR" property="payee" />
    <result column="refund_reason" jdbcType="LONGVARCHAR" property="refundReason" />
  </resultMap>

  <resultMap id="StoreDailyMap" type="com.ssm.manage.extendEntity.StoreDaily">
    <!--
      WARNING - @mbg.generated
    -->

    <result column="cash_people_num" jdbcType="INTEGER" property="cashPeopleNum" />
    <result column="cash_money" jdbcType="DECIMAL" property="cashMoney" />
    <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="refund_type" jdbcType="INTEGER" property="refundType" />
  </resultMap>

  <select id="selectDayRecord" resultMap="StoreDailyMap" parameterType="com.ssm.manage.query.StoreDailyRequest">
    select sum(refund_money) as refund_money from refund_order_list
    <where>
      store_id = #{storeId, jdbcType = BIGINT}
      <if test="state != null">
        and state = #{state, jdbcType = INTEGER}
      </if>
      <if test="dateStr != null">
        and audit_date like concat( #{dateStr, jdbcType = VARCHAR}, '%')
      </if>
    </where>
  </select>

  <select id="selectRefund" resultMap="StoreDailyMap" parameterType="com.ssm.manage.query.StoreDailyRequest">
    select type as refund_type,sum(refund_money) as refund_money from refund_order_list
    <where>
      store_id = #{storeId, jdbcType = BIGINT}
      <if test="state != null">
        and state = #{state, jdbcType = INTEGER}
      </if>
      <if test="dateStr != null">
        and audit_date like concat( #{dateStr, jdbcType = VARCHAR}, '%')
      </if>
    </where>
    GROUP BY type
  </select>


  <select id="selectFKJ" resultMap="BaseResultMap" parameterType="com.ssm.manage.entity.RefundOrderList">
    select * from refund_order_list
    <where>
      store_id = #{storeId, jdbcType = BIGINT} and state=3
      and DATE_FORMAT(refund_date, '%Y-%m-%d' ) = DATE_FORMAT(#{refundDate} , '%Y-%m-%d' );
    </where>
  </select>
  <resultMap id="selectByDay" type="com.ssm.manage.response.RefundDayVo">
    <result column="store_id" property="storeId"/>
    <result column="date" property="date"/>
    <result column="refund_money" property="refundMoney"/>
  </resultMap>
    <select id="selectByDay" resultMap="selectByDay">
      SELECT store_id,date(refund_date) as date,sum(ifnull(refund_money,0)) as refund_money
      from refund_order_list
      WHERE store_id IN
        <foreach collection="storeIds" separator="," close=")" open="(" item="item" >
          #{item}
        </foreach>
          AND refund_date BETWEEN #{startTime} and #{endTime} and state=3
      GROUP BY store_id,date(refund_date);
    </select>
    <select id="selectNew" resultMap="BaseResultMap">
      select * from refund_order_list where type = #{type} and SUBSTR(refund_date,1,7) = #{strDate}
    </select>
    <select id="selectFKJByDate" resultMap="BaseResultMap" parameterType="com.ssm.manage.entity.RefundOrderList">
      select * from refund_order_list
      <where>
        store_id = #{storeId, jdbcType = BIGINT} and state=3
        and audite_date between #{startTime} and #{endTime}
      </where>
    </select>
</mapper>