package com.zm.order.tool.server.model;

import com.alibaba.fastjson.JSON;
import com.aliyun.openservices.shade.org.apache.commons.lang3.builder.DiffBuilder;
import com.aliyun.openservices.shade.org.apache.commons.lang3.builder.DiffResult;
import com.aliyun.openservices.shade.org.apache.commons.lang3.builder.Diffable;
import com.aliyun.openservices.shade.org.apache.commons.lang3.builder.ToStringStyle;
import com.google.common.collect.Maps;
import org.springframework.util.StringUtils;

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

/**
 * 
 *
 * @author mybatis-generator
 * @date   2019/10/28
 */
public class OrderItem implements Diffable<OrderItem> {


    /**
     * 主键
     */
    private Long id;

    /**
     * 业务类型
     */
    private Integer bizType;

    /**
     * 订单号
     */
    private String orderNo;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 商品id
     */
    private String itemId;

    /**
     * 商品名称
     */
    private String itemName;

    /**
     * 商品图片
     */
    private String itemImage;

    /**
     * 商品规格
     */
    private String itemSpec;

    /**
     * 商品单位
     */
    private String itemUnit;

    /**
     * 商品条码
     */
    private String itemBarcode;

    /**
     * 商品标识
     */
    private String itemSign;

    /**
     * 品牌标识
     */
    private String brandSign;

    /**
     * 市场价
     */
    private Integer marketPrice;

    /**
     * 成本价
     */
    private Integer costPrice;

    /**
     * 会员价
     */
    private Integer memberPrice;

    /**
     * 成交价
     */
    private Integer itemPrice;

    /**
     * 数量
     */
    private BigDecimal num;

    /**
     * 优惠金额
     */
    private Integer discountAmount;

    /**
     * 包装费
     */
    private Integer packAmount;

    /**
     * 实付金额
     */
    private Integer paidAmount;

    /**
     * f码
     */
    private String fCode;

    /**
     * 状态
     */
    private Integer status;

    /**
     * 扩展信息 json
     */
    private String features;

    /**
     * 扩展信息 map
     */
    private Map<String, Object> extraMap;

    /**
     * 创建时间
     */
    private Date createdAt;

    /**
     * 修改时间
     */
    private Date updatedAt;

    /**
     * 删除标识
     */
    private Integer isDeleted;


    /**
     * spuId
     */
    private Long goodsId;

    /**
     * 活动id
     */
    private Long activityId;

    /**
     * 限时活动
     */
    private Integer isTimeDiscount;

    /**
     * 加菜时间
     */
    private Date orderAt ;

    /**
     * 条码
     */
    private String productNo;

    /**
     * 是否赠品
     */
    private Integer isGift;

    /**
     * 商家id
     */
    private Long sellerId;

    /**
     * 来源id
     */
    private String sourceId;

    /**
     * 单个商品行下，商家实收金额 单位：分',
     */
    private Integer incomeAmount;

    /**
     * 单个商品行下，商家承担金额 单位：分',
     */
    private Integer sellerBearAmount;

    /**
     * 单个商品行下，商家承担的手续费/服务费 单位：分
     */
    private Integer commissionAmount;

    /**
     * 商品类型
     * 0:普通商品 1:套餐商品 2:套餐子商品
     */
    private Integer itemType;

    /**
     * 归属商品ID
     */
    private Long ownerId;

    /**
     * 加料信息
     */
    private String batchingInfo;

    public Integer getIncomeAmount() {
        return incomeAmount;
    }

    public void setIncomeAmount(Integer incomeAmount) {
        this.incomeAmount = incomeAmount;
    }

    public Integer getSellerBearAmount() {
        return sellerBearAmount;
    }

    public void setSellerBearAmount(Integer sellerBearAmount) {
        this.sellerBearAmount = sellerBearAmount;
    }

    public Integer getCommissionAmount() {
        return commissionAmount;
    }

    public void setCommissionAmount(Integer commissionAmount) {
        this.commissionAmount = commissionAmount;
    }

    public String getBatchingInfo() {
        return batchingInfo;
    }

    public void setBatchingInfo(String batchingInfo) {
        this.batchingInfo = batchingInfo;
    }

    public Integer getItemType() {
        return itemType;
    }

    public void setItemType(Integer itemType) {
        this.itemType = itemType;
    }

    public Long getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(Long ownerId) {
        this.ownerId = ownerId;
    }

    public String getSourceId() {
        return sourceId;
    }

    public void setSourceId(String sourceId) {
        this.sourceId = sourceId;
    }

    public Integer getBizType() {
        return bizType;
    }

    public void setBizType(Integer bizType) {
        this.bizType = bizType;
    }

    public Date getOrderAt() {
        return orderAt;
    }

    public void setOrderAt(Date orderAt) {
        this.orderAt = orderAt;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getItemId() {
        return itemId;
    }

    public void setItemId(String itemId) {
        this.itemId = itemId;
    }

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public String getItemImage() {
        return itemImage;
    }

    public void setItemImage(String itemImage) {
        this.itemImage = itemImage;
    }

    public String getItemSpec() {
        return itemSpec;
    }

    public void setItemSpec(String itemSpec) {
        this.itemSpec = itemSpec;
    }

    public Integer getPaidAmount() {
        return paidAmount;
    }

    public void setPaidAmount(Integer paidAmount) {
        this.paidAmount = paidAmount;
    }

    public String getItemUnit() {
        return itemUnit;
    }

    public void setItemUnit(String itemUnit) {
        this.itemUnit = itemUnit;
    }

    public String getItemBarcode() {
        return itemBarcode;
    }

    public void setItemBarcode(String itemBarcode) {
        this.itemBarcode = itemBarcode;
    }

    public String getItemSign() {
        return itemSign;
    }

    public void setItemSign(String itemSign) {
        this.itemSign = itemSign;
    }

    public String getBrandSign() {
        return brandSign;
    }

    public void setBrandSign(String brandSign) {
        this.brandSign = brandSign;
    }

    public Integer getMarketPrice() {
        return marketPrice;
    }

    public void setMarketPrice(Integer marketPrice) {
        this.marketPrice = marketPrice;
    }

    public Integer getCostPrice() {
        return costPrice;
    }

    public void setCostPrice(Integer costPrice) {
        this.costPrice = costPrice;
    }

    public Integer getMemberPrice() {
        return memberPrice;
    }

    public void setMemberPrice(Integer memberPrice) {
        this.memberPrice = memberPrice;
    }

    public Long getSellerId() {
        return sellerId;
    }

    public void setSellerId(Long sellerId) {
        this.sellerId = sellerId;
    }

    public Integer getItemPrice() {
        return itemPrice;
    }

    public void setItemPrice(Integer itemPrice) {
        this.itemPrice = itemPrice;
    }

    public String getProductNo() {
        return productNo;
    }

    public void setProductNo(String productNo) {
        this.productNo = productNo;
    }

    public Integer getIsGift() {
        return isGift;
    }

    public void setIsGift(Integer isGift) {
        this.isGift = isGift;
    }

    public BigDecimal getNum() {
        return num;
    }

    public void setNum(BigDecimal num) {
        this.num = num;
    }

    public Integer getPackAmount() {
        return packAmount;
    }

    public void setPackAmount(Integer packAmount) {
        this.packAmount = packAmount;
    }

    public Integer getDiscountAmount() {
        return discountAmount;
    }

    public void setDiscountAmount(Integer discountAmount) {
        this.discountAmount = discountAmount;
    }

    public String getfCode() {
        return fCode;
    }

    public void setfCode(String fCode) {
        this.fCode = fCode;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getFeatures() {
        return features;
    }

    public void setFeatures(String features) {
        this.features = features;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public Integer getIsDeleted() {
        return isDeleted;
    }

    public void setIsDeleted(Integer isDeleted) {
        this.isDeleted = isDeleted;
    }

    public Long getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Long goodsId) {
        this.goodsId = goodsId;
    }

    public Long getActivityId() {
        return activityId;
    }

    public void setActivityId(Long activityId) {
        this.activityId = activityId;
    }

    public Integer getIsTimeDiscount() {
        return isTimeDiscount;
    }

    public void setIsTimeDiscount(Integer isTimeDiscount) {
        this.isTimeDiscount = isTimeDiscount;
    }

    public Map<String, Object> getExtraMap() {
        if (!StringUtils.isEmpty(features)) {
            Map<String, Object> extra = JSON.parseObject(features, Map.class);
            return extra;
        }
        return Maps.newHashMap();
    }

    public void setExtraMap(Map<String, Object> extraMap) {
        if (Objects.nonNull(extraMap) && !extraMap.isEmpty()) {
            this.features = JSON.toJSONString(extraMap);
        }
        this.extraMap = extraMap;
    }

    @Override
    public DiffResult diff(OrderItem obj) {
        return new DiffBuilder(this, obj, ToStringStyle.JSON_STYLE)
                .append("itemId", this.itemId, obj.itemId)
                .append("itemName", this.itemName, obj.itemName)
                .append("itemImage", this.itemImage, obj.itemImage)
                .append("itemSpec", this.itemSpec, obj.itemSpec)
                .append("itemUnit", this.itemUnit, obj.itemUnit)
                .append("itemBarcode", this.itemBarcode, obj.itemBarcode)
                .append("itemSign", this.itemSign, obj.itemSign)
                .append("goodsId", this.goodsId, obj.goodsId)
                .append("activityId", this.activityId, obj.activityId)
                .append("isTimeDiscount", this.isTimeDiscount, obj.isTimeDiscount)
                .append("brandSign", this.brandSign, obj.brandSign)
                .append("marketPrice", this.marketPrice, obj.marketPrice)
                .append("costPrice", this.costPrice, obj.costPrice)
                .append("memberPrice", this.memberPrice, obj.memberPrice)
                .append("itemPrice", this.itemPrice, obj.itemPrice)
                .append("num", this.num.stripTrailingZeros().toPlainString(), obj.num.stripTrailingZeros().toPlainString())
                .append("discountAmount", this.discountAmount, obj.discountAmount)
                .append("packAmount", this.packAmount, obj.packAmount)
                .append("fCode", this.fCode, obj.fCode)
                .append("status", this.status, obj.status)
                .append("orderAt", this.orderAt, obj.orderAt)
                .append("features", this.features, obj.features)
                .append("isGift", this.isGift, obj.isGift)
                .append("productNo", this.productNo, obj.productNo)
                .append("isDeleted", this.isDeleted, obj.isDeleted)
                .append("sourceId", this.sourceId, obj.sourceId)
                .append("itemType", this.itemType, obj.itemType)
                .append("ownerId", this.ownerId, obj.ownerId)
                .append("paidAmount", this.paidAmount, obj.paidAmount)
                .build();
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}