<?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.DocPromotionMapper">
  <resultMap id="BaseResultMap" type="com.ssm.manage.entity.DocPromotion">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <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="mobile_phone" jdbcType="VARCHAR" property="mobilePhone" />
    <result column="member_identity_card" jdbcType="VARCHAR" property="memberIdentityCard" />
    <result column="card" jdbcType="VARCHAR" property="card" />
    <result column="doc_num" jdbcType="VARCHAR" property="docNum" />
    <result column="doc_date" jdbcType="TIMESTAMP" property="docDate" />
    <result column="promotion_id" jdbcType="BIGINT" property="promotionId" />
    <result column="promotion_num" jdbcType="VARCHAR" property="promotionNum" />
    <result column="promotion_name" jdbcType="VARCHAR" property="promotionName" />
    <result column="price" jdbcType="DECIMAL" property="price" />
    <result column="count" jdbcType="INTEGER" property="count" />
    <result column="amount" jdbcType="DECIMAL" property="amount" />
    <result column="collection_cash_amount" jdbcType="DECIMAL" property="collectionCashAmount" />
    <result column="collection_recharge_amount" jdbcType="DECIMAL" property="collectionRechargeAmount" />
    <result column="sales_commission" jdbcType="DECIMAL" property="salesCommission" />
    <result column="card_sales_commission" jdbcType="DECIMAL" property="cardSalesCommission" />
    <result column="achievement_amount" jdbcType="DECIMAL" property="achievementAmount" />
    <result column="commission_amount" jdbcType="DECIMAL" property="commissionAmount" />
    <result column="card_achievement_amount" jdbcType="DECIMAL" property="cardAchievementAmount" />
    <result column="card_commission_amount" jdbcType="DECIMAL" property="cardCommissionAmount" />
    <result column="sale_one_number" jdbcType="VARCHAR" property="saleOneNumber" />
    <result column="sale_two_number" jdbcType="VARCHAR" property="saleTwoNumber" />
    <result column="sale_three_number" jdbcType="VARCHAR" property="saleThreeNumber" />
    <result column="sale_four_number" jdbcType="VARCHAR" property="saleFourNumber" />
    <result column="sale_one_staff_id" jdbcType="BIGINT" property="saleOneStaffId" />
    <result column="sale_two_staff_id" jdbcType="BIGINT" property="saleTwoStaffId" />
    <result column="sale_three_staff_id" jdbcType="BIGINT" property="saleThreeStaffId" />
    <result column="sale_four_staff_id" jdbcType="BIGINT" property="saleFourStaffId" />
    <result column="sale_one_staff_name" jdbcType="VARCHAR" property="saleOneStaffName" />
    <result column="sale_two_staff_name" jdbcType="VARCHAR" property="saleTwoStaffName" />
    <result column="sale_three_staff_name" jdbcType="VARCHAR" property="saleThreeStaffName" />
    <result column="sale_four_staff_name" jdbcType="VARCHAR" property="saleFourStaffName" />
    <result column="sale_one_identity" jdbcType="VARCHAR" property="saleOneIdentity" />
    <result column="sale_two_identity" jdbcType="VARCHAR" property="saleTwoIdentity" />
    <result column="sale_three_identity" jdbcType="VARCHAR" property="saleThreeIdentity" />
    <result column="sale_four_identity" jdbcType="VARCHAR" property="saleFourIdentity" />
    <result column="sale_one_ratio" jdbcType="DECIMAL" property="saleOneRatio" />
    <result column="sale_two_ratio" jdbcType="DECIMAL" property="saleTwoRatio" />
    <result column="sale_three_ratio" jdbcType="DECIMAL" property="saleThreeRatio" />
    <result column="sale_four_ratio" jdbcType="DECIMAL" property="saleFourRatio" />
    <result column="manage_staff_id" jdbcType="BIGINT" property="manageStaffId" />
    <result column="manage_staff_name" jdbcType="VARCHAR" property="manageStaffName" />
    <result column="manage_identity" jdbcType="VARCHAR" property="manageIdentity" />
    <result column="manage_number" jdbcType="VARCHAR" property="manageNumber" />
    <result column="sale_one_achievement_amount" jdbcType="DECIMAL" property="saleOneAchievementAmount" />
    <result column="sale_two_achievement_amount" jdbcType="DECIMAL" property="saleTwoAchievementAmount" />
    <result column="sale_three_achievement_amount" jdbcType="DECIMAL" property="saleThreeAchievementAmount" />
    <result column="sale_four_achievement_amount" jdbcType="DECIMAL" property="saleFourAchievementAmount" />
    <result column="sale_one_commission_amount" jdbcType="DECIMAL" property="saleOneCommissionAmount" />
    <result column="sale_two_commission_amount" jdbcType="DECIMAL" property="saleTwoCommissionAmount" />
    <result column="sale_three_commission_amount" jdbcType="DECIMAL" property="saleThreeCommissionAmount" />
    <result column="sale_four_commission_amount" jdbcType="DECIMAL" property="saleFourCommissionAmount" />
    <result column="input_id" jdbcType="BIGINT" property="inputId" />
    <result column="input_by" jdbcType="VARCHAR" property="inputBy" />
    <result column="input_date" jdbcType="TIMESTAMP" property="inputDate" />
    <result column="cancel_id" jdbcType="BIGINT" property="cancelId" />
    <result column="cancel_by" jdbcType="VARCHAR" property="cancelBy" />
    <result column="cancel_date" jdbcType="TIMESTAMP" property="cancelDate" />
    <result column="is_cancel" jdbcType="INTEGER" property="isCancel" />
    <result column="description" jdbcType="LONGVARCHAR" property="description" />
    <result column="is_debt" jdbcType="INTEGER" property="isDebt" />
    <result column="debt_money" jdbcType="DECIMAL" property="debtMoney" />
    <result column="project_count" jdbcType="INTEGER" property="projectCount" />
    <result column="project_total" jdbcType="INTEGER" property="projectTotal" />
    <result column="promotion_type" jdbcType="INTEGER" property="promotionType" />
    <result column="project_array" jdbcType="VARCHAR" property="projectArray" />
    <result column="money_type" jdbcType="INTEGER" property="moneyType" />
  </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="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" />
  </resultMap>


  <update id="updateStaff" parameterType="com.ssm.manage.entity.DocPromotion">
    update doc_promotion
    <set>
      <!--<if test="saleOneNumber != null">-->
      sale_one_number = #{saleOneNumber, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleTwoNumber != null">-->
      sale_two_number = #{saleTwoNumber, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleThreeNumber != null">-->
      sale_three_number = #{saleThreeNumber, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleFourNumber != null">-->
      sale_four_number = #{saleFourNumber, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleOneStaffId != null">-->
      sale_one_staff_id = #{saleOneStaffId, jdbcType = BIGINT},
      <!--</if>
      <if test="saleTwoStaffId != null">-->
      sale_two_staff_id = #{saleTwoStaffId, jdbcType = BIGINT},
      <!--</if>
      <if test="saleThreeStaffId != null">-->
      sale_three_staff_id = #{saleThreeStaffId, jdbcType = BIGINT},
      <!--</if>
      <if test="saleFourStaffId != null">-->
      sale_four_staff_id = #{saleFourStaffId, jdbcType = BIGINT},
      <!--</if>
      <if test="saleOneStaffName != null">-->
      sale_one_staff_name = #{saleOneStaffName, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleTwoStaffName != null">-->
      sale_two_staff_name = #{saleTwoStaffName, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleThreeStaffName != null">-->
      sale_three_staff_name = #{saleThreeStaffName, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleFourStaffName != null">-->
      sale_four_staff_name = #{saleFourStaffName, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleOneIdentity != null">-->
      sale_one_identity = #{saleOneIdentity, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleTwoIdentity != null">-->
      sale_two_identity = #{saleTwoIdentity, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleThreeIdentity != null">-->
      sale_three_identity = #{saleThreeIdentity, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleFourIdentity != null">-->
      sale_four_identity = #{saleFourIdentity, jdbcType = VARCHAR},
      <!--</if>
      <if test="saleOneRatio != null">-->
      sale_one_ratio = #{saleOneRatio, jdbcType = DECIMAL},
      <!--</if>
      <if test="saleTwoRatio != null">-->
      sale_two_ratio = #{saleTwoRatio, jdbcType = DECIMAL},
      <!--</if>
      <if test="saleThreeRatio != null">-->
      sale_three_ratio = #{saleThreeRatio, jdbcType = DECIMAL},
      <!--</if>
      <if test="saleFourRatio != null"> </if>-->
      sale_four_ratio = #{saleFourRatio, jdbcType = DECIMAL}
    </set>
    <where>
      id = #{id, jdbcType = BIGINT}
    </where>
  </update>

  <select id="selectDayRecord" resultMap="StoreDailyMap" parameterType="com.ssm.manage.query.StoreDailyRequest">
    select count(collection_cash_amount) as course_order_num, sum(collection_cash_amount+collection_recharge_amount) as course_money from doc_promotion
    <where>
      store_id = #{storeId, jdbcType = BIGINT} and is_cancel=0
      <if test="dateStr != null">
        and doc_date like concat( #{dateStr, jdbcType = VARCHAR}, '%')
      </if>
    </where>
  </select>

  <select id="selectFKJ" resultMap="BaseResultMap" parameterType="com.ssm.manage.query.DocPromotionRequest">
    select * from doc_promotion
    <where>
      store_id = #{storeId, jdbcType = BIGINT} and is_cancel=0
      and DATE_FORMAT(doc_date, '%Y-%m-%d' ) = DATE_FORMAT(#{docDate} , '%Y-%m-%d' );
    </where>
  </select>
  <resultMap id="selectByDay" type="com.ssm.manage.response.PromotionDayVo">
  <result column="store_id" property="storeId"/>
    <result column="date" property="date"/>
    <result column="collection_cash_amount" property="collectionCashAmount"/>
    <result column="collection_recharge_amount" property="collectionRechargeAmount"/>
    <result column="debt_money" property="debtMoney"/>
  </resultMap>
    <select id="selectByDay" resultMap="selectByDay" >
      SELECT store_id,date(doc_date) as date,
          sum(ifnull(collection_cash_amount,0)) as collection_cash_amount,
          SUM(ifnull(collection_recharge_amount,0)) as collection_recharge_amount,
          sum(ifnull(debt_money,0)) as debt_money
      from doc_promotion
      WHERE is_cancel = 0 and store_id IN
        <foreach collection="storeIds" item="item" open="(" close=")" separator=",">
          #{item}
        </foreach>
          AND doc_date BETWEEN #{startTime} and #{endTime}
      GROUP BY store_id,date(doc_date);
    </select>
    <select id="selectList" resultMap="BaseResultMap">
      select * from doc_promotion where SUBSTR(doc_date,1,7) = #{strDate} and store_id in <foreach
            collection="storeIds" open="(" close=")" separator="," item="item">
      #{item}
    </foreach>
    </select>
  <select id="selectFKJByDate" resultMap="BaseResultMap" parameterType="com.ssm.manage.query.DocPromotionRequest">
    select * from doc_promotion
    <where>
      store_id = #{storeId, jdbcType = BIGINT} and is_cancel=0
      and doc_date between #{startTime} and #{endTime}
    </where>
  </select>
    <select id="selectListByStartTimeAndEndTime" resultMap="BaseResultMap">
      select * from doc_promotion where is_cancel = 0 and store_id = #{storeId} and doc_date between #{startTime} and #{endTime}
    </select>

</mapper>