package com.slodon.b2b2c.vo.goods;

import com.slodon.b2b2c.core.util.FileUrlUtil;
import com.slodon.b2b2c.goods.pojo.Goods;
import com.slodon.b2b2c.goods.pojo.GoodsBindRank;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.Date;

/**
 *
 * 封装榜单商品VO对象
 * @author wuxy
 */
@NoArgsConstructor
@Data
public class RankGoodsVO {

    @ApiModelProperty("商品ID")
    private Long goodsId;

    @ApiModelProperty("商品名称")
    private String goodsName;

    @ApiModelProperty("品牌ID")
    private Integer brandId;

    @ApiModelProperty("品牌名称")
    private String brandName;

    @ApiModelProperty("商品所属分类")
    private String categoryPath;

    @ApiModelProperty("销售价格")
    private BigDecimal goodsPrice;

    @ApiModelProperty("商品库存")
    private Integer goodsStock;

    @ApiModelProperty("商家ID")
    private Long storeId;

    @ApiModelProperty("店铺名称")
    private String storeName;

    @ApiModelProperty("商品主图路径")
    private String goodsImage;

    @ApiModelProperty("发布时间")
    private Date createTime;

    @ApiModelProperty("榜单id")
    private Integer rankId;

    @ApiModelProperty("销量")
    private Integer saleNum;

    @ApiModelProperty("销售额")
    private BigDecimal saleAmount;

    @ApiModelProperty("好评数")
    private Integer highNum;

    @ApiModelProperty("好评率")
    private String highRate;

    @ApiModelProperty("上榜理由")
    private String rankReason;

    public RankGoodsVO(Goods goods, GoodsBindRank goodsBindRank) {
        this.goodsId = goods.getGoodsId();
        this.goodsName = goods.getGoodsName();
        this.brandId = goods.getBrandId();
        this.brandName = goods.getBrandName();
        this.categoryPath = goods.getCategoryPath();
        this.goodsPrice = goods.getGoodsPrice();
        this.goodsStock = goods.getGoodsStock();
        this.storeId = goods.getStoreId();
        this.storeName = goods.getStoreName();
        this.goodsImage = FileUrlUtil.getFileUrl(goods.getMainImage(), null);
        this.createTime = goods.getCreateTime();
        if (goodsBindRank != null) {
            this.rankId = goodsBindRank.getRankId();
            this.saleNum = StringUtils.isEmpty(goodsBindRank.getSaleNum()) ? goods.getActualSales() + goods.getVirtualSales() : goodsBindRank.getSaleNum();
            this.saleAmount = goodsBindRank.getSaleAmount();
            this.highNum = goodsBindRank.getHighNum();
            this.highRate = goodsBindRank.getHighRate();
            this.rankReason = goodsBindRank.getRankReason();
        } else {
            this.saleNum = goods.getActualSales() + goods.getVirtualSales();
        }
    }
}
