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

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.zm.order.tool.server.enums.SyncFlagEnum;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author mybatis-generator
 * @date 2019/10/28
 */
public class Order {

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

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

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

    /**
     * 订单类型
     */
    private Integer orderType;

    /**
     * 订单子类型
     */
    private Integer orderSubType;

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

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

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

    public Long getNewUserId() {
        return newUserId;
    }

    public void setNewUserId(Long newUserId) {
        this.newUserId = newUserId;
    }

    public Long getNewSellerId() {
        return newSellerId;
    }

    public void setNewSellerId(Long newSellerId) {
        this.newSellerId = newSellerId;
    }

    /**
     * 门店id
     */
    private Long storeId;

    /**
     * 店内单号
     */
    private String storeOrderNo;

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

    /**
     * 联系方式
     */
    private String mobile;

    /**
     * 地址id
     */
    private Integer addrId;

    /**
     * 订单来源
     */
    private Integer source;

    /**
     * 来源单号
     */
    private String sourceNo;

    /**
     * 来源系统
     */
    private Integer fromSystem;

    /**
     * 来源信息
     */
    private String sourceInfo;

    /**
     * 订单总金额
     */
    private Integer totalAmount;

    /**
     * 成本总金额
     */
    private Integer costAmount;

    /**
     * 打包总金额
     */
    private Integer packAmount;

    /**
     * 商品总金额
     */
    private Integer itemAmount;

    /**
     * 运费总金额
     */
    private Integer freightAmount;

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

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

    /**
     * 支付金额
     */
    private Integer payAmount;

    /**
     * 找零金额
     */
    private Integer changeAmount;

    /**
     * 是否独立收款
     */
    private Integer isAlone;

    /**
     * 支付方式
     */
    private Integer payType;

    /**
     * 支付模式
     */
    private Integer payModel;

    /**
     * 付款人
     */
    private Long payer;

    /**
     * 支付单号
     */
    private String payNo;

    /**
     * 第三方支付单号
     */
    private String thirdPayNo;

    /**
     * 支付信息
     */
    private String payInfo;

    /**
     * 发票类型
     */
    private Integer invoiceType;

    /**
     * 履约类型
     */
    private Integer performanceType;

    /**
     * 履约平台
     */
    private String performancePlatform;

    /**
     * 是否立即履约
     */
    private Integer isImmediatePerformance;

    /**
     * 履约信息
     */
    private String performanceInfo;

    /**
     * 活动信息
     */
    private String activityInfo;

    /**
     * 商品信息
     */
    private String itemInfo;

    /**
     * 折扣信息
     */
    private String discountInfo;

    /**
     * 商家备注
     */
    private String sellerRemarks;

    /**
     * 买家备注
     */
    private String buyerRemarks;

    /**
     * 是否打印
     */
    private Integer isReceipt;

    /**
     * 打印终端
     */
    private String receiptTerminal;

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

    /**
     * 支付状态
     */
    private Integer payStatus;

    /**
     * 售后状态
     */
    private Integer afterSaleStatus;

    /**
     * 履约状态
     */
    private Integer performanceStatus;

    /**
     * 评价状态
     */
    private Integer commentStatus;

    /**
     * 接单状态
     */
    private Integer receiveStatus;

    /**
     * 拒单原因
     */
    private String refusalReason;

    /**
     * 下单时间
     */
    private Date orderAt;

    /**
     * 支付时间
     */
    private Date payAt;

    /**
     * 评价时间
     */
    private Date commentAt;

    /**
     * 完成时间
     */
    private Date completedAt;

    /**
     * 接单时间
     */
    private Date receiveAt;


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

    /**
     * 扩展信息
     */
    private String featuresCipher;

    /**
     * 扩展信息
     */
    private String performanceInfoCipher;

    public String getPerformanceInfoCipher() {
        return performanceInfoCipher;
    }

    public void setPerformanceInfoCipher(String performanceInfoCipher) {
        this.performanceInfoCipher = performanceInfoCipher;
    }

    public String getFeaturesCipher() {
        return featuresCipher;
    }

    public void setFeaturesCipher(String featuresCipher) {
        this.featuresCipher = featuresCipher;
    }

    /**
     * 扩展信息
     */
    private String newFeatures;

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

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

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

    /**
     * 同步标识
     */
    private Integer syncFlag = SyncFlagEnum.SYNC.getValue();

    /**
     * 版本号 用于乐观锁控制
     */
    private Integer version;

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

    /**
     * 业务子类型
     */
    private Integer bizSubType;

    /**
     * 支付标记
     */
    private Integer payFlag;

    /**
     * 支付明细
     */
    private String payDetailInfo;

    /**
     * 地址信息
     */
    private String addrInfo;

    private String mobileCipher;

    private Integer refundFlag;

    /**
     * 开票状态
     */
    private Integer invoiceStatus;

    /**
     * 订单子状态
     */
    private Integer subStatus;

    /**
     * 商品
     */
    private List<OrderItem> itemList;

    /**
     * 币种
     */
    private String currency;

    /**
     * 平台用户id
     */
    private Long platformUserId;

    /**
     * 主数据源标记
     */
    private Integer masterDataSource;

    /**
     * 商家实收金额 单位：分
     */
    private Integer incomeAmount;

    /**
     * 商家承担的金额 单位：分
     */
    private Integer sellerBearAmount;

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

    /**
     * 账单时间
     */
    private Date billAt;

    /**
     * 账单信息
     */
    private String billInfo;


    public String getBillInfo() {
        return billInfo;
    }

    public void setBillInfo(String billInfo) {
        this.billInfo = billInfo;
    }

    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 Date getBillAt() {
        return billAt;
    }

    public void setBillAt(Date billAt) {
        this.billAt = billAt;
    }

    public String getNewFeatures() {
        return newFeatures;
    }

    public void setNewFeatures(String newFeatures) {
        this.newFeatures = newFeatures;
    }

    public Integer getMasterDataSource() {
        return masterDataSource;
    }

    public void setMasterDataSource(Integer masterDataSource) {
        this.masterDataSource = masterDataSource;
    }

    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public Long getPlatformUserId() {
        return platformUserId;
    }

    public void setPlatformUserId(Long platformUserId) {
        this.platformUserId = platformUserId;
    }

    public String getMobileCipher() {
        return mobileCipher;
    }

    public void setMobileCipher(String mobileCipher) {
        this.mobileCipher = mobileCipher;
    }

    public List<OrderItem> getItemList() {
        return itemList;
    }

    public void setItemList(List<OrderItem> itemList) {
        this.itemList = itemList;
    }

    public Integer getSubStatus() {
        return subStatus;
    }

    public void setSubStatus(Integer subStatus) {
        this.subStatus = subStatus;
    }

    public Integer getInvoiceStatus() {
        return invoiceStatus;
    }

    public void setInvoiceStatus(Integer invoiceStatus) {
        this.invoiceStatus = invoiceStatus;
    }

    public Integer getRefundFlag() {
        return refundFlag;
    }

    public void setRefundFlag(Integer refundFlag) {
        this.refundFlag = refundFlag;
    }

    public String getAddrInfo() {
        return addrInfo;
    }

    public void setAddrInfo(String addrInfo) {
        this.addrInfo = addrInfo;
    }

    public String getPayDetailInfo() {
        return payDetailInfo;
    }

    public void setPayDetailInfo(String payDetailInfo) {
        this.payDetailInfo = payDetailInfo;
    }

    public Integer getPayFlag() {
        return payFlag;
    }

    public void setPayFlag(Integer payFlag) {
        this.payFlag = payFlag;
    }

    public Status currentStatus() {
        Status status = new Status();
        status.setBizType(this.bizType);
        status.setDocType(this.orderType);
        status.setStatus(this.status);
        return status;
    }

    public Integer getBizSubType() {
        return bizSubType;
    }

    public void setBizSubType(Integer bizSubType) {
        this.bizSubType = bizSubType;
    }

    public Long getId() {
        return id;
    }

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

    public Integer getBizType() {
        return bizType;
    }

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

    public String getOrderNo() {
        return orderNo;
    }

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

    public Integer getOrderType() {
        return orderType;
    }

    public void setOrderType(Integer orderType) {
        this.orderType = orderType;
    }

    public Integer getOrderSubType() {
        return orderSubType;
    }

    public void setOrderSubType(Integer orderSubType) {
        this.orderSubType = orderSubType;
    }

    public Long getSellerId() {
        return sellerId;
    }

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

    public Long getStoreId() {
        return storeId;
    }

    public void setStoreId(Long storeId) {
        this.storeId = storeId;
    }

    public String getStoreOrderNo() {
        return storeOrderNo;
    }

    public void setStoreOrderNo(String storeOrderNo) {
        this.storeOrderNo = storeOrderNo;
    }

    public Long getUserId() {
        return userId;
    }

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

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public Integer getSource() {
        return source;
    }

    public void setSource(Integer source) {
        this.source = source;
    }

    public String getSourceNo() {
        return sourceNo;
    }

    public void setSourceNo(String sourceNo) {
        this.sourceNo = sourceNo;
    }

    public Integer getFromSystem() {
        return fromSystem;
    }

    public void setFromSystem(Integer fromSystem) {
        this.fromSystem = fromSystem;
    }

    public String getSourceInfo() {
        return sourceInfo;
    }

    public void setSourceInfo(String sourceInfo) {
        this.sourceInfo = sourceInfo;
    }

    public Integer getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(Integer totalAmount) {
        this.totalAmount = totalAmount;
    }

    public Integer getCostAmount() {
        return costAmount;
    }

    public void setCostAmount(Integer costAmount) {
        this.costAmount = costAmount;
    }

    public Integer getPackAmount() {
        return packAmount;
    }

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

    public Integer getItemAmount() {
        return itemAmount;
    }

    public void setItemAmount(Integer itemAmount) {
        this.itemAmount = itemAmount;
    }

    public Integer getFreightAmount() {
        return freightAmount;
    }

    public void setFreightAmount(Integer freightAmount) {
        this.freightAmount = freightAmount;
    }

    public Integer getDiscountAmount() {
        return discountAmount;
    }

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

    public Integer getActualAmount() {
        return actualAmount;
    }

    public void setActualAmount(Integer actualAmount) {
        this.actualAmount = actualAmount;
    }

    public Integer getPayAmount() {
        return payAmount;
    }

    public void setPayAmount(Integer payAmount) {
        this.payAmount = payAmount;
    }

    public Integer getChangeAmount() {
        return changeAmount;
    }

    public void setChangeAmount(Integer changeAmount) {
        this.changeAmount = changeAmount;
    }

    public Integer getIsAlone() {
        return isAlone;
    }

    public void setIsAlone(Integer isAlone) {
        this.isAlone = isAlone;
    }

    public Integer getPayType() {
        return payType;
    }

    public void setPayType(Integer payType) {
        this.payType = payType;
    }

    public Integer getPayModel() {
        return payModel;
    }

    public void setPayModel(Integer payModel) {
        this.payModel = payModel;
    }

    public Long getPayer() {
        return payer;
    }

    public void setPayer(Long payer) {
        this.payer = payer;
    }

    public String getPayNo() {
        return payNo;
    }

    public void setPayNo(String payNo) {
        this.payNo = payNo;
    }

    public String getThirdPayNo() {
        return thirdPayNo;
    }

    public void setThirdPayNo(String thirdPayNo) {
        this.thirdPayNo = thirdPayNo;
    }

    public String getPayInfo() {
        return payInfo;
    }

    public void setPayInfo(String payInfo) {
        this.payInfo = payInfo;
    }

    public Integer getInvoiceType() {
        return invoiceType;
    }

    public void setInvoiceType(Integer invoiceType) {
        this.invoiceType = invoiceType;
    }

    public Integer getAddrId() {
        return addrId;
    }

    public void setAddrId(Integer addrId) {
        this.addrId = addrId;
    }

    public Integer getPerformanceType() {
        return performanceType;
    }

    public void setPerformanceType(Integer performanceType) {
        this.performanceType = performanceType;
    }

    public String getPerformancePlatform() {
        return performancePlatform;
    }

    public void setPerformancePlatform(String performancePlatform) {
        this.performancePlatform = performancePlatform;
    }

    public Integer getIsImmediatePerformance() {
        return isImmediatePerformance;
    }

    public void setIsImmediatePerformance(Integer isImmediatePerformance) {
        this.isImmediatePerformance = isImmediatePerformance;
    }

    public String getPerformanceInfo() {
        return performanceInfo;
    }

    public void setPerformanceInfo(String performanceInfo) {
        this.performanceInfo = performanceInfo;
    }

    public String getActivityInfo() {
        return activityInfo;
    }

    public void setActivityInfo(String activityInfo) {
        this.activityInfo = activityInfo;
    }

    public String getItemInfo() {
        return itemInfo;
    }

    public void setItemInfo(String itemInfo) {
        this.itemInfo = itemInfo;
    }

    public String getDiscountInfo() {
        return discountInfo;
    }

    public void setDiscountInfo(String discountInfo) {
        this.discountInfo = discountInfo;
    }

    public String getSellerRemarks() {
        return sellerRemarks;
    }

    public void setSellerRemarks(String sellerRemarks) {
        this.sellerRemarks = sellerRemarks;
    }

    public String getBuyerRemarks() {
        return buyerRemarks;
    }

    public void setBuyerRemarks(String buyerRemarks) {
        this.buyerRemarks = buyerRemarks;
    }

    public Integer getIsReceipt() {
        return isReceipt;
    }

    public void setIsReceipt(Integer isReceipt) {
        this.isReceipt = isReceipt;
    }

    public String getReceiptTerminal() {
        return receiptTerminal;
    }

    public void setReceiptTerminal(String receiptTerminal) {
        this.receiptTerminal = receiptTerminal;
    }

    public Integer getStatus() {
        return status;
    }

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

    public Integer getPayStatus() {
        return payStatus;
    }

    public void setPayStatus(Integer payStatus) {
        this.payStatus = payStatus;
    }

    public Integer getAfterSaleStatus() {
        return afterSaleStatus;
    }

    public void setAfterSaleStatus(Integer afterSaleStatus) {
        this.afterSaleStatus = afterSaleStatus;
    }

    public Integer getPerformanceStatus() {
        return performanceStatus;
    }

    public void setPerformanceStatus(Integer performanceStatus) {
        this.performanceStatus = performanceStatus;
    }

    public Integer getCommentStatus() {
        return commentStatus;
    }

    public void setCommentStatus(Integer commentStatus) {
        this.commentStatus = commentStatus;
    }

    public Integer getReceiveStatus() {
        return receiveStatus;
    }

    public void setReceiveStatus(Integer receiveStatus) {
        this.receiveStatus = receiveStatus;
    }

    public String getRefusalReason() {
        return refusalReason;
    }

    public void setRefusalReason(String refusalReason) {
        this.refusalReason = refusalReason;
    }

    public Date getOrderAt() {
        return orderAt;
    }

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

    public Date getPayAt() {
        return payAt;
    }

    public void setPayAt(Date payAt) {
        this.payAt = payAt;
    }

    public Date getCommentAt() {
        return commentAt;
    }

    public void setCommentAt(Date commentAt) {
        this.commentAt = commentAt;
    }

    public Date getCompletedAt() {
        return completedAt;
    }

    public void setCompletedAt(Date completedAt) {
        this.completedAt = completedAt;
    }

    public Date getReceiveAt() {
        return receiveAt;
    }

    public void setReceiveAt(Date receiveAt) {
        this.receiveAt = receiveAt;
    }

    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 Integer getSyncFlag() {
        return syncFlag;
    }

    public void setSyncFlag(Integer syncFlag) {
        this.syncFlag = syncFlag;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

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

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

    public void paint(DataStream data) {
        this.orderType = data.getOrderType();
        this.orderSubType = data.getOrderSubType();
        this.status = data.getStatus();
        this.source = data.getSource();
        this.payType = data.getPayType();
        this.performanceType = data.getPerformanceType();
        this.performancePlatform = data.getPerformancePlatform();
        this.features = data.getFeatures();
    }

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