package cn.pluss.platform.vo;

import cn.pluss.platform.entity.MerchantOrderStatistics;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author djh
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class MerchantOrderStatisticsVO extends MerchantOrderStatistics {

    /**
     * 万
     */
    public static final BigDecimal TEN_THOUSAND = BigDecimal.valueOf(10000L);

    /**
     * 千万
     */
    public static final BigDecimal HUNDRED_THOUSAND = BigDecimal.valueOf(10000000L);

    /**
     * 百万
     */
    public static final BigDecimal MILLION = BigDecimal.valueOf(1000000L);

    /**
     * 百亿
     */
    public static final BigDecimal HUNDRED_BILLION = BigDecimal.valueOf(10000000000L);

    /**
     * 直推月交易总量
     */
    private String directMonthTotalFee;

    public void setDirectMonthTotalFee(BigDecimal directMonthTotalFee) {
        // 过百亿，用百万做单位
        if (directMonthTotalFee.compareTo(HUNDRED_BILLION) > 0) {
            this.directMonthTotalFee = directMonthTotalFee.divide(MILLION, RoundingMode.HALF_UP).setScale(3, RoundingMode.HALF_UP).toPlainString() + " 百万";
            return;
        }

        // 过千万，用万做单位
        if (directMonthTotalFee.compareTo(HUNDRED_THOUSAND) > 0) {
            this.directMonthTotalFee = directMonthTotalFee.divide(TEN_THOUSAND, RoundingMode.HALF_UP).setScale(3, RoundingMode.HALF_UP).toPlainString() + " 万";
            return;
        }


        this.directMonthTotalFee = directMonthTotalFee.setScale(2, RoundingMode.HALF_UP).toPlainString();
    }

    /**
     * 团队月交易总量
     */
    private String teamMonthTotalFee;

    public void setTeamMonthTotalFee(BigDecimal teamMonthTotalFee) {
        // 过百亿，用百万做单位
        if (teamMonthTotalFee.compareTo(HUNDRED_BILLION) > 0) {
            this.teamMonthTotalFee = teamMonthTotalFee.divide(MILLION, RoundingMode.HALF_UP).setScale(3, RoundingMode.HALF_UP).toPlainString() + " 百万";
            return;
        }

        // 过千万，用万做单位
        if (teamMonthTotalFee.compareTo(HUNDRED_THOUSAND) > 0) {
            this.teamMonthTotalFee = teamMonthTotalFee.divide(TEN_THOUSAND, RoundingMode.HALF_UP).setScale(3, RoundingMode.HALF_UP).toPlainString() + " 万";
            return;
        }


        this.teamMonthTotalFee = teamMonthTotalFee.setScale(2, RoundingMode.HALF_UP).toPlainString();
    }

    /**
     * 直推交易总量
     */
    private String directTotalFee;

    public void setDirectTotalFee(BigDecimal directTotalFee) {
        // 过百亿，用百万做单位
        if (directTotalFee.compareTo(HUNDRED_BILLION) > 0) {
            this.directTotalFee = directTotalFee.divide(MILLION, RoundingMode.HALF_UP).setScale(3, RoundingMode.HALF_UP).toPlainString() + " 百万";
            return;
        }

        // 过千万，用万做单位
        if (directTotalFee.compareTo(HUNDRED_THOUSAND) > 0) {
            this.directTotalFee = directTotalFee.divide(TEN_THOUSAND, RoundingMode.HALF_UP).setScale(3, RoundingMode.HALF_UP).toPlainString() + " 万";
            return;
        }


        this.directTotalFee = directTotalFee.setScale(2, RoundingMode.HALF_UP).toPlainString();
    }

    /**
     * 团队交易总量
     */
    private String teamTotalFee;

    public void setTeamTotalFee(BigDecimal teamTotalFee) {
        // 过百亿，用百万做单位
        if (teamTotalFee.compareTo(HUNDRED_BILLION) > 0) {
            this.teamTotalFee = teamTotalFee.divide(MILLION, RoundingMode.HALF_UP).setScale(3, RoundingMode.HALF_UP).toPlainString() + " 百万";
            return;
        }

        // 过千万，用万做单位
        if (teamTotalFee.compareTo(HUNDRED_THOUSAND) > 0) {
            this.teamTotalFee = teamTotalFee.divide(TEN_THOUSAND, RoundingMode.HALF_UP).setScale(3, RoundingMode.HALF_UP).toPlainString() + " 万";
            return;
        }


        this.teamTotalFee = teamTotalFee.setScale(2, RoundingMode.HALF_UP).toPlainString();
    }

    /**
     * (直推 + 团队) 月总交易笔数
     */
    private String monthCount;
}
