<?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.yd.dal.mapper.customer.AclCustomerFortuneMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.customer.AclCustomerFortune">
    <!--@mbg.generated-->
    <!--@Table ag_acl_customer_fortune-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="share_id" jdbcType="BIGINT" property="shareId" />
    <result column="customer_id" jdbcType="BIGINT" property="customerId" />
    <result column="order_id" jdbcType="BIGINT" property="orderId" />
    <result column="order_date" jdbcType="TIMESTAMP" property="orderDate" />
    <result column="order_price" jdbcType="DECIMAL" property="orderPrice" />
    <result column="commission_rate" jdbcType="DECIMAL" property="commissionRate" />
    <result column="commission_amount" jdbcType="DECIMAL" property="commissionAmount" />
    <result column="fyc_rate" jdbcType="DECIMAL" property="fycRate" />
    <result column="fyc_amount" jdbcType="DECIMAL" property="fycAmount" />
    <result column="grade_commission_rate" jdbcType="DECIMAL" property="gradeCommissionRate" />
    <result column="share_rate" jdbcType="DECIMAL" property="shareRate" />
    <result column="referral_rate" jdbcType="DECIMAL" property="referralRate" />
    <result column="referral_amount" jdbcType="DECIMAL" property="referralAmount" />
    <result column="month_period" jdbcType="VARCHAR" property="monthPeriod" />
    <result column="commission_type" jdbcType="VARCHAR" property="commissionType" />
    <result column="drop_option_code" jdbcType="VARCHAR" property="dropOptionCode" />
    <result column="practitioner_level" jdbcType="VARCHAR" property="practitionerLevel" />
    <result column="is_tax" jdbcType="INTEGER" property="isTax" />
    <result column="tax_amount" jdbcType="DECIMAL" property="taxAmount" />
    <result column="net_amount" jdbcType="DECIMAL" property="netAmount" />
    <result column="campaign_id" jdbcType="BIGINT" property="campaignId" />
    <result column="campaign_name" jdbcType="VARCHAR" property="campaignName" />
    <result column="withdrawable_date" jdbcType="TIMESTAMP" property="withdrawableDate" />
    <result column="payout_batch_id" jdbcType="BIGINT" property="payoutBatchId" />
    <result column="commission_payout_status" jdbcType="VARCHAR" property="commissionPayoutStatus" />
    <result column="commission_payout_at" jdbcType="TIMESTAMP" property="commissionPayoutAt" />
    <result column="commission_payout_by" jdbcType="BIGINT" property="commissionPayoutBy" />
    <result column="withdrawed_id" jdbcType="BIGINT" property="withdrawedId" />
    <result column="fortune_payed_id" jdbcType="BIGINT" property="fortunePayedId" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="BIGINT" property="createdBy" />

    <result column="rule_id" jdbcType="BIGINT" property="ruleId" />
    <result column="rule_code" jdbcType="VARCHAR" property="ruleCode" />
    <result column="settlement_type" jdbcType="VARCHAR" property="settlementType" />
    <result column="practitioner_id" jdbcType="BIGINT" property="practitionerId" />
    <result column="channel_id" jdbcType="BIGINT" property="channelId" />
    <result column="insurer_id" jdbcType="BIGINT" property="insurerId" />
    <result column="product_id" jdbcType="BIGINT" property="productId" />
    <result column="calculation_method" jdbcType="VARCHAR" property="calculationMethod" />
    <result column="calculation_formula" jdbcType="VARCHAR" property="calculationFormula" />
    <result column="statistic_start" jdbcType="BIGINT" property="statisticStart" />
    <result column="statistic_end" jdbcType="BIGINT" property="statisticEnd" />
    <result column="segment_vlaue" jdbcType="BIGINT" property="segmentVlaue" />
    <result column="predict_month_period" jdbcType="TIMESTAMP" property="predictMonthPeriod" />
    <result column="status" jdbcType="VARCHAR" property="status" />
    <result column="commission_id" jdbcType="BIGINT" property="commissionId" />
    <result column="commission_flag" jdbcType="VARCHAR" property="commissionFlag" />
    <result column="cover_introducer_id" jdbcType="BIGINT" property="coverIntroducerId" />
    <result column="commission_period" jdbcType="INTEGER" property="commissionPeriod" />
    <result column="remark" jdbcType="LONGVARCHAR" property="remark" />
    <result column="achievements_rate" jdbcType="DECIMAL" property="achievementsRate" />
    <result column="achievements" jdbcType="DECIMAL" property="achievements" />
    <result column="examine_fyc" jdbcType="DECIMAL" property="examineFyc" />
    <result column="comprehensive_fyc" jdbcType="DECIMAL" property="comprehensiveFyc" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, share_id, customer_id, order_id, order_date, order_price, commission_rate, commission_amount, 
    fyc_rate, fyc_amount, grade_commission_rate, share_rate, referral_rate, referral_amount, 
    month_period, commission_type, drop_option_code, practitioner_level, is_tax, tax_amount, 
    net_amount, campaign_id, campaign_name, withdrawable_date, payout_batch_id, commission_payout_status, 
    commission_payout_at, commission_payout_by, withdrawed_id, fortune_payed_id, created_at, created_by,
    rule_id,
    rule_code,
    settlement_type,
    practitioner_id,
    channel_id,
    insurer_id,
    product_id,
    calculation_method,
    calculation_formula,
    statistic_start,
    statistic_end,
    segment_vlaue,
    predict_month_period,
    status,
    commission_id,
    commission_flag,
    cover_introducer_id,
    commission_period,
    remark,
    achievements_rate,
    achievements,
    examine_fyc,
    comprehensive_fyc
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from ag_acl_customer_fortune
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from ag_acl_customer_fortune
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclCustomerFortune" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ag_acl_customer_fortune (share_id, customer_id, order_id, 
      order_date, order_price, commission_rate, 
      commission_amount, fyc_rate, fyc_amount, 
      grade_commission_rate, share_rate, referral_rate, 
      referral_amount, month_period, commission_type, 
      drop_option_code, practitioner_level, is_tax, 
      tax_amount, net_amount, campaign_id, 
      campaign_name, withdrawable_date, payout_batch_id, 
      commission_payout_status, commission_payout_at, 
      commission_payout_by, withdrawed_id, fortune_payed_id, 
      created_at, created_by)
    values (#{shareId,jdbcType=BIGINT}, #{customerId,jdbcType=BIGINT}, #{orderId,jdbcType=BIGINT}, 
      #{orderDate,jdbcType=TIMESTAMP}, #{orderPrice,jdbcType=DECIMAL}, #{commissionRate,jdbcType=DECIMAL}, 
      #{commissionAmount,jdbcType=DECIMAL}, #{fycRate,jdbcType=DECIMAL}, #{fycAmount,jdbcType=DECIMAL}, 
      #{gradeCommissionRate,jdbcType=DECIMAL}, #{shareRate,jdbcType=DECIMAL}, #{referralRate,jdbcType=DECIMAL}, 
      #{referralAmount,jdbcType=DECIMAL}, #{monthPeriod,jdbcType=VARCHAR}, #{commissionType,jdbcType=VARCHAR}, 
      #{dropOptionCode,jdbcType=VARCHAR}, #{practitionerLevel,jdbcType=VARCHAR}, #{isTax,jdbcType=INTEGER}, 
      #{taxAmount,jdbcType=DECIMAL}, #{netAmount,jdbcType=DECIMAL}, #{campaignId,jdbcType=BIGINT}, 
      #{campaignName,jdbcType=VARCHAR}, #{withdrawableDate,jdbcType=TIMESTAMP}, #{payoutBatchId,jdbcType=BIGINT}, 
      #{commissionPayoutStatus,jdbcType=VARCHAR}, #{commissionPayoutAt,jdbcType=TIMESTAMP}, 
      #{commissionPayoutBy,jdbcType=BIGINT}, #{withdrawedId,jdbcType=BIGINT}, #{fortunePayedId,jdbcType=BIGINT}, 
      #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclCustomerFortune" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ag_acl_customer_fortune
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="shareId != null">
        share_id,
      </if>
      <if test="customerId != null">
        customer_id,
      </if>
      <if test="orderId != null">
        order_id,
      </if>
      <if test="orderDate != null">
        order_date,
      </if>
      <if test="orderPrice != null">
        order_price,
      </if>
      <if test="commissionRate != null">
        commission_rate,
      </if>
      <if test="commissionAmount != null">
        commission_amount,
      </if>
      <if test="fycRate != null">
        fyc_rate,
      </if>
      <if test="fycAmount != null">
        fyc_amount,
      </if>
      <if test="gradeCommissionRate != null">
        grade_commission_rate,
      </if>
      <if test="shareRate != null">
        share_rate,
      </if>
      <if test="referralRate != null">
        referral_rate,
      </if>
      <if test="referralAmount != null">
        referral_amount,
      </if>
      <if test="monthPeriod != null">
        month_period,
      </if>
      <if test="commissionType != null">
        commission_type,
      </if>
      <if test="dropOptionCode != null">
        drop_option_code,
      </if>
      <if test="practitionerLevel != null">
        practitioner_level,
      </if>
      <if test="isTax != null">
        is_tax,
      </if>
      <if test="taxAmount != null">
        tax_amount,
      </if>
      <if test="netAmount != null">
        net_amount,
      </if>
      <if test="campaignId != null">
        campaign_id,
      </if>
      <if test="campaignName != null">
        campaign_name,
      </if>
      <if test="withdrawableDate != null">
        withdrawable_date,
      </if>
      <if test="payoutBatchId != null">
        payout_batch_id,
      </if>
      <if test="commissionPayoutStatus != null">
        commission_payout_status,
      </if>
      <if test="commissionPayoutAt != null">
        commission_payout_at,
      </if>
      <if test="commissionPayoutBy != null">
        commission_payout_by,
      </if>
      <if test="withdrawedId != null">
        withdrawed_id,
      </if>
      <if test="fortunePayedId != null">
        fortune_payed_id,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="shareId != null">
        #{shareId,jdbcType=BIGINT},
      </if>
      <if test="customerId != null">
        #{customerId,jdbcType=BIGINT},
      </if>
      <if test="orderId != null">
        #{orderId,jdbcType=BIGINT},
      </if>
      <if test="orderDate != null">
        #{orderDate,jdbcType=TIMESTAMP},
      </if>
      <if test="orderPrice != null">
        #{orderPrice,jdbcType=DECIMAL},
      </if>
      <if test="commissionRate != null">
        #{commissionRate,jdbcType=DECIMAL},
      </if>
      <if test="commissionAmount != null">
        #{commissionAmount,jdbcType=DECIMAL},
      </if>
      <if test="fycRate != null">
        #{fycRate,jdbcType=DECIMAL},
      </if>
      <if test="fycAmount != null">
        #{fycAmount,jdbcType=DECIMAL},
      </if>
      <if test="gradeCommissionRate != null">
        #{gradeCommissionRate,jdbcType=DECIMAL},
      </if>
      <if test="shareRate != null">
        #{shareRate,jdbcType=DECIMAL},
      </if>
      <if test="referralRate != null">
        #{referralRate,jdbcType=DECIMAL},
      </if>
      <if test="referralAmount != null">
        #{referralAmount,jdbcType=DECIMAL},
      </if>
      <if test="monthPeriod != null">
        #{monthPeriod,jdbcType=VARCHAR},
      </if>
      <if test="commissionType != null">
        #{commissionType,jdbcType=VARCHAR},
      </if>
      <if test="dropOptionCode != null">
        #{dropOptionCode,jdbcType=VARCHAR},
      </if>
      <if test="practitionerLevel != null">
        #{practitionerLevel,jdbcType=VARCHAR},
      </if>
      <if test="isTax != null">
        #{isTax,jdbcType=INTEGER},
      </if>
      <if test="taxAmount != null">
        #{taxAmount,jdbcType=DECIMAL},
      </if>
      <if test="netAmount != null">
        #{netAmount,jdbcType=DECIMAL},
      </if>
      <if test="campaignId != null">
        #{campaignId,jdbcType=BIGINT},
      </if>
      <if test="campaignName != null">
        #{campaignName,jdbcType=VARCHAR},
      </if>
      <if test="withdrawableDate != null">
        #{withdrawableDate,jdbcType=TIMESTAMP},
      </if>
      <if test="payoutBatchId != null">
        #{payoutBatchId,jdbcType=BIGINT},
      </if>
      <if test="commissionPayoutStatus != null">
        #{commissionPayoutStatus,jdbcType=VARCHAR},
      </if>
      <if test="commissionPayoutAt != null">
        #{commissionPayoutAt,jdbcType=TIMESTAMP},
      </if>
      <if test="commissionPayoutBy != null">
        #{commissionPayoutBy,jdbcType=BIGINT},
      </if>
      <if test="withdrawedId != null">
        #{withdrawedId,jdbcType=BIGINT},
      </if>
      <if test="fortunePayedId != null">
        #{fortunePayedId,jdbcType=BIGINT},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yd.dal.entity.customer.AclCustomerFortune">
    <!--@mbg.generated-->
    update ag_acl_customer_fortune
    <set>
      <if test="shareId != null">
        share_id = #{shareId,jdbcType=BIGINT},
      </if>
      <if test="customerId != null">
        customer_id = #{customerId,jdbcType=BIGINT},
      </if>
      <if test="orderId != null">
        order_id = #{orderId,jdbcType=BIGINT},
      </if>
      <if test="orderDate != null">
        order_date = #{orderDate,jdbcType=TIMESTAMP},
      </if>
      <if test="orderPrice != null">
        order_price = #{orderPrice,jdbcType=DECIMAL},
      </if>
      <if test="commissionRate != null">
        commission_rate = #{commissionRate,jdbcType=DECIMAL},
      </if>
      <if test="commissionAmount != null">
        commission_amount = #{commissionAmount,jdbcType=DECIMAL},
      </if>
      <if test="fycRate != null">
        fyc_rate = #{fycRate,jdbcType=DECIMAL},
      </if>
      <if test="fycAmount != null">
        fyc_amount = #{fycAmount,jdbcType=DECIMAL},
      </if>
      <if test="gradeCommissionRate != null">
        grade_commission_rate = #{gradeCommissionRate,jdbcType=DECIMAL},
      </if>
      <if test="shareRate != null">
        share_rate = #{shareRate,jdbcType=DECIMAL},
      </if>
      <if test="referralRate != null">
        referral_rate = #{referralRate,jdbcType=DECIMAL},
      </if>
      <if test="referralAmount != null">
        referral_amount = #{referralAmount,jdbcType=DECIMAL},
      </if>
      <if test="monthPeriod != null">
        month_period = #{monthPeriod,jdbcType=VARCHAR},
      </if>
      <if test="commissionType != null">
        commission_type = #{commissionType,jdbcType=VARCHAR},
      </if>
      <if test="dropOptionCode != null">
        drop_option_code = #{dropOptionCode,jdbcType=VARCHAR},
      </if>
      <if test="practitionerLevel != null">
        practitioner_level = #{practitionerLevel,jdbcType=VARCHAR},
      </if>
      <if test="isTax != null">
        is_tax = #{isTax,jdbcType=INTEGER},
      </if>
      <if test="taxAmount != null">
        tax_amount = #{taxAmount,jdbcType=DECIMAL},
      </if>
      <if test="netAmount != null">
        net_amount = #{netAmount,jdbcType=DECIMAL},
      </if>
      <if test="campaignId != null">
        campaign_id = #{campaignId,jdbcType=BIGINT},
      </if>
      <if test="campaignName != null">
        campaign_name = #{campaignName,jdbcType=VARCHAR},
      </if>
      <if test="withdrawableDate != null">
        withdrawable_date = #{withdrawableDate,jdbcType=TIMESTAMP},
      </if>
      <if test="payoutBatchId != null">
        payout_batch_id = #{payoutBatchId,jdbcType=BIGINT},
      </if>
      <if test="commissionPayoutStatus != null">
        commission_payout_status = #{commissionPayoutStatus,jdbcType=VARCHAR},
      </if>
      <if test="commissionPayoutAt != null">
        commission_payout_at = #{commissionPayoutAt,jdbcType=TIMESTAMP},
      </if>
      <if test="commissionPayoutBy != null">
        commission_payout_by = #{commissionPayoutBy,jdbcType=BIGINT},
      </if>
      <if test="withdrawedId != null">
        withdrawed_id = #{withdrawedId,jdbcType=BIGINT},
      </if>
      <if test="fortunePayedId != null">
        fortune_payed_id = #{fortunePayedId,jdbcType=BIGINT},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="updatedAt != null">
        updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        updated_by = #{updatedBy,jdbcType=BIGINT},
      </if>
      <if test="remark != null">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yd.dal.entity.customer.AclCustomerFortune">
    <!--@mbg.generated-->
    update ag_acl_customer_fortune
    set share_id = #{shareId,jdbcType=BIGINT},
      customer_id = #{customerId,jdbcType=BIGINT},
      order_id = #{orderId,jdbcType=BIGINT},
      order_date = #{orderDate,jdbcType=TIMESTAMP},
      order_price = #{orderPrice,jdbcType=DECIMAL},
      commission_rate = #{commissionRate,jdbcType=DECIMAL},
      commission_amount = #{commissionAmount,jdbcType=DECIMAL},
      fyc_rate = #{fycRate,jdbcType=DECIMAL},
      fyc_amount = #{fycAmount,jdbcType=DECIMAL},
      grade_commission_rate = #{gradeCommissionRate,jdbcType=DECIMAL},
      share_rate = #{shareRate,jdbcType=DECIMAL},
      referral_rate = #{referralRate,jdbcType=DECIMAL},
      referral_amount = #{referralAmount,jdbcType=DECIMAL},
      month_period = #{monthPeriod,jdbcType=VARCHAR},
      commission_type = #{commissionType,jdbcType=VARCHAR},
      drop_option_code = #{dropOptionCode,jdbcType=VARCHAR},
      practitioner_level = #{practitionerLevel,jdbcType=VARCHAR},
      is_tax = #{isTax,jdbcType=INTEGER},
      tax_amount = #{taxAmount,jdbcType=DECIMAL},
      net_amount = #{netAmount,jdbcType=DECIMAL},
      campaign_id = #{campaignId,jdbcType=BIGINT},
      campaign_name = #{campaignName,jdbcType=VARCHAR},
      withdrawable_date = #{withdrawableDate,jdbcType=TIMESTAMP},
      payout_batch_id = #{payoutBatchId,jdbcType=BIGINT},
      commission_payout_status = #{commissionPayoutStatus,jdbcType=VARCHAR},
      commission_payout_at = #{commissionPayoutAt,jdbcType=TIMESTAMP},
      commission_payout_by = #{commissionPayoutBy,jdbcType=BIGINT},
      withdrawed_id = #{withdrawedId,jdbcType=BIGINT},
      fortune_payed_id = #{fortunePayedId,jdbcType=BIGINT},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update ag_acl_customer_fortune
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="share_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.shareId,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="customer_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.customerId,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="order_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.orderId,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="order_date = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.orderDate,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="order_price = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.orderPrice,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="commission_rate = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.commissionRate,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="commission_amount = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.commissionAmount,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="fyc_rate = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.fycRate,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="fyc_amount = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.fycAmount,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="grade_commission_rate = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.gradeCommissionRate,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="share_rate = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.shareRate,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="referral_rate = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.referralRate,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="referral_amount = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.referralAmount,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="month_period = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.monthPeriod,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="commission_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.commissionType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="drop_option_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.dropOptionCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="practitioner_level = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.practitionerLevel,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="is_tax = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.isTax,jdbcType=INTEGER}
        </foreach>
      </trim>
      <trim prefix="tax_amount = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.taxAmount,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="net_amount = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.netAmount,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="campaign_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.campaignId,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="campaign_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.campaignName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="withdrawable_date = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.withdrawableDate,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="payout_batch_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.payoutBatchId,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="commission_payout_status = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.commissionPayoutStatus,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="commission_payout_at = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.commissionPayoutAt,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="commission_payout_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.commissionPayoutBy,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="status = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.status,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="predict_month_period = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.predictMonthPeriod,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="withdrawed_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.withdrawedId,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="fortune_payed_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.fortunePayedId,jdbcType=BIGINT}
        </foreach>
      </trim>
      <trim prefix="created_at = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.createdAt,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="created_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.createdBy,jdbcType=BIGINT}
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=BIGINT}
    </foreach>
  </update>
  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update ag_acl_customer_fortune
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="share_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.shareId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.shareId,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="customer_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.customerId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.customerId,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="order_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.orderId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.orderId,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="order_date = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.orderDate != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.orderDate,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="order_price = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.orderPrice != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.orderPrice,jdbcType=DECIMAL}
          </if>
        </foreach>
      </trim>
      <trim prefix="commission_rate = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.commissionRate != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.commissionRate,jdbcType=DECIMAL}
          </if>
        </foreach>
      </trim>
      <trim prefix="commission_amount = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.commissionAmount != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.commissionAmount,jdbcType=DECIMAL}
          </if>
        </foreach>
      </trim>
      <trim prefix="fyc_rate = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.fycRate != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.fycRate,jdbcType=DECIMAL}
          </if>
        </foreach>
      </trim>
      <trim prefix="fyc_amount = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.fycAmount != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.fycAmount,jdbcType=DECIMAL}
          </if>
        </foreach>
      </trim>
      <trim prefix="grade_commission_rate = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.gradeCommissionRate != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.gradeCommissionRate,jdbcType=DECIMAL}
          </if>
        </foreach>
      </trim>
      <trim prefix="share_rate = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.shareRate != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.shareRate,jdbcType=DECIMAL}
          </if>
        </foreach>
      </trim>
      <trim prefix="referral_rate = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.referralRate != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.referralRate,jdbcType=DECIMAL}
          </if>
        </foreach>
      </trim>
      <trim prefix="referral_amount = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.referralAmount != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.referralAmount,jdbcType=DECIMAL}
          </if>
        </foreach>
      </trim>
      <trim prefix="month_period = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.monthPeriod != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.monthPeriod,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="commission_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.commissionType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.commissionType,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="drop_option_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.dropOptionCode != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.dropOptionCode,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="practitioner_level = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.practitionerLevel != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.practitionerLevel,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="is_tax = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.isTax != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.isTax,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="tax_amount = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.taxAmount != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.taxAmount,jdbcType=DECIMAL}
          </if>
        </foreach>
      </trim>
      <trim prefix="net_amount = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.netAmount != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.netAmount,jdbcType=DECIMAL}
          </if>
        </foreach>
      </trim>
      <trim prefix="campaign_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.campaignId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.campaignId,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="campaign_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.campaignName != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.campaignName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="withdrawable_date = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.withdrawableDate != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.withdrawableDate,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="payout_batch_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.payoutBatchId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.payoutBatchId,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="commission_payout_status = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.commissionPayoutStatus != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.commissionPayoutStatus,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="commission_payout_at = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.commissionPayoutAt != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.commissionPayoutAt,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="commission_payout_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.commissionPayoutBy != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.commissionPayoutBy,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="withdrawed_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.withdrawedId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.withdrawedId,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="fortune_payed_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.fortunePayedId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.fortunePayedId,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="created_at = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.createdAt != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.createdAt,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="created_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.createdBy != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.createdBy,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=BIGINT}
    </foreach>
  </update>
  <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ag_acl_customer_fortune
    (share_id, customer_id, order_id, order_date, order_price, commission_rate, commission_amount, 
      fyc_rate, fyc_amount, grade_commission_rate, share_rate, referral_rate, referral_amount, 
      month_period, commission_type, drop_option_code, practitioner_level, is_tax, tax_amount, 
      net_amount, campaign_id, campaign_name, withdrawable_date, payout_batch_id, commission_payout_status, 
      commission_payout_at, commission_payout_by, withdrawed_id, fortune_payed_id, created_at, 
      created_by)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.shareId,jdbcType=BIGINT}, #{item.customerId,jdbcType=BIGINT}, #{item.orderId,jdbcType=BIGINT}, 
        #{item.orderDate,jdbcType=TIMESTAMP}, #{item.orderPrice,jdbcType=DECIMAL}, #{item.commissionRate,jdbcType=DECIMAL}, 
        #{item.commissionAmount,jdbcType=DECIMAL}, #{item.fycRate,jdbcType=DECIMAL}, #{item.fycAmount,jdbcType=DECIMAL}, 
        #{item.gradeCommissionRate,jdbcType=DECIMAL}, #{item.shareRate,jdbcType=DECIMAL}, 
        #{item.referralRate,jdbcType=DECIMAL}, #{item.referralAmount,jdbcType=DECIMAL}, 
        #{item.monthPeriod,jdbcType=VARCHAR}, #{item.commissionType,jdbcType=VARCHAR}, 
        #{item.dropOptionCode,jdbcType=VARCHAR}, #{item.practitionerLevel,jdbcType=VARCHAR}, 
        #{item.isTax,jdbcType=INTEGER}, #{item.taxAmount,jdbcType=DECIMAL}, #{item.netAmount,jdbcType=DECIMAL}, 
        #{item.campaignId,jdbcType=BIGINT}, #{item.campaignName,jdbcType=VARCHAR}, #{item.withdrawableDate,jdbcType=TIMESTAMP}, 
        #{item.payoutBatchId,jdbcType=BIGINT}, #{item.commissionPayoutStatus,jdbcType=VARCHAR}, 
        #{item.commissionPayoutAt,jdbcType=TIMESTAMP}, #{item.commissionPayoutBy,jdbcType=BIGINT}, 
        #{item.withdrawedId,jdbcType=BIGINT}, #{item.fortunePayedId,jdbcType=BIGINT}, #{item.createdAt,jdbcType=TIMESTAMP}, 
        #{item.createdBy,jdbcType=BIGINT})
    </foreach>
  </insert>

    <select id="findBySubordinateSystemStatistics" resultType="com.yd.api.practitioner.vo.rank.AclCustomerFortuneStatistics">
      SELECT
        f.customer_id  customerId ,
        p.id practitionerId ,
        p.`name` name ,
        p.subordinate_system_id subordinateSystemId ,
        ifnull(COUNT(f.id),0) count ,
        ifnull(SUM(f.order_price),0)  FYP ,
        ifnull(SUM(f.fyc_amount),0) FYC  ,
        s.practitioner_level practitionerLevelId
      FROM
        ((ag_acl_practitioner_setting s LEFT JOIN ag_acl_practitioner p ON s.practitioner_id = p.id)
          INNER JOIN (select t.* from ag_acl_customer_fortune t where t.drop_option_code = 'S01' group by t.order_id ) f ON f.customer_id = p.customer_id)
          INNER JOIN ag_po_order o ON f.order_id = o.id
      WHERE
        o.status = 3 and o.order_price &gt; 0
      <choose>
        <when test="time == 1">
          and DATE_FORMAT(f.order_date, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
        </when>
        <when test="time == 3">
          and QUARTER(f.order_date) = QUARTER(NOW()) AND year(f.order_date)=year(now())
        </when>
        <otherwise>
          and YEAR(f.order_date) = YEAR(now())
        </otherwise>
      </choose>
        AND p.subordinate_system_id = #{subordinateSystemId,jdbcType=BIGINT}
      GROUP BY f.customer_id
    </select>

  <select id="findByIds" parameterType="arraylist" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ag_acl_customer_fortune
    where id in
    <foreach close=")" collection="array" index="index" item="item" open="(" separator=",">
                #{item}
    </foreach>
  </select>

  <select id="findByWithdrawIds" parameterType="list" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ag_acl_customer_fortune
    where withdrawed_id in
    <foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
      #{item}
    </foreach>
  </select>

  <select id="queryLifeFortuneListByOrderIds" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from  ag_acl_customer_fortune f
    left join (select p.customer_id p_customer_id, s.practitioner_type_id from ag_acl_practitioner p left join ag_acl_practitioner_setting s on p.id = s.practitioner_id) p
    on f.customer_id = p.p_customer_id
    where 1=1
    and p.practitioner_type_id = 28
    and f.order_id in
    <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
      #{item}
    </foreach>
  </select>

  <select id="findByOrderId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ag_acl_customer_fortune f
    where  f.order_id = #{orderId}
  </select>

    <select id="findBypractitionerIds" resultType="com.yd.api.practitioner.vo.rank.AclCustomerFortuneStatistics">
      SELECT
        f.customer_id  customerId ,
        p.id practitionerId ,
        p.`name` name ,
        p.subordinate_system_id subordinateSystemId ,
        ifnull(COUNT(f.id),0) count ,
        ifnull(SUM(f.order_price),0)  FYP ,
        ifnull(SUM(f.fyc_amount),0) FYC  ,
        s.practitioner_level practitionerLevelId
      FROM
      ((ag_acl_practitioner_setting s LEFT JOIN ag_acl_practitioner p ON s.practitioner_id = p.id)
      INNER JOIN ag_acl_customer_fortune f ON f.customer_id = p.customer_id and f.drop_option_code in('S01','C01') )
      INNER JOIN ag_po_order o ON f.order_id = o.id
      WHERE
      o.status = 3 and o.payment_status = 3 and o.order_price &gt; 0
      <choose>
        <when test="time == 1">
          and DATE_FORMAT(f.order_date, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
        </when>
        <when test="time == 3">
          and QUARTER(f.order_date) = QUARTER(NOW()) AND year(f.order_date)=year(now())
        </when>
        <when test="time == 4">
          and YEAR(f.order_date) = YEAR(now())-1
        </when>
        <otherwise>
          and YEAR(f.order_date) = YEAR(now())
        </otherwise>
      </choose>
      and p.id in
      <foreach collection="list" item="practitionerId" index="index" open="(" close=")" separator=",">
        #{practitionerId,jdbcType=BIGINT}
      </foreach>
      GROUP BY f.customer_id
    </select>
    
    <select id="findTargetBypractitionerIds" resultType="com.yd.api.practitioner.vo.rank.AclCustomerFortuneStatistics">
	  select ifnull(sum(t.commission),0) targetFyc,
		     ifnull(sum(t.premium),0) targetFyp,
	 		 ifnull(sum(t.pieces),0) targetCount,
	 	     t.practitioner_id practitionerId 
	  from ag_mkt_leads_goals t where t.goals_type=1 and t.is_active=1
	      <choose>
	        <when test="time == 1">
	        	and t.statistic_time_unit=3
	            and t.current_year=year(now())
	            and t.seq_time=month(now())
	        </when>
	        <when test="time == 3">
	        	and t.statistic_time_unit=3
	            and t.current_year=year(now())
          		and quarter(concat(t.current_year,'-',t.seq_time,'-01'))=quarter(now())
	        </when>
	        <when test="time == 4">
	        	and t.statistic_time_unit=1
	            and t.current_year=year(now())-1
	        </when>
	        <otherwise>
	        	and t.statistic_time_unit=1
	            and t.current_year=year(now())
	        </otherwise>
	      </choose>
      and t.practitioner_id in
      <foreach collection="list" item="practitionerId" index="index" open="(" close=")" separator=",">
        #{practitionerId,jdbcType=BIGINT}
      </foreach>
      group by t.practitioner_id
    </select>

  <select id="queryLifeFortuneListByOrderId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from  ag_acl_customer_fortune f
    left join (select p.customer_id p_customer_id, s.practitioner_type_id from ag_acl_practitioner p left join ag_acl_practitioner_setting s on p.id = s.practitioner_id) p
    on f.customer_id = p.p_customer_id
    where 1=1
    and p.practitioner_type_id = 28
    and f.order_id = #{orderId,jdbcType=BIGINT}
  </select>

  <select id="queryLifeFortuneListByCommissionId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from  ag_acl_customer_fortune f
    where 1=1
    and f.commission_id = #{commissionId,jdbcType=BIGINT}
  </select>
</mapper>