package com.slodon.b2b2c.vo.statistics;

import com.slodon.b2b2c.statistics.pojo.base.PlatformBase;
import com.slodon.b2b2c.statistics.pojo.base.StoreBase;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

/**
 *
 * 封装商品动销-商品总览Vo对象
 * @author wuxy
 */
@Data
@NoArgsConstructor
public class GoodsOverviewVO {

    @ApiModelProperty("动销商品数")
    private Integer movableGoodsNum;

    @ApiModelProperty("上期动销商品数")
    private Integer preMovableGoodsNum;

    @ApiModelProperty("较上期动销商品")
    private String preMovableGoods;

    @ApiModelProperty("新增商品数")
    private Integer newGoodsNum;

    @ApiModelProperty("上期新增商品数")
    private Integer preNewGoodsNum;

    @ApiModelProperty("较上期新增商品")
    private String preNewGoods;

    @ApiModelProperty("新增品牌数")
    private Integer newBrandNum;

    @ApiModelProperty("上期新增品牌数")
    private Integer preNewBrandNum;

    @ApiModelProperty("较上期新增品牌")
    private String preNewBrand;

    @ApiModelProperty("支付金额")
    private BigDecimal orderPayAmount;

    @ApiModelProperty("上期支付金额")
    private BigDecimal preOrderPayAmount;

    @ApiModelProperty("较上期支付")
    private String preOrderPay;

    @ApiModelProperty("下单数")
    private Integer orderSubmitNum;

    @ApiModelProperty("上期下单数")
    private Integer preOrderSubmitNum;

    @ApiModelProperty("较上期下单")
    private String preOrderSubmit;

    public GoodsOverviewVO(PlatformBase platformBase, PlatformBase previousData) {
        this.movableGoodsNum = platformBase.getSalingGoodsNum();
        this.newGoodsNum = platformBase.getNewGoodsNum();
        this.newBrandNum = platformBase.getNewBrandNum();
        if (previousData != null) {
            this.preMovableGoodsNum = previousData.getSalingGoodsNum();
            this.preMovableGoods = dealPreMovableGoods(platformBase.getSalingGoodsNum(), previousData.getSalingGoodsNum());
            this.preNewGoodsNum = previousData.getNewGoodsNum();
            this.preNewGoods = dealPreNewGoods(platformBase.getNewGoodsNum(), previousData.getNewGoodsNum());
            this.preNewBrandNum = previousData.getNewBrandNum();
            this.preNewBrand = dealPreNewBrand(platformBase.getNewBrandNum(), previousData.getNewBrandNum());
        }
    }

    public GoodsOverviewVO(StoreBase storeBase, StoreBase previousData) {
        this.movableGoodsNum = storeBase.getSalingGoodsNum();
        this.newGoodsNum = storeBase.getNewGoodsNum();
        this.newBrandNum = storeBase.getNewBrandNum();
        this.orderPayAmount = storeBase.getOrderPayAmount();
        this.orderSubmitNum = storeBase.getOrderSubmitNum();
        if (previousData != null) {
            this.preMovableGoodsNum = previousData.getSalingGoodsNum();
            this.preMovableGoods = dealPreMovableGoods(storeBase.getSalingGoodsNum(), previousData.getSalingGoodsNum());
            this.preNewGoodsNum = previousData.getNewGoodsNum();
            this.preNewGoods = dealPreNewGoods(storeBase.getNewGoodsNum(), previousData.getNewGoodsNum());
            this.preOrderPayAmount = previousData.getOrderPayAmount();
            this.preOrderPay = dealPreOrderPay(storeBase.getOrderPayAmount(), previousData.getOrderPayAmount());
            this.preOrderSubmitNum = previousData.getOrderSubmitNum();
            this.preOrderSubmit = dealPreOrderSubmit(storeBase.getOrderSubmitNum(), previousData.getOrderSubmitNum());
        }
    }

    public static String dealPreMovableGoods(Integer movableGoodsNum, Integer preMovableGoodsNum) {
        if (preMovableGoodsNum == 0) return "0.00%";
        return (new BigDecimal(movableGoodsNum).subtract(new BigDecimal(preMovableGoodsNum))).multiply(new BigDecimal(100))
                .divide(new BigDecimal(preMovableGoodsNum), 2, BigDecimal.ROUND_HALF_UP) + "%";
    }

    public static String dealPreNewGoods(Integer newGoodsNum, Integer preNewGoodsNum) {
        if (preNewGoodsNum == 0) return "0.00%";
        return (new BigDecimal(newGoodsNum).subtract(new BigDecimal(preNewGoodsNum))).multiply(new BigDecimal(100))
                .divide(new BigDecimal(preNewGoodsNum), 2, BigDecimal.ROUND_HALF_UP) + "%";
    }

    public static String dealPreNewBrand(Integer newBrandNum, Integer preNewBrandNum) {
        if (preNewBrandNum == 0) return "0.00%";
        return (new BigDecimal(newBrandNum).subtract(new BigDecimal(preNewBrandNum))).multiply(new BigDecimal(100))
                .divide(new BigDecimal(preNewBrandNum), 2, BigDecimal.ROUND_HALF_UP) + "%";
    }

    public static String dealPreOrderPay(BigDecimal orderPayAmount, BigDecimal preOrderPayAmount) {
        if (preOrderPayAmount.compareTo(BigDecimal.ZERO) == 0) return "0.00%";
        return (orderPayAmount.subtract(preOrderPayAmount)).multiply(new BigDecimal(100))
                .divide(preOrderPayAmount, 2, BigDecimal.ROUND_HALF_UP) + "%";
    }

    public static String dealPreOrderSubmit(Integer orderSubmitNum, Integer preOrderSubmitNum) {
        if (preOrderSubmitNum == 0) return "0.00%";
        return (new BigDecimal(orderSubmitNum).subtract(new BigDecimal(preOrderSubmitNum))).multiply(new BigDecimal(100))
                .divide(new BigDecimal(preOrderSubmitNum), 2, BigDecimal.ROUND_HALF_UP) + "%";
    }
}
