package com.slodon.b2b2c.vo.statistics;

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

import java.math.BigDecimal;

/**
 *
 * 封装店铺分析-店铺总览Vo对象
 * @author wuxy
 */
@NoArgsConstructor
@Data
public class StoreOverviewVO {

    @ApiModelProperty("新增店铺数")
    private Integer newStoreNum;

    @ApiModelProperty("上期新增店铺数")
    private Integer preNewStoreNum;

    @ApiModelProperty("较上期新增店铺")
    private String preNewStore;

    @ApiModelProperty("访客数")
    private Integer visitorNum;

    @ApiModelProperty("上期访客数")
    private Integer preVisitorNum;

    @ApiModelProperty("较上期访客")
    private String preVisitor;

    @ApiModelProperty("浏览量")
    private Integer viewNum;

    @ApiModelProperty("上期浏览量")
    private Integer preViewNum;

    @ApiModelProperty("较上期浏览量")
    private String preView;

    public StoreOverviewVO(PlatformBase platformBase, PlatformBase previousData) {
        this.newStoreNum = platformBase.getNewStoreNum();
        this.visitorNum = platformBase.getVisitorNum();
        this.viewNum = platformBase.getViewNum();
        if (previousData != null) {
            this.preNewStoreNum = previousData.getNewStoreNum();
            this.preNewStore = dealPreNewStoreNum(platformBase.getNewStoreNum(), previousData.getNewStoreNum());
            this.preVisitorNum = previousData.getVisitorNum();
            this.preVisitor = dealPreVisitorNum(platformBase.getVisitorNum(), previousData.getVisitorNum());
            this.preViewNum = previousData.getViewNum();
            this.preView = dealPreViewNum(platformBase.getViewNum(), previousData.getViewNum());
        }
    }

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

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

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